⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functions.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: functions.c,v 1.1 2004/08/28 19:25:45 dannybackx Exp $ *//*****************************************************************************//**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **//**                          Salt Lake City, Utah                           **//**  Portions Copyright 1989 by the Massachusetts Institute of Technology   **//**                        Cambridge, Massachusetts                         **//**                                                                         **//**                           All Rights Reserved                           **//**                                                                         **//**    Permission to use, copy, modify, and distribute this software and    **//**    its documentation  for  any  purpose  and  without  fee is hereby    **//**    granted, provided that the above copyright notice appear  in  all    **//**    copies and that both  that  copyright  notice  and  this  permis-    **//**    sion  notice appear in supporting  documentation,  and  that  the    **//**    names of Evans & Sutherland and M.I.T. not be used in advertising    **//**    in publicity pertaining to distribution of the  software  without    **//**    specific, written prior permission.                                  **//**                                                                         **//**    EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD    **//**    TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES  OF  MERCHANT-    **//**    ABILITY  AND  FITNESS,  IN  NO  EVENT SHALL EVANS & SUTHERLAND OR    **//**    M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL  DAM-    **//**    AGES OR  ANY DAMAGES WHATSOEVER  RESULTING FROM LOSS OF USE, DATA    **//**    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER    **//**    TORTIOUS ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE    **//**    OR PERFORMANCE OF THIS SOFTWARE.                                     **//*****************************************************************************//**************************************************************************** * This module is based on Twm, but has been siginificantly modified  * by Rob Nation ****************************************************************************//**************************************************************************** * The win_list function is * by Rob Nation * A little of it is borrowed from ctwm. * Copyright 1993 Robert Nation. No restrictions are placed on this code, * as long as the copyright notice is preserved ***********************************************************************//*********************************************************************** * The rest of it is all my fault -- MLM * mwm - "LessTif Window Manager" ***********************************************************************/#include <LTconfig.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_TIME_H#include <sys/time.h>#endif#ifdef HAVE_SYS_SELECT_H#include <sys/select.h>#endif#ifdef __EMX__#include <process.h>#endif#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include <Xm/MessageB.h>#include "mwm.h"/* * this only works if what you're assigning to/comparing with is an int */#ifndef INT_MAX#define INT_MAX		((int)(~0U>>1))#endif#ifndef INT_MIN#define INT_MIN		(~0)#endif/* * Does `string' match `pattern'? '*' in pattern matches any sub-string * (including the null string) '?' matches any single char. For use * by filenameforall. Note that '*' matches across directory boundaries * * This code donated by  Paul Hudson <paulh@harlequin.co.uk>     * It is public domain, no strings attached. No guarantees either. */static intmatch_pattern(const char *pattern, const char *string){    if (string == NULL)    {	if (pattern == NULL)	    return True;	else if (strcmp(pattern, "*") == 0)	    return True;	else	    return False;    }    if (pattern == NULL)	return True;    while (*string && *pattern)    {	if (*pattern == '?')	{	    /* match any character */	    pattern += 1;	    string += 1;	}	else if (*pattern == '*')	{	    /* see if the rest of the pattern matches any trailing substring	       of the string. */	    pattern += 1;	    if (*pattern == 0)	    {		return True;	/* trailing * must match rest */	    }	    while (*string)	    {		if (match_pattern(pattern, string))		{		    return True;		}		string++;	    }	    return False;	}	else	{	    if (*pattern == '\\')		pattern++;	/* has strange, but harmless effects if the last				   character is a '\\' */	    if (*pattern++ != *string++)	    {		return False;	    }	}    }    if ((*pattern == 0) && (*string == 0))	return True;    if ((*string == 0) && (strcmp(pattern, "*") == 0))	return True;    return False;}/* * Checks the function "function", and sees if it * is an allowed function for window t,  according to the motif way of life. * This routine is used to decide if we should refuse to perform a function. */static intfunction_allowed(int function, MwmWindow *t){    if ((function == F_RESIZE) && (t) &&	(!(t->functions & MWM_FUNC_RESIZE)))	return 0;    if ((function == F_MOVE) && (t) &&	(!(t->functions & MWM_FUNC_MOVE)))	return 0;    if ((function == F_ICONIFY) && (t) &&	(!(t->flags & ICONIFIED)) &&	(!(t->functions & MWM_FUNC_MINIMIZE)))	return 0;    if ((function == F_MAXIMIZE) && (t) &&	(!(t->functions & MWM_FUNC_MAXIMIZE)))	return 0;    if ((function == F_CLOSE) && (t) &&	(!(t->functions & MWM_FUNC_CLOSE)))	return 0;    return 1;}/* * wait for the quit timeout to see if a window will exit itself */static voidwait_quit_timeout(ScreenInfo *sinfo, MwmWindow *win){#ifndef HAVE_GETITIMER    struct itimerval    {	struct timeval it_value;    };#endif    XEvent event;    struct itimerval value;    fd_set in_fdset, out_fdset;    Window child;    int retval, i;    ScreenInfo *scr;    int timeout;    timeout = Mwm.quit_timeout * 1000;    while (True)    {	/* Do this prior to the select() call, in case the timer already	 * expired, in which case the select would never return. */	if (alarmed)	{	    alarmed = False;	    for (i = 0; i < Mwm.number_of_screens; i++)	    {		scr = Mwm.screen_info[i];		XQueryPointer(dpy, scr->root_win, &JunkRoot, &child,			      &JunkX, &JunkY, &JunkX, &JunkY, &JunkMask);		if ((scr->mwm_focus != NULL) &&		    (child == scr->mwm_focus->frame))		{		    if (!(scr->mwm_focus->flags & VISIBLE) &&			scr->mwm_focus->focus_auto_raise)		    {			WIN_Raise(scr, scr->mwm_focus);			PAGER_Clear(scr);		    }		}	    }	    continue;	}	value.it_value.tv_usec = 10000;	value.it_value.tv_sec = 0;	FD_ZERO(&in_fdset);	FD_SET(x_fd, &in_fdset);	FD_ZERO(&out_fdset);	/* Do this IMMEDIATELY prior to select, to prevent any nasty	 * queued up X events from just hanging around waiting to be	 * flushed */	XFlush(dpy);	if (XPending(dpy))	{	    XNextEvent(dpy, &event);	    MISC_StashEventTime(&event);	    if ((event.type == UnmapNotify || event.type == DestroyNotify) &&		event.xany.window == win->w)	    {		EVENT_Dispatch(&event);		return;	    }	    EVENT_Dispatch(&event);	}	/* Zap all those zombies! */	/* If we get to here, then there are no X events waiting to be	 * processed.  Just take a moment to check for dead children. */	ReapChildren();	XFlush(dpy);#ifdef __hpux	retval = select(fd_width, (int *)&in_fdset, 0, 0, &value.it_value);#else	retval = select(fd_width, &in_fdset, 0, 0, &value.it_value);#endif	timeout -= value.it_value.tv_usec;	if (timeout <= 0)	{	    if (XGetGeometry(dpy, win->w, &JunkRoot, &JunkX, &JunkY,			     &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)		WIN_DestroyWindow(sinfo, win);	    else		XKillClient(dpy, win->w);	    XSync(dpy, 0);	    return;	}    }}/* * circulate a window */static MwmWindow *circulate(ScreenInfo *scr, MwmWindow *tmp_win, char *action, Bool Direction){    MwmWindow *t, *selected;    Bool found;    int count, pass = 1;    int base, best;    tmp_win = MISC_RootOfTree(tmp_win);    while (pass < 3)    {	if (tmp_win)	    base = tmp_win->focus_sequence;	else	    base = -1;	if (Direction == DOWN)	    best = -1;	else	    best = 10000;	selected = tmp_win;	/* move focus to the next window */	found = False;	t = tmp_win;	count = 0;	while (count < 3)	{	    if (Direction == DOWN)	    {		if ((t == (MwmWindow *)0) || (t->next == NULL))		{		    t = scr->mwm_root.next;		    count++;		}		else		    t = t->next;	    }	    else	    {			/* Direction Up */		if ((t == (MwmWindow *)0) || (t == &scr->mwm_root) ||		 (t->prev == &scr->mwm_root) || (t->prev == (MwmWindow *)NULL))		{		    for (t = scr->mwm_root.next; t->next != (MwmWindow *)NULL; t = t->next);		    count++;		}		else		    t = t->prev;	    }	    found = True;	    if (t->Desk != scr->current_desk)		found = False;	    if ((t) && (t->wmhints) && (t->wmhints->flags & InputHint) &&		(t->wmhints->input == False) &&		!(t->flags & WM_TAKES_FOCUS))		found = False;	    if (t->flags & CIRCULATESKIP)		found = False;	    /* optional skip over icons */	    if ((t->flags & ICONIFIED) && (scr->flags & CirculateSkipIcons))		found = False;	    /* Make CirculateUp and CirculateDown take args. by Y.NOMURA */	    if (action && (strlen(action) > 0) &&		!(match_pattern(action, t->name)) &&		!(match_pattern(action, t->icon_label)) &&		t->classhint.res_name &&		!(match_pattern(action, t->classhint.res_name)))		found = False;	    if ((found) && (Direction == DOWN) && (t->focus_sequence > best))	    {		best = t->focus_sequence;		selected = t;	    }	    if ((found) && (Direction != DOWN) && (t->focus_sequence < best)		&& (t->focus_sequence > base))	    {		best = t->focus_sequence;		selected = t;	    }	}	if ((selected) && (selected == tmp_win) && (base > 0))	{	    if (Direction == DOWN)	    {		MISC_SetFocusSequence(scr);		tmp_win->focus_sequence = 0;	    }	    else	    {		MwmWindow *temp;		temp = scr->mwm_root.next;		while (temp != NULL)		{		    temp->focus_sequence++;		    if (temp == tmp_win)			temp->focus_sequence = 0;		    temp = temp->next;		}	    }	    pass++;	}	else	    pass = 3;    }    return selected;}/*********************************************************************** * *  Procedure: *	(Un)maximize a window. * ***********************************************************************/static voidmaximize(ScreenInfo *scr, MwmWindow *tmp_win, int val1, int val2,	 int val1_unit, int val2_unit){    int new_width, new_height, new_x, new_y;    /* First make sure that window is de-iconified */    if (tmp_win->flags & ICONIFIED)    {	    if (val1 <= 0)		ICON_DeIconify(scr, tmp_win);    }    if (tmp_win->flags & MAXIMIZED)    {	tmp_win->flags &= ~MAXIMIZED;	DEC_ConfigureDecorations(scr, tmp_win, tmp_win->orig_x, tmp_win->orig_y,				 tmp_win->orig_wd, tmp_win->orig_ht, True);	DEC_DrawDecorations(scr, tmp_win, True, True, True, None);    }    else    {	new_width = tmp_win->frame_width;	new_height = tmp_win->frame_height;	new_x = tmp_win->frame_x;	new_y = tmp_win->frame_y;	if (val1 > 0)	{	    new_width = val1 * val1_unit / 100 - 2;	    new_x = 0;	}	if (val2 > 0)	{	    new_height = val2 * val2_unit / 100 - 2;	    new_y = 0;	}	if ((val1 == 0) && (val2 == 0))	{	    new_x = 0;	    new_y = 0;	    new_height = scr->d_height - 2;	    new_width = scr->d_width - 2;	}	tmp_win->flags |= MAXIMIZED;	WIN_ConstrainWindow(scr, tmp_win, &new_width, &new_height);	DEC_ConfigureDecorations(scr, tmp_win, new_x, new_y, new_width, new_height, True);	DEC_DrawDecorations(scr, tmp_win, scr->mwm_highlight == tmp_win,			    True, True, tmp_win->maximizeb);    }    PAGER_Clear(scr);}/* * Start a window move operation */static voidmove(ScreenInfo *scr, XEvent *eventp, Window w, MwmWindow *tmp_win,     int context, int val1, int val2, int val1_unit, int val2_unit){    int FinalX, FinalY;    /* gotta have a window */    if (tmp_win == NULL)	return;    w = tmp_win->frame;    if (tmp_win->flags & ICONIFIED)    {	if (tmp_win->icon_pixmap_w != None)	{	    XUnmapWindow(dpy, tmp_win->icon_w);	    w = tmp_win->icon_pixmap_w;	}	else	    w = tmp_win->icon_w;    }    if ((val1 != 0) || (val2 != 0))    {	FinalX = val1 * val1_unit / 100;	FinalY = val2 * val2_unit / 100;    }    else	MOVE_Interactive(scr, &w, tmp_win, &FinalX, &FinalY, eventp);    if (w == tmp_win->frame)    {	DEC_ConfigureDecorations(scr, tmp_win, FinalX, FinalY,			   tmp_win->frame_width, tmp_win->frame_height, False);    }    else    {				/* icon window */	tmp_win->flags |= ICON_MOVED;	tmp_win->icon_x_loc = FinalX;	tmp_win->icon_xl_loc = FinalX -	    (tmp_win->icon_w_width - tmp_win->icon_p_width) / 2;	tmp_win->icon_y_loc = FinalY;	XMoveWindow(dpy, tmp_win->icon_w,		    tmp_win->icon_xl_loc, FinalY + tmp_win->icon_p_height);	if (tmp_win->icon_pixmap_w != None)	{	    XMapWindow(dpy, tmp_win->icon_w);	    XMoveWindow(dpy, tmp_win->icon_pixmap_w, tmp_win->icon_x_loc, FinalY);	    XMapWindow(dpy, w);	}    }    PAGER_Clear(scr);}static voidcancel_cb(Widget w, XtPointer calldata, XtPointer cbs){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -