2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: ds_popup.c /main/5 1996/03/25 18:18:07 ageorge $ */
26 * Contains some common functions used by the popups throughout *
27 * the Desktop Calculator. *
29 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
30 * (c) Copyright 1993, 1994 International Business Machines Corp. *
31 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
32 * (c) Copyright 1993, 1994 Novell, Inc. *
37 #include <Xm/VendorSEP.h>
38 /* Copied from BaseClassI.h */
39 extern XmWidgetExtData _XmGetWidgetExtData(
41 #if NeedWidePrototypes
42 unsigned int extType) ;
44 unsigned char extType) ;
45 #endif /* NeedWidePrototypes */
47 #include <X11/ShellP.h>
48 #include <X11/Shell.h>
53 void _DtChildPosition P((Widget, Widget, Position *, Position *)) ;
59 XtPointer client_data,
66 parent = (Widget)client_data;
70 _DtChildPosition(w, parent, &newX, &newY);
71 XtSetArg(args[0], XmNx, newX);
72 XtSetArg(args[1], XmNy, newY);
73 XtSetValues(w, args, 2);
85 XtPointer client_data,
88 _DtmapCB(w, client_data, call_data);
90 XtRemoveCallback(w, XmNmapCallback, (XtCallbackProc)_DtMappedCB,
96 * This is the generic function for registering the map callback.
100 _DtGenericMapWindow (
104 XtAddCallback (parent, XmNmapCallback,
105 (XtCallbackProc)_DtMappedCB, (XtPointer) shell);
111 * Choose a position for a popup window ("child") so that the main
112 * window ("parent") is not obscured. The child will be positioned
113 * to the right, below, left, or above the parent, depending on where
114 * there is the most space.
125 XmVendorShellExtObject vendorExt;
126 XmWidgetExtData extData;
127 int xOffset, yOffset;
128 int pHeight, myHeight, sHeight;
129 int pWidth, myWidth, sWidth;
130 enum { posRight, posBelow, posLeft, posAbove } pos;
133 /* get x, y offsets for the parent's window frame */
134 extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
137 vendorExt = (XmVendorShellExtObject)extData->widget;
138 xOffset = vendorExt->vendor.xOffset;
139 yOffset = vendorExt->vendor.yOffset;
142 xOffset = yOffset = 0;
144 /* get size/position of screen, parent, and widget */
145 sHeight = HeightOfScreen(XtScreen(parent));;
146 sWidth = WidthOfScreen(XtScreen(parent));
147 pX = XtX(parent) - xOffset;
148 pY = XtY(parent) - yOffset;
149 pHeight = XtHeight(parent) + yOffset + xOffset;
150 pWidth = XtWidth(parent) + 2*xOffset;
151 myHeight = XtHeight(w) + yOffset + xOffset;
152 myWidth = XtWidth(w) + 2*xOffset;
155 * Determine how much space would be left if the child was positioned
156 * to the right, below, left, or above the parent. Choose the child
157 * positioning so that the maximum space is left.
160 space = sHeight - (pY + pHeight + myHeight);
162 if (pY - myHeight > space)
165 space = pY - myHeight;
171 sWidth - (pX + pWidth + myWidth);
172 if (pX - myWidth > space)
175 space = pX - myWidth;
179 /* Given relative positioning, determine x, y coordinates for the child */
184 *newX = pX + pWidth - 5;
185 *newY = pY + (pHeight - myHeight)/2;
189 *newX = pX + (pWidth - myWidth)/2;
190 *newY = pY + pHeight;
194 *newX = pX - myWidth + 10;
195 *newY = pY + (pHeight - myHeight)/2;
199 *newX = pX + (pWidth - myWidth)/2;
200 *newY = pY - myHeight;
204 * Defect 177440, put HelpDialog within the monitor
211 if ( ( *newX + myWidth ) > sWidth ) {
214 _tmp = sWidth - myWidth;
219 if ( ( *newY + myHeight ) > sHeight ) {
222 _tmp = sHeight - myHeight;