-
Notifications
You must be signed in to change notification settings - Fork 6
/
ComboBox.c
2839 lines (2323 loc) · 82.1 KB
/
ComboBox.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*@
* Copyright(c) 1995-1997 Gregory M. Messner
* All rights reserved
*
* Permission to use, copy, modify and distribute this material for
* non-commercial personal and educational use without fee is hereby
* granted, provided that the above copyright notice and this permission
* notice appear in all copies, and that the name of Gregory M. Messner
* not be used in advertising or publicity pertaining to this material
* without the specific, prior written permission of Gregory M. Messner
* or an authorized representative.
*
* GREGORY M. MESSNER MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES,
* EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST INFRINGEMENT OF PATENTS
* OR OTHER INTELLECTUAL PROPERTY RIGHTS. THE SOFTWARE IS PROVIDED "AS IS",
* AND IN NO EVENT SHALL GREGORY M. MESSNER BE LIABLE FOR ANY DAMAGES,
* INCLUDING ANY LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES
* RELATING TO THE SOFTWARE.
*
*/
/*************************************************************************\
* Copyright (c) 1994-2004 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 1997-2003 Southeastern Universities Research Association,
* as Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 1997-2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* +++FHDR+++
*
* Filename: ComboBox.c
* Module : Xg Widget Set
* SCCS ID : 1.1 25 Oct 1995
*
* Description:
* This is the source file for a Motif Combo Box widget.
*
*
*
* Changes
*
* By Date Description
* ------ -------------- ----------------------------------------------
* GMM 08/27/93 Original file
* GMM 09/02/93 General cleanup
* GMM 01/25/94 Added XgNexpandListWidth and XgNautoFillIn
* resources
*
*
* ---FHDR--- */
#include <ctype.h>
#include <stdlib.h>
/*
* We define a cursor for the list
*/
#include <X11/cursorfont.h>
/*
* These includes are needed to describe the widget
*/
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <Xm/XmP.h>
/*
* These includes are for the elements of the widget
*/
#include <Xm/Text.h>
#include <Xm/ArrowB.h>
#include <Xm/List.h>
#include <Xm/DialogS.h>
#include <Xm/ScrolledW.h>
#include "ComboBoxP.h"
/*
* Declaration of methods
*/
static void ClassInitialize(void);
static void Initialize(Widget wrequest, Widget wnew,
ArgList args, Cardinal *num_args);
#if 0
/* KE: unused */
static void Redisplay(Widget w, XEvent *event, Region region);
#endif
static Boolean SetValues(Widget cur, Widget req,
Widget new, ArgList args, Cardinal *nargs);
static void Destroy(Widget widget);
static void Resize(Widget w);
static XtGeometryResult QueryGeometry(Widget widget, XtWidgetGeometry *proposed,
XtWidgetGeometry *desired);
static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *reply);
/*
* Useful
*/
static char *XgConvertXmStringToString (XmString xmstr);
/*
* Internal use functions and callbacks
*/
static Widget createComboBoxList(XgComboBoxWidget comboBox);
static void verifyInputCB(Widget widget, XtPointer client, XtPointer call);
static void comboArrowCB(Widget arrow, XtPointer client, XtPointer call);
static void ActivateCallback(Widget w, XtPointer client, XtPointer call);
static Boolean CheckFocus(XgComboBoxWidget cb);
static void FocusChangeHandler(Widget w, XtPointer not_used,
XFocusChangeEvent *event, Boolean *continue_dispatch);
static void FillCallbackStruct(XgComboBoxWidget cbox, int reason, XEvent *event,
XgComboBoxCallbackStruct *cbs);
static void hideList(XgComboBoxWidget w);
static void updateListAndText(XgComboBoxWidget cbw, int index, XmString item,
Boolean notify);
static void CopyBg(XgComboBoxWidget cbw, int offset, XrmValue *value);
static void CopyFg(XgComboBoxWidget cbw, int offset, XrmValue *value);
static void FocusChangeCB(Widget w, XtPointer client_data, XtPointer call_data);
static void visibleCB(Widget parent, XtPointer client, XEvent *event,
Boolean *ctd);
static void comboListCB(Widget list, XtPointer client, XtPointer call);
#define AddFocusChangeHandler(w) \
XtAddEventHandler(w, FocusChangeMask, False, \
(XtEventHandler)FocusChangeHandler, NULL)
static char textTranslations[] =
"Alt<Key>osfDown: ComboBox-Manager(show-hide-list)\n\
Meta<Key>osfDown: ComboBox-Manager(show-hide-list)\n\
Alt<Key>osfUp: ComboBox-Manager(hide-list)\n\
Meta<Key>osfUp: ComboBox-Manager(hide-list)\n\
<Key>osfUp: ComboBox-Manager(up)\n\
<Key>osfDown: ComboBox-Manager(down)\n\
<Key>osfPageUp: ComboBox-Manager(page-up)\n\
<Key>osfPageDown: ComboBox-Manager(page-down)\n\
<Key>osfCancel: ComboBox-Manager(cancel)\n\
<Key>Return: ComboBox-Manager(activate) activate()";
static char noEditTextTranslations[] =
"<Key>osfBeginLine: ComboBox-Manager(top)\n\
<Key>osfEndLine: ComboBox-Manager(bottom)";
#ifdef NODRAGNDROP
static char noDDListTranslations[] =
"<Btn2Down>: ComboBox-Manager(no-operation)";
#endif
static char listTranslations[] =
"<Key>osfPageUp: ComboBox-Manager(page-up)\n\
<Key>osfPageDown: ComboBox-Manager(page-down)";
static void CBoxManager(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static XtActionsRec actions[] = {
{ "ComboBox-Manager", CBoxManager },
{ NULL, NULL }
};
static XtTranslations newTextTranslations, newNoEditTextTranslations,
newListTranslations;
#define TextChild(w) ((CompositeWidget)(w->combobox.text))
#define ArrowChild(w) ((CompositeWidget)(w->combobox.arrow))
static XtResource resources[] = {
{ XmNcolumns, XmCColumns, XmRShort, sizeof(short),
XtOffsetOf(XgComboBoxRec, combobox.textColumns),
XmRImmediate, (XtPointer)10 },
{ XgNtextForeground, XmCForeground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgComboBoxRec, combobox.textFg),
XtRCallProc, (XtPointer)CopyFg },
{ XgNlistForeground, XmCForeground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgComboBoxRec, combobox.listFg),
XtRCallProc, (XtPointer)CopyFg },
{ XgNtextBackground, XmCBackground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgComboBoxRec, combobox.textBg),
XtRCallProc, (XtPointer)CopyBg },
{ XgNlistBackground, XmCBackground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgComboBoxRec, combobox.listBg),
XtRCallProc, (XtPointer)CopyBg },
{ XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension,sizeof(Dimension),
XtOffsetOf(XgComboBoxRec, combobox.margin_height),
XmRImmediate, (XtPointer)5 },
{ XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension,
sizeof(Dimension), XtOffsetOf(XgComboBoxRec, combobox.margin_width),
XmRImmediate, (XtPointer)5 },
{ XmNmaxLength, XmCMaxLength, XmRInt, sizeof(int),
XtOffsetOf(XgComboBoxRec, combobox.textMaxLength),
XmRImmediate, (XtPointer)128 },
{ XmNeditable, XmCEditable, XmRBoolean, sizeof(Boolean),
XtOffsetOf(XgComboBoxRec, combobox.editable),
XmRImmediate, (XtPointer)True},
{ XmNverifyBell, XmCVerifyBell, XmRBoolean, sizeof(Boolean),
XtOffsetOf(XgComboBoxRec, combobox.audible),
XmRImmediate, (XtPointer)False },
{ XmNvisibleItemCount, XmCVisibleItemCount, XmRInt, sizeof(int),
XtOffsetOf(XgComboBoxRec, combobox.visibleItems),
XmRImmediate, (XtPointer) 1 },
{ XmNitemCount, XmCItemCount, XmRInt, sizeof(int),
XtOffsetOf(XgComboBoxRec, combobox.listCount),
XmRImmediate, (XtPointer) 0 },
{ XmNitems, XmCItems, XmRXmStringTable, sizeof(XmStringTable),
XtOffsetOf(XgComboBoxRec, combobox.listTable),
XmRImmediate, (XtPointer)NULL },
{ XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList),
XtOffsetOf(XgComboBoxRec, combobox.font_list),
XmRImmediate, (XtPointer) NULL},
{ XgNautoFillIn, XgNautoFillIn, XmRBoolean, sizeof(Boolean),
XtOffsetOf(XgComboBoxRec, combobox.autoFillIn),
XmRImmediate, (XtPointer)False},
{ XgNexpandListWidth, XgNexpandListWidth, XmRBoolean, sizeof(Boolean),
XtOffsetOf(XgComboBoxRec, combobox.expandListWidth),
XmRImmediate, (XtPointer)True},
{ XmNfocusCallback, XmCCallback, XmRCallback, sizeof(caddr_t),
XtOffsetOf( XgComboBoxRec, combobox.focus_list ),
XmRImmediate, (XtPointer) NULL },
{ XmNlosingFocusCallback, XmCCallback, XmRCallback, sizeof(caddr_t),
XtOffsetOf( XgComboBoxRec, combobox.losing_focus_list ),
XmRImmediate, (XtPointer) NULL },
{ XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(caddr_t),
XtOffsetOf( XgComboBoxRec, combobox.value_changed ),
XmRImmediate, (XtPointer) NULL },
{ XmNactivateCallback, XmCCallback, XmRCallback, sizeof(caddr_t),
XtOffsetOf( XgComboBoxRec, combobox.activate ),
XmRImmediate, (XtPointer) NULL }
};
XgComboBoxClassRec XgcomboBoxClassRec = {
{
/* core_class fields */
/* superclass */ (WidgetClass) &xmManagerClassRec,
/* class_name */ "XgComboBox",
/* widget_size */ sizeof(XgComboBoxRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize*/ NULL,
/* class_inited */ False,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ True,
/* compress_exposure */ XtExposeCompressMaximal,
/* compress_enterleave */ True,
/* visible_interest */ True,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ XtInheritExpose,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ XtInheritAcceptFocus,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ XtInheritTranslations,
/* query_geometry */ QueryGeometry,
/* display_accelerator */ NULL,
/* extension */ NULL
},
/* composite_class fields */
{
/* geometry_manager */ GeometryManager,
/* changed_managed */ XtInheritChangeManaged,
/* insert_child */ XtInheritInsertChild,
/* delete_child */ XtInheritDeleteChild,
/* extension */ NULL
},
/* constraint_class fields */
{
NULL, /* resource list */
0, /* num resources */
0, /* constraint size */
NULL, /* init proc */
NULL, /* destroy proc */
NULL, /* set values proc */
NULL
},
/* manager_class */
{
XtInheritTranslations, /* translations */
NULL, /* syn_resources */
0, /* num_syn_resources */
NULL, /* syn_cont_resources */
0, /* num_syn_cont_resources */
XmInheritParentProcess, /* parent_process */
NULL
},
/* combo box fields */
{
0,
}
};
WidgetClass xgComboBoxWidgetClass = (WidgetClass) &XgcomboBoxClassRec;
static Boolean
CvtStringToStringTable(display, args, num_args, from, to)
Display *display;
XrmValuePtr args;
Cardinal *num_args;
XrmValuePtr from;
XrmValuePtr to;
{
int i;
char *tmp_string, *string;
static XmStringTable items = NULL;
static int item_count = 0;
if ( *num_args != 0 )
XtWarningMsg("XtToolkitError", "wrongParameters",
"CvtStringToStringTable",
"conversion needs no arguments", (String *) NULL,
(Cardinal *) NULL);
if ( items != NULL )
{
for ( i = 0; i < item_count; i++ )
XmStringFree(items[i]);
XtFree((char *)items);
items = NULL;
}
/*
* User didn't provide enough space
*/
if ( to->addr != NULL && to->size < sizeof(XmStringTable) )
{
to->size = sizeof(XmStringTable);
return False;
}
items = (XmStringTable) malloc(sizeof(XmString));
items[0] = NULL;
item_count = 0;
string = (char *)from->addr;
if ( string != NULL )
{
int len = strlen(string);
for ( tmp_string = string, i = 0; i <= len; i++ )
{
if ( string[i] == ',' || string[i] == '\0' )
{
string[i] = '\0';
items[item_count] = XmStringCreateLtoR(
tmp_string, XmSTRING_DEFAULT_CHARSET);
tmp_string = string + i + 1;
item_count++;
items = (XmStringTable)realloc(items,
sizeof(XmString) * (item_count + 1));
items[item_count] = NULL;
if ( i == len || *tmp_string == '\0' )
break;
}
}
}
to->size = sizeof(XmStringTable);
if ( item_count == 0 )
{
XtFree((char *)items);
items = NULL;
return False;
}
if ( to->addr == NULL )
to->addr = (caddr_t) &items;
else
*(XmStringTable *) to->addr = items;
return True;
}
static void CopyBg(XgComboBoxWidget cbw, int offset, XrmValue *value)
{
value->addr = (XtPointer) &cbw->core.background_pixel;
}
static void CopyFg(XgComboBoxWidget cbw, int offset, XrmValue *value)
{
value->addr = (XtPointer) &cbw->manager.foreground;
}
static void
ClassInitialize(void)
{
XtSetTypeConverter(XmRString, XmRXmStringTable,
(XtTypeConverter)CvtStringToStringTable, NULL,
0, XtCacheNone, NULL);
newTextTranslations =
XtParseTranslationTable(textTranslations);
newNoEditTextTranslations =
XtParseTranslationTable(noEditTextTranslations);
#ifdef NODRAGNDROP
newNoDDListTranslations =
XtParseTranslationTable(noDDListTranslations);
#endif
newListTranslations =
XtParseTranslationTable(listTranslations);
}
/* +++PHDR+++
*
* Function: Initialize()
*
* Scope: static
*
* Description:
* This function is the Initialize() method for the XgComboBox widget.
*
*
* Argument Type Description
* ------------ ----------------------- -------------------------------------
* request XgComboBoxWidget Widget filled in from resources
* new XgComboBoxWidget Copy of request widget that has
* been potentialy altered by
* XgComboBox's superclasses
*
*
* Returns: void
*
*
* ---PHDR--- */
static void Initialize(Widget wrequest, Widget wnew,
ArgList args, Cardinal *num_args)
{
Dimension textWidth, textHeight;
Position arrowX, arrowY;
Boolean editable, cursorPositionVisible;
XgComboBoxWidget new=(XgComboBoxWidget)wnew;
new->combobox.initializing = True;
new->combobox.saved_text = NULL;
XtAppAddActions(XtWidgetToApplicationContext((Widget) new),
actions, XtNumber(actions));
new->combobox.activate = new->combobox.value_changed = NULL;
new->combobox.focus_list = new->combobox.losing_focus_list = NULL;
new->combobox.workproc_id = None;
new->combobox.focus_widget = NULL;
new->combobox.i_have_focus = False;
/*
* Create the Text part of the Combo Box
*/
if ( new->combobox.editable == False )
editable = cursorPositionVisible = False;
else
editable = cursorPositionVisible = True;
new->combobox.text = XtVaCreateManagedWidget(NULL,
xmTextWidgetClass, (Widget) new,
XmNforeground, new->combobox.textFg,
XmNbackground, new->combobox.textBg,
XmNtraversalOn, True,
XmNfontList, new->combobox.font_list,
XmNeditable, editable,
XmNverifyBell, new->combobox.audible,
XmNcursorPositionVisible, cursorPositionVisible,
XmNrows, 1,
XmNcolumns, new->combobox.textColumns,
XmNmarginHeight, new->combobox.margin_height,
XmNmarginWidth, new->combobox.margin_width,
XmNmaxLength, new->combobox.textMaxLength,
XmNwordWrap, False,
XmNresizeWidth, False,
XmNresizeHeight, False,
XmNeditMode, XmSINGLE_LINE_EDIT,
XmNnavigationType, XmNONE,
NULL);
XtOverrideTranslations(new->combobox.text, newTextTranslations);
if ( !new->combobox.editable )
XtOverrideTranslations(new->combobox.text,
newNoEditTextTranslations);
#ifdef NODRAGNDROP
XtOverrideTranslations(new->combobox.text, newNoDDListTranslations);
#endif
/*
* Get the fontList if ULL was passed
*/
if ( new->combobox.font_list == NULL )
XtVaGetValues(new->combobox.text,
XmNfontList, &new->combobox.font_list, NULL);
/*
* Get the size and location of the Text Widget, we use this
* to locate the arrow button
*/
XtVaGetValues(new->combobox.text,
XmNwidth, &textWidth,
XmNheight, &textHeight,
XmNx, &arrowX,
XmNy, &arrowY,
NULL);
/*
* Now create and manage the arrow button
*/
new->combobox.arrow = XtVaCreateManagedWidget(NULL,
xmArrowButtonWidgetClass, (Widget) new,
XmNtraversalOn, True,
XmNarrowDirection, XmARROW_DOWN,
XmNwidth, (Dimension)((double)textHeight * .75),
XmNheight, (Dimension)textHeight,
XmNx, arrowX + textWidth,
XmNy, arrowY,
XmNforeground, new->manager.foreground,
XmNbackground, new->core.background_pixel,
XmNtraversalOn, False,
NULL);
/*
* Add an event handler for FocusChange
*/
AddFocusChangeHandler(new->combobox.arrow);
/*
* Add the width and spacing of the ArrowButton to the textWidth
*/
textWidth += (Dimension)((double)textHeight * .75);
/*
* Save these values as the minimal combo box size
*/
new->combobox.minWidth = textWidth;
new->combobox.minHeight = textHeight;
/*
* Set the Combo Box to it's computed size, or resize it to the
* passed size
*/
if ( textWidth > new->core.width )
new->core.width = textWidth;
if ( textHeight > new->core.height )
new->core.height = textHeight;
Resize(wnew);
createComboBoxList(new);
/*
*
*/
new->combobox.dont_reenter = FALSE;
new->combobox.initializing = False;
XtAddCallback(new->combobox.text,
XmNlosingFocusCallback, FocusChangeCB, NULL);
/*
* Add an Event Handler to Unmanage the list if the window of
* it's parent widget is unmapped
*/
XtAddEventHandler((Widget)new->combobox.text,
VisibilityChangeMask, False, visibleCB, (XtPointer)new);
/*
* Add a callback to verify the text typed into the text widget
*/
XtAddCallback(new->combobox.text,
XmNvalueChangedCallback, verifyInputCB, NULL);
/*
* Add a callback for activate
*/
XtAddCallback(new->combobox.text,
XmNactivateCallback, ActivateCallback, NULL);
/*
* Add a callback to popdown the Combo List Box
*/
XtAddCallback(new->combobox.arrow,
XmNactivateCallback, comboArrowCB, NULL);
}
static void FillCallbackStruct(XgComboBoxWidget cbox, int reason, XEvent *event,
XgComboBoxCallbackStruct *cbs)
{
int pos_count, *pos_list;
XmString xstr;
cbs->reason = reason;
cbs->event = event;
cbs->value = XmTextGetString(cbox->combobox.text);
cbs->list_pos = -1;
if ( cbs->value != NULL )
xstr = XmStringCreateLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET);
else
xstr = NULL;
if ( xstr != NULL )
{
if ( XmListGetMatchPos(cbox->combobox.list, xstr,
&pos_list, &pos_count) == True )
{
if ( pos_list != NULL )
{
cbs->list_pos = pos_list[0];
XtFree((char *)pos_list);
}
}
XmStringFree(xstr);
}
}
static Boolean CheckFocus(XgComboBoxWidget cb)
{
XgComboBoxCallbackStruct cbs;
cb->combobox.workproc_id = None;
/*
* See if we've lost or gained focus
*/
if ( cb->combobox.i_have_focus == True )
{
if ( cb->combobox.focus_widget != cb->combobox.text )
{
cb->combobox.focus_widget = cb->combobox.text;
XmProcessTraversal(cb->combobox.text,
XmTRAVERSE_CURRENT);
/* KE: There was no return value here. Not sure
if True is correct, though */
return True;
}
cb->combobox.i_have_focus = False;
/*
* Make sure the list is poped up
*/
hideList(cb);
if ( cb->combobox.losing_focus_list == NULL )
return True;
FillCallbackStruct(cb, XmCR_LOSING_FOCUS, NULL, &cbs);
XtCallCallbacks((Widget)cb, XmNlosingFocusCallback, &cbs);
if ( cbs.value != NULL )
XtFree(cbs.value);
}
else
{
cb->combobox.i_have_focus = True;
if ( cb->combobox.focus_widget != cb->combobox.text )
{
cb->combobox.focus_widget = cb->combobox.text;
XmProcessTraversal(cb->combobox.text,
XmTRAVERSE_CURRENT);
}
if ( cb->combobox.focus_list == NULL )
return True;
FillCallbackStruct(cb, XmCR_FOCUS, NULL, &cbs);
XtCallCallbacks((Widget)cb, XmNfocusCallback, &cbs);
if ( cbs.value != NULL )
XtFree(cbs.value);
}
/*
* Tell XtMainLoop to remove the work procedure
*/
return True;
}
static void FocusChangeCB(Widget w, XtPointer client_data, XtPointer call_data)
{
XgComboBoxWidget cb = (XgComboBoxWidget)XtParent(w);
if ( cb->combobox.workproc_id == None &&
cb->combobox.focus_widget == cb->combobox.text )
{
cb->combobox.workproc_id = XtAppAddWorkProc(
XtWidgetToApplicationContext(w),
(XtWorkProc)CheckFocus, (XtPointer)cb);
}
}
static void FocusChangeHandler(Widget w, XtPointer not_used,
XFocusChangeEvent *event, Boolean *continue_dispatch)
{
XgComboBoxWidget cb;
cb = (XgComboBoxWidget)XtParent(w);
while ( !XgIsComboBox((Widget)cb) )
cb = (XgComboBoxWidget)XtParent((Widget)cb);
cb->combobox.focus_widget = w;
if ( event->type == FocusIn && cb->combobox.workproc_id == None )
{
cb->combobox.workproc_id = XtAppAddWorkProc(
XtWidgetToApplicationContext(w),
(XtWorkProc)CheckFocus, (XtPointer)cb);
}
*continue_dispatch = True;
}
static XtGeometryResult QueryGeometry(Widget widget, XtWidgetGeometry *proposed,
XtWidgetGeometry *desired)
{
#define Set(bit) (proposed->request_mode & bit)
XgComboBoxWidget w = (XgComboBoxWidget)widget;
desired->width = TextChild(w)->core.width + ArrowChild(w)->core.width;
desired->height = TextChild(w)->core.height;
desired->request_mode = CWWidth | CWHeight;
if ( Set(CWWidth) && proposed->width == desired->width &&
Set(CWHeight) && proposed->height == desired->height )
return XtGeometryYes;
if ( desired->width == w->core.width &&
desired->height == w->core.height )
return XtGeometryNo;
return XtGeometryAlmost;
#undef Set
}
#if 0
/* KE: unused */
static void
InsertChild(w)
Widget w;
{
XgComboBoxWidget cb = (XgComboBoxWidget)XtParent(w);
if ( cb->combobox.initializing != True )
{
XtAppWarningMsg(XtWidgetToApplicationContext(w),
"insertChild", "badChild", "XbaeCaption",
"XgComboBox: Cannot add children.",
(String *)NULL, (Cardinal *)NULL);
return;
}
(*((CompositeWidgetClass)
(xgComboBoxWidgetClass->core_class.superclass))->composite_class.
insert_child) (w);
}
#endif
static void Destroy(Widget widget)
{
XgComboBoxWidget w=(XgComboBoxWidget)widget;
/*
* Make sure this is a ComboBox widget
*/
if ( !XgIsComboBox((Widget)widget) )
return;
#if 0
/* KE: The Destroy method only frees memory and resources
allocated by the widget, not memory allocated by Xt. I am
not sure, but I don't think this belongs here. It seems to
be causing FMRs in Purify. It does not seem to cause MLKs
when it is removed. */
/*
* Destroy the dialog shell for the popup list
*/
if ( w->combobox.popup != NULL )
XtDestroyWidget(XtParent(w->combobox.popup));
#endif
/*
* Remove the work procedure for the FocusHandler
*/
if ( w->combobox.workproc_id != None )
XtRemoveWorkProc(w->combobox.workproc_id);
/*
* Remove the callbacks, if any installed
*/
if ( w->combobox.focus_list != NULL )
XtRemoveCallbacks( (Widget)w, XmNfocusCallback,
w->combobox.focus_list);
if ( w->combobox.losing_focus_list != NULL )
XtRemoveCallbacks( (Widget)w, XmNlosingFocusCallback,
w->combobox.losing_focus_list);
if ( w->combobox.value_changed != NULL )
XtRemoveAllCallbacks((Widget)w, XmNvalueChangedCallback);
if ( w->combobox.activate != NULL )
XtRemoveAllCallbacks((Widget)w, XmNactivateCallback);
}
#if 0
/* KE: unused */
static void
GetValuesHook(w, args, num_args)
XgComboBoxWidget w;
ArgList args;
Cardinal *num_args;
{
Cardinal i;
Arg xtarg;
/*
* We don't save a copy of the items or itemsCount.
* If the user wants these, we get them from the list widget.
*/
for (i = 0; i < *num_args; i++)
if ( strcmp(args[i].name, XmNitems) == 0 )
{
if ( w->combobox.list != NULL )
XtGetValues(w->combobox.list, &args[i], 1);
}
else if ( strcmp(args[i].name, XmNitemCount) == 0 )
{
if ( w->combobox.list != NULL )
XtGetValues(w->combobox.list, &args[i], 1);
}
else if ( strcmp(args[i].name, XmNvisibleItemCount) == 0 )
{
if ( w->combobox.list != NULL )
XtGetValues(w->combobox.list, &args[i], 1);
}
else if ( strcmp(args[i].name, XmNcolumns) == 0 )
XtGetValues(w->combobox.text, &args[i], 1);
else if ( strcmp(args[i].name, XmNmaxLength) == 0 )
XtGetValues(w->combobox.text, &args[i], 1);
else if ( strcmp(args[i].name, XmNeditable) == 0 )
XtGetValues(w->combobox.text, &args[i], 1);
else if ( strcmp(args[i].name, XmNverifyBell) == 0 )
XtGetValues(w->combobox.text, &args[i], 1);
else if ( strcmp(args[i].name, XgNtextBackground) == 0 )
{
XtSetArg(xtarg, XmNbackground, args[i].value);
XtGetValues(w->combobox.text, &xtarg, 1);
}
else if ( strcmp(args[i].name, XgNlistBackground) == 0 )
{
if ( w->combobox.list != NULL )
{
XtSetArg(xtarg, XmNbackground, args[i].value);
XtGetValues(w->combobox.list, &xtarg, 1);
}
}
}
#endif
static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *reply)
{
XgComboBoxWidget cb = (XgComboBoxWidget)XtParent(w);
if ( w == cb->combobox.arrow )
{
if ( !(request->request_mode & (CWX | CWHeight)) )
return XtGeometryNo;
}
else if ( w == cb->combobox.text )
{
if ( !(request->request_mode & (CWHeight | CWWidth)) )
return XtGeometryNo;
}
else if ( w == cb->combobox.list )
return XtGeometryYes;
else
return XtGeometryNo;
return XtGeometryYes;
}
static void Resize(Widget widget)
{
Dimension newWidth, width, height, border;
Position y;
XgComboBoxWidget w = (XgComboBoxWidget)widget;
/*
* What we need to do here is get the width of the arrow button
* and subtract that from the passed width to compute the new
* width of the text portion of the combo box. We then use
* XtVaSetValues to set the new width of the text and the X location
* of the arrow button.
*/
XtVaGetValues((Widget)w->combobox.arrow,
XmNy, &y, XmNwidth, &width, NULL);
newWidth = w->core.width - width;
XtMoveWidget((Widget)w->combobox.arrow, newWidth, y);
XtVaGetValues((Widget)w->combobox.text,
XmNheight, &height, XmNborderWidth, &border, NULL);
XtResizeWidget((Widget)w->combobox.text, newWidth, height, border);
}
/* +++PHDR+++