-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiList.c
1761 lines (1433 loc) · 54.2 KB
/
MultiList.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
/****************************************************************************
MultiList.c
This file contains the implementation of the Picasso List
widget. Its functionality is intended to be similar to
The Athena List widget, with some extra features added.
This code is loosely based on the Athena List source which
is why the MIT copyright notice appears below.
The code was changed substantially in V3.4 to change the
action/callback interface which was unnecessarily ugly. Code
using some features of the old interface may need to be changed.
Hope the changes don't make people's lives too miserable.
****************************************************************************/
/*
* Author:
* Brian Totty
* Department of Computer Science
* University Of Illinois at Urbana-Champaign
* 1304 West Springfield Avenue
* Urbana, IL 61801
*
*
*/
/*
* Copyright 1989 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Original Athena Author: Chris D. Peterson, MIT X Consortium
*/
#include <stdio.h>
#ifndef NOSTDHDRS
#include <stdlib.h>
#endif
#include <ctype.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "MultiListP.h"
/*===========================================================================*
D E C L A R A T I O N S A N D D E F I N I T I O N S
*===========================================================================*/
Pixmap XmuCreateStippledPixmap();
extern void XawInitializeWidgetSet();
#define SUPERCLASS &(simpleClassRec)
#define FontAscent(f) ((f)->max_bounds.ascent)
#define FontDescent(f) ((f)->max_bounds.descent)
#define FontH(f) (FontAscent(f) + FontDescent(f) + 2)
#define FontW(f,s) (XTextWidth(f,s,strlen(s)) + 1)
#define FontMaxCharW(f) ((f)->max_bounds.rbearing-(f)->min_bounds.lbearing+1)
#ifndef abs
#define abs(a) ((a) < 0 ? -(a) : (a))
#endif
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define XtStrlen(s) ((s) ? strlen(s) : 0)
#define TypeAlloc(t,n) (t *)malloc(sizeof(t) * n)
#define StrCopy(s) strcpy(TypeAlloc(char,strlen(s)+1),s)
#define StrCopyRetLength(s,lp) strcpy(TypeAlloc(char,(*lp=(strlen(s)+1))),s)
#define CoreFieldOffset(f) XtOffset(Widget,core.f)
#define SimpleFieldOffset(f) XtOffset(XfwfMultiListWidget,simple.f)
#define MultiListFieldOffset(f) XtOffset(XfwfMultiListWidget,multiList.f)
/*===========================================================================*
I N T E R N A L P R O C E D U R E D E C L A R A T I O N S
*===========================================================================*/
#if (!NeedFunctionPrototypes)
static void Initialize();
static void Redisplay();
static XtGeometryResult PreferredGeometry();
static void Resize();
static Boolean SetValues();
static void DestroyOldData();
static void InitializeNewData();
static void CreateNewGCs();
static void RecalcCoords();
static void NegotiateSizeChange();
static Boolean Layout();
static void RedrawAll();
static void RedrawItem();
static void RedrawRowColumn();
static void PixelToRowColumn();
static void RowColumnToPixels();
static Boolean RowColumnToItem();
static Boolean ItemToRowColumn();
static void Select();
static void Unselect();
static void Toggle();
static void Extend();
static void Notify();
#else
static void Initialize(Widget request, Widget new);
static void Redisplay(XfwfMultiListWidget mlw,
XEvent *event, Region rectangle_union);
static XtGeometryResult PreferredGeometry(XfwfMultiListWidget mlw,
XtWidgetGeometry *parent_idea,
XtWidgetGeometry *our_idea);
static void Resize(XfwfMultiListWidget mlw);
static Boolean SetValues(XfwfMultiListWidget cpl,
XfwfMultiListWidget rpl,
XfwfMultiListWidget npl);
static void DestroyOldData(XfwfMultiListWidget mlw);
static void InitializeNewData(XfwfMultiListWidget mlw);
static void CreateNewGCs(XfwfMultiListWidget mlw);
static void RecalcCoords(XfwfMultiListWidget mlw,
Boolean width_changeable,
Boolean height_changeable);
static void NegotiateSizeChange(XfwfMultiListWidget mlw,
Dimension width, Dimension height);
static Boolean Layout(XfwfMultiListWidget mlw,
Boolean w_changeable, Boolean h_changeable,
Dimension *w_ptr, Dimension *h_ptr);
static void RedrawAll(XfwfMultiListWidget mlw);
static void RedrawItem(XfwfMultiListWidget mlw, int item_index);
static void RedrawRowColumn(XfwfMultiListWidget mlw,
int row, int column);
static void PixelToRowColumn(XfwfMultiListWidget mlw,
int x, int y, int *row_ptr, int *column_ptr);
static void RowColumnToPixels(XfwfMultiListWidget mlw,
int row, int col, int *x_ptr, int *y_ptr,
int *w_ptr, int *h_ptr);
static Boolean RowColumnToItem(XfwfMultiListWidget mlw,
int row, int column, int *item_ptr);
static Boolean ItemToRowColumn(XfwfMultiListWidget mlw,
int item_index, int *row_ptr, int *column_ptr);
static void Select(XfwfMultiListWidget mlw, XEvent *event,
String *params, Cardinal *num_params);
static void Unselect(XfwfMultiListWidget mlw, XEvent *event,
String *params, Cardinal *num_params);
static void Toggle(XfwfMultiListWidget mlw, XEvent *event,
String *params, Cardinal *num_params);
static void Extend(XfwfMultiListWidget mlw, XEvent *event,
String *params, Cardinal *num_params);
static void Notify(XfwfMultiListWidget mlw, XEvent *event,
String *params, Cardinal *num_params);
#endif
/*===========================================================================*
R E S O U R C E I N I T I A L I Z A T I O N
*===========================================================================*/
static XtResource resources[] =
{
{XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
CoreFieldOffset(width), XtRString, "0"},
{XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
CoreFieldOffset(height), XtRString, "0"},
{XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
CoreFieldOffset(background_pixel),XtRString,"XtDefaultBackground"},
{XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
SimpleFieldOffset(cursor), XtRString, "left_ptr"},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
MultiListFieldOffset(foreground), XtRString,"XtDefaultForeground"},
{XtNhighlightForeground, XtCHForeground, XtRPixel, sizeof(Pixel),
MultiListFieldOffset(highlight_fg), XtRString, "XtDefaultBackground"},
{XtNhighlightBackground, XtCHBackground, XtRPixel, sizeof(Pixel),
MultiListFieldOffset(highlight_bg), XtRString, "XtDefaultForeground"},
{XtNcolumnSpacing, XtCSpacing, XtRDimension, sizeof(Dimension),
MultiListFieldOffset(column_space), XtRImmediate, (caddr_t)8},
{XtNrowSpacing, XtCSpacing, XtRDimension, sizeof(Dimension),
MultiListFieldOffset(row_space), XtRImmediate, (caddr_t)0},
{XtNdefaultColumns, XtCColumns, XtRInt, sizeof(int),
MultiListFieldOffset(default_cols), XtRImmediate, (caddr_t)1},
{XtNforceColumns, XtCColumns, XtRBoolean, sizeof(Boolean),
MultiListFieldOffset(force_cols), XtRString, (caddr_t) "False"},
{XtNpasteBuffer, XtCBoolean, XtRBoolean, sizeof(Boolean),
MultiListFieldOffset(paste), XtRString, (caddr_t) "False"},
{XtNverticalList, XtCBoolean, XtRBoolean, sizeof(Boolean),
MultiListFieldOffset(row_major), XtRString, (caddr_t) "False"},
{XtNlongest, XtCLongest, XtRInt, sizeof(int),
MultiListFieldOffset(longest), XtRImmediate, (caddr_t)0},
{XtNnumberStrings, XtCNumberStrings, XtRInt, sizeof(int),
MultiListFieldOffset(nitems), XtRImmediate, (caddr_t)0},
{XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
MultiListFieldOffset(font),XtRString, "XtDefaultFont"},
{XtNlist, XtCList, XtRPointer, sizeof(char **),
MultiListFieldOffset(list), XtRString, NULL},
{XtNsensitiveArray, XtCList, XtRPointer, sizeof(Boolean *),
MultiListFieldOffset(sensitive_array), XtRString, NULL},
{XtNcallback, XtCCallback, XtRCallback, sizeof(caddr_t),
MultiListFieldOffset(callback), XtRCallback, NULL},
{XtNmaxSelectable, XtCValue, XtRInt, sizeof(int),
MultiListFieldOffset(max_selectable), XtRImmediate, (caddr_t) 1},
{XtNshadeSurplus, XtCBoolean, XtRBoolean, sizeof(Boolean),
MultiListFieldOffset(shade_surplus), XtRString, "True"},
{XtNcolumnWidth, XtCValue, XtRDimension, sizeof(Dimension),
MultiListFieldOffset(col_width), XtRImmediate, (caddr_t)0},
{XtNrowHeight, XtCValue, XtRDimension, sizeof(Dimension),
MultiListFieldOffset(row_height), XtRImmediate, (caddr_t)0},
};
/*===========================================================================*
A C T I O N A N D T R A N S L A T I O N T A B L E S
*===========================================================================*/
static char defaultTranslations[] =
" Shift <Btn1Down>: Toggle()\n\
Ctrl <Btn1Down>: Unselect()\n\
<Btn1Down>: Select()\n\
Button1 <Btn1Motion>: Extend()\n\
<Btn1Up>: Notify()";
static XtActionsRec actions[] =
{
{"Select", (XtActionProc)Select},
{"Unselect", (XtActionProc)Unselect},
{"Toggle", (XtActionProc)Toggle},
{"Extend", (XtActionProc)Extend},
{"Notify", (XtActionProc)Notify},
{NULL, (XtActionProc)NULL}
};
/*===========================================================================*
C L A S S A L L O C A T I O N
*===========================================================================*/
XfwfMultiListClassRec xfwfMultiListClassRec =
{
{
/* superclass */ (WidgetClass)SUPERCLASS,
/* class_name */ "XfwfMultiList",
/* widget_size */ sizeof(XfwfMultiListRec),
/* class_initialize */ NULL,
/* class_part_initialize*/ NULL,
/* class_inited */ FALSE,
/* initialize */ (XtInitProc)Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* resource_count */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ FALSE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ NULL,
/* resize */ (XtWidgetProc)Resize,
/* expose */ (XtExposeProc)Redisplay,
/* set_values */ (XtSetValuesFunc)SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ (XtGeometryHandler)
PreferredGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
}, /* Core Part */
{
/* change_sensitive */ XtInheritChangeSensitive
}
};
WidgetClass xfwfMultiListWidgetClass = (WidgetClass)&xfwfMultiListClassRec;
/*===========================================================================*
T O O L K I T M E T H O D S
*===========================================================================*/
/*---------------------------------------------------------------------------*
Initialize()
This procedure is called by the X toolkit to initialize
the widget instance. The hook to this routine is in the
initialize part of the core part of the class.
*---------------------------------------------------------------------------*/
/* ARGSUSED */
static void Initialize(request,new)
Widget request,new;
{
XfwfMultiListWidget mlw;
mlw = (XfwfMultiListWidget)new;
CreateNewGCs(mlw);
InitializeNewData(mlw);
RecalcCoords(mlw,(MultiListWidth(mlw) == 0),
(MultiListHeight(mlw) == 0));
} /* Initialize */
/*---------------------------------------------------------------------------*
Redisplay(mlw,event,rectangle_union)
This routine redraws the MultiList widget <mlw> based on the exposure
region requested in <event>.
*---------------------------------------------------------------------------*/
/* ARGSUSED */
static void Redisplay(mlw,event,rectangle_union)
XfwfMultiListWidget mlw;
XEvent *event;
Region rectangle_union;
{
GC shade_gc;
int i,x1,y1,w,h,x2,y2,row,col,ul_row,ul_col,lr_row,lr_col;
if (MultiListShadeSurplus(mlw))
shade_gc = MultiListGrayGC(mlw);
else
shade_gc = MultiListEraseGC(mlw);
if (event == NULL)
{
XFillRectangle(XtDisplay(mlw),XtWindow(mlw),shade_gc,0,0,
MultiListWidth(mlw),MultiListHeight(mlw));
for (i = 0; i < MultiListNumItems(mlw); i++) RedrawItem(mlw,i);
}
else
{
x1 = event->xexpose.x;
y1 = event->xexpose.y;
w = event->xexpose.width;
h = event->xexpose.height;
x2 = x1 + w;
y2 = y1 + h;
XFillRectangle(XtDisplay(mlw),XtWindow(mlw),
shade_gc,x1,y1,w,h);
PixelToRowColumn(mlw,x1,y1,&ul_row,&ul_col);
PixelToRowColumn(mlw,x2,y2,&lr_row,&lr_col);
lr_row = min(lr_row,MultiListNumRows(mlw) - 1);
lr_col = min(lr_col,MultiListNumCols(mlw) - 1);
for (col = ul_col; col <= lr_col; col++)
{
for (row = ul_row; row <= lr_row; row++)
{
RedrawRowColumn(mlw,row,col);
}
}
}
} /* End Redisplay */
/*---------------------------------------------------------------------------*
PreferredGeometry(mlw,parent_idea,our_idea)
This routine is called by the parent to tell us about the
parent's idea of our width and/or height. We then suggest
our preference through <our_idea> and return the information
to the parent.
*---------------------------------------------------------------------------*/
static XtGeometryResult PreferredGeometry(mlw,parent_idea,our_idea)
XfwfMultiListWidget mlw;
XtWidgetGeometry *parent_idea,*our_idea;
{
Dimension nw,nh;
Boolean parent_wants_w,parent_wants_h,we_changed_size;
parent_wants_w = (parent_idea->request_mode) & CWWidth;
parent_wants_h = (parent_idea->request_mode) & CWHeight;
if (parent_wants_w)
nw = parent_idea->width;
else
nw = MultiListWidth(mlw);
if (parent_wants_h)
nh = parent_idea->height;
else
nh = MultiListHeight(mlw);
our_idea->request_mode = 0;
if (!parent_wants_w && !parent_wants_h) return(XtGeometryYes);
we_changed_size = Layout(mlw,!parent_wants_w,!parent_wants_h,&nw,&nh);
our_idea->request_mode |= (CWWidth | CWHeight);
our_idea->width = nw;
our_idea->height = nh;
if (we_changed_size)
return(XtGeometryAlmost);
else
return(XtGeometryYes);
} /* End PreferredGeometry */
/*---------------------------------------------------------------------------*
Resize(mlw)
This function is called when the widget is being resized. It
recalculates the layout of the widget.
*---------------------------------------------------------------------------*/
static void Resize(mlw)
XfwfMultiListWidget mlw;
{
Dimension width,height;
width = MultiListWidth(mlw);
height = MultiListHeight(mlw);
Layout(mlw,False,False,&width,&height);
} /* End Resize */
/*---------------------------------------------------------------------------*
SetValues(cpl,rpl,npl)
This routine is called when the user is changing resources. <cpl>
is the current widget before the user's changes have been instituted.
<rpl> includes the original changes as requested by the user. <npl>
is the new resulting widget with the requested changes and with all
superclass changes already made.
*---------------------------------------------------------------------------*/
/*ARGSUSED*/
static Boolean SetValues(cpl,rpl,npl)
XfwfMultiListWidget cpl,rpl,npl;
{
Boolean redraw,recalc;
redraw = False;
recalc = False;
/* Graphic Context Changes */
if ((MultiListFG(cpl) != MultiListFG(npl)) ||
(MultiListBG(cpl) != MultiListBG(npl)) ||
(MultiListHighlightFG(cpl) != MultiListHighlightFG(npl)) ||
(MultiListHighlightBG(cpl) != MultiListHighlightBG(npl)) ||
(MultiListFont(cpl) != MultiListFont(npl)))
{
XtDestroyGC(MultiListEraseGC(cpl));
XtDestroyGC(MultiListDrawGC(cpl));
XtDestroyGC(MultiListHighlightForeGC(cpl));
XtDestroyGC(MultiListHighlightBackGC(cpl));
XtDestroyGC(MultiListGrayGC(cpl));
CreateNewGCs(npl);
redraw = True;
}
/* Changes That Require Redraw */
if ((MultiListSensitive(cpl) != MultiListSensitive(npl)) ||
(MultiListAncesSensitive(cpl) != MultiListAncesSensitive(npl)))
{
redraw = True;
}
/* Changes That Require Selection Changes */
if ((MultiListMaxSelectable(cpl) != MultiListMaxSelectable(npl)))
{
XtWarning("Dynamic change to maxSelectable unimplemented");
}
/* Changes That Require Data Initialization */
if ((MultiListList(cpl) != MultiListList(npl)) ||
(MultiListNumItems(cpl) != MultiListNumItems(npl)) ||
(MultiListSensitiveArray(cpl) != MultiListSensitiveArray(npl)))
{
DestroyOldData(cpl);
InitializeNewData(npl);
recalc = True;
redraw = True;
}
/* Changes That Require Recalculating Coordinates */
if ((MultiListWidth(cpl) != MultiListWidth(npl)) ||
(MultiListHeight(cpl) != MultiListHeight(npl)) ||
(MultiListColumnSpace(cpl) != MultiListColumnSpace(npl)) ||
(MultiListRowSpace(cpl) != MultiListRowSpace(npl)) ||
(MultiListDefaultCols(cpl) != MultiListDefaultCols(npl)) ||
((MultiListForceCols(cpl) != MultiListForceCols(npl)) &&
(MultiListNumCols(cpl) != MultiListNumCols(npl))) ||
(MultiListRowMajor(cpl) != MultiListRowMajor(npl)) ||
(MultiListFont(cpl) != MultiListFont(npl)) ||
(MultiListLongest(cpl) != MultiListLongest(npl)))
{
recalc = True;
redraw = True;
}
if (MultiListColWidth(cpl) != MultiListColWidth(npl))
{
XtWarning("columnWidth Resource Is Read-Only");
MultiListColWidth(npl) = MultiListColWidth(cpl);
}
if (MultiListRowHeight(cpl) != MultiListRowHeight(npl))
{
XtWarning("rowHeight Resource Is Read-Only");
MultiListRowHeight(npl) = MultiListRowHeight(cpl);
}
if (recalc)
{
RecalcCoords(npl,!MultiListWidth(npl),!MultiListHeight(npl));
}
if (!XtIsRealized((Widget)cpl))
return(False);
else
return(redraw);
} /* End SetValues */
/*===========================================================================*
D A T A I N I T I A L I Z A T I O N
*===========================================================================*/
/*---------------------------------------------------------------------------*
DestroyOldData(mlw)
This routine frees the internal list item array and sets the
item count to 0. This is normally done immediately before
calling InitializeNewData() to rebuild the internal item
array from new user specified arrays.
*---------------------------------------------------------------------------*/
static void DestroyOldData(mlw)
XfwfMultiListWidget mlw;
{
int i;
if (MultiListItemArray(mlw) != NULL) /* Free Old List */
{
for (i = 0; i < MultiListNumItems(mlw); i++)
{
free(MultiListItemString(MultiListNthItem(mlw,i)));
}
free((char *)MultiListItemArray(mlw));
}
if (MultiListSelArray(mlw) != NULL)
free((char *)MultiListSelArray(mlw));
MultiListSelArray(mlw) = NULL;
MultiListNumSelected(mlw) = 0;
MultiListItemArray(mlw) = NULL;
MultiListNumItems(mlw) = 0;
} /* End DestroyOldData */
/*---------------------------------------------------------------------------*
InitializeNewData(mlw)
This routine takes a MultiList widget <mlw> and builds up new
data item tables based on the string list and the sensitivity array.
All previous data should have already been freed. If the number
of items is 0, they will be counted, so the array must be NULL
terminated. If the list of strings is NULL, this is treated as
a list of 0 elements. If the sensitivity array is NULL, all
items are treated as sensitive.
When this routine is done, the string list and sensitivity array
fields will all be set to NULL, and the widget will not reference
them again.
*---------------------------------------------------------------------------*/
static void InitializeNewData(mlw)
XfwfMultiListWidget mlw;
{
int i;
XfwfMultiListItem *item;
String *string_array;
string_array = MultiListList(mlw);
if (string_array == NULL) MultiListNumItems(mlw) = 0;
if (MultiListNumItems(mlw) == 0) /* Count Elements */
{
if (string_array == NULL) /* No elements */
{
MultiListNumItems(mlw) = 0;
}
else
{
for (i = 0; string_array[i] != NULL; i++);
MultiListNumItems(mlw) = i;
}
}
if (MultiListNumItems(mlw) == 0) /* No Items */
{
MultiListItemArray(mlw) = NULL;
}
else
{
MultiListItemArray(mlw) =
TypeAlloc(XfwfMultiListItem,MultiListNumItems(mlw));
for (i = 0; i < MultiListNumItems(mlw); i++)
{
item = MultiListNthItem(mlw,i);
if (MultiListSensitiveArray(mlw) == NULL ||
(MultiListSensitiveArray(mlw)[i] == True))
{
MultiListItemSensitive(item) = True;
}
else
{
MultiListItemSensitive(item) = False;
}
MultiListItemString(item) = StrCopy(string_array[i]);
MultiListItemHighlighted(item) = False;
}
}
if (MultiListMaxSelectable(mlw) == 0)
{
MultiListSelArray(mlw) = NULL;
MultiListNumSelected(mlw) = 0;
}
else
{
MultiListSelArray(mlw) =
TypeAlloc(int,MultiListMaxSelectable(mlw));
MultiListNumSelected(mlw) = 0;
}
MultiListList(mlw) = NULL;
MultiListSensitiveArray(mlw) = NULL;
} /* End InitializeNewData */
/*---------------------------------------------------------------------------*
CreateNewGCs(mlw)
This routine takes a MultiList widget <mlw> and creates a new set of
graphic contexts for the widget based on the colors, fonts, etc.
in the widget. Any previous GCs are assumed to have already been
destroyed.
*---------------------------------------------------------------------------*/
static void CreateNewGCs(mlw)
XfwfMultiListWidget mlw;
{
XGCValues values;
unsigned int attribs;
attribs = GCForeground | GCBackground | GCFont;
values.foreground = MultiListFG(mlw);
values.background = MultiListBG(mlw);
values.font = MultiListFont(mlw)->fid;
MultiListDrawGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
values.foreground = MultiListBG(mlw);
MultiListEraseGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
values.foreground = MultiListHighlightFG(mlw);
values.background = MultiListHighlightBG(mlw);
MultiListHighlightForeGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
values.foreground = MultiListHighlightBG(mlw);
values.background = MultiListHighlightBG(mlw);
MultiListHighlightBackGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
attribs |= GCTile | GCFillStyle;
values.foreground = MultiListFG(mlw);
values.background = MultiListBG(mlw);
values.fill_style = FillTiled;
values.tile = XmuCreateStippledPixmap(XtScreen(mlw),MultiListFG(mlw),
MultiListBG(mlw),MultiListDepth(mlw));
MultiListGrayGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
} /* End CreateNewGCs */
/*===========================================================================*
L A Y O U T A N D G E O M E T R Y M A N A G E M E N T
*===========================================================================*/
/*---------------------------------------------------------------------------*
RecalcCoords(mlw,width_changeable,height_changeable)
This routine takes a MultiList widget <mlw> and recalculates
the coordinates, and item placement based on the current
width, height, and list of items. The <width_changeable> and
<height_changeable> indicate if the width and/or height can
be arbitrarily set.
This routine requires that the internal list data be initialized.
*---------------------------------------------------------------------------*/
#if NeedFunctionPrototypes
static void
RecalcCoords(XfwfMultiListWidget mlw,
Boolean width_changeable, Boolean height_changeable)
#else
static void
RecalcCoords(mlw,width_changeable,height_changeable)
XfwfMultiListWidget mlw;
Boolean width_changeable,height_changeable;
#endif
{
String str;
Dimension width,height;
register int i,text_width;
width = MultiListWidth(mlw);
height = MultiListHeight(mlw);
if (MultiListNumItems(mlw) != 0 && MultiListLongest(mlw) == 0)
{
for (i = 0; i < MultiListNumItems(mlw); i++)
{
str = MultiListItemString(MultiListNthItem(mlw,i));
text_width = FontW(MultiListFont(mlw),str);
MultiListLongest(mlw) = max(MultiListLongest(mlw),
text_width);
}
}
if (Layout(mlw,width_changeable,height_changeable,&width,&height))
{
NegotiateSizeChange(mlw,width,height);
}
} /* End RecalcCoords */
/*---------------------------------------------------------------------------*
NegotiateSizeChange(mlw,width,height)
This routine tries to change the MultiList widget <mlw> to have the
new size <width> by <height>. A negotiation will takes place
to try to change the size. The resulting size is not necessarily
the requested size.
*---------------------------------------------------------------------------*/
#if NeedFunctionPrototypes
static void
NegotiateSizeChange(XfwfMultiListWidget mlw, Dimension width, Dimension height)
#else
static void
NegotiateSizeChange(mlw,width,height)
XfwfMultiListWidget mlw;
Dimension width,height;
#endif
{
int attempt_number;
Boolean w_fixed,h_fixed;
Dimension *w_ptr,*h_ptr;
XtWidgetGeometry request,reply;
request.request_mode = CWWidth | CWHeight;
request.width = width;
request.height = height;
for (attempt_number = 1; attempt_number <= 3; attempt_number++)
{
switch (XtMakeGeometryRequest((Widget)mlw,&request,&reply))
{
case XtGeometryYes:
case XtGeometryNo:
return;
case XtGeometryAlmost:
switch (attempt_number)
{
case 1:
w_fixed = (request.width != reply.width);
h_fixed = (request.height != reply.height);
w_ptr = &(reply.width);
h_ptr = &(reply.height);
Layout(mlw,!w_fixed,!h_fixed,w_ptr,h_ptr);
break;
case 2:
w_ptr = &(reply.width);
h_ptr = &(reply.height);
Layout(mlw,False,False,w_ptr,h_ptr);
break;
case 3:
return;
}
break;
default:
XtAppWarning(XtWidgetToApplicationContext((Widget)mlw),
"MultiList Widget: Unknown geometry return.");
break;
}
request = reply;
}
} /* End NegotiateSizeChange */
/*---------------------------------------------------------------------------*
Boolean Layout(mlw,w_changeable,h_changeable,w_ptr,h_ptr)
This routine tries to generate a layout for the MultiList widget
<mlw>. The Layout routine is free to arbitrarily set the width
or height if the corresponding variables <w_changeable> and
<h_changeable> are set True. Otherwise the original width or
height in <w_ptr> and <h_ptr> are used as fixed values. The
resulting new width and height are stored back through the
<w_ptr> and <h_ptr> pointers. False is returned if no size
change was done, True is returned otherwise.
*---------------------------------------------------------------------------*/
#if NeedFunctionPrototypes
static Boolean
Layout(XfwfMultiListWidget mlw, Boolean w_changeable, Boolean h_changeable,
Dimension *w_ptr, Dimension *h_ptr)
#else
static Boolean
Layout(mlw,w_changeable,h_changeable,w_ptr,h_ptr)
XfwfMultiListWidget mlw;
Boolean w_changeable,h_changeable;
Dimension *w_ptr,*h_ptr;
#endif
{
Boolean size_changed = False;
/*
* If force columns is set, then always use the number
* of columns specified by default_cols.
*/
MultiListColWidth(mlw) = MultiListLongest(mlw) +
MultiListColumnSpace(mlw);
MultiListRowHeight(mlw) = FontH(MultiListFont(mlw)) +
MultiListRowSpace(mlw);
if (MultiListForceCols(mlw))
{
MultiListNumCols(mlw) = max(MultiListDefaultCols(mlw),1);
if (MultiListNumItems(mlw) == 0)
MultiListNumRows(mlw) = 1;
else
MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
MultiListNumCols(mlw) + 1;
if (w_changeable)
{
*w_ptr = MultiListNumCols(mlw) *
MultiListColWidth(mlw);
size_changed = True;
}
else
{
MultiListColWidth(mlw) = *w_ptr /
(Dimension)MultiListNumCols(mlw);
}
if (h_changeable)
{
*h_ptr = MultiListNumRows(mlw) *
MultiListRowHeight(mlw);
size_changed = True;
}
return(size_changed);
}
/*
* If both width and height are free to change then use
* default_cols to determine the number of columns and set
* the new width and height to just fit the window.
*/
if (w_changeable && h_changeable)
{
MultiListNumCols(mlw) = max(MultiListDefaultCols(mlw),1);
if (MultiListNumItems(mlw) == 0)
MultiListNumRows(mlw) = 1;
else
MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
MultiListNumCols(mlw) + 1;
*w_ptr = MultiListNumCols(mlw) * MultiListColWidth(mlw);
*h_ptr = MultiListNumRows(mlw) * MultiListRowHeight(mlw);
return(True);
}
/*
* If the width is fixed then use it to determine the
* number of columns. If the height is free to move
* (width still fixed) then resize the height of the
* widget to fit the current MultiList exactly.
*/
if (!w_changeable)
{
MultiListNumCols(mlw) = *w_ptr / MultiListColWidth(mlw);
MultiListNumCols(mlw) = max(MultiListNumCols(mlw),1);
MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
MultiListNumCols(mlw) + 1;
MultiListColWidth(mlw) = *w_ptr / (Dimension)MultiListNumCols(mlw);
if (h_changeable)
{
*h_ptr = MultiListNumRows(mlw) * MultiListRowHeight(mlw);
size_changed = True;
}
return(size_changed);
}
/*
* The last case is xfree and !yfree we use the height to
* determine the number of rows and then set the width to
* just fit the resulting number of columns.
*/
MultiListNumRows(mlw) = *h_ptr / MultiListRowHeight(mlw);
MultiListNumRows(mlw) = max(MultiListNumRows(mlw),1);
MultiListNumCols(mlw) = (MultiListNumItems(mlw) - 1) /
MultiListNumRows(mlw) + 1;
*w_ptr = MultiListNumCols(mlw) * MultiListColWidth(mlw);
return(True);
} /* End Layout */
/*===========================================================================*
R E D R A W R O U T I N E S
*===========================================================================*/
/*---------------------------------------------------------------------------*
RedrawAll(mlw)
This routine simple calls Redisplay to redraw the entire
MultiList widget <mlw>.
*---------------------------------------------------------------------------*/
static void RedrawAll(mlw)
XfwfMultiListWidget mlw;
{
Redisplay(mlw,NULL,NULL);
} /* End RedrawAll */
/*---------------------------------------------------------------------------*
RedrawItem(mlw,item_index)