4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Giving Russians Opium May Alter Current Situation
40 static char *SRCID_x11_h = "$Id$";
42 #ident "@(#) x11.h 1.6 12/16/92"
43 #endif /* HAVE_IDENT */
49 /* These colours will be mapped to black on a monochrome screen */
50 extern unsigned long BLACK,BLUE,GREEN,CYAN,RED,BROWN,GREY,DARKGREY;
52 /* These colours will be mapped to white on a monochrome screen */
53 extern unsigned long LIGHTBLUE,LIGHTGREY,LIGHTGREEN,LIGHTCYAN,
54 LIGHTRED,VIOLET,YELLOW,WHITE;
56 typedef enum { ecbOK } ecbReturn;
58 #define CBARGS (struct t_x11 *x11,XEvent *event, Window w, void *data)
59 /* Callback function. Return FALSE to continue, TRUE to exit */
61 typedef struct t_x11 {
72 struct t_wlist *wlist;
73 void (*GetNamedColor)(struct t_x11 *x11,char *name,unsigned long *col);
74 void (*MainLoop)(struct t_x11 *x11);
75 void (*RegisterCallback)(struct t_x11 *x11,Window w,Window Parent,
76 bool cb CBARGS, void *data);
77 void (*UnRegisterCallback)(struct t_x11 *x11, Window w);
78 void (*SetInputMask)(struct t_x11 *x11, Window w, unsigned long mask);
79 unsigned long (*GetInputMask)(struct t_x11 *x11, Window w);
80 void (*CleanUp)(struct t_x11 *x11);
81 void (*Flush)(struct t_x11 *x11);
84 typedef bool CallBack CBARGS;
86 typedef struct t_wlist {
87 Window w; /* The window itself */
88 Window Parent; /* It's parent window */
89 CallBack *cb; /* Call back function */
90 unsigned long mask; /* Input mask */
91 void *data; /* User data struct */
95 t_x11 *GetX11(int *argc, char *argv[]);
96 /* x11 is a struct / function-set that manages a number of windows.
97 * more or (presumably) less like Xt does, but since x11 uses only
98 * Xlib calls, it is *PORTABLE* software.
100 * The x11 struct is in principle Object Oriented, in that the functions
101 * are member of the struct. This makes the software a little more
102 * managable. Because of portability I decided not to use C++, even
103 * though it would be much nicer to work with in the X-Bizz.
105 * Here's the description of how to use the x11 struct
106 * 1. Call the GetX11 routine, with the argc and argv from your main.
107 * This will sort out the X-arguments on the command line and remove
108 * them from the command line. When the routine returns, only the
109 * application specific arguments should be left. Thi opens the
110 * display, selects a font, creates a Graphics Context and also sets
111 * the colours listed above in the global variables.
112 * 2. Call x11->RegisterCallback for each window you want to have
113 * managed by x11. You have to create a Callback routine for your
114 * application that handles *ONE* event at a time. The idea is that
115 * each window has it's own Callback which is not polluted by code
116 * for other windows, but it is of course entirely possible to have
117 * one Callback routine for a number of windows (eg. when you need
118 * to know something about your children).
119 * 3. Call x11->SetInputMask. This comes in place of the normal
120 * XSelectInput, because it enables x11 to manually decide which
121 * events are passed to the windows. With the x11->GetInputMask,
122 * x11->SetInputMask combination, a child window can temporarily
123 * disable mouse and keyboard input for it's parent, while allowing
124 * redraw events to pass through for instance. Hereby a simple way
125 * for creating application modal child windows is implemented.
126 * 4. Call x11->MainLoop. This will call every callback function as
127 * appropriate. When a window receives a message, that makes it decide
128 * to terminate it should call x11->UnRegisterCallback, in order to
129 * tell the x11 Manager that it does not want to receive any more
130 * events. It is up to the window to destroy itself. The MainLoop
131 * routine exits when there are no more windows to manage, i.e. when
132 * all routines have called UnRegisterCallback, OR when one Callback
133 * routine returns non-zero (TRUE).
134 * 5. Call x11->CleanUp. This closes the display, and frees all
135 * memory allocated by x11 before.
138 extern void GetNamedColor(t_x11 *x11,char *name,unsigned long *col);