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