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 <Xm/XmPrivate.h> /* _XmStringUngenerate, _XmGetWidgetExtData */
87 #include <X11/ShellP.h>
88 #include <X11/Shell.h>
89 #include <X11/Xutil.h>
90 #include <X11/Xatom.h>
91 #include <X11/Intrinsic.h>
94 #include <Dt/DtNlUtils.h>
104 #define MAX_NAME_LIST_SIZE 25
105 #define MAX_RESOURCE_LENGTH 256
108 /* Cache array handling defines, structure, and global statics */
110 #define INCREMENT_SIZE 10
113 typedef struct _Dialog
116 Widget dialog_widget;
118 DialogData * dialog_data;
119 DialogChangedProc change;
120 XtPointer change_client_data;
121 DialogClosedProc close;
122 XtPointer close_client_data;
123 struct _Dialog * next;
130 Dialog * dialog_list;
132 Boolean destroyPopups;
135 extern int filter_dialog,mod_attr_dialog;
137 static ClassSet * class_set = NULL;
138 static int class_set_size = 0;
139 static int num_classes = 0;
140 static int NumberOfDialogMapped = 0;
142 static char * resourceBuf = NULL;
143 static int commonResourceCount = 5;
144 static DialogResource commonResources[] =
146 { "displayed", XmRBoolean, sizeof(Boolean),
147 XtOffset(DialogInstanceDataPtr, displayed),
148 (caddr_t) False, _DtBooleanToString },
150 { "x", XmRPosition, sizeof(Position),
151 XtOffset(DialogInstanceDataPtr, x),
152 (caddr_t) 0, _DtPositionToString},
154 { "y", XmRPosition, sizeof(Position),
155 XtOffset(DialogInstanceDataPtr, y),
156 (caddr_t) 0, _DtPositionToString },
158 { "width", XmRHorizontalDimension, sizeof(Dimension),
159 XtOffset(DialogInstanceDataPtr, width),
160 (caddr_t) 0, _DtDimensionToString },
162 { "height", XmRVerticalDimension, sizeof(Dimension),
163 XtOffset(DialogInstanceDataPtr, height),
164 (caddr_t) 0, _DtDimensionToString },
167 static Widget encap_parent_shell;
169 extern int file_mgr_dialog;
173 * initialTimeoutLength is used to specify how long to wait before initially
174 * kicking of the building of the dialog cache.
175 * activeTimeoutLength is used to specify how long to wait after adding
176 * a dialog to the cache, before adding the next dialog.
177 * idleTimeoutLength is used to specify how long to wait after all dialogs
178 * have been built, and the cache is full.
180 int initialTimeoutLength = 180000; /* 3 minutes, in milliseconds */
181 int activeTimeoutLength = 30000; /* 30 seconds, in milliseconds */
182 int idleTimeoutLength = 900000; /* 15 minutes, in milliseconds */
184 #define TIMER_STARTUP_STATE 0
185 #define TIMER_ACTIVE_STATE 1
186 #define TIMER_IDLE_STATE 2
188 static int timerState = TIMER_STARTUP_STATE;
189 static XtIntervalId timerId = 0;
193 * This global is used when positioning a dialog ABOVE (not below) its
194 * parent window. The 'y' position is defined to be the 'y' position
195 * of the parent, minus the 'height' of the dialog, minus the value
196 * assigned to 'topPositionOffset'; this allows the application to control
197 * how much, if any, of the parent's title bar is covered.
199 int topPositionOffset = 20;
202 /******** Static Function Declarations ********/
204 static void DialogStructureNotifyHandler(
206 XtPointer client_data,
208 static void SetIconifyState(
211 static void DataChangeCallback(
213 XtPointer client_data,
214 XtPointer call_data) ;
215 static void DataCloseCallback(
217 XtPointer client_data,
218 XtPointer call_data) ;
219 static void TimerEvent(
222 static void IntDialogGetResources(
223 XrmDatabase database,
225 DialogResource *resource,
228 XrmQuark stringQuark) ;
229 static void IntDialogPutResources(
234 DialogResource *resource) ;
236 /******** End Static Function Declarations ********/
240 /************************************************************************
242 * _DtInitializeEncapsulation
243 * This function is used to initialize the dialog encapsulation.
245 ************************************************************************/
248 _DtInitializeEncapsulation(
256 /* Create an application shell that will never be */
257 /* displayed that is used as a parent of all of the */
258 /* dialog created. */
260 encap_parent_shell = XtAppCreateShell (name, class,
261 applicationShellWidgetClass,
264 /* Supposedly required to be ICCCM complient */
265 XtSetArg(args[0], XmNmappedWhenManaged, False);
266 XtSetArg(args[1], XmNwidth, 1);
267 XtSetArg(args[2], XmNheight, 1);
268 XtSetValues(encap_parent_shell, args, 3);
269 XtRealizeWidget(encap_parent_shell);
271 /* Get a timer going that is used for auto creation of dialogs. */
273 timerState = TIMER_STARTUP_STATE;
274 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(encap_parent_shell),
275 initialTimeoutLength, (XtTimerCallbackProc)
276 TimerEvent, (caddr_t) encap_parent_shell);
278 /* Allocate a buffer for writing out resource values */
279 resourceBuf = XtMalloc(20);
285 /************************************************************************
288 * This function is used to register a dialog class with the
289 * encapsulation functions.
291 ************************************************************************/
295 DialogClass *dialog_class,
297 Boolean destroyPopups )
300 /* Allocate additional dialog cache space if needed */
302 if (num_classes == class_set_size)
304 class_set_size += INCREMENT_SIZE;
306 (ClassSet *) XtRealloc ((char *)class_set,
307 sizeof (ClassSet) * class_set_size);
310 class_set[num_classes].class = dialog_class;
311 class_set[num_classes].dialog_list = NULL;
312 class_set[num_classes].cache = cache;
313 class_set[num_classes].destroyPopups = destroyPopups;
317 return (num_classes - 1);
323 /************************************************************************
326 * This function is used to get a structure containing the
327 * current dialog data for a particular dialog instance.
329 ************************************************************************/
333 DialogData *dialog_data )
337 DialogData * new_data;
339 dialog = class_set[dialog_data->type].dialog_list;
341 while (dialog != NULL)
343 if (dialog->dialog_data == dialog_data)
345 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
347 new_data->type = dialog->dialog_data->type;
348 new_data->data = NULL;
349 if (class_set[new_data->type].class->get_values)
352 (*(class_set[new_data->type].class->get_values)) (dialog->dialog);
358 dialog = dialog->next;
367 /************************************************************************
369 * _DtGetDefaultDialogData
370 * This function is used to get a structure containing the
371 * default data for a particular dialog type.
373 ************************************************************************/
376 _DtGetDefaultDialogData(
381 DialogData * dialog_data;
383 dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
385 dialog_data->type = dialog_type;
386 dialog_data->data = (*(class_set[dialog_type].class->get_default_values))();
388 return (dialog_data);
394 /************************************************************************
396 * _DtGetResourceDialogData
397 * This function is used to get a structure containing the
398 * data for a particular dialog type from a resource data base.
400 ************************************************************************/
403 _DtGetResourceDialogData(
405 XrmDatabase data_base,
409 DialogData * dialog_data;
411 dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
413 dialog_data->type = dialog_type;
414 dialog_data->data = (*(class_set[dialog_type].class->get_resource_values))
415 (data_base, name_list);
417 return (dialog_data);
423 /************************************************************************
426 * This functions is used to display an instance of a dialog with
427 * the provided data. The functions and data to be set back to
428 * the application upon change or close of the dialog is also
429 * provided as parameters.
431 ************************************************************************/
437 DialogData *dialog_data,
438 DialogChangedProc change_proc,
439 XtPointer change_data,
440 DialogClosedProc close_proc,
441 XtPointer close_data,
443 Boolean iconify_state,
446 XClassHint * classHints )
451 DialogInstanceData * instance_data;
454 Boolean doCenter = False;
455 Boolean doParentRelativePositioning = False;
456 int availableDialogCount;
459 /* See if there is a cached, unused dialog of the correct type. */
461 dialog_type = dialog_data->type;
466 Dialog * availableDialog;
468 availableDialog = class_set[dialog_type].dialog_list;
469 availableDialogCount = 0;
472 * In addition to looking for an available dialog in the cache to use,
473 * we also want to count up the number of unused dialogs in the cache.
474 * This lets us know it we need to restart the timer, to again build
477 while (availableDialog != NULL)
479 if (availableDialog->in_use == False)
482 dialog = availableDialog;
484 availableDialogCount++;
486 availableDialog = availableDialog->next;
492 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
494 (*(class_set[dialog_type].class->create))
495 (XtDisplay (encap_parent_shell), encap_parent_shell,
496 &(dialog->dialog_widget), &dialog->dialog);
498 /* if this is a File Manager view we want to update the headers
499 * (i.e icon_path, current_directory, status_line), now so that they
500 * don't get managed up front. This is to make the Application
501 * Manager (toolbox) happy.
503 if(dialog_type == file_mgr_dialog)
504 UpdateHeaders(dialog->dialog, dialog_data->data, False);
506 /* Add the change and close callbacks into the dialog */
508 if (class_set[dialog_type].class->install_change_callback)
509 (*(class_set[dialog_type].class->install_change_callback))
510 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
512 if (class_set[dialog_type].class->install_close_callback)
513 (*(class_set[dialog_type].class->install_close_callback))
514 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
516 dialog->next = class_set[dialog_type].dialog_list;
517 class_set[dialog_type].dialog_list = dialog;
521 if(dialog_type == mod_attr_dialog)
523 ModAttrRec *mr = (ModAttrRec *)dialog->dialog;
524 ResetFlag(NULL,mr->ok);
525 ResetFlag(NULL,mr->cancel);
527 else if(dialog_type == filter_dialog)
529 FilterRec *fr = (FilterRec *)dialog->dialog;
530 ResetFlag(NULL,fr->ok);
531 ResetFlag(NULL,fr->close);
535 if ((!ignoreCache) && (class_set[dialog_type].cache) &&
536 (availableDialogCount < 1) && (timerState == TIMER_IDLE_STATE))
539 * We need to reset the cache building timer, so that it gets kicked
540 * off quickly, instead of after the longer idle delay.
543 XtRemoveTimeOut(timerId);
544 timerState = TIMER_ACTIVE_STATE;
545 timerId = XtAppAddTimeOut(
546 XtWidgetToApplicationContext(encap_parent_shell),
547 activeTimeoutLength, (XtTimerCallbackProc) TimerEvent,
548 (XtPointer) encap_parent_shell);
552 * Set pointer to top dialog data in child of the shell.
553 * This is needed to get help to work.
556 top_rec = dialog->dialog;
557 XtSetArg(args[0], XmNuserData, top_rec);
558 XtSetValues(dialog->dialog_widget, args, 1);
560 /* Need to add the map callback in relation to the parent */
561 if (class_set[dialog_type].class->map)
564 * The map_parent parameter gives us the ability to position
565 * the dialog relative to a window which is not the transientFor
566 * parent. This is used for the audio preview dialog.
568 if (map_parent == NULL)
571 (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
575 /* Set the dialog structure fields to the parameter data. */
577 dialog->in_use = True;
578 dialog->dialog_data = dialog_data;
579 dialog->change = change_proc;
580 dialog->change_client_data = change_data;
581 dialog->close = close_proc;
582 dialog->close_client_data = close_data;
585 instance_data = (DialogInstanceData *) dialog_data->data;
587 /* If a special title has been specified, we need to set it now */
590 XtSetArg(args[0], XmNtitle, title);
591 XtSetValues(XtParent(dialog->dialog_widget), args, 1);
594 /* If this is a top level shell, get it realized */
596 if (XtIsSubclass (XtParent (dialog->dialog_widget),
597 applicationShellWidgetClass))
599 if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
601 if (instance_data->displayed == True)
603 (void) sprintf (geometry, "=%dx%d+%d+%d",
604 instance_data->width, instance_data->height,
605 instance_data->x, instance_data->y);
607 XtSetArg (args[0], XmNgeometry, geometry);
608 XtSetValues (XtParent (dialog->dialog_widget), args, 1);
610 else if ((instance_data->width != 0) && (instance_data->height != 0))
613 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
614 XtSetArg (args[n], XmNheight, instance_data->height); n++;
615 XtSetValues (XtParent (dialog->dialog_widget), args, n);
618 /* Toggle mappedWhenManaged to false */
619 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
620 XtRealizeWidget (XtParent(dialog->dialog_widget));
622 /* Set the proper workspaces if needed */
623 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
625 /* Set any application-specified class hints for the window */
628 XSetClassHint(XtDisplay(dialog->dialog_widget),
629 XtWindow(XtParent(dialog->dialog_widget)),
633 /* Set the iconify state */
634 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
637 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
638 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
639 XSync(XtDisplay(dialog->dialog_widget), False);
644 if (instance_data->displayed == True)
646 WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
648 wm->wm.size_hints.flags |= USPosition;
649 XtSetArg (args[0], XmNx, instance_data->x);
650 XtSetArg (args[1], XmNy, instance_data->y);
651 XtSetArg (args[2], XmNwidth, instance_data->width);
652 XtSetArg (args[3], XmNheight, instance_data->height);
653 XtSetValues (XtParent (dialog->dialog_widget), args, 4);
655 else if ((instance_data->width != 0) && (instance_data->height != 0))
658 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
659 XtSetArg (args[n], XmNheight, instance_data->height); n++;
660 XtSetValues (XtParent (dialog->dialog_widget), args, n);
663 /* Set the proper workspaces if needed */
664 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
666 /* Set any application-specified class hints for the window */
669 XSetClassHint(XtDisplay(dialog->dialog_widget),
670 XtWindow(XtParent(dialog->dialog_widget)),
674 /* Set the iconify state */
675 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
678 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
683 if (instance_data->displayed == True)
685 XtSetArg (args[0], XmNx, instance_data->x);
686 XtSetArg (args[1], XmNy, instance_data->y);
687 XtSetArg (args[2], XmNwidth, instance_data->width);
688 XtSetArg (args[3], XmNheight, instance_data->height);
689 XtSetArg (args[4], XmNdefaultPosition, False);
690 XtSetValues (dialog->dialog_widget, args, 5);
691 XtRealizeWidget (dialog->dialog_widget);
695 XtSetArg (args[0], XmNdefaultPosition, False);
696 XtSetValues (dialog->dialog_widget, args, 1);
698 XtRealizeWidget (dialog->dialog_widget);
702 /* Position relative to the parent dialog */
704 * Must be done after the set_values call, since the dialog
705 * may get forced to a different size.
707 doParentRelativePositioning = True;
711 /* Center in the display */
713 * Must be done after the set_values call, since the dialog
714 * may get forced to a different size.
721 * Dialogs with no controlling parent window, need to have their
722 * own workspace perperty set, if some workspaces have been requested.
724 if ((parent == NULL) && workspaces)
725 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
729 /* Set Values onto the dialog to set it to the correct data. */
731 (*(class_set[dialog_data->type].class->set_values))
732 (dialog->dialog, dialog_data->data);
735 * These two adjustments MUST be done AFTER the dialog's SetValues()
736 * procedure is called. This is due to the fact that the setvalues
737 * may cause the dialog size to change, and since both of the following
738 * positioning algorithms are dependent upon the dialog size, we want
739 * to make sure that the correct size is used.
743 XtSetArg (args[0], XmNx,
744 (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
745 dialog->dialog_widget->core.width) / (Dimension)2);
746 XtSetArg (args[1], XmNy,
747 (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
748 dialog->dialog_widget->core.height) / (Dimension)2);
749 XtSetValues (dialog->dialog_widget, args, 2);
751 else if (doParentRelativePositioning)
753 XtSetArg (args[0], XmNx,
755 (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
756 XtSetArg (args[1], XmNy,
758 (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
759 XtSetValues (XtParent(dialog->dialog_widget), args, 2);
763 /* Fix up the transient-for windowing information so that */
764 /* the window manager will shuffle and iconify as a group */
768 if (XtIsRealized(parent))
770 XSetTransientForHint (XtDisplay (parent),
771 XtWindow (XtParent (dialog->dialog_widget)),
777 if (!XtIsSubclass (XtParent (dialog->dialog_widget),
778 applicationShellWidgetClass))
780 XSetTransientForHint (XtDisplay (encap_parent_shell),
781 XtWindow (XtParent (dialog->dialog_widget)),
782 XtWindow (encap_parent_shell));
787 /* Display the dialogs, application shells are displayed above. */
789 if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
790 applicationShellWidgetClass)))
792 XtManageChild (dialog->dialog_widget);
796 /* Set the dialog instance data to indicate that the dialog */
799 ((DialogInstanceData *) (dialog_data->data))->displayed = True;
802 /* Give the dialog a chance to set its focus widget, if necessary */
804 if (class_set[dialog_data->type].class->set_focus)
806 (*(class_set[dialog_data->type].class->set_focus))
807 (dialog->dialog, dialog_data->data);
812 XtAddEventHandler( XtParent( dialog->dialog_widget ),
815 (XtEventHandler)DialogStructureNotifyHandler,
822 /************************************************************************
825 * This function is used to undisplay a dialog.
827 ************************************************************************/
831 DialogData *dialog_data,
832 Boolean call_callbacks )
836 DialogData * new_data;
841 /* Find the dialog and then hide it. */
843 dialog = class_set[dialog_data->type].dialog_list;
845 while (dialog != NULL)
847 if ((dialog->dialog_data &&
848 dialog->dialog_data == dialog_data) && dialog->in_use == True)
852 /* Free up any dialogs attached to the dialog widget */
854 if(class_set[dialog_data->type].destroyPopups)
856 core = (CorePart *) (XtParent (dialog->dialog_widget));
858 for (i = core->num_popups - 1; i >= 0; i--)
859 XtDestroyWidget (core->popup_list[i]);
863 /* Get the dialog down, invoke the close callbacks, and */
864 /* take it out of use. */
866 if (XtIsSubclass (XtParent (dialog->dialog_widget),
867 applicationShellWidgetClass))
869 ShellWidget shell_widget;
872 * If we had been iconified, then our popped_up flag will
873 * have been cleared by the vendor shell. When we call
874 * XtPopdown(), it will see that we are no longer popped
875 * up, and will not notify the window manager that our
876 * icon should be removed; this can cause a subsequent
877 * core dump if the user later tries to deiconify the window.
878 * This fix should not be necessary once the toolkit is
879 * fixed to properly track the shell's state.
881 shell_widget = (ShellWidget) XtParent(dialog->dialog_widget);
882 shell_widget->shell.popped_up = True;
884 XtPopdown ((Widget)shell_widget);
889 * The following is for the condition described above. However,
890 * for a dialog shell, what happens it that the 'managed' flag
891 * was set to 'False' when the windows were iconified (apparently
892 * by the dialog shell), and when we tell the intrinsics to
893 * really unmanage the child, it thinks it already has, so
894 * nothing happens; as a result, the dialog shell is left with
895 * its 'popped_up' flag set to 'True'. The next time we try
896 * to post this dialog, the intrinsics think that it is already
897 * up, so it does nothing.
899 dialog->dialog_widget->core.managed = True;
900 XtUnmanageChild (dialog->dialog_widget);
904 /* Set the dialog data to hidden */
906 ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
909 if (call_callbacks && dialog->close)
911 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
913 new_data->type = dialog->dialog_data->type;
914 new_data->data = NULL;
915 if (class_set[new_data->type].class->get_values)
918 (*(class_set[new_data->type].class->get_values))(dialog->dialog);
921 dialog->in_use = False;
923 ((DialogInstanceData *) (new_data->data))->displayed = False;
926 (dialog->close_client_data, dialog->dialog_data, new_data);
930 dialog->in_use = False;
931 ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
937 dialog = dialog->next;
944 /************************************************************************
947 * This function is used return the shell widget of a dialog that
948 * is currently displayed.
950 ************************************************************************/
954 DialogData *dialog_data )
960 /* Find the dialog and then return the shell. */
962 dialog = class_set[dialog_data->type].dialog_list;
964 while (dialog != NULL)
966 if (dialog->dialog_data == dialog_data)
967 return (dialog->dialog_widget);
969 dialog = dialog->next;
978 /************************************************************************
980 * _DtGetDialogInstance
981 * This function is used return the dialog instance structure
982 * of a currently in use dialog.
984 ************************************************************************/
987 _DtGetDialogInstance(
988 DialogData *dialog_data )
994 /* Find the dialog and then return the instance */
996 dialog = class_set[dialog_data->type].dialog_list;
998 while (dialog != NULL)
1000 if (dialog->dialog_data && dialog->dialog_data == dialog_data)
1001 return (dialog->dialog);
1003 dialog = dialog->next;
1012 /************************************************************************
1014 * _DtGetInstanceData
1015 * This function is used return the dialog data structure contained
1016 * within the cache structure referenced by instance.
1018 ************************************************************************/
1022 XtPointer instance )
1029 /* Find the dialog and then return the instance */
1031 for (i = 0; i < num_classes; i++)
1033 dialog = class_set[i].dialog_list;
1035 while (dialog != NULL)
1037 if (dialog->dialog == instance && dialog->in_use == True)
1038 return (dialog->dialog_data);
1040 dialog = dialog->next;
1050 /************************************************************************
1052 * _DtIsDialogShowing
1053 * This function is used return a boolean indicating whether the
1054 * a dialog is displayed which contains the dialog data.
1055 * of a currently in use dialog.
1057 ************************************************************************/
1061 DialogData *dialog_data )
1067 /* Find the dialog and then return the instance */
1069 dialog = class_set[dialog_data->type].dialog_list;
1071 while (dialog != NULL)
1073 if (dialog->in_use && dialog->dialog_data == dialog_data)
1076 dialog = dialog->next;
1085 /************************************************************************
1087 * _DtWriteDialogData
1088 * This function is used to write, as resources, the data
1089 * for a dialog contained in dialog_data to the open file fd.
1091 ************************************************************************/
1095 DialogData *dialog_data,
1100 if (dialog_data != NULL)
1101 (*(class_set[dialog_data->type].class->write_resource_values))
1102 (dialog_data, fd, name_list);
1108 /************************************************************************
1111 * This function is used to free up the data space allocated
1114 ************************************************************************/
1118 DialogData *dialog_data )
1121 if (dialog_data != NULL)
1123 (*(class_set[dialog_data->type].class->free_values)) (dialog_data->data);
1124 XtFree ((char *) dialog_data);
1132 /************************************************************************
1134 * _DtDialogGetResources
1135 * This function accesses data_base to extract the resource set
1136 * described by the resoruces array. Resources values are
1137 * converted to the proper type and defaults are used if not
1138 * data is found in the resource data base.
1140 ************************************************************************/
1143 _DtDialogGetResources(
1144 XrmDatabase database,
1148 DialogResource *resources,
1149 int resource_count )
1152 XrmName xrmName[MAX_NAME_LIST_SIZE];
1153 XrmQuark stringQuark;
1157 /* Build the quarkified name list from name_list and dialog_name */
1158 /* provided by the calling procedure. */
1161 if (name_list != NULL)
1163 while (name_list[nameCount] != NULL)
1165 xrmName[nameCount] = XrmStringToQuark (name_list[nameCount]);
1171 xrmName[nameCount] = XrmStringToQuark (dialog_name);
1175 xrmName[nameCount + 2] = 0;
1176 stringQuark = XrmStringToQuark (XmRString);
1179 /* Load the common dialog size/position resources */
1180 for (i = 0; i < resource_count; i++)
1182 IntDialogGetResources(database, base, resources + i, xrmName, nameCount,
1187 * Load the dialog specific resources. If no value found, use the default.
1189 for (i = 0; i < commonResourceCount; i++)
1191 IntDialogGetResources(database, base, commonResources + i, xrmName,
1192 nameCount, stringQuark);
1198 * This internal function does the real work of loading a single resource
1199 * value. If the value is not found in the resource database, then the
1200 * specified default value is used.
1204 IntDialogGetResources(
1205 XrmDatabase database,
1207 DialogResource *resource,
1210 XrmQuark stringQuark )
1213 XrmRepresentation repType;
1215 XrmValue convertedValue;
1222 xrmName[nameCount + 1] = XrmStringToQuark (resource->name);
1224 if (XrmQGetResource (database, xrmName, xrmName, &repType, &value))
1226 if (repType == stringQuark)
1227 if (strcmp (resource->type, XmRString) != 0)
1229 XtConvert (encap_parent_shell, XmRString, &value,
1230 resource->type, &convertedValue);
1234 *((char **)(base + resource->offset)) = (char *)value.addr;
1238 convertedValue.addr = NULL;
1242 convertedValue.addr = NULL;
1245 /* Set the converted value address pointer and value to */
1246 /* the proper default value if the addr is NULL. */
1248 if (convertedValue.addr == NULL)
1250 if (resource->size == sizeof(char))
1252 charVal = (char)(XtArgVal)resource->default_value;
1253 convertedValue.addr = (caddr_t) &charVal;
1255 else if (resource->size == sizeof(short))
1257 shortVal = (short)(XtArgVal)resource->default_value;
1258 convertedValue.addr = (caddr_t) &shortVal;
1260 else if (resource->size == sizeof(int))
1262 intVal = (int)(XtArgVal)resource->default_value;
1263 convertedValue.addr = (caddr_t) &intVal;
1267 longVal = (long)(XtArgVal)resource->default_value;
1268 convertedValue.addr = (caddr_t) &longVal;
1273 /* Stuff the converted value into the calling functions */
1274 /* structure according to the size of the piece of data. */
1276 if (resource->size == sizeof(char))
1277 *((char *)(base + resource->offset)) = *((char *)convertedValue.addr);
1278 else if (resource->size == sizeof(short))
1279 *((short *)(base + resource->offset))= *((short *)convertedValue.addr);
1280 else if (resource->size == sizeof(int))
1281 *((int *)(base + resource->offset))= *((int *)convertedValue.addr);
1283 *((long *)(base + resource->offset)) = *((long *)convertedValue.addr);
1289 /************************************************************************
1291 * _DtDialogPutResources
1292 * This function writes a resource set to a file.
1294 ************************************************************************/
1297 _DtDialogPutResources(
1302 DialogResource *resources,
1307 DialogInstanceData * dialogInstanceData;
1310 * Write out the common dialog size/position resources, only if the
1311 * dialog is currently displayed.
1313 dialogInstanceData = (DialogInstanceData *)base;
1314 if (dialogInstanceData->displayed)
1316 for (i = 0; i < commonResourceCount; i++)
1318 IntDialogPutResources(fd, nameList, dialogName, base,
1319 commonResources + i);
1324 * Loop through the dialog specific resources, write the name list and
1327 for (i = 0; i < resourceCount; i++)
1328 IntDialogPutResources( fd, nameList, dialogName, base, resources + i);
1333 * This internal function does the real work involved in writing a single
1334 * resource out to a session file.
1338 IntDialogPutResources(
1343 DialogResource *resource )
1346 static char outBuf[MAX_RESOURCE_LENGTH];
1351 (void) strcat (outBuf, "*");
1354 if (nameList != NULL)
1356 while (nameList[nameCount] != NULL)
1358 (void) strcat (outBuf, nameList[nameCount]);
1359 (void) strcat (outBuf, ".");
1364 if (dialogName != NULL)
1366 (void) strcat (outBuf, dialogName);
1367 (void) strcat (outBuf, ".");
1370 (void) strcat (outBuf, resource->name);
1371 (void) strcat (outBuf, ": ");
1373 (*(resource->write_resource))
1374 (fd, (XtPointer) (base + resource->offset), outBuf);
1379 /************************************************************************
1380 ************************************************************************
1382 * Internal functions
1384 ************************************************************************
1385 ************************************************************************/
1388 /************************************************************************
1390 * _DtEncapSetWorkSpaceHints
1391 * This function sets a given shell to a given set(s) of
1394 ************************************************************************/
1396 _DtEncapSetWorkSpaceHints(
1402 Atom * workspace_atoms = NULL;
1403 int num_workspaces=0;
1409 ptr = DtStrchr (workspaces, '*');
1411 if (ptr != NULL) *ptr = '\0';
1413 workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
1414 sizeof (Atom) * (num_workspaces + 1));
1416 workspace_atoms[num_workspaces] =
1417 XmInternAtom (XtDisplay(shell), workspaces, True);
1424 workspaces = ptr + 1;
1426 } while (ptr != NULL);
1428 DtWsmSetWorkspacesOccupied (XtDisplay(shell), XtWindow (shell), workspace_atoms,
1431 XtFree ((char *) workspace_atoms);
1432 workspace_atoms = NULL;
1438 Screen *currentScreen;
1440 char *workspace_name;
1443 * Since no specific workspaces were specified, we will force the
1444 * dialog to the current workspace.
1446 screen = XDefaultScreen(XtDisplay(shell));
1447 currentScreen = XScreenOfDisplay(XtDisplay(shell), screen);
1448 rootWindow = RootWindowOfScreen(currentScreen);
1450 if(DtWsmGetCurrentWorkspace(XtDisplay(shell), rootWindow, &pCurrent) ==
1453 DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell), &pCurrent, 1);
1458 /************************************************************************
1461 * This function sets a given shell to a given iconify state.
1462 * (e.g. Mapped or iconified)
1464 ************************************************************************/
1476 /* add the iconify hint to the current shell */
1477 XtSetArg(args[0], XmNinitialState, IconicState);
1478 XtSetValues(shell, args, 1);
1482 /* Remove the iconify hint from the current shell */
1483 wmhints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
1484 wmhints->flags |= IconWindowHint;
1485 wmhints->initial_state = NormalState;
1486 XSetWMHints(XtDisplay(shell), XtWindow(shell), wmhints);
1491 /************************************************************************
1493 * DataChangeCallback
1494 * This callback is invoked from a dialog upon an action on the
1495 * dialog that means that the data within the dialog has been
1498 ************************************************************************/
1504 XtPointer client_data,
1505 XtPointer call_data )
1508 Dialog * dialog = (Dialog *) client_data;
1509 DialogData * new_data;
1511 new_data = (DialogData *) XtMalloc (sizeof (DialogData));
1513 new_data->type = dialog->dialog_data->type;
1514 new_data->data = NULL;
1515 if (class_set[new_data->type].class->get_values)
1517 new_data->data = (*(class_set[new_data->type].class->get_values))
1523 (dialog->change_client_data, dialog->dialog_data, new_data, call_data);
1529 /************************************************************************
1532 * This callback is invoked from a dialog upon an action on the
1533 * dialog that means the dialog has been closed.
1535 ************************************************************************/
1541 XtPointer client_data,
1542 XtPointer call_data )
1546 Dialog * dialog = (Dialog *) client_data;
1548 if(RecheckFlag(NULL,widget)) /* cancel flag already set, just return */
1550 _DtHideDialog (dialog->dialog_data, True);
1556 /************************************************************************
1559 * This action function is called upon the encapsulations
1560 * timeout going off. Its function is to precreate and destroy
1563 ************************************************************************/
1574 Dialog * prev_dialog;
1578 /* First pass through the dialog set to see if any */
1579 /* need to be created. This is based on having 0 */
1580 /* not in use dialogs of each type. */
1582 for (i = 0; i < num_classes; i++)
1584 dialog = class_set[i].dialog_list;
1586 /* Only attempt to cache dialogs requesting this feature */
1587 if (!class_set[i].cache)
1590 while (dialog != NULL)
1591 if (dialog->in_use == False)
1594 dialog = dialog->next;
1598 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
1600 (*(class_set[i].class->create))
1601 (XtDisplay (encap_parent_shell), encap_parent_shell,
1602 &(dialog->dialog_widget), &dialog->dialog);
1605 /* Add the change and close callbacks into the dialog */
1607 if (class_set[i].class->install_change_callback)
1608 (*(class_set[i].class->install_change_callback))
1609 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
1611 if (class_set[i].class->install_close_callback)
1612 (*(class_set[i].class->install_close_callback))
1613 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
1616 dialog->next = class_set[i].dialog_list;
1617 class_set[i].dialog_list = dialog;
1619 dialog->in_use = False;
1621 timerState = TIMER_ACTIVE_STATE;
1622 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
1623 activeTimeoutLength,
1624 (XtTimerCallbackProc) TimerEvent,
1625 (XtPointer) widget);
1632 /* Pass through the dialog set to see if any need to be destroyed */
1633 /* This is based on having more than 1 not in use dialog of a type. */
1635 for (i = 0; i < num_classes; i++)
1637 dialog = class_set[i].dialog_list;
1640 while (dialog != NULL)
1642 if (dialog->in_use == False)
1645 dialog = dialog->next;
1650 dialog = class_set[i].dialog_list;
1652 if (dialog->in_use == False)
1653 class_set[i].dialog_list = dialog->next;
1656 prev_dialog = class_set[i].dialog_list;
1657 dialog = dialog->next;
1659 while (dialog->in_use == True)
1661 prev_dialog = dialog;
1662 dialog = dialog->next;
1665 prev_dialog->next = dialog->next;
1668 (*(class_set[i].class->destroy)) (dialog->dialog);
1669 XtFree ((char *) dialog);
1676 timerState = TIMER_IDLE_STATE;
1677 timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
1679 (XtTimerCallbackProc)TimerEvent,
1686 /************************************************************************
1687 ************************************************************************
1689 * Externed Type to String Converters and writers
1691 ************************************************************************
1692 ************************************************************************/
1701 (void) sprintf (resourceBuf, "%d", *value);
1702 _DtStringToString( fd, &resourceBuf, out_buf );
1714 (void) sprintf (resourceBuf, "%d", *value);
1715 _DtStringToString( fd, &resourceBuf, out_buf );
1721 _DtPositionToString(
1727 (void) sprintf (resourceBuf, "%d", *value);
1728 _DtStringToString( fd, &resourceBuf, out_buf );
1734 _DtDimensionToString(
1740 (void) sprintf (resourceBuf, "%d", *value);
1741 _DtStringToString( fd, &resourceBuf, out_buf );
1759 _DtStringToString( fd, (char **)&buf, out_buf );
1764 _DtXmStringToString(
1770 char *out_value = NULL;
1774 out_value = (char *) _XmStringUngenerate(*value, XmFONTLIST_DEFAULT_TAG,
1775 XmCHARSET_TEXT, XmCHARSET_TEXT);
1776 if ( out_value != NULL)
1778 if (strlen (out_value) != 0)
1780 (void) write (fd, out_value, strlen (out_value));
1781 _DtStringToString( fd, &out_value, out_buf );
1783 XtFree ((char *) out_value);
1791 _DtXmStringTableToString(
1793 XmStringTable *value,
1798 char *out_value = NULL;
1799 Boolean first = True;
1801 if ((value != NULL) && (*value != NULL))
1804 while ((*value)[i] != NULL)
1806 out_value = (char *)_XmStringUngenerate((*value)[i],
1807 XmFONTLIST_DEFAULT_TAG,
1808 XmCHARSET_TEXT, XmCHARSET_TEXT);
1809 if ( out_value != NULL)
1813 (void) write (fd, out_buf, strlen (out_buf));
1817 (void) write (fd, ", ", strlen (", "));
1819 (void) write (fd, out_value, strlen (out_value));
1821 XtFree ((char *) out_value);
1829 (void) write (fd, "\n", strlen ("\n"));
1841 if (*value == NULL || strlen (*value) == 0)
1845 (void) write (fd, out_buf, strlen (out_buf));
1846 (void) write (fd, *value, strlen (*value));
1847 (void) write (fd, "\n", strlen ("\n"));
1854 * Choose a position for a popup window ("child") so that the main
1855 * window ("parent") is not obscured. The child will be positioned
1856 * to the right, below, left, or above the parent, depending on where
1857 * there is the most space.
1868 XmVendorShellExtObject vendorExt;
1869 XmWidgetExtData extData;
1870 int xOffset, yOffset;
1871 int pHeight, myHeight, sHeight;
1872 int pWidth, myWidth, sWidth;
1873 enum { posRight, posBelow, posLeft, posAbove } pos;
1876 /* get x, y offsets for the parent's window frame */
1877 extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
1880 vendorExt = (XmVendorShellExtObject)extData->widget;
1881 xOffset = vendorExt->vendor.xOffset;
1882 yOffset = vendorExt->vendor.yOffset;
1885 xOffset = yOffset = 0;
1887 /* get size/position of screen, parent, and widget */
1888 sHeight = HeightOfScreen(XtScreen(parent));;
1889 sWidth = WidthOfScreen(XtScreen(parent));
1890 pX = XtX(parent) - xOffset;
1891 pY = XtY(parent) - yOffset;
1892 pHeight = XtHeight(parent) + yOffset + xOffset;
1893 pWidth = XtWidth(parent) + 2*xOffset;
1894 myHeight = XtHeight(w) + yOffset + xOffset;
1895 myWidth = XtWidth(w) + 2*xOffset;
1898 * Determine how much space would be left if the child was positioned
1899 * to the right, below, left, or above the parent. Choose the child
1900 * positioning so that the maximum space is left.
1903 space = sWidth - (pX + pWidth + myWidth);
1905 if (sHeight - (pY + pHeight + myHeight) > space)
1908 space = sHeight - (pY + pHeight + myHeight);
1911 if (pX - myWidth > space)
1914 space = pX - myWidth;
1917 if (pY - myHeight > space)
1920 space = pY - myHeight;
1923 /* Given relative positioning, determine x, y coordinates for the child */
1928 *newX = pX + pWidth + 5;
1929 *newY = pY + (pHeight - myHeight)/2;
1933 *newX = pX + (pWidth - myWidth)/2;
1934 *newY = pY + pHeight + 5;
1938 *newX = pX - myWidth - 5;
1939 *newY = pY + (pHeight - myHeight)/2;
1943 *newX = pX + (pWidth - myWidth)/2;
1944 *newY = pY - myHeight - 5;
1949 * The above calculations may put the dialog offscreen so one
1950 * last check must be made. One way this can happen is if the
1951 * parent has been resized to fill almost the entire screen.
1952 * This can also happen if the parent has been maximized
1953 * and the window manager has its 'positionOnScreen' resource
1956 if ((*newX >= (sWidth - 10)) || (*newX < 0))
1957 *newX = sWidth - myWidth + 5;
1958 if ((*newY >= (sHeight - 10)) || (*newY < 0))
1959 *newY = (sHeight - myHeight) / 2;
1968 XtPointer client_data,
1969 XtPointer call_data )
1973 Position newX, newY;
1975 parent = (Widget)client_data;
1979 _DtChildPosition(w, parent, &newX, &newY);
1980 XtSetArg(args[0], XmNx, newX);
1981 XtSetArg(args[1], XmNy, newY);
1982 XtSetValues(w, args, 2);
1987 /************************************************************************
1990 * This functions is used to build an instance of a dialog with
1991 * the provided data but not display it. The functions and data
1992 * to be set back to the application upon change or close of the
1993 * dialog is also provided as parameters.
1995 ************************************************************************/
2002 DialogData *dialog_data,
2003 DialogChangedProc change_proc,
2004 XtPointer change_data,
2005 DialogClosedProc close_proc,
2006 XtPointer close_data,
2008 Boolean iconify_state,
2009 Boolean ignoreCache,
2011 XClassHint * classHints )
2016 DialogInstanceData * instance_data;
2019 Boolean doCenter = False;
2020 Boolean doParentRelativePositioning = False;
2021 int availableDialogCount;
2024 /* See if there is a cached, unused dialog of the correct type. */
2026 dialog_type = dialog_data->type;
2031 Dialog * availableDialog;
2033 availableDialog = class_set[dialog_type].dialog_list;
2034 availableDialogCount = 0;
2037 * In addition to looking for an available dialog in the cache to use,
2038 * we also want to count up the number of unused dialogs in the cache.
2039 * This lets us know it we need to restart the timer, to again build
2042 while (availableDialog != NULL)
2044 if (availableDialog->in_use == False)
2047 dialog = availableDialog;
2049 availableDialogCount++;
2051 availableDialog = availableDialog->next;
2057 dialog = (Dialog *) XtMalloc (sizeof (Dialog));
2059 (*(class_set[dialog_type].class->create))
2060 (XtDisplay (encap_parent_shell), encap_parent_shell,
2061 &(dialog->dialog_widget), &dialog->dialog);
2063 /* Add the change and close callbacks into the dialog */
2065 if (class_set[dialog_type].class->install_change_callback)
2066 (*(class_set[dialog_type].class->install_change_callback))
2067 (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
2069 if (class_set[dialog_type].class->install_close_callback)
2070 (*(class_set[dialog_type].class->install_close_callback))
2071 (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
2073 dialog->next = class_set[dialog_type].dialog_list;
2074 class_set[dialog_type].dialog_list = dialog;
2078 * Set pointer to top dialog data in child of the shell.
2079 * This is needed to get help to work.
2081 if (top_rec == NULL)
2082 top_rec = dialog->dialog;
2083 XtSetArg(args[0], XmNuserData, top_rec);
2084 XtSetValues(dialog->dialog_widget, args, 1);
2086 /* Set the dialog structure fields to the parameter data. */
2088 dialog->in_use = True;
2089 dialog->dialog_data = dialog_data;
2090 dialog->change = change_proc;
2091 dialog->change_client_data = change_data;
2092 dialog->close = close_proc;
2093 dialog->close_client_data = close_data;
2095 /* If a special title has been specified, we need to set it now */
2098 XtSetArg(args[0], XmNtitle, title);
2099 XtSetValues(XtParent(dialog->dialog_widget), args, 1);
2104 /************************************************************************
2106 * _DtShowBuiltDialog
2107 * This functions is used to display an instance of a dialog which
2108 * has already been built with _DtBuildDialog.
2110 ************************************************************************/
2116 DialogData *dialog_data,
2118 Boolean iconify_state,
2119 XClassHint * classHints )
2124 DialogInstanceData * instance_data;
2127 Boolean doCenter = False;
2128 Boolean doParentRelativePositioning = False;
2129 int availableDialogCount;
2132 dialog_type = dialog_data->type;
2134 /* Find the dialog */
2135 dialog = class_set[dialog_data->type].dialog_list;
2136 while (dialog != NULL)
2138 if (dialog->dialog_data == dialog_data)
2141 dialog = dialog->next;
2144 /* Need to add the map callback in relation to the parent */
2145 if (class_set[dialog_type].class->map)
2148 * The map_parent parameter gives us the ability to position
2149 * the dialog relative to a window which is not the transientFor
2150 * parent. This is used for the audio preview dialog.
2152 if (map_parent == NULL)
2153 map_parent = parent;
2155 (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
2158 instance_data = (DialogInstanceData *) dialog_data->data;
2160 /* If this is a top level shell, get it realized */
2161 if (XtIsSubclass (XtParent (dialog->dialog_widget),
2162 applicationShellWidgetClass))
2164 if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
2166 if (instance_data->displayed == True)
2168 (void) sprintf (geometry, "=%dx%d+%d+%d",
2169 instance_data->width, instance_data->height,
2170 instance_data->x, instance_data->y);
2172 XtSetArg (args[0], XmNgeometry, geometry);
2173 XtSetValues (XtParent (dialog->dialog_widget), args, 1);
2175 else if ((instance_data->width != 0) && (instance_data->height != 0))
2178 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
2179 XtSetArg (args[n], XmNheight, instance_data->height); n++;
2180 XtSetValues (XtParent (dialog->dialog_widget), args, n);
2183 /* Toggle mappedWhenManaged to false */
2184 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
2185 XtRealizeWidget (XtParent(dialog->dialog_widget));
2187 /* Set the proper workspaces if needed */
2188 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2190 /* Set any application-specified class hints for the window */
2193 XSetClassHint(XtDisplay(dialog->dialog_widget),
2194 XtWindow(XtParent(dialog->dialog_widget)),
2198 /* Set the iconify state */
2199 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
2201 /* Map the window */
2202 XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
2203 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
2204 XSync(XtDisplay(dialog->dialog_widget), False);
2209 if (instance_data->displayed == True)
2211 WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
2213 wm->wm.size_hints.flags |= USPosition;
2214 XtSetArg (args[0], XmNx, instance_data->x);
2215 XtSetArg (args[1], XmNy, instance_data->y);
2216 XtSetArg (args[2], XmNwidth, instance_data->width);
2217 XtSetArg (args[3], XmNheight, instance_data->height);
2218 XtSetValues (XtParent (dialog->dialog_widget), args, 4);
2220 else if ((instance_data->width != 0) && (instance_data->height != 0))
2223 XtSetArg (args[n], XmNwidth, instance_data->width); n++;
2224 XtSetArg (args[n], XmNheight, instance_data->height); n++;
2225 XtSetValues (XtParent (dialog->dialog_widget), args, n);
2228 /* Set the proper workspaces if needed */
2229 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2231 /* Set any application-specified class hints for the window */
2234 XSetClassHint(XtDisplay(dialog->dialog_widget),
2235 XtWindow(XtParent(dialog->dialog_widget)),
2239 /* Set the iconify state */
2240 SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
2242 /* Map the window */
2243 XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
2248 if (instance_data->displayed == True)
2250 XtSetArg (args[0], XmNx, instance_data->x);
2251 XtSetArg (args[1], XmNy, instance_data->y);
2252 XtSetArg (args[2], XmNwidth, instance_data->width);
2253 XtSetArg (args[3], XmNheight, instance_data->height);
2254 XtSetArg (args[4], XmNdefaultPosition, False);
2255 XtSetValues (dialog->dialog_widget, args, 5);
2256 XtRealizeWidget (dialog->dialog_widget);
2260 XtSetArg (args[0], XmNdefaultPosition, False);
2261 XtSetValues (dialog->dialog_widget, args, 1);
2263 XtRealizeWidget (dialog->dialog_widget);
2267 /* Position relative to the parent dialog */
2269 * Must be done after the set_values call, since the dialog
2270 * may get forced to a different size.
2272 doParentRelativePositioning = True;
2276 /* Center in the display */
2278 * Must be done after the set_values call, since the dialog
2279 * may get forced to a different size.
2286 * Dialogs with no controlling parent window, need to have their
2287 * own workspace perperty set, if some workspaces have been requested.
2289 if ((parent == NULL) && workspaces)
2290 _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
2294 /* Set Values onto the dialog to set it to the correct data. */
2296 (*(class_set[dialog_data->type].class->set_values))
2297 (dialog->dialog, dialog_data->data);
2300 * These two adjustments MUST be done AFTER the dialog's SetValues()
2301 * procedure is called. This is due to the fact that the setvalues
2302 * may cause the dialog size to change, and since both of the following
2303 * positioning algorithms are dependent upon the dialog size, we want
2304 * to make sure that the correct size is used.
2308 XtSetArg (args[0], XmNx,
2309 (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
2310 dialog->dialog_widget->core.width) / (Dimension)2);
2311 XtSetArg (args[1], XmNy,
2312 (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
2313 dialog->dialog_widget->core.height) / (Dimension)2);
2314 XtSetValues (dialog->dialog_widget, args, 2);
2316 else if (doParentRelativePositioning)
2318 XtSetArg (args[0], XmNx,
2320 (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
2321 XtSetArg (args[1], XmNy,
2323 (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
2324 XtSetValues (XtParent(dialog->dialog_widget), args, 2);
2328 /* Fix up the transient-for windowing information so that */
2329 /* the window manager will shuffle and iconify as a group */
2333 if (XtIsRealized(parent))
2335 XSetTransientForHint (XtDisplay (parent),
2336 XtWindow (XtParent (dialog->dialog_widget)),
2342 if (!XtIsSubclass (XtParent (dialog->dialog_widget),
2343 applicationShellWidgetClass))
2345 XSetTransientForHint (XtDisplay (encap_parent_shell),
2346 XtWindow (XtParent (dialog->dialog_widget)),
2347 XtWindow (encap_parent_shell));
2352 /* Display the dialogs, application shells are displayed above. */
2354 if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
2355 applicationShellWidgetClass)))
2357 XtManageChild (dialog->dialog_widget);
2361 /* Set the dialog instance data to indicate that the dialog */
2364 ((DialogInstanceData *) (dialog_data->data))->displayed = True;
2367 /* Give the dialog a chance to set its focus widget, if necessary */
2369 if (class_set[dialog_data->type].class->set_focus)
2371 (*(class_set[dialog_data->type].class->set_focus))
2372 (dialog->dialog, dialog_data->data);
2379 DialogStructureNotifyHandler(
2381 XtPointer client_data,
2384 if( event->type == MapNotify )
2386 if( NumberOfDialogMapped == 0 )
2390 if( timerState == TIMER_STARTUP_STATE )
2391 timeOut = initialTimeoutLength;
2392 else if( timerState == TIMER_ACTIVE_STATE )
2393 timeOut = activeTimeoutLength;
2394 else if( timerState == TIMER_IDLE_STATE )
2395 timeOut = idleTimeoutLength;
2402 XtRemoveTimeOut( timerId );
2404 timerId = XtAppAddTimeOut( XtWidgetToApplicationContext( w ),
2406 (XtTimerCallbackProc)TimerEvent,
2410 ++NumberOfDialogMapped;
2412 else if( event->type == UnmapNotify )
2414 if( NumberOfDialogMapped )
2415 --NumberOfDialogMapped;
2417 if( NumberOfDialogMapped == 0 )
2421 XtRemoveTimeOut( timerId );
2431 XtPointer client_data,
2434 Dialog * dialog = (Dialog *) client_data;
2436 ChangeDirectoryToParent(dialog->change_client_data, directory);
2441 DialogData *dialog_data)
2443 Dialog *dialog,**headptr;
2444 headptr = &class_set[dialog_data->type].dialog_list;
2447 while (dialog != NULL)
2449 if (dialog->dialog_data == dialog_data)
2451 *headptr = dialog->next;
2452 XtFree((char *) dialog);
2455 headptr = &(dialog->next);