| 1 |
/* @(#)center_vis.c 17.1 (ESO-IPG) 01/25/02 17:26:32 */ |
| 2 |
/*--------------------------------------------------------------------- |
| 3 |
* $Date: 2003-06-04 14:49:18 $ $Revision: 1.1.1.1 $ |
| 4 |
*--------------------------------------------------------------------- |
| 5 |
* |
| 6 |
* |
| 7 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 8 |
* |
| 9 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 10 |
* distribute this software and its documentation for any purpose |
| 11 |
* and without fee is hereby granted, provided that the above |
| 12 |
* copyright notice appear in all copies and that both that |
| 13 |
* copyright notice and this permission notice appear in supporting |
| 14 |
* documentation, and that the name of Visual Edge Software not be |
| 15 |
* used in advertising or publicity pertaining to distribution of |
| 16 |
* the software without specific, written prior permission. The year |
| 17 |
* included in the notice is the year of the creation of the work. |
| 18 |
*-------------------------------------------------------------------*/ |
| 19 |
|
| 20 |
/*--------------------------------------------------------------------- |
| 21 |
* FILE: center_vis.c |
| 22 |
* |
| 23 |
* CONTENTS: |
| 24 |
* widget placement utilities |
| 25 |
* UxCenterVisibly |
| 26 |
* UxCenterWidgetVisibly |
| 27 |
* |
| 28 |
* Shared between design and runtime systems. |
| 29 |
*--------------------------------------------------------------------*/ |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <X11/Xlib.h> |
| 33 |
#include <X11/Intrinsic.h> |
| 34 |
#include "valloc.h" |
| 35 |
|
| 36 |
#ifdef MOTIF_WIDGETS |
| 37 |
#include <Xm/DialogS.h> |
| 38 |
#include <Xm/BulletinB.h> |
| 39 |
#endif /* MOTIF_WIDGETS */ |
| 40 |
|
| 41 |
#include "UxLib.h" |
| 42 |
#include "global.h" |
| 43 |
|
| 44 |
#include "unit.h" |
| 45 |
#include "uimx_cat.h" |
| 46 |
#include "misc1_ds.h" |
| 47 |
|
| 48 |
|
| 49 |
/* X/OPEN message catalog macros. */ |
| 50 |
#define CGETS(ms,ds_ms) UxCatGets(MC_MISC1,ms,ds_ms) |
| 51 |
|
| 52 |
/* Allowances made for decoration when ensuring that |
| 53 |
* widgets stay onscreen. |
| 54 |
*/ |
| 55 |
|
| 56 |
#define DECORATION_X 10 |
| 57 |
#define DECORATION_Y 10 |
| 58 |
|
| 59 |
|
| 60 |
/*----------------------------------------------------------------------------- |
| 61 |
* GLOBAL |
| 62 |
*----------------------------------------------------------------------------- |
| 63 |
* NAME: void UxCenterWidgetVisibly (rs, parent) |
| 64 |
* INPUT: swidget rs - swidget to center on |
| 65 |
* swidget parent - swidget to move |
| 66 |
* |
| 67 |
* DESCRIPTION: Center 'rs' under the cursor by moving 'parent'. If 'parent' |
| 68 |
* would have to be partly off the screen then 'parent' is moved |
| 69 |
* as far as possible on the screen, and if MOTIF widgets are |
| 70 |
* NOT being used the cursor is warped to the center of 'rs'. |
| 71 |
* |
| 72 |
* REVISON: Last revision: bugfix 2605 |
| 73 |
*-----------------------------------------------------------------------------*/ |
| 74 |
|
| 75 |
void UxCenterWidgetVisibly (child, parent) |
| 76 |
Widget child; |
| 77 |
Widget parent; |
| 78 |
{ |
| 79 |
Window rp, wp; |
| 80 |
int xoff, yoff; |
| 81 |
int rx, ry, wx= 0, wy= 0; |
| 82 |
int px, py; |
| 83 |
Position x, y; |
| 84 |
Dimension w, h, bw; |
| 85 |
unsigned char unittype=0; |
| 86 |
Widget widget; |
| 87 |
unsigned int mask; |
| 88 |
|
| 89 |
/* Initialize offsets with center of child. |
| 90 |
*/ |
| 91 |
XtVaGetValues (child, |
| 92 |
XmNwidth, &w, |
| 93 |
XmNheight, &h, |
| 94 |
NULL); |
| 95 |
unittype = UxFindUnitType (child); |
| 96 |
UxConvertDimension (child, unittype, w, h, XmPIXELS, &w, &h); |
| 97 |
|
| 98 |
xoff = w / 2; |
| 99 |
yoff = h / 2; |
| 100 |
|
| 101 |
/* Add each containing widget offset until we reach parent. |
| 102 |
*/ |
| 103 |
|
| 104 |
widget = child; |
| 105 |
|
| 106 |
while (widget != parent) { |
| 107 |
if (( widget == NULL) || XtIsSubclass (widget, wmShellWidgetClass)) { |
| 108 |
char *msg_ptr; |
| 109 |
|
| 110 |
msg_ptr = UxCopyString (CGETS(MS_MISC1_PARM_ERR, DS_MS_MISC1_PARM_ERR)); |
| 111 |
UxStandardError (msg_ptr); |
| 112 |
UxFree (msg_ptr); |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
XtVaGetValues (widget, |
| 117 |
XmNx, &x, |
| 118 |
XmNy, &y, |
| 119 |
XmNborderWidth, &bw, |
| 120 |
NULL); |
| 121 |
unittype = UxFindUnitType (widget); |
| 122 |
|
| 123 |
if(!XtIsSubclass(widget, xmBulletinBoardWidgetClass)) { |
| 124 |
UxConvertPosition (widget, unittype, x, y, XmPIXELS, &x, &y); |
| 125 |
bw = XmConvertUnits (widget,XmHORIZONTAL,unittype,(int)bw,XmPIXELS); |
| 126 |
} |
| 127 |
|
| 128 |
xoff+= x + bw; |
| 129 |
yoff+= y + bw; |
| 130 |
|
| 131 |
widget = XtParent (widget); |
| 132 |
} |
| 133 |
|
| 134 |
#ifdef MOTIF_WIDGETS |
| 135 |
/* If the parent is a XmDialogShell then its child will have |
| 136 |
* an X and Y position that are the same as that of the dialogShell. |
| 137 |
* In other words, we have to correct for the distance we already |
| 138 |
* subtracted (all other shell children have an X and Y of 0). |
| 139 |
*/ |
| 140 |
if (XtClass (parent) == xmDialogShellWidgetClass) { |
| 141 |
xoff -= (x+bw); |
| 142 |
yoff -= (y+bw); |
| 143 |
} |
| 144 |
#endif /* MOTIF_WIDGETS */ |
| 145 |
|
| 146 |
XQueryPointer (UxDisplay, UxRootWindow, &rp, &wp, |
| 147 |
&rx, &ry, |
| 148 |
&px, &py, |
| 149 |
&mask); |
| 150 |
|
| 151 |
#if defined (UX_FORCE_CENTER_VISIBLY) |
| 152 |
{ |
| 153 |
/* If the resources used to force the center of the parent |
| 154 |
* widget are set, use them instead. This makes it possible |
| 155 |
* to perform Automated testing with HP's Synergy Tool |
| 156 |
*/ |
| 157 |
XrmValue resX, resY; |
| 158 |
char *type; |
| 159 |
extern char * UxProgramName; |
| 160 |
|
| 161 |
if (UxGetAnyResource(UxProgramName, |
| 162 |
"centerVisX", &type, &resX) == True) { |
| 163 |
rx = atoi(resX.addr); |
| 164 |
} |
| 165 |
if (UxGetAnyResource(UxProgramName, |
| 166 |
"centerVisY", &type, &resY) == True) { |
| 167 |
ry = atoi(resY.addr); |
| 168 |
} |
| 169 |
} |
| 170 |
#endif |
| 171 |
|
| 172 |
rx -= xoff; |
| 173 |
ry -= yoff; |
| 174 |
|
| 175 |
/* rx and ry are our tentative coordinates for parent. |
| 176 |
* Make sure we don't put parent offscreen (even partially), |
| 177 |
* leaving margin all round for window decoration. |
| 178 |
* If we adjust rx or ry, we set wx or wy to the amount |
| 179 |
* we must warp the cursor so it shows up centered in rs. |
| 180 |
*/ |
| 181 |
|
| 182 |
XtVaGetValues (parent, |
| 183 |
XmNwidth, &w, |
| 184 |
XmNheight, &h, |
| 185 |
NULL); |
| 186 |
unittype = UxFindUnitType (parent); |
| 187 |
UxConvertDimension (parent, unittype, w, h, XmPIXELS, &w, &h); |
| 188 |
|
| 189 |
|
| 190 |
if (rx-DECORATION_X < 0) { |
| 191 |
wx = DECORATION_X - rx; |
| 192 |
rx = DECORATION_X; |
| 193 |
} else if (rx+w+DECORATION_X > DisplayWidth (UxDisplay, UxScreen)) { |
| 194 |
wx = DisplayWidth (UxDisplay, UxScreen) - (rx + w); |
| 195 |
rx = DisplayWidth (UxDisplay, UxScreen) - (w + DECORATION_X); |
| 196 |
} |
| 197 |
|
| 198 |
if (ry-DECORATION_Y < 0) { |
| 199 |
wy = DECORATION_Y - ry; |
| 200 |
ry = DECORATION_Y; |
| 201 |
} else if (ry+h+DECORATION_Y > DisplayHeight (UxDisplay,UxScreen)) { |
| 202 |
wy = DisplayHeight (UxDisplay, UxScreen) - (ry + h); |
| 203 |
ry = DisplayHeight (UxDisplay, UxScreen) - (h + DECORATION_Y); |
| 204 |
} |
| 205 |
|
| 206 |
#ifndef MOTIF_WIDGETS |
| 207 |
if ((wy != 0) || (wx != 0)) { |
| 208 |
XWarpPointer (UxDisplay,UxRootWindow,UxRootWindow, |
| 209 |
px,py, |
| 210 |
DisplayWidth (UxDisplay,UxScreen), |
| 211 |
DisplayHeight (UxDisplay, UxScreen), |
| 212 |
wx+px, wy+py); |
| 213 |
} |
| 214 |
#endif /* MOTIF_WIDGETS */ |
| 215 |
|
| 216 |
UxConvertPosition (parent, XmPIXELS, rx, ry, unittype, &x, &y); |
| 217 |
|
| 218 |
XtVaSetValues (parent, |
| 219 |
XmNx, x, |
| 220 |
XmNy, y, |
| 221 |
NULL); |
| 222 |
|
| 223 |
#ifdef OL_WIDGETS |
| 224 |
/* Set the window manager size hints to position shells properly. |
| 225 |
* These are obsolete in X11R4, but are needed for pre-R4 managers. |
| 226 |
* This code used to modify the parent WMShell size_hints member, |
| 227 |
* but that struct is under the complete control of the WMShell |
| 228 |
* implementation in Motif. |
| 229 |
* The code also used to set USSize hints, for no apparent reason. |
| 230 |
*/ |
| 231 |
|
| 232 |
if (XtIsSubclass (parent, wmShellWidgetClass) |
| 233 |
&& |
| 234 |
XtIsRealized (parent)) |
| 235 |
{ |
| 236 |
XSizeHints size_hints; |
| 237 |
|
| 238 |
size_hints.x = rx; |
| 239 |
size_hints.y = ry; |
| 240 |
size_hints.flags = USPosition; |
| 241 |
|
| 242 |
XSetNormalHints (UxDisplay, XtWindow (parent), &size_hints); |
| 243 |
} |
| 244 |
#endif /* OL_WIDGETS */ |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
/*----------------------------------------------------------------------------- |
| 249 |
* GLOBAL |
| 250 |
*----------------------------------------------------------------------------- |
| 251 |
* NAME: void UxCenterVisibly (rs, parent) |
| 252 |
* INPUT: swidget *rs - swidget to center on |
| 253 |
* swidget *parent - ancestor to move |
| 254 |
* |
| 255 |
* DESCRIPTION: |
| 256 |
* Center 'rs' under the cursor by moving 'parent'. If 'parent' |
| 257 |
* would have to be partly off the screen then 'parent' is moved |
| 258 |
* as far as possible to the edge of the screen, and if MOTIF |
| 259 |
* widgets are NOT being used, the pointer is warped |
| 260 |
* to the center of 'rs'. |
| 261 |
* |
| 262 |
* Last revision: bugfix 2605 |
| 263 |
*---------------------------------------------------------------------------*/ |
| 264 |
|
| 265 |
void UxCenterVisibly (rs, parent) |
| 266 |
swidget rs; |
| 267 |
swidget parent; |
| 268 |
{ |
| 269 |
|
| 270 |
#ifndef RUNTIME |
| 271 |
if (UxIsInvalidObject (rs, "UxCenterVisibly")) |
| 272 |
return; |
| 273 |
|
| 274 |
if (UxIsInvalidObject (parent, "UxCenterVisibly")) |
| 275 |
return; |
| 276 |
#endif /* RUNTIME */ |
| 277 |
|
| 278 |
UxCenterWidgetVisibly (UxGetWidget (rs), UxRealWidget (parent)); |
| 279 |
} |
| 280 |
|
| 281 |
#ifndef RUNTIME |
| 282 |
|
| 283 |
/* Alternate name used in UIMX interface code. */ |
| 284 |
|
| 285 |
UxCenter_visibly (rs, par) |
| 286 |
swidget rs, par; |
| 287 |
{ |
| 288 |
UxCenterVisibly (rs, par); |
| 289 |
} |
| 290 |
|
| 291 |
#endif |
| 292 |
|