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 HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 
28 #ifdef REV_INFO
29 #ifndef lint
30 static char rcsid[] = "$TOG: SelectioB.c /main/19 1997/06/18 17:42:11 samborn $"
31 #endif
32 #endif
33 
34 /*-------------------------------------------------------------------------
35 **
36 **	include files
37 **
38 **-------------------------------------------------------------------------
39 */
40 
41 #ifndef X_NOT_STDC_ENV
42 #include <stdlib.h>
43 #endif
44 
45 #include <Xm/AccTextT.h>
46 #include <Xm/ActivatableT.h>
47 #include <Xm/ArrowB.h>
48 #include <Xm/DialogS.h>
49 #include <Xm/GadgetP.h>
50 #include <Xm/LabelG.h>
51 #include <Xm/List.h>
52 #include <Xm/PushBG.h>
53 #include <Xm/RowColumnP.h>
54 #include <Xm/SeparatoG.h>
55 #include <Xm/TextF.h>
56 #include <Xm/TraitP.h>
57 #include <Xm/TransltnsP.h>
58 #include <Xm/VaSimpleP.h>
59 #include "BulletinBI.h"
60 #include "GeoUtilsI.h"
61 #include "GMUtilsI.h"
62 #include "ManagerI.h"
63 #include "MessagesI.h"
64 #include "RepTypeI.h"
65 #include "SelectioBI.h"
66 #include "TransferI.h"
67 #include "XmI.h"
68 #include "XmStringI.h"
69 
70 #define WARN_DIALOG_TYPE_CHANGE _XmMMsgSelectioB_0001
71 #define WARN_CHILD_TYPE		_XmMMsgSelectioB_0002
72 #define MESSAGE0     		_XmMMsgMotif_0001
73 
74 #define defaultTextAccelerators		_XmSelectioB_defaultTextAccelerators
75 
76 #define IsButton(w) \
77 (((XtPointer) XmeTraitGet((XtPointer) XtClass((w)), XmQTactivatable) != NULL))
78 
79 #define IsAutoButton(sb, w) ( \
80       w == SB_OkButton(sb)     || \
81       w == SB_ApplyButton(sb)  || \
82       w == SB_CancelButton(sb) || \
83       w == SB_HelpButton(sb))
84 
85 #define SetupWorkArea(sb) \
86     if (_XmGeoSetupKid (boxPtr, SB_WorkArea(sb)))     \
87     {                                                 \
88       layoutPtr->space_above = vspace;                \
89       vspace = BB_MarginHeight(sb);                   \
90       boxPtr += 2 ;                                 \
91       ++layoutPtr ;                                 \
92     }
93 
94 
95 
96 /********    Static Function Declarations    ********/
97 
98 static void ClassInitialize( void ) ;
99 static void ClassPartInitialize(
100                         WidgetClass w_class) ;
101 static void Initialize(
102                         Widget rw,
103                         Widget nw,
104                         ArgList args,
105                         Cardinal *num_args) ;
106 static void InsertChild(
107                         Widget child) ;
108 static void DeleteChild(
109                         Widget child) ;
110 static void _XmDialogTypeDefault(
111                         Widget widget,
112                         int offset,
113                         XrmValue *value) ;
114 static XmImportOperator _XmSetSyntheticResForChild(
115                         Widget widget,
116                         int offset,
117                         XtArgVal *value) ;
118 static void SelectionBoxCallback(
119                         Widget w,
120                         XtPointer client_data,
121                         XtPointer call_data) ;
122 static void ListCallback(
123                         Widget w,
124                         XtPointer client_data,
125                         XtPointer call_data) ;
126 static void UpdateString(
127                         Widget w,
128                         XmString string,
129 #if NeedWidePrototypes
130                         int direction) ;
131 #else
132                         XmStringDirection direction) ;
133 #endif /* NeedWidePrototypes */
134 static Boolean SetValues(
135                         Widget cw,
136                         Widget rw,
137                         Widget nw,
138                         ArgList args,
139                         Cardinal *num_args) ;
140 
141 /********    End Static Function Declarations    ********/
142 
143 
144 static XtAccelerators defaultTextAcceleratorsParsed;
145 
146 /*  Action list  */
147 
148 static XtActionsRec actionsList[] =
149 {
150     { "UpOrDown",               _XmSelectionBoxUpOrDown }, /* Motif 1.0 */
151     { "SelectionBoxUpOrDown",   _XmSelectionBoxUpOrDown },
152     { "SelectionBoxRestore",    _XmSelectionBoxRestore },
153     };
154 
155 
156 /*  Resource definitions for SelectionBox
157 */
158 
159 static XmSyntheticResource syn_resources[] =
160 {
161 	{	XmNselectionLabelString,
162 		sizeof (XmString),
163 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.selection_label_string),
164 		_XmSelectionBoxGetSelectionLabelString,
165 		_XmSetSyntheticResForChild
166 	},
167 
168 	{	XmNlistLabelString,
169 		sizeof (XmString),
170 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_label_string),
171 		_XmSelectionBoxGetListLabelString,
172 		_XmSetSyntheticResForChild
173 	},
174 
175 	{	XmNtextColumns,
176 		sizeof(short),
177 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.text_columns),
178 		_XmSelectionBoxGetTextColumns,
179 		NULL
180 	},
181 
182 	{	XmNtextString,
183 		sizeof (XmString),
184 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.text_string),
185 		_XmSelectionBoxGetTextString,
186 		_XmSetSyntheticResForChild
187 	},
188 
189 	{	XmNlistItems,
190 		sizeof (XmStringTable),
191 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_items),
192 		_XmSelectionBoxGetListItems,
193 		_XmSetSyntheticResForChild
194 	},
195 
196 	{	XmNlistItemCount,
197 		sizeof(int),
198 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_item_count),
199 		_XmSelectionBoxGetListItemCount,
200 		_XmSetSyntheticResForChild
201 	},
202 
203 	{	XmNlistVisibleItemCount,
204 		sizeof(int),
205 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_visible_item_count),
206 		_XmSelectionBoxGetListVisibleItemCount,
207 		_XmSetSyntheticResForChild
208 	},
209 
210 	{	XmNokLabelString,
211 		sizeof (XmString),
212 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.ok_label_string),
213 		_XmSelectionBoxGetOkLabelString,
214 		NULL
215 	},
216 
217 	{	XmNapplyLabelString,
218 		sizeof (XmString),
219 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.apply_label_string),
220 		_XmSelectionBoxGetApplyLabelString,
221 		NULL
222 	},
223 
224 	{	XmNcancelLabelString,
225 		sizeof (XmString),
226 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.cancel_label_string),
227 		_XmSelectionBoxGetCancelLabelString,
228 		NULL
229 	},
230 
231 	{	XmNhelpLabelString,
232 		sizeof (XmString),
233 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.help_label_string),
234 		_XmSelectionBoxGetHelpLabelString,
235 		NULL
236 	},
237 };
238 
239 
240 
241 static XtResource resources[] =
242 {
243 	{	XmNtextAccelerators,
244 		XmCAccelerators, XmRAcceleratorTable, sizeof (XtAccelerators),
245 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.text_accelerators),
246 		XmRImmediate, NULL
247 	},
248 
249 	{	XmNselectionLabelString,
250 		XmCSelectionLabelString, XmRXmString, sizeof (XmString),
251 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.selection_label_string),
252 		XmRString, NULL
253 	},
254 
255 	{	XmNlistLabelString,
256 		XmCListLabelString, XmRXmString, sizeof (XmString),
257 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_label_string),
258 		XmRString, NULL
259 	},
260 
261 	{	XmNtextColumns,
262 		XmCColumns, XmRShort, sizeof(short),
263 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.text_columns),
264 		XmRImmediate, (XtPointer) 20
265 	},
266 
267 	{	XmNtextString,
268 		XmCTextString, XmRXmString, sizeof (XmString),
269 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.text_string),
270 		XmRImmediate, (XtPointer) XmUNSPECIFIED
271 	},
272 
273 	{	XmNlistItems,
274 		XmCItems, XmRXmStringTable, sizeof (XmStringTable),
275 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_items),
276 		XmRImmediate, NULL
277 	},
278 
279 	{	XmNlistItemCount,
280 		XmCItemCount, XmRInt, sizeof(int),
281 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_item_count),
282 		XmRImmediate, (XtPointer) XmUNSPECIFIED_COUNT
283 	},
284 
285 	{	XmNlistVisibleItemCount,
286 		XmCVisibleItemCount, XmRInt, sizeof(int),
287 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.list_visible_item_count),
288 		XmRImmediate, (XtPointer) 8
289 	},
290 
291 	{	XmNokLabelString,
292 		XmCOkLabelString, XmRXmString, sizeof (XmString),
293 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.ok_label_string),
294 		XmRString, NULL
295 	},
296 
297 	{	XmNapplyLabelString,
298 		XmCApplyLabelString, XmRXmString, sizeof (XmString),
299 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.apply_label_string),
300 		XmRString, NULL
301 	},
302 
303 	{	XmNcancelLabelString,
304 		XmCCancelLabelString, XmRXmString, sizeof (XmString),
305 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.cancel_label_string),
306 		XmRString, NULL
307 	},
308 
309 	{	XmNhelpLabelString,
310 		XmCHelpLabelString, XmRXmString, sizeof (XmString),
311 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.help_label_string),
312 		XmRString, NULL
313 	},
314 
315 	{	XmNnoMatchCallback,
316 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
317 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.no_match_callback),
318 		XmRImmediate, (XtPointer) NULL
319 	},
320 
321 	{	XmNmustMatch,
322 		XmCMustMatch, XmRBoolean, sizeof(Boolean),
323 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.must_match),
324 		XmRImmediate, (XtPointer) False
325 	},
326 
327 	{	XmNminimizeButtons,
328 		XmCMinimizeButtons, XmRBoolean, sizeof(Boolean),
329 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.minimize_buttons),
330 		XmRImmediate, (XtPointer) False
331 	},
332 
333 	{	XmNokCallback,
334 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
335 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.ok_callback),
336 		XmRImmediate, (XtPointer) NULL
337 	},
338 
339 	{	XmNapplyCallback,
340 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
341 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.apply_callback),
342 		XmRImmediate, (XtPointer) NULL
343 	},
344 
345 	{	XmNcancelCallback,
346 		XmCCallback, XmRCallback, sizeof (XtCallbackList),
347 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.cancel_callback),
348 		XmRImmediate, (XtPointer) NULL
349 	},
350 
351 	{	XmNdialogType,
352 		XmCDialogType, XmRSelectionType, sizeof (unsigned char),
353 		XtOffsetOf( struct _XmSelectionBoxRec, selection_box.dialog_type),
354 		XmRCallProc, (XtPointer) _XmDialogTypeDefault
355         },
356 
357         {       XmNchildPlacement,
358                 XmCChildPlacement, XmRChildPlacement, sizeof (unsigned char),
359                 XtOffsetOf( struct _XmSelectionBoxRec, selection_box.child_placement),
360                 XmRImmediate, (XtPointer) XmPLACE_ABOVE_SELECTION
361 	},
362 };
363 
364 
365 
366 externaldef( xmselectionboxclassrec) XmSelectionBoxClassRec
367                                                        xmSelectionBoxClassRec =
368 {
369     {
370     	/* superclass	      */	(WidgetClass) &xmBulletinBoardClassRec,
371     	/* class_name	      */	"XmSelectionBox",
372     	/* widget_size	      */	sizeof(XmSelectionBoxRec),
373     	/* class_initialize   */    	ClassInitialize,
374     	/* chained class init */	ClassPartInitialize,
375     	/* class_inited       */	FALSE,
376     	/* initialize	      */	Initialize,
377     	/* initialize hook    */	NULL,
378     	/* realize	      */	XtInheritRealize,
379     	/* actions	      */	actionsList,
380     	/* num_actions	      */	XtNumber(actionsList),
381     	/* resources	      */	resources,
382     	/* num_resources      */	XtNumber(resources),
383     	/* xrm_class	      */	NULLQUARK,
384     	/* compress_motion    */	TRUE,
385     	/* compress_exposure  */	XtExposeCompressMaximal,
386     	/* compress enter/exit*/	TRUE,
387     	/* visible_interest   */	FALSE,
388     	/* destroy	      */	NULL,
389     	/* resize	      */	XtInheritResize,
390     	/* expose	      */	XtInheritExpose,
391     	/* set_values	      */	SetValues,
392 	/* set_values_hook    */	NULL,
393 	/* set_values_almost  */	XtInheritSetValuesAlmost,
394 	/* get_values_hook    */	NULL,
395     	/* accept_focus	      */	NULL,
396 	/* version	      */	XtVersion,
397         /* callback_offsets   */        NULL,
398         /* tm_table           */        XtInheritTranslations,
399     	/* query_geometry     */	XtInheritGeometryManager,
400     	/* display_accelerator*/	NULL,
401 	/* extension	      */	NULL,
402     },
403 
404     {	/* composite class record */
405 
406 	/* childrens geo mgr proc   */  XtInheritGeometryManager,
407 	/* set changed proc	    */  XtInheritChangeManaged,
408 	/* insert_child		    */	InsertChild,
409 	/* delete_child 	    */	DeleteChild,
410 	/* extension		    */	NULL,
411     },
412 
413     {	/* constraint class record */
414 
415 	/* no additional resources  */	NULL,
416 	/* num additional resources */	0,
417 	/* size of constraint rec   */	0,
418 	/* constraint_initialize    */	NULL,
419 	/* constraint_destroy	    */	NULL,
420 	/* constraint_setvalue	    */	NULL,
421 	/* extension		    */	NULL,
422     },
423 
424     {	/* manager class record */
425       XmInheritTranslations, 		        /* default translations   */
426       syn_resources, 				/* syn_resources      	  */
427       XtNumber (syn_resources), 		/* num_syn_resources 	  */
428       NULL, 					/* syn_cont_resources     */
429       0, 					/* num_syn_cont_resources */
430       XmInheritParentProcess,                   /* parent_process         */
431       NULL, 					/* extension		  */
432     },
433 
434     {	/* bulletin board class record */
435         TRUE,                                   /*always_install_accelerators*/
436         _XmSelectionBoxGeoMatrixCreate,         /* geo_matrix_create */
437         XmInheritFocusMovedProc,                /* focus_moved_proc */
438 	NULL, 					/* extension */
439     },
440 
441     {	/* selection box class record */
442         ListCallback,                           /* list_callback */
443 	NULL, 					/* extension  */
444     },
445 };
446 
447 externaldef( xmselectionboxwidgetclass) WidgetClass xmSelectionBoxWidgetClass
448                                       = (WidgetClass) &xmSelectionBoxClassRec ;
449 
450 
451 /****************************************************************/
452 static void
ClassInitialize(void)453 ClassInitialize( void )
454 {
455 /****************/
456 
457     /* parse the default translation and accelerator tables
458     */
459     defaultTextAcceleratorsParsed =
460                             XtParseAcceleratorTable( defaultTextAccelerators) ;
461     return ;
462     }
463 /****************************************************************/
464 static void
ClassPartInitialize(WidgetClass w_class)465 ClassPartInitialize(
466         WidgetClass w_class )
467 {
468 /****************/
469     XmSelectionBoxWidgetClass wc = (XmSelectionBoxWidgetClass) w_class;
470     XmSelectionBoxWidgetClass super =
471         (XmSelectionBoxWidgetClass) wc->core_class.superclass;
472 
473     if (wc->selection_box_class.list_callback == XmInheritCallbackProc)
474         wc->selection_box_class.list_callback =
475             super->selection_box_class.list_callback;
476 
477     _XmFastSubclassInit(w_class, XmSELECTION_BOX_BIT) ;
478 
479     return ;
480 }
481 
482 
483 /****************************************************************
484  * Create a SelectionBox instance.
485  ****************/
486 /*ARGSUSED*/
487 static void
Initialize(Widget rw,Widget nw,ArgList args,Cardinal * num_args)488 Initialize(
489         Widget rw,		/* unused */
490         Widget nw,
491         ArgList args,		/* unused */
492         Cardinal *num_args )	/* unused */
493 {
494     XmSelectionBoxWidget new_w = (XmSelectionBoxWidget) nw ;
495 /****************/
496 
497     new_w->selection_box.work_area = NULL;
498 
499     if ( new_w->selection_box.text_accelerators == NULL ) {
500 	new_w->selection_box.text_accelerators =
501 	    defaultTextAcceleratorsParsed;
502     }
503 
504     /*	Validate dialog type.
505      */
506     if(    !XmRepTypeValidValue( XmRID_SELECTION_TYPE,
507 				new_w->selection_box.dialog_type,
508 				(Widget) new_w)    )
509         {
510             new_w->selection_box.dialog_type =
511 		XmIsDialogShell( XtParent( new_w))
512 		    ? XmDIALOG_SELECTION : XmDIALOG_WORK_AREA ;
513 	}
514     /*      Validate child placement.
515      */
516     if(    !XmRepTypeValidValue( XmRID_CHILD_PLACEMENT,
517 				new_w->selection_box.child_placement,
518 				(Widget) new_w)    )
519         {
520 	    new_w->selection_box.child_placement = XmPLACE_ABOVE_SELECTION;
521 	}
522 
523     /*	Create child widgets.
524 	Here we have now to take care of XmUNSPECIFIED (CR 4856).
525 	*/
526     new_w->selection_box.adding_sel_widgets = True;
527 
528     if ( (new_w->selection_box.dialog_type != XmDIALOG_PROMPT)
529 	&& (new_w->selection_box.dialog_type != XmDIALOG_COMMAND) )
530 	{
531             if (new_w->selection_box.list_label_string ==
532 		(XmString) XmUNSPECIFIED) {
533 		new_w->selection_box.list_label_string = NULL ;
534 		_XmSelectionBoxCreateListLabel( new_w) ;
535 		new_w->selection_box.list_label_string =
536 		    (XmString) XmUNSPECIFIED ;
537 	    } else
538 		_XmSelectionBoxCreateListLabel( new_w) ;
539 
540 	}
541     else
542         {   SB_ListLabel (new_w) = NULL;
543 	}
544 
545     if (new_w->selection_box.list_label_string !=
546 	(XmString) XmUNSPECIFIED)
547 	new_w->selection_box.list_label_string = NULL ;
548 
549 
550     if (new_w->selection_box.dialog_type != XmDIALOG_PROMPT)
551 	{
552             _XmSelectionBoxCreateList( new_w) ;
553 	}
554     else
555         {   SB_List (new_w) = NULL;
556 	}
557     new_w->selection_box.list_items = NULL ;
558     new_w->selection_box.list_item_count = XmUNSPECIFIED_COUNT ;
559 
560 
561     if (new_w->selection_box.selection_label_string ==
562 	(XmString) XmUNSPECIFIED) {
563 	new_w->selection_box.selection_label_string = NULL ;
564 	_XmSelectionBoxCreateSelectionLabel(new_w);
565 	new_w->selection_box.selection_label_string =
566 	    (XmString) XmUNSPECIFIED ;
567     } else {
568 	_XmSelectionBoxCreateSelectionLabel(new_w);
569 	new_w->selection_box.selection_label_string = NULL ;
570     }
571 
572 
573     _XmSelectionBoxCreateText(new_w);
574 
575     /* Do not reset text_string to XmUNSPECIFIED until after calls
576      *   to CreateList and CreateText.
577      */
578     new_w->selection_box.text_string = (XmString) XmUNSPECIFIED ;
579 
580     if(    new_w->manager.initial_focus == NULL    )
581         {
582             new_w->manager.initial_focus = SB_Text( new_w) ;
583 	}
584 
585     if (new_w->selection_box.dialog_type != XmDIALOG_COMMAND)
586 	{
587 	    _XmSelectionBoxCreateSeparator (new_w);
588 	    _XmSelectionBoxCreateOkButton (new_w);
589 	    if (new_w->selection_box.apply_label_string ==
590 		(XmString) XmUNSPECIFIED) {
591 		new_w->selection_box.apply_label_string = NULL ;
592 		_XmSelectionBoxCreateApplyButton (new_w);
593 		new_w->selection_box.apply_label_string =
594 		    (XmString) XmUNSPECIFIED ;
595 	    } else
596 		_XmSelectionBoxCreateApplyButton (new_w);
597 	    _XmSelectionBoxCreateCancelButton (new_w);
598 	    _XmSelectionBoxCreateHelpButton (new_w);
599 
600 	    BB_DefaultButton( new_w) = SB_OkButton( new_w) ;
601 	    _XmBulletinBoardSetDynDefaultButton( (Widget) new_w,
602 						BB_DefaultButton( new_w)) ;
603 	}
604     else
605 	{
606 	    SB_Separator (new_w) = NULL;
607 	    SB_OkButton (new_w) = NULL;
608 	    SB_ApplyButton (new_w) = NULL;
609 	    SB_CancelButton (new_w) = NULL;
610 	    SB_HelpButton (new_w) = NULL;
611 	}
612     new_w->selection_box.ok_label_string = NULL ;
613     if (new_w->selection_box.apply_label_string !=
614 	(XmString) XmUNSPECIFIED)
615 	new_w->selection_box.apply_label_string = NULL ;
616     new_w->selection_box.cancel_label_string = NULL ;
617     new_w->selection_box.help_label_string = NULL ;
618 
619     new_w->selection_box.adding_sel_widgets = False;
620 
621 
622     XtManageChildren (new_w->composite.children,
623 		      new_w->composite.num_children) ;
624 
625     if (new_w->selection_box.dialog_type == XmDIALOG_PROMPT ||
626 	new_w->selection_box.dialog_type == XmDIALOG_WORK_AREA)
627 	{
628 	    XtUnmanageChild (SB_ApplyButton (new_w));
629 	}
630 
631 }
632 
633 /****************************************************************
634  * Selection widget supports ONE child.  This routine
635  *   handles adding a child to selection widget
636  ****************/
637 static void
InsertChild(Widget child)638 InsertChild(
639         Widget child )
640 {
641             XmSelectionBoxWidget sb ;
642 /****************/
643     XtWidgetProc insert_child;
644 
645     /* Use the dialog class insert proc to do all the dirty work
646     */
647     _XmProcessLock();
648     insert_child = ((XmBulletinBoardWidgetClass) xmBulletinBoardWidgetClass)
649 					  ->composite_class.insert_child;
650     _XmProcessUnlock();
651 
652     (*insert_child)(child) ;
653 
654     if(    !XtIsRectObj( child)    )
655     {   return ;
656         }
657     sb = (XmSelectionBoxWidget) XtParent( child) ;
658 
659     /* check if this child is to be the selection widget's work area widget
660     */
661     if(    !sb->selection_box.adding_sel_widgets
662         && !XtIsShell( child)    )
663     {
664         if(    !sb->selection_box.work_area    )
665         {   sb->selection_box.work_area = child ;
666             }
667         }
668     return ;
669     }
670 
671 /****************************************************************
672  * Remove child from selection widget
673  ****************/
674 static void
DeleteChild(Widget child)675 DeleteChild(
676         Widget child )
677 {
678             XmSelectionBoxWidget sel ;
679 	    XtWidgetProc delete_child;
680 /****************/
681 
682     if(    XtIsRectObj( child)    )
683     {
684         sel = (XmSelectionBoxWidget) XtParent( child) ;
685         /*	Clear widget fields (BulletinBoard does default and cancel).
686         */
687         if(    child == SB_ListLabel (sel)    )
688         {   SB_ListLabel( sel) = NULL ;
689             }
690         else
691         {   if(    SB_List( sel)  &&  (child == XtParent( SB_List (sel)))    )
692             {   SB_List( sel) = NULL ;
693                 }
694             else
695             {   if(    child == SB_SelectionLabel (sel)    )
696                 {   SB_SelectionLabel( sel) = NULL ;
697                     }
698                 else
699                 {   if(    child == SB_Text (sel)    )
700                     {   SB_Text( sel) = NULL ;
701                         }
702                     else
703                     {   if(    child == SB_WorkArea (sel)    )
704                         {   SB_WorkArea( sel) = NULL ;
705                             }
706                         else
707                         {   if(    child == SB_Separator (sel)    )
708                             {   SB_Separator( sel) = NULL ;
709                                 }
710                             else
711                             {   if(    child == SB_OkButton (sel)    )
712                                 {   SB_OkButton( sel) = NULL ;
713                                     }
714                                 else
715                                 {   if(    child == SB_ApplyButton (sel)    )
716                                     {   SB_ApplyButton( sel) = NULL ;
717                                         }
718                                     else
719                                     {   if(    child == SB_HelpButton (sel)   )
720                                         {   SB_HelpButton( sel) = NULL ;
721                                             }
722                                         }
723                                     }
724                                 }
725                             }
726                         }
727                     }
728                 }
729             }
730         }
731     _XmProcessLock();
732     delete_child = ((XmBulletinBoardWidgetClass) xmBulletinBoardWidgetClass)
733 					  ->composite_class.delete_child;
734     _XmProcessUnlock();
735     (*delete_child)( child) ;
736     return ;
737     }
738 
739 /****************************************************************
740  * Set the default type (selection or workarea) based on parent.
741  ****************/
742 /*ARGSUSED*/
743 static void
_XmDialogTypeDefault(Widget widget,int offset,XrmValue * value)744 _XmDialogTypeDefault(
745         Widget widget,
746         int offset,		/* unused */
747         XrmValue *value )
748 {
749     static unsigned char	type;
750 /****************/
751 
752     /*
753      * Set the default type.  To do this, we check the dialog
754      * box's parent.  If it is a DialogShell widget, then this
755      * is a "pop-up" dialog box, and the default type is selection.
756      * Else the default type is workarea.
757      */
758     type = XmDIALOG_WORK_AREA;
759     if (XmIsDialogShell (XtParent (widget)))
760 	type = XmDIALOG_SELECTION;
761     value->addr = (XPointer)(&type);
762     return ;
763 }
764 
765 /*ARGSUSED*/
766 static XmImportOperator
_XmSetSyntheticResForChild(Widget widget,int offset,XtArgVal * value)767 _XmSetSyntheticResForChild(
768         Widget widget,		/* unused */
769         int offset,		/* unused */
770         XtArgVal *value)	/* unused */
771 {
772     return XmSYNTHETIC_LOAD;
773     }
774 
775 /****************************************************************
776  * Create the Label displayed above the List widget.
777  ****************/
778 void
_XmSelectionBoxCreateListLabel(XmSelectionBoxWidget sel)779 _XmSelectionBoxCreateListLabel(
780         XmSelectionBoxWidget sel )
781 {
782 /****************/
783 
784     SB_ListLabel( sel) = _XmBB_CreateLabelG( (Widget) sel,
785                                sel->selection_box.list_label_string, "Items",
786 			       XmItemsStringLoc) ;
787     return ;
788     }
789 /****************************************************************
790  * Create the Label displayed above the Text widget.
791  ****************/
792 void
_XmSelectionBoxCreateSelectionLabel(XmSelectionBoxWidget sel)793 _XmSelectionBoxCreateSelectionLabel(
794         XmSelectionBoxWidget sel )
795 {
796 /****************/
797 
798 
799 
800   if (sel->selection_box.dialog_type == XmDIALOG_COMMAND)
801       SB_SelectionLabel(sel) = _XmBB_CreateLabelG((Widget)sel,
802 				     sel->selection_box.selection_label_string,
803 				     "Selection",
804 				     XmPromptStringLoc);
805   else
806       SB_SelectionLabel( sel) = _XmBB_CreateLabelG( (Widget) sel,
807 		                      sel->selection_box.selection_label_string,
808 				      "Selection",
809 				      XmSelectionStringLoc) ;
810 }
811 
812 
813 /****************************************************************
814  * Create the List widget.
815  ****************/
816 void
_XmSelectionBoxCreateList(XmSelectionBoxWidget sel)817 _XmSelectionBoxCreateList(
818         XmSelectionBoxWidget sel )
819 {
820             Arg		al[20] ;
821     register int	ac = 0 ;
822             int *       position ;
823             int         pos_count ;
824             XtCallbackProc callbackProc ;
825 /****************/
826 
827     if(    sel->selection_box.list_items    )
828     {
829         XtSetArg( al[ac], XmNitems, sel->selection_box.list_items) ; ac++ ;
830         }
831     if(    sel->selection_box.list_item_count != XmUNSPECIFIED    )
832     {
833         XtSetArg( al[ac], XmNitemCount,
834                                   sel->selection_box.list_item_count) ;  ac++ ;
835         }
836     XtSetArg( al[ac], XmNvisibleItemCount,
837 		sel->selection_box.list_visible_item_count) ;  ac++ ;
838 
839     sel->selection_box.list_selected_item_position = 0 ;
840 
841     XtSetArg( al[ac], XmNstringDirection, SB_StringDirection (sel)) ;  ac++ ;
842     XtSetArg( al[ac], XmNselectionPolicy, XmBROWSE_SELECT) ;  ac++ ;
843     XtSetArg( al[ac], XmNlistSizePolicy, XmCONSTANT) ;  ac++ ;
844     XtSetArg( al[ac], XmNnavigationType, XmSTICKY_TAB_GROUP) ; ++ac ;
845 
846     SB_List( sel) = XmCreateScrolledList( (Widget) sel, "ItemsList", al, ac) ;
847 
848     if(    sel->selection_box.text_string != (XmString) XmUNSPECIFIED    )
849     {
850         if(    sel->selection_box.text_string
851             && XmListGetMatchPos( SB_List( sel),
852                     sel->selection_box.text_string, &position, &pos_count)    )
853         {   if(    pos_count    )
854             {
855                 sel->selection_box.list_selected_item_position = position[0] ;
856                 XmListSelectPos( SB_List( sel), position[0], FALSE) ;
857                 }
858             XtFree( (char *) position) ;
859             }
860         }
861     callbackProc = ((XmSelectionBoxWidgetClass) sel->core.widget_class)
862                                           ->selection_box_class.list_callback ;
863     if(    callbackProc    )
864     {
865         XtAddCallback( SB_List( sel), XmNsingleSelectionCallback,
866                                                callbackProc, (XtPointer) sel) ;
867         XtAddCallback( SB_List( sel), XmNbrowseSelectionCallback,
868                                                callbackProc, (XtPointer) sel) ;
869         XtAddCallback( SB_List( sel), XmNdefaultActionCallback,
870                                                callbackProc, (XtPointer) sel) ;
871         }
872     XtManageChild( SB_List( sel)) ;
873 
874     return ;
875     }
876 
877 /****************************************************************
878  * Create the Text widget.
879  ****************/
880 void
_XmSelectionBoxCreateText(XmSelectionBoxWidget sel)881 _XmSelectionBoxCreateText(
882         XmSelectionBoxWidget sel )
883 {
884 	Arg		al[10];
885 	register int	ac = 0;
886 	String		text_value ;
887 	XtAccelerators	temp_accelerators ;
888 /****************/
889 
890 	XtSetArg (al[ac], XmNcolumns, sel->selection_box.text_columns);  ac++;
891 	XtSetArg (al[ac], XmNresizeWidth, False);  ac++;
892 	XtSetArg (al[ac], XmNeditMode, XmSINGLE_LINE_EDIT);  ac++;
893         XtSetArg( al[ac], XmNnavigationType, XmSTICKY_TAB_GROUP) ; ++ac ;
894 
895 	SB_Text( sel) = XmCreateTextField( (Widget) sel, "Text", al, ac);
896 	if(    (sel->selection_box.text_string != (XmString) XmUNSPECIFIED)    )
897         {
898             text_value = _XmStringGetTextConcat(
899                                               sel->selection_box.text_string) ;
900             XmTextFieldSetString( SB_Text (sel), text_value) ;
901             if(    text_value    )
902             {   XmTextFieldSetInsertionPosition( SB_Text( sel),
903 			          XmTextFieldGetLastPosition( SB_Text( sel))) ;
904                 }
905             XtFree( (char *) text_value) ;
906             }
907 
908 	/*	Install text accelerators.
909 	*/
910         temp_accelerators = sel->core.accelerators;
911 	sel->core.accelerators = sel->selection_box.text_accelerators;
912 	XtInstallAccelerators( SB_Text( sel), (Widget) sel) ;
913 	sel->core.accelerators = temp_accelerators;
914         return ;
915 }
916 
917 /****************************************************************
918  * Create the Separator displayed above the buttons.
919  ****************/
920 void
_XmSelectionBoxCreateSeparator(XmSelectionBoxWidget sel)921 _XmSelectionBoxCreateSeparator(
922         XmSelectionBoxWidget sel )
923 {
924 	Arg		al[10];
925 	register int	ac = 0;
926 /****************/
927 
928 	XtSetArg (al[ac], XmNhighlightThickness, 0);  ac++;
929 	SB_Separator (sel) =
930 		XmCreateSeparatorGadget( (Widget) sel, "Separator", al, ac);
931         return ;
932 }
933 /****************************************************************
934  * Create the "OK" PushButton.
935  ****************/
936 void
_XmSelectionBoxCreateOkButton(XmSelectionBoxWidget sel)937 _XmSelectionBoxCreateOkButton(
938         XmSelectionBoxWidget sel )
939 {
940 /****************/
941 
942     SB_OkButton( sel) = _XmBB_CreateButtonG( (Widget) sel,
943                                     sel->selection_box.ok_label_string, "OK",
944 				    XmOkStringLoc) ;
945     XtAddCallback (SB_OkButton (sel), XmNactivateCallback,
946                         SelectionBoxCallback, (XtPointer) XmDIALOG_OK_BUTTON) ;
947     return ;
948     }
949 
950 /****************************************************************
951  * Create the "Apply" PushButton.
952  ****************/
953 void
_XmSelectionBoxCreateApplyButton(XmSelectionBoxWidget sel)954 _XmSelectionBoxCreateApplyButton(
955         XmSelectionBoxWidget sel )
956 {
957 /****************/
958 
959     SB_ApplyButton( sel) = _XmBB_CreateButtonG( (Widget) sel,
960                               sel->selection_box.apply_label_string, "Apply",
961                               XmApplyStringLoc) ;
962     /* Remove BulletinBoard Unmanage callback from apply and help buttons.
963     */
964     XtRemoveAllCallbacks( SB_ApplyButton( sel), XmNactivateCallback) ;
965     XtAddCallback (SB_ApplyButton (sel), XmNactivateCallback,
966                      SelectionBoxCallback, (XtPointer) XmDIALOG_APPLY_BUTTON) ;
967     return ;
968     }
969 /****************************************************************
970  * Create the "Cancel" PushButton.
971  ****************/
972 void
_XmSelectionBoxCreateCancelButton(XmSelectionBoxWidget sel)973 _XmSelectionBoxCreateCancelButton(
974         XmSelectionBoxWidget sel )
975 {
976 /****************/
977 
978     SB_CancelButton( sel) = _XmBB_CreateButtonG( (Widget) sel,
979                             sel->selection_box.cancel_label_string, "Cancel",
980                             XmCancelStringLoc) ;
981     XtAddCallback( SB_CancelButton( sel), XmNactivateCallback,
982                     SelectionBoxCallback, (XtPointer) XmDIALOG_CANCEL_BUTTON) ;
983     return ;
984     }
985 /****************************************************************
986  * Create the "Help" PushButton.
987  ****************/
988 void
_XmSelectionBoxCreateHelpButton(XmSelectionBoxWidget sel)989 _XmSelectionBoxCreateHelpButton(
990         XmSelectionBoxWidget sel )
991 {
992 /****************/
993 
994     SB_HelpButton( sel) = _XmBB_CreateButtonG( (Widget) sel,
995                                 sel->selection_box.help_label_string, "Help",
996                                 XmHelpStringLoc) ;
997     /* Remove BulletinBoard Unmanage callback from apply and help buttons.
998     */
999     XtRemoveAllCallbacks( SB_HelpButton( sel), XmNactivateCallback) ;
1000     XtAddCallback (SB_HelpButton (sel), XmNactivateCallback,
1001                       SelectionBoxCallback, (XtPointer) XmDIALOG_HELP_BUTTON) ;
1002     return ;
1003     }
1004 
1005 /****************************************************************/
1006 
1007 XmGeoMatrix
_XmSelectionBoxGeoMatrixCreate(Widget wid,Widget instigator,XtWidgetGeometry * desired)1008 _XmSelectionBoxGeoMatrixCreate(
1009         Widget wid,
1010         Widget instigator,
1011         XtWidgetGeometry *desired )
1012 {
1013     XmSelectionBoxWidget sb = (XmSelectionBoxWidget) wid ;
1014     XmGeoMatrix     geoSpec ;
1015     register XmGeoRowLayout  layoutPtr ;
1016     register XmKidGeometry   boxPtr ;
1017     XmKidGeometry   firstButtonBox ;
1018     XmListWidget    list ;
1019     Boolean         listLabelBox ;
1020     Boolean         selLabelBox ;
1021     Dimension       vspace = BB_MarginHeight(sb);
1022     int             i;
1023 
1024 /*
1025  * Layout SelectionBox XmGeoMatrix.
1026  * Each row is terminated by leaving an empty XmKidGeometry and
1027  * moving to the next XmGeoRowLayout.
1028  */
1029 
1030     geoSpec = _XmGeoMatrixAlloc( XmSB_MAX_WIDGETS_VERT,
1031                               sb->composite.num_children, 0) ;
1032     geoSpec->composite = (Widget) sb ;
1033     geoSpec->instigator = (Widget) instigator ;
1034     if(    desired    )
1035     {   geoSpec->instig_request = *desired ;
1036         }
1037     geoSpec->margin_w = BB_MarginWidth( sb) + sb->manager.shadow_thickness ;
1038     geoSpec->margin_h = BB_MarginHeight( sb) + sb->manager.shadow_thickness ;
1039     geoSpec->no_geo_request = _XmSelectionBoxNoGeoRequest ;
1040 
1041     layoutPtr = &(geoSpec->layouts->row) ;
1042     boxPtr = geoSpec->boxes ;
1043 
1044     /* menu bar */
1045 
1046     for (i = 0; i < sb->composite.num_children; i++)
1047     {	Widget w = sb->composite.children[i];
1048 
1049         if(    XmIsRowColumn(w)
1050             && ((XmRowColumnWidget)w)->row_column.type == XmMENU_BAR
1051             && w != SB_WorkArea(sb)
1052             && _XmGeoSetupKid( boxPtr, w)    )
1053 	{   layoutPtr->fix_up = _XmMenuBarFix ;
1054             boxPtr += 2;
1055             ++layoutPtr;
1056             vspace = 0;		/* fixup space_above of next row. */
1057             break;
1058             }
1059         }
1060 
1061     /* work area, XmPLACE_TOP */
1062 
1063     if (sb->selection_box.child_placement == XmPLACE_TOP)
1064       SetupWorkArea(sb);
1065 
1066     /* list box label */
1067 
1068     listLabelBox = FALSE ;
1069     if(    _XmGeoSetupKid( boxPtr, SB_ListLabel( sb))    )
1070     {
1071         listLabelBox = TRUE ;
1072         layoutPtr->space_above = vspace;
1073         vspace = BB_MarginHeight(sb);
1074         boxPtr += 2 ;
1075         ++layoutPtr ;
1076         }
1077 
1078     /* list box */
1079 
1080     list = (XmListWidget) SB_List( sb) ;
1081     if(    list  &&  XtIsManaged((Widget)list)
1082         && _XmGeoSetupKid( boxPtr, XtParent( list))    )
1083     {
1084         if(    !listLabelBox    )
1085         {   layoutPtr->space_above = vspace;
1086             vspace = BB_MarginHeight(sb);
1087             }
1088         layoutPtr->stretch_height = TRUE ;
1089         layoutPtr->min_height = 70 ;
1090         boxPtr += 2 ;
1091         ++layoutPtr ;
1092         }
1093 
1094     /* work area, XmPLACE_ABOVE_SELECTION */
1095 
1096     if (sb->selection_box.child_placement == XmPLACE_ABOVE_SELECTION)
1097       SetupWorkArea(sb)
1098 
1099     /* selection label */
1100 
1101     selLabelBox = FALSE ;
1102     if(    _XmGeoSetupKid( boxPtr, SB_SelectionLabel( sb))    )
1103     {   selLabelBox = TRUE ;
1104         layoutPtr->space_above = vspace;
1105         vspace = BB_MarginHeight(sb);
1106         boxPtr += 2 ;
1107         ++layoutPtr ;
1108         }
1109 
1110     /* selection text */
1111 
1112     if(    _XmGeoSetupKid( boxPtr, SB_Text( sb))    )
1113     {
1114         if(    !selLabelBox    )
1115         {   layoutPtr->space_above = vspace;
1116             vspace = BB_MarginHeight(sb);
1117             }
1118         boxPtr += 2 ;
1119         ++layoutPtr ;
1120         }
1121 
1122     /* work area, XmPLACE_BELOW_SELECTION */
1123 
1124     if (sb->selection_box.child_placement == XmPLACE_BELOW_SELECTION)
1125       SetupWorkArea(sb)
1126 
1127     /* separator */
1128 
1129     if(    _XmGeoSetupKid( boxPtr, SB_Separator( sb))    )
1130     {   layoutPtr->fix_up = _XmSeparatorFix ;
1131         layoutPtr->space_above = vspace;
1132         vspace = BB_MarginHeight(sb);
1133         boxPtr += 2 ;
1134         ++layoutPtr ;
1135         }
1136 
1137     /* button row */
1138 
1139     firstButtonBox = boxPtr ;
1140 
1141     if (LayoutIsRtoLM(sb))
1142     {
1143        if(    _XmGeoSetupKid( boxPtr, SB_HelpButton( sb))    )
1144        {   ++boxPtr ;
1145            }
1146        if(    _XmGeoSetupKid( boxPtr, SB_CancelButton( sb))    )
1147        {   ++boxPtr ;
1148            }
1149        if(    _XmGeoSetupKid( boxPtr, SB_ApplyButton( sb))    )
1150        {   ++boxPtr ;
1151            }
1152 
1153        for (i = 0; i < sb->composite.num_children; i++)
1154        {
1155 	    Widget w = sb->composite.children[sb->composite.num_children-i-1];
1156 	    if (IsButton(w) && !IsAutoButton(sb,w) && w != SB_WorkArea(sb))
1157 	    {
1158 		if (_XmGeoSetupKid( boxPtr, w))
1159 		{   ++boxPtr ;
1160 		}
1161 	    }
1162        }
1163 
1164        if(    _XmGeoSetupKid( boxPtr, SB_OkButton( sb))    )
1165        {   ++boxPtr ;
1166            }
1167     }
1168     else
1169     {
1170       if(    _XmGeoSetupKid( boxPtr, SB_OkButton( sb))    )
1171 	{   ++boxPtr ;
1172 	  }
1173       for (i = 0; i < sb->composite.num_children; i++)
1174 	{
1175 	  Widget w = sb->composite.children[i];
1176 	  if (IsButton(w) && !IsAutoButton(sb,w) && w != SB_WorkArea(sb))
1177 	    {
1178 	      if (_XmGeoSetupKid( boxPtr, w))
1179 		{   ++boxPtr ;
1180 		  }
1181 	    }
1182 	}
1183       if(    _XmGeoSetupKid( boxPtr, SB_ApplyButton( sb))    )
1184 	{   ++boxPtr ;
1185 	  }
1186       if(    _XmGeoSetupKid( boxPtr, SB_CancelButton( sb))    )
1187 	{   ++boxPtr ;
1188 	  }
1189       if(    _XmGeoSetupKid( boxPtr, SB_HelpButton( sb))    )
1190 	{   ++boxPtr ;
1191 	  }
1192     }
1193 
1194     if(    boxPtr != firstButtonBox    )
1195     {   layoutPtr->fill_mode = XmGEO_CENTER ;
1196         layoutPtr->fit_mode = XmGEO_WRAP ;
1197         layoutPtr->space_above = vspace;
1198         vspace = BB_MarginHeight(sb);
1199         if(    !(sb->selection_box.minimize_buttons)    )
1200         {   layoutPtr->even_width = 1 ;
1201             }
1202         layoutPtr->even_height = 1 ;
1203 	++layoutPtr ;
1204         }
1205 
1206     /* the end. */
1207 
1208     layoutPtr->space_above = vspace;
1209     layoutPtr->end = TRUE ;
1210     return( geoSpec) ;
1211     }
1212 
1213 /****************************************************************/
1214 Boolean
_XmSelectionBoxNoGeoRequest(XmGeoMatrix geoSpec)1215 _XmSelectionBoxNoGeoRequest(
1216         XmGeoMatrix geoSpec )
1217 {
1218 /****************/
1219 
1220     if(    BB_InSetValues( geoSpec->composite)
1221         && (XtClass( geoSpec->composite) == xmSelectionBoxWidgetClass)    )
1222     {
1223         return( TRUE) ;
1224         }
1225     return( FALSE) ;
1226     }
1227 
1228 /****************************************************************
1229  * Call the callbacks for a SelectionBox button.
1230  ****************/
1231 static void
SelectionBoxCallback(Widget w,XtPointer client_data,XtPointer call_data)1232 SelectionBoxCallback(
1233         Widget w,
1234         XtPointer client_data,
1235         XtPointer call_data )
1236 {
1237 	unsigned char		which_button = (unsigned char)(long) client_data;
1238 	XmSelectionBoxWidget	sel = (XmSelectionBoxWidget) XtParent (w);
1239 	XmAnyCallbackStruct	*callback = (XmAnyCallbackStruct *) call_data;
1240 	XmSelectionBoxCallbackStruct	temp;
1241 	Boolean			match = True;
1242 	String			text_value;
1243 /****************/
1244 
1245 	text_value = XmTextFieldGetString (SB_Text (sel));
1246 	temp.event = callback->event;
1247 	temp.value = XmStringGenerate(text_value, XmFONTLIST_DEFAULT_TAG,
1248 				      XmCHARSET_TEXT, NULL);
1249 	temp.length = XmStringLength (temp.value);
1250 	XtFree (text_value);
1251 
1252 	switch (which_button)
1253 	{
1254 		case XmDIALOG_OK_BUTTON:
1255                         if (sel->selection_box.list != NULL)
1256 			   if (sel->selection_box.must_match)
1257 			   {
1258 				match = XmListItemExists (SB_List (sel), temp.value);
1259 			   }
1260 			if (!match)
1261 			{
1262 				temp.reason = XmCR_NO_MATCH;
1263 				XtCallCallbackList ((Widget) sel, sel->
1264 					selection_box.no_match_callback, &temp);
1265 			}
1266 			else
1267 			{
1268 				temp.reason = XmCR_OK;
1269 				XtCallCallbackList ((Widget) sel, sel->
1270 					selection_box.ok_callback, &temp);
1271 			}
1272 			break;
1273 
1274 		case XmDIALOG_APPLY_BUTTON:
1275 			temp.reason = XmCR_APPLY;
1276 			XtCallCallbackList ((Widget) sel, sel->selection_box.apply_callback, &temp);
1277 			break;
1278 
1279 		case XmDIALOG_CANCEL_BUTTON:
1280 			temp.reason = XmCR_CANCEL;
1281 			XtCallCallbackList ((Widget) sel, sel->selection_box.cancel_callback, &temp);
1282 			break;
1283 
1284 		case XmDIALOG_HELP_BUTTON:
1285 			/* Invoke the help system. */
1286                         _XmManagerHelp((Widget)sel, callback->event, NULL, NULL) ;
1287 			break;
1288 	}
1289         XmStringFree( temp.value) ;
1290         return ;
1291 }
1292 
1293 /****************************************************************
1294  * Process callback from the List in a SelectionBox.
1295  ****************/
1296 static void
ListCallback(Widget w,XtPointer client_data,XtPointer call_data)1297 ListCallback(
1298         Widget w,
1299         XtPointer client_data,
1300         XtPointer call_data )
1301 {
1302 	enum { XmA_MOTIF_SELECTION_TEXT, XmA_MOTIF_COMPOUND_STRING,
1303 	       XmACOMPOUND_TEXT, NUM_ATOMS };
1304 	static char *atom_names[] = {
1305 	  XmI_MOTIF_SELECTION_TEXT, XmS_MOTIF_COMPOUND_STRING,
1306 	  XmSCOMPOUND_TEXT };
1307 
1308 	XmListCallbackStruct	*callback = (XmListCallbackStruct *) call_data;
1309 	XmSelectionBoxWidget	sel = (XmSelectionBoxWidget) client_data ;
1310 	XmGadgetClass		gadget_class;
1311         XmGadget                dbutton = (XmGadget)
1312                                                 BB_DynamicDefaultButton( sel) ;
1313 	XmAccessTextualTrait	textTrait;
1314 	Atom		atoms[XtNumber(atom_names)];
1315 	Atom		PRIMARY = XA_PRIMARY;
1316 	XtPointer	value;
1317 	Atom		type;
1318 	unsigned long	size;
1319 	int		format;
1320 	Boolean		success;
1321 
1322 
1323 	textTrait = (XmAccessTextualTrait)
1324 	  XmeTraitGet((XtPointer) XtClass(SB_Text(sel)), XmQTaccessTextual);
1325 	if (textTrait == NULL) return; /* Abort if text child is broken */
1326 
1327 	assert(XtNumber(atom_names) == NUM_ATOMS);
1328 	XInternAtoms(XtDisplay(w), atom_names, XtNumber(atom_names),
1329 		     False, atoms);
1330 
1331 	/*	Update the text widget to relect the latest list selection.
1332 	 *	If list default action (double click), activate default button.
1333 	 */
1334 	sel->selection_box.list_selected_item_position =
1335                                                        callback->item_position;
1336 
1337 	success = False;
1338 	/*
1339 	 * Obtain item.
1340 	 *
1341 	 * We do this via the selection mechanism by calling
1342 	 * _XmConvertHandler directly.  First we call with
1343 	 * the target _MOTIF_SELECTION_TEXT,  then we fallback
1344 	 * to using _MOTIF_COMPOUND_STRING if no reply is obtained
1345 	 */
1346 	_XmConvertHandlerSetLocal();
1347 	success = _XmConvertHandler(w, &PRIMARY,
1348 				    &atoms[XmA_MOTIF_SELECTION_TEXT],
1349 				    &type, &value, &size, &format);
1350 	if (! success) {
1351 	  _XmConvertHandlerSetLocal();
1352 	  success = _XmConvertHandler(w, &PRIMARY,
1353 				      &atoms[XmA_MOTIF_COMPOUND_STRING],
1354 				      &type, &value, &size, &format);
1355 	}
1356 	if (success) {
1357 	  if (type == atoms[XmA_MOTIF_COMPOUND_STRING]) {
1358 	    XmString temp;
1359 	    temp = XmCvtByteStreamToXmString((unsigned char *) value);
1360 
1361 	    textTrait -> setValue(SB_Text(sel), temp, XmFORMAT_XmSTRING);
1362 	    XmStringFree(temp);
1363 	  } else if (type == atoms[XmACOMPOUND_TEXT]) {
1364 	    XmString temp;
1365 	    temp = XmCvtCTToXmString((char*) value);
1366 	    textTrait -> setValue(SB_Text(sel), value, XmFORMAT_XmSTRING);
1367 	    XmStringFree(temp);
1368 	  } else if (type == XA_STRING) {
1369 	    textTrait -> setValue(SB_Text(sel), value, XmFORMAT_MBYTE);
1370 	  }
1371 	}
1372 
1373 	if(success)
1374 	{
1375 	  XmTextFieldSetInsertionPosition(SB_Text (sel),
1376 				       XmTextFieldGetLastPosition( SB_Text( sel))) ;
1377 	  XtFree((char*) value);
1378 	}
1379         /* Catch only double-click default action here.
1380         *  Key press events are handled through the ParentProcess routine.
1381         */
1382 	if(    (callback->reason == XmCR_DEFAULT_ACTION)
1383             && (callback->event->type != KeyPress)
1384             && dbutton  &&  XtIsManaged((Widget)dbutton)
1385             && XtIsSensitive((Widget)dbutton)  &&  XmIsGadget( dbutton)    )
1386 	 {
1387             gadget_class = (XmGadgetClass) dbutton->object.widget_class ;
1388             if (gadget_class->gadget_class.arm_and_activate)
1389 		{
1390 		/* pass the event so that the button can pass it on to its
1391 		** callbacks, even though the event isn't within the button
1392 		*/
1393 		(*(gadget_class->gadget_class.arm_and_activate))
1394 			  ((Widget) dbutton, callback->event, NULL, NULL) ;
1395 		}
1396 	 }
1397         return ;
1398         }
1399 
1400 
1401 /****************************************************************
1402  * Set the label string of a label or button
1403  ****************/
1404 static void
UpdateString(Widget w,XmString string,int direction)1405 UpdateString(
1406         Widget w,
1407         XmString string,
1408 #if NeedWidePrototypes
1409         int direction )
1410 #else
1411         XmStringDirection direction )
1412 #endif /* NeedWidePrototypes */
1413 {
1414 	Arg		al[3];
1415     	register int	ac = 0;
1416 /****************/
1417 
1418 	if (w)
1419 	{
1420 		XtSetArg (al[ac], XmNstringDirection, direction);  ac++;
1421 		XtSetArg (al[ac], XmNlabelString, string);  ac++;
1422 		XtSetValues (w, al, ac);
1423 	}
1424         return ;
1425 }
1426 
1427 /****************************************************************
1428  * Update widget when values change.
1429  ****************/
1430 /*ARGSUSED*/
1431 static Boolean
SetValues(Widget cw,Widget rw,Widget nw,ArgList args,Cardinal * num_args)1432 SetValues(
1433         Widget cw,
1434         Widget rw,
1435         Widget nw,
1436         ArgList args,		/* unused */
1437         Cardinal *num_args )	/* unused */
1438 {
1439             XmSelectionBoxWidget current = (XmSelectionBoxWidget) cw ;
1440             XmSelectionBoxWidget request = (XmSelectionBoxWidget) rw ;
1441             XmSelectionBoxWidget new_w = (XmSelectionBoxWidget) nw ;
1442 	Arg		al[10];
1443 	register int	ac;
1444 
1445 	String		text_value ;
1446 /****************/
1447 
1448 	BB_InSetValues (new_w) = True;
1449 
1450 
1451       /*      Validate child placement.
1452       */
1453       if(    (new_w->selection_box.child_placement
1454                       != current->selection_box.child_placement)
1455               && !XmRepTypeValidValue( XmRID_CHILD_PLACEMENT,
1456                       new_w->selection_box.child_placement, (Widget) new_w)    )
1457       {
1458           new_w->selection_box.child_placement =
1459                       current->selection_box.child_placement;
1460           }
1461 
1462 	/*	Update label strings.
1463 	*/
1464 	if(    new_w->selection_box.selection_label_string
1465                           != current->selection_box.selection_label_string    )
1466 	{   UpdateString( SB_SelectionLabel (new_w),
1467                                      new_w->selection_box.selection_label_string,
1468                                                     SB_StringDirection (new_w)) ;
1469             new_w->selection_box.selection_label_string = NULL ;
1470             }
1471 
1472 	if(    new_w->selection_box.list_label_string
1473                                != current->selection_box.list_label_string    )
1474 	{   UpdateString( SB_ListLabel (new_w),
1475                                           new_w->selection_box.list_label_string,
1476                                                     SB_StringDirection (new_w)) ;
1477             new_w->selection_box.list_label_string = NULL ;
1478             }
1479 
1480 	if(    new_w->selection_box.ok_label_string
1481                                  != current->selection_box.ok_label_string    )
1482 	{   UpdateString( SB_OkButton (new_w),
1483                                             new_w->selection_box.ok_label_string,
1484                                                     SB_StringDirection (new_w)) ;
1485             new_w->selection_box.ok_label_string = NULL ;
1486             }
1487 
1488 	if(    new_w->selection_box.apply_label_string
1489                               != current->selection_box.apply_label_string    )
1490 	{   UpdateString( SB_ApplyButton (new_w),
1491                                          new_w->selection_box.apply_label_string,
1492                                                     SB_StringDirection (new_w)) ;
1493             new_w->selection_box.apply_label_string = NULL ;
1494             }
1495 
1496 	if(    new_w->selection_box.cancel_label_string
1497                              != current->selection_box.cancel_label_string    )
1498 	{   UpdateString( SB_CancelButton (new_w),
1499                                         new_w->selection_box.cancel_label_string,
1500                                                     SB_StringDirection (new_w)) ;
1501             new_w->selection_box.cancel_label_string = NULL ;
1502             }
1503 
1504 	if(    new_w->selection_box.help_label_string
1505                                != current->selection_box.help_label_string    )
1506 	{   UpdateString( SB_HelpButton (new_w),
1507                                           new_w->selection_box.help_label_string,
1508                                                     SB_StringDirection (new_w)) ;
1509             new_w->selection_box.help_label_string = NULL ;
1510             }
1511 
1512 	/*	Update List widget.
1513 	*/
1514 	ac = 0;
1515 	if(    new_w->selection_box.list_items    ) {
1516 	  XtSetArg( al[ac], XmNitems,
1517 		   new_w->selection_box.list_items) ;  ac++ ;
1518 	}
1519 	if(    new_w->selection_box.list_item_count != XmUNSPECIFIED_COUNT ) {
1520 	  XtSetArg( al[ac], XmNitemCount,
1521 		   new_w->selection_box.list_item_count) ;  ac++ ;
1522 	  new_w->selection_box.list_item_count = XmUNSPECIFIED_COUNT ;
1523 	}
1524 	if (new_w->selection_box.list_visible_item_count !=
1525 	    current->selection_box.list_visible_item_count) {
1526 	  XtSetArg (al[ac], XmNvisibleItemCount,
1527 		    new_w->selection_box.list_visible_item_count);  ac++;
1528 	}
1529 	if (ac)	{
1530 	  if (SB_List (new_w))
1531 	    XtSetValues (SB_List (new_w), al, ac);
1532 	  new_w->selection_box.list_items = NULL ;
1533 	}
1534 
1535 	/*	Update Text widget.
1536 	*/
1537         text_value = NULL ;
1538 	ac = 0;
1539 	if(    new_w->selection_box.text_string
1540                                      != current->selection_box.text_string    )
1541 	{
1542             text_value = _XmStringGetTextConcat(
1543                                               new_w->selection_box.text_string) ;
1544             XtSetArg( al[ac], XmNvalue, text_value) ;  ac++ ;
1545             new_w->selection_box.text_string = (XmString) XmUNSPECIFIED ;
1546             }
1547 	if (new_w->selection_box.text_columns !=
1548 		current->selection_box.text_columns)
1549 	{
1550 		XtSetArg (al[ac], XmNcolumns,
1551 			new_w->selection_box.text_columns);  ac++;
1552 	}
1553 	if (ac)
1554 	{
1555 		if (SB_Text (new_w))
1556 			XtSetValues (SB_Text (new_w), al, ac);
1557 	}
1558 	if (text_value)
1559 	{
1560 		if (SB_Text (new_w))
1561 			XmTextFieldSetInsertionPosition (SB_Text (new_w),
1562 			          XmTextFieldGetLastPosition( SB_Text( new_w))) ;
1563 		XtFree (text_value);
1564 	}
1565 
1566 	/*	Validate dialog type.
1567 	*/
1568 	if (request->selection_box.dialog_type !=
1569 			 current->selection_box.dialog_type)
1570 	{
1571 		XmeWarning( (Widget) new_w, WARN_DIALOG_TYPE_CHANGE);
1572 		new_w->selection_box.dialog_type =
1573 			current->selection_box.dialog_type;
1574 	}
1575 	BB_InSetValues (new_w) = False;
1576 
1577 	/*	If this is the instantiated class then do layout.
1578 	*/
1579 	if(    XtClass( new_w) == xmSelectionBoxWidgetClass    )
1580 	{
1581             _XmBulletinBoardSizeUpdate( (Widget) new_w) ;
1582 	    }
1583 	return (Boolean) (FALSE);
1584         }
1585 
1586 /****************************************************************/
1587 /*ARGSUSED*/
1588 void
_XmSelectionBoxGetSelectionLabelString(Widget wid,int resource_offset,XtArgVal * value)1589 _XmSelectionBoxGetSelectionLabelString(
1590         Widget wid,
1591         int resource_offset,	/* unused */
1592         XtArgVal *value )
1593 {
1594             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1595             XmString        data ;
1596             Arg             al[1] ;
1597 /****************/
1598 
1599     if(    SB_SelectionLabel (sel)    )
1600     {
1601         XtSetArg( al[0], XmNlabelString, &data) ;
1602         XtGetValues( SB_SelectionLabel( sel), al, 1) ;
1603         *value = (XtArgVal) data ;
1604         }
1605     else
1606     {   *value = (XtArgVal) NULL ;
1607         }
1608     return ;
1609     }
1610 /****************************************************************/
1611 /*ARGSUSED*/
1612 void
_XmSelectionBoxGetListLabelString(Widget wid,int resource_offset,XtArgVal * value)1613 _XmSelectionBoxGetListLabelString(
1614         Widget wid,
1615         int resource_offset,	/* unused */
1616         XtArgVal *value )
1617 {
1618             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1619             XmString        data ;
1620             Arg             al[1] ;
1621 /****************/
1622 
1623     if(    SB_ListLabel( sel)    )
1624     {
1625         XtSetArg( al[0], XmNlabelString, &data) ;
1626         XtGetValues( SB_ListLabel( sel), al, 1) ;
1627         *value = (XtArgVal) data ;
1628         }
1629     else
1630     {   *value = (XtArgVal) NULL ;
1631         }
1632     return ;
1633     }
1634 /****************************************************************/
1635 /*ARGSUSED*/
1636 void
_XmSelectionBoxGetTextColumns(Widget wid,int resource_offset,XtArgVal * value)1637 _XmSelectionBoxGetTextColumns(
1638         Widget wid,
1639         int resource_offset,	/* unused */
1640         XtArgVal *value )
1641 {
1642             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1643             short           data ;
1644             Arg             al[1] ;
1645 /****************/
1646 
1647     if(    SB_Text( sel)    )
1648     {
1649         XtSetArg( al[0], XmNcolumns, &data) ;
1650         XtGetValues( SB_Text( sel), al, 1) ;
1651         *value = (XtArgVal) data ;
1652         }
1653     else
1654     {   *value = (XtArgVal) 0 ;
1655         }
1656     return ;
1657     }
1658 /****************************************************************/
1659 /*ARGSUSED*/
1660 void
_XmSelectionBoxGetTextString(Widget wid,int resource_offset,XtArgVal * value)1661 _XmSelectionBoxGetTextString(
1662         Widget wid,
1663         int resource_offset,	/* unused */
1664         XtArgVal *value )
1665 {
1666             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1667             String          data = NULL ;
1668             XmString        text_string ;
1669             Arg             al[1] ;
1670 /****************/
1671 
1672     if(    SB_Text( sel)    )
1673     {
1674         XtSetArg( al[0], XmNvalue, &data) ;
1675         XtGetValues( SB_Text( sel), al, 1) ;
1676         text_string = XmStringGenerate(data, XmFONTLIST_DEFAULT_TAG,
1677 				       XmCHARSET_TEXT, NULL) ;
1678         *value = (XtArgVal) text_string ;
1679 	XtFree((char *)data);
1680         }
1681     else
1682     {   *value = (XtArgVal) NULL ;
1683         }
1684     return ;
1685     }
1686 /****************************************************************/
1687 /*ARGSUSED*/
1688 void
_XmSelectionBoxGetListItems(Widget wid,int resource_offset,XtArgVal * value)1689 _XmSelectionBoxGetListItems(
1690         Widget wid,
1691         int resource_offset,	/* unused */
1692         XtArgVal *value )
1693 {
1694             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1695             Arg             al[1] ;
1696             XmString        data ;
1697 /****************/
1698 
1699     if(    SB_List( sel)    )
1700     {
1701         XtSetArg( al[0], XmNitems, &data) ;
1702         XtGetValues( SB_List( sel), al, 1) ;
1703         *value = (XtArgVal) data ;
1704         }
1705     else
1706     {   *value = (XtArgVal) NULL ;
1707         }
1708     return ;
1709     }
1710 /****************************************************************/
1711 /*ARGSUSED*/
1712 void
_XmSelectionBoxGetListItemCount(Widget wid,int resource_offset,XtArgVal * value)1713 _XmSelectionBoxGetListItemCount(
1714         Widget wid,
1715         int resource_offset,	/* unused */
1716         XtArgVal *value )
1717 {
1718             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1719             int             data ;
1720             Arg             al[1] ;
1721 /****************/
1722 
1723     if(    SB_List( sel)    )
1724     {
1725         XtSetArg( al[0], XmNitemCount, &data) ;
1726         XtGetValues( SB_List( sel), al, 1) ;
1727         *value = (XtArgVal) data ;
1728         }
1729     else
1730     {   *value = (XtArgVal) 0 ;
1731         }
1732     return ;
1733     }
1734 /****************************************************************/
1735 /*ARGSUSED*/
1736 void
_XmSelectionBoxGetListVisibleItemCount(Widget wid,int resource_offset,XtArgVal * value)1737 _XmSelectionBoxGetListVisibleItemCount(
1738         Widget wid,
1739         int resource_offset,	/* unused */
1740         XtArgVal *value )
1741 {
1742             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1743             int             data ;
1744             Arg             al[1] ;
1745 /****************/
1746 
1747     if(    SB_List( sel)    )
1748     {
1749         XtSetArg( al[0], XmNvisibleItemCount, &data) ;
1750         XtGetValues( SB_List( sel), al, 1) ;
1751         *value = (XtArgVal) data ;
1752         }
1753     else
1754     {   *value = (XtArgVal) 0 ;
1755         }
1756     return ;
1757     }
1758 /****************************************************************/
1759 /*ARGSUSED*/
1760 void
_XmSelectionBoxGetOkLabelString(Widget wid,int resource_offset,XtArgVal * value)1761 _XmSelectionBoxGetOkLabelString(
1762         Widget wid,
1763         int resource_offset,	/* unused */
1764         XtArgVal *value )
1765 {
1766             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1767             XmString        data ;
1768             Arg             al[1] ;
1769 /****************/
1770 
1771     if(    SB_OkButton( sel)    )
1772     {
1773         XtSetArg( al[0], XmNlabelString, &data) ;
1774         XtGetValues( SB_OkButton( sel), al, 1) ;
1775         *value = (XtArgVal) data ;
1776         }
1777     else
1778     {   *value = (XtArgVal) NULL ;
1779         }
1780     return ;
1781     }
1782 /****************************************************************/
1783 /*ARGSUSED*/
1784 void
_XmSelectionBoxGetApplyLabelString(Widget wid,int resource_offset,XtArgVal * value)1785 _XmSelectionBoxGetApplyLabelString(
1786         Widget wid,
1787         int resource_offset,	/* unused */
1788         XtArgVal *value )
1789 {
1790             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1791             XmString        data ;
1792             Arg             al[1] ;
1793 /****************/
1794 
1795     if(    SB_ApplyButton( sel)    )
1796     {
1797         XtSetArg( al[0], XmNlabelString, &data) ;
1798         XtGetValues( SB_ApplyButton( sel), al, 1) ;
1799         *value = (XtArgVal) data ;
1800         }
1801     else
1802     {   *value = (XtArgVal) NULL ;
1803         }
1804     return ;
1805     }
1806 /****************************************************************/
1807 /*ARGSUSED*/
1808 void
_XmSelectionBoxGetCancelLabelString(Widget wid,int resource_offset,XtArgVal * value)1809 _XmSelectionBoxGetCancelLabelString(
1810         Widget wid,
1811         int resource_offset,	/* unused */
1812         XtArgVal *value )
1813 {
1814             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1815             XmString        data ;
1816             Arg             al[1] ;
1817 /****************/
1818 
1819     if(    SB_CancelButton( sel)    )
1820     {
1821         XtSetArg( al[0], XmNlabelString, &data) ;
1822         XtGetValues( SB_CancelButton( sel), al, 1) ;
1823         *value = (XtArgVal) data ;
1824         }
1825     else
1826     {   *value = (XtArgVal) NULL ;
1827         }
1828     return ;
1829     }
1830 /****************************************************************/
1831 /*ARGSUSED*/
1832 void
_XmSelectionBoxGetHelpLabelString(Widget wid,int resource_offset,XtArgVal * value)1833 _XmSelectionBoxGetHelpLabelString(
1834         Widget wid,
1835         int resource_offset,	/* unused */
1836         XtArgVal *value )
1837 {
1838             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1839             XmString        data ;
1840             Arg             al[1] ;
1841 /****************/
1842 
1843     if(    SB_HelpButton( sel)    )
1844     {
1845         XtSetArg( al[0], XmNlabelString, &data) ;
1846         XtGetValues( SB_HelpButton( sel), al, 1) ;
1847         *value = (XtArgVal) data ;
1848         }
1849     else
1850     {   *value = (XtArgVal) NULL ;
1851         }
1852     return ;
1853     }
1854 
1855 /****************************************************************/
1856 /*ARGSUSED*/
1857 void
_XmSelectionBoxUpOrDown(Widget wid,XEvent * event,String * argv,Cardinal * argc)1858 _XmSelectionBoxUpOrDown(
1859         Widget wid,
1860         XEvent *event,		/* unused */
1861         String *argv,
1862         Cardinal *argc )
1863 {
1864             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1865             int	            visible ;
1866             int	            top ;
1867             int	            key_pressed ;
1868             Widget	    list ;
1869             int	*           position ;
1870             int	            count ;
1871             Arg             av[5] ;
1872             Cardinal        ac ;
1873 /****************/
1874 
1875     if (!argc || (*argc != 1) || !argv)
1876     {
1877         XmeWarning(wid, MESSAGE0);
1878         return;
1879     }
1880 
1881     if(    !(list = sel->selection_box.list)    )
1882     {   return ;
1883         }
1884     ac = 0 ;
1885     XtSetArg( av[ac], XmNitemCount, &count) ; ++ac ;
1886     XtSetArg( av[ac], XmNtopItemPosition, &top) ; ++ac ;
1887     XtSetArg( av[ac], XmNvisibleItemCount, &visible) ; ++ac ;
1888     XtGetValues( list, av, ac) ;
1889 
1890     if(    !count    )
1891     {   return ;
1892         }
1893 
1894     if (_XmConvertActionParamToRepTypeId((Widget) sel,
1895 			 XmRID_SELECTION_BOX_UP_OR_DOWN_ACTION_PARAMS,
1896 			 argv[0], True, &key_pressed) == False)
1897     {
1898 	/* We couldn't convert the value. Just assume a value of 0. */
1899 	key_pressed = 0;
1900     }
1901 
1902     position = &(sel->selection_box.list_selected_item_position) ;
1903 
1904     if(    *position == 0    )
1905     {   /*  No selection, so select first item or last if key_pressed == end.
1906         */
1907         if(    key_pressed == 3    )
1908         {   *position = count ;
1909             XmListSelectPos( list, *position, True) ;
1910             }
1911         else
1912         {   XmListSelectPos( list, ++*position, True) ;
1913             }
1914         }
1915     else
1916     {   if(    !key_pressed && (*position > 1)    )
1917         {   /*  up  */
1918             XmListDeselectPos( list, *position) ;
1919             XmListSelectPos( list, --*position, True) ;
1920             }
1921         else
1922         {   if(    (key_pressed == 1) && (*position < count)    )
1923             {   /*  down  */
1924                 XmListDeselectPos( list, *position) ;
1925                 XmListSelectPos( list, ++*position, True) ;
1926                 }
1927             else
1928             {   if(    key_pressed == 2    )
1929                 {   /*  home  */
1930                     XmListDeselectPos( list, *position) ;
1931                     *position = 1 ;
1932                     XmListSelectPos( list, *position, True) ;
1933                     }
1934                 else
1935                 {   if(    key_pressed == 3    )
1936                     {   /*  end  */
1937                         XmListDeselectPos( list, *position) ;
1938                         *position = count ;
1939                         XmListSelectPos( list, *position, True) ;
1940                         }
1941                     }
1942                 }
1943             }
1944         }
1945     if(    top > *position    )
1946     {   XmListSetPos( list, *position) ;
1947         }
1948     else
1949     {   if(    (top + visible) <= *position    )
1950         {   XmListSetBottomPos( list, *position) ;
1951             }
1952         }
1953     return ;
1954     }
1955 
1956 /****************************************************************/
1957 /*ARGSUSED*/
1958 void
_XmSelectionBoxRestore(Widget wid,XEvent * event,String * argv,Cardinal * argc)1959 _XmSelectionBoxRestore(
1960         Widget wid,
1961         XEvent *event,		/* unused */
1962         String *argv,		/* unused */
1963         Cardinal *argc )	/* unused */
1964 {
1965             XmSelectionBoxWidget sel = (XmSelectionBoxWidget) wid ;
1966             Widget          list ;
1967             int	            count ;
1968             XmString *      items ;
1969             Arg             al[5] ;
1970             int             ac ;
1971             String          textItem ;
1972 /****************/
1973 
1974     list = SB_List( sel) ;
1975 
1976     if(    list
1977         && SB_Text( sel)    )
1978     {
1979         ac = 0 ;
1980         XtSetArg( al[ac], XmNselectedItems, &items) ; ++ac ;
1981         XtSetArg( al[ac], XmNselectedItemCount, &count) ; ++ac ;
1982         XtGetValues( list, al, ac) ;
1983         if(    count    )
1984         {
1985             textItem = _XmStringGetTextConcat( *items) ;
1986             XmTextFieldSetString( SB_Text( sel), textItem) ;
1987             XmTextFieldSetInsertionPosition( SB_Text( sel),
1988 			          XmTextFieldGetLastPosition( SB_Text( sel))) ;
1989             XtFree( textItem) ;
1990             }
1991         else
1992         {
1993             XmTextFieldSetString( SB_Text( sel), NULL) ;
1994             }
1995         }
1996     return ;
1997     }
1998 
1999 /****************************************************************
2000  * This function returns the widget id of a SelectionBox child widget.
2001  ****************/
2002 Widget
XmSelectionBoxGetChild(Widget sb,unsigned int which)2003 XmSelectionBoxGetChild(
2004         Widget sb,
2005 #if NeedWidePrototypes
2006         unsigned int which )
2007 #else
2008         unsigned char which )
2009 #endif /* NeedWidePrototypes */
2010 {
2011 /****************/
2012 	Widget	child = NULL;
2013 	_XmWidgetToAppContext(sb);
2014 	_XmAppLock(app);
2015 
2016 	switch (which)
2017 	{
2018 		case XmDIALOG_LIST:
2019 			child = SB_List (sb);
2020 			break;
2021 
2022 		case XmDIALOG_LIST_LABEL:
2023 			child = SB_ListLabel (sb);
2024 			break;
2025 
2026 		case XmDIALOG_SELECTION_LABEL:
2027 			child = SB_SelectionLabel (sb);
2028 			break;
2029 
2030 		case XmDIALOG_WORK_AREA:
2031 			child = SB_WorkArea (sb);
2032 			break;
2033 
2034 		case XmDIALOG_TEXT:
2035 			child = SB_Text (sb);
2036 			break;
2037 
2038 		case XmDIALOG_SEPARATOR:
2039 			child = SB_Separator (sb);
2040 			break;
2041 
2042 		case XmDIALOG_OK_BUTTON:
2043 			child = SB_OkButton (sb);
2044 			break;
2045 
2046 		case XmDIALOG_APPLY_BUTTON:
2047 			child = SB_ApplyButton (sb);
2048 			break;
2049 
2050 		case XmDIALOG_CANCEL_BUTTON:
2051 			child = SB_CancelButton (sb);
2052 			break;
2053 
2054 		case XmDIALOG_HELP_BUTTON:
2055 			child = SB_HelpButton (sb);
2056 			break;
2057 
2058 		case XmDIALOG_DEFAULT_BUTTON:
2059 			child = SB_DefaultButton (sb);
2060 			break;
2061 
2062 		default:
2063 			XmeWarning( (Widget) sb, WARN_CHILD_TYPE);
2064 			break;
2065 	}
2066 	_XmAppUnlock(app);
2067 	return (child);
2068 }
2069 
2070 /****************************************************************
2071  * This function creates and returns a SelectionBox widget.
2072  ****************/
2073 Widget
XmCreateSelectionBox(Widget p,String name,ArgList args,Cardinal n)2074 XmCreateSelectionBox(
2075         Widget p,
2076         String name,
2077         ArgList args,
2078         Cardinal n )
2079 {
2080     return (XtCreateWidget (name, xmSelectionBoxWidgetClass, p, args, n));
2081 }
2082 
2083 Widget
XmVaCreateSelectionBox(Widget parent,char * name,...)2084 XmVaCreateSelectionBox(
2085         Widget parent,
2086         char *name,
2087         ...)
2088 {
2089     register Widget w;
2090     va_list var;
2091     int count;
2092 
2093     Va_start(var,name);
2094     count = XmeCountVaListSimple(var);
2095     va_end(var);
2096 
2097 
2098     Va_start(var, name);
2099     w = XmeVLCreateWidget(name,
2100                          xmSelectionBoxWidgetClass,
2101                          parent, False,
2102                          var, count);
2103     va_end(var);
2104     return w;
2105 }
2106 
2107 Widget
XmVaCreateManagedSelectionBox(Widget parent,char * name,...)2108 XmVaCreateManagedSelectionBox(
2109         Widget parent,
2110         char *name,
2111         ...)
2112 {
2113     Widget w = NULL;
2114     va_list var;
2115     int count;
2116 
2117     Va_start(var, name);
2118     count = XmeCountVaListSimple(var);
2119     va_end(var);
2120 
2121     Va_start(var, name);
2122     w = XmeVLCreateWidget(name,
2123                          xmSelectionBoxWidgetClass,
2124                          parent, True,
2125                          var, count);
2126     va_end(var);
2127     return w;
2128 }
2129 
2130 /****************************************************************
2131  * This convenience function creates a DialogShell and a SelectionBox
2132  *   child of the shell; returns the SelectionBox widget.
2133  ****************/
2134 Widget
XmCreateSelectionDialog(Widget ds_p,String name,ArgList sb_args,Cardinal sb_n)2135 XmCreateSelectionDialog(
2136         Widget ds_p,
2137         String name,
2138         ArgList sb_args,
2139         Cardinal sb_n )
2140 {
2141     ArgList		_sb_args;	/*  arglist for sb	*/
2142     Widget w;
2143 
2144     /*  allocate arglist, copy args, add dialog type arg
2145      */
2146     _sb_args = (ArgList) XtMalloc (sizeof (Arg) * (sb_n + 1));
2147     memcpy(_sb_args, sb_args, sizeof (Arg) * sb_n);
2148     XtSetArg (_sb_args[sb_n], XmNdialogType, XmDIALOG_SELECTION);  sb_n++;
2149 
2150     /*  create SelectionBoxDialog, free args, return */
2151     w = XmeCreateClassDialog (xmSelectionBoxWidgetClass,
2152 			      ds_p, name, _sb_args, sb_n) ;
2153     XtFree((char *)_sb_args);
2154     return w ;
2155 }
2156 
2157 
2158 
2159 /****************************************************************
2160  * This convenience function creates a DialogShell and a SelectionBox
2161  *   child of the shell; returns the SelectionBox widget.
2162  ****************/
2163 Widget
XmCreatePromptDialog(Widget ds_p,String name,ArgList sb_args,Cardinal sb_n)2164 XmCreatePromptDialog(
2165         Widget ds_p,
2166         String name,
2167         ArgList sb_args,
2168         Cardinal sb_n )
2169 {
2170     ArgList		_sb_args;	/*  arglist for sb	*/
2171     Widget w;
2172 
2173     /*  allocate arglist, copy args, add dialog type arg
2174      */
2175     _sb_args = (ArgList) XtMalloc (sizeof (Arg) * (sb_n + 1));
2176     memcpy(_sb_args, sb_args, sizeof (Arg) * sb_n);
2177     XtSetArg (_sb_args[sb_n], XmNdialogType, XmDIALOG_PROMPT);  sb_n++;
2178 
2179     /*  create SelectionBoxDialog, free args, return */
2180     w = XmeCreateClassDialog (xmSelectionBoxWidgetClass,
2181 			      ds_p, name, _sb_args, sb_n) ;
2182     XtFree((char*)_sb_args);
2183     return w ;
2184 }
2185