~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to docking_window.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                docking_window.c
 
6
 
 
7
Purpose:
 
8
        Prepare docking window,  docking icon and  storage required for
 
9
        docking.
 
10
 
 
11
Input:
 
12
        (1) Pointer to RuntimeS structure.
 
13
        (2) Pointer to GUIS structure.
 
14
 
 
15
Output:
 
16
        (1) Docking window created or mapped.
 
17
 
 
18
Return value:
 
19
        (1) Positive on success.
 
20
        (2) Zero if docking window was created before.
 
21
        (3) Negative on failure.
 
22
 
 
23
Notes:
 
24
        (1) The index of exposed atom is of the type int, though size_t
 
25
            is used elsewhere. The reason is that int may have negative
 
26
            value,  while size_t is unsigned on many systems.  Negative
 
27
            values are used  to signal that data stored  to a given box
 
28
            are obsolete.
 
29
 
 
30
========includes:============================================================*/
 
31
 
 
32
#include <stdio.h>
 
33
 
 
34
#include <string.h>
 
35
#include <stdlib.h>
 
36
 
 
37
#include <X11/Xlib.h>
 
38
#include <X11/Xutil.h>
 
39
#include <X11/Xos.h>
 
40
#include <X11/Xatom.h>
 
41
 
 
42
#include "defines.h"
 
43
#include "typedefs.h"
 
44
 
 
45
#include "docking.xpm"
 
46
 
 
47
/*======function prototypes:=================================================*/
 
48
 
 
49
void            ErrorMessage_ (char *, char *, char *,
 
50
                               char *, char *, char *, char *);
 
51
int             MakePixmap_ (WindowS *, GUIS *, char **);
 
52
 
 
53
/*======prepare docking window:==============================================*/
 
54
 
 
55
int PrepareDockingWindow_ (RuntimeS *runtimeSP, GUIS *guiSP)
 
56
{
 
57
XSetWindowAttributes    docking_attribS;
 
58
unsigned long           docking_value_mask;
 
59
XSetWindowAttributes    docking_icon_attribS;
 
60
unsigned long           docking_icon_value_mask;
 
61
static char             docking_win_titleA[SHORTSTRINGSIZE];
 
62
char                    *docking_win_titleP;
 
63
static char             docking_icon_titleA[SHORTSTRINGSIZE];
 
64
char                    *docking_icon_titleP;
 
65
XTextProperty           docking_win_titleS, docking_icon_titleS;
 
66
XSizeHints              *size_hintsSP;
 
67
XWMHints                *wm_hintsSP;
 
68
XClassHint              *class_hintsSP;
 
69
long                    event_mask;
 
70
int                     width;
 
71
size_t                  elementsN, int_size;
 
72
size_t                  exposed_polar_size;
 
73
 
 
74
/* If docking window was created before, just make it visible: */
 
75
if (guiSP->docking_window_createdF)
 
76
        {
 
77
        if (guiSP->docking_window_mappedF == 0)
 
78
                {
 
79
                XMapWindow (guiSP->displaySP, guiSP->docking_winS.ID);
 
80
                }
 
81
        return 0;
 
82
        }
 
83
 
 
84
/*------create docking window:-----------------------------------------------*/
 
85
 
 
86
/* Docking window width and height: */
 
87
guiSP->docking_winS.width  = guiSP->screen_width / 3;
 
88
guiSP->docking_winS.height = guiSP->docking_winS.width;
 
89
 
 
90
/* Position of the top left corner: */
 
91
guiSP->docking_winS.x0 = (int) guiSP->docking_winS.width  - 20;
 
92
guiSP->docking_winS.y0 = (int) guiSP->docking_winS.height - 20;
 
93
 
 
94
/* Set window attributes: */
 
95
docking_attribS.border_pixel = guiSP->main_winS.fg_colorID;
 
96
docking_attribS.background_pixel = guiSP->main_winS.bg_colorID;
 
97
docking_attribS.cursor = guiSP->main_winS.cursorID;
 
98
docking_attribS.colormap = guiSP->colormapID;
 
99
docking_value_mask = CWBorderPixel | CWBackPixel | CWCursor | CWColormap;
 
100
guiSP->docking_winS.border_width = 1;
 
101
 
 
102
/* Border width: */
 
103
guiSP->docking_winS.border_width = guiSP->main_winS.border_width;
 
104
 
 
105
/* Create docking window (root window is the parent) and set flag: */
 
106
guiSP->docking_winS.ID = XCreateWindow (
 
107
                guiSP->displaySP, DefaultRootWindow (guiSP->displaySP),
 
108
                guiSP->docking_winS.x0, guiSP->docking_winS.y0,
 
109
                guiSP->docking_winS.width, guiSP->docking_winS.height,
 
110
                guiSP->docking_winS.border_width, guiSP->depth,
 
111
                InputOutput, guiSP->visualSP,
 
112
                docking_value_mask, &docking_attribS);
 
113
guiSP->docking_window_createdF = 1;
 
114
 
 
115
/* Prepare docking window name: */
 
116
strcpy (docking_win_titleA, "Docking");
 
117
docking_win_titleP = docking_win_titleA;
 
118
 
 
119
/* Set docking window name: */
 
120
if (!XStringListToTextProperty (&docking_win_titleP, 1, &docking_win_titleS))
 
121
        {
 
122
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
123
                "XStringListToTextProperty failed!\n",
 
124
                "", "", "");
 
125
        return -1;
 
126
        }
 
127
 
 
128
/*------docking icon window:-------------------------------------------------*/
 
129
 
 
130
/* Create docking icon pixmap: */
 
131
if (MakePixmap_ (&guiSP->docking_icon_winS, guiSP, docking_xpm) < 0) return -2;
 
132
 
 
133
/* Set icon window attributes: */
 
134
docking_icon_attribS.border_pixel = BlackPixel (guiSP->displaySP,
 
135
                                                guiSP->screenID);
 
136
docking_icon_attribS.background_pixmap = guiSP->docking_icon_winS.pixmapID;
 
137
docking_icon_attribS.colormap = guiSP->colormapID;
 
138
docking_icon_value_mask = CWBorderPixel | CWBackPixmap | CWColormap;
 
139
guiSP->docking_icon_winS.x0 = 440;
 
140
guiSP->docking_icon_winS.y0 = 50;
 
141
guiSP->docking_icon_winS.border_width = 1;
 
142
 
 
143
/* Create docking icon window: */
 
144
guiSP->docking_icon_winS.ID = XCreateWindow (
 
145
                guiSP->displaySP, DefaultRootWindow (guiSP->displaySP),
 
146
                guiSP->docking_icon_winS.x0, guiSP->docking_icon_winS.y0,
 
147
                guiSP->docking_icon_winS.width,
 
148
                guiSP->docking_icon_winS.height,
 
149
                guiSP->docking_icon_winS.border_width, guiSP->depth,
 
150
                InputOutput, guiSP->visualSP,
 
151
                docking_icon_value_mask, &docking_icon_attribS);
 
152
 
 
153
/* Set docking icon window colormap: */
 
154
XSetWindowColormap (guiSP->displaySP,
 
155
                    guiSP->docking_icon_winS.ID,
 
156
                    guiSP->colormapID);
 
157
 
 
158
/* Prepare docking icon window name: */
 
159
strcpy (docking_icon_titleA, "Docking");
 
160
docking_icon_titleP = docking_icon_titleA;
 
161
 
 
162
/* Set docking icon window name: */
 
163
if (!XStringListToTextProperty (&docking_icon_titleP, 1, &docking_icon_titleS))
 
164
        {
 
165
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
166
                "Failed to allocate storage for XTextProperty structure!\n",
 
167
                "", "", "");
 
168
        return -3;
 
169
        }
 
170
 
 
171
/*------set window manager properties:---------------------------------------*/
 
172
 
 
173
/* Allocate and set size hints: */
 
174
size_hintsSP = XAllocSizeHints ();
 
175
if (!size_hintsSP)
 
176
        {
 
177
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
178
                "Failed to allocate storage for size hints!\n",
 
179
                "", "", "");
 
180
        return -4;
 
181
        }
 
182
size_hintsSP->flags = PPosition | PSize | PMinSize;
 
183
size_hintsSP->min_width  = 100;
 
184
size_hintsSP->min_height = 100;
 
185
 
 
186
/* Allocate and set window manager hints: */
 
187
wm_hintsSP = XAllocWMHints ();
 
188
if (!wm_hintsSP)
 
189
        {
 
190
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
191
                "Failed to allocate storage for window manager hints!\n",
 
192
                "", "", "");
 
193
        return -5;
 
194
        }
 
195
wm_hintsSP->initial_state = NormalState;
 
196
wm_hintsSP->input = True;
 
197
wm_hintsSP->icon_pixmap = guiSP->docking_icon_winS.pixmapID;
 
198
wm_hintsSP->flags = StateHint | IconPixmapHint | InputHint;
 
199
 
 
200
/* Allocate and set class hints: */
 
201
class_hintsSP = XAllocClassHint ();
 
202
if (!class_hintsSP)
 
203
        {
 
204
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
205
                "Failed to allocate storage for class hints!\n",
 
206
                "", "", "");
 
207
        return -6;
 
208
        }
 
209
class_hintsSP->res_name = "docking";
 
210
class_hintsSP->res_class = "Garlic";
 
211
 
 
212
/* Set window manager properties: */
 
213
XSetWMProperties (guiSP->displaySP, guiSP->docking_winS.ID,
 
214
                  &docking_win_titleS, &docking_icon_titleS,
 
215
                  NULL, 0, 
 
216
                  size_hintsSP, wm_hintsSP, class_hintsSP);
 
217
 
 
218
/*------select events:-------------------------------------------------------*/
 
219
 
 
220
event_mask = ExposureMask |
 
221
             KeyPressMask | KeyReleaseMask |
 
222
             StructureNotifyMask;       /* Selects ConfigureNotify event */
 
223
 
 
224
XSelectInput (guiSP->displaySP, guiSP->docking_winS.ID, event_mask);
 
225
 
 
226
/*------allocate storage required to project two structures:-----------------*/
 
227
 
 
228
/* The total number of cells across docking area: */
 
229
width = runtimeSP->docking_matrix_width;
 
230
 
 
231
/* The number  of elements  in the array  which  contains */
 
232
/* indices of exposed atoms and size of a single element: */
 
233
elementsN = width * width;
 
234
int_size = sizeof (int);
 
235
 
 
236
/* Allocate the array reserved for the first complex (bottom molecule): */
 
237
runtimeSP->exposed_atom1IP = (int *) calloc (elementsN, int_size);
 
238
if (!runtimeSP->exposed_atom1IP)
 
239
        {
 
240
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
241
                "Failed to allocate storage for exposed_atom1IP!\n",
 
242
                "", "", "");
 
243
        return -7;
 
244
        }
 
245
 
 
246
/* Allocate the array for the second complex (top molecule): */
 
247
runtimeSP->exposed_atom2IP = (int *) calloc (elementsN, int_size);
 
248
if (!runtimeSP->exposed_atom2IP)
 
249
        {
 
250
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
251
                "Failed to allocate storage for exposed_atom2IP!\n",
 
252
                "", "", "");
 
253
        return -8;
 
254
        }
 
255
 
 
256
/*------allocate storage for two lists of exposed polar residues:------------*/
 
257
 
 
258
/* The size of ExposedResidueS structure: */
 
259
exposed_polar_size = sizeof (ExposedResidueS);
 
260
 
 
261
/* Allocate the storage for the exposed polar residues (bottom complex): */
 
262
runtimeSP->exposed_polar1SP =
 
263
                (ExposedResidueS *) calloc (MAX_EXPOSED_RESIDUES,
 
264
                                            exposed_polar_size);
 
265
if (runtimeSP->exposed_polar1SP == NULL)
 
266
        {
 
267
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
268
                       "Failed to allocate memory",
 
269
                       " for exposed polar residues (bottom complex)!\n",
 
270
                       "", "");
 
271
        return -9;
 
272
        }
 
273
 
 
274
/* Allocate the storage for the exposed polar residues (top complex): */
 
275
runtimeSP->exposed_polar2SP =
 
276
                (ExposedResidueS *) calloc (MAX_EXPOSED_RESIDUES,
 
277
                                            exposed_polar_size);
 
278
if (runtimeSP->exposed_polar2SP == NULL)
 
279
        {
 
280
        ErrorMessage_ ("garlic", "PrepareDockingWindow_", "",
 
281
                       "Failed to allocate memory",
 
282
                       " for exposed polar residues (top complex)!\n",
 
283
                       "", "");
 
284
        return -10;
 
285
        }
 
286
 
 
287
/*------map docking window:--------------------------------------------------*/
 
288
 
 
289
/* Map docking window and set flag: */
 
290
XMapWindow (guiSP->displaySP, guiSP->docking_winS.ID);
 
291
guiSP->docking_window_mappedF = 1;
 
292
 
 
293
/*---------------------------------------------------------------------------*/
 
294
 
 
295
/* Return positive value on success: */
 
296
return 1;
 
297
}
 
298
 
 
299
/*===========================================================================*/
 
300
 
 
301