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 static char sccsid[] = "@(#)96 1.4 com/config/UxXt.c, aic, aic324, 9317324f 5/12/93 15:40:01";
25 * COMPONENT_NAME: AIC AIXwindows Interface Composer
30 * Copyright IBM Corporation 1991, 1993
34 * Permission to use, copy, modify, and distribute this software and its
35 * documentation for any purpose and without fee is hereby granted,
36 * provided that the above copyright notice appear in all copies and that
37 * both that copyright notice and this permission notice appear in
38 * supporting documentation, and that the name of IBM not be
39 * used in advertising or publicity pertaining to distribution of the
40 * software without specific, written prior permission.
42 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
43 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
45 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
46 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
47 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
48 * OR PERFORMANCE OF THIS SOFTWARE.
50 /*---------------------------------------------------------------------
51 * $XConsortium: UxXt.c /main/4 1995/11/01 16:08:57 rswiston $
52 *---------------------------------------------------------------------
55 * Copyright (c) 1991, Visual Edge Software Ltd.
57 * ALL RIGHTS RESERVED. Permission to use, copy, modify, and
58 * distribute this software and its documentation for any purpose
59 * and without fee is hereby granted, provided that the above
60 * copyright notice appear in all copies and that both that
61 * copyright notice and this permission notice appear in supporting
62 * documentation, and that the name of Visual Edge Software not be
63 * used in advertising or publicity pertaining to distribution of
64 * the software without specific, written prior permission. The year
65 * included in the notice is the year of the creation of the work.
66 *-------------------------------------------------------------------*/
67 /*------------------------------------------------------------------------
69 *-----------------------------------------------------------------------*/
74 #include <X11/Intrinsic.h>
75 #include <X11/Shell.h>
76 #include <X11/StringDefs.h>
77 #include <X11/Xutil.h>
82 #include <Xm/DialogS.h>
85 #include <Mrm/MrmPublic.h>
90 static XContext xcontext_id = 0;
92 /******************************************************************************
93 NAME: GetTrueToplevel( wgt )
95 INPUT: Widget wgt - the top user-created widget
97 RETURN: Widget - the shell widget
99 DESCRIPTION: Returns the true toplevel of that interface.
100 This is needed for implicit shells where the widget passed to
101 one of the Ux functions is not always the shell.
103 CREATION: Visual Edge Software April 6 1991
104 -----------------------------------------------------------------------------*/
105 Widget GetTrueToplevel( Widget wgt )
107 while (wgt && !XtIsShell(wgt))
114 /******************************************************************************
115 NAME: handle_dialog_child( wgt, manage_func )
117 INPUT: Widget wgt - the dialogShellWidget
118 void (*manage_func)() - either XtManageChild
121 RETURN: int - UX_NO_ERROR if successfull
124 DESCRIPTION: Handles the popping up or popping down of dialog shells
125 by managing or unmanaging their children.
127 CREATION: Visual Edge Software Sept 19/91
128 -----------------------------------------------------------------------------*/
129 static int handle_dialog_child( Widget wgt, void (*manage_func)(Widget) )
131 XtArgVal i, num_children;
133 int error_flag = UX_ERROR;
136 XmNnumChildren, &num_children,
137 XmNchildren, &children,
140 /*-----------------------------------------------------
141 * We manage/unmanage the first rectObj child in the list.
142 * Note that the check for rectObjClass is necessary since
143 * some implementations of Motif add protocol children to
144 * the dialogShell. Additionally, when the LANG is set to
145 * Japanese, a widget of class Core is created. This widget
146 * should not be managed. We'll skip it.
147 *-----------------------------------------------------*/
149 for (i = 0; i < num_children; i++)
151 if ( XtIsSubclass( children[i], rectObjClass ) &&
152 (XtClass (children[i]) != coreWidgetClass))
154 (*manage_func)(children[i]);
155 error_flag = UX_NO_ERROR;
160 return ( error_flag );
163 /******************************************************************************
164 NAME: popup_dialog( wgt, grab_flag )
166 INPUT: Widget wgt - dialogShell to pop up
167 XtGrabKind grab_flag - the grab flag
171 DESCRIPTION: Pops up a dialogShell.
173 CREATION: Visual Edge Software Sept 19/91
174 -----------------------------------------------------------------------------*/
175 static void popup_dialog( Widget wgt, XtGrabKind grab_flag )
177 if ( handle_dialog_child( wgt, XtManageChild ) == UX_ERROR )
178 XtPopup( wgt, grab_flag );
181 /******************************************************************************
182 NAME: UxPopupInterface( wgt, grab_flag )
184 INPUT: Widget wgt - Widget to popup
185 XtGrabKind grab_flag - grab flag
187 RETURN: int UX_ERROR or UX_NO_ERROR
189 DESCRIPTION: Popups up an interface. The widget should be a toplevel widget.
190 Note that special handling is required for dialogShells since
191 those are popped up by managing their children if they have
193 The grab_flag could be any of:
195 nonexclusive_grab (XtGrabNonexclusive)
196 exclusive_grab (XtGrabExclusive)
198 CREATION: Visual Edge Software April 6 1991
199 -----------------------------------------------------------------------------*/
200 int UxPopupInterface( Widget wgt, XtGrabKind grab_flag )
202 if (!(wgt = GetTrueToplevel(wgt)))
205 if ( XtIsSubclass( wgt, xmDialogShellWidgetClass ) )
207 popup_dialog( wgt, grab_flag );
211 XtPopup( wgt, grab_flag );
214 return ( UX_NO_ERROR );
217 /******************************************************************************
218 NAME: popdown_dialog( wgt )
220 INPUT: Widget wgt - dialogShell to popdown
224 DESCRIPTION: Pops down a dialogShell.
226 CREATION: Visual Edge Software Sept 19/91
227 -----------------------------------------------------------------------------*/
228 static void popdown_dialog( Widget wgt )
230 if ( handle_dialog_child( wgt, XtUnmanageChild ) == UX_ERROR )
234 /******************************************************************************
235 NAME: UxPopdownInterface( wgt )
237 INPUT: Widget wgt - Widget to popdown
239 RETURN: int UX_ERROR / UX_NO_ERROR
241 DESCRIPTION: Pops down an interface. The widget should be a toplevel widget.
242 Note that special handling is required for dialogShells since
243 those are popped down by unmanaging their children if they have
246 CREATION: Visual Edge Software April 6 1991
247 -----------------------------------------------------------------------------*/
248 int UxPopdownInterface( Widget wgt )
250 if (!(wgt = GetTrueToplevel(wgt)))
253 if ( XtIsSubclass( wgt, xmDialogShellWidgetClass ) )
255 popdown_dialog( wgt );
262 return ( UX_NO_ERROR );
265 /******************************************************************************
266 NAME: UxDeleteContextCB( wgt, client_data, call_data )
268 INPUT: Widget wgt - widget causing the callback
269 XtPointer client_data - not used
270 XtPointer call_data - not used
274 DESCRIPTION: Deletes the X context entry.
276 EXT REFERENCES: UxTopLevel, xcontext_id
278 CREATION: Visual Edge Software April 6 1991
279 -----------------------------------------------------------------------------*/
280 void UxDeleteContextCB( Widget wgt, XtPointer client_data,
281 XtPointer _call_data )
283 XtPointer call_data = _call_data;
285 (void) XDeleteContext( XtDisplay( UxTopLevel ),
287 (XContext)(XtArgVal) client_data );
290 /******************************************************************************
291 NAME: UxPutContext( wgt, context )
293 INPUT: Widget wgt - Widget
294 XtPointer context - context pointer
296 RETURN: int UX_ERROR / UX_NO_ERROR
298 DESCRIPTION: Uses the X Context manager to store the given context pointer
299 in a memory location that is indexed by the given widget id.
300 Also adds a destroyCallback to delete that context when the
303 EXT REFERENCES: UxTopLevel, xcontext_id
304 EXT EFFECTS: xcontext_id
306 CREATION: Visual Edge Software April 6 1991
307 -----------------------------------------------------------------------------*/
308 int UxPutContext( Widget wgt, caddr_t context )
312 if ( xcontext_id == 0 )
313 xcontext_id = XUniqueContext();
318 status = XSaveContext( XtDisplay( UxTopLevel ),
325 XtAddCallback (wgt, XmNdestroyCallback,
326 UxDeleteContextCB, (XtPointer)(XtArgVal) xcontext_id);
328 return ( UX_NO_ERROR );
331 /******************************************************************************
332 NAME: UxGetContext( wgt )
334 INPUT: Widget wgt - widget
336 RETURN: caddr_t - the context pointer
338 DESCRIPTION: Uses the X Context manager to find the context pointer
339 stored in a memory location indexed by the given widget id.
341 EXT REFERENCES: UxTopLevel, xcontext_id
343 CREATION: Visual Edge Software April 6 1991
344 -----------------------------------------------------------------------------*/
345 caddr_t UxGetContext( Widget wgt )
351 return ( (caddr_t) NULL );
353 status = XFindContext( XtDisplay( UxTopLevel ),
359 return ( (caddr_t) NULL );
364 /******************************************************************************
365 NAME: DelayedFreeData ( client_data, id )
367 INPUT: XtPointer client_data - pointer to be freed
372 DESCRIPTION: This XtTimerCallbackProc function simply frees the client data.
374 CREATION: Visual Edge Software April 30 1993
375 -----------------------------------------------------------------------------*/
376 static void DelayedFreeData( XtPointer client_data, XtIntervalId *_id)
378 XtIntervalId *id = _id;
380 if (client_data != NULL) {
381 XtFree((char *) client_data);
384 /******************************************************************************
385 NAME: UxDestroyContextCB ( wgt, client_data, call_data )
387 INPUT: Widget wgt - widget
388 XtPointer client_data - pointer to be freed
389 XtPointer call_data - not used
393 DESCRIPTION: This callback function registers a timeout to free the
394 context structure. This mechanism is used to ensure that
395 user's destroyCallbacks are executed before we free the
398 CREATION: Visual Edge Software April 6 1991
399 -----------------------------------------------------------------------------*/
400 void UxDestroyContextCB( Widget _wgt, XtPointer client_data,
401 XtPointer _call_data )
404 XtPointer call_data = _call_data;
406 if (client_data != NULL) {
407 XtAppAddTimeOut(UxAppContext, 0,
408 DelayedFreeData, client_data);
412 /******************************************************************************
413 NAME: UxConvertFontList( fontlist_str )
415 INPUT: char *fontlist_str - string form of fontlist
417 RETURN: XmFontList - fontlist
419 DESCRIPTION: Converts a fontlist from the resource-file string format
420 to the XmFontList type expected in C code.
421 The conversion is done by a call to the built-in Motif convertor
422 and the return value points into Xt's resource cache
423 and so the return value should NOT be XmFontListFree'd.
425 CREATION: Visual Edge Software June 17 1992
426 -----------------------------------------------------------------------------*/
427 XmFontList UxConvertFontList( char *fontlist_str )
430 XmFontList fontlist = NULL;
433 from.size = strlen( fontlist_str ) + 1;
434 from.addr = fontlist_str;
436 to.size = sizeof(XmFontList);
437 to.addr = (caddr_t) &fontlist;
439 status = XtConvertAndStore( UxTopLevel,
446 /******************************************************************************
447 NAME: static ConvertPixmap( file_name, depth )
449 INPUT: char *file_name - Pixmap file name
450 int depth - 0 for no depth specified
454 DESCRIPTION: If the depth argument is 0 , then call XmGetPixmap (no depth
455 argument). Otherwise, call XmGetPixmapByDepth (with depth as
456 specified by the argument).
457 Since there is no way of knowing how long the Pixmaps will be
458 used, they are never destroyed. This is not a serious problem
459 since XmGetPixmap does not regenerate existing Pixmaps.
460 It simply keeps a reference count for the number of times a
463 CREATION: Visual Edge Software March 31, 1993
464 -----------------------------------------------------------------------------*/
465 static Pixmap ConvertPixmap( char *file_name, int depth )
467 XrmValue fg_from, fg_to, bg_from, bg_to;
470 fg_from.size = strlen(XtDefaultForeground);
471 fg_from.addr = XtDefaultForeground;
472 fg_to.addr = (XPointer)&fg;
473 bg_from.size = strlen(XtDefaultBackground);
474 bg_from.addr = XtDefaultBackground;
475 bg_to.addr = (XPointer)&bg;
476 if (!XtConvertAndStore
477 (UxTopLevel, XtRString, &bg_from, XtRPixel, &bg_to)
478 || !XtConvertAndStore
479 (UxTopLevel, XtRString, &fg_from, XtRPixel, &fg_to)
481 fg = WhitePixelOfScreen(XtScreen(UxTopLevel));
482 bg = BlackPixelOfScreen(XtScreen(UxTopLevel));
485 return (XmGetPixmapByDepth
486 (XtScreen(UxTopLevel), file_name, fg, bg, depth));
489 return (XmGetPixmap(XtScreen(UxTopLevel), file_name, fg, bg));
492 /******************************************************************************
493 NAME: UxConvertPixmap( file_name )
495 INPUT: char *file_name - pixmap file name
497 RETURN: Pixmap - Pixmap
499 DESCRIPTION: Call ConvertPixmap with depth 0 (Pixmap)
501 CREATION: Visual Edge Software March 31, 1993
502 -----------------------------------------------------------------------------*/
503 Pixmap UxConvertPixmap( char *file_name )
505 return (ConvertPixmap(file_name, 0));
508 /*------------------------------------------------------------------------
510 * <Allocate a context structure>
511 * INPUT: size -- of the desired structure
512 * isSubclass -- nonzero if the requester is a subclass,
513 * requiring that the result also be
514 * returned for the base.
515 * RETURNS: Pointer to a data area of (at least) the desired size.
516 *------------------------------------------------------------------------*/
517 void* UxNewContext (size_t size, int isSubclass)
519 static void* LastSubclassResult = 0;
520 static int LastResultSize = 0;
524 if (LastSubclassResult) {
525 result = LastSubclassResult;
527 result = XtMalloc(size);
531 LastSubclassResult = result;
532 if (LastResultSize < size) {
533 LastResultSize = size;
536 LastSubclassResult = 0;