1 /**
2  *
3  * $Header: /cvsroot/lesstif/lesstif/lib/Xm-2.1/Manager.c,v 1.6 2007/09/12 20:29:35 jwrdegoede Exp $
4  *
5  * Copyright (C) 1995 Free Software Foundation, Inc.
6  * Copyright � 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 static const char rcsid[] = "$Header: /cvsroot/lesstif/lesstif/lib/Xm-2.1/Manager.c,v 1.6 2007/09/12 20:29:35 jwrdegoede Exp $";
27 
28 #include <LTconfig.h>
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #include <XmI/XmI.h>
35 #include <XmI/TraversalI.h>
36 
37 #include <Xm/XmP.h>
38 #include <Xm/BaseClassP.h>
39 #include <Xm/ManagerP.h>
40 #include <Xm/GadgetP.h>
41 #include <Xm/RepType.h>
42 #include <Xm/TransltnsP.h>
43 #include <X11/keysym.h>
44 #include <Xm/VirtKeysP.h>
45 
46 /* For determining class type */
47 #include <Xm/CascadeBP.h>
48 #include <Xm/CascadeBGP.h>
49 #include <Xm/MenuUtilP.h>
50 
51 /*
52  * Yes I know this is crazy... Danny
53  */
54 #include <Xm/RowColumnP.h>
55 #include <Xm/DialogS.h>
56 
57 #include <XmI/ManagerI.h>
58 /*
59  * Traits
60  */
61 #include <Xm/TraitP.h>
62 #include <Xm/LayoutT.h>
63 #include <XmI/DirectionI.h>
64 #include <Xm/CareVisualT.h>
65 
66 #include <XmI/DebugUtil.h>
67 
68 static XmDirection get_direction(Widget w);
69 
70 static XmSpecifyLayoutDirectionTraitRec _XmManagerLayoutTraitRec =
71 {
72     0,				/* version */
73     get_direction		/* getValue */
74 };
75 
76 
77 /* Forward Declarations */
78 static void class_initialize(void);
79 static void class_part_initialize(WidgetClass w_class);
80 static void initialize(Widget request, Widget new_w,
81 		       ArgList args, Cardinal *num_args);
82 static void realize(Widget w, XtValueMask *value_mask,
83 		    XSetWindowAttributes *attributes);
84 static void destroy(Widget w);
85 static Boolean set_values(Widget current, Widget request, Widget new_w,
86 			  ArgList args, Cardinal *num_args);
87 
88 static void constraint_initialize(Widget request, Widget new_w,
89 				  ArgList args, Cardinal *num_args);
90 static XmNavigability widget_navigable(Widget w);
91 void _XmManagerInstallAccelerator(Widget m, Widget w, String s);
92 static void _XmManagerExportX(Widget w, int offset, XtArgVal *value);
93 static void _XmManagerExportY(Widget w, int offset, XtArgVal *value);
94 
95 /* action routine prototypes */
96 void _XmGadgetButtonMotion(Widget w, XEvent *event,
97 			   String *params, Cardinal *num_params);
98 void _XmGadgetArm(Widget w, XEvent *event,
99 		  String *params, Cardinal *num_params);
100 void _XmGadgetActivate(Widget w, XEvent *event,
101 		       String *params, Cardinal *num_params);
102 void _XmGadgetMultiArm(Widget w, XEvent *event,
103 		       String *params, Cardinal *num_params);
104 void _XmGadgetMultiActivate(Widget w, XEvent *event,
105 			    String *params, Cardinal *num_params);
106 void _XmGadgetDrag(Widget w, XEvent *event,
107 		   String *params, Cardinal *num_params);
108 void _XmGadgetSelect(Widget w, XEvent *event,
109 		     String *params, Cardinal *num_params);
110 void _XmManagerParentActivate(Widget w, XEvent *event,
111 			      String *params, Cardinal *num_params);
112 void _XmManagerParentCancel(Widget w, XEvent *event,
113 			    String *params, Cardinal *num_params);
114 void _XmGadgetTraversePrevTabGroup(Widget w, XEvent *event,
115 				   String *params, Cardinal *num_params);
116 void _XmGadgetTraverseNextTabGroup(Widget w, XEvent *event,
117 				   String *params, Cardinal *num_params);
118 void _XmGadgetTraversePrev(Widget w, XEvent *event,
119 			   String *params, Cardinal *num_params);
120 void _XmGadgetTraverseNext(Widget w, XEvent *event,
121 			   String *params, Cardinal *num_params);
122 void _XmGadgetTraverseUp(Widget w, XEvent *event,
123 			 String *params, Cardinal *num_params);
124 void _XmGadgetTraverseDown(Widget w, XEvent *event,
125 			   String *params, Cardinal *num_params);
126 void _XmGadgetTraverseLeft(Widget w, XEvent *event,
127 			   String *params, Cardinal *num_params);
128 void _XmGadgetTraverseRight(Widget w, XEvent *event,
129 			    String *params, Cardinal *num_params);
130 void _XmGadgetTraverseHome(Widget w, XEvent *event,
131 			   String *params, Cardinal *num_params);
132 void _XmGadgetHelp(Widget w, XEvent *event,
133 		   String *params, Cardinal *num_params);
134 void _XmGadgetKeyInput(Widget w, XEvent *event,
135 		       String *params, Cardinal *num_params);
136 void _XmGadgetHelp(Widget w, XEvent *event,
137 		   String *params, Cardinal *num_params);
138 
139 
140 /*
141  * the event handler to handle pointer position related events for gadget
142  * children
143  */
144 static void _XmManagerEventHandler(Widget w, XtPointer data,
145 				   XEvent *event, Boolean *cont);
146 
147 static XtActionsRec actions[] =
148 {
149     {"ManagerEnter", _XmManagerEnter},
150     {"ManagerLeave", _XmManagerLeave},
151     {"ManagerFocusIn", _XmManagerFocusIn},
152     {"ManagerFocusOut", _XmManagerFocusOut},
153     {"ManagerGadgetPrevTabGroup", _XmGadgetTraversePrevTabGroup},
154     {"ManagerGadgetNextTabGroup", _XmGadgetTraverseNextTabGroup},
155     {"ManagerGadgetTraversePrev", _XmGadgetTraversePrev},
156     {"ManagerGadgetTraverseNext", _XmGadgetTraverseNext},
157     {"ManagerGadgetTraverseLeft", _XmGadgetTraverseLeft},
158     {"ManagerGadgetTraverseRight", _XmGadgetTraverseRight},
159     {"ManagerGadgetTraverseUp", _XmGadgetTraverseUp},
160     {"ManagerGadgetTraverseDown", _XmGadgetTraverseDown},
161     {"ManagerGadgetTraverseHome", _XmGadgetTraverseHome},
162     {"ManagerGadgetSelect", _XmGadgetSelect},
163     {"ManagerParentActivate", _XmManagerParentActivate},
164     {"ManagerParentCancel", _XmManagerParentCancel},
165     {"ManagerGadgetButtonMotion", _XmGadgetButtonMotion},
166     {"ManagerGadgetKeyInput", _XmGadgetKeyInput},
167     {"ManagerGadgetHelp", _XmGadgetHelp},
168     {"ManagerGadgetArm", _XmGadgetArm},
169     {"ManagerGadgetDrag", _XmGadgetDrag},
170     {"ManagerGadgetActivate", _XmGadgetActivate},
171     {"ManagerGadgetMultiArm", _XmGadgetMultiArm},
172     {"ManagerGadgetMultiActivate", _XmGadgetMultiActivate},
173     {"Enter", _XmManagerEnter},
174     {"FocusIn", _XmManagerFocusIn},
175     {"Help", _XmGadgetHelp},
176     {"Arm", _XmGadgetArm},
177     {"Activate", _XmGadgetActivate},
178 
179     {"ManagerGadgetMultiArm", _XmGadgetMultiArm},
180 };
181 
182 #define Offset(field) XtOffsetOf(XmManagerRec, manager.field)
183 
184 /* Resources for the manager class */
185 static XtResource resources[] =
186 {
187     {
188 	XmNunitType, XmCUnitType, XmRUnitType,
189 	sizeof(unsigned char), Offset(unit_type),
190 	XmRCallProc, (XtPointer)_XmUnitTypeDefault
191     },
192     {
193 	XmNx, XmCPosition, XmRHorizontalPosition,
194 	sizeof(Position), XtOffsetOf(XmManagerRec, core.x),
195 	XmRImmediate, (XtPointer)0
196     },
197     {
198 	XmNy, XmCPosition, XmRVerticalPosition,
199 	sizeof(Position), XtOffsetOf(XmManagerRec, core.y),
200 	XmRImmediate, (XtPointer)0
201     },
202     {
203 	XmNwidth, XmCDimension, XmRHorizontalDimension,
204 	sizeof(Dimension), XtOffsetOf(XmManagerRec, core.width),
205 	XmRImmediate, (XtPointer)0
206     },
207     {
208 	XmNheight, XmCDimension, XmRVerticalDimension,
209 	sizeof(Dimension), XtOffsetOf(XmManagerRec, core.height),
210 	XmRImmediate, (XtPointer)0
211     },
212     {
213 	XmNborderWidth, XmCBorderWidth, XmRHorizontalDimension,
214 	sizeof(Dimension), XtOffsetOf(XmManagerRec, core.border_width),
215 	XmRImmediate, (XtPointer)0
216     },
217     {
218 	XmNforeground, XmCForeground, XmRPixel,
219 	sizeof(Pixel), Offset(foreground),
220 	XmRCallProc, (XtPointer)_XmForegroundColorDefault
221     },
222     {
223 	XmNbackground, XmCBackground, XmRPixel,
224 	sizeof(Pixel), XtOffsetOf(XmManagerRec, core.background_pixel),
225 	XmRCallProc, (XtPointer)_XmBackgroundColorDefault
226     },
227     {
228 	XmNbackgroundPixmap, XmCPixmap, XmRXmBackgroundPixmap,
229 	sizeof(Pixmap), XtOffsetOf(XmManagerRec, core.background_pixmap),
230 	XmRImmediate, (XtPointer)XmUNSPECIFIED_PIXMAP
231     },
232     {
233 	XmNhighlightColor, XmCHighlightColor, XmRPixel,
234 	sizeof(Pixel), Offset(highlight_color),
235 	XmRCallProc, (XtPointer)_XmHighlightColorDefault
236     },
237     {
238 	XmNhighlightPixmap, XmCHighlightPixmap, XmRManHighlightPixmap,
239 	sizeof(Pixmap), Offset(highlight_pixmap),
240 	XmRCallProc, (XtPointer)_XmManagerHighlightPixmapDefault
241     },
242     {
243 	XmNnavigationType, XmCNavigationType, XmRNavigationType,
244 	sizeof(XmNavigationType), Offset(navigation_type),
245 	XmRImmediate, (XtPointer)XmTAB_GROUP
246     },
247     {
248 	XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension,
249 	sizeof(Dimension), Offset(shadow_thickness),
250 	XmRImmediate, (XtPointer)0
251     },
252     {
253 	XmNtopShadowColor, XmCTopShadowColor, XmRPixel,
254 	sizeof(Pixel), Offset(top_shadow_color),
255 	XmRCallProc, (XtPointer)_XmTopShadowColorDefault
256     },
257     {
258 	XmNtopShadowPixmap, XmCTopShadowPixmap, XmRManTopShadowPixmap,
259 	sizeof(Pixmap), Offset(top_shadow_pixmap),
260 	XmRCallProc, (XtPointer)_XmManagerTopShadowPixmapDefault
261     },
262     {
263 	XmNbottomShadowColor, XmCBottomShadowColor, XmRPixel,
264 	sizeof(Pixel), Offset(bottom_shadow_color),
265 	XmRCallProc, (XtPointer)_XmBottomShadowColorDefault
266     },
267     {
268 	XmNbottomShadowPixmap, XmCBottomShadowPixmap, XmRManBottomShadowPixmap,
269 	sizeof(Pixmap), Offset(bottom_shadow_pixmap),
270 	XtRImmediate, (XtPointer)XmUNSPECIFIED_PIXMAP
271     },
272     {
273 	XmNhelpCallback, XmCCallback, XmRCallback,
274 	sizeof(XtCallbackList), Offset(help_callback),
275 	XtRPointer, (XtPointer)NULL
276     },
277     {
278 	XmNuserData, XmCUserData, XmRPointer,
279 	sizeof(XtPointer), Offset(user_data),
280 	XmRPointer, (XtPointer)NULL
281     },
282     {
283 	XmNtraversalOn, XmCTraversalOn, XmRBoolean,
284 	sizeof(Boolean), Offset(traversal_on),
285 	XmRImmediate, (XtPointer)True
286     },
287     {
288 	XmNstringDirection, XmCStringDirection, XmRStringDirection,
289 	sizeof(XmStringDirection), Offset(string_direction),
290 	XmRImmediate, (XtPointer)((XmStringDirection)XmUNSPECIFIED)
291     },
292     {
293 	XmNinitialFocus, XmCInitialFocus, XmRWidget,
294 	sizeof(Widget), Offset(initial_focus),
295 	XmRImmediate, (XtPointer)NULL
296     }
297     ,
298     {
299 	XmNpopupHandlerCallback, XmCCallback, XmRCallback,
300 	sizeof(XtCallbackList), Offset(popup_handler_callback),
301 	XtRPointer, (XtPointer)NULL
302     }
303     ,
304     {
305 	XmNlayoutDirection, XmCLayoutDirection, XmRDirection,
306 	sizeof(XmDirection), Offset(string_direction),
307 	XmRImmediate, (XtPointer)((XmDirection) NULL)	/* dynamic how? */
308     }
309 };
310 
311 #define MOffset(field)	XtOffset(XmManagerWidget, manager.field)
312 #define COffset(field)	XtOffset(XmManagerWidget, core.field)
313 static XmSyntheticResource syn_resources[] =
314 {
315     /* core part */
316     {
317 	XmNx,
318 	sizeof(Position), COffset(x),
319 	_XmManagerExportX, _XmToHorizontalPixels
320     },
321     {
322 	XmNy,
323 	sizeof(Position),
324 	COffset(y),
325 	_XmManagerExportY, _XmToVerticalPixels
326     },
327     {
328 	XmNwidth,
329 	sizeof(Dimension), COffset(width),
330 	_XmFromHorizontalPixels, _XmToHorizontalPixels
331     },
332     {
333 	XmNheight,
334 	sizeof(Dimension), COffset(height),
335 	_XmFromVerticalPixels, _XmToVerticalPixels
336     },
337     {
338 	XmNborderWidth,
339 	sizeof(Dimension), COffset(border_width),
340 	_XmFromHorizontalPixels, _XmToHorizontalPixels
341     },
342     /* manager */
343     {
344 	XmNshadowThickness,
345 	sizeof(Dimension), MOffset(shadow_thickness),
346 	_XmFromHorizontalPixels, _XmToHorizontalPixels
347     },
348     {
349 	XmNstringDirection,
350 	sizeof(XmStringDirection), MOffset(string_direction),
351 	_XmFromLayoutDirection, _XmToLayoutDirection
352     },
353 };
354 
355 static XmBaseClassExtRec _XmManagerCoreClassExtRec = {
356     /* next_extension            */ NULL,
357     /* record_type               */ NULLQUARK,
358     /* version                   */ XmBaseClassExtVersion,
359     /* size                      */ sizeof(XmBaseClassExtRec),
360     /* initialize_prehook        */ NULL,
361     /* set_values_prehook        */ NULL,
362     /* initialize_posthook       */ NULL,
363     /* set_values_posthook       */ NULL,
364     /* secondary_object_class    */ NULL,
365     /* secondary_object_create   */ NULL,
366     /* get_secondary_resources   */ NULL,
367     /* fast_subclass             */ { 0 },
368     /* get_values_prehook        */ NULL,
369     /* get_values_posthook       */ NULL,
370     /* class_part_init_prehook   */ NULL,
371     /* class_part_init_posthook  */ NULL,
372     /* ext_resources             */ NULL,
373     /* compiled_ext_resources    */ NULL,
374     /* num_ext_resources         */ 0,
375     /* use_sub_resources         */ False,
376     /* widget_navigable          */ widget_navigable,
377     /* focus_change              */ NULL,
378     /* wrapper_data              */ NULL
379 };
380 
381 static CompositeClassExtensionRec managerCompositeExt =
382 {
383     /* next_extension */  NULL,
384     /* record_type    */  NULLQUARK,
385     /* version        */  XtCompositeExtensionVersion,
386     /* record_size    */  sizeof(CompositeClassExtensionRec),
387     /* accepts_objects */ True,
388 #if XtSpecificationRelease >= 6
389     /* allows_change_managed_set */ False
390 #endif
391 };
392 
393 static XmManagerClassExtRec _XmManagerClassExtRec = {
394     /* next_extension            */ NULL,
395     /* record_type               */ NULLQUARK,
396     /* version                   */ XmManagerClassExtVersion,
397     /* record_size               */ sizeof(XmManagerClassExtRec),
398     /* traversal_children        */ NULL /* FIX ME */
399 };
400 
401 XmManagerClassRec xmManagerClassRec = {
402     /* Core class part */
403     {
404 	/* superclass            */ (WidgetClass) &constraintClassRec,
405         /* class_name            */ "XmManager",
406 	/* widget_size           */ sizeof(XmManagerRec),
407 	/* class_initialize      */ class_initialize,
408 	/* class_part_initialize */ class_part_initialize,
409 	/* class_inited          */ False,
410 	/* initialize            */ initialize,
411 	/* initialize_hook       */ NULL,
412 	/* realize               */ realize,
413 	/* actions               */ actions,
414 	/* num_actions           */ XtNumber(actions),
415 	/* resources             */ resources,
416 	/* num_resources         */ XtNumber(resources),
417 	/* xrm_class             */ NULLQUARK,
418 	/* compress_motion       */ True,
419 	/* compress_exposure     */ XtExposeCompressMaximal /*XtExposeCompressMultiple*/,
420 	/* compress_enterleave   */ True,
421 	/* visible_interest      */ False,
422 	/* destroy               */ destroy,
423 	/* resize                */ NULL,
424 	/* expose                */ NULL,
425 	/* set_values            */ set_values,
426 	/* set_values_hook       */ NULL,
427 	/* set_values_almost     */ XtInheritSetValuesAlmost,
428 	/* get_values_hook       */ _XmManagerGetValuesHook,
429 	/* accept_focus          */ NULL,
430 	/* version               */ XtVersion,
431 	/* callback offsets      */ NULL,
432 	/* tm_table              */ _XmManager_defaultTranslations,
433 	/* query_geometry        */ NULL,
434 	/* display_accelerator   */ NULL /*XtInheritDisplayAccelerator*/,
435 	/* extension             */ (XtPointer)&_XmManagerCoreClassExtRec
436     },
437     /* Composite class part */
438     {
439 	/* geometry manager */ NULL,
440         /* change_managed   */ NULL,
441         /* insert_child     */ XtInheritInsertChild,
442         /* delete_child     */ XtInheritDeleteChild,
443         /* extension        */ (XtPointer)&managerCompositeExt,
444     },
445     /* Constraint class part */
446     {
447 	/* subresources      */ NULL,
448         /* subresource_count */ 0,
449         /* constraint_size   */ 0,
450         /* initialize        */ constraint_initialize,
451         /* destroy           */ NULL,
452         /* set_values        */ NULL,
453         /* extension         */ NULL,
454     },
455     /* XmManager class part */
456     {
457 	/* translations                 */ _XmManager_managerTraversalTranslations,
458         /* syn_resources                */ syn_resources,
459         /* num_syn_resources            */ XtNumber(syn_resources),
460         /* syn_constraint_resources     */ NULL,
461         /* num_syn_constraint_resources */ 0,
462         /* parent_process               */ _XmParentProcess,
463 	/* extension                    */ (XtPointer)&_XmManagerClassExtRec
464     },
465 };
466 
467 
468 
469 
470 WidgetClass xmManagerWidgetClass = (WidgetClass)&xmManagerClassRec;
471 
472 static void
class_initialize(void)473 class_initialize(void)
474 {
475     _XmRegisterConverters();
476     _XmRegisterPixmapConverters();
477     _XmInitializeExtensions();
478     _XmManagerCoreClassExtRec.record_type = XmQmotif;
479 }
480 
481 static void
class_part_initialize(WidgetClass widget_class)482 class_part_initialize(WidgetClass widget_class)
483 {
484     XmManagerWidgetClass mwc = (XmManagerWidgetClass)widget_class;
485     XmManagerWidgetClass swc = (XmManagerWidgetClass)widget_class->core_class.superclass;
486     CompositeClassExtension ext, *extptr;
487 
488     if (mwc->manager_class.translations == XtInheritTranslations)
489     {
490 	mwc->manager_class.translations =
491 	    swc->manager_class.translations;
492     }
493     else if (mwc->manager_class.translations != NULL)
494     {
495 	mwc->manager_class.translations =
496 	    (String)XtParseTranslationTable(mwc->manager_class.translations);
497     }
498     if (mwc->manager_class.parent_process == XmInheritParentProcess)
499     {
500 	mwc->manager_class.parent_process =
501 	    swc->manager_class.parent_process;
502     }
503     extptr = (CompositeClassExtension *)_XmGetClassExtensionPtr(
504 			(XmGenericClassExt *)&(mwc->composite_class.extension),
505 								   NULLQUARK);
506 
507     if (extptr == NULL || *extptr == NULL)
508     {
509 	ext = (CompositeClassExtension)XtNew(CompositeClassExtensionRec);
510 	if (ext != NULL)
511 	{
512 	    ext->next_extension = mwc->composite_class.extension;
513 	    ext->record_type = NULLQUARK;
514 	    ext->version = XtCompositeExtensionVersion;
515 	    ext->record_size = sizeof(CompositeClassExtensionRec);
516 	    ext->accepts_objects = True;
517 #if XtSpecificationRelease >= 6
518 	    ext->allows_change_managed_set = False;
519 #endif
520 	    mwc->composite_class.extension = (XtPointer)ext;
521 	}
522     }
523     /*
524        else
525        {
526        (*extptr)->accepts_objects = True;
527        }
528      */
529 
530 
531     if (widget_class != xmManagerWidgetClass)
532     {
533 	XmManagerClassExt *mce = NULL, *sce = NULL;
534 
535 	mce = _XmGetManagerClassExtPtr(mwc, NULLQUARK);
536 	sce = _XmGetManagerClassExtPtr(swc, NULLQUARK);
537 
538 	if (mce && !*mce && sce && *sce)
539 	{
540 	    *mce =
541 		(XmManagerClassExtRec *)XtCalloc(1, sizeof(XmManagerClassExtRec));
542 	    (*mce)->next_extension = NULL;
543 	    (*mce)->record_type = NULLQUARK;
544 	    (*mce)->version = XmManagerClassExtVersion;
545 	    (*mce)->record_size = sizeof(XmManagerClassExtRec);
546 	    (*mce)->traversal_children = (*sce)->traversal_children;
547 	}
548 	else if (mce && sce && *mce && *sce)
549 	{
550 	    if ((*mce)->traversal_children == XmInheritTraversalChildrenProc)
551 	    {
552 		(*mce)->traversal_children =
553 		    (*sce)->traversal_children;
554 	    }
555 	}
556     }
557 
558     _XmBaseClassPartInitialize(widget_class);
559     _XmFastSubclassInit(widget_class, XmMANAGER_BIT);
560 
561     /* compile the resources */
562     if (widget_class == xmManagerWidgetClass)
563     {
564 	_XmSortResourceList((XrmResource **)mwc->core_class.resources,
565 			    mwc->core_class.num_resources);
566     }
567 
568     _XmInitializeSyntheticResources(mwc->manager_class.syn_resources,
569 				    mwc->manager_class.num_syn_resources);
570     _XmInitializeSyntheticResources(mwc->manager_class.syn_constraint_resources,
571 			      mwc->manager_class.num_syn_constraint_resources);
572 
573     if (widget_class != xmManagerWidgetClass)
574     {
575 	XmManagerWidgetClass msc =
576 	(XmManagerWidgetClass)mwc->core_class.superclass;
577 
578 	_XmBuildResources(&mwc->manager_class.syn_resources,
579 			  &mwc->manager_class.num_syn_resources,
580 			  msc->manager_class.syn_resources,
581 			  msc->manager_class.num_syn_resources);
582 
583 	_XmBuildResources(&mwc->manager_class.syn_constraint_resources,
584 			  &mwc->manager_class.num_syn_constraint_resources,
585 			  msc->manager_class.syn_constraint_resources,
586 			  msc->manager_class.num_syn_constraint_resources);
587     }
588 
589     /* FIX ME: do I need to worry about subclasses */
590     /* initialize traits */
591     if (!XmeTraitSet((XtPointer)xmManagerWidgetClass, XmQTspecifyLayoutDirection,
592 		     (XtPointer)&_XmManagerLayoutTraitRec))
593     {
594 	_XmWarning(NULL, "XmManager ClassInitialize: XmeTraitSet failed\n");
595     }
596 }
597 
598 static void
CreateHighlightGC(Widget mw)599 CreateHighlightGC(Widget mw)
600 {
601     XGCValues values;
602     unsigned long mask,dynamic,unused;
603 
604     mask = GCForeground | GCBackground;
605     values.foreground = MGR_HighlightColor(mw);
606     values.background = XtBackground(mw);
607 
608     if (MGR_HighlightPixmap(mw) != None
609 	&& MGR_HighlightPixmap(mw) != XmUNSPECIFIED_PIXMAP)
610     {
611 	/* we're dealing with a pixmap'ed highlight */
612 	mask |= GCTile | GCFillStyle;
613 
614 	values.tile = MGR_HighlightPixmap(mw);
615 	values.fill_style = FillTiled;
616     }
617 
618     mask |= GCLineWidth | GCLineStyle | GCJoinStyle | GCCapStyle;
619     values.line_width = 1;
620     values.line_style = LineSolid;
621     values.join_style = JoinMiter;
622     values.cap_style = CapButt;
623 
624     /* these may be changed in _XmDrawHighlight() called from
625      * gadget_border_highlight() */
626     dynamic = GCLineWidth | GCLineStyle | GCJoinStyle | GCDashList;
627 
628     /* have no idea ! */
629     unused = 0;
630 
631     MGR_HighlightGC(mw) = XtGetGC((Widget)mw, mask, &values);
632 
633 }
634 
635 static void
CreateBottomShadowGC(Widget mw)636 CreateBottomShadowGC(Widget mw)
637 {
638     XGCValues values;
639     unsigned long mask;
640 
641     mask = GCForeground | GCBackground;
642     values.foreground = MGR_BottomShadowColor(mw);
643     values.background = XtBackground(mw);
644 
645     if (MGR_BottomShadowPixmap(mw) != None
646 	&& MGR_BottomShadowPixmap(mw) != XmUNSPECIFIED_PIXMAP)
647     {
648 	/* we're dealing with a pixmap'ed bottom shadow */
649 	mask |= GCTile | GCFillStyle;
650 
651 	values.tile = MGR_BottomShadowPixmap(mw);
652 	values.fill_style = FillTiled;
653     }
654 
655     mask |= GCLineWidth;
656     values.line_width = 1;
657 
658     MGR_BottomShadowGC(mw) = XtGetGC((Widget)mw, mask, &values);
659 }
660 
661 static void
CreateTopShadowGC(Widget mw)662 CreateTopShadowGC(Widget mw)
663 {
664     XGCValues values;
665     unsigned long mask;
666 
667     mask = GCForeground | GCBackground;
668     values.foreground = MGR_TopShadowColor(mw);
669     values.background = XtBackground(mw);
670 
671     if (MGR_TopShadowPixmap(mw) != None
672 	&& MGR_TopShadowPixmap(mw) != XmUNSPECIFIED_PIXMAP)
673     {
674 	/* we're dealing with a pixmap'ed top shadow */
675 	mask |= GCTile | GCFillStyle;
676 
677 	values.tile = MGR_TopShadowPixmap(mw);
678 	values.fill_style = FillTiled;
679     }
680 
681     /* these GC's get used for shadow drawing, so set 'em up */
682     mask |= GCLineWidth | GCLineStyle | GCJoinStyle | GCCapStyle;
683     values.line_width = 1;
684     values.line_style = LineSolid;
685     values.join_style = JoinMiter;
686     values.cap_style = CapButt;
687 
688     MGR_TopShadowGC(mw) = XtGetGC((Widget)mw, mask, &values);
689 }
690 
691 static void
CreateBackgroundGC(Widget mw)692 CreateBackgroundGC(Widget mw)
693 {
694     XGCValues values;
695     unsigned long mask;
696 
697     mask = GCForeground | GCBackground;
698 
699     values.foreground = XtBackground(mw);
700     values.background = XtBackground(mw);
701 
702     /* these GC's get used for shadow drawing, so set 'em up */
703     mask |= GCLineWidth | GCLineStyle | GCJoinStyle | GCCapStyle;
704     values.line_width = 1;
705     values.line_style = LineSolid;
706     values.join_style = JoinMiter;
707     values.cap_style = CapButt;
708 
709     MGR_BackgroundGC(mw) = XtGetGC((Widget)mw, mask, &values);
710 }
711 
712 static void
initialize(Widget request,Widget new_w,ArgList args,Cardinal * num_args)713 initialize(Widget request,
714 	   Widget new_w,
715 	   ArgList args,
716 	   Cardinal *num_args)
717 {
718     XmManagerWidgetClass mwc = (XmManagerWidgetClass)new_w->core.widget_class;
719     /*XmManagerWidget   mw = (XmManagerWidget)new_w; */
720 
721     MGR_EventHandlerAdded(new_w) = False;
722     MGR_HighlightedWidget(new_w) = NULL;
723     MGR_SelectedGadget(new_w) = NULL;
724     MGR_ActiveChild(new_w) = NULL;
725     MGR_KeyboardList(new_w) = NULL;
726     MGR_NumKeyboardEntries(new_w) = 0;
727     MGR_SizeKeyboardList(new_w) = 0;
728 
729     if (!XmRepTypeValidValue(XmRepTypeGetId(XmRUnitType),
730 			     MGR_UnitType(new_w),
731 			     new_w))
732     {
733 	MGR_UnitType(new_w) = XmPIXELS;
734     }
735 
736 
737     /* initialize these to values that aren't possible */
738     if (!XmRepTypeValidValue(XmRepTypeGetId(XmRNavigationType),
739 			     MGR_NavigationType(new_w),
740 			     new_w))
741     {
742 	MGR_UnitType(new_w) = XmTAB_GROUP;
743     }
744 
745     /* This is way too simple. FIX ME */
746     if (MGR_StringDirection(new_w) == (XmStringDirection)XmUNSPECIFIED)
747     {
748 	if (XmIsManager(XtParent(new_w)))
749 	{
750 	    MGR_StringDirection(new_w) = MGR_StringDirection(XtParent(new_w));
751 	}
752 	else
753 	{
754 	    MGR_StringDirection(new_w) = XmSTRING_DIRECTION_L_TO_R;
755 	}
756     }
757 
758     _XmNavigInitialize(request, new_w, args, num_args);
759 
760     _XmManagerImportArgs(new_w, args, num_args);
761 
762     if (mwc->manager_class.translations)
763     {
764 	XtOverrideTranslations(new_w,
765 			       (XtTranslations)mwc->
766 			       manager_class.translations);
767     }
768 
769     /*
770      * there's a really nasty reason for this.  CoreBackgroundPixmap() is
771      * field that appears in *all* Core derivatives -- including Shell.
772      * If we try to convert a string to a pixmap in for Shells, we'll have
773      * a real nasty mess with infinite recursion.  This is because
774      * we want to use XmGetPixmapByDepth(), but that function uses
775      * XmGetXmScreen() -- which is a VendorShell derivative.  Now consider
776      * the case where we say "*.backgroundPixmap: slant_left", and we create
777      * our first AppShell.  Neither the XmScreen nor the XmDisplay has been
778      * created yet.  The converter proc will call XmGetPixmapByDepth(), which
779      * will call XmGetXmScreen(), which will try to create the XmScreen,
780      * which is a VendorShell so the converter proc will be called, which
781      * will call XmGetPixmapByDepth(), which ..... recursion.
782      */
783     if (_XmGetBGPixmapName() != NULL)
784     {
785 	CoreBackgroundPixmap(new_w) =
786 	    XmGetPixmapByDepth(XtScreen(new_w),
787 			       _XmGetBGPixmapName(),
788 			       MGR_Foreground(new_w),
789 			       XtBackground(new_w),
790 			       CoreDepth(new_w));
791 	_XmClearBGPixmap();
792     }
793 
794     CreateTopShadowGC(new_w);
795     CreateBottomShadowGC(new_w);
796     CreateHighlightGC(new_w);
797     CreateBackgroundGC(new_w);
798 
799     /* Install a Virtual Keys magic event handler on all widgets */
800     XtAddEventHandler(new_w, KeyPressMask, False, _XmVirtKeysHandler, NULL);
801 }
802 
803 static void
destroy(Widget w)804 destroy(Widget w)
805 {
806     DEBUGOUT(_LtDebug("RWS", w, "%s:destroy(%d)\n",
807 		      __FILE__, __LINE__
808 	     ));
809     XtReleaseGC(w, MGR_TopShadowGC(w));
810     XtReleaseGC(w, MGR_BottomShadowGC(w));
811     XtReleaseGC(w, MGR_HighlightGC(w));
812     XtReleaseGC(w, MGR_BackgroundGC(w));
813     if (MGR_KeyboardList(w))
814     {
815         XtFree((char *)MGR_KeyboardList(w));
816     }
817 
818     if (MGR_EventHandlerAdded(w))
819     {
820 	XtRemoveEventHandler(w,
821 			     PointerMotionMask,
822 			     False,
823 			     _XmManagerEventHandler,
824 			     NULL);
825     }
826     _XmNavigDestroy(w);
827 }
828 
829 static void
realize(Widget w,XtValueMask * value_mask,XSetWindowAttributes * attributes)830 realize(Widget w, XtValueMask *value_mask, XSetWindowAttributes *attributes)
831 {
832     /* rws 13 Nov 1998
833        This causes a parse error with gcc on AIX???
834        Boolean wz = False, hz = False; */
835 
836     DEBUGOUT(_LtDebug(__FILE__, w, "XmManager realize() - %dx%d\n",
837 		      XtWidth(w), XtHeight(w)));
838 
839     /*
840      * MLM 960524 - if you get an XError: widget has zero width or height.
841      */
842     if (XtWidth(w) == 0)
843     {
844 	/* wz = True; */
845 	XtWidth(w) = 1;
846     }
847     if (XtHeight(w) == 0)
848     {
849 	/* hz = True; */
850 	XtHeight(w) = 1;
851     }
852 
853     *value_mask |= CWDontPropagate | CWBitGravity;
854     attributes->do_not_propagate_mask =
855 	(KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
856 	 PointerMotionMask);
857     attributes->bit_gravity = NorthWestGravity;
858 
859     XtCreateWindow(w, (unsigned int)InputOutput,
860 		   (Visual *)CopyFromParent, *value_mask, attributes);
861 
862     /* rws 7 Oct 1998
863        drawingarea/test7 shows that this does not happen
864        if (wz)
865        {
866        XtWidth(w) = 0;
867        }
868        if (hz)
869        {
870        XtHeight(w) = 0;
871        }
872      */
873 }
874 
875 static Boolean
set_values(Widget old,Widget request,Widget new_w,ArgList args,Cardinal * num_args)876 set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
877 {
878 	Boolean need_refresh = False;
879 	/* A variable to hold the trait flags */
880 	Mask	msk = 0;
881 
882     DEBUGOUT(_LtDebug(__FILE__, new_w, "SetValues()\n"));
883 
884     if (_XmGetBGPixmapName() != NULL)
885     {
886 	XSetWindowAttributes attr;
887 
888 	CoreBackgroundPixmap(new_w) =
889 	    XmGetPixmapByDepth(XtScreen(new_w),
890 			       _XmGetBGPixmapName(),
891 			       MGR_Foreground(new_w),
892 			       XtBackground(new_w),
893 			       CoreDepth(new_w));
894 
895 	attr.background_pixmap = CoreBackgroundPixmap(new_w);
896 	XChangeWindowAttributes(XtDisplay(new_w), XtWindow(new_w),
897 				CWBackPixmap, &attr);
898 
899 	_XmClearBGPixmap();
900     }
901 
902     if (!XmRepTypeValidValue(XmRepTypeGetId(XmRUnitType),
903 			     MGR_UnitType(new_w),
904 			     new_w))
905     {
906 	MGR_UnitType(new_w) = MGR_UnitType(old);
907     }
908 
909     if (!XmRepTypeValidValue(XmRepTypeGetId(XmRNavigationType),
910 			     MGR_NavigationType(new_w),
911 			     new_w))
912     {
913 	MGR_NavigationType(new_w) = MGR_NavigationType(old);
914     }
915 
916     need_refresh = _XmNavigSetValues(old, request, new_w, args, num_args);
917 
918     if (MGR_ShadowThickness(old) != MGR_ShadowThickness(new_w)
919 	|| MGR_Foreground(old) != MGR_Foreground(new_w))
920     {
921 	need_refresh = True;
922     }
923 	if (MGR_Foreground(old) != MGR_Foreground(new_w))
924 		msk |= VisualForeground;
925 
926 	if (MGR_HighlightColor(old) != MGR_HighlightColor(new_w)
927 			|| MGR_HighlightPixmap(old) != MGR_HighlightPixmap(new_w)) {
928 		XtReleaseGC(new_w, MGR_HighlightGC(new_w));
929 		CreateHighlightGC(new_w);
930 		need_refresh = True;
931 		if (MGR_HighlightColor(old) != MGR_HighlightColor(new_w))
932 			msk |= VisualHighlightColor;
933 		if (MGR_HighlightPixmap(old) != MGR_HighlightPixmap(new_w))
934 			msk |= VisualHighlightPixmap;
935 	}
936 
937 	if (MGR_BottomShadowColor(old) != MGR_BottomShadowColor(new_w)
938 			|| MGR_BottomShadowPixmap(old) != MGR_BottomShadowPixmap(new_w)) {
939 		XtReleaseGC(new_w, MGR_BottomShadowGC(new_w));
940 		CreateBottomShadowGC(new_w);
941 		need_refresh = True;
942 		if (MGR_BottomShadowColor(old) != MGR_BottomShadowColor(new_w))
943 			msk |= VisualBottomShadowColor;
944 		if (MGR_BottomShadowPixmap(old) != MGR_BottomShadowPixmap(new_w))
945 			msk |= VisualBottomShadowPixmap;
946 	}
947 
948 	if (MGR_TopShadowColor(old) != MGR_TopShadowColor(new_w)
949 			|| MGR_TopShadowPixmap(old) != MGR_TopShadowPixmap(new_w)) {
950 		XtReleaseGC(new_w, MGR_TopShadowGC(new_w));
951 		CreateTopShadowGC(new_w);
952 		need_refresh = True;
953 		if (MGR_TopShadowColor(old) != MGR_TopShadowColor(new_w))
954 			msk |= VisualTopShadowColor;
955 		if (MGR_TopShadowPixmap(old) != MGR_TopShadowPixmap(new_w))
956 			msk |= VisualTopShadowPixmap;
957 	}
958 
959 	if (XtBackground(old) != XtBackground(new_w)) {
960 		XtReleaseGC(new_w, MGR_BackgroundGC(new_w));
961 		CreateBackgroundGC(new_w);
962 		need_refresh = True;
963 		if (XtBackground(old) != XtBackground(new_w))
964 			msk |= VisualBackgroundPixel;
965 	}
966 
967 	_XmManagerImportArgs(new_w, args, num_args);
968 
969 	if (msk) {
970 		XmCareVisualTrait	t;
971 		int			i;
972 
973 		for (i=0; i<MGR_NumChildren(new_w); i++) {
974 			Widget	child = MGR_Children(new_w)[i];
975 
976 			t = (XmCareVisualTrait) XmeTraitGet((XtPointer)XtClass(child),
977 				XmQTcareParentVisual);
978 			if (t && t->redraw(child, old, new_w, msk)) {
979 				/* FIX ME this doesn't look like the right action, does it ? */
980 				need_refresh = True;
981 			}
982 		}
983 	}
984 	return need_refresh;
985 }
986 
987 /* constraint class methods */
988 
989 static void
constraint_initialize(Widget request,Widget new_w,ArgList args,Cardinal * num_args)990 constraint_initialize(Widget request,
991 		      Widget new_w,
992 		      ArgList args,
993 		      Cardinal *num_args)
994 {
995     Widget manager = XtParent(new_w);
996     /* check to see if the gadget's event mask specifies an event
997        that requires us to install an event handler. */
998 
999     if (XmIsGadget(new_w))
1000 	if (!MGR_EventHandlerAdded(manager))
1001 	{
1002 	    /* we only need to check if we haven't already added one. */
1003 
1004 	    if (G_EventMask(new_w) & XmMOTION_EVENT
1005 		|| G_EventMask(new_w) & XmENTER_EVENT
1006 		|| G_EventMask(new_w) & XmLEAVE_EVENT)
1007 	    {
1008 		DEBUGOUT(_LtDebug(__FILE__, manager, "adding event handler\n"));
1009 
1010 		XtAddEventHandler(manager,
1011 				  PointerMotionMask | EnterWindowMask |
1012 				  LeaveWindowMask,
1013 				  True,
1014 				  (XtEventHandler)_XmManagerEventHandler, NULL);
1015 
1016 		MGR_EventHandlerAdded(manager) = True;
1017 	    }
1018 	}
1019 
1020 }
1021 
1022 void
_XmGadgetArm(Widget w,XEvent * event,String * params,Cardinal * num_params)1023 _XmGadgetArm(Widget w,
1024 	     XEvent *event,
1025 	     String *params,
1026 	     Cardinal *num_params)
1027 {
1028     XButtonEvent *ev = (XButtonEvent *)event;
1029     Widget g = (Widget)_XmInputForGadget(w, ev->x, ev->y);
1030 
1031     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetArm()\n"));
1032 
1033     if (g)
1034     {
1035 	XmProcessTraversal(g, XmTRAVERSE_CURRENT);
1036 	_XmDispatchGadgetInput(g,
1037 			       event,
1038 			       XmARM_EVENT);
1039 
1040 	MGR_SelectedGadget(w) = (XmGadget)g;
1041     }
1042     else
1043     {
1044 	if (_XmIsNavigable(w))
1045 	{
1046 	    XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1047 	}
1048     }
1049     MGR_EligibleForMultiButtonEvent(w) = NULL;
1050 }
1051 
1052 void
_XmGadgetActivate(Widget w,XEvent * event,String * params,Cardinal * num_params)1053 _XmGadgetActivate(Widget w,
1054 		  XEvent *event,
1055 		  String *params,
1056 		  Cardinal *num_params)
1057 {
1058     Widget g = (Widget)MGR_SelectedGadget(w);
1059 
1060     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetActivate()\n"));
1061 
1062     if (g)
1063     {
1064 	_XmDispatchGadgetInput((Widget)g,
1065 			       event,
1066 			       XmACTIVATE_EVENT);
1067 	MGR_EligibleForMultiButtonEvent(w) = (XmGadget)g;
1068     }
1069     MGR_SelectedGadget(w) = NULL;
1070 }
1071 
1072 void
_XmGadgetMultiArm(Widget w,XEvent * event,String * params,Cardinal * num_params)1073 _XmGadgetMultiArm(Widget w,
1074 		  XEvent *event,
1075 		  String *params,
1076 		  Cardinal *num_params)
1077 {
1078     XButtonEvent *ev = (XButtonEvent *)event;
1079     Widget g = (Widget)_XmInputForGadget(w, ev->x, ev->y);
1080 
1081     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetMultiArm()\n"));
1082 
1083     if (g)
1084     {
1085 	/* This only counts as a multiArm if we're arming the gadget we just
1086 	 * activated.  Otherwise it's just a regular arm.
1087 	 */
1088 
1089 	if (g == (Widget)MGR_EligibleForMultiButtonEvent(w))
1090 	{
1091 	    _XmDispatchGadgetInput(g,
1092 				   event,
1093 				   XmMULTI_ARM_EVENT);
1094 	}
1095 	else
1096 	{
1097 	    XmProcessTraversal(g, XmTRAVERSE_CURRENT);
1098 	    _XmDispatchGadgetInput(g,
1099 				   event,
1100 				   XmARM_EVENT);
1101 	    MGR_EligibleForMultiButtonEvent(w) = NULL;
1102 	}
1103 	MGR_SelectedGadget(w) = (XmGadget)g;
1104     }
1105     else
1106     {
1107 	if (_XmIsNavigable(w))
1108 	{
1109 	    XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1110 	}
1111 	MGR_EligibleForMultiButtonEvent(w) = NULL;
1112     }
1113 }
1114 
1115 void
_XmGadgetMultiActivate(Widget w,XEvent * event,String * params,Cardinal * num_params)1116 _XmGadgetMultiActivate(Widget w,
1117 		       XEvent *event,
1118 		       String *params,
1119 		       Cardinal *num_params)
1120 {
1121     Widget g = (Widget)MGR_SelectedGadget(w);
1122 
1123     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetMultiActivate()\n"));
1124 
1125     if (g)
1126     {
1127 	/* This only counts as a multiActivate if we're activating a
1128 	 * multiArmed gadget.  Otherwise it's just a regular activate.
1129 	 */
1130 
1131 	if (g == (Widget)MGR_EligibleForMultiButtonEvent(w))
1132 	{
1133 	    _XmDispatchGadgetInput((Widget)g,
1134 				   event,
1135 				   XmMULTI_ACTIVATE_EVENT);
1136 	}
1137 	else
1138 	{
1139 	    _XmDispatchGadgetInput((Widget)g,
1140 				   event,
1141 				   XmACTIVATE_EVENT);
1142 	    MGR_EligibleForMultiButtonEvent(w) = (XmGadget)g;
1143 	}
1144     }
1145 
1146     MGR_SelectedGadget(w) = NULL;
1147 }
1148 
1149 void
_XmGadgetDrag(Widget w,XEvent * event,String * params,Cardinal * num_params)1150 _XmGadgetDrag(Widget w,
1151 	      XEvent *event,
1152 	      String *params,
1153 	      Cardinal *num_params)
1154 {
1155     XButtonEvent *ev = (XButtonEvent *)event;
1156     Widget g = (Widget)_XmInputForGadget(w, ev->x, ev->y);
1157 
1158     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetDrag()\n"));
1159 
1160     if (g)
1161     {
1162 	_XmDispatchGadgetInput((Widget)g,
1163 			       event,
1164 			       XmBDRAG_EVENT);
1165     }
1166 }
1167 
1168 void
_XmGadgetSelect(Widget w,XEvent * event,String * params,Cardinal * num_params)1169 _XmGadgetSelect(Widget w,
1170 		XEvent *event,
1171 		String *params,
1172 		Cardinal *num_params)
1173 {
1174     Widget g = MGR_ActiveChild(w);
1175 
1176     DEBUGOUT(_LtDebug2(__FILE__, w, g, "Inside _XmGadgetSelect()\n"));
1177 
1178     if (g && XmIsGadget(g))
1179     {
1180 	XmGadgetClass gc = (XmGadgetClass)XtClass(g);
1181 
1182 	if (gc->gadget_class.arm_and_activate)
1183 	{
1184 	    (*gc->gadget_class.arm_and_activate) (g, event, params, num_params);
1185 	}
1186     }
1187 }
1188 
1189 void
_XmManagerParentActivate(Widget w,XEvent * event,String * params,Cardinal * num_params)1190 _XmManagerParentActivate(Widget w,
1191 			 XEvent *event,
1192 			 String *params,
1193 			 Cardinal *num_params)
1194 {
1195     XmParentProcessDataRec data;
1196     XmManagerWidgetClass mwc = (XmManagerWidgetClass)w->core.widget_class;
1197 
1198     DEBUGOUT(_LtDebug(__FILE__, w, "Inside ManagerParentActivate()\n"));
1199 
1200     data.input_action.process_type = XmINPUT_ACTION;
1201     data.input_action.event = event;
1202     data.input_action.action = XmPARENT_ACTIVATE;
1203     data.input_action.params = params;
1204     data.input_action.num_params = num_params;
1205 
1206     if (XmIsManager(w) && mwc->manager_class.parent_process)
1207     {
1208 	if (!(*mwc->manager_class.parent_process) (w, &data))
1209 	{
1210 	    /* propagate to parent? */
1211 	}
1212     }
1213 }
1214 
1215 void
_XmGadgetTraversePrevTabGroup(Widget w,XEvent * event,String * params,Cardinal * num_params)1216 _XmGadgetTraversePrevTabGroup(Widget w,
1217 			      XEvent *event,
1218 			      String *params,
1219 			      Cardinal *num_params)
1220 {
1221 	Widget g = MGR_ActiveChild(w);
1222 
1223 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraversePrevTabGroup()\n"));
1224 	XmProcessTraversal(g, XmTRAVERSE_PREV_TAB_GROUP);
1225 }
1226 
1227 void
_XmGadgetTraverseNextTabGroup(Widget w,XEvent * event,String * params,Cardinal * num_params)1228 _XmGadgetTraverseNextTabGroup(Widget w,
1229 			      XEvent *event,
1230 			      String *params,
1231 			      Cardinal *num_params)
1232 {
1233 	Widget g = MGR_ActiveChild(w);
1234 
1235 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseNextTabGroup()\n"));
1236 	XmProcessTraversal(g, XmTRAVERSE_NEXT_TAB_GROUP);
1237 }
1238 
1239 void
_XmGadgetTraverseUp(Widget w,XEvent * event,String * params,Cardinal * num_params)1240 _XmGadgetTraverseUp(Widget w,
1241 		    XEvent *event,
1242 		    String *params,
1243 		    Cardinal *num_params)
1244 {
1245 	Widget g = MGR_ActiveChild(w);
1246 
1247 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseUp()\n"));
1248 	XmProcessTraversal(g, XmTRAVERSE_UP);
1249 }
1250 
1251 void
_XmGadgetTraverseDown(Widget w,XEvent * event,String * params,Cardinal * num_params)1252 _XmGadgetTraverseDown(Widget w,
1253 		      XEvent *event,
1254 		      String *params,
1255 		      Cardinal *num_params)
1256 {
1257 	Widget g = MGR_ActiveChild(w);
1258 
1259 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseDown()\n"));
1260 	XmProcessTraversal(g, XmTRAVERSE_DOWN);
1261 }
1262 
1263 void
_XmGadgetTraverseLeft(Widget w,XEvent * event,String * params,Cardinal * num_params)1264 _XmGadgetTraverseLeft(Widget w,
1265 		      XEvent *event,
1266 		      String *params,
1267 		      Cardinal *num_params)
1268 {
1269 	Widget g = MGR_ActiveChild(w);
1270 
1271 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseLeft()\n"));
1272 	XmProcessTraversal(g, XmTRAVERSE_LEFT);
1273 }
1274 
1275 void
_XmGadgetTraverseRight(Widget w,XEvent * event,String * params,Cardinal * num_params)1276 _XmGadgetTraverseRight(Widget w,
1277 		       XEvent *event,
1278 		       String *params,
1279 		       Cardinal *num_params)
1280 {
1281 	Widget g = MGR_ActiveChild(w);
1282 
1283 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseRight()\n"));
1284 	XmProcessTraversal(g, XmTRAVERSE_RIGHT);
1285 }
1286 
1287 void
_XmGadgetTraverseHome(Widget w,XEvent * event,String * params,Cardinal * num_params)1288 _XmGadgetTraverseHome(Widget w,
1289 		      XEvent *event,
1290 		      String *params,
1291 		      Cardinal *num_params)
1292 {
1293 	Widget g = MGR_ActiveChild(w);
1294 
1295 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseHome()\n"));
1296 	XmProcessTraversal(g, XmTRAVERSE_HOME);
1297 }
1298 
1299 void
_XmGadgetHelp(Widget w,XEvent * event,String * params,Cardinal * num_params)1300 _XmGadgetHelp(Widget w,
1301 	      XEvent *event,
1302 	      String *params,
1303 	      Cardinal *num_params)
1304 {
1305     Widget g = MGR_ActiveChild(w);
1306     Widget cur;
1307     XmAnyCallbackStruct cbs;
1308 
1309     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmGadgetHelp()\n"));
1310 
1311     if (g)
1312     {
1313 	_XmDispatchGadgetInput(g,
1314 			       event,
1315 			       XmHELP_EVENT);
1316     }
1317     else
1318     {
1319 	cur = w;
1320 
1321 	cbs.reason = XmCR_HELP;
1322 	cbs.event = event;
1323 
1324 	while (cur != NULL)
1325 	{
1326 	    if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
1327 	    {
1328 		XtCallCallbacks(w, XmNhelpCallback, (XtPointer)&cbs);
1329 		return;
1330 	    }
1331 
1332 	    cur = XtParent(cur);
1333 	}
1334     }
1335 }
1336 
1337 void
_XmManagerHelp(Widget w,XEvent * event,String * params,Cardinal * num_params)1338 _XmManagerHelp(Widget w,
1339 	       XEvent *event,
1340 	       String *params,
1341 	       Cardinal *num_params)
1342 {
1343     _XmGadgetHelp(w, event, params, num_params);
1344 }
1345 
1346 void
_XmGadgetKeyInput(Widget w,XEvent * event,String * params,Cardinal * num_params)1347 _XmGadgetKeyInput(Widget w,
1348 		  XEvent *event,
1349 		  String *params,
1350 		  Cardinal *num_params)
1351 {
1352     Widget g = MGR_ActiveChild(w);
1353 
1354     DEBUGOUT(_LtDebug2(__FILE__, w, g, "Inside _XmGadgetKeyInput()\n"));
1355     DEBUGOUT(_LtDebug2(__FILE__, w, g,
1356 		       "event type: %d code %08x\n",
1357 		       event->type, event->xkey.keycode));
1358 
1359     if (g)
1360     {
1361 	_XmDispatchGadgetInput(g,
1362 			       event,
1363 			       XmKEY_EVENT);
1364     }
1365 }
1366 
1367 void
_XmGadgetButtonMotion(Widget w,XEvent * event,String * params,Cardinal * num_params)1368 _XmGadgetButtonMotion(Widget w,
1369 		      XEvent *event,
1370 		      String *params,
1371 		      Cardinal *num_params)
1372 {
1373     Widget g = MGR_ActiveChild(w);
1374 
1375     DEBUGOUT(_LtDebug(__FILE__, w,
1376 		      "Inside _XmGadgetButtonMotion(), gadget %s\n",
1377 		      g ? XtName(g) : "(null)"));
1378 
1379     if (g)
1380     {
1381 	_XmDispatchGadgetInput(g,
1382 			       event,
1383 			       XmMOTION_EVENT);
1384     }
1385 }
1386 
1387 void
_XmManagerParentCancel(Widget w,XEvent * event,String * params,Cardinal * num_params)1388 _XmManagerParentCancel(Widget w,
1389 		       XEvent *event,
1390 		       String *params,
1391 		       Cardinal *num_params)
1392 {
1393     XmParentProcessDataRec data;
1394     XmManagerWidgetClass mwc = (XmManagerWidgetClass)w->core.widget_class;
1395 
1396     DEBUGOUT(_LtDebug(__FILE__, w, "ManagerParentCancel\n"));
1397 
1398     data.input_action.process_type = XmINPUT_ACTION;
1399     data.input_action.event = event;
1400     data.input_action.action = XmPARENT_CANCEL;
1401     data.input_action.params = params;
1402     data.input_action.num_params = num_params;
1403 
1404     if (XmIsManager(w) && mwc->manager_class.parent_process)
1405     {
1406 	(*mwc->manager_class.parent_process) (w, &data);
1407     }
1408 }
1409 
1410 void
_XmGadgetTraversePrev(Widget w,XEvent * event,String * params,Cardinal * num_params)1411 _XmGadgetTraversePrev(Widget w,
1412 		      XEvent *event,
1413 		      String *params,
1414 		      Cardinal *num_params)
1415 {
1416 	Widget g = MGR_ActiveChild(w);
1417 
1418 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraversePrev()\n"));
1419 	XmProcessTraversal(g, XmTRAVERSE_PREV);
1420 }
1421 
1422 
1423 void
_XmGadgetTraverseNext(Widget w,XEvent * event,String * params,Cardinal * num_params)1424 _XmGadgetTraverseNext(Widget w,
1425 		      XEvent *event,
1426 		      String *params,
1427 		      Cardinal *num_params)
1428 {
1429 	Widget g = MGR_ActiveChild(w);
1430 
1431 	DEBUGOUT(_LtDebug2(__FILE__, w, g, "_XmGadgetTraverseNext()\n"));
1432 	XmProcessTraversal(g, XmTRAVERSE_NEXT);
1433 }
1434 
1435 /*
1436  * yeah, right.  Who came up with these names, anyway?
1437  */
1438 void
_XmSocorro(Widget w,XEvent * event,String * params,Cardinal * num_params)1439 _XmSocorro(Widget w, XEvent *event, String *params, Cardinal *num_params)
1440 {
1441     XmAnyCallbackStruct cbs;
1442 
1443     DEBUGOUT(_LtDebug(__FILE__, w, "Inside _XmSocorro()\n"));
1444 
1445     cbs.reason = XmCR_HELP;
1446     cbs.event = event;
1447 
1448     while (w != NULL)
1449     {
1450 	if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
1451 	{
1452 	    XtCallCallbacks(w, XmNhelpCallback, (XtPointer)&cbs);
1453 	    return;
1454 	}
1455 	w = XtParent(w);
1456     }
1457 }
1458 
1459 /* we don't handle anything by default.  We leave that up to the other
1460  * manager widgets, like bulletin board. Just pop up to our parent*/
1461 Boolean
_XmParentProcess(Widget widget,XmParentProcessData data)1462 _XmParentProcess(Widget widget,
1463 		 XmParentProcessData data)
1464 {
1465     Widget p = XtParent(widget);
1466     XmManagerWidgetClass mwc = (XmManagerWidgetClass)p->core.widget_class;
1467 
1468     if (XmIsManager(p) && mwc->manager_class.parent_process)
1469     {
1470 	return ((*mwc->manager_class.parent_process) (p, data));
1471     }
1472 
1473     return False;
1474 }
1475 
1476 static void
_XmManagerEventHandler(Widget w,XtPointer data,XEvent * event,Boolean * cont)1477 _XmManagerEventHandler(Widget w,
1478 		       XtPointer data,
1479 		       XEvent *event,
1480 		       Boolean *cont)
1481 {
1482     XmGadget g;
1483 
1484     if (CoreBeingDestroyed(w))
1485     {
1486 	return;
1487     }
1488 
1489     g = _XmInputForGadget(w, event->xmotion.x, event->xmotion.y);
1490     if (g == NULL)
1491     {
1492 	DEBUGOUT(_LtDebug(__FILE__, w,
1493 			  "### _XmManagerEventHandler(gadget NULL)\n"));
1494     }
1495     else
1496     {
1497 	DEBUGOUT(_LtDebug2(__FILE__, w,
1498 			   (Widget)g, "### _XmManagerEventHandler()\n"));
1499     }
1500 
1501     /* We've got to tie this into the focus policy.  If the focus mode is
1502      * explicit, we get focus in/out events.  If the focus mode is pointer,
1503      * we get enter/leave events.  Regardless, we get one or the other,
1504      * but not both.  You can see this in Motif/mwm, but not in LessTif/lmwm.
1505      * There's a lot of wacky stuff that Motif does in the BaseClass
1506      * extension procs.  This (at least for Gadgets) is one of them (the
1507      * FocusChange proc).
1508      * Started this, but currently it is a hack.  Focus in/out and Enter/Leave
1509      * look the same -- and they shouldn't.  The trouble I'm having is how
1510      * to distinguish the two cases.  It really needs to follow when the
1511      * Gadget gets the keyboard focus (er, well, really when the parent
1512      * gets the keyboard focus). MLM
1513      *
1514      * 960720 -- fixed this.  Now this event handler only does the work for
1515      * XmPOINTER.  XmEXPLICIT is handled via the focus mechanism in Traversal.c
1516      * MLM
1517      *
1518      * 961114 -- Sometimes I am slow.  POINTER or InDragMode, stupid.  MLM
1519      *
1520      * Not so.  Enter and Leave events are quite independent of focus,
1521      * and despite its name, MGR_HighlightedWidget is only used for tracking
1522      * Enter/Leave.  So regardless of focus policy, set MGR_HighlightedWidget
1523      * to track the gadget under the pointer.  JHG
1524      */
1525     if (g == NULL)
1526     {
1527 	/*
1528 	 * we're now not in a gadget child, or the child isn't listening
1529 	 *
1530 	 * if we weren't in a gadget before, do nothing.
1531 	 * else
1532 	 * if we were in a gadget before, send a leave event to the old gadget
1533 	 */
1534 
1535 	if (MGR_HighlightedWidget(w) != NULL)
1536 	{
1537 	    DEBUGOUT(_LtDebug(__FILE__, w, "Sending LEAVE event to gadget\n"));
1538 	    _XmDispatchGadgetInput(MGR_HighlightedWidget(w),
1539 				   event,
1540 				   XmLEAVE_EVENT);
1541 
1542 	    MGR_HighlightedWidget(w) = NULL;
1543 	}
1544     }
1545     else
1546     {
1547 	/* we are in a gadget child
1548 	 * if we weren't in a gadget before, send an enter event to the new
1549 	 *    gadget
1550 	 * else
1551 	 * if we were in a gadget before:
1552 	 *    if it's the same gadget, send a motion event.
1553 	 *    else
1554 	 *    it it's not the same gadget, send a leave event to the old
1555 	 *       one and an enter event to the new one.
1556 	 */
1557 
1558 	if (MGR_HighlightedWidget(w) == NULL)
1559 	{
1560 	    DEBUGOUT(_LtDebug(__FILE__, w, "Sending ENTER event to gadget\n"));
1561 
1562 	    _XmDispatchGadgetInput((Widget)g,
1563 				   event,
1564 				   XmENTER_EVENT);
1565 	    MGR_HighlightedWidget(w) = (Widget)g;
1566 	}
1567 	else
1568 	{
1569 	    /* the motion events are already propagated to highlightedwidget */
1570 	    if (MGR_HighlightedWidget(w) != (Widget)g)
1571 	    {
1572 
1573 		DEBUGOUT(_LtDebug(__FILE__, w,
1574 				  "Sending LEAVE event to old gadget\n"));
1575 
1576 		_XmDispatchGadgetInput(MGR_HighlightedWidget(w),
1577 				       event,
1578 				       XmLEAVE_EVENT);
1579 
1580 		DEBUGOUT(_LtDebug(__FILE__, w,
1581 				  "Sending ENTER event to new gadget\n"));
1582 
1583 		_XmDispatchGadgetInput((Widget)g,
1584 				       event,
1585 				       XmENTER_EVENT);
1586 
1587 		MGR_HighlightedWidget(w) = (Widget)g;
1588 	    }
1589 	}
1590     }
1591 }
1592 
1593 void
_XmDestroyParentCallback(Widget w,XtPointer client,XtPointer call)1594 _XmDestroyParentCallback(Widget w, XtPointer client, XtPointer call)
1595 {
1596     DEBUGOUT(_LtDebug2("NEDIT", XtParent(w), w,
1597 		       "%s:_XmDestroyParentCallback(%d)\n",
1598 		       __FILE__, __LINE__));
1599     XtDestroyWidget(XtParent(w));
1600 }
1601 
1602 void
_XmClearShadowType(Widget w,Dimension old_width,Dimension old_height,Dimension old_shadow_thickness,Dimension old_highlight_thickness)1603 _XmClearShadowType(Widget w,
1604 		   Dimension old_width, Dimension old_height,
1605 		   Dimension old_shadow_thickness,
1606 		   Dimension old_highlight_thickness)
1607 {
1608     if (old_shadow_thickness > 0 && XtIsRealized(w))
1609     {
1610 	if (XtWidth(w) >= old_width)
1611 	{
1612 	    XClearArea(XtDisplay(w), XtWindow(w),
1613 		    old_width - old_shadow_thickness - old_highlight_thickness,
1614 		       0, old_shadow_thickness,
1615 		       old_height - old_highlight_thickness, False);
1616 	}
1617 	if (XtHeight(w) >= old_height)
1618 	{
1619 	    XClearArea(XtDisplay(w), XtWindow(w),
1620 		       0,
1621 		   old_height - old_shadow_thickness - old_highlight_thickness,
1622 		       old_width - old_highlight_thickness,
1623 		       old_shadow_thickness, False);
1624 	}
1625     }
1626 }
1627 
1628 /*
1629  * Accelerators and Mnemonics -  How they work.
1630  *
1631  * Accelerators are an issue to be dealt with on a per "window" basis -
1632  * if you take the user's perception of a window.
1633  * We collect the information on accelerators in the Menu Bar (a RowColumn
1634  * hence a subclass of Manager).
1635  *
1636  * Information on mnemonics is stored in the menu pane itself - also a
1637  * RowColumn.
1638  *
1639  * MENU BAR Mnemonics:
1640  * Two cases :
1641  * If one of the cascades in the menu bar has been activated, then
1642  *      the mnemonic's key by itself should trigger the corresponding
1643  *      cascade button.
1644  * If the menu bar is not selected, then Alt+the mnemonic should work.
1645  *
1646  * Only the latter case is treated here - the other is treated by ???
1647  * when the menu is activated, either through the mouse or the keyboard.
1648  *
1649  * MENU PULLDOWN Mnemonics:
1650  * If the menu is up and has the focus, then the mnemonic's key
1651  * by itself should trigger the widget
1652  *
1653  * MENU OPTION Mnemonics:
1654  * FIX ME -- don't know what this is supposed to do
1655  */
1656 static void
_XmAcceleratorHandler(Widget w,XtPointer client_data,XEvent * event,Boolean * cont)1657 _XmAcceleratorHandler(Widget w, XtPointer client_data,
1658 		      XEvent *event, Boolean *cont)
1659 {
1660     int i;
1661     XtActionProc act = NULL;
1662     Widget comp = (Widget)client_data;
1663 
1664     DEBUGOUT(_LtDebug(__FILE__, w,
1665 		      "Got Accelerator key: type %d code %04x "
1666 		      "state %08x data %08x\n",
1667 		      event->type, event->xkey.keycode, event->xkey.state,
1668 		      client_data));
1669     DEBUGOUT(_LtDebug("NMEM", w,
1670 		      "Got Accelerator key: type %d code %04x "
1671 		      "state %08x data %08x\n",
1672 		      event->type, event->xkey.keycode, event->xkey.state,
1673 		      client_data));
1674 
1675     if (!XmIsManager(w) ||
1676 	(event->type != KeyPress && event->type != KeyRelease))
1677     {
1678 	DEBUGOUT(_LtDebug(__FILE__, w,
1679 			  "Bad match for event.  Not manager or bad event.\n"));
1680 	return;
1681     }
1682 
1683     DEBUGOUT(_LtDebug(__FILE__, w,
1684 		    "Got Accelerator key: code: %08x state: %08x cd %08x %s\n",
1685 		      event->xkey.keycode, event->xkey.state, comp,
1686 		      XtName(comp)));
1687     DEBUGOUT(_LtDebug("NMEM", w,
1688 		    "Got Accelerator key: code: %08x state: %08x cd %08x %s\n",
1689 		      event->xkey.keycode, event->xkey.state, comp,
1690 		      XtName(comp)));
1691 
1692     /* JAC added this test.  Occasionally in nedit the accelerators cause
1693        segfaults.  The comp value passed has 0 for all fields in the
1694        Widget.  e.g.:
1695 
1696        (gdb) p *comp
1697 
1698        $10 = {core = {self = 0x0, widget_class = 0x0, parent = 0x0,
1699        xrm_name = 0, being_destroyed = 0 '\000', destroy_callbacks = 0x0,
1700        constraints = 0x0, x = 0, y = 0, width = 0, height = 0,
1701        border_width = 0, managed = 0 '\000', sensitive = 0 '\000',
1702        ancestor_sensitive = 0 '\000', event_table = 0x0, tm = {
1703        translations = 0x0, proc_table = 0x0, current_state = 0x0,
1704        lastEventTime = 0}, accelerators = 0x0, border_pixel = 0,
1705        border_pixmap = 0, popup_list = 0x0, num_popups = 0, name = 0x0,
1706        screen = 0x0, colormap = 0, window = 0, depth = 0, background_pixel
1707        = 0, background_pixmap = 0, visible = 0 '\000', mapped_when_managed
1708        = 0 '\000'}}
1709 
1710        I suspect that "comp" may be the address of a widget that's been
1711        destroyed, and for some reason we're still getting the callback,
1712        but that's a WAG.
1713      */
1714     if (!comp->core.widget_class)
1715     {
1716 #ifdef	LESSTIF_VERBOSE
1717 	_XmWarning(NULL, "XmManager _XmAcceleratorHandler: bad news!!!\n");
1718 #endif
1719 	DEBUGOUT(_LtDebug(__FILE__, w,
1720 			  "_XmAcceleratorHandler: called for w=%s"
1721 			  " with invalid comp, ignoring\n",
1722 			  XtName(w)));
1723 	return;
1724 
1725     }
1726     /* Another one of these. Danny 21/10/2001 */
1727     if (comp->core.being_destroyed) {
1728 #ifdef	LESSTIF_VERBOSE
1729 	_XmWarning(NULL, "XmManager _XmAcceleratorHandler: being destroyed, bad news!!!\n");
1730 #endif
1731 	return;
1732     }
1733 
1734     /* Yet another one - Danny 30/5/2002 */
1735     if (comp->core.self != comp) {
1736 #ifdef	LESSTIF_VERBOSE
1737 	_XmWarning(NULL, "XmManager _XmAcceleratorHandler: I am not myself lately\n");
1738 #endif
1739 	return;
1740     }
1741 
1742     /*
1743      * Insensitive widgets shouldn't be activated by accelerators or
1744      * mnemonics.  We could keep inserting and removing things from
1745      * the MGR_KeyboardList as widgets change sensitivity but that's
1746      * just sick.  Hence, we just filter out insensitive widgets.
1747      * This test could go inside the following search loop but there's
1748      * no point in searching when we know that we can't do anything with
1749      * what we find.
1750      * --mu@trends.net, 1998.09.06 */
1751     if (!XtIsSensitive(comp))
1752     {
1753 	DEBUGOUT(_LtDebug(__FILE__, w,
1754 			"_XmAcceleratorHandler: %s is insensitive, ignoring\n",
1755 			  XtName(comp)));
1756 	return;
1757     }
1758 
1759     for (i = 0; i < MGR_NumKeyboardEntries(w); i++)
1760     {
1761           /* Modified 21-Sep-04 - dwilliss - MicroImages, Inc
1762 	 Accelerator shouldn't care if CapsLock or NumLock is down. Ideally, the
1763 	 accelerator specification should have been able to tell us "only these
1764 	 modifiers" or "these modifiers plus any others" */
1765 	if (/*MGR_KeyboardList(w)[i].eventType == event->type && */
1766 	    MGR_KeyboardList(w)[i].key == event->xkey.keycode &&
1767 	    MGR_KeyboardList(w)[i].modifiers ==
1768 	        (event->xkey.state & ~(Mod2Mask | LockMask)) &&
1769 	    MGR_KeyboardList(w)[i].component == comp &&
1770 	    XtIsManaged(comp))
1771 	{
1772 	    Cardinal num_params = 0;
1773 
1774 	    DEBUGOUT(_LtDebug(__FILE__, w,
1775 			      "MATCH!!!! "
1776 			      "code %08x state %08x name: %s:%s mnem: %d\n",
1777 			      event->xkey.keycode, event->xkey.state,
1778 			      comp
1779 			      ? comp->core.widget_class->core_class.class_name
1780 			      : "(nil)",
1781 			      comp ? XtName(comp) : "(nil)",
1782 			      MGR_KeyboardList(w)[i].isMnemonic));
1783 	    DEBUGOUT(_LtDebug("NMEM", w,
1784 			      "MATCH!!!! "
1785 			      "code %08x state %08x name: %s:%s mnem: %d\n",
1786 			      event->xkey.keycode, event->xkey.state,
1787 			      comp
1788 			      ? comp->core.widget_class->core_class.class_name
1789 			      : "(nil)",
1790 			      comp ? XtName(comp) : "(nil)",
1791 			      MGR_KeyboardList(w)[i].isMnemonic));
1792 
1793 	    /* Make sure XmGetPostedFromWidget works: ? */
1794 
1795    /* amai: The following "if (act==NULL)" catches are just dumb
1796             attempts to prevent some rare crashes, e.g. as seen with
1797    	    NEdit. They really should be replaced by something better.
1798    	    Actually the only confirmed crash location is the
1799    	    first one, however I just decided to add a "full set"
1800 	    of checks here ...
1801 	    The _XmWarning()s should help us to get additional feedback
1802 	    on that issue!
1803 	    FIX ME ! */
1804 
1805 	    if (!MGR_KeyboardList(w)[i].isMnemonic || RC_Type(XtParent(comp)) == XmMENU_BAR ||
1806 		(MGR_KeyboardList(w)[i].isMnemonic && XtParent(comp) == RC_PopupPosted(w))
1807 		)
1808 	    {
1809 		DEBUGOUT(_LtDebug2(__FILE__, w, MGR_KeyboardList(w)[i].component,
1810 				   "menu showing\n"));
1811 		DEBUGOUT(_LtDebug2("NMEM", w, MGR_KeyboardList(w)[i].component,
1812 				   "menu showing\n"));
1813 		if (XmIsPrimitive(MGR_KeyboardList(w)[i].component))
1814 		{
1815 		    act = PrimC_ArmAndActivate(XtClass(comp));
1816 		    if (act==NULL) {
1817 #ifdef	LESSTIF_VERBOSE
1818                        _XmWarning(w, "%s:_XmAcceleratorHandler(%d) - act==NULL for %s",
1819 		               __FILE__, __LINE__, comp->core.widget_class->core_class.class_name);
1820 #endif
1821 		    } else {
1822                        (*act) (comp, event, NULL, &num_params);
1823 		    }
1824 		}
1825 		else if (XmIsGadget(MGR_KeyboardList(w)[i].component))
1826 		{
1827 		    act = GC_ArmAndActivate(XtClass(comp));
1828 		    if (act==NULL) {
1829 #ifdef	LESSTIF_VERBOSE
1830                        _XmWarning(w, "%s:_XmAcceleratorHandler(%d) - act==NULL for gadget",
1831 		               __FILE__, __LINE__);
1832 #endif
1833 	            } else {
1834                        (*act) (comp, event, NULL, &num_params);
1835 		    }
1836 		}
1837 		else if (XmIsRowColumn(w))
1838 		{
1839 		    act = RCClass_ArmAndActivate(XtClass(comp));
1840 		    if (act==NULL) {
1841 #ifdef	LESSTIF_VERBOSE
1842                        _XmWarning(w, "%s:_XmAcceleratorHandler(%d) - act==NULL for RowColumn",
1843 		               __FILE__, __LINE__);
1844 #endif
1845 		    } else {
1846                        (*act) (comp, event, NULL, &num_params);
1847 		    }
1848 		}
1849 		else
1850 		{
1851 		    DEBUGOUT(_LtDebug(__FILE__, MGR_KeyboardList(w)[i].component,
1852 				      "Not a widget/gadget\n"));
1853 
1854 		    XtCallActionProc(comp, "Activate", event, NULL, 0);
1855 		}
1856 		*cont = False;
1857 		break;
1858 	    }
1859 	    else
1860 	    {
1861 		DEBUGOUT(_LtDebug2(__FILE__, w, MGR_KeyboardList(w)[i].component,
1862 				   "menu is not showing\n"));
1863 		DEBUGOUT(_LtDebug2("NMEM", w, MGR_KeyboardList(w)[i].component,
1864 				   "menu is not showing\n"));
1865 	    }
1866 
1867 	    /*
1868 	    *cont = False;
1869 	    break;
1870 	    */
1871 	}
1872     }
1873 }
1874 
1875 static void
AddKeyboardEntry(Widget m,Widget w,XmKeyboardData * item)1876 AddKeyboardEntry(Widget m, Widget w, XmKeyboardData *item)
1877 {
1878     int i;
1879     unsigned long mask;
1880 
1881     /* Register with the manager widget */
1882     if (MGR_SizeKeyboardList(m) == 0 ||
1883 	(MGR_NumKeyboardEntries(m) == MGR_SizeKeyboardList(m)))
1884     {
1885 	i = MGR_SizeKeyboardList(m);
1886 
1887 	if (MGR_SizeKeyboardList(m) == 0)
1888 	{
1889 	    MGR_SizeKeyboardList(m) = 8;
1890 	    MGR_KeyboardList(m) =
1891 		(XmKeyboardData *)XtMalloc(sizeof(XmKeyboardData) *
1892 					   MGR_SizeKeyboardList(m));
1893 	}
1894 	else
1895 	{
1896 	    MGR_SizeKeyboardList(m) *= 2;
1897 	    MGR_KeyboardList(m) =
1898 		(XmKeyboardData *)XtRealloc((char *)MGR_KeyboardList(m),
1899 					    sizeof(XmKeyboardData) *
1900 					    MGR_SizeKeyboardList(m));
1901 	}
1902 
1903 	if (MGR_SizeKeyboardList(m) > i)
1904 	{
1905 	    memset(&MGR_KeyboardList(m)[i], 0,
1906 		  (MGR_SizeKeyboardList(m) - i) * sizeof(XmKeyboardData));
1907 	}
1908     }
1909     else
1910     {
1911 	i = MGR_NumKeyboardEntries(m);
1912     }
1913 
1914     if (MGR_KeyboardList(m)[i].component != NULL)
1915     {
1916 	_XmError(m, "This should not happen: %d\n", i);
1917     }
1918 
1919     memcpy(&MGR_KeyboardList(m)[i], item, sizeof(XmKeyboardData));
1920 
1921     MGR_NumKeyboardEntries(m)++;
1922 
1923     DEBUGOUT(_LtDebug(__FILE__, m,
1924 		      "GrabKey: key %04x Sym: %04x modifiers %08x %s %s\n",
1925 		      item->key, item->keysym, item->modifiers,
1926 		      item->needGrab ? "Grabbing" : "Not Grabbing",
1927 		      item->isMnemonic ? "mnemonic" : "not mnemonic"));
1928     DEBUGOUT(_LtDebug("NMEM", m,
1929 		      "GrabKey: key %04x Sym: %04x modifiers %08x %s %s\n",
1930 		      item->key, item->keysym, item->modifiers,
1931 		      item->needGrab ? "Grabbing" : "Not Grabbing",
1932 		      item->isMnemonic ? "mnemonic" : "not mnemonic"));
1933 #if 1
1934 	switch (item->eventType) {
1935 	case KeyPress:
1936 		mask = KeyPressMask;
1937 		break;
1938 	case KeyRelease:
1939 		mask = KeyReleaseMask;
1940 		break;
1941 	case ButtonPress:
1942 		mask = ButtonPressMask;
1943 		break;
1944 	case ButtonRelease:
1945 		mask = ButtonReleaseMask;
1946 		break;
1947 	default:
1948 #ifdef	LESSTIF_VERBOSE
1949 		_XmWarning(m, "AddKeyboardEntry: can't map event %d\n", item->eventType);
1950 #endif
1951 		mask = 0;
1952 	}
1953 #else
1954 	mask = KeyPressMask;
1955 	mask = item->eventType;	/* This must be wrong but the alternatives crash nedit. FIX ME */
1956 #endif
1957     XtInsertEventHandler(m, mask,
1958 			 False, _XmAcceleratorHandler,
1959 			 (XtPointer)w, XtListHead);
1960 
1961     if (item->needGrab)
1962     {
1963       /* Modified 21-Sep-04 - dwilliss - MicroImages, Inc
1964 	 Grab for accelerator - accelerator shouldn't care if CapsLock or NumLock
1965 	 is down, but we have to XtGrabKey with all combinations of them or we only
1966 	 get called if they're off. Ideally, the accelerator specification should
1967 	 have been able to tell us "only these modifiers" or "these modifiers plus
1968 	 any others" */
1969 	XtGrabKey(m, item->key, item->modifiers, False,
1970 		  GrabModeAsync, GrabModeAsync);
1971         XtGrabKey(m, item->key, item->modifiers | LockMask, False,
1972 		  GrabModeAsync, GrabModeAsync);
1973 	XtGrabKey(m, item->key, item->modifiers | Mod2Mask, False,
1974 		  GrabModeAsync, GrabModeAsync);
1975 	XtGrabKey(m, item->key, item->modifiers | Mod2Mask | LockMask, False,
1976 		  GrabModeAsync, GrabModeAsync);
1977     }
1978 }
1979 
1980 static void
DeleteKeyboardEntry(Widget m,Widget w,Boolean isMnemonic)1981 DeleteKeyboardEntry(Widget m, Widget w, Boolean isMnemonic)
1982 {
1983     int i;
1984 
1985     /* Danger, Will Robinson */
1986     if (CoreBeingDestroyed(m))
1987     {
1988 	return;
1989     }
1990 
1991     for (i = 0; i < MGR_NumKeyboardEntries(m); i++)
1992     {
1993 	if (MGR_KeyboardList(m) && w == MGR_KeyboardList(m)[i].component &&
1994 	    ((MGR_KeyboardList(m)[i].isMnemonic && isMnemonic) ||
1995 	     (!MGR_KeyboardList(m)[i].isMnemonic && !isMnemonic)))
1996 	{
1997 	    XmKeyboardData *data = &MGR_KeyboardList(m)[i];
1998 
1999 	    XtRemoveEventHandler(m, data->eventType, False,
2000 				 _XmAcceleratorHandler, w);
2001 
2002 	    if (data->needGrab)
2003 	    {
2004 	     /* Modified 21-Sep-04 - dwilliss - MicroImages, Inc
2005 		  To balance change made to AddKeyboardEntry above */
2006 		XtUngrabKey(m, data->key, data->modifiers);
2007 		XtUngrabKey(m, data->key, data->modifiers | LockMask);
2008 		XtUngrabKey(m, data->key, data->modifiers | Mod2Mask);
2009 		XtUngrabKey(m, data->key, data->modifiers | LockMask | Mod2Mask);
2010 	    }
2011 
2012 	    if (i < MGR_NumKeyboardEntries(m) - 1)
2013 	    {
2014 		memcpy(&MGR_KeyboardList(m)[i],
2015                        &MGR_KeyboardList(m)[i + 1],
2016 		       sizeof(XmKeyboardData) *
2017 		        (MGR_NumKeyboardEntries(m) - i - 1));
2018 
2019 		memset(&MGR_KeyboardList(m)[MGR_NumKeyboardEntries(m) - 1], 0,
2020 		      sizeof(XmKeyboardData));
2021 	    }
2022 	    /* end of list */
2023 	    else
2024 	    {
2025 		memset(&MGR_KeyboardList(m)[i], 0,
2026 		       sizeof(XmKeyboardData));
2027 	    }
2028 
2029 	    MGR_NumKeyboardEntries(m)--;
2030 	    break;
2031 	}
2032     }
2033 }
2034 
2035 void
_XmManagerInstallAccelerator(Widget m,Widget w,String s)2036 _XmManagerInstallAccelerator(Widget m, Widget w, String s)
2037 {
2038     Widget mw, sh;
2039     int eventType = 0;
2040     unsigned keysym = 0;
2041     unsigned int modifiers = 0;
2042     XmKeyboardData data;
2043 
2044     DEBUGOUT(_LtDebug2(__FILE__, m, w,
2045 		       "_XmManagerInstallAccelerator(%s)\n", s));
2046     DEBUGOUT(_LtDebug2("NMEM", m, w,
2047 		       "_XmManagerInstallAccelerator(%s)\n", s));
2048 
2049     /* Do we really have an accelerator ? */
2050     if (s == NULL || strlen(s) == 0)
2051 	return;
2052 
2053     /* Check whether we're in a menu system */
2054     mw = XtParent(w);
2055     if (!XmIsRowColumn(mw))
2056     {
2057 	return;
2058     }
2059 
2060     if (!(RC_Type(mw) == XmMENU_PULLDOWN || RC_Type(mw) == XmMENU_OPTION))
2061     {
2062 	return;
2063     }
2064 
2065     /* Find the manager widget just underneath the shell */
2066     for (mw = m; XtParent(mw); mw = sh)
2067     {
2068 	sh = XtParent(mw);
2069 
2070 	if (XtIsSubclass(sh, applicationShellWidgetClass) ||
2071 	    XtIsSubclass(sh, xmDialogShellWidgetClass) ||
2072 	    XtIsSubclass(sh, transientShellWidgetClass) ||
2073 	    XtIsSubclass(sh, topLevelShellWidgetClass))
2074 	{
2075 	    break;
2076 	}
2077     }
2078 
2079     if (!XmIsManager(mw))
2080     {
2081 	return;
2082     }
2083 
2084 
2085     DEBUGOUT(_LtDebug(__FILE__, w,
2086 		      "_XmManagerInstallAccelerator found manager %s\n",
2087 		      XtName(mw)));
2088 
2089 
2090     _XmMapKeyEvent(s, &eventType, &keysym, &modifiers);
2091 
2092     /* Put the data in the entry */
2093     data.component = w;
2094     data.eventType = eventType;
2095     data.isMnemonic = False;
2096     data.keysym = keysym;
2097     data.key = XKeysymToKeycode(XtDisplay(w), data.keysym);
2098     data.modifiers = modifiers;
2099     data.needGrab = True;
2100     if (data.key == 0)
2101     {
2102 #if 1
2103     KeySym real_sym;
2104     Modifiers real_mod;
2105 
2106 	_XmVirtualToActualKeysym(XtDisplay(w), data.keysym, &real_sym, &real_mod);
2107 	if (real_sym == NoSymbol && real_mod == (Modifiers)0)
2108 	{
2109 	    _XmWarning(m, "%s:_XmManagerInstallAccelerator(%d) - Could not convert >%s< to a KeyCode\n    %s -> %08x -> %i",
2110 		__FILE__, __LINE__, s,
2111 		s, data.keysym, data.key);
2112 	}
2113 	else
2114 	{
2115 	    data.key = XKeysymToKeycode(XtDisplay(w), real_sym);
2116 	    data.modifiers = real_mod;
2117 	    AddKeyboardEntry(mw, w, &data);
2118 	}
2119 #endif
2120     }
2121     else
2122     {
2123 	AddKeyboardEntry(mw, w, &data);
2124     }
2125 }
2126 
2127 void
_XmManagerUninstallAccelerator(Widget m,Widget w)2128 _XmManagerUninstallAccelerator(Widget m, Widget w)
2129 {
2130     Widget mw, sh;
2131 
2132     /* Find the manager widget just underneath the shell */
2133     for (mw = m; XtParent(mw); mw = sh)
2134     {
2135 	sh = XtParent(mw);
2136 	if (XtIsSubclass(sh, applicationShellWidgetClass) ||
2137 	    XtIsSubclass(sh, xmDialogShellWidgetClass) ||
2138 	    XtIsSubclass(sh, transientShellWidgetClass) ||
2139 		XtIsSubclass(sh, transientShellWidgetClass) ||
2140 		XtIsSubclass(sh, transientShellWidgetClass) ||
2141 	    XtIsSubclass(sh, topLevelShellWidgetClass))
2142 	{
2143 	    break;
2144 	}
2145     }
2146 
2147     if (!XmIsManager(mw))
2148     {
2149 	return;
2150     }
2151 
2152     DeleteKeyboardEntry(mw, w, False);
2153 }
2154 
2155 void
_XmManagerInstallMnemonic(Widget m,Widget w,KeySym mn)2156 _XmManagerInstallMnemonic(Widget m, Widget w, KeySym mn)
2157 {
2158     unsigned int modifiers = 0;
2159     Boolean need_grab = False;
2160     XmKeyboardData data;
2161 
2162     if (mn == 0 || mn == NoSymbol)
2163     {
2164 	return;
2165     }
2166 
2167     DEBUGOUT(_LtDebug2(__FILE__, m, w, "_XmManagerInstallMnemonic(%c)\n", mn));
2168     DEBUGOUT(_LtDebug2("NMEM", m, w, "_XmManagerInstallMnemonic(%c)\n", mn));
2169 
2170     /* If we're dealing with the menu bar, store the stuff in the highest
2171      * manager widget that you can find (with all the accelerators) */
2172     if (XmIsRowColumn(m) &&
2173 	(RC_Type(m) == XmMENU_PULLDOWN || RC_Type(m) == XmMENU_BAR || RC_Type(m) == XmMENU_OPTION))
2174     {
2175 	Widget mw, sh;
2176 	XmModifierMaskSetReference mods =
2177 	_XmGetModifierMappingsForDisplay(XtDisplay(w));
2178 
2179 	if (RC_Type(m) == XmMENU_PULLDOWN)
2180 	{
2181 	}
2182 	else
2183 	{
2184 	    need_grab = True;
2185 	    modifiers |= mods[ALTModifier];
2186 	}
2187 
2188 	for (mw = m; XtParent(mw); mw = sh)
2189 	{
2190 	    sh = XtParent(mw);
2191 	    if (XtIsSubclass(sh, applicationShellWidgetClass) ||
2192 		XtIsSubclass(sh, xmDialogShellWidgetClass) ||
2193 		XtIsSubclass(sh, topLevelShellWidgetClass) ||
2194 		(RC_Type(m) != XmMENU_BAR && XmIsRowColumn(mw) && RC_Type(mw) == XmMENU_BAR))
2195 	    {
2196 		break;
2197 	    }
2198 	}
2199 
2200 	DEBUGOUT(_LtDebug2(__FILE__, mw, w, "Store mnemonic info\n"));
2201 	DEBUGOUT(_LtDebug2("NMEM", mw, w, "Store mnemonic info\n"));
2202 	m = mw;
2203     }
2204 
2205     if (XmIsManager(m))
2206     {
2207 	/* Put the data in the entry */
2208 	data.component = w;
2209 	data.eventType = KeyPress;
2210 	data.keysym = mn;
2211 	data.isMnemonic = True;
2212 	data.key = XKeysymToKeycode(XtDisplay(w), data.keysym);
2213 	data.modifiers = modifiers;
2214 	data.needGrab = need_grab;
2215 
2216 	AddKeyboardEntry(m, w, &data);
2217     }
2218 }
2219 
2220 void
_XmManagerUninstallMnemonic(Widget m,Widget w)2221 _XmManagerUninstallMnemonic(Widget m, Widget w)
2222 {
2223     Widget mw, sh;
2224 
2225     if (XmIsRowColumn(m) &&
2226 	(RC_Type(m) == XmMENU_PULLDOWN || RC_Type(m) == XmMENU_BAR || RC_Type(m) == XmMENU_OPTION))
2227     {
2228 	/* Find the manager widget just underneath the shell */
2229 	for (mw = m; XtParent(mw); mw = sh)
2230 	{
2231 	    sh = XtParent(mw);
2232 	    if (XtIsSubclass(sh, applicationShellWidgetClass) ||
2233 		XtIsSubclass(sh, xmDialogShellWidgetClass) ||
2234 		XtIsSubclass(sh, topLevelShellWidgetClass) ||
2235 		(RC_Type(m) != XmMENU_BAR && XmIsRowColumn(mw) && RC_Type(mw) == XmMENU_BAR))
2236 	    {
2237 		break;
2238 	    }
2239 	}
2240     }
2241     else
2242     {
2243 	mw = m;
2244     }
2245 
2246     if (!XmIsManager(mw))
2247     {
2248 	return;
2249     }
2250 
2251     DeleteKeyboardEntry(mw, w, True);
2252 }
2253 
2254 static XmNavigability
widget_navigable(Widget w)2255 widget_navigable(Widget w)
2256 {
2257     if (XtSensitive(w) && MGR_TraversalOn(w))
2258     {
2259 	if (MGR_NavigationType(w) == XmSTICKY_TAB_GROUP ||
2260 	    MGR_NavigationType(w) == XmEXCLUSIVE_TAB_GROUP ||
2261 	    (MGR_NavigationType(w) == XmTAB_GROUP && !_XmShellIsExclusive(w)))
2262 	{
2263 	    DEBUGOUT(_LtDebug(__FILE__, w,
2264 			  "WidgetNavigable => XmDESCENDANTS_TAB_NAVIGABLE\n"));
2265 
2266 	    return XmDESCENDANTS_TAB_NAVIGABLE;
2267 	}
2268 	DEBUGOUT(_LtDebug(__FILE__, w,
2269 			  "WidgetNavigable => XmDESCENDANTS_NAVIGABLE\n"));
2270 
2271 	return XmDESCENDANTS_NAVIGABLE;
2272     }
2273 
2274     DEBUGOUT(_LtDebug(__FILE__, w, "WidgetNavigable => XmNOT_NAVIGABLE\n"));
2275 
2276     return XmNOT_NAVIGABLE;
2277 }
2278 
2279 
2280 void
_XmManagerHighlightPixmapDefault(Widget w,int offset,XrmValue * value)2281 _XmManagerHighlightPixmapDefault(Widget w, int offset, XrmValue *value)
2282 {
2283     static Pixmap pixmap;
2284 
2285     DEBUGOUT(_LtDebug(__FILE__, w, "_XmManagerHighlightPixmapDefault\n"));
2286 
2287     pixmap = XmUNSPECIFIED_PIXMAP;
2288 
2289     value->addr = (char *)&pixmap;
2290     value->size = sizeof(Pixmap);
2291 
2292     if (MGR_HighlightColor(w) == XtBackground(w))
2293 	pixmap = XmGetPixmapByDepth(XtScreen(w), "50_foreground",
2294 				    MGR_HighlightColor(w),
2295 				    MGR_Foreground(w),
2296 				    CoreDepth(w));
2297 }
2298 
2299 
2300 void
_XmManagerTopShadowPixmapDefault(Widget w,int offset,XrmValue * value)2301 _XmManagerTopShadowPixmapDefault(Widget w, int offset, XrmValue *value)
2302 {
2303     static Pixmap pixmap;
2304 
2305     DEBUGOUT(_LtDebug(__FILE__, w, "_XmManagerTopShadowPixmapDefault\n"));
2306 
2307     pixmap = XmUNSPECIFIED_PIXMAP;
2308 
2309     value->addr = (char *)&pixmap;
2310     value->size = sizeof(Pixmap);
2311 
2312     if (MGR_TopShadowColor(w) == XtBackground(w))
2313 	pixmap = XmGetPixmapByDepth(XtScreen(w), "50_foreground",
2314 				    MGR_TopShadowColor(w),
2315 				    MGR_Foreground(w),
2316 				    CoreDepth(w));
2317     else if (DefaultDepthOfScreen(XtScreen(w)) == 1)
2318 	pixmap = XmGetPixmapByDepth(XtScreen(w), "50_foreground",
2319 				    MGR_TopShadowColor(w),
2320 				    XtBackground(w),
2321 				    CoreDepth(w));
2322 }
2323 
2324 
2325 static void
_XmManagerExportX(Widget widget,int offset,XtArgVal * value)2326 _XmManagerExportX(Widget widget, int offset, XtArgVal *value)
2327 {
2328     unsigned char unitType = _XmGetUnitType(widget);
2329     int converted_value;
2330 
2331     if (XtIsManaged(widget) && XtParent(widget) && XmIsVendorShell(XtParent(widget)))
2332     {
2333 	*value = XtX(XtParent(widget));
2334     }
2335     converted_value = XmConvertUnits(widget,
2336 				     XmHORIZONTAL,
2337 				     XmPIXELS,
2338 				     *value,
2339 				     unitType);
2340 
2341     *value = converted_value;
2342 }
2343 
2344 static void
_XmManagerExportY(Widget widget,int offset,XtArgVal * value)2345 _XmManagerExportY(Widget widget, int offset, XtArgVal *value)
2346 {
2347     unsigned char unitType = _XmGetUnitType(widget);
2348     int converted_value;
2349 
2350     if (XtIsManaged(widget) && XtParent(widget) && XmIsVendorShell(XtParent(widget)))
2351     {
2352 	*value = XtY(XtParent(widget));
2353     }
2354     converted_value = XmConvertUnits(widget,
2355 				     XmVERTICAL,
2356 				     XmPIXELS,
2357 				     *value,
2358 				     unitType);
2359 
2360     *value = converted_value;
2361 }
2362 
2363 static XmDirection
get_direction(Widget w)2364 get_direction(Widget w)
2365 {
2366     /*
2367        This macro obtains the layout direction resource even
2368        though it looks like the string direction resource.
2369        In 2.0 layout direction replaced string direction
2370        but the identifier in the internal data structure stayed
2371        the same.  Everyone still with me. 8)
2372      */
2373     return MGR_StringDirection(w);
2374 }
2375 
2376 extern Widget
XmObjectAtPoint(Widget w,Position x,Position y)2377 XmObjectAtPoint(Widget w, Position x, Position y)
2378 {
2379 
2380    /* FIX ME */
2381    /* Used to be in GadgetUtil.c, but didn't do
2382       exactly what it is supposed to ... */
2383 
2384     int i;
2385 
2386     DEBUGOUT(_LtDebug(__FILE__, w, "XmObjectAtPoint()\n"));
2387     for (i = 0; i < (int)MGR_NumChildren(w); i++)
2388     {
2389 	Widget g = MGR_Children(w)[i];
2390 
2391 	if (!XtIsManaged(g))
2392 	{
2393 	    continue;
2394 	}
2395 
2396 	if ((x >= XtX(g) && x < XtX(g) + XtWidth(g)) &&
2397 	    (y >= XtY(g) && y < XtY(g) + XtHeight(g)))
2398 	{
2399 	    return g;
2400 	}
2401     }
2402     /* Northing found */
2403     return NULL;
2404 }
2405