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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $TOG: deskset.c /main/4 1999/02/03 15:35:56 mgreess $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)deskset.c 1.11 94/12/22 Copyr 1993 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
58 #include <sys/param.h>
67 #include <X11/Intrinsic.h>
68 #include <X11/Xutil.h>
74 #define DS_TITLE_LINE_HEIGHT 25
76 /******************************************************************************
78 ** Function: ds_relname
80 ** Description: Return revision name.
84 ** Returns: Revision name (char *)
86 ******************************************************************************/
90 static char buf[MAXNAMELEN];
92 sprintf(buf, "Version %d.%d.%d Revision %d",
93 DtVERSION, DtREVISION, DtUPDATE_LEVEL,
99 * Function: ds_position_popup
101 * Description: Position a popup relative to the parent frame
102 * making sure it doesn't go off of the screen.
104 * Parameters: base Popup's parent widget
106 * location_op Where you would like the popup to
107 * appear. Location_op may be any
110 * DS_POPUP_LEFT Place the popup to the left of base with the tops flush
111 * DS_POPUP_RIGHT Place the popup to the right of base with the tops flush
112 * DS_POPUP_ABOVE Place the popup above base with the left edges flush
113 * DS_POPUP_BELOW Place the popup below base with the left edges flush
114 * DS_POPUP_LOR Place the popup either to the left or right of base
115 * depending on which side has the most space.
116 * DS_POPUP_AOF Place the popup either above or below base
117 * depending on which side has the most space.
118 * DS_POPUP_CENTERED Center popup within baseframe
120 * Returns: 0 Could not get screen size
124 ds_position_popup(Widget base, Widget popup, ds_location_op location_op) {
125 int bh, bw, bx, by, ph, pw, px, py ;
126 int screen_width, screen_height ;
127 Position base_x, base_y, popup_x, popup_y ;
128 Dimension base_width, base_height, popup_width, popup_height ;
133 XmNwidth, &base_width,
134 XmNheight, &base_height,
138 bw = (int) base_width ;
139 bh = (int) base_height ;
144 XmNwidth, &popup_width,
145 XmNheight, &popup_height,
150 pw = (int) popup_width ;
151 ph = (int) popup_height ;
153 ds_get_screen_size(popup, &screen_width, &screen_height) ;
155 if (location_op == DS_POPUP_LOR)
157 if (bx >= screen_width - bw - bx) location_op = DS_POPUP_LEFT ;
158 else location_op = DS_POPUP_RIGHT ;
160 else if (location_op == DS_POPUP_AOB)
162 if (by > screen_height - bh - by) location_op = DS_POPUP_ABOVE ;
163 else location_op = DS_POPUP_BELOW ;
168 case DS_POPUP_RIGHT : px = bx + bw + 5 ;
169 py = by - DS_TITLE_LINE_HEIGHT ;
171 case DS_POPUP_LEFT : px = bx - pw - 5 ;
172 py = by - DS_TITLE_LINE_HEIGHT ;
174 case DS_POPUP_ABOVE : px = bx - 5 ;
177 case DS_POPUP_BELOW : px = bx - 5 ;
180 case DS_POPUP_CENTERED :
181 default : px = bx + (bw - pw) / 2 ;
182 py = by + (bh - ph) / 2 ;
184 ds_force_popup_on_screen(popup, &px, &py) ;
189 /* Function: ds_force_popup_on_screen
191 * Description: Make sure that the specified widget appears entirely
194 * You specify the x and y where you would like the
195 * popup to appear. If this location would cause any
196 * portion of the popup to appear off of the screen
197 * then the routine makes the minimum adjustments
198 * necessary to move it onto the screen.
200 * NOTE: The following coordinates must be specified
201 * relative to the screen origin *not* the
204 * Parameters: popup_x_p Pointer to x location where you would
205 * like the popup to appear. If the popup
206 * is moved this is updated to reflect
208 * popup_y_p Pointer to y location where you would
209 * like the popup to appear. If the popup
210 * is moved this is updated to reflect
213 * popup Popup`s widget.
215 * Returns: TRUE The popup was moved
216 * FALSE The popup was not moved
219 ds_force_popup_on_screen(Widget popup, int *popup_x_p, int *popup_y_p) {
220 Dimension popup_width, popup_height ;
222 int popup_x, popup_y ;
223 int n, rcode, screen_width, screen_height ;
225 popup_x = *popup_x_p ;
226 popup_y = *popup_y_p ;
228 /* Get the screen size */
230 ds_get_screen_size(popup, &screen_width, &screen_height) ;
233 XmNwidth, &popup_width,
234 XmNheight, &popup_height,
237 /* Make sure frame does not go off side of screen */
239 n = popup_x + (int) popup_width ;
240 if (n > screen_width) popup_x -= (n - screen_width) ;
241 else if (popup_x < 0) popup_x = 0 ;
243 /* Make sure frame doen't go off top or bottom */
245 n = popup_y + (int) popup_height ;
246 if (n > screen_height) popup_y -= n - screen_height ;
247 else if (popup_y < 0) popup_y = 0 ;
249 /* Set location and return */
251 left = (Position) popup_x ;
252 top = (Position) popup_y ;
258 if (popup_x != *popup_x_p || popup_y != *popup_y_p) rcode = TRUE ;
260 *popup_x_p = popup_x ;
261 *popup_y_p = popup_y ;
266 /* Function: ds_get_screen_size
268 * Description: Get the width and height of the screen in pixels
270 * Parameters: width_p Pointer to an integer to place width
271 * height_p Pointer to an integer to place height
276 ds_get_screen_size(Widget widget, int *width_p, int *height_p) {
277 Display *dpy = XtDisplay(widget) ;
278 int screen = DefaultScreen(dpy) ;
280 *width_p = DisplayWidth(dpy, screen) ;
281 *height_p = DisplayHeight(dpy, screen) ;