1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22 */
23 #ifdef REV_INFO
24 #ifndef lint
25 static char rcsid[] = "$TOG: BulletinB.c /main/22 1999/10/13 16:15:40 mgreess $"
26 #endif
27 #endif
28 
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 
34 #include "BulletinBI.h"
35 #include <Xm/AtomMgr.h>
36 #include <Xm/BaseClassP.h>
37 #include <Xm/DialogS.h>
38 #include <Xm/DrawP.h>
39 #include <Xm/LabelG.h>
40 #include <Xm/MwmUtil.h>
41 #include <Xm/PushBGP.h>
42 #include <Xm/PushBP.h>
43 #include <Xm/Text.h>
44 #include <Xm/TextF.h>
45 #include <Xm/TransltnsP.h>
46 #include <Xm/VendorS.h>
47 #include <Xm/VendorSEP.h>
48 #include <Xm/TraitP.h>
49 #include <Xm/DialogSavvyT.h>
50 #include <Xm/SpecRenderT.h>
51 #include <Xm/TakesDefT.h>
52 #include <Xm/VaSimpleP.h>
53 #include "XmI.h"
54 #include "BaseClassI.h"
55 #include "CallbackI.h"
56 #include "GeoUtilsI.h"
57 #include "GMUtilsI.h"
58 #include "MessagesI.h"
59 #include "RepTypeI.h"
60 #include "TraversalI.h"
61 
62 /****************************************************************/
63 /* Local defines:
64 */
65 
66 #define STRING_CHARSET          "ISO8859-1"
67 #define	MARGIN_DEFAULT		10
68 
69 #define DONT_CARE               -1L
70 #define COMMON_FUNCS     (MWM_FUNC_CLOSE | MWM_FUNC_MOVE | MWM_FUNC_RESIZE)
71 #define DIALOG_FUNCS     COMMON_FUNCS
72 #define CLIENT_FUNCS     (COMMON_FUNCS | MWM_FUNC_MAXIMIZE | MWM_FUNC_MINIMIZE)
73 
74 #define WARN_DIALOG_STYLE	_XmMMsgBulletinB_0001
75 
76 
77 /********    Static Function Declarations    ********/
78 
79 static void ClassPartInitialize(
80                         WidgetClass w_class) ;
81 static void Initialize(
82                         Widget wid_req,
83                         Widget wid_new,
84                         ArgList args,
85                         Cardinal *numArgs) ;
86 static void Destroy(
87                         Widget wid) ;
88 static Boolean SetValues(
89                         Widget cw,
90                         Widget rw,
91                         Widget nw,
92                         ArgList args,
93                         Cardinal *num_args) ;
94 static Boolean SetValuesHook(
95                         Widget wid,
96                         ArgList args,
97                         Cardinal *num_args) ;
98 static void HandleChangeManaged(
99                         XmBulletinBoardWidget bbWid,
100                         XmGeoCreateProc geoMatrixCreate) ;
101 static void HandleResize(
102                         XmBulletinBoardWidget bbWid,
103                         XmGeoCreateProc geoMatrixCreate) ;
104 static XtGeometryResult HandleGeometryManager(
105                         Widget instigator,
106                         XtWidgetGeometry *desired,
107                         XtWidgetGeometry *allowed,
108                         XmGeoCreateProc geoMatrixCreate) ;
109 static void ChangeManaged(
110                         Widget wid) ;
111 static void UnmanageCallback(
112                         Widget w,
113                         XtPointer client_data,
114                         XtPointer call_data) ;
115 static void InsertChild(
116                         Widget child) ;
117 static void DeleteChild(
118                         Widget child) ;
119 static XtGeometryResult GeometryManager(
120                         Widget w,
121                         XtWidgetGeometry *request,
122                         XtWidgetGeometry *reply) ;
123 static XtGeometryResult QueryGeometry(
124                         Widget wid,
125                         XtWidgetGeometry *intended,
126                         XtWidgetGeometry *desired) ;
127 static void Resize(
128                         Widget wid) ;
129 static void Redisplay(
130                         Widget wid,
131                         XEvent *event,
132                         Region region) ;
133 static Boolean BulletinBoardParentProcess(
134                         Widget wid,
135                         XmParentProcessData event) ;
136 static void GetDialogTitle(
137                         Widget bb,
138                         int resource,
139                         XtArgVal *value) ;
140 static Widget GetBBWithDB(
141                         Widget wid) ;
142 static XmFontList GetTable(Widget wid,
143 			   XtEnum type);
144 static void CallMapUnmap(Widget wid,
145 			 Boolean map_unmap) ;
146 static void BulletinBoardSetDefaultShadow(
147                         Widget button) ;
148 static void BBUpdateDynDefaultButton(
149                          Widget bb) ;
150 static void CheckSetRenderTables(Widget wid,
151 				int offset,
152 				XrmValue *value);
153 
154 /********    End Static Function Declarations    ********/
155 
156 
157 /*  default translation table and action list  */
158 
159 #define defaultTranslations	_XmBulletinB_defaultTranslations
160 
161 static XtActionsRec actionsList[] =
162 {
163 	{ "Return",	_XmBulletinBoardReturn },       /*Motif 1.0 BC. */
164 	{ "BulletinBoardReturn", _XmBulletinBoardReturn },
165         { "BulletinBoardCancel", _XmBulletinBoardCancel },
166 	{ "BulletinBoardMap",    _XmBulletinBoardMap },
167 };
168 
169 
170 
171 /*  Resource definitions for BulletinBoard
172  */
173 
174 static XmSyntheticResource syn_resources[] =
175 {
176 	{	XmNdialogTitle,
177 		sizeof (XmString),
178 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.dialog_title),
179 		GetDialogTitle,
180 		NULL
181 	},
182 	{	XmNmarginWidth,
183 		sizeof (Dimension),
184 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.margin_width),
185 		XmeFromHorizontalPixels,
186 		XmeToHorizontalPixels
187 	},
188 
189 	{	XmNmarginHeight,
190 		sizeof (Dimension),
191 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.margin_height),
192 		XmeFromVerticalPixels,
193 		XmeToVerticalPixels
194 	},
195 };
196 
197 
198 
199 static XtResource resources[] =
200 {
201 	{	XmNshadowType,
202 		XmCShadowType, XmRShadowType, sizeof (unsigned char),
203 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.shadow_type),
204 		XmRImmediate, (XtPointer) XmSHADOW_OUT
205 	},
206 
207 	{
208 		XmNshadowThickness,
209 		XmCShadowThickness, XmRHorizontalDimension, sizeof (Dimension),
210 		XtOffsetOf( struct _XmBulletinBoardRec, manager.shadow_thickness),
211 		XmRImmediate, (XtPointer) XmINVALID_DIMENSION
212 	},
213 
214 	{	XmNmarginWidth,
215 		XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
216 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.margin_width),
217 		XmRImmediate, (XtPointer) MARGIN_DEFAULT
218 	},
219 
220 	{	XmNmarginHeight,
221 		XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
222 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.margin_height),
223 		XmRImmediate, (XtPointer) MARGIN_DEFAULT
224 	},
225 
226 	{	XmNdefaultButton,
227 		XmCWidget, XmRWidget, sizeof (Widget),
228 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.default_button),
229 		XmRImmediate, (XtPointer) NULL
230 	},
231 
232 	{	XmNcancelButton,
233 		XmCWidget, XmRWidget, sizeof (Widget),
234 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.cancel_button),
235 		XmRImmediate, (XtPointer) NULL
236 	},
237 
238 	{	XmNfocusCallback,
239 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
240 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.focus_callback),
241 		XmRImmediate, (XtPointer) NULL
242 	},
243 	{	XmNmapCallback,
244 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
245 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.map_callback),
246 		XmRImmediate, (XtPointer) NULL
247 	},
248 
249 	{	XmNunmapCallback,
250 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
251 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.unmap_callback),
252 		XmRImmediate, (XtPointer) NULL
253 	},
254 	{	"pri.vate", "Pri.vate",
255 	 	XmRUnsignedChar, sizeof (unsigned char),
256 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.check_set),
257 		XmRImmediate, 0
258 	},
259 	{	XmNbuttonFontList,
260 		XmCButtonFontList, XmRButtonFontList, sizeof (XmFontList),
261 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.button_font_list),
262 		XmRCallProc, (XtPointer) CheckSetRenderTables
263 	},
264 
265 	{	XmNlabelFontList,
266 		XmCLabelFontList, XmRLabelFontList, sizeof (XmFontList),
267 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.label_font_list),
268 		XmRCallProc, (XtPointer) CheckSetRenderTables
269 	},
270 
271 	{	XmNtextFontList,
272 		XmCTextFontList, XmRTextFontList, sizeof (XmFontList),
273 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.text_font_list),
274 		XmRCallProc, (XtPointer) CheckSetRenderTables
275 	},
276 
277 	{	XmNbuttonRenderTable,
278 		XmCButtonRenderTable, XmRButtonRenderTable, sizeof (XmRenderTable),
279 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.button_font_list),
280 		XmRCallProc, (XtPointer)CheckSetRenderTables
281 	},
282 
283 	{	XmNlabelRenderTable,
284 		XmCLabelRenderTable, XmRLabelRenderTable, sizeof (XmRenderTable),
285 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.label_font_list),
286 		XmRCallProc, (XtPointer)CheckSetRenderTables
287 	},
288 
289 	{	XmNtextRenderTable,
290 		XmCTextRenderTable, XmRTextRenderTable, sizeof (XmRenderTable),
291 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.text_font_list),
292 		XmRCallProc, (XtPointer)CheckSetRenderTables
293 	},
294 
295 	{	XmNtextTranslations,
296 		XmCTranslations, XmRTranslationTable, sizeof (XtTranslations),
297 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.text_translations),
298 		XmRImmediate, (XtPointer) NULL
299 	},
300 
301 	{	XmNallowOverlap,
302 		XmCAllowOverlap, XmRBoolean, sizeof (Boolean),
303 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.allow_overlap),
304 		XmRImmediate, (XtPointer) True
305 	},
306 
307 	{	XmNautoUnmanage,
308 		XmCAutoUnmanage, XmRBoolean, sizeof (Boolean),
309 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.auto_unmanage),
310 		XmRImmediate, (XtPointer) True
311 	},
312 
313 	{	XmNdefaultPosition,
314 		XmCDefaultPosition, XmRBoolean, sizeof (Boolean),
315 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.default_position),
316 		XmRImmediate, (XtPointer) True
317 	},
318 
319 	{	XmNresizePolicy,
320 		XmCResizePolicy, XmRResizePolicy, sizeof (unsigned char),
321 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.resize_policy),
322 		XmRImmediate, (XtPointer) XmRESIZE_ANY
323 	},
324 
325 	{	XmNnoResize,
326 		XmCNoResize, XmRBoolean, sizeof (Boolean),
327 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.no_resize),
328 		XmRImmediate, (XtPointer) False
329 	},
330 
331 	{	XmNdialogStyle,
332 		XmCDialogStyle, XmRDialogStyle, sizeof (unsigned char),
333 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.dialog_style),
334 		XmRImmediate, (XtPointer) XmDIALOG_MODELESS
335 	},
336 
337 	{	XmNdialogTitle,
338 		XmCDialogTitle, XmRXmString, sizeof (XmString),
339 		XtOffsetOf( struct _XmBulletinBoardRec, bulletin_board.dialog_title),
340 		XmRImmediate, (XtPointer) NULL
341 	},
342 
343 };
344 
345 
346 
347 /****************************************************************
348  *
349  *	BulletinBoard class record
350  *
351  ****************************************************************/
352 
353 externaldef( xmbulletinboardclassrec) XmBulletinBoardClassRec
354                                                       xmBulletinBoardClassRec =
355 {
356    {			/* core_class fields      */
357       (WidgetClass) &xmManagerClassRec,		/* superclass         */
358       "XmBulletinBoard",			/* class_name         */
359       sizeof(XmBulletinBoardRec),		/* widget_size        */
360       NULL,					/* class_initialize   */
361       ClassPartInitialize,			/* class_part_init    */
362       FALSE,					/* class_inited       */
363       Initialize,				/* initialize         */
364       NULL,					/* initialize_hook    */
365       XtInheritRealize,                    	/* realize            */
366       actionsList,		                /* actions	      */
367       XtNumber(actionsList),			/* num_actions	      */
368       resources,	                	/* resources          */
369       XtNumber(resources),			/* num_resources      */
370       NULLQUARK,				/* xrm_class          */
371       TRUE,					/* compress_motion    */
372       XtExposeCompressMaximal,			/* compress_exposure  */
373       TRUE,					/* compress_enterlv   */
374       FALSE,					/* visible_interest   */
375       Destroy,                                  /* destroy            */
376       Resize,					/* resize             */
377       Redisplay,        			/* expose             */
378       SetValues,	                	/* set_values         */
379       SetValuesHook,				/* set_values_hook    */
380       XtInheritSetValuesAlmost, 		/* set_values_almost  */
381       NULL,					/* get_values_hook    */
382       NULL,					/* accept_focus       */
383       XtVersion,				/* version            */
384       NULL,					/* callback_private   */
385       defaultTranslations,                      /* tm_table           */
386       QueryGeometry,	                        /* query_geometry     */
387       NULL,             	                /* display_accelerator*/
388       NULL,		                        /* extension          */
389    },
390 
391    {		/* composite_class fields */
392       GeometryManager,    	                /* geometry_manager   */
393       ChangeManaged,		                /* change_managed     */
394       InsertChild,				/* insert_child       */
395       DeleteChild,				/* delete_child       */
396       NULL,                                     /* extension          */
397    },
398 
399    {		/* constraint_class fields */
400       NULL,					/* resource list        */
401       0,					/* num resources        */
402       sizeof(XmManagerConstraintRec),		/* constraint size      */
403       NULL,					/* init proc            */
404       NULL,             			/* destroy proc         */
405       NULL,					/* set values proc      */
406       NULL,                                     /* extension            */
407    },
408 
409    {		/* manager_class fields */
410       XtInheritTranslations,			/* default translations   */
411       syn_resources,				/* syn_resources      	  */
412       XtNumber (syn_resources),			/* num_syn_resources 	  */
413       NULL,					/* syn_cont_resources     */
414       0,					/* num_syn_cont_resources */
415       BulletinBoardParentProcess,               /* parent_process         */
416       NULL,					/* extension		  */
417    },
418 
419    {		/* bulletinBoard class fields */
420       FALSE,                                    /*always_install_accelerators*/
421       NULL,                                     /* geo_matrix_create */
422       _XmBulletinBoardFocusMoved,               /* focus_moved_proc */
423       NULL					/* extension */
424    }
425 };
426 
427 externaldef( xmbulletinboardwidgetclass) WidgetClass xmBulletinBoardWidgetClass
428                                      = (WidgetClass) &xmBulletinBoardClassRec ;
429 
430 
431 /* Trait record for BulletinB specify render table */
432 
433 static XmConst XmSpecRenderTraitRec bulletinbSRT = {
434   0,		/* version */
435   GetTable,
436 };
437 
438 
439 /* Trait record for BulletinB dialog shell savvy */
440 
441 static XmConst XmDialogSavvyTraitRec bulletinbDST = {
442   0,		/* version */
443   CallMapUnmap,
444 };
445 
446 
447 /*
448  * Copy the XmString in XmNdialogTitle before returning it to the user.
449  */
450 /*ARGSUSED*/
451 static void
GetDialogTitle(Widget bb,int resource,XtArgVal * value)452 GetDialogTitle(
453         Widget bb,
454         int resource,		/* unused */
455         XtArgVal *value)
456 {
457     XmString      data ;
458 /****************/
459 
460     data = XmStringCopy((XmString) ((XmBulletinBoardWidget) bb)
461                                                 ->bulletin_board.dialog_title);
462     *value = (XtArgVal) data ;
463 
464     return ;
465     }
466 
467 
468 /****************************************************************/
469 static void
ClassPartInitialize(WidgetClass w_class)470 ClassPartInitialize(
471         WidgetClass w_class )
472 {
473     XmBulletinBoardWidgetClass bbClass
474 	= (XmBulletinBoardWidgetClass) w_class ;
475     XmBulletinBoardWidgetClass bbSuper
476 	= (XmBulletinBoardWidgetClass) w_class->core_class.superclass ;
477 
478 
479     _XmFastSubclassInit (w_class, XmBULLETIN_BOARD_BIT);
480 
481     if (bbClass->bulletin_board_class.geo_matrix_create
482        == XmInheritGeoMatrixCreate    )
483 	{   bbClass->bulletin_board_class.geo_matrix_create
484 		= bbSuper->bulletin_board_class.geo_matrix_create ;
485         }
486     if (bbClass->bulletin_board_class.focus_moved_proc
487 	== XmInheritFocusMovedProc    )
488 	{   bbClass->bulletin_board_class.focus_moved_proc
489 		= bbSuper->bulletin_board_class.focus_moved_proc ;
490         }
491 
492     /* Install the specifyrendertable trait for all subclasses */
493     XmeTraitSet((XtPointer)w_class, XmQTspecifyRenderTable,
494 		(XtPointer) &bulletinbSRT);
495 
496     /* Install the dialogShellsavyy trait for all subclasses */
497     XmeTraitSet((XtPointer)w_class, XmQTdialogShellSavvy,
498 		(XtPointer) &bulletinbDST);
499 
500     return ;
501 }
502 
503 
504 /****************************************************************
505  * Initialize a BulletinBoard instance.
506  ****************/
507 /*ARGSUSED*/
508 static void
Initialize(Widget wid_req,Widget wid_new,ArgList args,Cardinal * numArgs)509 Initialize(
510         Widget wid_req,
511         Widget wid_new,
512         ArgList args,		/* unused */
513         Cardinal *numArgs )	/* unused */
514 {
515             XmBulletinBoardWidget request = (XmBulletinBoardWidget) wid_req ;
516             XmBulletinBoardWidget new_w = (XmBulletinBoardWidget) wid_new ;
517             Arg             al[5] ;
518     register Cardinal       ac ;
519             int             mwm_functions ;
520             char *          text_value ;
521             XmFontList      defaultFL ;
522             int             mwmStyle ;
523             Widget          ancestor ;
524             XmWidgetExtData extData ;
525             XmBulletinBoardWidgetClass bbClass ;
526             XmVendorShellExtObject vendorExt;
527 /****************/
528 
529     new_w->bulletin_board.in_set_values = False ;
530     new_w->bulletin_board.geo_cache = (XmGeoMatrix) NULL ;
531     new_w->bulletin_board.initial_focus = TRUE ;
532 
533     /*	Copy font list data.
534     */
535     defaultFL = BB_ButtonFontList( new_w) ;
536     if(    !defaultFL    )
537     {   defaultFL = XmeGetDefaultRenderTable( (Widget) new_w, XmBUTTON_FONTLIST) ;
538         }
539     BB_ButtonFontList( new_w) = XmFontListCopy( defaultFL) ;
540 
541     defaultFL = BB_LabelFontList( new_w) ;
542     if(    !defaultFL    )
543     {   defaultFL = XmeGetDefaultRenderTable( (Widget) new_w, XmLABEL_FONTLIST) ;
544         }
545     BB_LabelFontList( new_w) = XmFontListCopy( defaultFL) ;
546 
547     defaultFL = BB_TextFontList( new_w) ;
548     if(    !defaultFL    )
549     {   defaultFL = XmeGetDefaultRenderTable( (Widget) new_w, XmTEXT_FONTLIST) ;
550         }
551     BB_TextFontList( new_w) = XmFontListCopy( defaultFL) ;
552 
553     if(    (request->manager.shadow_thickness == XmINVALID_DIMENSION)
554        && XtIsShell( XtParent( request))    ){
555 	new_w->manager.shadow_thickness = 1 ;
556     }
557     if(new_w->manager.shadow_thickness == XmINVALID_DIMENSION)
558 	new_w->manager.shadow_thickness = 0 ;
559 
560     /* Default and Cancel buttons are Set/Get resources only.  The
561     *   DefaultButton field is used as a marker for the state of buttons
562     *   in the child list.  As such, it is essential that it is NULL at
563     *   the end of Initialize.
564     */
565     BB_DefaultButton( new_w) = NULL ;
566     BB_CancelButton( new_w) = NULL ;
567 
568     /* The DynamicButton fields are managed and will be set appropriately
569     *   in the focus moved callback routine.
570     */
571     BB_DynamicDefaultButton( new_w) = NULL ;
572     BB_DynamicCancelButton( new_w) = NULL ;
573 
574     new_w->bulletin_board.old_shadow_thickness = 0 ;
575 
576     if(    request->bulletin_board.dialog_title    )
577     {
578         new_w->bulletin_board.dialog_title = XmStringCopy(
579                                         request->bulletin_board.dialog_title) ;
580         XmeSetWMShellTitle(new_w->bulletin_board.dialog_title,
581 			   XtParent(new_w)) ;
582         }
583     /*	Set parent attributes.
584     */
585     ac = 0 ;
586     text_value = NULL ;
587 
588     /*	Turn off window manager resize.
589     */
590     if(    request->bulletin_board.no_resize
591         && XmIsVendorShell( XtParent( new_w))    )
592     {
593         int old_mwm_functions ;
594 
595         XtSetArg( al[0], XmNmwmFunctions, &old_mwm_functions) ;
596 	XtGetValues( XtParent( new_w), al, 1) ;
597 
598 	mwm_functions = (int)
599 	  (XmIsDialogShell(XtParent(new_w)) ? DIALOG_FUNCS : CLIENT_FUNCS);
600 	if(    old_mwm_functions != DONT_CARE    )
601 	  {
602             mwm_functions |= old_mwm_functions ;
603 	  }
604         mwm_functions &= ~MWM_FUNC_RESIZE ;
605         XtSetArg( al[ac], XmNmwmFunctions, mwm_functions) ;  ac++ ;
606         }
607 
608     /* If parent is DialogShell, set dialog attributes and realize.
609     */
610     if(    XmIsDialogShell (XtParent (request))    )
611     {
612         new_w->bulletin_board.shell = XtParent( request) ;
613 
614         switch(    request->bulletin_board.dialog_style    )
615         {
616             case XmDIALOG_PRIMARY_APPLICATION_MODAL:
617             {   mwmStyle = MWM_INPUT_PRIMARY_APPLICATION_MODAL ;
618                 break ;
619                 }
620             case XmDIALOG_FULL_APPLICATION_MODAL:
621             {   mwmStyle = MWM_INPUT_FULL_APPLICATION_MODAL ;
622                 break;
623                 }
624             case XmDIALOG_SYSTEM_MODAL:
625             {   mwmStyle = MWM_INPUT_SYSTEM_MODAL ;
626                 break ;
627                 }
628             case XmDIALOG_MODELESS:
629             default:
630             {   mwmStyle = MWM_INPUT_MODELESS ;
631                 break ;
632                 }
633             }
634         XtSetArg( al[ac], XmNmwmInputMode, mwmStyle) ;  ac++ ;
635         XtSetValues( new_w->bulletin_board.shell, al, ac) ;
636         XtRealizeWidget( new_w->bulletin_board.shell) ;
637         }
638     else
639     {   new_w->bulletin_board.shell = NULL ;
640         if(    ac    )
641         {   XtSetValues( XtParent (request), al, (Cardinal) ac) ;
642             }
643         }
644     XtFree( text_value) ;
645 
646     if(    !XmRepTypeValidValue( XmRID_SHADOW_TYPE,
647                             new_w->bulletin_board.shadow_type, (Widget) new_w)    )
648     {   new_w->bulletin_board.shadow_type = XmSHADOW_OUT ;
649         }
650 
651     if(    !XmRepTypeValidValue( XmRID_RESIZE_POLICY,
652                           new_w->bulletin_board.resize_policy, (Widget) new_w)    )
653     {   new_w->bulletin_board.resize_policy = XmRESIZE_ANY ;
654         }
655 
656     if(    new_w->bulletin_board.shell    )
657     {
658         if(    !XmRepTypeValidValue( XmRID_DIALOG_STYLE,
659                            new_w->bulletin_board.dialog_style, (Widget) new_w)    )
660         {   new_w->bulletin_board.dialog_style = XmDIALOG_MODELESS ;
661             }
662         }
663     else
664     {   if(    new_w->bulletin_board.dialog_style != XmDIALOG_MODELESS    )
665         {
666             XmeWarning( (Widget) new_w, WARN_DIALOG_STYLE) ;
667             new_w->bulletin_board.dialog_style = XmDIALOG_MODELESS ;
668             }
669         }
670     /* Set source widget for accelerators used
671     *   by Manager in ConstraintInitialize.
672     */
673     if(    new_w->core.accelerators    )
674     {   new_w->manager.accelerator_widget = (Widget) new_w ;
675         }
676 
677     bbClass = (XmBulletinBoardWidgetClass) new_w->core.widget_class ;
678 
679     if(    bbClass->bulletin_board_class.focus_moved_proc    )
680     {
681         /* Walk up hierarchy to find vendor shell.  Then setup moved focus
682         *   callback so default button can be maintained.
683         */
684         ancestor = XtParent( new_w) ;
685         while(    ancestor  &&  !XmIsVendorShell( ancestor)    )
686         {   ancestor = XtParent( ancestor) ;
687             }
688         if(    ancestor
689 	   && (extData = _XmGetWidgetExtData( ancestor, XmSHELL_EXTENSION))
690 	   && (extData->widget)  )
691         {
692              vendorExt = (XmVendorShellExtObject) extData->widget;
693 
694             _XmAddCallback((InternalCallbackList *) &(vendorExt->vendor.focus_moved_callback),
695                             (XtCallbackProc) bbClass->bulletin_board_class.focus_moved_proc,
696                             (XtPointer) new_w) ;
697         }
698     }
699     new_w->bulletin_board.old_width = new_w->core.width;  /* may be 0 */
700     new_w->bulletin_board.old_height = new_w->core.height;        /* may be 0 */
701 
702     return ;
703 }
704 
705 
706 /****************************************************************
707  * Free fontlists, etc.
708  ****************/
709 static void
Destroy(Widget wid)710 Destroy(
711         Widget wid )
712 {
713     XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
714     Widget          ancestor ;
715     XmWidgetExtData extData ;
716     XmBulletinBoardWidgetClass bbClass ;
717     XmVendorShellExtObject vendorExt;
718     int num_children, i;
719     Widget *childList;
720 
721  /*
722   * Fix for 5209 - Check all ancestors to see if they are also bulletin
723   *                boards.  If they are, check the values in the ancestor's
724   *                default_button, cancel_button, and dynamic buttons to
725   *                see if they match those of the bb being destroyed.  If
726   *                they do, set those fields on the ancestor to NULL to
727   *                avoid accessing freed memory in the future.
728   */
729     ancestor = XtParent( bb) ;
730     while(    ancestor  &&  !XmIsVendorShell( ancestor)    )
731        {
732            if (XmIsBulletinBoard(ancestor))
733            {
734              num_children = bb->composite.num_children;
735              childList = bb->composite.children;
736              for (i = 0; i < num_children; i++)
737              {
738                if (BB_CancelButton(ancestor) == childList[i])
739                  BB_CancelButton(ancestor) = NULL;
740                if (BB_DynamicCancelButton(ancestor) == childList[i])
741                  BB_DynamicCancelButton(ancestor) = NULL;
742                if (BB_DefaultButton(ancestor) == childList[i])
743                  BB_DefaultButton(ancestor) = NULL;
744                if (BB_DynamicDefaultButton(ancestor) == childList[i])
745                  BB_DynamicDefaultButton(ancestor) = NULL;
746              }
747            }
748            ancestor = XtParent( ancestor) ;
749        }
750   /* End 5209 */
751 
752 
753     XmStringFree( bb->bulletin_board.dialog_title) ;
754 
755     /*  Free geometry cache.
756     */
757     if(    bb->bulletin_board.geo_cache    )
758     {   _XmGeoMatrixFree( bb->bulletin_board.geo_cache) ;
759         }
760     /*	Free fontlists.
761     */
762     if(    bb->bulletin_board.button_font_list    )
763     {   XmFontListFree( bb->bulletin_board.button_font_list) ;
764         }
765     if(    bb->bulletin_board.label_font_list    )
766     {   XmFontListFree( bb->bulletin_board.label_font_list) ;
767         }
768     if(    bb->bulletin_board.text_font_list    )
769     {   XmFontListFree( bb->bulletin_board.text_font_list) ;
770         }
771 
772     bbClass = (XmBulletinBoardWidgetClass) bb->core.widget_class ;
773 
774 
775     if(    bbClass->bulletin_board_class.focus_moved_proc    )
776     {
777         /* Walk up hierarchy to find vendor shell.  Then remove focus moved
778         *   callback.
779         */
780         ancestor = XtParent( bb) ;
781         while(    ancestor  &&  !XmIsVendorShell( ancestor)    )
782         {   ancestor = XtParent( ancestor) ;
783             }
784         if(    ancestor
785             && !ancestor->core.being_destroyed
786             && (extData = _XmGetWidgetExtData( ancestor, XmSHELL_EXTENSION))  )
787         {
788              vendorExt = (XmVendorShellExtObject) extData->widget;
789 
790             _XmRemoveCallback((InternalCallbackList *) &(vendorExt->vendor.focus_moved_callback),
791                              (XtCallbackProc) bbClass->bulletin_board_class.focus_moved_proc,
792                              (XtPointer) bb) ;
793         }
794     }
795 }
796 
797 
798 /****************************************************************
799  * Modify attributes of a BulletinBoard instance.
800  ****************/
801 /*ARGSUSED*/
802 static Boolean
SetValues(Widget cw,Widget rw,Widget nw,ArgList args,Cardinal * num_args)803 SetValues(
804         Widget cw,
805         Widget rw,
806         Widget nw,
807         ArgList args,		/* unused */
808         Cardinal *num_args )	/* unused */
809 {
810     XmBulletinBoardWidget current = (XmBulletinBoardWidget) cw ;
811     XmBulletinBoardWidget request = (XmBulletinBoardWidget) rw ;
812     XmBulletinBoardWidget new_w = (XmBulletinBoardWidget) nw ;
813     Arg		    al[10] ;
814     register Cardinal       ac ;
815     int             mwm_functions ;
816     int             mwmStyle ;
817     unsigned int    numChildren ;
818     unsigned int    childIndex ;
819     Widget *        childList ;
820     Boolean flag = False ;
821 
822 /****************/
823 
824     current->bulletin_board.in_set_values = True ;
825 
826     if(new_w->bulletin_board.shadow_type
827        != current->bulletin_board.shadow_type) {
828 	if (XmRepTypeValidValue( XmRID_SHADOW_TYPE,
829 				new_w->bulletin_board.shadow_type,
830 				(Widget) new_w) )
831 	    flag = True ;
832 	else
833 	    new_w->bulletin_board.shadow_type =
834 		current->bulletin_board.shadow_type ;
835     }
836 
837     if(    (new_w->bulletin_board.resize_policy
838                                       != current->bulletin_board.resize_policy)
839         && !XmRepTypeValidValue( XmRID_RESIZE_POLICY,
840                           new_w->bulletin_board.resize_policy, (Widget) new_w)    )
841     {   new_w->bulletin_board.resize_policy
842                                       = current->bulletin_board.resize_policy ;
843         }
844 
845     if(    new_w->bulletin_board.dialog_style
846                                    != current->bulletin_board.dialog_style    )
847     {   if(    new_w->bulletin_board.shell    )
848         {
849             if(    !XmRepTypeValidValue( XmRID_DIALOG_STYLE,
850                            new_w->bulletin_board.dialog_style, (Widget) new_w)    )
851             {   new_w->bulletin_board.dialog_style
852                                        = current->bulletin_board.dialog_style ;
853                 }
854             }
855         else
856         {   if(    new_w->bulletin_board.dialog_style != XmDIALOG_MODELESS    )
857             {
858                 XmeWarning( (Widget) new_w, WARN_DIALOG_STYLE) ;
859                 new_w->bulletin_board.dialog_style
860                                        = current->bulletin_board.dialog_style ;
861                 }
862             }
863         }
864     /*	Update shell attributes.
865     */
866     if(    new_w->bulletin_board.dialog_title !=
867                                       current->bulletin_board.dialog_title    )
868     {   /* Update window manager title.
869         */
870         XmStringFree( current->bulletin_board.dialog_title) ;
871         new_w->bulletin_board.dialog_title = XmStringCopy(
872                                         request->bulletin_board.dialog_title) ;
873         XmeSetWMShellTitle(new_w->bulletin_board.dialog_title,
874 				    XtParent(new_w)) ;
875         }
876 
877 /*
878  * Fix for 2940 - If the parent of the BulletinBoard is a VendorShell or
879  *                related to VendorShell, check the no_resize and
880  *		  change it if necessary
881  */
882     if (XmIsVendorShell(XtParent(new_w)))
883     {
884         ac = 0 ;
885         /*	Turn window manager resize on or off.
886         */
887         if(    new_w->bulletin_board.no_resize != current->bulletin_board.no_resize    )
888         {
889             XtSetArg( al[0], XmNmwmFunctions, &mwm_functions) ;
890 	    XtGetValues( XtParent( new_w), al, 1) ;
891 
892 	    if(    mwm_functions == DONT_CARE    )
893 	      {
894 		mwm_functions = (int) (XmIsDialogShell(XtParent(new_w)) ?
895 				       DIALOG_FUNCS : CLIENT_FUNCS);
896 	      }
897             if(    new_w->bulletin_board.no_resize    )
898             {   mwm_functions &= ~MWM_FUNC_RESIZE ;
899                 }
900             else
901             {   mwm_functions |= MWM_FUNC_RESIZE ;
902                 }
903             XtSetArg( al[ac], XmNmwmFunctions, mwm_functions) ;  ac++ ;
904             }
905         if(    new_w->bulletin_board.shell    )
906         {
907           if(    new_w->bulletin_board.dialog_style
908                                    != current->bulletin_board.dialog_style    )
909           {   if(    !XmRepTypeValidValue( XmRID_DIALOG_STYLE,
910                              new_w->bulletin_board.dialog_style, (Widget) new_w)    )
911               {
912                   new_w->bulletin_board.dialog_style
913                                        = current->bulletin_board.dialog_style ;
914                   }
915               else
916               {   switch(    new_w->bulletin_board.dialog_style    )
917                   {
918                       case XmDIALOG_PRIMARY_APPLICATION_MODAL:
919                       {   mwmStyle = MWM_INPUT_PRIMARY_APPLICATION_MODAL ;
920                           break ;
921                           }
922                       case XmDIALOG_FULL_APPLICATION_MODAL:
923                       {   mwmStyle = MWM_INPUT_FULL_APPLICATION_MODAL ;
924                           break ;
925                           }
926                       case XmDIALOG_SYSTEM_MODAL:
927                       {   mwmStyle = MWM_INPUT_SYSTEM_MODAL ;
928                           break ;
929                           }
930                       case XmDIALOG_MODELESS:
931 	              default:
932                       {   mwmStyle = MWM_INPUT_MODELESS ;
933                           break ;
934                           }
935                       }
936                   XtSetArg( al[ac], XmNmwmInputMode, mwmStyle) ; ac++ ;
937                   }
938               }
939           }
940         if(    ac    )
941         {
942             XtSetValues( XtParent (new_w), al, ac) ;
943             }
944         }
945     /*	Copy new font list data, free previous.
946     */
947     if(    request->bulletin_board.button_font_list
948                                != current->bulletin_board.button_font_list    )
949     {   if(    current->bulletin_board.button_font_list    )
950         {   XmFontListFree( current->bulletin_board.button_font_list) ;
951             }
952         if(    new_w->bulletin_board.button_font_list    )
953         {   new_w->bulletin_board.button_font_list = XmFontListCopy(
954                                     request->bulletin_board.button_font_list) ;
955             }
956         if(    !new_w->bulletin_board.button_font_list    )
957         {   new_w->bulletin_board.button_font_list = XmFontListCopy(
958                      XmeGetDefaultRenderTable( (Widget) new_w, XmBUTTON_FONTLIST)) ;
959             }
960         }
961     if(    request->bulletin_board.label_font_list
962                                 != current->bulletin_board.label_font_list    )
963     {   if(    current->bulletin_board.label_font_list    )
964         {   XmFontListFree( current->bulletin_board.label_font_list) ;
965             }
966         if(    new_w->bulletin_board.label_font_list    )
967         {   new_w->bulletin_board.label_font_list = XmFontListCopy(
968                                      request->bulletin_board.label_font_list) ;
969             }
970         if(    !new_w->bulletin_board.label_font_list    )
971         {   new_w->bulletin_board.label_font_list = XmFontListCopy(
972                       XmeGetDefaultRenderTable( (Widget) new_w, XmLABEL_FONTLIST)) ;
973             }
974         }
975     if(    request->bulletin_board.text_font_list
976                                  != current->bulletin_board.text_font_list    )
977     {   if(    current->bulletin_board.text_font_list    )
978         {   XmFontListFree( current->bulletin_board.text_font_list) ;
979             }
980         if(    new_w->bulletin_board.text_font_list    )
981         {   new_w->bulletin_board.text_font_list = XmFontListCopy(
982                                       request->bulletin_board.text_font_list) ;
983             }
984         if(    !new_w->bulletin_board.text_font_list    )
985         {   new_w->bulletin_board.text_font_list = XmFontListCopy(
986                        XmeGetDefaultRenderTable( (Widget) new_w, XmTEXT_FONTLIST)) ;
987             }
988         }
989     if(    BB_DefaultButton( new_w) != BB_DefaultButton( current)    )
990     {
991         if(    !BB_DefaultButton( current)    )
992         {
993             /* This is the a new default button.  Notify all potential
994 	       default button that they might turn default on sooner
995             */
996             numChildren = new_w->composite.num_children ;
997             childList = new_w->composite.children ;
998             childIndex = 0 ;
999             while(childIndex < numChildren    )
1000             {
1001                 BulletinBoardSetDefaultShadow( childList[childIndex]) ;
1002 
1003                 ++childIndex ;
1004 	    }
1005 	}
1006 	BBUpdateDynDefaultButton( (Widget) new_w) ;
1007     }
1008     if(    !(new_w->manager.initial_focus) && BB_DefaultButton( new_w)    )
1009       {
1010 	_XmSetInitialOfTabGroup( (Widget) new_w, BB_DefaultButton( new_w)) ;
1011       }
1012 
1013 
1014     if(new_w->manager.shadow_thickness
1015        != current->manager.shadow_thickness) {
1016 	flag = True ;
1017 	new_w->bulletin_board.old_shadow_thickness =
1018 	    new_w->manager.shadow_thickness ;
1019     }
1020 
1021 
1022     if(    XtClass( new_w) == xmBulletinBoardWidgetClass    )
1023     {
1024      /* do the margin enforcement only for pure BB, not subclasses,
1025        which have their own layout */
1026 
1027 	if (((new_w->bulletin_board.margin_width !=
1028 	      current->bulletin_board.margin_width) ||
1029 	     (new_w->bulletin_board.margin_height !=
1030 	      current->bulletin_board.margin_height))) {
1031 	    /*
1032 	       Do not change size if not realized; otherwise, ChangeManaged
1033 	       will assume that the user set a size resource, and will not
1034 	       resize to fit children added after this call, but before
1035 	       realizing. ChangeManaged will perform layout at realize-time.
1036 	    */
1037 	    if (XtIsRealized((Widget)new_w)) {
1038 		/* move the child around if necessary */
1039 		_XmGMEnforceMargin((XmManagerWidget)new_w,
1040 			       new_w->bulletin_board.margin_width,
1041 			       new_w->bulletin_board.margin_height,
1042 			       False); /* use movewidget, no request */
1043 		_XmGMCalcSize ((XmManagerWidget)new_w,
1044 			   new_w->bulletin_board.margin_width,
1045 			   new_w->bulletin_board.margin_height,
1046 			   &new_w->core.width, &new_w->core.height);
1047 	    }
1048 	}
1049     }
1050 
1051     current->bulletin_board.in_set_values = False ;
1052 
1053     return( flag) ;
1054 }
1055 
1056 /****************************************************************/
1057 static Boolean
SetValuesHook(Widget wid,ArgList args,Cardinal * num_args)1058 SetValuesHook(
1059         Widget wid,
1060         ArgList args,
1061         Cardinal *num_args )
1062 {
1063         XmBulletinBoardWidget   bb = (XmBulletinBoardWidget) wid ;
1064 	int			i;
1065 	Widget			shell = bb->bulletin_board.shell;
1066 
1067 /****************/
1068 /* look the comments on MAGIC in DialogSavvyT.h */
1069 
1070     if (!shell)
1071       return (False);
1072 
1073     for (i=0; i<*num_args; i++)
1074       {
1075 	  if (strcmp (args[i].name, XmNx) == 0)
1076 	    {
1077 		if ((args[i].value == 0) && (XtX (bb) == 0))
1078 		  {
1079 		      XtX (bb) = XmDIALOG_SAVVY_FORCE_ORIGIN;
1080 		  }
1081 	    }
1082 	  if (strcmp (args[i].name, XmNy) == 0)
1083 	    {
1084 		if ((args[i].value == 0) && (XtY (bb) == 0))
1085 		  {
1086 		      XtY (bb) = XmDIALOG_SAVVY_FORCE_ORIGIN;
1087 		  }
1088 	    }
1089       }
1090     return (False);
1091 }
1092 
1093 
1094 /****************************************************************
1095  * Arrange widgets and make geometry request if necessary.
1096  ****************/
1097 static void
HandleChangeManaged(XmBulletinBoardWidget bbWid,XmGeoCreateProc geoMatrixCreate)1098 HandleChangeManaged(
1099         XmBulletinBoardWidget bbWid,
1100         XmGeoCreateProc geoMatrixCreate)
1101 {
1102             Dimension       desired_w = 0 ;
1103             Dimension       desired_h = 0 ;
1104             Dimension       allowed_w ;
1105             Dimension       allowed_h ;
1106             XmGeoMatrix     geoSpec ;
1107 /****************/
1108 
1109 	/* honor initial sizes if given and resize_none sizes */
1110     if (!XtIsRealized((Widget)bbWid)) {
1111 	if (XtWidth(bbWid)) desired_w = XtWidth(bbWid) ;
1112 	if (XtHeight(bbWid)) desired_h = XtHeight(bbWid) ;
1113     } else {
1114 	if(BB_ResizePolicy(bbWid) == XmRESIZE_NONE) {
1115 	    desired_w = XtWidth(bbWid) ;
1116 	    desired_h = XtHeight(bbWid) ;
1117 	}
1118     }
1119 
1120     geoSpec = (*geoMatrixCreate)( (Widget) bbWid, NULL, NULL) ;
1121 
1122     _XmGeoMatrixGet( geoSpec, XmGET_PREFERRED_SIZE) ;
1123 
1124     _XmGeoArrangeBoxes( geoSpec, (Position) 0, (Position) 0,
1125                                                       &desired_w, &desired_h) ;
1126     /*	Adjust desired width and height if resize_grow.
1127     */
1128     if(    BB_ResizePolicy( bbWid) == XmRESIZE_GROW    )
1129     {
1130 	Boolean		reset_w = False ;
1131         Boolean         reset_h = False ;
1132 
1133         if(    desired_w < XtWidth( bbWid)    )
1134 	{
1135 	    desired_w = XtWidth( bbWid) ;
1136 	    reset_w = True ;
1137 	    }
1138 	if(    desired_h < XtHeight( bbWid)    )
1139 	{
1140 	    desired_h = XtHeight( bbWid) ;
1141 	    reset_h = True ;
1142 	    }
1143 	if(    reset_w  ||  reset_h    )
1144 	{
1145             _XmGeoArrangeBoxes( geoSpec, (Position) 0, (Position) 0,
1146                      &desired_w, &desired_h) ;
1147             }
1148 	}
1149 
1150     /*	Request new geometry from parent.
1151     */
1152     if(    (desired_h != XtHeight( bbWid))
1153         || (desired_w != XtWidth( bbWid))    )
1154     {
1155         switch(    XtMakeResizeRequest( (Widget) bbWid, desired_w, desired_h,
1156                                      &allowed_w, &allowed_h)    )
1157         {
1158             case XtGeometryYes:
1159             {   break ;
1160                 }
1161             case XtGeometryAlmost:
1162             {
1163                 XtMakeResizeRequest( (Widget) bbWid, allowed_w, allowed_h,
1164                                   NULL, NULL) ;
1165                 _XmGeoArrangeBoxes( geoSpec, (Position) 0, (Position) 0,
1166                                  &allowed_w, &allowed_h) ;
1167                 break ;
1168                 }
1169             case XtGeometryNo:
1170 	    default:
1171             {   allowed_w = XtWidth( bbWid) ;
1172                 allowed_h = XtHeight( bbWid) ;
1173                 _XmGeoArrangeBoxes( geoSpec, (Position) 0, (Position) 0,
1174                                  &allowed_w, &allowed_h) ;
1175                 break ;
1176                 }
1177             }
1178         /*	Clear shadow if necessary.
1179         */
1180         if(    bbWid->bulletin_board.old_shadow_thickness
1181             && (   (allowed_w > bbWid->bulletin_board.old_width)
1182                 || (allowed_h > bbWid->bulletin_board.old_height))    )
1183         {
1184             _XmClearShadowType( (Widget) bbWid,
1185 			       bbWid->bulletin_board.old_width,
1186 			       bbWid->bulletin_board.old_height,
1187 			       bbWid->bulletin_board.old_shadow_thickness,
1188 			       (Dimension) 0) ;
1189             bbWid->bulletin_board.old_shadow_thickness = 0 ;
1190             }
1191         }
1192     /*	Update children.
1193     */
1194     _XmGeoMatrixSet( geoSpec) ;
1195 
1196     _XmGeoMatrixFree( geoSpec) ;
1197 
1198     if(    bbWid->manager.shadow_thickness
1199         && (XtWidth( bbWid) <= bbWid->bulletin_board.old_width)
1200         && (XtHeight( bbWid) <= bbWid->bulletin_board.old_height)    )
1201     {
1202         XmeDrawShadows(XtDisplay((Widget) bbWid),
1203 			XtWindow((Widget) bbWid),
1204 			bbWid->manager.top_shadow_GC,
1205 			bbWid->manager.bottom_shadow_GC,
1206 			0, 0,
1207 			bbWid->core.width, bbWid->core.height,
1208 			bbWid->manager.shadow_thickness,
1209 			bbWid->bulletin_board.shadow_type) ;
1210         bbWid->bulletin_board.old_shadow_thickness
1211                                             = bbWid->manager.shadow_thickness ;
1212         }
1213     bbWid->bulletin_board.old_width = bbWid->core.width ;
1214     bbWid->bulletin_board.old_height = bbWid->core.height ;
1215 
1216     XmeNavigChangeManaged( (Widget) bbWid) ;
1217 
1218     return ;
1219     }
1220 /****************************************************************
1221  * Arrange widgets based on new size.
1222  ****************/
1223 static void
HandleResize(XmBulletinBoardWidget bbWid,XmGeoCreateProc geoMatrixCreate)1224 HandleResize(
1225         XmBulletinBoardWidget bbWid,
1226         XmGeoCreateProc geoMatrixCreate)
1227 {
1228             Dimension       new_w = XtWidth( bbWid) ;
1229             Dimension       new_h = XtHeight( bbWid) ;
1230             XmGeoMatrix     geoSpec ;
1231 /*********** draw_shadow is not used **************
1232             Boolean         draw_shadow = False ;
1233 ****************/
1234 
1235     /*	Clear shadow.
1236     */
1237     if(    bbWid->bulletin_board.old_shadow_thickness
1238         && (   (bbWid->bulletin_board.old_width != bbWid->core.width)
1239             || (bbWid->bulletin_board.old_height != bbWid->core.height))    )
1240     {
1241 	_XmClearShadowType( (Widget) bbWid, bbWid->bulletin_board.old_width,
1242                               bbWid->bulletin_board.old_height,
1243                                bbWid->bulletin_board.old_shadow_thickness,
1244                                                                (Dimension) 0) ;
1245         bbWid->bulletin_board.old_shadow_thickness = 0 ;
1246 	}
1247 
1248     geoSpec = (*geoMatrixCreate)( (Widget) bbWid, NULL, NULL) ;
1249 
1250     _XmGeoMatrixGet( geoSpec, XmGET_PREFERRED_SIZE) ;
1251 
1252     _XmGeoArrangeBoxes( geoSpec, (Position) 0, (Position) 0, &new_w, &new_h) ;
1253 
1254     _XmGeoMatrixSet( geoSpec) ;
1255 
1256     if(    bbWid->manager.shadow_thickness
1257         && (XtWidth( bbWid) <= bbWid->bulletin_board.old_width)
1258         && (XtHeight( bbWid) <= bbWid->bulletin_board.old_height)    )
1259     {
1260         XmeDrawShadows(XtDisplay((Widget) bbWid),
1261 			XtWindow((Widget) bbWid),
1262 			bbWid->manager.top_shadow_GC,
1263 			bbWid->manager.bottom_shadow_GC,
1264 			0, 0,
1265 			bbWid->core.width, bbWid->core.height,
1266 			bbWid->manager.shadow_thickness,
1267 			bbWid->bulletin_board.shadow_type) ;
1268         bbWid->bulletin_board.old_shadow_thickness
1269                                             = bbWid->manager.shadow_thickness ;
1270         }
1271     bbWid->bulletin_board.old_width = bbWid->core.width ;
1272     bbWid->bulletin_board.old_height = bbWid->core.height ;
1273 
1274     _XmGeoMatrixFree( geoSpec) ;
1275     return ;
1276     }
1277 /****************************************************************
1278  * Handle geometry requests from children.
1279  ****************/
1280 static XtGeometryResult
HandleGeometryManager(Widget instigator,XtWidgetGeometry * desired,XtWidgetGeometry * allowed,XmGeoCreateProc geoMatrixCreate)1281 HandleGeometryManager(
1282         Widget instigator,
1283         XtWidgetGeometry *desired,
1284         XtWidgetGeometry *allowed,
1285         XmGeoCreateProc geoMatrixCreate)
1286 {
1287             XmBulletinBoardWidget bbWid ;
1288             XtGeometryResult result ;
1289 /****************/
1290 
1291     bbWid = (XmBulletinBoardWidget) XtParent( instigator) ;
1292 
1293     if(    !(desired->request_mode & (CWWidth | CWHeight))    )
1294     {   return (XtGeometryYes) ;
1295         }
1296 
1297     /*	Clear shadow if necessary.
1298     */
1299     if(    bbWid->bulletin_board.old_shadow_thickness
1300         && (BB_ResizePolicy( bbWid) != XmRESIZE_NONE)    )
1301     {
1302         _XmClearShadowType( (Widget) bbWid, bbWid->bulletin_board.old_width,
1303                               bbWid->bulletin_board.old_height,
1304                                bbWid->bulletin_board.old_shadow_thickness, 0) ;
1305         bbWid->bulletin_board.old_shadow_thickness = 0 ;
1306 	}
1307 
1308     result = _XmHandleGeometryManager( (Widget) bbWid,
1309                          instigator, desired, allowed, BB_ResizePolicy( bbWid),
1310                            &bbWid->bulletin_board.geo_cache, geoMatrixCreate) ;
1311 
1312     if(    !bbWid->bulletin_board.in_set_values
1313         && bbWid->manager.shadow_thickness
1314         && (XtWidth( bbWid) <= bbWid->bulletin_board.old_width)
1315         && (XtHeight( bbWid) <= bbWid->bulletin_board.old_height)    )
1316     {
1317         XmeDrawShadows(XtDisplay((Widget) bbWid),
1318 			XtWindow((Widget) bbWid),
1319 			bbWid->manager.top_shadow_GC,
1320 			bbWid->manager.bottom_shadow_GC,
1321 			0, 0,
1322 			bbWid->core.width, bbWid->core.height,
1323 			bbWid->manager.shadow_thickness,
1324 			bbWid->bulletin_board.shadow_type) ;
1325         bbWid->bulletin_board.old_shadow_thickness
1326                                             = bbWid->manager.shadow_thickness ;
1327         }
1328     bbWid->bulletin_board.old_width = bbWid->core.width ;
1329     bbWid->bulletin_board.old_height = bbWid->core.height ;
1330 
1331     return( result) ;
1332     }
1333 
1334 /****************************************************************/
1335 void
_XmBulletinBoardSizeUpdate(Widget wid)1336 _XmBulletinBoardSizeUpdate(
1337         Widget wid )
1338 {
1339             XmBulletinBoardWidget bbWid = (XmBulletinBoardWidget) wid ;
1340             XmBulletinBoardWidgetClass classPtr =
1341                         (XmBulletinBoardWidgetClass) bbWid->core.widget_class ;
1342 /****************/
1343 
1344     if(    !XtIsRealized((Widget)bbWid)    )
1345     {   return ;
1346         }
1347 
1348     if(    classPtr->bulletin_board_class.geo_matrix_create    )
1349     {
1350         /*	Clear shadow if necessary.
1351         */
1352         if(    bbWid->bulletin_board.old_shadow_thickness
1353             && (BB_ResizePolicy( bbWid) != XmRESIZE_NONE)    )
1354         {
1355             _XmClearShadowType( (Widget) bbWid,
1356                          bbWid->bulletin_board.old_width,
1357                             bbWid->bulletin_board.old_height,
1358                                bbWid->bulletin_board.old_shadow_thickness, 0) ;
1359             bbWid->bulletin_board.old_shadow_thickness = 0 ;
1360             }
1361 
1362         _XmHandleSizeUpdate( (Widget) bbWid, BB_ResizePolicy( bbWid),
1363                             classPtr->bulletin_board_class.geo_matrix_create) ;
1364 
1365         if(    bbWid->manager.shadow_thickness
1366             && (XtWidth( bbWid) <= bbWid->bulletin_board.old_width)
1367             && (XtHeight( bbWid) <= bbWid->bulletin_board.old_height)    )
1368         {
1369             XmeDrawShadows(XtDisplay((Widget) bbWid),
1370 			    XtWindow((Widget) bbWid),
1371 			    bbWid->manager.top_shadow_GC,
1372 			    bbWid->manager.bottom_shadow_GC,
1373 			    0, 0,
1374 			    bbWid->core.width, bbWid->core.height,
1375 			    bbWid->manager.shadow_thickness,
1376 			    bbWid->bulletin_board.shadow_type) ;
1377 	    bbWid->bulletin_board.old_shadow_thickness
1378 		= bbWid->manager.shadow_thickness ;
1379             }
1380         }
1381     bbWid->bulletin_board.old_width = bbWid->core.width ;
1382     bbWid->bulletin_board.old_height = bbWid->core.height ;
1383 
1384     return ;
1385     }
1386 
1387 /****************************************************************
1388  * Layout children of the BulletinBoard.
1389  ****************/
1390 static void
ChangeManaged(Widget wid)1391 ChangeManaged(
1392         Widget wid )
1393 {
1394             XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1395             XmBulletinBoardWidgetClass classPtr =
1396                            (XmBulletinBoardWidgetClass) bb->core.widget_class ;
1397 /****************/
1398 
1399     if(    classPtr->bulletin_board_class.geo_matrix_create    )
1400     {   HandleChangeManaged( bb,
1401                             classPtr->bulletin_board_class.geo_matrix_create) ;
1402         return ;
1403         }
1404 
1405     /* function shared with Bulletin Board */
1406     _XmGMEnforceMargin((XmManagerWidget)bb,
1407                      bb->bulletin_board.margin_width,
1408                      bb->bulletin_board.margin_height,
1409                      False); /* use movewidget, not setvalue */
1410 
1411     /*	Clear shadow if necessary.
1412     */
1413     if(    bb->bulletin_board.old_shadow_thickness    )
1414     {
1415         _XmClearShadowType( (Widget) bb, bb->bulletin_board.old_width,
1416 				bb->bulletin_board.old_height,
1417 				bb->bulletin_board.old_shadow_thickness, 0) ;
1418         bb->bulletin_board.old_shadow_thickness = 0 ;
1419         }
1420 
1421     /* The first time, reconfigure only if explicit size were not given */
1422 
1423     if (XtIsRealized((Widget)bb) || (!XtWidth(bb)) || (!XtHeight(bb))) {
1424       /* function shared with DrawingArea */
1425       (void)_XmGMDoLayout((XmManagerWidget)bb,
1426                           bb->bulletin_board.margin_width,
1427                           bb->bulletin_board.margin_height,
1428                           bb->bulletin_board.resize_policy,
1429                           False);  /* queryonly not specified */
1430     }
1431 
1432     if(    bb->manager.shadow_thickness
1433         && (XtWidth( bb) <= bb->bulletin_board.old_width)
1434         && (XtHeight( bb) <= bb->bulletin_board.old_height)    )
1435     {
1436         XmeDrawShadows(XtDisplay((Widget) bb),
1437 			XtWindow((Widget) bb),
1438 			bb->manager.top_shadow_GC,
1439 			bb->manager.bottom_shadow_GC,
1440 			0, 0,
1441 			bb->core.width, bb->core.height,
1442 			bb->manager.shadow_thickness,
1443 			bb->bulletin_board.shadow_type) ;
1444         bb->bulletin_board.old_shadow_thickness
1445                                                = bb->manager.shadow_thickness ;
1446         }
1447     bb->bulletin_board.old_width = bb->core.width ;
1448     bb->bulletin_board.old_height = bb->core.height ;
1449 
1450     XmeNavigChangeManaged( (Widget) bb) ;
1451 
1452     return ;
1453     }
1454 
1455 /****************************************************************
1456  * Unmanage BulletinBoard after button is activated.
1457  ****************/
1458 /*ARGSUSED*/
1459 static void
UnmanageCallback(Widget w,XtPointer client_data,XtPointer call_data)1460 UnmanageCallback(
1461         Widget w,		/* unused */
1462         XtPointer client_data,
1463         XtPointer call_data )	/* unused */
1464 {
1465             Widget          bb = (Widget) client_data ;
1466 /****************/
1467 
1468     XtUnmanageChild( bb) ;
1469 
1470     return ;
1471     }
1472 
1473 /****************************************************************
1474  * Add a child to the BulletinBoard.
1475  ****************/
1476 static void
InsertChild(Widget child)1477 InsertChild(
1478         Widget child )
1479 {
1480     XmBulletinBoardWidget bb = (XmBulletinBoardWidget) XtParent( child) ;
1481     Boolean         is_button = False ;
1482     XtWidgetProc insert_child;
1483 
1484     _XmProcessLock();
1485     insert_child = ((XmManagerWidgetClass) xmManagerWidgetClass)
1486 				  ->composite_class.insert_child;
1487     _XmProcessUnlock();
1488     (*insert_child)(child);
1489 
1490     if(    !XtIsRectObj( child)    )
1491     {   return ;
1492         }
1493 
1494     if(XmeTraitGet((XtPointer)XtClass(child), XmQTtakesDefault))
1495     {   is_button = TRUE ;
1496 
1497         if(    BB_DefaultButton( bb)    )
1498         {
1499             /* Notify child that it has to be ready for default visual
1500             */
1501             BulletinBoardSetDefaultShadow( child) ;
1502             }
1503         }
1504     if(    XmIsDrawnButton( child)    )
1505     {   is_button = True ;
1506         }
1507 
1508     /* Now, here I could use the activatable trait to add the
1509        auto_unmanage callback but I'm afraid that by covering the
1510        Arrow button I introduce behavior compatibility problem, so
1511        I keep the DrawnButton check for now */
1512 
1513     if(    is_button && bb->bulletin_board.shell
1514                                        && bb->bulletin_board.auto_unmanage    )
1515     {
1516         XtAddCallback( child, XmNactivateCallback,
1517                                             UnmanageCallback, (XtPointer) bb) ;
1518         }
1519     if(    XmIsText (child)
1520         || XmIsTextField (child)    )
1521     {
1522         if(    bb->bulletin_board.text_translations    )
1523         {   XtOverrideTranslations( child,
1524 				bb->bulletin_board.text_translations) ;
1525             }
1526         }
1527     return ;
1528     }
1529 
1530 /****************************************************************
1531  * Clear widget id in instance record
1532  ****************/
1533 static void
DeleteChild(Widget child)1534 DeleteChild(
1535         Widget child )
1536 {
1537   XmBulletinBoardWidget bb ;
1538   XtWidgetProc      delete_child;
1539 /****************/
1540 
1541   if(    XtIsRectObj( child)    )
1542     {
1543       bb = (XmBulletinBoardWidget) XtParent( child) ;
1544 
1545       /* To fix CR #4882, unnest the following to allow
1546 	 for one button to be more than one of the defined buttons */
1547       if(    child == BB_DefaultButton( bb)    )
1548 	BB_DefaultButton( bb) = NULL ;
1549       if(    child == BB_DynamicDefaultButton( bb)    )
1550 	BB_DynamicDefaultButton( bb) = NULL ;
1551       if(    child == BB_CancelButton( bb)    )
1552 	BB_CancelButton( bb) = NULL ;
1553       if(    child == BB_DynamicCancelButton( bb)    )
1554 	BB_DynamicCancelButton( bb) = NULL ;
1555     }
1556   _XmProcessLock();
1557   delete_child = ((XmManagerWidgetClass) xmManagerWidgetClass)
1558 	     			->composite_class.delete_child;
1559   _XmProcessUnlock();
1560   (*delete_child)(child);
1561   return ;
1562 }
1563 
1564 /****************************************************************/
1565 static XtGeometryResult
GeometryManager(Widget w,XtWidgetGeometry * request,XtWidgetGeometry * reply)1566 GeometryManager(
1567         Widget w,
1568         XtWidgetGeometry *request,
1569         XtWidgetGeometry *reply )
1570 {
1571             XmBulletinBoardWidget bb ;
1572             XmBulletinBoardWidgetClass classPtr ;
1573 /****************/
1574 
1575     bb = (XmBulletinBoardWidget) w->core.parent ;
1576     classPtr = (XmBulletinBoardWidgetClass) bb->core.widget_class ;
1577 
1578     if(    classPtr->bulletin_board_class.geo_matrix_create    )
1579     {   return( HandleGeometryManager( w, request, reply,
1580                            classPtr->bulletin_board_class.geo_matrix_create)) ;
1581         }
1582 
1583     /* function shared with DrawingArea */
1584     return(_XmGMHandleGeometryManager((Widget)bb, w, request, reply,
1585                                     bb->bulletin_board.margin_width,
1586                                     bb->bulletin_board.margin_height,
1587                                     bb->bulletin_board.resize_policy,
1588                                     bb->bulletin_board.allow_overlap));
1589     }
1590 
1591 /****************************************************************
1592  * Handle query geometry requests
1593  ****************/
1594 static XtGeometryResult
QueryGeometry(Widget wid,XtWidgetGeometry * intended,XtWidgetGeometry * desired)1595 QueryGeometry(
1596         Widget wid,
1597         XtWidgetGeometry *intended,
1598         XtWidgetGeometry *desired )
1599 {
1600             XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1601             XmBulletinBoardWidgetClass classPtr =
1602                            (XmBulletinBoardWidgetClass) bb->core.widget_class ;
1603 /****************/
1604 
1605     if(    classPtr->bulletin_board_class.geo_matrix_create    )
1606     {
1607         return( _XmHandleQueryGeometry( (Widget) bb,
1608                         intended, desired, BB_ResizePolicy( bb),
1609                            classPtr->bulletin_board_class.geo_matrix_create)) ;
1610         }
1611     /* function shared with DrawingArea */
1612     return(_XmGMHandleQueryGeometry(wid, intended, desired,
1613                                   bb->bulletin_board.margin_width,
1614                                   bb->bulletin_board.margin_height,
1615                                   bb->bulletin_board.resize_policy));
1616     }
1617 
1618 /****************************************************************
1619  * Conform to new size.
1620  ****************/
1621 static void
Resize(Widget wid)1622 Resize(
1623         Widget wid )
1624 {
1625             XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1626             XmBulletinBoardWidgetClass classPtr =
1627                            (XmBulletinBoardWidgetClass) bb->core.widget_class ;
1628 /****************/
1629 
1630     if(    classPtr->bulletin_board_class.geo_matrix_create    )
1631     {
1632         HandleResize( bb, classPtr->bulletin_board_class.geo_matrix_create) ;
1633         return ;
1634         }
1635     /*	Clear shadow.
1636     */
1637     if(    bb->bulletin_board.old_shadow_thickness    )
1638     {
1639         _XmClearShadowType( (Widget) bb, bb->bulletin_board.old_width,
1640 				bb->bulletin_board.old_height,
1641 				bb->bulletin_board.old_shadow_thickness, 0) ;
1642         bb->bulletin_board.old_shadow_thickness = 0 ;
1643         }
1644     if(    bb->manager.shadow_thickness
1645         && (XtWidth( bb) <= bb->bulletin_board.old_width)
1646         && (XtHeight( bb) <= bb->bulletin_board.old_height)    )
1647     {
1648         XmeDrawShadows(XtDisplay((Widget) bb),
1649 			XtWindow((Widget) bb),
1650 			bb->manager.top_shadow_GC,
1651 			bb->manager.bottom_shadow_GC,
1652 			0, 0,
1653 			bb->core.width, bb->core.height,
1654 			bb->manager.shadow_thickness,
1655 			bb->bulletin_board.shadow_type) ;
1656         bb->bulletin_board.old_shadow_thickness
1657                                                = bb->manager.shadow_thickness ;
1658         }
1659     bb->bulletin_board.old_width = bb->core.width ;
1660     bb->bulletin_board.old_height = bb->core.height ;
1661 
1662     return ;
1663     }
1664 
1665 /****************************************************************
1666  * Redisplay gadgets and draw shadow.
1667  ****************/
1668 static void
Redisplay(Widget wid,XEvent * event,Region region)1669 Redisplay(
1670         Widget wid,
1671         XEvent *event,
1672         Region region )
1673 {
1674             XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1675 /****************/
1676 
1677     /*	Redisplay gadgets.
1678     */
1679     XmeRedisplayGadgets( wid, event, region) ;
1680 
1681     /*	Draw shadow.
1682     */
1683     if(    bb->manager.shadow_thickness    )
1684     {
1685         XmeDrawShadows(XtDisplay((Widget) bb),
1686 			XtWindow((Widget) bb),
1687 			bb->manager.top_shadow_GC,
1688 			bb->manager.bottom_shadow_GC,
1689 			0, 0,
1690 			bb->core.width, bb->core.height,
1691 			bb->manager.shadow_thickness,
1692 			bb->bulletin_board.shadow_type) ;
1693         bb->bulletin_board.old_shadow_thickness
1694                                                = bb->manager.shadow_thickness ;
1695         }
1696     bb->bulletin_board.old_width = bb->core.width ;
1697     bb->bulletin_board.old_height = bb->core.height ;
1698 
1699     return ;
1700     }
1701 
1702 
1703 
1704 /****************************************************************/
1705 /*ARGSUSED*/
1706 void
_XmBulletinBoardFocusMoved(Widget wid,XtPointer client_data,XtPointer data)1707 _XmBulletinBoardFocusMoved(
1708         Widget wid,		/* unused */
1709         XtPointer client_data,
1710         XtPointer data )
1711 {
1712             XmFocusMovedCallbackStruct * call_data
1713                                         = (XmFocusMovedCallbackStruct *) data ;
1714             Widget          ancestor ;
1715 	    XmBulletinBoardWidget bb = (XmBulletinBoardWidget) client_data ;
1716             XmAnyCallbackStruct	cb ;
1717             Boolean         BBHasFocus = FALSE ;
1718             Boolean         BBHadFocus = FALSE ;
1719             Widget          dbutton = NULL ;
1720             Widget          cbutton = NULL ;
1721 /****************/
1722 
1723     if(    !call_data->cont    )
1724     {   /* Preceding callback routine wants focus-moved processing
1725         *   to be discontinued.
1726         */
1727         return ;
1728         }
1729 
1730     /* Walk the heirarchy above the widget that is getting the focus to
1731     *   determine the correct default and cancel buttons for the current
1732     *   context.
1733     *  Note that no changes are made to the Bulletin Board instance record
1734     *   until after the possibility of a forced traversal is evaluated.
1735     */
1736     ancestor = call_data->new_focus ;
1737     while(    ancestor  &&  !XtIsShell( ancestor)    )
1738     {
1739         if(    ancestor == (Widget) bb    )
1740         {   BBHasFocus = TRUE ;
1741             break ;
1742             }
1743         if(    XmIsBulletinBoard( ancestor)    )
1744         {
1745             if(    !dbutton    )
1746             {   dbutton = BB_DefaultButton( ancestor) ;
1747                 }
1748             if(    !cbutton    )
1749             {   cbutton = BB_CancelButton( ancestor) ;
1750                 }
1751             }
1752         ancestor = XtParent( ancestor) ;
1753         }
1754     ancestor = call_data->old_focus ;
1755     while(    ancestor  &&  !XtIsShell( ancestor)    )
1756     {
1757         if(    ancestor == (Widget) bb    )
1758         {   BBHadFocus = TRUE ;
1759             break ;
1760             }
1761         ancestor = XtParent( ancestor) ;
1762         }
1763 
1764     if(    BBHasFocus    )
1765     {
1766         /* The widget getting the input focus is a descendent of
1767         *   or is this Bulletin Board.
1768         * If there were no descendent Bulletin Boards with default or cancel
1769         *   buttons, use our own.
1770         */
1771         if(    !dbutton    ) dbutton = BB_DefaultButton( bb) ;
1772 
1773         if(    !cbutton    ) cbutton = BB_CancelButton( bb) ;
1774 
1775         if(    !dbutton    )
1776         {
1777 	    /* No descendant has active default button, so be sure
1778              *   that the dynamic_default_button field for this
1779              *   ancestor is NULL.
1780              */
1781             BB_DynamicDefaultButton( bb) = NULL ;
1782 	} else {
1783             if(XmeTraitGet((XtPointer)XtClass(call_data->new_focus),
1784 			   XmQTtakesDefault))
1785             {
1786                 /* Any defaultable which gets the focus
1787                 *   gets the default visuals and behavior.
1788                 */
1789                 _XmBulletinBoardSetDynDefaultButton( (Widget) bb,
1790                                                         call_data->new_focus) ;
1791                 }
1792             else /* call_data->new_focus is not a push button */
1793             {
1794                 if(    (call_data->focus_policy == XmEXPLICIT)
1795                     || !XmIsManager( call_data->new_focus)
1796                     || !call_data->old_focus
1797                     || (!XmeTraitGet((XtPointer)XtClass(call_data->old_focus),
1798 				     XmQTtakesDefault)))
1799                 {
1800                     /* Avoid setting the default button when in pointer mode,
1801                     *   leaving a button, and entering the background area.
1802                     *   The appropriate default button will be set when the
1803                     *   next focus moved event occurs.
1804                     *   This will avoid unnecessary flashing of default
1805                     *   button shadow when moving pointer between buttons.
1806                     */
1807                     if(    XtIsManaged( dbutton)    )
1808                     {
1809                         _XmBulletinBoardSetDynDefaultButton((Widget) bb,
1810 							    dbutton) ;
1811                         }
1812                     }
1813                 }
1814           }
1815         BB_DynamicCancelButton( bb) = cbutton ;
1816 
1817         if(    !BBHadFocus    )
1818         {
1819             cb.reason = XmCR_FOCUS ;
1820             cb.event = NULL ;
1821             XtCallCallbackList( (Widget) bb,
1822                                       bb->bulletin_board.focus_callback, &cb) ;
1823             }
1824         }
1825     else /* Bulletin Board does not have focus */
1826     {
1827         if(    BBHadFocus    )
1828         {
1829  	  if(    call_data->new_focus != NULL    )
1830  	    {
1831  	      _XmBulletinBoardSetDynDefaultButton( (Widget) bb, NULL) ;
1832  	    }
1833 	}
1834     }
1835     BB_InitialFocus( bb) = FALSE ;
1836 
1837     return ;
1838     }
1839 
1840 /****************************************************************/
1841 static Boolean
BulletinBoardParentProcess(Widget wid,XmParentProcessData event)1842 BulletinBoardParentProcess(
1843         Widget wid,
1844         XmParentProcessData event )
1845 {
1846             XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1847 /****************/
1848 
1849     if(    (event->any.process_type == XmINPUT_ACTION)
1850         && (   (    (event->input_action.action == XmPARENT_ACTIVATE)
1851                  && BB_DynamicDefaultButton( bb))
1852             || (    (event->input_action.action == XmPARENT_CANCEL)
1853                  && BB_DynamicCancelButton( bb)))    )
1854     {
1855         if(    event->input_action.action == XmPARENT_ACTIVATE    )
1856         {
1857             _XmBulletinBoardReturn( (Widget)bb, event->input_action.event,
1858                                       event->input_action.params,
1859                                          event->input_action.num_params) ;
1860             }
1861         else
1862         {   _XmBulletinBoardCancel( (Widget)bb, event->input_action.event,
1863                                       event->input_action.params,
1864                                          event->input_action.num_params) ;
1865             }
1866         return( TRUE) ;
1867         }
1868 
1869     return( _XmParentProcess( XtParent( bb), event)) ;
1870     }
1871 
1872 /****************************************************************
1873  * Process Return and Enter key events in the BulletinBoard.
1874  *   If there is a default button, call its Activate callbacks.
1875  ****************/
1876 void
_XmBulletinBoardReturn(Widget wid,XEvent * event,String * params,Cardinal * numParams)1877 _XmBulletinBoardReturn(Widget wid,
1878 		       XEvent *event,
1879 		       String *params,
1880 		       Cardinal *numParams )
1881 {
1882   XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1883   XmGadgetClass   gadget_class ;
1884   XmPrimitiveWidgetClass primitive_class ;
1885   Widget          dbutton = BB_DynamicDefaultButton( bb) ;
1886 
1887   if (!dbutton)
1888     {
1889       XmParentInputActionRec parentEvent ;
1890 
1891       parentEvent.process_type = XmINPUT_ACTION ;
1892       parentEvent.action = XmPARENT_ACTIVATE ;
1893       parentEvent.event = event ;
1894       parentEvent.params = params ;
1895       parentEvent.num_params = numParams ;
1896 
1897       _XmParentProcess( XtParent( bb), (XmParentProcessData) &parentEvent) ;
1898     }
1899   else if (XmIsGadget( dbutton) && XtIsManaged( dbutton))
1900     {
1901       gadget_class = (XmGadgetClass) XtClass( dbutton) ;
1902       if (gadget_class->gadget_class.arm_and_activate &&
1903 	  XtIsSensitive(dbutton))
1904 	{
1905 	  (*(gadget_class->gadget_class.arm_and_activate))
1906 	    (dbutton, event, params, numParams) ;
1907 	}
1908     }
1909   else if (XmIsPrimitive( dbutton) && XtIsManaged( dbutton))
1910     {
1911       primitive_class = (XmPrimitiveWidgetClass) XtClass( dbutton) ;
1912       if (primitive_class->primitive_class.arm_and_activate &&
1913 	  XtIsSensitive(dbutton))
1914 	{
1915 	  (*(primitive_class->primitive_class.arm_and_activate))
1916 	    (dbutton, event, params, numParams);
1917 	}
1918     }
1919   else
1920     {
1921       if (XtIsSensitive(dbutton))
1922 	{
1923 	  XmAnyCallbackStruct cb ;
1924 
1925 	  cb.reason = XmCR_ACTIVATE ;
1926 	  cb.event = event ;
1927 	  XtCallCallbacks(dbutton, XmNactivateCallback, (XtPointer) &cb) ;
1928 	}
1929     }
1930 }
1931 
1932 /****************************************************************
1933  * Process Cancel key events in the BulletinBoard.
1934  * If there is a cancel button, call its Activate callbacks.
1935  ****************/
1936 void
_XmBulletinBoardCancel(Widget wid,XEvent * event,String * params,Cardinal * numParams)1937 _XmBulletinBoardCancel(Widget wid,
1938 		       XEvent *event,
1939 		       String *params,
1940 		       Cardinal *numParams )
1941 {
1942   XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
1943   XmGadgetClass   gadget_class ;
1944   XmPrimitiveWidgetClass primitive_class ;
1945   Widget          cbutton = BB_DynamicCancelButton( bb) ;
1946 
1947   if (!cbutton)
1948     {
1949       XmParentInputActionRec parentEvent ;
1950 
1951       parentEvent.process_type = XmINPUT_ACTION ;
1952       parentEvent.action = XmPARENT_CANCEL ;
1953       parentEvent.event = event ;
1954       parentEvent.params = params ;
1955       parentEvent.num_params = numParams ;
1956 
1957       _XmParentProcess( XtParent( bb), (XmParentProcessData) &parentEvent) ;
1958     }
1959   else if (XmIsGadget(cbutton) && XtIsManaged(cbutton))
1960     {
1961       gadget_class = (XmGadgetClass) XtClass( cbutton) ;
1962       if (gadget_class->gadget_class.arm_and_activate &&
1963 	  XtIsSensitive( cbutton))
1964 	{
1965 	  (*(gadget_class->gadget_class.arm_and_activate))
1966 	    (cbutton, event, params, numParams) ;
1967 	}
1968     }
1969   else if (XmIsPrimitive( cbutton) && XtIsManaged( cbutton))
1970     {
1971       primitive_class = (XmPrimitiveWidgetClass) XtClass( cbutton) ;
1972       if (primitive_class->primitive_class.arm_and_activate &&
1973 	  XtIsSensitive(cbutton))
1974 	{
1975 	  (*(primitive_class->primitive_class.arm_and_activate))
1976 	    (cbutton, event, params, numParams) ;
1977 	}
1978     }
1979   else
1980     {
1981       if (XtIsSensitive(cbutton))
1982 	{
1983 	  XmAnyCallbackStruct cb ;
1984 
1985 	  cb.reason = XmCR_ACTIVATE ;
1986 	  cb.event = event ;
1987 	  XtCallCallbacks( cbutton, XmNactivateCallback, (XtPointer) &cb) ;
1988 	}
1989     }
1990 }
1991 
1992 /*ARGSUSED*/
1993 void
_XmBulletinBoardMap(Widget wid,XEvent * event,String * params,Cardinal * numParams)1994 _XmBulletinBoardMap(
1995          Widget wid,
1996          XEvent *event,		/* unused */
1997          String *params,	/* unused */
1998          Cardinal *numParams )	/* unused */
1999  {
2000    if(    BB_DefaultButton( wid)    )
2001      {
2002        Widget focus_hier = _XmGetFirstFocus( wid) ;
2003 
2004        while(    focus_hier
2005  	    &&  !XtIsShell( focus_hier)    )
2006  	{
2007  	  if(    focus_hier == wid    )
2008  	    {
2009  	      _XmBulletinBoardSetDynDefaultButton( wid,
2010  						      BB_DefaultButton( wid)) ;
2011  	      break ;
2012  	    }
2013  	  if(    XmIsBulletinBoard( focus_hier)
2014  	     &&  BB_DefaultButton( focus_hier)    )
2015  	    {
2016  	      break ;
2017  	    }
2018  	  focus_hier = XtParent( focus_hier) ;
2019  	}
2020      }
2021  }
2022 
2023 /****************************************************************/
2024 static void
BulletinBoardSetDefaultShadow(Widget button)2025 BulletinBoardSetDefaultShadow(
2026         Widget button )
2027 {
2028     XmTakesDefaultTrait trait_default ;
2029 
2030     trait_default = (XmTakesDefaultTrait) XmeTraitGet((XtPointer)
2031 						      XtClass(button),
2032 						      XmQTtakesDefault) ;
2033     if (trait_default)
2034 	trait_default->showAsDefault  (button, XmDEFAULT_READY);
2035 }
2036 
2037 
2038 /****************************************************************
2039  * If the default button of the bulletin board widget (wid) is not equal to
2040  *   the specified default button (newDefaultButton), then the trait is used
2041  *   to turn off/on the appropriate default borders and the default button
2042  *   field of the bulletin board instance record is updated appropriately.
2043   ****************/
2044 void
_XmBulletinBoardSetDynDefaultButton(Widget wid,Widget newDefaultButton)2045 _XmBulletinBoardSetDynDefaultButton(
2046         Widget wid,
2047         Widget newDefaultButton )
2048 {
2049     XmBulletinBoardWidget bbWid = (XmBulletinBoardWidget) wid ;
2050     XmTakesDefaultTrait trait_default ;
2051 
2052 
2053     if (newDefaultButton != BB_DynamicDefaultButton( bbWid)) {
2054         if (BB_DynamicDefaultButton(bbWid)) {
2055 	    trait_default = (XmTakesDefaultTrait)
2056 		XmeTraitGet((XtPointer)
2057 			    XtClass(BB_DynamicDefaultButton(bbWid)),
2058 			    XmQTtakesDefault) ;
2059 
2060 	    if (trait_default)
2061 		trait_default->showAsDefault ((Widget)
2062 					      BB_DynamicDefaultButton(bbWid),
2063 					      XmDEFAULT_OFF);
2064 	}
2065 
2066         BB_DynamicDefaultButton( bbWid) = newDefaultButton ;
2067 
2068         if (newDefaultButton) {
2069             trait_default = (XmTakesDefaultTrait)
2070 		XmeTraitGet((XtPointer)
2071 			    XtClass(BB_DynamicDefaultButton(bbWid)),
2072 			    XmQTtakesDefault) ;
2073 
2074 	    if (trait_default)
2075 		trait_default->showAsDefault ((Widget)
2076 					      BB_DynamicDefaultButton(bbWid),
2077 					      XmDEFAULT_ON);
2078 	}
2079     }
2080     return ;
2081 }
2082 
2083 
2084 
2085 static void
BBUpdateDynDefaultButton(Widget bb)2086 BBUpdateDynDefaultButton(
2087  	Widget bb)
2088 {
2089     Widget bbwdb = GetBBWithDB( bb) ;
2090 
2091     if(    bbwdb == NULL    ) {
2092 	if(    ((XmBulletinBoardWidget) bb)
2093 	   ->bulletin_board.dynamic_default_button    )
2094  	{
2095 	    _XmBulletinBoardSetDynDefaultButton( bb, NULL) ;
2096  	}
2097     }
2098     else {
2099 	if(    bbwdb == bb    ) {
2100 	    _XmBulletinBoardSetDynDefaultButton( bb, BB_DefaultButton( bb)) ;
2101  	}
2102     }
2103 }
2104 
2105 static Widget
GetBBWithDB(Widget wid)2106 GetBBWithDB(
2107  	Widget wid)
2108  {
2109    Widget focus ;
2110 
2111    if(    (_XmGetFocusPolicy( wid) == XmEXPLICIT)
2112       &&  (    (focus = XmGetFocusWidget( wid))
2113  	  ||  (focus = _XmGetFirstFocus( wid)))    )
2114      {
2115        while(    focus
2116  	    &&  !XtIsShell( focus)    )
2117  	{
2118  	  if(    XmIsBulletinBoard( focus)
2119  	     &&  BB_DefaultButton( focus)    )
2120  	    {
2121  	      return focus ;
2122  	    }
2123  	  focus = XtParent( focus) ;
2124  	}
2125 
2126      }
2127    return NULL ;
2128  }
2129 
2130 /*
2131  * XmRCallProc routine for checking font before setting it to NULL
2132  * if no value is specified for both XmNrenderTable and XmNfontList.
2133  * If the appropriate bit in "check_state" is True, this function has
2134  * been called twice on same widget for that resource, thus
2135  * the resource needs to be set NULL, otherwise leave it alone.
2136  */
2137 /* ARGSUSED */
2138 static void
CheckSetRenderTables(Widget wid,int offset,XrmValue * value)2139 CheckSetRenderTables(Widget wid,
2140 		     int offset,
2141 		     XrmValue *value )
2142 {
2143 
2144 #define SET_BFL(state) (state |= 0x01)
2145 #define IS_SET_BFL(state) (state & 0x01)
2146 #define SET_LFL(state) (state |= 0x02)
2147 #define IS_SET_LFL(state) (state & 0x02)
2148 #define SET_TFL(state) (state |= 0x04)
2149 #define IS_SET_TFL(state) (state & 0x04)
2150 
2151   XmBulletinBoardWidget bbw = (XmBulletinBoardWidget)wid;
2152 
2153   if (((char*)bbw + offset) ==
2154       (char*) &(bbw->bulletin_board.button_font_list)) {
2155 	if (IS_SET_BFL(bbw->bulletin_board.check_set))
2156 		value->addr = NULL;
2157 	else {
2158 		SET_BFL(bbw->bulletin_board.check_set);
2159 		value->addr = ((char *)bbw + offset);
2160 	}
2161   }
2162   else if (((char*)bbw + offset) ==
2163 	   (char*) &(bbw->bulletin_board.label_font_list)) {
2164 	if (IS_SET_LFL(bbw->bulletin_board.check_set))
2165 		value->addr = NULL;
2166 	else {
2167 		SET_LFL(bbw->bulletin_board.check_set);
2168 		value->addr = ((char *)bbw + offset);
2169 	}
2170   }
2171   else if (((char*)bbw + offset) ==
2172 	   (char*) &(bbw->bulletin_board.text_font_list)) {
2173 	if (IS_SET_TFL(bbw->bulletin_board.check_set))
2174 		value->addr = NULL;
2175 	else {
2176 		SET_TFL(bbw->bulletin_board.check_set);
2177 		value->addr = ((char *)bbw + offset);
2178 	}
2179   }
2180 }
2181 
2182 
2183 
2184 /****************************************************************
2185  *
2186  * Trait method for specify render table
2187  *
2188  **************************************************************/
2189 static XmFontList
GetTable(Widget wid,XtEnum type)2190 GetTable(
2191 	 Widget wid,
2192 	 XtEnum type)
2193 {
2194     XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
2195 
2196     switch(type) {
2197     case XmLABEL_RENDER_TABLE : return bb->bulletin_board.label_font_list ;
2198     case XmBUTTON_RENDER_TABLE : return bb->bulletin_board.button_font_list ;
2199     case XmTEXT_RENDER_TABLE : return bb->bulletin_board.text_font_list ;
2200     }
2201 
2202     return NULL ;
2203 }
2204 
2205 
2206 
2207 
2208 /****************************************************************
2209  *
2210  * Trait method for dialog shell savvy
2211  *
2212  **************************************************************/
2213 static void
CallMapUnmap(Widget wid,Boolean map_unmap)2214 CallMapUnmap(
2215 	 Widget wid,
2216 	 Boolean map_unmap)
2217 {
2218     XmBulletinBoardWidget bb = (XmBulletinBoardWidget) wid ;
2219     XmAnyCallbackStruct call_data;
2220 
2221     call_data.reason = (map_unmap)? XmCR_MAP : XmCR_UNMAP;
2222     call_data.event  = NULL;
2223 
2224     if (map_unmap) {
2225 	XtCallCallbackList (wid, bb->bulletin_board.map_callback,
2226 			    &call_data);
2227     } else {
2228 	XtCallCallbackList (wid, bb->bulletin_board.unmap_callback,
2229 			    &call_data);
2230     }
2231 }
2232 
2233 
2234 
2235 /****************************************************************
2236  * This function creates and returns a BulletinBoard widget.
2237  ****************/
2238 Widget
XmCreateBulletinBoard(Widget p,String name,ArgList args,Cardinal n)2239 XmCreateBulletinBoard(
2240         Widget p,
2241         String name,
2242         ArgList args,
2243         Cardinal n )
2244 {
2245 
2246     return( XtCreateWidget( name, xmBulletinBoardWidgetClass, p, args, n)) ;
2247 }
2248 
2249 
2250 
2251 
2252 /****************************************************************
2253  * This convenience function creates a DialogShell and a BulletinBoard
2254  *   child of the shell; returns the BulletinBoard widget.
2255  ****************/
2256 Widget
XmCreateBulletinBoardDialog(Widget ds_p,String name,ArgList bb_args,Cardinal bb_n)2257 XmCreateBulletinBoardDialog(
2258         Widget ds_p,
2259         String name,
2260         ArgList bb_args,
2261         Cardinal bb_n )
2262 {
2263     return XmeCreateClassDialog (xmBulletinBoardWidgetClass,
2264 				 ds_p, name, bb_args, bb_n) ;
2265 }
2266 
2267 Widget
XmVaCreateBulletinBoard(Widget parent,char * name,...)2268 XmVaCreateBulletinBoard(
2269         Widget parent,
2270         char *name,
2271         ...)
2272 {
2273     register Widget w;
2274     va_list var;
2275     int count;
2276 
2277     Va_start(var,name);
2278     count = XmeCountVaListSimple(var);
2279     va_end(var);
2280 
2281 
2282     Va_start(var, name);
2283     w = XmeVLCreateWidget(name,
2284                          xmBulletinBoardWidgetClass,
2285                          parent, False,
2286                          var, count);
2287     va_end(var);
2288     return w;
2289 }
2290 
2291 Widget
XmVaCreateManagedBulletinBoard(Widget parent,char * name,...)2292 XmVaCreateManagedBulletinBoard(
2293         Widget parent,
2294         char *name,
2295         ...)
2296 {
2297     Widget w = NULL;
2298     va_list var;
2299     int count;
2300 
2301     Va_start(var, name);
2302     count = XmeCountVaListSimple(var);
2303     va_end(var);
2304 
2305     Va_start(var, name);
2306     w = XmeVLCreateWidget(name,
2307                          xmBulletinBoardWidgetClass,
2308                          parent, True,
2309                          var, count);
2310     va_end(var);
2311     return w;
2312 }
2313