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 /* $XConsortium: Encaps.c /main/10 1996/10/30 11:10:16 drk $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Source file for the dialog encapsulation functions.
33 * FUNCTIONS: DataChangeCallback
35 * DialogStructureNotifyHandler
36 * IntDialogGetResources
37 * IntDialogPutResources
43 * _DtDialogGetResources
44 * _DtDialogPutResources
45 * _DtDimensionToString
46 * _DtEncapSetWorkSpaceHints
48 * _DtGetDefaultDialogData
50 * _DtGetDialogInstance
53 * _DtGetResourceDialogData
55 * _DtInitializeEncapsulation
65 * _DtXmStringTableToString
70 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
71 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
72 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
73 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
75 ****************************************************************************
76 ************************************<+>*************************************/
82 #include <Xm/BulletinB.h>
83 #include <Xm/AtomMgr.h>
84 #include <Xm/MwmUtil.h>
85 #include <Xm/VendorSEP.h>
86 #include <X11/ShellP.h>
87 #include <X11/Shell.h>
88 #include <X11/Xutil.h>
89 #include <X11/Xatom.h>
90 #include <X11/Intrinsic.h>
91 /* Copied from Xm/BaseClassI.h */
92 extern XmWidgetExtData _XmGetWidgetExtData(
94 #if NeedWidePrototypes
95 unsigned int extType) ;
97 unsigned char extType) ;
98 #endif /* NeedWidePrototypes */
101 #include <Dt/DtNlUtils.h>
108 #define MAX_NAME_LIST_SIZE 25
109 #define MAX_RESOURCE_LENGTH 256
112 /* Cache array handling defines, structure, and global statics */
114 #define INCREMENT_SIZE 10
117 typedef struct _Dialog
120 Widget dialog_widget;
122 DialogData * dialog_data;
123 DialogChangedProc change;
124 XtPointer change_client_data;
125 DialogClosedProc close;
126 XtPointer close_client_data;
127 struct _Dialog * next;
134 Dialog * dialog_list;
136 Boolean destroyPopups;
139 extern int filter_dialog,mod_attr_dialog;
141 static ClassSet * class_set = NULL;
142 static int class_set_size = 0;
143 static int num_classes = 0;
144 static int NumberOfDialogMapped = 0;
146 static char * resourceBuf = NULL;
147 static int commonResourceCount = 5;
148 static DialogResource commonResources[] =
150 { "displayed", XmRBoolean, sizeof(Boolean),
151 XtOffset(DialogInstanceDataPtr, displayed),
152 (caddr_t) False, _DtBooleanToString },
154 { "x", XmRPosition, sizeof(Position),
155 XtOffset(DialogInstanceDataPtr, x),
156 (caddr_t) 0, _DtPositionToString},
158 { "y", XmRPosition, sizeof(Position),
159 XtOffset(DialogInstanceDataPtr, y),
160 (caddr_t) 0, _DtPositionToString },
162 { "width", XmRHorizontalDimension, sizeof(Dimension),
163 XtOffset(DialogInstanceDataPtr, width),
164 (caddr_t) 0, _DtDimensionToString },
166 { "height", XmRVerticalDimension, sizeof(Dimension),
167 XtOffset(DialogInstanceDataPtr, height),
168 (caddr_t) 0, _DtDimensionToString },
171 static Widget encap_parent_shell;
173 extern int file_mgr_dialog;
177 * initialTimeoutLength is used to specify how long to wait before initially
178 * kicking of the building of the dialog cache.
179 * activeTimeoutLength is used to specify how long to wait after adding
180 * a dialog to the cache, before adding the next dialog.
181 * idleTimeoutLength is used to specify how long to wait after all dialogs
182 * have been built, and the cache is full.
184 int initialTimeoutLength = 180000; /* 3 minutes, in milliseconds */
185 int activeTimeoutLength = 30000; /* 30 seconds, in milliseconds */
186 int idleTimeoutLength = 900000; /* 15 minutes, in milliseconds */
188 #define TIMER_STARTUP_STATE 0
189 #define TIMER_ACTIVE_STATE 1
190 #define TIMER_IDLE_STATE 2
192 static int timerState = TIMER_STARTUP_STATE;
193 static XtIntervalId timerId = 0;
197 * This global is used when positioning a dialog ABOVE (not below) its
198 * parent window. The 'y' position is defined to be the 'y' position
199 * of the parent, minus the 'height' of the dialog, minus the value
200 * assigned to 'topPositionOffset'; this allows the application to control
201 * how much, if any, of the parent's title bar is covered.
203 int topPositionOffset = 20;
206 /******** Static Function Declarations ********/
208 static void DialogStructureNotifyHandler(
210 XtPointer client_data,
212 static void SetIconifyState(
215 static void DataChangeCallback(
217 XtPointer client_data,
218 XtPointer call_data) ;
219 static void DataCloseCallback(
221 XtPointer client_data,
222 XtPointer call_data) ;
223 static void TimerEvent(
226 static void IntDialogGetResources(
227 XrmDatabase database,
229 DialogResource *resource,
232 XrmQuark stringQuark) ;
233 static void IntDialogPutResources(
238 DialogResource *resource) ;
240 /******** End Static Function Declarations ********/
244 /************************************************************************
246 * _DtInitializeEncapsulation
247 * This function is used to initialize the dialog encapsulation.
249 ************************************************************************/
252 _DtInitializeEncapsulation(
260 /* Create an application shell that will never be */
261 /* displayed that is used as a parent of all of the */
262 /* dialog created. */
264 encap_parent_shell = XtAppCreateShell (name, class,
265 applicationShellWidgetClass,
268 /* Supposedly required to be ICCCM complient */
269 XtSetArg(args[0], XmNmappedWhenManaged, False);
270 XtSetArg(args[1], XmNwidth, 1);
271 XtSetArg(args[2], XmNheight, 1);
272 XtSetValues(encap_parent_shell, args, 3);
273 XtRealizeWidget(encap_parent_shell);
275 /* Get a timer going that is used for auto creation of dialogs. */
277 timerState = TIMER_STARTUP_STATE;
278 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(encap_parent_shell),
279 initialTimeoutLength, (XtTimerCallbackProc)
280 TimerEvent, (caddr_t) encap_parent_shell);
282 /* Allocate a buffer for writing out resource values */
283 resourceBuf = XtMalloc(20);
289 /************************************************************************
292 * This function is used to register a dialog class with the
293 * encapsulation functions.
295 ************************************************************************/
299 DialogClass *dialog_class,
301 Boolean destroyPopups )
304 /* Allocate additional dialog cache space if needed */
306 if (num_classes == class_set_size)
308 class_set_size += INCREMENT_SIZE;
310 (ClassSet *) XtRealloc ((char *)class_set,
311 sizeof (ClassSet) * class_set_size);
314 class_set[num_classes].class = dialog_class;
315 class_set[num_classes].dialog_list = NULL;
316 class_set[num_classes].cache = cache;
317 class_set[num_classes].destroyPopups = destroyPopups;
321 return (num_classes - 1);
327 /************************************************************************
330 * This function is used to get a structure containing the
331 * current dialog data for a particular dialog instance.
333 ************************************************************************/
337 DialogData *dialog_data )
341 DialogData * new_data;
343 dialog = class_set[dialog_data->type].dialog_list;
345 while (dialog != NULL)
347 if (dialog->dialog_data == dialog_data)
349 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
351 new_data->type = dialog->dialog_data->type;
352 new_data->data = NULL;
353 if (class_set[new_data->type].class->get_values)
356 (*(class_set[new_data->type].class->get_values)) (dialog->dialog);
362 dialog = dialog->next;
371 /************************************************************************
373 * _DtGetDefaultDialogData
374 * This function is used to get a structure containing the
375 * default data for a particular dialog type.
377 ************************************************************************/
380 _DtGetDefaultDialogData(
385 DialogData * dialog_data;
387 dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
389 dialog_data->type = dialog_type;
390 dialog_data->data = (*(class_set[dialog_type].class->get_default_values))();
392 return (dialog_data);
398 /************************************************************************
400 * _DtGetResourceDialogData
401 * This function is used to get a structure containing the
402 * data for a particular dialog type from a resource data base.
404 ************************************************************************/
407 _DtGetResourceDialogData(
409 XrmDatabase data_base,
413 DialogData * dialog_data;
415 dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
417 dialog_data->type = dialog_type;
418 dialog_data->data = (*(class_set[dialog_type].class->get_resource_values))
419 (data_base, name_list);
421 return (dialog_data);
427 /************************************************************************
430 * This functions is used to display an instance of a dialog with
431 * the provided data. The functions and data to be set back to
432 * the application upon change or close of the dialog is also
433 * provided as parameters.
435 ************************************************************************/
441 DialogData *dialog_data,
442 DialogChangedProc change_proc,
443 XtPointer change_data,
444 DialogClosedProc close_proc,
445 XtPointer close_data,
447 Boolean iconify_state,
450 XClassHint * classHints )
455 DialogInstanceData * instance_data;
458 Boolean doCenter = False;
459 Boolean doParentRelativePositioning = False;
460 int availableDialogCount;
463 /* See if there is a cached, unused dialog of the correct type. */
465 dialog_type = dialog_data->type;
470 Dialog * availableDialog;
472 availableDialog = class_set[dialog_type].dialog_list;
473 availableDialogCount = 0;
476 * In addition to looking for an available dialog in the cache to use,
477 * we also want to count up the number of unused dialogs in the cache.
478 * This lets us know it we need to restart the timer, to again build
481 while (availableDialog != NULL)
483 if (availableDialog->in_use == False)
486 dialog = availableDialog;
488 availableDialogCount++;
490 availableDialog = availableDialog->next;
496 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
498 (*(class_set[dialog_type].class->create))
499 (XtDisplay (encap_parent_shell), encap_parent_shell,
500 &(dialog->dialog_widget), &dialog->dialog);
502 /* if this is a File Manager view we want to update the headers
503 * (i.e icon_path, current_directory, status_line), now so that they
504 * don't get managed up front. This is to make the Application
505 * Manager (toolbox) happy.
507 if(dialog_type == file_mgr_dialog)
508 UpdateHeaders(dialog->dialog, dialog_data->data, False);
510 /* Add the change and close callbacks into the dialog */
512 if (class_set[dialog_type].class->install_change_callback)
513 (*(class_set[dialog_type].class->install_change_callback))
514 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
516 if (class_set[dialog_type].class->install_close_callback)
517 (*(class_set[dialog_type].class->install_close_callback))
518 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
520 dialog->next = class_set[dialog_type].dialog_list;
521 class_set[dialog_type].dialog_list = dialog;
525 if(dialog_type == mod_attr_dialog)
527 ModAttrRec *mr = (ModAttrRec *)dialog->dialog;
528 ResetFlag(NULL,mr->ok);
529 ResetFlag(NULL,mr->cancel);
531 else if(dialog_type == filter_dialog)
533 FilterRec *fr = (FilterRec *)dialog->dialog;
534 ResetFlag(NULL,fr->ok);
535 ResetFlag(NULL,fr->close);
539 if ((!ignoreCache) && (class_set[dialog_type].cache) &&
540 (availableDialogCount < 1) && (timerState == TIMER_IDLE_STATE))
543 * We need to reset the cache building timer, so that it gets kicked
544 * off quickly, instead of after the longer idle delay.
547 XtRemoveTimeOut(timerId);
548 timerState = TIMER_ACTIVE_STATE;
549 timerId = XtAppAddTimeOut(
550 XtWidgetToApplicationContext(encap_parent_shell),
551 activeTimeoutLength, (XtTimerCallbackProc) TimerEvent,
552 (XtPointer) encap_parent_shell);
556 * Set pointer to top dialog data in child of the shell.
557 * This is needed to get help to work.
560 top_rec = dialog->dialog;
561 XtSetArg(args[0], XmNuserData, top_rec);
562 XtSetValues(dialog->dialog_widget, args, 1);
564 /* Need to add the map callback in relation to the parent */
565 if (class_set[dialog_type].class->map)
568 * The map_parent parameter gives us the ability to position
569 * the dialog relative to a window which is not the transientFor
570 * parent. This is used for the audio preview dialog.
572 if (map_parent == NULL)
575 (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
579 /* Set the dialog structure fields to the parameter data. */
581 dialog->in_use = True;
582 dialog->dialog_data = dialog_data;
583 dialog->change = change_proc;
584 dialog->change_client_data = change_data;
585 dialog->close = close_proc;
586 dialog->close_client_data = close_data;
589 instance_data = (DialogInstanceData *) dialog_data->data;
591 /* If a special title has been specified, we need to set it now */
594 XtSetArg(args[0], XmNtitle, title);
595 XtSetValues(XtParent(dialog->dialog_widget), args, 1);
598 /* If this is a top level shell, get it realized */
600 if (XtIsSubclass (XtParent (dialog->dialog_widget),
601 applicationShellWidgetClass))
603 if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
605 if (instance_data->displayed == True)
607 (void) sprintf (geometry, "=%dx%d+%d+%d",
608 instance_data->width, instance_data->height,
609 instance_data->x, instance_data->y);
611 XtSetArg (args[0], XmNgeometry, geometry);
612 XtSetValues (XtParent (dialog->dialog_widget), args, 1);
614 else if ((instance_data->width != 0) && (instance_data->height != 0))
617 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
618 XtSetArg (args[n], XmNheight, instance_data->height); n++;
619 XtSetValues (XtParent (dialog->dialog_widget), args, n);
622 /* Toggle mappedWhenManaged to false */
623 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
624 XtRealizeWidget (XtParent(dialog->dialog_widget));
626 /* Set the proper workspaces if needed */
627 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
629 /* Set any application-specified class hints for the window */
632 XSetClassHint(XtDisplay(dialog->dialog_widget),
633 XtWindow(XtParent(dialog->dialog_widget)),
637 /* Set the iconify state */
638 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
641 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
642 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
643 XSync(XtDisplay(dialog->dialog_widget), False);
648 if (instance_data->displayed == True)
650 WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
652 wm->wm.size_hints.flags |= USPosition;
653 XtSetArg (args[0], XmNx, instance_data->x);
654 XtSetArg (args[1], XmNy, instance_data->y);
655 XtSetArg (args[2], XmNwidth, instance_data->width);
656 XtSetArg (args[3], XmNheight, instance_data->height);
657 XtSetValues (XtParent (dialog->dialog_widget), args, 4);
659 else if ((instance_data->width != 0) && (instance_data->height != 0))
662 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
663 XtSetArg (args[n], XmNheight, instance_data->height); n++;
664 XtSetValues (XtParent (dialog->dialog_widget), args, n);
667 /* Set the proper workspaces if needed */
668 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
670 /* Set any application-specified class hints for the window */
673 XSetClassHint(XtDisplay(dialog->dialog_widget),
674 XtWindow(XtParent(dialog->dialog_widget)),
678 /* Set the iconify state */
679 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
682 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
687 if (instance_data->displayed == True)
689 XtSetArg (args[0], XmNx, instance_data->x);
690 XtSetArg (args[1], XmNy, instance_data->y);
691 XtSetArg (args[2], XmNwidth, instance_data->width);
692 XtSetArg (args[3], XmNheight, instance_data->height);
693 XtSetArg (args[4], XmNdefaultPosition, False);
694 XtSetValues (dialog->dialog_widget, args, 5);
695 XtRealizeWidget (dialog->dialog_widget);
699 XtSetArg (args[0], XmNdefaultPosition, False);
700 XtSetValues (dialog->dialog_widget, args, 1);
702 XtRealizeWidget (dialog->dialog_widget);
706 /* Position relative to the parent dialog */
708 * Must be done after the set_values call, since the dialog
709 * may get forced to a different size.
711 doParentRelativePositioning = True;
715 /* Center in the display */
717 * Must be done after the set_values call, since the dialog
718 * may get forced to a different size.
725 * Dialogs with no controlling parent window, need to have their
726 * own workspace perperty set, if some workspaces have been requested.
728 if ((parent == NULL) && workspaces)
729 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
733 /* Set Values onto the dialog to set it to the correct data. */
735 (*(class_set[dialog_data->type].class->set_values))
736 (dialog->dialog, dialog_data->data);
739 * These two adjustments MUST be done AFTER the dialog's SetValues()
740 * procedure is called. This is due to the fact that the setvalues
741 * may cause the dialog size to change, and since both of the following
742 * positioning algorithms are dependent upon the dialog size, we want
743 * to make sure that the correct size is used.
747 XtSetArg (args[0], XmNx,
748 (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
749 dialog->dialog_widget->core.width) / (Dimension)2);
750 XtSetArg (args[1], XmNy,
751 (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
752 dialog->dialog_widget->core.height) / (Dimension)2);
753 XtSetValues (dialog->dialog_widget, args, 2);
755 else if (doParentRelativePositioning)
757 XtSetArg (args[0], XmNx,
759 (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
760 XtSetArg (args[1], XmNy,
762 (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
763 XtSetValues (XtParent(dialog->dialog_widget), args, 2);
767 /* Fix up the transient-for windowing information so that */
768 /* the window manager will shuffle and iconify as a group */
772 if (XtIsRealized(parent))
774 XSetTransientForHint (XtDisplay (parent),
775 XtWindow (XtParent (dialog->dialog_widget)),
781 if (!XtIsSubclass (XtParent (dialog->dialog_widget),
782 applicationShellWidgetClass))
784 XSetTransientForHint (XtDisplay (encap_parent_shell),
785 XtWindow (XtParent (dialog->dialog_widget)),
786 XtWindow (encap_parent_shell));
791 /* Display the dialogs, application shells are displayed above. */
793 if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
794 applicationShellWidgetClass)))
796 XtManageChild (dialog->dialog_widget);
800 /* Set the dialog instance data to indicate that the dialog */
803 ((DialogInstanceData *) (dialog_data->data))->displayed = True;
806 /* Give the dialog a chance to set its focus widget, if necessary */
808 if (class_set[dialog_data->type].class->set_focus)
810 (*(class_set[dialog_data->type].class->set_focus))
811 (dialog->dialog, dialog_data->data);
816 XtAddEventHandler( XtParent( dialog->dialog_widget ),
819 (XtEventHandler)DialogStructureNotifyHandler,
826 /************************************************************************
829 * This function is used to undisplay a dialog.
831 ************************************************************************/
835 DialogData *dialog_data,
836 Boolean call_callbacks )
840 DialogData * new_data;
845 /* Find the dialog and then hide it. */
847 dialog = class_set[dialog_data->type].dialog_list;
849 while (dialog != NULL)
851 if ((dialog->dialog_data &&
852 dialog->dialog_data == dialog_data) && dialog->in_use == True)
856 /* Free up any dialogs attached to the dialog widget */
858 if(class_set[dialog_data->type].destroyPopups)
860 core = (CorePart *) (XtParent (dialog->dialog_widget));
862 for (i = core->num_popups - 1; i >= 0; i--)
863 XtDestroyWidget (core->popup_list[i]);
867 /* Get the dialog down, invoke the close callbacks, and */
868 /* take it out of use. */
870 if (XtIsSubclass (XtParent (dialog->dialog_widget),
871 applicationShellWidgetClass))
873 ShellWidget shell_widget;
876 * If we had been iconified, then our popped_up flag will
877 * have been cleared by the vendor shell. When we call
878 * XtPopdown(), it will see that we are no longer popped
879 * up, and will not notify the window manager that our
880 * icon should be removed; this can cause a subsequent
881 * core dump if the user later tries to deiconify the window.
882 * This fix should not be necessary once the toolkit is
883 * fixed to properly track the shell's state.
885 shell_widget = (ShellWidget) XtParent(dialog->dialog_widget);
886 shell_widget->shell.popped_up = True;
888 XtPopdown ((Widget)shell_widget);
893 * The following is for the condition described above. However,
894 * for a dialog shell, what happens it that the 'managed' flag
895 * was set to 'False' when the windows were iconified (apparently
896 * by the dialog shell), and when we tell the intrinsics to
897 * really unmanage the child, it thinks it already has, so
898 * nothing happens; as a result, the dialog shell is left with
899 * its 'popped_up' flag set to 'True'. The next time we try
900 * to post this dialog, the intrinsics think that it is already
901 * up, so it does nothing.
903 dialog->dialog_widget->core.managed = True;
904 XtUnmanageChild (dialog->dialog_widget);
908 /* Set the dialog data to hidden */
910 ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
913 if (call_callbacks && dialog->close)
915 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
917 new_data->type = dialog->dialog_data->type;
918 new_data->data = NULL;
919 if (class_set[new_data->type].class->get_values)
922 (*(class_set[new_data->type].class->get_values))(dialog->dialog);
925 dialog->in_use = False;
927 ((DialogInstanceData *) (new_data->data))->displayed = False;
930 (dialog->close_client_data, dialog->dialog_data, new_data);
934 dialog->in_use = False;
935 ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
941 dialog = dialog->next;
948 /************************************************************************
951 * This function is used return the shell widget of a dialog that
952 * is currently displayed.
954 ************************************************************************/
958 DialogData *dialog_data )
964 /* Find the dialog and then return the shell. */
966 dialog = class_set[dialog_data->type].dialog_list;
968 while (dialog != NULL)
970 if (dialog->dialog_data == dialog_data)
971 return (dialog->dialog_widget);
973 dialog = dialog->next;
982 /************************************************************************
984 * _DtGetDialogInstance
985 * This function is used return the dialog instance structure
986 * of a currently in use dialog.
988 ************************************************************************/
991 _DtGetDialogInstance(
992 DialogData *dialog_data )
998 /* Find the dialog and then return the instance */
1000 dialog = class_set[dialog_data->type].dialog_list;
1002 while (dialog != NULL)
1004 if (dialog->dialog_data && dialog->dialog_data == dialog_data)
1005 return (dialog->dialog);
1007 dialog = dialog->next;
1016 /************************************************************************
1018 * _DtGetInstanceData
1019 * This function is used return the dialog data structure contained
1020 * within the cache structure referenced by instance.
1022 ************************************************************************/
1026 XtPointer instance )
1033 /* Find the dialog and then return the instance */
1035 for (i = 0; i < num_classes; i++)
1037 dialog = class_set[i].dialog_list;
1039 while (dialog != NULL)
1041 if (dialog->dialog == instance && dialog->in_use == True)
1042 return (dialog->dialog_data);
1044 dialog = dialog->next;
1054 /************************************************************************
1056 * _DtIsDialogShowing
1057 * This function is used return a boolean indicating whether the
1058 * a dialog is displayed which contains the dialog data.
1059 * of a currently in use dialog.
1061 ************************************************************************/
1065 DialogData *dialog_data )
1071 /* Find the dialog and then return the instance */
1073 dialog = class_set[dialog_data->type].dialog_list;
1075 while (dialog != NULL)
1077 if (dialog->in_use && dialog->dialog_data == dialog_data)
1080 dialog = dialog->next;
1089 /************************************************************************
1091 * _DtWriteDialogData
1092 * This function is used to write, as resources, the data
1093 * for a dialog contained in dialog_data to the open file fd.
1095 ************************************************************************/
1099 DialogData *dialog_data,
1104 if (dialog_data != NULL)
1105 (*(class_set[dialog_data->type].class->write_resource_values))
1106 (dialog_data, fd, name_list);
1112 /************************************************************************
1115 * This function is used to free up the data space allocated
1118 ************************************************************************/
1122 DialogData *dialog_data )
1125 if (dialog_data != NULL)
1127 (*(class_set[dialog_data->type].class->free_values)) (dialog_data->data);
1128 XtFree ((char *) dialog_data);
1136 /************************************************************************
1138 * _DtDialogGetResources
1139 * This function accesses data_base to extract the resource set
1140 * described by the resoruces array. Resources values are
1141 * converted to the proper type and defaults are used if not
1142 * data is found in the resource data base.
1144 ************************************************************************/
1147 _DtDialogGetResources(
1148 XrmDatabase database,
1152 DialogResource *resources,
1153 int resource_count )
1156 XrmName xrmName[MAX_NAME_LIST_SIZE];
1157 XrmQuark stringQuark;
1161 /* Build the quarkified name list from name_list and dialog_name */
1162 /* provided by the calling procedure. */
1165 if (name_list != NULL)
1167 while (name_list[nameCount] != NULL)
1169 xrmName[nameCount] = XrmStringToQuark (name_list[nameCount]);
1175 xrmName[nameCount] = XrmStringToQuark (dialog_name);
1179 xrmName[nameCount + 2] = 0;
1180 stringQuark = XrmStringToQuark (XmRString);
1183 /* Load the common dialog size/position resources */
1184 for (i = 0; i < resource_count; i++)
1186 IntDialogGetResources(database, base, resources + i, xrmName, nameCount,
1191 * Load the dialog specific resources. If no value found, use the default.
1193 for (i = 0; i < commonResourceCount; i++)
1195 IntDialogGetResources(database, base, commonResources + i, xrmName,
1196 nameCount, stringQuark);
1202 * This internal function does the real work of loading a single resource
1203 * value. If the value is not found in the resource database, then the
1204 * specified default value is used.
1208 IntDialogGetResources(
1209 XrmDatabase database,
1211 DialogResource *resource,
1214 XrmQuark stringQuark )
1217 XrmRepresentation repType;
1219 XrmValue convertedValue;
1226 xrmName[nameCount + 1] = XrmStringToQuark (resource->name);
1228 if (XrmQGetResource (database, xrmName, xrmName, &repType, &value))
1230 if (repType == stringQuark)
1231 if (strcmp (resource->type, XmRString) != 0)
1233 XtConvert (encap_parent_shell, XmRString, &value,
1234 resource->type, &convertedValue);
1238 *((char **)(base + resource->offset)) = (char *)value.addr;
1242 convertedValue.addr = NULL;
1246 convertedValue.addr = NULL;
1249 /* Set the converted value address pointer and value to */
1250 /* the proper default value if the addr is NULL. */
1252 if (convertedValue.addr == NULL)
1254 if (resource->size == sizeof(char))
1256 charVal = (char)resource->default_value;
1257 convertedValue.addr = (caddr_t) &charVal;
1259 else if (resource->size == sizeof(short))
1261 shortVal = (short)resource->default_value;
1262 convertedValue.addr = (caddr_t) &shortVal;
1264 else if (resource->size == sizeof(int))
1266 intVal = (int)resource->default_value;
1267 convertedValue.addr = (caddr_t) &intVal;
1271 longVal = (long)resource->default_value;
1272 convertedValue.addr = (caddr_t) &longVal;
1277 /* Stuff the converted value into the calling functions */
1278 /* structure according to the size of the piece of data. */
1280 if (resource->size == sizeof(char))
1281 *((char *)(base + resource->offset)) = *((char *)convertedValue.addr);
1282 else if (resource->size == sizeof(short))
1283 *((short *)(base + resource->offset))= *((short *)convertedValue.addr);
1284 else if (resource->size == sizeof(int))
1285 *((int *)(base + resource->offset))= *((int *)convertedValue.addr);
1287 *((long *)(base + resource->offset)) = *((long *)convertedValue.addr);
1293 /************************************************************************
1295 * _DtDialogPutResources
1296 * This function writes a resource set to a file.
1298 ************************************************************************/
1301 _DtDialogPutResources(
1306 DialogResource *resources,
1311 DialogInstanceData * dialogInstanceData;
1314 * Write out the common dialog size/position resources, only if the
1315 * dialog is currently displayed.
1317 dialogInstanceData = (DialogInstanceData *)base;
1318 if (dialogInstanceData->displayed)
1320 for (i = 0; i < commonResourceCount; i++)
1322 IntDialogPutResources(fd, nameList, dialogName, base,
1323 commonResources + i);
1328 * Loop through the dialog specific resources, write the name list and
1331 for (i = 0; i < resourceCount; i++)
1332 IntDialogPutResources( fd, nameList, dialogName, base, resources + i);
1337 * This internal function does the real work involved in writing a single
1338 * resource out to a session file.
1342 IntDialogPutResources(
1347 DialogResource *resource )
1350 static char outBuf[MAX_RESOURCE_LENGTH];
1355 (void) strcat (outBuf, "*");
1358 if (nameList != NULL)
1360 while (nameList[nameCount] != NULL)
1362 (void) strcat (outBuf, nameList[nameCount]);
1363 (void) strcat (outBuf, ".");
1368 if (dialogName != NULL)
1370 (void) strcat (outBuf, dialogName);
1371 (void) strcat (outBuf, ".");
1374 (void) strcat (outBuf, resource->name);
1375 (void) strcat (outBuf, ": ");
1377 (*(resource->write_resource))
1378 (fd, (XtPointer) (base + resource->offset), outBuf);
1383 /************************************************************************
1384 ************************************************************************
1386 * Internal functions
1388 ************************************************************************
1389 ************************************************************************/
1392 /************************************************************************
1394 * _DtEncapSetWorkSpaceHints
1395 * This function sets a given shell to a given set(s) of
1398 ************************************************************************/
1400 _DtEncapSetWorkSpaceHints(
1406 Atom * workspace_atoms = NULL;
1407 int num_workspaces=0;
1413 ptr = DtStrchr (workspaces, '*');
1415 if (ptr != NULL) *ptr = '\0';
1417 workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
1418 sizeof (Atom) * (num_workspaces + 1));
1420 workspace_atoms[num_workspaces] =
1421 XmInternAtom (XtDisplay(shell), workspaces, True);
1428 workspaces = ptr + 1;
1430 } while (ptr != NULL);
1432 DtWsmSetWorkspacesOccupied (XtDisplay(shell), XtWindow (shell), workspace_atoms,
1435 XtFree ((char *) workspace_atoms);
1436 workspace_atoms = NULL;
1442 Screen *currentScreen;
1444 char *workspace_name;
1447 * Since no specific workspaces were specified, we will force the
1448 * dialog to the current workspace.
1450 screen = XDefaultScreen(XtDisplay(shell));
1451 currentScreen = XScreenOfDisplay(XtDisplay(shell), screen);
1452 rootWindow = RootWindowOfScreen(currentScreen);
1454 if(DtWsmGetCurrentWorkspace(XtDisplay(shell), rootWindow, &pCurrent) ==
1457 DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell), &pCurrent, 1);
1462 /************************************************************************
1465 * This function sets a given shell to a given iconify state.
1466 * (e.g. Mapped or iconified)
1468 ************************************************************************/
1480 /* add the iconify hint to the current shell */
1481 XtSetArg(args[0], XmNinitialState, IconicState);
1482 XtSetValues(shell, args, 1);
1486 /* Remove the iconify hint from the current shell */
1487 wmhints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
1488 wmhints->flags |= IconWindowHint;
1489 wmhints->initial_state = NormalState;
1490 XSetWMHints(XtDisplay(shell), XtWindow(shell), wmhints);
1495 /************************************************************************
1497 * DataChangeCallback
1498 * This callback is invoked from a dialog upon an action on the
1499 * dialog that means that the data within the dialog has been
1502 ************************************************************************/
1508 XtPointer client_data,
1509 XtPointer call_data )
1512 Dialog * dialog = (Dialog *) client_data;
1513 DialogData * new_data;
1515 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
1517 new_data->type = dialog->dialog_data->type;
1518 new_data->data = NULL;
1519 if (class_set[new_data->type].class->get_values)
1521 new_data->data = (*(class_set[new_data->type].class->get_values))
1527 (dialog->change_client_data, dialog->dialog_data, new_data, call_data);
1533 /************************************************************************
1536 * This callback is invoked from a dialog upon an action on the
1537 * dialog that means the dialog has been closed.
1539 ************************************************************************/
1545 XtPointer client_data,
1546 XtPointer call_data )
1550 Dialog * dialog = (Dialog *) client_data;
1552 if(RecheckFlag(NULL,widget)) /* cancel flag already set, just return */
1554 _DtHideDialog (dialog->dialog_data, True);
1560 /************************************************************************
1563 * This action function is called upon the encapsulations
1564 * timeout going off. Its function is to precreate and destroy
1567 ************************************************************************/
1578 Dialog * prev_dialog;
1582 /* First pass through the dialog set to see if any */
1583 /* need to be created. This is based on having 0 */
1584 /* not in use dialogs of each type. */
1586 for (i = 0; i < num_classes; i++)
1588 dialog = class_set[i].dialog_list;
1590 /* Only attempt to cache dialogs requesting this feature */
1591 if (!class_set[i].cache)
1594 while (dialog != NULL)
1595 if (dialog->in_use == False)
1598 dialog = dialog->next;
1602 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
1604 (*(class_set[i].class->create))
1605 (XtDisplay (encap_parent_shell), encap_parent_shell,
1606 &(dialog->dialog_widget), &dialog->dialog);
1609 /* Add the change and close callbacks into the dialog */
1611 if (class_set[i].class->install_change_callback)
1612 (*(class_set[i].class->install_change_callback))
1613 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
1615 if (class_set[i].class->install_close_callback)
1616 (*(class_set[i].class->install_close_callback))
1617 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
1620 dialog->next = class_set[i].dialog_list;
1621 class_set[i].dialog_list = dialog;
1623 dialog->in_use = False;
1625 timerState = TIMER_ACTIVE_STATE;
1626 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
1627 activeTimeoutLength,
1628 (XtTimerCallbackProc) TimerEvent,
1629 (XtPointer) widget);
1636 /* Pass through the dialog set to see if any need to be destroyed */
1637 /* This is based on having more than 1 not in use dialog of a type. */
1639 for (i = 0; i < num_classes; i++)
1641 dialog = class_set[i].dialog_list;
1644 while (dialog != NULL)
1646 if (dialog->in_use == False)
1649 dialog = dialog->next;
1654 dialog = class_set[i].dialog_list;
1656 if (dialog->in_use == False)
1657 class_set[i].dialog_list = dialog->next;
1660 prev_dialog = class_set[i].dialog_list;
1661 dialog = dialog->next;
1663 while (dialog->in_use == True)
1665 prev_dialog = dialog;
1666 dialog = dialog->next;
1669 prev_dialog->next = dialog->next;
1672 (*(class_set[i].class->destroy)) (dialog->dialog);
1673 XtFree ((char *) dialog);
1680 timerState = TIMER_IDLE_STATE;
1681 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
1683 (XtTimerCallbackProc)TimerEvent,
1690 /************************************************************************
1691 ************************************************************************
1693 * Externed Type to String Converters and writers
1695 ************************************************************************
1696 ************************************************************************/
1705 (void) sprintf (resourceBuf, "%d", *value);
1706 _DtStringToString( fd, &resourceBuf, out_buf );
1718 (void) sprintf (resourceBuf, "%d", *value);
1719 _DtStringToString( fd, &resourceBuf, out_buf );
1725 _DtPositionToString(
1731 (void) sprintf (resourceBuf, "%d", *value);
1732 _DtStringToString( fd, &resourceBuf, out_buf );
1738 _DtDimensionToString(
1744 (void) sprintf (resourceBuf, "%d", *value);
1745 _DtStringToString( fd, &resourceBuf, out_buf );
1763 _DtStringToString( fd, (char **)&buf, out_buf );
1768 _DtXmStringToString(
1774 char *out_value = NULL;
1778 out_value = (char *) _XmStringUngenerate(*value, XmFONTLIST_DEFAULT_TAG,
1779 XmCHARSET_TEXT, XmCHARSET_TEXT);
1780 if ( out_value != NULL)
1782 if (strlen (out_value) != 0)
1784 (void) write (fd, out_value, strlen (out_value));
1785 _DtStringToString( fd, &out_value, out_buf );
1787 XtFree ((char *) out_value);
1795 _DtXmStringTableToString(
1797 XmStringTable *value,
1802 char *out_value = NULL;
1803 Boolean first = True;
1805 if ((value != NULL) && (*value != NULL))
1808 while ((*value)[i] != NULL)
1810 out_value = (char *)_XmStringUngenerate((*value)[i],
1811 XmFONTLIST_DEFAULT_TAG,
1812 XmCHARSET_TEXT, XmCHARSET_TEXT);
1813 if ( out_value != NULL)
1817 (void) write (fd, out_buf, strlen (out_buf));
1821 (void) write (fd, ", ", strlen (", "));
1823 (void) write (fd, out_value, strlen (out_value));
1825 XtFree ((char *) out_value);
1833 (void) write (fd, "\n", strlen ("\n"));
1845 if (*value == NULL || strlen (*value) == 0)
1849 (void) write (fd, out_buf, strlen (out_buf));
1850 (void) write (fd, *value, strlen (*value));
1851 (void) write (fd, "\n", strlen ("\n"));
1858 * Choose a position for a popup window ("child") so that the main
1859 * window ("parent") is not obscured. The child will be positioned
1860 * to the right, below, left, or above the parent, depending on where
1861 * there is the most space.
1872 XmVendorShellExtObject vendorExt;
1873 XmWidgetExtData extData;
1874 int xOffset, yOffset;
1875 int pHeight, myHeight, sHeight;
1876 int pWidth, myWidth, sWidth;
1877 enum { posRight, posBelow, posLeft, posAbove } pos;
1880 /* get x, y offsets for the parent's window frame */
1881 extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
1884 vendorExt = (XmVendorShellExtObject)extData->widget;
1885 xOffset = vendorExt->vendor.xOffset;
1886 yOffset = vendorExt->vendor.yOffset;
1889 xOffset = yOffset = 0;
1891 /* get size/position of screen, parent, and widget */
1892 sHeight = HeightOfScreen(XtScreen(parent));;
1893 sWidth = WidthOfScreen(XtScreen(parent));
1894 pX = XtX(parent) - xOffset;
1895 pY = XtY(parent) - yOffset;
1896 pHeight = XtHeight(parent) + yOffset + xOffset;
1897 pWidth = XtWidth(parent) + 2*xOffset;
1898 myHeight = XtHeight(w) + yOffset + xOffset;
1899 myWidth = XtWidth(w) + 2*xOffset;
1902 * Determine how much space would be left if the child was positioned
1903 * to the right, below, left, or above the parent. Choose the child
1904 * positioning so that the maximum space is left.
1907 space = sWidth - (pX + pWidth + myWidth);
1909 if (sHeight - (pY + pHeight + myHeight) > space)
1912 space = sHeight - (pY + pHeight + myHeight);
1915 if (pX - myWidth > space)
1918 space = pX - myWidth;
1921 if (pY - myHeight > space)
1924 space = pY - myHeight;
1927 /* Given relative positioning, determine x, y coordinates for the child */
1932 *newX = pX + pWidth + 5;
1933 *newY = pY + (pHeight - myHeight)/2;
1937 *newX = pX + (pWidth - myWidth)/2;
1938 *newY = pY + pHeight + 5;
1942 *newX = pX - myWidth - 5;
1943 *newY = pY + (pHeight - myHeight)/2;
1947 *newX = pX + (pWidth - myWidth)/2;
1948 *newY = pY - myHeight - 5;
1953 * The above calculations may put the dialog offscreen so one
1954 * last check must be made. One way this can happen is if the
1955 * parent has been resized to fill almost the entire screen.
1956 * This can also happen if the parent has been maximized
1957 * and the window manager has its 'positionOnScreen' resource
1960 if ((*newX >= (sWidth - 10)) || (*newX < 0))
1961 *newX = sWidth - myWidth + 5;
1962 if ((*newY >= (sHeight - 10)) || (*newY < 0))
1963 *newY = (sHeight - myHeight) / 2;
1972 XtPointer client_data,
1973 XtPointer call_data )
1977 Position newX, newY;
1979 parent = (Widget)client_data;
1983 _DtChildPosition(w, parent, &newX, &newY);
1984 XtSetArg(args[0], XmNx, newX);
1985 XtSetArg(args[1], XmNy, newY);
1986 XtSetValues(w, args, 2);
1991 /************************************************************************
1994 * This functions is used to build an instance of a dialog with
1995 * the provided data but not display it. The functions and data
1996 * to be set back to the application upon change or close of the
1997 * dialog is also provided as parameters.
1999 ************************************************************************/
2006 DialogData *dialog_data,
2007 DialogChangedProc change_proc,
2008 XtPointer change_data,
2009 DialogClosedProc close_proc,
2010 XtPointer close_data,
2012 Boolean iconify_state,
2013 Boolean ignoreCache,
2015 XClassHint * classHints )
2020 DialogInstanceData * instance_data;
2023 Boolean doCenter = False;
2024 Boolean doParentRelativePositioning = False;
2025 int availableDialogCount;
2028 /* See if there is a cached, unused dialog of the correct type. */
2030 dialog_type = dialog_data->type;
2035 Dialog * availableDialog;
2037 availableDialog = class_set[dialog_type].dialog_list;
2038 availableDialogCount = 0;
2041 * In addition to looking for an available dialog in the cache to use,
2042 * we also want to count up the number of unused dialogs in the cache.
2043 * This lets us know it we need to restart the timer, to again build
2046 while (availableDialog != NULL)
2048 if (availableDialog->in_use == False)
2051 dialog = availableDialog;
2053 availableDialogCount++;
2055 availableDialog = availableDialog->next;
2061 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
2063 (*(class_set[dialog_type].class->create))
2064 (XtDisplay (encap_parent_shell), encap_parent_shell,
2065 &(dialog->dialog_widget), &dialog->dialog);
2067 /* Add the change and close callbacks into the dialog */
2069 if (class_set[dialog_type].class->install_change_callback)
2070 (*(class_set[dialog_type].class->install_change_callback))
2071 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
2073 if (class_set[dialog_type].class->install_close_callback)
2074 (*(class_set[dialog_type].class->install_close_callback))
2075 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
2077 dialog->next = class_set[dialog_type].dialog_list;
2078 class_set[dialog_type].dialog_list = dialog;
2082 * Set pointer to top dialog data in child of the shell.
2083 * This is needed to get help to work.
2085 if (top_rec == NULL)
2086 top_rec = dialog->dialog;
2087 XtSetArg(args[0], XmNuserData, top_rec);
2088 XtSetValues(dialog->dialog_widget, args, 1);
2090 /* Set the dialog structure fields to the parameter data. */
2092 dialog->in_use = True;
2093 dialog->dialog_data = dialog_data;
2094 dialog->change = change_proc;
2095 dialog->change_client_data = change_data;
2096 dialog->close = close_proc;
2097 dialog->close_client_data = close_data;
2099 /* If a special title has been specified, we need to set it now */
2102 XtSetArg(args[0], XmNtitle, title);
2103 XtSetValues(XtParent(dialog->dialog_widget), args, 1);
2108 /************************************************************************
2110 * _DtShowBuiltDialog
2111 * This functions is used to display an instance of a dialog which
2112 * has already been built with _DtBuildDialog.
2114 ************************************************************************/
2120 DialogData *dialog_data,
2122 Boolean iconify_state,
2123 XClassHint * classHints )
2128 DialogInstanceData * instance_data;
2131 Boolean doCenter = False;
2132 Boolean doParentRelativePositioning = False;
2133 int availableDialogCount;
2136 dialog_type = dialog_data->type;
2138 /* Find the dialog */
2139 dialog = class_set[dialog_data->type].dialog_list;
2140 while (dialog != NULL)
2142 if (dialog->dialog_data == dialog_data)
2145 dialog = dialog->next;
2148 /* Need to add the map callback in relation to the parent */
2149 if (class_set[dialog_type].class->map)
2152 * The map_parent parameter gives us the ability to position
2153 * the dialog relative to a window which is not the transientFor
2154 * parent. This is used for the audio preview dialog.
2156 if (map_parent == NULL)
2157 map_parent = parent;
2159 (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
2162 instance_data = (DialogInstanceData *) dialog_data->data;
2164 /* If this is a top level shell, get it realized */
2165 if (XtIsSubclass (XtParent (dialog->dialog_widget),
2166 applicationShellWidgetClass))
2168 if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
2170 if (instance_data->displayed == True)
2172 (void) sprintf (geometry, "=%dx%d+%d+%d",
2173 instance_data->width, instance_data->height,
2174 instance_data->x, instance_data->y);
2176 XtSetArg (args[0], XmNgeometry, geometry);
2177 XtSetValues (XtParent (dialog->dialog_widget), args, 1);
2179 else if ((instance_data->width != 0) && (instance_data->height != 0))
2182 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
2183 XtSetArg (args[n], XmNheight, instance_data->height); n++;
2184 XtSetValues (XtParent (dialog->dialog_widget), args, n);
2187 /* Toggle mappedWhenManaged to false */
2188 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
2189 XtRealizeWidget (XtParent(dialog->dialog_widget));
2191 /* Set the proper workspaces if needed */
2192 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2194 /* Set any application-specified class hints for the window */
2197 XSetClassHint(XtDisplay(dialog->dialog_widget),
2198 XtWindow(XtParent(dialog->dialog_widget)),
2202 /* Set the iconify state */
2203 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
2205 /* Map the window */
2206 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
2207 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
2208 XSync(XtDisplay(dialog->dialog_widget), False);
2213 if (instance_data->displayed == True)
2215 WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
2217 wm->wm.size_hints.flags |= USPosition;
2218 XtSetArg (args[0], XmNx, instance_data->x);
2219 XtSetArg (args[1], XmNy, instance_data->y);
2220 XtSetArg (args[2], XmNwidth, instance_data->width);
2221 XtSetArg (args[3], XmNheight, instance_data->height);
2222 XtSetValues (XtParent (dialog->dialog_widget), args, 4);
2224 else if ((instance_data->width != 0) && (instance_data->height != 0))
2227 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
2228 XtSetArg (args[n], XmNheight, instance_data->height); n++;
2229 XtSetValues (XtParent (dialog->dialog_widget), args, n);
2232 /* Set the proper workspaces if needed */
2233 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2235 /* Set any application-specified class hints for the window */
2238 XSetClassHint(XtDisplay(dialog->dialog_widget),
2239 XtWindow(XtParent(dialog->dialog_widget)),
2243 /* Set the iconify state */
2244 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
2246 /* Map the window */
2247 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
2252 if (instance_data->displayed == True)
2254 XtSetArg (args[0], XmNx, instance_data->x);
2255 XtSetArg (args[1], XmNy, instance_data->y);
2256 XtSetArg (args[2], XmNwidth, instance_data->width);
2257 XtSetArg (args[3], XmNheight, instance_data->height);
2258 XtSetArg (args[4], XmNdefaultPosition, False);
2259 XtSetValues (dialog->dialog_widget, args, 5);
2260 XtRealizeWidget (dialog->dialog_widget);
2264 XtSetArg (args[0], XmNdefaultPosition, False);
2265 XtSetValues (dialog->dialog_widget, args, 1);
2267 XtRealizeWidget (dialog->dialog_widget);
2271 /* Position relative to the parent dialog */
2273 * Must be done after the set_values call, since the dialog
2274 * may get forced to a different size.
2276 doParentRelativePositioning = True;
2280 /* Center in the display */
2282 * Must be done after the set_values call, since the dialog
2283 * may get forced to a different size.
2290 * Dialogs with no controlling parent window, need to have their
2291 * own workspace perperty set, if some workspaces have been requested.
2293 if ((parent == NULL) && workspaces)
2294 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2298 /* Set Values onto the dialog to set it to the correct data. */
2300 (*(class_set[dialog_data->type].class->set_values))
2301 (dialog->dialog, dialog_data->data);
2304 * These two adjustments MUST be done AFTER the dialog's SetValues()
2305 * procedure is called. This is due to the fact that the setvalues
2306 * may cause the dialog size to change, and since both of the following
2307 * positioning algorithms are dependent upon the dialog size, we want
2308 * to make sure that the correct size is used.
2312 XtSetArg (args[0], XmNx,
2313 (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
2314 dialog->dialog_widget->core.width) / (Dimension)2);
2315 XtSetArg (args[1], XmNy,
2316 (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
2317 dialog->dialog_widget->core.height) / (Dimension)2);
2318 XtSetValues (dialog->dialog_widget, args, 2);
2320 else if (doParentRelativePositioning)
2322 XtSetArg (args[0], XmNx,
2324 (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
2325 XtSetArg (args[1], XmNy,
2327 (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
2328 XtSetValues (XtParent(dialog->dialog_widget), args, 2);
2332 /* Fix up the transient-for windowing information so that */
2333 /* the window manager will shuffle and iconify as a group */
2337 if (XtIsRealized(parent))
2339 XSetTransientForHint (XtDisplay (parent),
2340 XtWindow (XtParent (dialog->dialog_widget)),
2346 if (!XtIsSubclass (XtParent (dialog->dialog_widget),
2347 applicationShellWidgetClass))
2349 XSetTransientForHint (XtDisplay (encap_parent_shell),
2350 XtWindow (XtParent (dialog->dialog_widget)),
2351 XtWindow (encap_parent_shell));
2356 /* Display the dialogs, application shells are displayed above. */
2358 if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
2359 applicationShellWidgetClass)))
2361 XtManageChild (dialog->dialog_widget);
2365 /* Set the dialog instance data to indicate that the dialog */
2368 ((DialogInstanceData *) (dialog_data->data))->displayed = True;
2371 /* Give the dialog a chance to set its focus widget, if necessary */
2373 if (class_set[dialog_data->type].class->set_focus)
2375 (*(class_set[dialog_data->type].class->set_focus))
2376 (dialog->dialog, dialog_data->data);
2383 DialogStructureNotifyHandler(
2385 XtPointer client_data,
2388 if( event->type == MapNotify )
2390 if( NumberOfDialogMapped == 0 )
2394 if( timerState == TIMER_STARTUP_STATE )
2395 timeOut = initialTimeoutLength;
2396 else if( timerState == TIMER_ACTIVE_STATE )
2397 timeOut = activeTimeoutLength;
2398 else if( timerState == TIMER_IDLE_STATE )
2399 timeOut = idleTimeoutLength;
2406 XtRemoveTimeOut( timerId );
2408 timerId = XtAppAddTimeOut( XtWidgetToApplicationContext( w ),
2410 (XtTimerCallbackProc)TimerEvent,
2414 ++NumberOfDialogMapped;
2416 else if( event->type == UnmapNotify )
2418 if( NumberOfDialogMapped )
2419 --NumberOfDialogMapped;
2421 if( NumberOfDialogMapped == 0 )
2425 XtRemoveTimeOut( timerId );
2435 XtPointer client_data,
2438 Dialog * dialog = (Dialog *) client_data;
2440 ChangeDirectoryToParent(dialog->change_client_data, directory);
2445 DialogData *dialog_data)
2447 Dialog *dialog,**headptr;
2448 headptr = &class_set[dialog_data->type].dialog_list;
2451 while (dialog != NULL)
2453 if (dialog->dialog_data == dialog_data)
2455 *headptr = dialog->next;
2456 XtFree((char *) dialog);
2459 headptr = &(dialog->next);