Debian Codegraph @

gui/GraphLib/libsrc/uimxR5/src/uimx.c

raw
1 /*---------------------------------------------------------------------
2 * $Date: 2012-05-07 09:34:30 $ $Revision: 1.3 $
3 *---------------------------------------------------------------------
4 *
5 *
6 * Copyright (c) 1989-1992, Visual Edge Software Ltd.
7 *
8 * ALL RIGHTS RESERVED. Permission to use, copy, modify, and
9 * distribute this software and its documentation for any purpose
10 * and without fee is hereby granted, provided that the above
11 * copyright notice appear in all copies and that both that
12 * copyright notice and this permission notice appear in supporting
13 * documentation, and that the name of Visual Edge Software not be
14 * used in advertising or publicity pertaining to distribution of
15 * the software without specific, written prior permission. The year
16 * included in the notice is the year of the creation of the work.
17 *-------------------------------------------------------------------*/
18
19 /*
20
21 .VERSION
22 090818 last modif
23
24 */
25
26
27
28 #include <string.h>
29 #include <stdio.h>
30
31 #ifdef MOTIF_WIDGETS
32 #include <X11/Intrinsic.h>
33 #include <X11/IntrinsicP.h>
34 #include <X11/RectObjP.h>
35 #include <Xm/DialogS.h>
36 #endif /* MOTIF_WIDGETS */
37
38 #include "UxLib.h"
39 #include "UxLibP.h"
40 #include "resload.h"
41
42 #include "dstring.h"
43 #include <X11/ShellP.h>
44 #include "uimx_cat.h"
45 #include "lib_ds.h"
46 #include "valloc.h"
47 #include "utype.h"
48
49 #define CGETS(x,y) UxCatGets(MC_LIBUIMX,(x),(y))
50
51 extern void XmRegisterConverters();
52 extern void UxDDInit(), UxDDInstall();
53 extern void UxAddRuntimeResources();
54 extern void UxInit_colors(), UxSwidgetFreeArgs(), UxSwidgetAddNamedValue();
55
56 extern int UxIsInterface(), UxSwidgetGetWinGroupFlag();
57
58 int UxStrEqual(), UxQueryTree();
59
60
61
62 /*-----------------------------------------------------
63 * Standard system globals.
64 *-----------------------------------------------------*/
65
66 Widget UxTopLevel;
67 XEvent *UxCurrentEvent;
68 XtAppContext UxAppContext;
69 Display *UxDisplay;
70 int UxScreen;
71 Window UxRootWindow;
72 char *UxDefaultShellType;
73 char *UxUserShell;
74 char *UxThisWidget;
75 GC UxDrawGC;
76 GC UxUimxBlackGC;
77
78 int UxNotifyFlag = 0;
79
80 static void RecordWidget UXPROTO((Widget, swidget));
81 static void RemoveWidgets UXPROTO((Widget, Widget));
82 static void GC_init UXPROTO((void));
83 static void DestroyTree UXPROTO((swidget));
84 static void DestroyWidgetTree UXPROTO((Widget));
85
86 /*-----------------------------------------------------------------------------
87 NAME: void UxDelayUpdate (sw)
88 INPUT: swidget sw
89 DESCRIPTION: Set swidget update flag to false so that when resources
90 are set update of the widget in swidget is delayed until
91 UxUpdate is executed
92 CREATION: 14 Mar 89 run-time version
93 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
94 -----------------------------------------------------------------------------*/
95
96 void UxDelayUpdate (sw)
97 swidget sw;
98 {
99 sw->UpdateFlag = 0;
100 }
101
102 /*-----------------------------------------------------------------------------
103 NAME: void UxUpdate (sw)
104 INPUT: swidget sw
105 DESCRIPTION: Update the widget in swidget and set the swidget update flag
106 to true.
107 LAST REV: March 93 fix3963 UxIsSwidget now called.
108 -----------------------------------------------------------------------------*/
109
110 void UxUpdate (sw)
111 swidget sw;
112 {
113 if (UxIsSwidget(sw) && sw->ItsWidget) {
114 if (sw->NumValues> 0) {
115 XtSetValues(sw->ItsWidget, sw->Values, sw->NumValues);
116 }
117 sw->UpdateFlag = 1;
118 UxSwidgetFreeArgs (sw);
119 }
120 }
121
122 /*-----------------------------------------------------------------------------
123 NAME: int UxPutProp (sw, name, value)
124 INPUT: swidget sw
125 char *name
126 XtArgVal value
127
128 DESCRIPTION:
129 General put for a value that does not require conversion.
130 If the swidget is under delay, save the value in its Values list;
131 otherwise, just send it to the Widget.
132
133 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
134 Aug 93 fix4472 Free proper value.
135 -----------------------------------------------------------------------------*/
136
137 int UxPutProp (sw, prop, val)
138 swidget sw;
139 String prop;
140 XtArgVal val;
141 {
142 Arg arg[2];
143 Widget w = UxGetWidget(sw);
144
145 /* Rename msgDialogType to dialogType so that the widget understands!
146 This is done for setting a resource value when updating or creating
147 a widget */
148 if (UxStrEqual(prop, "msgDialogType")) {
149 prop = "dialogType";
150 }
151
152 if (w && sw->UpdateFlag) {
153
154 XtSetArg(arg[0], prop, val);
155 XtSetValues(w, arg, 1);
156 UxFreeXValue(sw, prop, val);
157
158 } else {
159
160 UxSwidgetAddNamedValue(sw, prop, val);
161
162 }
163 return NO_ERROR;
164 }
165
166 /*-----------------------------------------------------------------------------
167 NAME: void UxGetProp (sw, name)
168 INPUT: swidget sw
169 char *name
170 DESCRIPTION: Get the value of the named resource associated with the
171 specified swidget.
172 Should be used only for resources whose size is == sizeof(XtArgVal).
173
174 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
175 -----------------------------------------------------------------------------*/
176
177 XtArgVal UxGetProp (sw, prop)
178 swidget sw;
179 String prop;
180 {
181 Arg arg[2];
182 XtArgVal val = 0;
183 Widget w = UxGetWidget(sw);
184
185 if (w)
186 {
187 XtSetArg(arg[0], prop, &val);
188 XtGetValues(w, arg, 1);
189 return ((XtArgVal) val);
190 } else {
191 return (XtArgVal) UxSwidgetGetProp(sw, prop);
192 }
193 }
194
195 /*-----------------------------------------------------------------------------
196 NAME: void UxShortGetProp (sw, name)
197 INPUT: swidget sw
198 char *name
199 DESCRIPTION: Get the value of the named resource associated with the
200 specified swidget.
201 CREATION: 14 Feb 90 run-time version
202 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
203 -----------------------------------------------------------------------------*/
204
205 short UxShortGetProp (sw, prop)
206 swidget sw;
207 String prop;
208 {
209 Arg arg[2];
210 short val =0;
211 Widget w = UxGetWidget(sw);
212
213 if (w)
214 {
215 XtSetArg(arg[0], prop, &val);
216 XtGetValues(w, arg, 1);
217 return val;
218 } else {
219 return (short) UxSwidgetGetProp(sw, prop);
220 }
221 }
222
223 /*-----------------------------------------------------------------------------
224 NAME: void UxCharGetProp (sw, name)
225 INPUT: swidget sw
226 char *name
227 DESCRIPTION: Get the value of the named resource associated with the
228 specified swidget.
229 CREATION: 14 Feb 90 run-time version
230 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
231 -----------------------------------------------------------------------------*/
232
233 char UxCharGetProp (sw, prop)
234 swidget sw;
235 String prop;
236 {
237 Arg arg[2];
238 char val =0;
239 Widget w = UxGetWidget(sw);
240
241 if (w)
242 {
243 XtSetArg(arg[0], prop, &val);
244 XtGetValues(w, arg, 1);
245 return val;
246 } else {
247 return (char) UxSwidgetGetProp(sw, prop);
248 }
249 }
250
251 /*-----------------------------------------------------------------------------
252 NAME: int UxIsOverrideShell (sw)
253 INPUT: swidget sw
254 RETURN: integer (1 or 0)
255 DESCRIPTION: check if the given swidget is an override shell.
256 CREATION:
257 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
258 -----------------------------------------------------------------------------*/
259
260 int UxIsOverrideShell (sw)
261 swidget sw;
262 {
263 return (UxGetClass(sw) == overrideShellWidgetClass);
264 }
265
266 /*-----------------------------------------------------------------------------
267 NAME: int UxIsShellClass (cls)
268 INPUT: WidgetClass cls
269 RETURN: integer (1 or 0)
270 DESCRIPTION: check if the given widgetclass is shellwidgetclass
271 CREATION:
272 REVISIONS: 14 Mar 89 run-time version
273 29 Aug 90 OLE MERGE
274 -- separator motif and ol
275 -----------------------------------------------------------------------------*/
276
277 int UxIsShellClass (cls)
278 WidgetClass cls;
279 {
280 #ifdef MOTIF_WIDGETS
281
282 return ((cls == topLevelShellWidgetClass) ||
283 (cls == transientShellWidgetClass) ||
284 (cls == overrideShellWidgetClass) ||
285 (cls == applicationShellWidgetClass) ||
286 (cls == xmDialogShellWidgetClass));
287
288 #endif /* MOTIF_WIDGETS */
289 }
290
291 #ifdef MOTIF_WIDGETS
292
293 #include "uimxMF.c"
294 #endif /* MOTIF_WIDGETS */
295
296 /*-----------------------------------------------------------------------------
297 NAME: void UxAddCallback (sw, name, callback, client_data)
298 INPUT: swidget sw, char *name, XtCallbackProc callback, XtPointer client_data
299 RETURN:
300 DESCRIPTION: given swidget add callback client_data to it.
301 REVISIONS: 14 Mar 89 run-time version
302 -----------------------------------------------------------------------------*/
303
304 void UxAddCallback (sw, name, callback, client_data)
305 swidget sw;
306 char *name;
307 XtCallbackProc callback;
308 XtPointer client_data;
309 {
310 if (UxGetWidget(sw)) {
311 XtAddCallback(UxGetWidget(sw), name, callback, client_data);
312 }
313 }
314
315 /*-----------------------------------------------------------------------------
316 NAME: void UxMainLoop ()
317 INPUT:
318 RETURN:
319 DESCRIPTION: call XtmainLoop
320 REVISIONS: 14 Mar 89 run-time version
321 25 Aug 89 call Events routines
322 -----------------------------------------------------------------------------*/
323
324 void UxMainLoop ()
325 {
326 XEvent event;
327
328 for (;;) {
329 UxNextEvent (&event);
330 UxDispatchEvent (&event);
331 }
332 }
333
334
335 /******************************************************************************
336 NAME: void destroySwidgetsCallback (wid)
337
338 INPUT: Widget wid - widget to destroy
339 XtPointer client_data - not used
340 XtPointer call_data - not used
341
342 DESCRIPTION: Find the swidget for 'wid' and destroy all the libuimx data
343 structures. This is called as a callback from the top
344 widget to be deleted in a tree.
345
346 CREATION: Jul 29/1990
347 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
348 -----------------------------------------------------------------------------*/
349
350 static void destroySwidgetsCallback (wid, client_data, call_data)
351 Widget wid;
352 XtPointer client_data;
353 XtPointer call_data;
354 {
355 swidget curr;
356
357 curr = UxWidgetToSwidget (wid);
358
359 DestroyTree (curr);
360 }
361
362 /******************************************************************************
363 NAME: DelayedFreeData ( client_data, id )
364
365 INPUT: XtPointer client_data - pointer to be freed
366 XtIntervalId *id;
367
368 RETURN: void
369
370 DESCRIPTION: This XtTimerCallbackProc function simply frees the client data.
371
372 CREATION: Visual Edge Software April 6 1991
373 -----------------------------------------------------------------------------*/
374 static void DelayedFreeData( client_data, _id )
375 XtPointer client_data;
376 XtIntervalId *_id;
377 {
378 /* XtIntervalId *id = _id; */
379
380 if (client_data != NULL) {
381 UxFree(client_data);
382 }
383 }
384 /******************************************************************************
385 NAME: void UxDestroyContextCB (wid, con)
386
387 INPUT: Widget wid - widget for callback
388 XtPointer con - context pointer
389 XtPointer call_data - not used
390
391 DESCRIPTION: This callback function registers a timeout to free the
392 context structure. This mechanism is used to ensure that
393 user's destroyCallbacks are executed before we free the
394 context structure.
395
396 CREATION: Jul 29/1990
397 REVISIONS: Visual Edge Software April 30 1993
398 -----------------------------------------------------------------------------*/
399
400 void UxDestroyContextCB (wid, con, call_data)
401 Widget wid;
402 XtPointer con;
403 XtPointer call_data;
404 {
405 XtAppAddTimeOut(UxAppContext, 0,
406 DelayedFreeData, con);
407 }
408
409 /*-----------------------------------------------------------------------------
410 NAME: void UxDestroyInterface (sw)
411 INPUT: swidget sw
412 DESCRIPTION: Destroys the interface.
413 CREATION: 20 Dec 88
414 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
415 -----------------------------------------------------------------------------*/
416
417 int UxDestroyInterface (sw)
418 swidget sw;
419 {
420 Widget w = UxGetWidget(sw);
421
422 if (! w) return (ERROR);
423
424 #ifdef MOTIF_WIDGETS
425 XtAddCallback(w, XmNdestroyCallback, destroySwidgetsCallback, NULL);
426 #endif /* MOTIF_WIDGETS */
427
428 XtDestroyWidget(UxRealWidget(sw));
429
430 return NO_ERROR;
431 }
432
433 /* ---------------------------------------------------------------------------
434 NAME: UxDestroySwidget (sw)
435 INPUT: swidget sw;
436 RETURN:
437 DESCRIPTION: Destroys an swidget.
438 CREATION: 14 Mar 89
439 16 Nov 89 added XtDestroyWidget (at top level)
440 Jul 29/1990
441 - register destroy handler to destroy the swidgets then
442 destroy the widgets.
443 ---------------------------------------------------------------------------*/
444 void UxDestroySwidget (sw)
445 swidget sw;
446 {
447 Widget w = UxGetWidget(sw);
448
449 if (! w) return;
450
451 #ifdef MOTIF_WIDGETS
452 XtAddCallback(w, XmNdestroyCallback, destroySwidgetsCallback, NULL);
453 #endif /* MOTIF_WIDGETS */
454
455 XtDestroyWidget(UxRealWidget(sw));
456 }
457
458 /* ---------------------------------------------------------------------------
459 NAME: void UxRealizeInterface (sw)
460 INPUT: swidget sw
461 RETURN:
462 DESCRIPTION: Realizes the swidget tree, so long as its parent is realized.
463 CREATION: Dec 20/1988
464 REVISIONS: 14 Mar 89 run-time version
465 -----------------------------------------------------------------------------*/
466 int UxRealizeInterface (sw)
467 swidget sw;
468 {
469 Widget w = UxRealWidget(sw);
470
471 if (w)
472 {
473 if (XtIsRealized(XtParent(w)) || XtParent(w) == UxTopLevel) {
474 XtRealizeWidget(w);
475 }
476 return NO_ERROR;
477 }
478 return ERROR;
479 }
480
481 #ifdef MOTIF_WIDGETS
482 /*-----------------------------------------------------------------------------
483 NAME: handle_dialog_child(wgt, manage_func)
484 INPUT: Widget wgt - the dialogShell widget
485 void (*manage_func)() - either XtManageChild
486 or XtUnmanageChild
487 RETURN: int - NO_ERROR if successful
488 ERROR otherwise
489 DESCRIPTION: Handles the popping up or popping down of dialog shells
490 by managing or unmanaging their children.
491 REVISIONS: Oct 8/91 fix3035
492 -----------------------------------------------------------------------------*/
493
494 static int handle_dialog_child(wgt, manage_func)
495 Widget wgt;
496 void (*manage_func)();
497 {
498 int i, num_children;
499 Widget *children;
500 int error_flag = ERROR;
501
502 XtVaGetValues (wgt,
503 XmNnumChildren, &num_children,
504 XmNchildren, &children,
505 0,NULL);
506
507 /* We manage/unmanage the first rectObj child in the list.
508 * Note that the check for rectObjClass is necessary since some
509 * implementations of Motif add protocol children to the dialogShell.
510 * Additionally, when the LANG is set to Japanese, a widget of class
511 * Core is created. This widget should not be managed. We'll skip it.
512 */
513
514 for (i = 0; i < num_children; i++)
515 {
516 if (XtIsSubclass(children[i], rectObjClass) &&
517 (XtClass (children[i]) != coreWidgetClass))
518 {
519 (*manage_func)(children[i]);
520 error_flag = NO_ERROR;
521 break;
522 }
523 }
524
525 return (error_flag);
526 }
527 #endif /* MOTIF_WIDGETS */
528
529 #ifdef MOTIF_WIDGETS
530 /*-----------------------------------------------------------------------------
531 NAME: popup_dialog (wgt, grab_flag)
532 INPUT: Widget wgt - dialogShell to pop up
533 XtGrabKind grab_flag - the grab flag
534 RETURN: void
535 DESCRIPTION: Pops up the dialogShell.
536 -----------------------------------------------------------------------------*/
537
538 static void popup_dialog (wgt, grab_flag)
539 Widget wgt;
540 XtGrabKind grab_flag;
541 {
542 if (handle_dialog_child(wgt, XtManageChild) == ERROR)
543 XtPopup(wgt, grab_flag);
544 }
545 #endif /* MOTIF_WIDGETS */
546
547 /*-----------------------------------------------------------------------------
548 NAME: static void DealWithWindowGroup (sw)
549 INPUT: swidget sw - swidget to popup
550 RETURN: void
551 DESCRIPTION: Set the window group if the window group flag is set.
552 CREATION: Aug/1 /1990 (see bug866)
553 REVISIONS:
554 -----------------------------------------------------------------------------*/
555 static void DealWithWindowGroup (sw)
556 swidget sw;
557 {
558 Widget w = UxGetWidget(sw);
559
560 if (w &&
561 UxIsShellClass(UxGetClass(sw)) && /* if explicit shell */
562 !UxIsOverrideShell(sw) && /* and not override shell */
563 UxSwidgetGetWinGroupFlag(sw)) /* and window group flag set*/
564 {
565 if (!XtIsRealized(w))
566 XtRealizeWidget(w);
567 UxPutWindowGroup(sw, UxGetName(sw));
568 }
569 }
570
571 /*-----------------------------------------------------------------------------
572 NAME: int UxPopupInterface (sw, type)
573 INPUT: swidget sw - swidget to popup
574 grabtype type - grab type
575 RETURN: ERROR/NO_ERROR
576 DESCRIPTION: If the swidget is a shell then call a Popup function using
577 the proper grab type.
578 CREATION: Dec 19/1988
579 REVISIONS: March 14/1989
580 Aug 1/90 (see bug866)
581 -- deal with window groups
582 Oct 8/91 fix3035 - use of popup_dialog()
583 -----------------------------------------------------------------------------*/
584
585 int UxPopupInterface (sw, type)
586 swidget sw;
587 grabtype type;
588 {
589 Widget w = UxRealWidget(sw);
590
591 if (w && XtIsSubclass(w, shellWidgetClass))
592 {
593 XtGrabKind xt_grab;
594
595 /* deal with window group */
596 DealWithWindowGroup(sw);
597
598 switch (type) {
599 case nonexclusive_grab:
600 xt_grab = XtGrabNonexclusive;
601 break;
602 case exclusive_grab:
603 xt_grab = XtGrabExclusive;
604 break;
605 default:
606 xt_grab = XtGrabNone;
607 break;
608 }
609
610 #ifdef MOTIF_WIDGETS
611 if (XtIsSubclass(w, xmDialogShellWidgetClass))
612 popup_dialog(w, xt_grab);
613 else
614 #endif /* MOTIF_WIDGETS */
615 XtPopup(w, xt_grab);
616
617 return NO_ERROR;
618 }
619 return (ERROR);
620 }
621
622 #ifdef MOTIF_WIDGETS
623 /*-----------------------------------------------------------------------------
624 NAME: popdown_dialog (wgt)
625 INPUT: Widget wgt - dialogShell to pop down
626 RETURN: void
627 DESCRIPTION: Pops down the dialogShell.
628 -----------------------------------------------------------------------------*/
629
630 static void popdown_dialog (wgt)
631 Widget wgt;
632 {
633 if (handle_dialog_child(wgt, XtUnmanageChild) == ERROR)
634 XtPopdown(wgt);
635 }
636 #endif /* MOTIF_WIDGETS */
637
638 /*-----------------------------------------------------------------------------
639 NAME: int UxPopdownInterface (sw)
640 INPUT: swidget sw - swidget to popdown
641 RETURN: ERROR/NO_ERROR
642 DESCRIPTION: If the swidget is a shell then call a popdown function.
643 CREATION: Dec 19/1988
644 REVISIONS: Mar 14/1989
645 Oct 8/91 fix3035 - use of popdown_dialog ()
646 -----------------------------------------------------------------------------*/
647
648 int UxPopdownInterface (sw)
649 swidget sw;
650 {
651 Widget w = UxRealWidget(sw);
652
653 if (w && XtIsSubclass(w, shellWidgetClass)) {
654 #ifdef MOTIF_WIDGETS
655 if (XtIsSubclass(w, xmDialogShellWidgetClass))
656 popdown_dialog(w);
657 else
658 #endif /* MOTIF_WIDGETS */
659 XtPopdown(w);
660 return NO_ERROR;
661 }
662 return(ERROR);
663 }
664
665 /*-----------------------------------------------------------------------------
666 NAME: void UxUnmap (sw)
667 INPUT: swidget sw
668 RETURN:
669 DESCRIPTION: Unmap the swidget
670 CREATION:
671 REVISIONS: 14 Mar 89 run-time version
672 24 July 90 (see bug802)
673 -- unmap widgets that are subclass of windowObjClass
674 -----------------------------------------------------------------------------*/
675
676 void UxUnmap (sw)
677 swidget sw;
678 {
679 Widget w = UxGetWidget(sw);
680
681 if (w)
682 {
683 if (UxIsInterface (sw)) {
684 Widget rw = UxRealWidget (sw);
685 #ifdef MOTIF_WIDGETS
686 if (XtIsSubclass(rw, xmDialogShellWidgetClass))
687 popdown_dialog(rw);
688 else
689 #endif /* MOTIF_WIDGETS */
690 XtPopdown(rw);
691 }
692 /* unmap if widget is subclass of windowObjClass */
693 else if (XtIsSubclass(w, widgetClass)){
694 XtUnmapWidget(w);
695 }
696 else {
697 XtUnmanageChild(w);
698 }
699 }
700 }
701 /*--------------------------------------------------------------------------
702 NAME: int UxIsInterface (sw)
703 INPUT: swidget sw
704 RETURN: True or False.
705 DESCRIPTION: Determines if the swidget is a top level interface.
706 CREATION: Nov/4/91 fix3112
707 REVISIONS: March 93 fix3963 UxIsSwidget now called.
708 --------------------------------------------------------------------------*/
709 int UxIsInterface (sw)
710 swidget sw;
711 {
712 if (UxIsSwidget (sw))
713 {
714 Widget w = UxGetWidget (sw);
715 swidget parent;
716
717 if (w) {
718 if (XtIsSubclass(w, shellWidgetClass))
719 return 1;
720 }
721 else {
722 WidgetClass cl = UxGetClass (sw);
723 if (UxIsShellClass (cl))
724 return 1;
725 }
726 parent = UxGetParent(sw);
727 if (! UxGetWidget (parent))
728 return 1;
729 }
730 return 0;
731 }
732
733 /*--------------------------------------------------------------------------
734 NAME: void UxMap (sw)
735 INPUT: swidget sw
736 RETURN:
737 DESCRIPTION: map swidget
738 CREATION: 25 May 1989
739 REVISIONS: 24 July 90 (see bug802)
740 -- map widgets that are subclass of windowObjClass
741 4 Nov 91 fix3112
742 --------------------------------------------------------------------------*/
743 void UxMap (sw)
744 swidget sw;
745 {
746 Widget w = UxGetWidget(sw);
747
748 if (w)
749 {
750 if (UxIsInterface (sw))
751 {
752 Widget rw = UxRealWidget (sw);
753 #ifdef MOTIF_WIDGETS
754 if (XtIsSubclass(rw, xmDialogShellWidgetClass))
755 popup_dialog(rw, XtGrabNone);
756 else
757 #endif /* MOTIF_WIDGETS */
758 XtPopup(rw, XtGrabNone);
759 }
760 else if (XtIsSubclass(w, widgetClass)){
761 XtMapWidget(w);
762 }
763 else {
764 XtManageChild(w);
765 }
766 }
767 }
768
769 /*-----------------------------------------------------------------------------
770 NAME: void UxUnmanage (sw)
771 INPUT: swidget sw
772 RETURN:
773 DESCRIPTION: Unmanage the swidget
774 LAST REV: Nov 92, fix3728 Always unmanage even when popping down.
775 -----------------------------------------------------------------------------*/
776
777 void UxUnmanage (sw)
778 swidget sw;
779 {
780 Widget w = UxGetWidget(sw);
781 Widget rw = UxRealWidget(sw);
782
783 if (rw && XtIsSubclass(rw, shellWidgetClass)){
784 XtPopdown(rw);
785 }
786 if (w && XtIsComposite(XtParent(w))) {
787 XtUnmanageChild(w);
788 }
789 }
790
791 /*--------------------------------------------------------------------------
792 NAME: void UxManage (sw)
793 INPUT: swidget sw
794 RETURN:
795 DESCRIPTION: manage swidget
796 LAST REV: Nov 92, fix3728 Always manage even when popping up.
797 --------------------------------------------------------------------------*/
798 void UxManage (sw)
799 swidget sw;
800 {
801 Widget w = UxGetWidget(sw);
802 Widget rw = UxRealWidget(sw);
803
804 if (w && XtIsComposite(XtParent(w))) {
805 XtManageChild(w);
806 }
807 if (rw && XtIsSubclass(rw, shellWidgetClass)) {
808 XtPopup(rw, XtGrabNone);
809 }
810 }
811
812 /*-----------------------------------------------------------------------------
813 NAME: void UxWaitForNotify ()
814 INPUT: --
815 RETURN: --
816 DESCRIPTION: Do an event loop until UxNotify_flag is set
817 CREATION: Jan 21/1989
818 REVISIONS: --
819 -----------------------------------------------------------------------------*/
820 void UxWaitForNotify ()
821 {
822 XEvent *oldev, event;
823
824 UxNotifyFlag = 0;
825 oldev = UxCurrentEvent;
826 UxCurrentEvent = &event;
827
828 while (!UxNotifyFlag) {
829 if (XtAppPeekEvent (UxAppContext, &event)) {
830 XtAppNextEvent(UxAppContext, &event);
831 XtDispatchEvent (&event);
832 } else {
833 XtAppProcessEvent (UxAppContext,
834 XtIMTimer | XtIMAlternateInput);
835 }
836 }
837
838 UxCurrentEvent = oldev;
839 UxFlushQueue ();
840 }
841
842 /*-----------------------------------------------------------------------------
843 NAME: void UxNotify ()
844 INPUT: --
845 RETURN: --
846 DESCRIPTION: set UxNotify_flag to break from event loop in UxWait_for_notify
847 CREATION: Jan 21/1989
848 REVISIONS: Apr 29/1993 fix4208 push back event on event Q
849 -----------------------------------------------------------------------------*/
850 void UxNotify ()
851 {
852 UxNotifyFlag = 1;
853 }
854
855 /*-----------------------------------------------------------------------------
856 NAME: void UxFlushQueue ()
857 INPUT: --
858 RETURN: --
859 DESCRIPTION: set UxNotify_flag to break from event loop in UxWait_for_notify
860 CREATION: Jan 21/1989
861 REVISIONS: --
862 -----------------------------------------------------------------------------*/
863 void UxFlushQueue ()
864 {
865 XEvent *oldev, event;
866
867 oldev = UxCurrentEvent;
868
869 UxCurrentEvent = &event;
870
871 while (XtAppPending(UxAppContext))
872 {
873 XtAppNextEvent(UxAppContext, &event);
874 XtDispatchEvent(&event);
875 }
876
877 UxCurrentEvent = oldev;
878 }
879
880 /*------------------------------------------------------------------------
881 * NAME: IgnoreErrors
882 *
883 * DESCRIPTION: Default XErrorHandler for runtime, does nothing.
884 *------------------------------------------------------------------------*/
885
886 static int IgnoreErrors (display, event)
887 Display *display;
888 XErrorEvent *event;
889 {
890 return 0;
891 }
892
893 /*----------------------------------------------------------------------
894 * NAME: UxXtInitialize
895 * DESCRIPTION: Starts the toolkit session.
896 * PARAMETERS:
897 * char *rfile -- The resource file of the user's
898 * application.
899 * int *arc; -- Args from the mainline
900 * char **argc
901 * RETURN: The applications top level widget
902 * REVISIONS: 09/11/92 fix3711
903 *--------------------------------------------------------------------*/
904 char *UxProgramName = (char *) 0;
905 char *UxProgramClassName = (char *) 0;
906
907 void UxXtInitialize (rfile, argc, argv)
908 char *rfile;
909 int *argc;
910 char **argv;
911 {
912 dstring uxapp;
913
914 UxProgramName = strrchr(argv[0], '/');
915 if (UxProgramName)
916 ++UxProgramName;
917 else
918 UxProgramName = argv[0];
919
920 uxapp = dcreate("UXAPP=");
921 dappend(uxapp, rfile);
922 putenv(dnstr(uxapp));
923 if ((UxProgramClassName = strchr(dnstr(uxapp), '=')))
924 UxProgramClassName++;
925 else
926 UxProgramClassName = dnstr(uxapp);
927
928 /* do not free uxapp -- memory used by putenv permanently */
929
930 #ifdef MOTIF_WIDGETS
931 XmRegisterConverters();
932 UxAddActions(action_list, XtNumber(action_list));
933 #endif /* MOTIF_WIDGETS */
934
935 XSetErrorHandler(IgnoreErrors);
936
937 UxDisplay = XtDisplay(UxTopLevel);
938 UxScreen = XDefaultScreen(UxDisplay);
939 UxRootWindow = RootWindow(UxDisplay, UxScreen);
940
941 /* We set the geometry of UxTopLevel so that dialogShells
942 that are parented on it will get centered on the screen
943 (if defaultPosition is true). */
944
945 XtVaSetValues(UxTopLevel,
946 XtNx, 0,
947 XtNy, 0,
948 XtNwidth, DisplayWidth(UxDisplay, UxScreen),
949 XtNheight, DisplayHeight(UxDisplay, UxScreen),
950 /* 0,NULL); */
951 /* P.Ballester 2012-04-30. The above line must be NULL terminated, not 0,NULL */
952 NULL);
953
954 UxInit_colors();
955 UxInitializeResourcePath();
956 UxInitializeBitmapPath();
957 UxSetDefaultShell(0);
958 UxUtype_init();
959 UxDDInit();
960 /*
961 Since MsgDialogType is only an alias to the resource DialogType,
962 it was added to the SpecialCaseCheck in tools/getputapp.c. This
963 is done to avoid generating bad code (XmNmsgDialogType) in UxGetsMF.c
964 and UxPutsMF.c. Unfortunately, the following call was never generated
965 within UxDDInit() (in runtime/uxddMF.c). So it is added here...
966 */
967 UxDDInstall ("msgDialogType", UxUT_string, UxXT_MsgDialogType);
968 /*
969 *
970 * At this point we are initializing the User defined resources.
971 *
972 */
973 UxAddRuntimeResources();
974
975 GC_init();
976 return;
977 }
978
979 #ifdef MOTIF_WIDGETS
980 /*----------------------------------------------------------------------
981 * NAME: UxOptionInitialize
982 * DESCRIPTION: Starts off our prototyping mode and allows command line
983 * options to be set.
984 * PARAMETERS:
985 * char *rfile -- The resource file of the user's application.
986 * int *arc -- Args from the mainline
987 * char **argc
988 * XrmOptionDescRec *options -- command line arguments
989 * Cardinal num_options -- the number of options
990 * RETURN: The applications top level widget
991 * REVISIONS: 09/11/92 fix3711
992 *--------------------------------------------------------------------*/
993 Widget UxOptionInitialize (rfile, argc, argv, options, num_options)
994 char *rfile;
995 int *argc;
996 char **argv;
997 XrmOptionDescRec *options;
998 Cardinal num_options;
999 {
1000 UxTopLevel = XtAppInitialize(&UxAppContext, rfile,
1001 options, num_options, argc, argv, NULL, NULL, 0);
1002 UxAppInitialize(rfile, argc, argv);
1003
1004 return(UxTopLevel);
1005 }
1006
1007 /*----------------------------------------------------------------------
1008 * NAME: UxInitialize
1009 * DESCRIPTION: Starts off our prototyping mode
1010 * PARAMETERS:
1011 * char *rfile -- The resource file of the user's application.
1012 * int *arc; -- Args from the mainline
1013 * char **argc
1014 * RETURN: The applications top level widget
1015 * REVISIONS: 09/11/92 fix3711
1016 *--------------------------------------------------------------------*/
1017 Widget UxInitialize (rfile, argc, argv)
1018 char *rfile;
1019 int *argc;
1020 char **argv;
1021 {
1022 UxTopLevel = XtAppInitialize(&UxAppContext, rfile,
1023 NULL, 0, argc, argv, NULL, NULL, 0);
1024 UxAppInitialize(rfile, argc, argv);
1025
1026 return(UxTopLevel);
1027 }
1028
1029 /*----------------------------------------------------------------------
1030 * NAME: UxAppInitialize
1031 * DESCRIPTION: Starts off our prototyping mode
1032 * PARAMETERS:
1033 * char *rfile -- The resource file of the user's application.
1034 * int *arc; -- Args from the mainline
1035 * char **argc
1036 * RETURN: The applications top level widget
1037 * REVISIONS: 09/11/92 fix3711
1038 *--------------------------------------------------------------------*/
1039 void UxAppInitialize (rfile, argc, argv)
1040 char *rfile;
1041 int *argc;
1042 char **argv;
1043 {
1044 UxXtInitialize(rfile, argc, argv);
1045 return;
1046 }
1047 #endif /* MOTIF_WIDGETS */
1048
1049 /* ---------------------------------------------------------------------------
1050 NAME: void UxSetDefaultShell ()
1051 INPUT: --
1052 RETURN --
1053 DESCRIPTION: Initializes the shell class used depending on what the
1054 user places int the sub-resource:
1055 CREATION: Sep 24 1988 Visual Edge Software
1056 -- changed to allow setting of UxDefaultShellType
1057 LAST REV: May 92 fix3571 Removed some antique code.
1058 ---------------------------------------------------------------------------*/
1059 void UxSetDefaultShell (shelltype)
1060 char *shelltype;
1061 {
1062 #ifdef MOTIF_WIDGETS
1063 #define DEF_SHELL "toplevel"
1064 #endif /* MOTIF_WIDGETS */
1065
1066 dstring ds;
1067
1068 if (shelltype == 0)
1069 UxDefaultShellType = UxGetUimxDefault("defaultShell", DEF_SHELL);
1070 else
1071 UxDefaultShellType = shelltype;
1072
1073 /* store these in permanent storage */
1074
1075 ds = dcreate(UxDefaultShellType);
1076 UxDefaultShellType = dnstr(ds);
1077
1078 #ifdef MOTIF_WIDGETS
1079 if (UxStrEqual(UxDefaultShellType, DEF_SHELL))
1080 UxUserShell = (char*) topLevelShellWidgetClass;
1081 else if (UxStrEqual(UxDefaultShellType, "transient"))
1082 UxUserShell = (char*) transientShellWidgetClass;
1083 else
1084 UxUserShell = (char*) overrideShellWidgetClass;
1085
1086 #endif /* MOTIF_WIDGETS */
1087 }
1088
1089
1090 /*---------------------------------------------------------------------------
1091 NAME: Widget UxRealWidget (rs)
1092 INPUT: swidget s
1093 RETURN: real widget (if shell get parent widget)
1094 DESCRIPTION: get the real widget for UIMX.
1095 CREATION: Feb 27/1989
1096 REVISIONS: March 93 fix3963 UxIsSwidget now called.
1097 -----------------------------------------------------------------------------*/
1098 Widget UxRealWidget (s)
1099 swidget s;
1100 {
1101 Widget wp;
1102 swidget sp;
1103 Widget wid = UxGetWidget(s);
1104
1105 if (wid)
1106 {
1107 if (XtIsSubclass(wid, shellWidgetClass))
1108 return(wid);
1109
1110 sp = UxGetParent(s);
1111 wp = XtParent(wid);
1112
1113 if (!UxIsSwidget(sp))
1114 return(wp ? wp : wid);
1115 else if (wp && XtIsSubclass(wp, shellWidgetClass))
1116 return wp;
1117 else
1118 return wid;
1119 }
1120 return (Widget)0;
1121 }
1122 /*--------------------------------------------------------------------------
1123 NAME: UxAddTranslations (s, t)
1124 INPUT: swidget s, String t
1125 RETURN: --
1126 DESCRIPTION: add translation to swidget
1127 CREATION: 25 May 1989
1128 REVISIONS: Sept 1989
1129 add ol virtual convertion.
1130 04 1990
1131 -- Handles policy: the switch statement is just a work around
1132 a Motif bug.
1133 --------------------------------------------------------------------------*/
1134 void UxAddTranslations (s, t)
1135 swidget s;
1136 String t;
1137 {
1138 XtTranslations tr;
1139 Arg a[1];
1140 char *policy;
1141 Widget w = UxGetWidget(s);
1142
1143 if (w && t)
1144 {
1145 #ifdef MOTIF_WIDGETS
1146 tr = XtParseTranslationTable (t);
1147 #endif /* MOTIF_WIDGETS */
1148
1149 policy = t;
1150 if (*policy == '#') {
1151 policy++;
1152 switch (*policy) {
1153 case 'r':
1154 XtSetArg(a[0], XtNtranslations, tr);
1155 XtSetValues(w, a, 1);
1156 break;
1157 case 'a':
1158 XtAugmentTranslations(w, tr);
1159 break;
1160 case 'o':
1161 default:
1162 XtOverrideTranslations(w, tr);
1163 break;
1164 }
1165 } else {
1166 XtOverrideTranslations(w, tr);
1167 }
1168 }
1169 }
1170
1171 /*--------------------------------------------------------------------------
1172 NAME: void GC_init ()
1173 INPUT: --
1174 RETURN: --
1175 DESCRIPTION: create graphic context
1176 CREATION: 25 May 1989
1177 REVISIONS: --
1178 --------------------------------------------------------------------------*/
1179 static void GC_init ()
1180 {
1181 Window root;
1182 XGCValues xgc;
1183
1184 if (!UxDrawGC) {
1185
1186 root = XRootWindow(UxDisplay, UxScreen);
1187 xgc.foreground = 0xfd;
1188 xgc.function = GXxor;
1189 xgc.subwindow_mode = IncludeInferiors;
1190 UxDrawGC = XCreateGC(UxDisplay, DefaultRootWindow(UxDisplay),
1191 GCForeground | GCFunction | GCSubwindowMode, &xgc);
1192
1193 xgc.foreground = BlackPixel(UxDisplay, UxScreen);
1194 xgc.background = WhitePixel(UxDisplay, UxScreen);
1195 UxUimxBlackGC = XCreateGC(UxDisplay, root, GCForeground | GCBackground,
1196 &xgc);
1197 }
1198 }
1199
1200 /*--------------------------------------------------------------------------
1201 NAME: NameToSwidget (sw, name)
1202 INPUT: swidget sw
1203 char *name
1204 RETURN:
1205 DESCRIPTION:
1206 CREATION: 1. March.90
1207 REVISIONS: 16, March, 90
1208 -- gadget does not have name and has no children,
1209 add XrmQuarkToString to get gadget name
1210 --------------------------------------------------------------------------*/
1211 static Widget NameToWidget (wid, name)
1212 Widget wid;
1213 char *name;
1214 {
1215 WidgetList w_children;
1216 unsigned int nc, i;
1217 Widget w = (Widget)0;
1218
1219 if (wid){
1220 if (!XtIsSubclass(wid, widgetClass)) {
1221 if (UxStrEqual(XrmQuarkToString(wid->core.xrm_name), name))
1222 return wid;
1223 }
1224 else if ((w = XtNameToWidget(wid, name)))
1225 return w;
1226 else if ((UxQueryTree(wid, &w_children, &nc))){
1227 for (i =0; i < nc; i++)
1228 if ((w = NameToWidget(w_children[i], name)))
1229 break;
1230 free(w_children);
1231 }
1232 }
1233 return w;
1234 }
1235
1236 /*--------------------------------------------------------------------------
1237 NAME: swidget UxNameToSwidget (ref, name)
1238 INPUT: char *name
1239 swidget ref
1240 RETURN: swidget
1241 DESCRIPTION: given a widget name and a reference swidget
1242 return it's swidget object if that object exist as
1243 a child or as a sibling.
1244 CREATION: 25 May 1989
1245 LAST REV: May 7, 1991 See bugfix 2311.
1246 -- Modified to start search at parent rather than grand-parent.
1247 If search fails then do search over again starting at grand-
1248 parent if one exists.
1249 --------------------------------------------------------------------------*/
1250
1251 swidget UxNameToSwidget (ref, name)
1252 swidget ref;
1253 char *name;
1254 {
1255 Widget w;
1256 swidget parent = UxGetParent(ref);
1257 Widget wid = UxGetWidget(parent);
1258
1259 /*
1260 * Search for widget starting at parent. If not found and there
1261 * is a grand-parent then restart search at grand-parent. If still
1262 * not found then do global search.
1263 */
1264
1265 if (wid)
1266 w = NameToWidget(wid, name);
1267 else
1268 w = NameToWidget(UxGetWidget(ref), name);
1269
1270 if (wid && ! w) {
1271 Widget pwid = XtParent(wid);
1272
1273 if (pwid)
1274 w = NameToWidget(pwid, name);
1275 }
1276
1277 if (w) {
1278 return UxWidgetToSwidget(w);
1279 } else {
1280
1281 /* named swidget not in "ref" widget tree so */
1282 /* find the first occurence of the named swidget in the */
1283 /* swidget table. Note that for multiple instances */
1284 /* interface this may not get the appropriate swidget */
1285
1286 return UxFindSwidget(name);
1287 }
1288 }
1289
1290 /*--------------------------------------------------------------------------
1291 NAME: Widget UxShellWidget (sw)
1292 INPUT: swidget sw
1293 RETURN: Widget
1294 DESCRIPTION: gaven the swidget return it's most top Widget
1295 CREATION: 13, Sept. 1989
1296 REVISIONS: 19, Sept. 1989
1297 XtParent get extra parent, So add parentwp to keep
1298 Shell Widget
1299 --------------------------------------------------------------------------*/
1300
1301 Widget UxShellWidget (sw)
1302 swidget sw;
1303 {
1304 Widget wp, parentwp = (Widget) NULL;
1305 Widget w = UxGetWidget (sw);
1306
1307 if (w)
1308 {
1309 while ((wp = XtParent(w)))
1310 {
1311 parentwp = w;
1312 w = wp;
1313 }
1314 }
1315 return parentwp? parentwp: w;
1316 }
1317
1318
1319 /*--------------------------------------------------------------------------
1320 NAME: void UxTextAppend (w, string)
1321 INPUT: Widget w
1322 char *string
1323 DESCRIPTION: appends 'string' to the end of the buffer
1324 CREATION: Jun 30 1988, Visual Edge Software
1325 REVISION: July 11, 1989
1326 -- added support for Motif widgets
1327 July 15
1328 -- added OpenLook support
1329 July 16, 1990
1330 -- changed the second parameter from `string` to `str`
1331 because `string` is a typedef for some compiliers.
1332 Nov 19/91 fix3189
1333 ---------------------------------------------------------------------------*/
1334 void UxTextAppend (w, str)
1335 Widget w;
1336 char *str;
1337 {
1338 #ifdef MOTIF_WIDGETS
1339 int last_position;
1340
1341 last_position = XmTextGetLastPosition(w);
1342 XmTextReplace(w, last_position, last_position, str);
1343 /*
1344 * get last position again so that last part of
1345 * message is visible in message window
1346 */
1347 last_position = XmTextGetLastPosition(w);
1348 XmTextShowPosition(w, last_position);
1349 #endif /* MOTIF_WIDGETS */
1350 }
1351
1352
1353
1354 /*--------------------------------------------------------------------------
1355 NAME: UxQueryTree (widget, wid_children, nc)
1356 INPUT: Widget widget, WidgetList *wid_children, unsigned int *nc
1357 RETURN: if given widget has children 1 otherwise return 0
1358 DESCRIPTION: given widget copy its children widget list to *wid_children
1359 and copy the total number of children to *nc.
1360 CREATION: 12, Oct. 89
1361 REVISIONS: 15. Nov. 89
1362 fixed popup childdren list index error.
1363 --------------------------------------------------------------------------*/
1364
1365 int UxQueryTree (widget, wid_children, nc)
1366 Widget widget;
1367 WidgetList *wid_children;
1368 unsigned int *nc;
1369 {
1370 WidgetList wlist, plist;
1371 int i, np, n, size;
1372 CompositeWidget w;
1373
1374
1375 wlist = plist = (WidgetList) 0;
1376
1377 if (widget && XtIsSubclass(widget, widgetClass))
1378 {
1379 if (XtIsComposite(widget))
1380 {
1381 w = (CompositeWidget) widget;
1382 if ((*nc = tree_num_children(w)))
1383 wlist = tree_children(w);
1384 } else {
1385 *nc = 0;
1386 }
1387
1388 if ((np = tree_num_popups(widget)))
1389 plist = tree_popups(widget);
1390
1391 if ((n = *nc + np))
1392 {
1393 size = n*sizeof(Widget);
1394 if ((*wid_children = (WidgetList) UxMalloc(size)))
1395 {
1396 for (i = 0; i < *nc; i++)
1397 (*wid_children)[i]= wlist[i];
1398 for (i = *nc; i < n; i++)
1399 (*wid_children)[i]= plist[i - *nc];
1400 *nc = n;
1401 return 1;
1402 }
1403 }
1404 }
1405 return 0;
1406 }
1407
1408 /*--------------------------------------------------------------------------
1409 NAME: DestroyTree (sw)
1410 INPUT: swidget sw.
1411 RETURN:
1412 DESCRIPTION: Delete given swidget and its children.
1413 CREATION: 12. Oct. 89
1414 REVISIONS:
1415 --------------------------------------------------------------------------*/
1416 static void DestroyTree (sw)
1417 swidget sw;
1418 {
1419 Widget w = UxRealWidget(sw);
1420
1421 if (w)
1422 DestroyWidgetTree(w);
1423 }
1424
1425 /******************************************************************************
1426 NAME: int IsImplicitShell (sw)
1427
1428 INPUT: swidget sw - swidget to check
1429
1430 RETURN: 1 or 0
1431
1432 DESCRIPTION: Return whether this swidget has an implicit shell or not.
1433 It will only work correctly after the widget is created.
1434
1435 It is an implicit shell if
1436 there is no realized swidget parent, and
1437 the widget itself is not a shell.
1438
1439 CREATION: Aug 02/1990
1440 REVISIONS: --
1441 -----------------------------------------------------------------------------*/
1442
1443 static int IsImplicitShell (sw)
1444 swidget sw;
1445 {
1446 Widget wid = UxGetWidget(sw);
1447 Widget pwid = UxGetWidget(UxGetParent(sw));
1448
1449 if (!pwid && !XtIsSubclass(wid, shellWidgetClass))
1450 return(1);
1451
1452 return (0);
1453 }
1454
1455 /*--------------------------------------------------------------------------
1456 NAME: DestroyWidgetTree (widget)
1457 INPUT: widget
1458 RETURN:
1459 DESCRIPTION: given widget find all its children and delete its corresponding Swidget.
1460 CREATION: 12. Oct. 89
1461 REVISIONS: March 93 fix3963 UxIsSwidget now called.
1462 --------------------------------------------------------------------------*/
1463
1464 static void DestroyWidgetTree (widget)
1465 Widget widget;
1466 {
1467 WidgetList w_children;
1468 unsigned int nc, i;
1469 swidget sw;
1470
1471 if (widget)
1472 {
1473 if (UxQueryTree(widget, &w_children, &nc))
1474 {
1475 for (i =0; i < nc; i++)
1476 DestroyWidgetTree(w_children[i]);
1477
1478 free (w_children);
1479 }
1480
1481 sw = UxWidgetToSwidget(widget);
1482
1483 if (UxIsSwidget(sw))
1484 {
1485 if (IsImplicitShell(sw))
1486 RemoveWidgets(widget, UxRealWidget(sw));
1487 else
1488 RemoveWidgets(widget, 0);
1489
1490 UxFreeSwidget(sw);
1491 }
1492 }
1493 }
1494
1495
1496 /******************************************************************************
1497 NAME: int UxStrEqual (str1, str2)
1498 INPUTS: char *str1, *str2;
1499 RETURN: 1 if the strings are equal, 0 otherwise
1500
1501 DESCRIPTION: Compares two strings and returns 1 if they are equal, 0
1502 otherwise. This routine checks for NULL pointers. If both
1503 pointers are NULL, the strings are equal. If only one
1504 pointer is NULL, the strings are not equal.
1505
1506 CREATION: july/29/91 fix2823
1507 REVISIONS: --
1508 -----------------------------------------------------------------------------*/
1509
1510 int UxStrEqual (str1, str2)
1511 char *str1, *str2;
1512 {
1513 if (str1 == str2)
1514 return 1; /* both same ptr (maybe NULL) */
1515
1516 else if (!str1 || !str2)
1517 return 0; /* one is NULL and one is not */
1518
1519 else if (*str1 == *str2) /* This often saves a fn call */
1520 return !strcmp(str1, str2);
1521
1522 else
1523 return 0;
1524 }
1525
1526 /*------------------------------------------------------------------------
1527 * The table of all widgets.
1528 *------------------------------------------------------------------------*/
1529
1530 typedef struct WidRec
1531 {
1532 Widget TheWidget;
1533 swidget TheSwidget;
1534 } WidRec_t;
1535
1536 static WidRec_t * AllWidgets = 0;
1537 static int NumWidgets = 0;
1538 static int MaxWidgets = 0;
1539 #define TABLEBLOCK 100
1540
1541 /*-----------------------------------------------------------------------------
1542 NAME: void RecordWidget (w, m)
1543 INPUT: Widget w, swidget m
1544 RETURN:
1545 DESCRIPTION: record widget swidget pair to widget table
1546 CREATION:
1547 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
1548 -----------------------------------------------------------------------------*/
1549
1550 static void RecordWidget (w, m)
1551 Widget w;
1552 swidget m;
1553 {
1554 if (MaxWidgets <= NumWidgets)
1555 {
1556 AllWidgets = (WidRec_t*)
1557 UxRealloc(AllWidgets,
1558 (MaxWidgets += TABLEBLOCK) * sizeof(WidRec_t));
1559 }
1560
1561 AllWidgets[NumWidgets].TheWidget = w;
1562 AllWidgets[NumWidgets].TheSwidget = m;
1563
1564 NumWidgets ++;
1565 }
1566
1567 /*-----------------------------------------------------------------------------
1568 NAME: swidget UxWidgetToSwidget (w)
1569 INPUT: Widget w
1570 RETURN: swidget
1571 DESCRIPTION: given object Widget return it's corresponding swidget
1572 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
1573 -----------------------------------------------------------------------------*/
1574
1575 swidget UxWidgetToSwidget (w)
1576 Widget w;
1577 {
1578 int i;
1579 for (i = 0; i < NumWidgets; i++)
1580 {
1581 if (AllWidgets[i].TheWidget == w)
1582 {
1583 return AllWidgets[i].TheSwidget;
1584 }
1585 }
1586
1587 return NULL;
1588 }
1589
1590 /*--------------------------------------------------------------------------
1591 NAME: swidget UxFindSwidget (name)
1592 INPUT: char *name
1593 RETURN: swidget
1594 DESCRIPTION: given a widgetname return it's swidget object
1595 CREATION: 25 May 1989
1596 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
1597 --------------------------------------------------------------------------*/
1598
1599 swidget UxFindSwidget (name)
1600 char *name;
1601 {
1602 int i;
1603 for (i = NumWidgets-1; i >= 0; i--)
1604 {
1605 if (UxStrEqual(name, AllWidgets[i].TheSwidget->Name))
1606 return AllWidgets[i].TheSwidget;
1607 }
1608 return NULL_SWIDGET;
1609 }
1610
1611 /*------------------------------------------------------------------------
1612 * NAME: RemoveWidgets
1613 * INPUT:
1614 * Widget wid1; -- to be removed from global table
1615 * Widget wid2; -- to be removed from global table
1616 *
1617 * DESCRIPTION:
1618 * Removes one or two widgets from the AllWidgets table,
1619 * shifting down all higher entries so the table is contiguous.
1620 *
1621 * We do two, rather than one, to speed a bit the case
1622 * where we destroy an implicit shell; the manager and shell
1623 * Widgets can both be removed at one pass.
1624 *
1625 * LAST REV: May 92 fix3571 Runtime swidgets are pointers.
1626 *------------------------------------------------------------------------*/
1627
1628 static void RemoveWidgets (wid1, wid2)
1629 Widget wid1;
1630 Widget wid2;
1631 {
1632 int i;
1633 int Shifting = 0; /* # of positions we're shifting down */
1634
1635 for (i = 0; i < NumWidgets; i++)
1636 {
1637 if (Shifting) {
1638 AllWidgets[i-Shifting] = AllWidgets[i];
1639 }
1640
1641 /*-----------------------------------------------------
1642 * As we find the entries we want, we just increment
1643 * Shifting, so the scan will slide down the rest.
1644 *-----------------------------------------------------*/
1645
1646 if (wid1 && AllWidgets[i].TheWidget == wid1)
1647 {
1648 wid1 = 0;
1649 Shifting++;
1650 }
1651 else if (wid2 && AllWidgets[i].TheWidget == wid2)
1652 {
1653 wid2 = 0;
1654 Shifting++;
1655 }
1656 }
1657 NumWidgets -= Shifting;
1658 }
1659
1660 /*--------------------------------------------------------------------------
1661 NAME: Widget UxWindowToWidget (win)
1662 INPUT: Window win.
1663 RETURN: given Window win return its Widget.
1664 DESCRIPTION:
1665 CREATION: 12. Oct. 89
1666 LAST REV: May 92 fix3571 Runtime swidgets are pointers.
1667 --------------------------------------------------------------------------*/
1668
1669 Widget UxWindowToWidget (win)
1670 Window win;
1671 {
1672 int i;
1673 for (i = NumWidgets-1; i>= 0; i--)
1674 {
1675 if (XtWindow(AllWidgets[i].TheWidget) == win)
1676 return AllWidgets[i].TheWidget;
1677 }
1678 return (Widget) 0;
1679 }