-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tabs.c
3618 lines (3022 loc) · 97.7 KB
/
Tabs.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: Tabs.c
* Module : Xg Widget Set
* SCCS ID : 1.5 07 Nov 1996
*
* Description:
* This is the source file for the Tabs widget.
*
*
*
* Changes
*
* By Date Description
* ------ -------------- ----------------------------------------------
* GMM 06/14/95 Original file
* GMM 07/26/95 Now keep pixmaps of vertical tab labels,
* this speeds things up substantially
*
*
* ---FHDR--- */
#include <ctype.h>
/*
* These includes are needed to describe the widget
*/
#include <Xm/XmP.h>
#include "TabsP.h"
/*
* We include this for rotated text
*/
#include "x_rotate.h"
#if NeedFunctionPrototypes
# undef PROTO
# define PROTO(f, p) f p
#else
# undef PROTO
# define PROTO(f, p) f()
#endif
/*
* Ratio of height to slant for slanted shape
*/
#define TAB_SKEW 3
/*
* Length of corner for chamferred shape
*/
#define SLANT 4 /* Length of corner for chamferred shape */
#define SHADOW_OFFSET(s) ((s < 1) ? 1 : s)
/*
* Various macros used within
*/
#define RIGHT_TABS(tabw) (tabw->tabs.numtabs - tabw->tabs.curtab - 1)
#define TAB_SHAPE(tabw) (tabw->tabs.tab_shape)
#define TAB_LOCATION(tabw) (tabw->tabs.tab_location)
#define IS_HORIZ_TAB(tabw) (TAB_LOCATION(tabw) == XgTOP || \
TAB_LOCATION(tabw) == XgBOTTOM)
#define HEIGHT(w) w->core.height
#define WIDTH(w) w->core.width
#define TOP_SHADOW_GC(tabw) (tabw->tabs.topgc)
#define BOTTOM_SHADOW_GC(tabw) (tabw->tabs.bottomgc)
#define HIGHLIGHT_THICKNESS(tabw) (tabw->primitive.highlight_thickness)
/*
* Method prototypes
*/
PROTO(static void ClassInitialize, ( void ) );
PROTO(static void Initialize, ( XgTabsWidget,XgTabsWidget,ArgList,Cardinal *));
PROTO(static void Realize, ( Widget tabw, XtValueMask *mask,
XSetWindowAttributes *attributes ) );
PROTO(static XtGeometryResult QueryGeometry, (
XgTabsWidget, XtWidgetGeometry*, XtWidgetGeometry * ) );
PROTO(static Boolean SetValues,(XgTabsWidget, XgTabsWidget, XgTabsWidget));
PROTO(static void GetValuesHook, (
XgTabsWidget w, ArgList args, Cardinal *num_args ) );
PROTO(static void Resize, ( XgTabsWidget));
PROTO(static void Destroy, ( XgTabsWidget ));
PROTO(static void Redraw, ( XgTabsWidget, XEvent *, Region ));
/*
* Prototypes for the tab drawing functions
*/
PROTO(static void DrawLeftTab, ( XgTabsWidget, Region, int ));
PROTO(static void DrawRightTab, ( XgTabsWidget, Region, int ));
PROTO(static void DrawCurrentTab, ( XgTabsWidget, Region ));
PROTO(static void Highlight, ( XgTabsWidget ));
PROTO(static void UnHighlight, ( XgTabsWidget ));
PROTO(static void HorizCurrentChamferred, (XgTabsWidget, Region, Boolean));
PROTO(static void HorizRightChamferred, (XgTabsWidget, Region, int, Boolean));
PROTO(static void HorizLeftChamferred, (XgTabsWidget, Region, int, Boolean));
PROTO(static void HorizCurrentSlant, (XgTabsWidget, Region, Boolean));
PROTO(static void HorizRightSlant, (XgTabsWidget, Region, int, Boolean));
PROTO(static void HorizLeftSlant, (XgTabsWidget, Region, int, Boolean));
PROTO(static void VertCurrentChamferred, (XgTabsWidget, Region, Boolean));
PROTO(static void VertBottomChamferred, (XgTabsWidget, Region, int, Boolean));
PROTO(static void VertTopChamferred, (XgTabsWidget, Region, int, Boolean));
PROTO(static void VertCurrentSlant, (XgTabsWidget, Region, Boolean));
PROTO(static void VertBottomSlant, (XgTabsWidget, Region, int, Boolean));
PROTO(static void VertTopSlant, (XgTabsWidget, Region, int, Boolean));
PROTO(static void DrawHorizText, ( XgTabsWidget, int, int, int, int,
unsigned long, Boolean ) );
PROTO(static void DrawVertText, ( XgTabsWidget, int, int, int, int,
unsigned long, unsigned long, Region, Boolean ) );
/*
* Prototypes for utility functions
*/
PROTO(static void CreateTopGc, ( XgTabsWidget));
PROTO(static void CreateBottomGc, ( XgTabsWidget));
PROTO(static void CreateTextGc, ( XgTabsWidget));
PROTO(static void CreateFillGc, ( XgTabsWidget));
PROTO(static void CopyBg, ( XgTabsWidget,int ,XrmValue *));
PROTO(static int GetMainTabWidth, ( XgTabsWidget, int ) );
PROTO(static void GetPreferredSize, ( XgTabsWidget, int *, int * ) );
PROTO(static void SetMainTabWidth, ( XgTabsWidget ) );
PROTO(static void SetTabs, ( XgTabsWidget, int ) );
PROTO(static XFontStruct *GetFontStruct, ( XmFontList ) );
PROTO(static void CreatePixmapArray, ( XgTabsWidget ) );
PROTO(static void FreePixmapArray, ( XgTabsWidget ) );
/*
* Prototypes for the resource convertors
*/
PROTO(static Boolean cvtStringToStringArray, (
Display *display,
XrmValuePtr args,
Cardinal *num_args,
XrmValuePtr from,
XrmValuePtr to,
XtPointer *converter_data
));
PROTO(static Boolean cvtStringToTabShape, (
Display *display,
XrmValuePtr args,
Cardinal *num_args,
XrmValuePtr from,
XrmValuePtr to,
XtPointer *converter_data
));
PROTO(static void freeStringArray, ( String * ) );
/*
* Define things for the widgets actions
*/
PROTO(static void Activate, ( XgTabsWidget, XEvent*, String*, Cardinal* ));
PROTO(static void TraverseTabs, ( XgTabsWidget, XEvent*, String*, Cardinal* ));
PROTO(static void ProcessTraversal, (XgTabsWidget,XEvent*,String*,Cardinal*));
static char defaultTranslations[] =
"<FocusIn>: ProcessTraversal(in) \n\
<FocusOut>: ProcessTraversal(out) \n\
<Btn1Down>: Activate(mouse) \n\
<Key>space: Activate(space) \n\
<Key>osfUp: TraverseTabs(prev) \n\
<Key>osfDown: TraverseTabs(next) \n\
<Key>osfRight: TraverseTabs(next) \n\
<Key>osfLeft: TraverseTabs(prev) \n\
~Shift<Key>Tab: ProcessTraversal(next)\n\
Shift<Key>Tab: ProcessTraversal(prev) ";
static XtActionsRec actionsList[] = {
{ "Activate", (XtActionProc)Activate },
{ "TraverseTabs", (XtActionProc)TraverseTabs },
{ "ProcessTraversal", (XtActionProc)ProcessTraversal }};
/*
* Define the resource table
*/
static XtResource resources[] = {
{
XgNtabCount, XgCTabCount, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.numtabs),
XtRImmediate, (XtPointer)1
},
{
XgNcurrentTab, XgCCurrentTab, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.curtab),
XtRImmediate, (XtPointer)0
},
{
XgNfocusTab, XgCFocusTab, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.focus_tab),
XtRImmediate, (XtPointer)0
},
{
XgNtabLabels, XgCTabLabels, XmRStringArray,
sizeof(((XgTabsRec*)NULL)->tabs.tablabels),
XtOffsetOf(XgTabsRec,tabs.tablabels),
XtRImmediate, (XtPointer)NULL
},
{
XgNtabShape, XgCShape, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.tab_shape),
XtRImmediate, (XtPointer)XgSLANTED
},
{
XgNtabLocation, XgCLocation, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.tab_location),
XtRImmediate, (XtPointer)XgTOP
},
{
XgNtabWidgets, XgCTabWidgets, XmRWidgetList, sizeof(Widget *),
XtOffsetOf(XgTabsRec,tabs.tabwidgets),
XtRImmediate, (XtPointer)NULL
},
{
XgNautoUnmanage, XmCAutoUnmanage, XmRBoolean, sizeof(Boolean),
XtOffsetOf(XgTabsRec,tabs.auto_unmanage),
XtRImmediate, (XtPointer)False
},
{
XgNtabColor, XmCBackground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgTabsRec,tabs.tabcolor),
XtRCallProc, (XtPointer)CopyBg
},
{
XgNselectedTabColor, XmCBackground, XmRPixel, sizeof(Pixel),
XtOffsetOf(XgTabsRec,tabs.selected_color),
XtRCallProc, (XtPointer)CopyBg
},
{
XgNfontList, XmCFontList, XmRFontList,
sizeof(((XgTabsRec*)NULL)->tabs.font_list),
XtOffsetOf(XgTabsRec,tabs.font_list),
XtRString, (XtPointer)XtDefaultFont
},
{
XgNactivateCallback, XmCCallback, XmRCallback,
sizeof(((XgTabsRec*)NULL)->tabs.activateCallback),
XtOffsetOf(XgTabsRec,tabs.activateCallback),
XtRImmediate, (XtPointer)NULL
},
{
XgNlabelMargin, XmCMargin, XmRInt, sizeof(int),
XtOffsetOf(XgTabsRec,tabs.textmargin),
XtRImmediate, (XtPointer)3
},
{
XgNhighlightThickness, XmCHighlightThickness,
XmRDimension, sizeof(Dimension),
XtOffsetOf(XgTabsRec, primitive.highlight_thickness),
XtRImmediate, (XtPointer)1
},
{
XgNnavigationType, XmCNavigationType,
XmRNavigationType, sizeof(XmNavigationType),
XtOffsetOf(XgTabsRec, primitive.navigation_type),
XtRImmediate, (XtPointer)XmTAB_GROUP
}
};
/*
* Define the class record for the widget
*/
XgTabsClassRec tabsClassRec = {
{
/*
* core_class part
*/
(WidgetClass) &xmPrimitiveClassRec, /* superclass */
"XgTabs", /* class_name */
sizeof(XgTabsRec), /* widget_size */
ClassInitialize, /* ClassInitialize */
NULL, /* class_part_initialize*/
FALSE, /* class_inited */
(XtInitProc)Initialize, /* initialize */
NULL, /* initialize_hook */
Realize, /* realize */
actionsList, /* actions */
XtNumber(actionsList), /* num_actions */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
XtExposeCompressMultiple, /* compress_exposure */
False, /* compress_enterleave */
False, /* visible_interest */
(XtWidgetProc)Destroy, /* destroy */
(XtWidgetProc)Resize, /* resize */
(XtExposeProc)Redraw, /* expose */
(XtSetValuesFunc)SetValues, /* set_values */
NULL, /* set_values_hook */
XtInheritSetValuesAlmost, /* set_values_almost */
(XtArgsProc)GetValuesHook, /* get_values_hook */
NULL, /* accept_focus */
XtVersion, /* version */
NULL, /* callback_private */
defaultTranslations, /* tm_table */
(XtGeometryHandler)QueryGeometry, /* query_geometry */
XtInheritDisplayAccelerator, /* display_accelerator */
NULL /* extension */
},
{
/*
* primitive_class part
*/
NULL, /* border_highlight */
NULL, /* border_unhighlight */
NULL, /* translations */
NULL, /* arm_and_activate */
0, /* syn_resources */
0, /* num_syn_resources */
NULL, /* primitive_extension */
},
{
/*
* tabs_class part
*/
0
},
};
WidgetClass xgTabsWidgetClass = (WidgetClass) &tabsClassRec;
static void
ClassInitialize()
{
/*
* Add a type converter for the TabShape type
*/
XtSetTypeConverter(XmRString, XgRTabShapeType,
(XtTypeConverter)cvtStringToTabShape, NULL, 0,
XtCacheAll, NULL);
/*
* And one for string arrays (tab labels)
*/
XtSetTypeConverter(XmRString, XmRStringArray, cvtStringToStringArray,
NULL, 0, XtCacheNone, (XtDestructor)freeStringArray);
}
static void
Initialize(request, tabw, args, num_args)
XgTabsWidget request;
XgTabsWidget tabw;
ArgList args;
Cardinal *num_args;
{
String *tabstrings;
int i, h, w;
tabw->tabs.i_have_focus = False;
/*
* Make sure the focus and current tab are within range
*/
if ( tabw->tabs.focus_tab >= tabw->tabs.numtabs )
tabw->tabs.focus_tab = 0;
if ( tabw->tabs.curtab >= tabw->tabs.numtabs )
tabw->tabs.curtab = 0;
/*
* Create the GCs for drawing the tabs
*/
tabw->tabs.topgc = tabw->tabs.bottomgc =
tabw->tabs.textgc = tabw->tabs.fillgc = None;
CreateTopGc(tabw);
CreateBottomGc(tabw);
CreateTextGc(tabw);
CreateFillGc(tabw);
/*
* Get a local copy of the tab label strings
*/
if ( tabw->tabs.tablabels != NULL )
{
Boolean last_one = False;
tabstrings = (String*) XtMalloc((tabw->tabs.numtabs + 1) *
sizeof(*tabstrings));
for ( i = 0; i < tabw->tabs.numtabs; i++ )
{
if ( !last_one )
if ( tabw->tabs.tablabels[i] == NULL )
last_one = True;
if ( last_one )
tabstrings[i] = NULL;
else
tabstrings[i] = XtNewString(tabw->tabs.tablabels[i]);
}
tabstrings[tabw->tabs.numtabs] = NULL;
tabw->tabs.labels = tabstrings;
}
else
tabw->tabs.labels = NULL;
/*
* If the tabs are vertical allocate an array to hold the label pixmaps
*/
tabw->tabs.label_pixmaps = NULL;
CreatePixmapArray(tabw);
/*
* Set dimensions to something acceptable
*/
GetPreferredSize(tabw, &w, &h);
if ( WIDTH(tabw) < w )
WIDTH(tabw) = w;
if ( HEIGHT(tabw) < h )
HEIGHT(tabw) = h;
SetMainTabWidth(tabw);
}
static void
Realize(tabw,mask,attributes)
Widget tabw;
XtValueMask * mask;
XSetWindowAttributes *attributes;
{
xmPrimitiveClassRec.core_class.realize(tabw, mask, attributes);
XClearWindow(XtDisplay(tabw), XtWindow(tabw));
}
static XtGeometryResult
QueryGeometry(tabw, proposed, desired)
XgTabsWidget tabw;
XtWidgetGeometry *proposed, *desired;
{
#define Set(bit) (proposed->request_mode & bit)
int width;
int height;
/*
* Get the size we'd like to be
*/
GetPreferredSize(tabw, &width, &height);
desired->request_mode = CWWidth | CWHeight;
desired->width = width;
desired->height = height;
desired->request_mode = CWWidth | CWHeight;
if ( Set(CWWidth) && proposed->width == desired->width &&
Set(CWHeight) && proposed->height == desired->height )
return XtGeometryYes;
if ( desired->width == WIDTH(tabw) &&
desired->height == HEIGHT(tabw) )
return XtGeometryNo;
return XtGeometryAlmost;
#undef Set
}
static void
Destroy(tabw)
XgTabsWidget tabw;
{
int i;
/*
* Free the local copy of the labels
*/
if ( tabw->tabs.labels != NULL )
{
for ( i = 0; tabw->tabs.labels[i] != NULL; i++ )
XtFree(tabw->tabs.labels[i]);
XtFree((XtPointer)tabw->tabs.labels);
}
/*
* Free the array of label pixmaps
*/
FreePixmapArray(tabw);
/*
* Destroy the GC created for this widget
*/
if ( tabw->tabs.topgc != NULL )
XtReleaseGC((Widget)tabw, tabw->tabs.topgc);
if ( tabw->tabs.bottomgc != NULL )
XtReleaseGC((Widget)tabw, tabw->tabs.bottomgc);
if (tabw->tabs.textgc != NULL)
XFreeGC(XtDisplay((Widget)tabw), tabw->tabs.textgc);
if (tabw->tabs.fillgc != NULL)
XFreeGC(XtDisplay((Widget)tabw), tabw->tabs.fillgc);
}
static void
Activate(tabw, event, params, num_params)
XgTabsWidget tabw;
XEvent *event;
String *params;
Cardinal *num_params;
{
Dimension width, slant, height;
int old_tab, i, current_tab = -1, righttabs = RIGHT_TABS(tabw);
XgTabsCallbackStruct cbs;
cbs.doit = True;
cbs.old_tab = old_tab = tabw->tabs.curtab;
/*
* Was a tab selected with the Space bar
*/
if ( params[0][0] == 's' )
{
cbs.tab = current_tab = tabw->tabs.focus_tab;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
if ( tabw->tabs.curtab == tabw->tabs.focus_tab )
cbs.doit = False;
XtCallCallbackList((Widget)tabw, tabw->tabs.activateCallback,
(XtPointer)&cbs);
if ( cbs.doit == True )
SetTabs(tabw, current_tab);
return;
}
/*
* Make sure this widget has the keyboard focus
*/
if ( tabw->tabs.i_have_focus == False )
XmProcessTraversal((Widget)tabw, XmTRAVERSE_CURRENT);
/*
* See which tab was selected, we have 2 methods here, one for horizontal
* and one for vertical tabs
*/
if ( IS_HORIZ_TAB(tabw) )
{
Dimension ww, w1;
if ( TAB_SHAPE(tabw) == XgSLANTED )
slant = (HEIGHT(tabw) - event->xbutton.y) / TAB_SKEW;
else
slant = 0;
if ( tabw->tabs.numtabs > 1 )
{
int max_width;
max_width = tabw->tabs.main_tab_width -
(HEIGHT(tabw) * 2 / TAB_SKEW *
((TAB_SHAPE(tabw) == XgSLANTED) ? 1 : 0));
width = (WIDTH(tabw) - tabw->tabs.main_tab_width) /
(tabw->tabs.numtabs - 1);
if ( width > max_width )
width = max_width;
}
else
width = 0;
w1 = tabw->tabs.curtab * width;
if ( event->xbutton.x < w1 + slant)
{
/*
* Click above the main tab
*/
if (tabw->tabs.curtab != 0)
{
ww = width + slant;
for ( i = tabw->tabs.curtab ; event->xbutton.x >= ww;
i--, ww += width);
cbs.tab = current_tab = tabw->tabs.curtab - i;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
}
}
else if ( event->xbutton.x < w1 + tabw->tabs.main_tab_width - slant )
{
/*
* Click on main tab
*/
cbs.tab = current_tab = tabw->tabs.curtab;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
cbs.doit = False;
}
else if ( event->xbutton.x < (tabw->tabs.curtab) * width +
tabw->tabs.main_tab_width + width * righttabs )
{
/*
* Click below the main tab
*/
if ( righttabs != 0 )
{
ww = w1 + tabw->tabs.main_tab_width + width;
for ( i = tabw->tabs.curtab + 1; event->xbutton.x > ww;
i++, ww += width );
cbs.tab = current_tab = i;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
}
}
}
else
{
Dimension hh, h1;
if ( TAB_SHAPE(tabw) == XgSLANTED )
slant = (WIDTH(tabw) - event->xbutton.x) / TAB_SKEW;
else
slant = 0;
if ( tabw->tabs.numtabs > 1 )
{
int max_height;
max_height = tabw->tabs.main_tab_width -
(WIDTH(tabw) * 2 / TAB_SKEW *
((TAB_SHAPE(tabw) == XgSLANTED) ? 1 : 0));
height= (HEIGHT(tabw) - tabw->tabs.main_tab_width) /
(tabw->tabs.numtabs - 1);
if ( height > max_height )
height = max_height;
}
else
height = 0;
h1 = tabw->tabs.curtab * height;
if ( event->xbutton.y < h1 + slant)
{
/*
* Click left of main tab
*/
if (tabw->tabs.curtab != 0)
{
hh = height + slant;
for ( i = tabw->tabs.curtab ; event->xbutton.y >= hh;
i--, hh += height );
cbs.tab = current_tab = tabw->tabs.curtab - i;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
}
}
else if ( event->xbutton.y < h1 + tabw->tabs.main_tab_width - slant )
{
/*
* Click on main tab
*/
cbs.tab = current_tab = tabw->tabs.curtab;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
cbs.doit = False;
}
else if ( event->xbutton.y < (tabw->tabs.curtab) * height +
tabw->tabs.main_tab_width + height * righttabs )
{
/*
* Click right of main tab
*/
if ( righttabs != 0 )
{
hh = h1 + tabw->tabs.main_tab_width + height;
for ( i = tabw->tabs.curtab + 1; event->xbutton.y > hh;
i++, hh += height );
cbs.tab = current_tab = i;
cbs.tab_label = tabw->tabs.labels[cbs.tab];
}
}
}
/*
* Set the focus tab, draw the tabs with the selected one on top and
* then call the callbacks
*/
if ( current_tab != -1 )
{
if ( tabw->tabs.focus_tab != current_tab )
{
UnHighlight(tabw);
tabw->tabs.focus_tab = current_tab;
if ( cbs.doit == False )
Highlight(tabw);
}
if ( cbs.doit == True )
SetTabs(tabw, current_tab);
XtCallCallbackList((Widget)tabw, tabw->tabs.activateCallback,
(XtPointer)&cbs);
/*
* The client did not want this new tab, so redraw the old one
*/
if ( cbs.doit == False && (old_tab != current_tab) )
SetTabs(tabw, old_tab);
}
}
static void
SetTabs(tabw, current_tab)
XgTabsWidget tabw;
int current_tab;
{
int i;
int old_curtab = tabw->tabs.curtab;
if ( current_tab == tabw->tabs.curtab )
return;
tabw->tabs.curtab = current_tab;
/*
* Only draw the tabs that have been exposed and the one
* on each side of the new top tab
*/
if ( old_curtab < current_tab )
for ( i = old_curtab; i < current_tab; i++)
DrawLeftTab(tabw, NULL, i);
else
for ( i = old_curtab; i > current_tab; i-- )
DrawRightTab(tabw, NULL, i);
/*
* Draw the new current tab
*/
DrawCurrentTab(tabw, NULL);
/*
* Manage and raise the associated widget if there is one
*/
if ( tabw->tabs.tabwidgets != NULL )
{
Widget w = tabw->tabs.tabwidgets[current_tab];
if ( w != NULL )
{
Window win = XtWindow(w);
if ( win != None )
{
/*
* Manage the widget if it's not
*/
if ( !XtIsManaged(w) )
XtManageChild(w);
/*
* Raise its window
*/
XRaiseWindow(XtDisplay(w), win);
}
}
/*
* If auto unmanage is set then unmanage the last current widget
*/
if ( tabw->tabs.auto_unmanage == True && old_curtab >= 0 &&
old_curtab < tabw->tabs.numtabs )
{
w = tabw->tabs.tabwidgets[old_curtab];
if ( w != NULL )
XtUnmanageChild(w);
}
}
}
static void
GetValuesHook(w, args, num_args)
XgTabsWidget w;
ArgList args;
Cardinal *num_args;
{
Cardinal i;
/*
*
*/
for (i = 0; i < *num_args; i++)
{
if ( strcmp(args[i].name, XgNtabLabels) == 0 )
{
XtSetArg(args[i], XgNtabLabels, w->tabs.labels);
}
}
}
static Boolean
SetValues(old, request, new)
XgTabsWidget old;
XgTabsWidget request;
XgTabsWidget new;
{
Boolean redraw = False;
#define NOT_EQUAL(field) (old->field != new->field)
if ( NOT_EQUAL(core.background_pixel) ||
NOT_EQUAL(core.background_pixmap) ||
NOT_EQUAL(primitive.shadow_thickness) )
{
CreateTopGc(new);
CreateBottomGc(new);
redraw = True;
}
if ( NOT_EQUAL(primitive.highlight_color) )
{
redraw = True;
}
if ( NOT_EQUAL(primitive.foreground) || NOT_EQUAL(tabs.font_list) ||
NOT_EQUAL(primitive.highlight_thickness) )
{
CreateTextGc(new);
redraw = True;
}
if ( NOT_EQUAL(tabs.textmargin) )
redraw = True;
if ( NOT_EQUAL(tabs.tabcolor) )
{
CreateFillGc(new);
redraw = True;
}
/*
* if the labels have changed then get our local copy
*/
if ( NOT_EQUAL(tabs.tablabels) )
{
int i;
String *strings;
if ( old->tabs.labels != NULL )
{
for ( i = 0; old->tabs.labels[i] != NULL; i++ )
XtFree(old->tabs.labels[i]);
XtFree((XtPointer)old->tabs.labels);
}
if ( new->tabs.tablabels != NULL )
{
Boolean last_one = False;
strings = (String*) XtMalloc((new->tabs.numtabs + 1) *
sizeof(String));
for ( i = 0; i < new->tabs.numtabs; i++ )
{
if ( !last_one )
if ( new->tabs.tablabels[i] == NULL )
last_one = True;
if ( last_one )
strings[i] = NULL;
else
strings[i] = XtNewString(new->tabs.tablabels[i]);
}
strings[new->tabs.numtabs] = NULL;
new->tabs.labels = strings;
new->tabs.tablabels = NULL;
}
else
new->tabs.labels = NULL;
redraw = True;
}
if ( NOT_EQUAL(tabs.tab_shape) || NOT_EQUAL(tabs.tab_location) )
redraw = True;
if ( NOT_EQUAL(tabs.numtabs) || NOT_EQUAL(tabs.curtab) ||
NOT_EQUAL(tabs.focus_tab) )
redraw = True;
/*
* Make sure the focus and current tab are within range
*/
if ( new->tabs.focus_tab >= new->tabs.numtabs )
{
XtWarning( "Focus Tab not valid, forcing to 0");
new->tabs.focus_tab = 0;
}
if ( new->tabs.curtab >= new->tabs.numtabs )
{
XtWarning( "Current Tab not valid, forcing to 0");
new->tabs.curtab = 0;
}
/*
* If we need to redraw recompute the current tab width, and get the
* array of label pixmaps
*/
if ( redraw )
{
SetMainTabWidth(new);
FreePixmapArray(old);
new->tabs.label_pixmaps = NULL;
CreatePixmapArray(new);
}
return redraw;
#undef NOT_EQUAL
}
static void