-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtkPanedWindow.c
More file actions
3184 lines (2833 loc) · 87.4 KB
/
Copy pathtkPanedWindow.c
File metadata and controls
3184 lines (2833 loc) · 87.4 KB
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
/*
* tkPanedWindow.c --
*
* This module implements "paned window" widgets that are object based. A
* "paned window" is a widget that manages the geometry for some number
* of other widgets, placing a movable "sash" between them, which can be
* used to alter the relative sizes of adjacent widgets.
*
* Copyright © 1997 Sun Microsystems, Inc.
* Copyright © 2000 Ajuba Solutions.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkInt.h"
#include "default.h"
/*
* Flag values for "sticky"ness. The 16 combinations subsume the packer's
* notion of anchor and fill.
*
* STICK_NORTH This window sticks to the top of its cavity.
* STICK_EAST This window sticks to the right edge of its cavity.
* STICK_SOUTH This window sticks to the bottom of its cavity.
* STICK_WEST This window sticks to the left edge of its cavity.
*/
#define STICK_NORTH 1
#define STICK_EAST 2
#define STICK_SOUTH 4
#define STICK_WEST 8
/*
* The following table defines the legal values for the -orient option.
*/
static const char *const orientStrings[] = {
"horizontal", "vertical", NULL
};
enum orient { ORIENT_HORIZONTAL, ORIENT_VERTICAL };
/*
* The following table defines the legal values for the -stretch option.
*/
static const char *const stretchStrings[] = {
"always", "first", "last", "middle", "never", NULL
};
enum stretch {
STRETCH_ALWAYS, /* Always give extra space to this pane. */
STRETCH_FIRST, /* Give extra space to pane if it is first. */
STRETCH_LAST, /* Give extra space to pane if it is last. */
STRETCH_MIDDLE, /* Give extra space to pane only if it is
* neither first nor last. */
STRETCH_NEVER /* Never give extra space to this pane. */
};
/*
* Codify the stretchiness rule in one place.
*/
#define IsStretchable(stretch,index,first,last) \
(((stretch) == STRETCH_ALWAYS) || \
((stretch) == STRETCH_FIRST && (index) == (first)) || \
((stretch) == STRETCH_LAST && (index) == (last)) || \
((stretch) == STRETCH_MIDDLE && (index) != (first) && (index) != (last)))
typedef struct {
Tk_OptionTable pwOptions; /* Token for paned window option table. */
Tk_OptionTable paneOpts; /* Token for pane cget option table. */
} OptionTables;
/*
* One structure of the following type is kept for each window
* managed by a paned window widget.
*/
typedef struct Pane {
Tk_Window tkwin; /* Window being managed. */
Tcl_Obj *minSizeObj; /* Minimum size of this pane, on the relevant
* axis, in pixels. */
Tcl_Obj *padXObj; /* Additional padding requested for pane, in
* the x dimension. */
Tcl_Obj *padYObj; /* Additional padding requested for pane, in
* the y dimension. */
Tcl_Obj *widthObj, *heightObj;
/* Tcl_Obj rep's of pane width/height, to
* allow for null values. */
int sticky; /* Sticky string. */
int x, y; /* Coordinates of the widget. */
int paneWidth, paneHeight; /* Pane dimensions (may be different from
* pane width/height). */
int sashx, sashy; /* Coordinates of the sash of the right or
* bottom of this pane. */
int markx, marky; /* Coordinates of the last mark set for the
* sash. */
int handlex, handley; /* Coordinates of the sash handle. */
enum stretch stretch; /* Controls how pane grows/shrinks */
int hide; /* Controls visibility of pane */
struct PanedWindow *containerPtr;
/* Paned window managing the window. */
Tk_Window after; /* Placeholder for parsing options. */
Tk_Window before; /* Placeholder for parsing options. */
int width; /* Pane width. Same as widthObj, but updatable */
int height; /* Pane height. Same as heightObj, but updatable */
} Pane;
/*
* A data structure of the following type is kept for each paned window widget
* managed by this file:
*/
typedef struct PanedWindow {
Tk_Window tkwin; /* Window that embodies the paned window. */
Tk_Window proxywin; /* Window for the resizing proxy. */
Display *display; /* X's token for the window's display. */
Tcl_Interp *interp; /* Interpreter associated with widget. */
Tcl_Command widgetCmd; /* Token for square's widget command. */
Tk_OptionTable optionTable; /* Token representing the configuration
* specifications. */
Tk_OptionTable paneOpts; /* Token for pane cget table. */
Tk_3DBorder background; /* Background color. */
Tcl_Obj *borderWidthObj;
int relief; /* 3D border effect (TK_RELIEF_RAISED, etc) */
Tcl_Obj *widthObj; /* Tcl_Obj rep for width. */
Tcl_Obj *heightObj; /* Tcl_Obj rep for height. */
enum orient orient; /* Orientation of the widget. */
Tk_Cursor cursor; /* Current cursor for window, or None. */
int resizeOpaque; /* Boolean indicating whether resize should be
* opaque or rubberband style. */
int sashRelief; /* Relief used to draw sash. */
Tcl_Obj *sashWidthObj; /* Tcl_Obj rep for sash width. */
Tcl_Obj *sashPadObj; /* Tcl_Obj rep for sash padding. */
int showHandle; /* Boolean indicating whether sash handles
* should be drawn. */
Tcl_Obj *handleSizeObj; /* Size of one side of a sash handle (handles
* are square), in pixels. */
Tcl_Obj *handlePadObj; /* Distance from border to draw handle. */
Tk_Cursor sashCursor; /* Cursor used when mouse is above a sash. */
GC gc; /* Graphics context for copying from
* off-screen pixmap onto screen. */
int proxyx, proxyy; /* Proxy x,y coordinates. */
Tk_3DBorder proxyBackground;/* Background color used to draw proxy. If NULL, use background. */
Tcl_Obj *proxyBorderWidthObj; /* Tcl_Obj rep for proxyBorderWidth */
int proxyRelief; /* Relief used to draw proxy, if TK_RELIEF_NULL then use relief. */
Pane **panes; /* Pointer to array of Panes. */
int numPanes; /* Number of panes. */
int sizeofPanes; /* Number of elements in the panes array. */
int flags; /* Flags for widget; see below. */
} PanedWindow;
/*
* Flags used for paned windows:
*
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler has been
* queued to redraw this window.
*
* WIDGET_DELETED: Non-zero means that the paned window has been,
* or is in the process of being, deleted.
*
* RESIZE_PENDING: Non-zero means that the window might need to
* change its size (or the size of its panes)
* because of a change in the size of one of its
* children.
*/
#define REDRAW_PENDING 0x0001
#define WIDGET_DELETED 0x0002
#define REQUESTED_RELAYOUT 0x0004
#define RECOMPUTE_GEOMETRY 0x0008
#define PROXY_REDRAW_PENDING 0x0010
#define RESIZE_PENDING 0x0020
/*
* Forward declarations for functions defined later in this file:
*/
static void PanedWindowCmdDeletedProc(void *clientData);
static int ConfigurePanedWindow(Tcl_Interp *interp,
PanedWindow *pwPtr, int objc,
Tcl_Obj *const objv[]);
static void DestroyPanedWindow(PanedWindow *pwPtr);
static void DisplayPanedWindow(void *clientData);
static void PanedWindowEventProc(void *clientData,
XEvent *eventPtr);
static void ProxyWindowEventProc(void *clientData,
XEvent *eventPtr);
static void DisplayProxyWindow(void *clientData);
static void PanedWindowWorldChanged(void *instanceData);
static Tcl_ObjCmdProc PanedWindowWidgetObjCmd;
static void PanedWindowLostPaneProc(void *clientData,
Tk_Window tkwin);
static void PanedWindowReqProc(void *clientData,
Tk_Window tkwin);
static void ArrangePanes(void *clientData);
static void Unlink(Pane *panePtr);
static Pane * GetPane(PanedWindow *pwPtr, Tk_Window tkwin);
static void GetFirstLastVisiblePane(PanedWindow *pwPtr,
int *firstPtr, int *lastPtr);
static void PaneStructureProc(void *clientData,
XEvent *eventPtr);
static int PanedWindowSashCommand(PanedWindow *pwPtr,
Tcl_Interp *interp, int objc,
Tcl_Obj * const objv[]);
static int PanedWindowProxyCommand(PanedWindow *pwPtr,
Tcl_Interp *interp, int objc,
Tcl_Obj * const objv[]);
static void ComputeGeometry(PanedWindow *pwPtr);
static int ConfigurePanes(PanedWindow *pwPtr,
Tcl_Interp *interp, int objc,
Tcl_Obj * const objv[]);
static void DestroyOptionTables(void *clientData,
Tcl_Interp *interp);
static int SetSticky(void *clientData, Tcl_Interp *interp,
Tk_Window tkwin, Tcl_Obj **value, char *recordPtr,
Tcl_Size internalOffset, char *oldInternalPtr,
int flags);
static Tcl_Obj * GetSticky(void *clientData, Tk_Window tkwin,
char *recordPtr, Tcl_Size internalOffset);
static void RestoreSticky(void *clientData, Tk_Window tkwin,
char *internalPtr, char *oldInternalPtr);
static void AdjustForSticky(int sticky, int cavityWidth,
int cavityHeight, int *xPtr, int *yPtr,
int *paneWidthPtr, int *paneHeightPtr);
static void MoveSash(PanedWindow *pwPtr, int sash, int diff);
static void * ComputeSlotAddress(void *recordPtr, Tcl_Size offset);
static int PanedWindowIdentifyCoords(PanedWindow *pwPtr,
Tcl_Interp *interp, int x, int y);
/*
* Sashes are between panes only, so there is one less sash than panes
*/
#define ValidSashIndex(pwPtr, sash) \
(((sash) >= 0) && ((sash) < ((pwPtr)->numPanes-1)))
static const Tk_GeomMgr panedWindowMgrType = {
"panedwindow", /* name */
PanedWindowReqProc, /* requestProc */
PanedWindowLostPaneProc, /* lostPaneProc */
};
/*
* Information used for objv parsing.
*/
#define GEOMETRY 0x0001
/*
* The following structure contains pointers to functions used for processing
* the custom "-sticky" option for panes.
*/
static const Tk_ObjCustomOption stickyOption = {
"sticky", /* name */
SetSticky, /* setProc */
GetSticky, /* getProc */
RestoreSticky, /* restoreProc */
NULL, /* freeProc */
0
};
static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_BORDER, "-background", "background", "Background",
DEF_PANEDWINDOW_BG_COLOR, TCL_INDEX_NONE, offsetof(PanedWindow, background), 0,
DEF_PANEDWINDOW_BG_MONO, 0},
{TK_OPTION_SYNONYM, "-bd", NULL, NULL,
NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
{TK_OPTION_SYNONYM, "-bg", NULL, NULL,
NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_PANEDWINDOW_BORDERWIDTH, offsetof(PanedWindow, borderWidthObj), TCL_INDEX_NONE,
0, 0, GEOMETRY},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
DEF_PANEDWINDOW_CURSOR, TCL_INDEX_NONE, offsetof(PanedWindow, cursor),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-handlepad", "handlePad", "HandlePad",
DEF_PANEDWINDOW_HANDLEPAD, offsetof(PanedWindow, handlePadObj), TCL_INDEX_NONE,
0, 0, GEOMETRY},
{TK_OPTION_PIXELS, "-handlesize", "handleSize", "HandleSize",
DEF_PANEDWINDOW_HANDLESIZE, offsetof(PanedWindow, handleSizeObj),
TCL_INDEX_NONE, 0, 0, GEOMETRY},
{TK_OPTION_PIXELS, "-height", "height", "Height",
DEF_PANEDWINDOW_HEIGHT, offsetof(PanedWindow, heightObj),
TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY},
{TK_OPTION_BOOLEAN, "-opaqueresize", "opaqueResize", "OpaqueResize",
DEF_PANEDWINDOW_OPAQUERESIZE, TCL_INDEX_NONE,
offsetof(PanedWindow, resizeOpaque), 0, 0, 0},
{TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
DEF_PANEDWINDOW_ORIENT, TCL_INDEX_NONE, offsetof(PanedWindow, orient),
TK_OPTION_ENUM_VAR, orientStrings, GEOMETRY},
{TK_OPTION_BORDER, "-proxybackground", "proxyBackground", "ProxyBackground",
0, TCL_INDEX_NONE, offsetof(PanedWindow, proxyBackground), TK_OPTION_NULL_OK,
(void *)DEF_PANEDWINDOW_BG_MONO, 0},
{TK_OPTION_PIXELS, "-proxyborderwidth", "proxyBorderWidth", "ProxyBorderWidth",
DEF_PANEDWINDOW_PROXYBORDER, offsetof(PanedWindow, proxyBorderWidthObj),
TCL_INDEX_NONE, 0, 0, GEOMETRY},
{TK_OPTION_RELIEF, "-proxyrelief", "proxyRelief", "Relief",
0, TCL_INDEX_NONE, offsetof(PanedWindow, proxyRelief),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
DEF_PANEDWINDOW_RELIEF, TCL_INDEX_NONE, offsetof(PanedWindow, relief), 0, 0, 0},
{TK_OPTION_CURSOR, "-sashcursor", "sashCursor", "Cursor",
DEF_PANEDWINDOW_SASHCURSOR, TCL_INDEX_NONE, offsetof(PanedWindow, sashCursor),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-sashpad", "sashPad", "SashPad",
DEF_PANEDWINDOW_SASHPAD, offsetof(PanedWindow, sashPadObj), TCL_INDEX_NONE,
0, 0, GEOMETRY},
{TK_OPTION_RELIEF, "-sashrelief", "sashRelief", "Relief",
DEF_PANEDWINDOW_SASHRELIEF, TCL_INDEX_NONE, offsetof(PanedWindow, sashRelief),
0, 0, 0},
{TK_OPTION_PIXELS, "-sashwidth", "sashWidth", "Width",
DEF_PANEDWINDOW_SASHWIDTH, offsetof(PanedWindow, sashWidthObj),
TCL_INDEX_NONE, 0, 0, GEOMETRY},
{TK_OPTION_BOOLEAN, "-showhandle", "showHandle", "ShowHandle",
DEF_PANEDWINDOW_SHOWHANDLE, TCL_INDEX_NONE, offsetof(PanedWindow, showHandle),
0, 0, GEOMETRY},
{TK_OPTION_PIXELS, "-width", "width", "Width",
DEF_PANEDWINDOW_WIDTH, offsetof(PanedWindow, widthObj),
TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};
static const Tk_OptionSpec paneOptionSpecs[] = {
{TK_OPTION_WINDOW, "-after", NULL, NULL,
DEF_PANEDWINDOW_PANE_AFTER, TCL_INDEX_NONE, offsetof(Pane, after),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_WINDOW, "-before", NULL, NULL,
DEF_PANEDWINDOW_PANE_BEFORE, TCL_INDEX_NONE, offsetof(Pane, before),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-height", NULL, NULL,
DEF_PANEDWINDOW_PANE_HEIGHT, offsetof(Pane, heightObj),
offsetof(Pane, height), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_BOOLEAN, "-hide", "hide", "Hide",
DEF_PANEDWINDOW_PANE_HIDE, TCL_INDEX_NONE, offsetof(Pane, hide), 0,0,GEOMETRY},
{TK_OPTION_PIXELS, "-minsize", NULL, NULL,
DEF_PANEDWINDOW_PANE_MINSIZE, offsetof(Pane, minSizeObj), TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_PIXELS, "-padx", NULL, NULL,
DEF_PANEDWINDOW_PANE_PADX, offsetof(Pane, padXObj), TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_PIXELS, "-pady", NULL, NULL,
DEF_PANEDWINDOW_PANE_PADY, offsetof(Pane, padYObj), TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_CUSTOM, "-sticky", NULL, NULL,
DEF_PANEDWINDOW_PANE_STICKY, TCL_INDEX_NONE, offsetof(Pane, sticky),
0, &stickyOption, 0},
{TK_OPTION_STRING_TABLE, "-stretch", "stretch", "Stretch",
DEF_PANEDWINDOW_PANE_STRETCH, TCL_INDEX_NONE, offsetof(Pane, stretch),
TK_OPTION_ENUM_VAR, stretchStrings, 0},
{TK_OPTION_PIXELS, "-width", NULL, NULL,
DEF_PANEDWINDOW_PANE_WIDTH, offsetof(Pane, widthObj),
offsetof(Pane, width), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};
/*
*--------------------------------------------------------------
*
* Tk_PanedWindowObjCmd --
*
* This function is invoked to process the "panedwindow" Tcl command. It
* creates a new "panedwindow" widget.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* A new widget is created and configured.
*
*--------------------------------------------------------------
*/
int
Tk_PanedWindowObjCmd(
TCL_UNUSED(void *), /* NULL. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj * const objv[]) /* Argument objects. */
{
PanedWindow *pwPtr;
Tk_Window tkwin, parent;
OptionTables *pwOpts;
XSetWindowAttributes atts;
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
return TCL_ERROR;
}
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
Tcl_GetString(objv[1]), NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
pwOpts = (OptionTables *)
Tcl_GetAssocData(interp, "PanedWindowOptionTables", NULL);
if (pwOpts == NULL) {
/*
* The first time this function is invoked, the option tables will be
* NULL. We then create the option tables from the templates and store
* a pointer to the tables as the command's clientData so we'll have
* easy access to it in the future.
*/
pwOpts = (OptionTables *)ckalloc(sizeof(OptionTables));
/*
* Set up an exit handler to free the optionTables struct.
*/
Tcl_SetAssocData(interp, "PanedWindowOptionTables",
DestroyOptionTables, pwOpts);
/*
* Create the paned window option tables.
*/
pwOpts->pwOptions = Tk_CreateOptionTable(interp, optionSpecs);
pwOpts->paneOpts = Tk_CreateOptionTable(interp, paneOptionSpecs);
}
Tk_SetClass(tkwin, "Panedwindow");
/*
* Allocate and initialize the widget record.
*/
pwPtr = (PanedWindow *)ckalloc(sizeof(PanedWindow));
memset((void *)pwPtr, 0, (sizeof(PanedWindow)));
pwPtr->tkwin = tkwin;
pwPtr->display = Tk_Display(tkwin);
pwPtr->interp = interp;
pwPtr->widgetCmd = Tcl_CreateObjCommand(interp,
Tk_PathName(pwPtr->tkwin), PanedWindowWidgetObjCmd, pwPtr,
PanedWindowCmdDeletedProc);
pwPtr->optionTable = pwOpts->pwOptions;
pwPtr->paneOpts = pwOpts->paneOpts;
pwPtr->relief = TK_RELIEF_RAISED;
pwPtr->gc = NULL;
pwPtr->cursor = NULL;
pwPtr->sashCursor = NULL;
/*
* Keep a hold of the associated tkwin until we destroy the widget,
* otherwise Tk might free it while we still need it.
*/
Tcl_Preserve(pwPtr->tkwin);
if (Tk_InitOptions(interp, pwPtr, pwOpts->pwOptions,
tkwin) != TCL_OK) {
Tk_DestroyWindow(pwPtr->tkwin);
return TCL_ERROR;
}
Tk_CreateEventHandler(pwPtr->tkwin, ExposureMask|StructureNotifyMask,
PanedWindowEventProc, pwPtr);
/*
* Find the toplevel ancestor of the panedwindow, and make a proxy win as
* a child of that window; this way the proxy can always float above
* panes in the panedwindow.
*/
parent = Tk_Parent(pwPtr->tkwin);
while (!(Tk_IsTopLevel(parent))) {
parent = Tk_Parent(parent);
if (parent == NULL) {
parent = pwPtr->tkwin;
break;
}
}
pwPtr->proxywin = Tk_CreateAnonymousWindow(interp, parent, NULL);
/*
* The proxy window has to be able to share GCs with the main panedwindow
* despite being children of windows with potentially different
* characteristics, and it looks better that way too. [Bug 702230] Also
* set the X window save under attribute to avoid expose events as the
* proxy sash is dragged across the panes. [Bug 1036963]
*/
Tk_SetWindowVisual(pwPtr->proxywin,
Tk_Visual(tkwin), Tk_Depth(tkwin), Tk_Colormap(tkwin));
Tk_CreateEventHandler(pwPtr->proxywin, ExposureMask, ProxyWindowEventProc,
pwPtr);
atts.save_under = True;
Tk_ChangeWindowAttributes(pwPtr->proxywin, CWSaveUnder, &atts);
if (ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2) != TCL_OK) {
Tk_DestroyWindow(pwPtr->proxywin);
Tk_DestroyWindow(pwPtr->tkwin);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tk_NewWindowObj(pwPtr->tkwin));
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* PanedWindowWidgetObjCmd --
*
* This function is invoked to process the Tcl command that corresponds
* to a widget managed by this module. See the user documentation for
* details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
static int
PanedWindowWidgetObjCmd(
void *clientData, /* Information about square widget. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj * const objv[]) /* Argument objects. */
{
PanedWindow *pwPtr = (PanedWindow *)clientData;
int result = TCL_OK;
static const char *const optionStrings[] = {
"add", "cget", "configure", "forget", "identify", "panecget",
"paneconfigure", "panes", "proxy", "sash", NULL
};
enum options {
PW_ADD, PW_CGET, PW_CONFIGURE, PW_FORGET, PW_IDENTIFY, PW_PANECGET,
PW_PANECONFIGURE, PW_PANES, PW_PROXY, PW_SASH
};
Tcl_Obj *resultObj;
int index, count, i, x, y;
Tk_Window tkwin;
Pane *panePtr;
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "command",
0, &index) != TCL_OK) {
return TCL_ERROR;
}
Tcl_Preserve(pwPtr);
switch ((enum options) index) {
case PW_ADD:
if (objc < 3) {
Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
result = TCL_ERROR;
break;
}
result = ConfigurePanes(pwPtr, interp, objc, objv);
break;
case PW_CGET:
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "option");
result = TCL_ERROR;
break;
}
resultObj = Tk_GetOptionValue(interp, pwPtr,
pwPtr->optionTable, objv[2], pwPtr->tkwin);
if (resultObj == NULL) {
result = TCL_ERROR;
} else {
Tcl_SetObjResult(interp, resultObj);
}
break;
case PW_CONFIGURE:
resultObj = NULL;
if (objc <= 3) {
resultObj = Tk_GetOptionInfo(interp, pwPtr,
pwPtr->optionTable,
(objc == 3) ? objv[2] : NULL, pwPtr->tkwin);
if (resultObj == NULL) {
result = TCL_ERROR;
} else {
Tcl_SetObjResult(interp, resultObj);
}
} else {
result = ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2);
}
break;
case PW_FORGET: {
if (objc < 3) {
Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
result = TCL_ERROR;
break;
}
/*
* Clean up each window named in the arg list.
*/
for (count = 0, i = 2; i < objc; i++) {
Tk_Window pane = Tk_NameToWindow(interp, Tcl_GetString(objv[i]),
pwPtr->tkwin);
if (pane == NULL) {
continue;
}
panePtr = GetPane(pwPtr, pane);
if ((panePtr != NULL) && (panePtr->containerPtr != NULL)) {
count++;
Tk_ManageGeometry(pane, NULL, NULL);
Tk_UnmaintainGeometry(panePtr->tkwin, pwPtr->tkwin);
Tk_DeleteEventHandler(panePtr->tkwin, StructureNotifyMask,
PaneStructureProc, panePtr);
Tk_UnmapWindow(panePtr->tkwin);
Unlink(panePtr);
}
if (count != 0) {
ComputeGeometry(pwPtr);
}
}
break;
}
case PW_IDENTIFY:
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "x y");
result = TCL_ERROR;
break;
}
if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
result = TCL_ERROR;
break;
}
result = PanedWindowIdentifyCoords(pwPtr, interp, x, y);
break;
case PW_PANECGET:
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "pane option");
result = TCL_ERROR;
break;
}
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), pwPtr->tkwin);
if (tkwin == NULL) {
result = TCL_ERROR;
break;
}
resultObj = NULL;
for (i = 0; i < pwPtr->numPanes; i++) {
if (pwPtr->panes[i]->tkwin == tkwin) {
resultObj = Tk_GetOptionValue(interp,
pwPtr->panes[i], pwPtr->paneOpts,
objv[3], tkwin);
}
}
if (resultObj == NULL) {
if (i == pwPtr->numPanes) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"not managed by this window", TCL_INDEX_NONE));
Tcl_SetErrorCode(interp, "TK", "PANEDWINDOW", "UNMANAGED",
(char *)NULL);
}
result = TCL_ERROR;
} else {
Tcl_SetObjResult(interp, resultObj);
}
break;
case PW_PANECONFIGURE:
if (objc < 3) {
Tcl_WrongNumArgs(interp, 2, objv,
"pane ?-option value ...?");
result = TCL_ERROR;
break;
}
resultObj = NULL;
if (objc <= 4) {
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
pwPtr->tkwin);
if (tkwin == NULL) {
/*
* Just a plain old bad window; Tk_NameToWindow filled in an
* error message for us.
*/
result = TCL_ERROR;
break;
}
for (i = 0; i < pwPtr->numPanes; i++) {
if (pwPtr->panes[i]->tkwin == tkwin) {
resultObj = Tk_GetOptionInfo(interp,
pwPtr->panes[i], pwPtr->paneOpts,
(objc == 4) ? objv[3] : NULL,
pwPtr->tkwin);
if (resultObj == NULL) {
result = TCL_ERROR;
} else {
Tcl_SetObjResult(interp, resultObj);
}
break;
}
}
} else {
result = ConfigurePanes(pwPtr, interp, objc, objv);
}
break;
case PW_PANES:
resultObj = Tcl_NewObj();
for (i = 0; i < pwPtr->numPanes; i++) {
Tcl_ListObjAppendElement(NULL, resultObj,
Tk_NewWindowObj(pwPtr->panes[i]->tkwin));
}
Tcl_SetObjResult(interp, resultObj);
break;
case PW_PROXY:
result = PanedWindowProxyCommand(pwPtr, interp, objc, objv);
break;
case PW_SASH:
result = PanedWindowSashCommand(pwPtr, interp, objc, objv);
break;
}
Tcl_Release(pwPtr);
return result;
}
/*
*----------------------------------------------------------------------
*
* ConfigurePanes --
*
* Add or alter the configuration options of a pane in a paned window.
*
* Results:
* Standard Tcl result.
*
* Side effects:
* Depends on options; may add a pane to the paned window, may alter the
* geometry management options of a pane.
*
*----------------------------------------------------------------------
*/
static int
ConfigurePanes(
PanedWindow *pwPtr, /* Information about paned window. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int i, firstOptionArg, j, found, doubleBw, index, numNewPanes, haveLoc;
int insertIndex;
Tk_Window tkwin = NULL, ancestor, parent;
Pane *panePtr, **inserts, **newPanes;
Pane options;
const char *arg;
/*
* Find the non-window name arguments; these are the configure options for
* the panes. Also validate that the window names given are legitimate
* (ie, they are real windows, they are not the panedwindow itself, etc.).
*/
for (i = 2; i < objc; i++) {
arg = Tcl_GetString(objv[i]);
if (arg[0] == '-') {
break;
} else {
tkwin = Tk_NameToWindow(interp, arg, pwPtr->tkwin);
if (tkwin == NULL) {
/*
* Just a plain old bad window; Tk_NameToWindow filled in an
* error message for us.
*/
return TCL_ERROR;
} else if (tkwin == pwPtr->tkwin) {
/*
* A panedwindow cannot manage itself.
*/
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"cannot add %s to itself", arg));
Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "SELF", (char *)NULL);
return TCL_ERROR;
} else if (Tk_IsTopLevel(tkwin)) {
/*
* A panedwindow cannot manage a toplevel.
*/
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"cannot add toplevel %s to %s", arg,
Tk_PathName(pwPtr->tkwin)));
Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", (char *)NULL);
return TCL_ERROR;
} else {
/*
* Make sure the panedwindow is the parent of the pane,
* or a descendant of the pane's parent.
*/
parent = Tk_Parent(tkwin);
for (ancestor = pwPtr->tkwin;;ancestor = Tk_Parent(ancestor)) {
if (ancestor == parent) {
break;
}
if (Tk_IsTopLevel(ancestor)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"cannot add %s to %s", arg,
Tk_PathName(pwPtr->tkwin)));
Tcl_SetErrorCode(interp, "TK", "GEOMETRY",
"HIERARCHY", (char *)NULL);
return TCL_ERROR;
}
}
}
}
}
firstOptionArg = i;
/*
* Pre-parse the configuration options, to get the before/after specifiers
* into an easy-to-find location (a local variable). Also, check the
* return from Tk_SetOptions once, here, so we can save a little bit of
* extra testing in the for loop below.
*/
memset((void *)&options, 0, sizeof(Pane));
if (Tk_SetOptions(interp, &options, pwPtr->paneOpts,
objc - firstOptionArg, objv + firstOptionArg,
pwPtr->tkwin, NULL, NULL) != TCL_OK) {
return TCL_ERROR;
}
/*
* If either -after or -before was given, find the numerical index that
* corresponds to the given window. If both -after and -before are given,
* the option precedence is: -after, then -before.
*/
index = -1;
haveLoc = 0;
if (options.after != NULL) {
tkwin = options.after;
haveLoc = 1;
for (i = 0; i < pwPtr->numPanes; i++) {
if (options.after == pwPtr->panes[i]->tkwin) {
index = i + 1;
break;
}
}
} else if (options.before != NULL) {
tkwin = options.before;
haveLoc = 1;
for (i = 0; i < pwPtr->numPanes; i++) {
if (options.before == pwPtr->panes[i]->tkwin) {
index = i;
break;
}
}
}
/*
* If a window was given for -after/-before, but it's not a window managed
* by the panedwindow, throw an error
*/
if (haveLoc && index == -1) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" is not managed by %s",
Tk_PathName(tkwin), Tk_PathName(pwPtr->tkwin)));
Tcl_SetErrorCode(interp, "TK", "PANEDWINDOW", "UNMANAGED", (char *)NULL);
Tk_FreeConfigOptions(&options, pwPtr->paneOpts,
pwPtr->tkwin);
return TCL_ERROR;
}
/*
* Allocate an array to hold, in order, the pointers to the pane
* structures corresponding to the windows specified. Some of those
* structures may already have existed, some may be new.
*/
inserts = (Pane **)ckalloc(sizeof(Pane *) * (firstOptionArg - 2));
insertIndex = 0;
/*
* Populate the inserts array, creating new pane structures as necessary,
* applying the options to each structure as we go, and, if necessary,
* marking the spot in the original panes array as empty (for
* pre-existing pane structures).
*/
for (i = 0, numNewPanes = 0; i < firstOptionArg - 2; i++) {
/*
* We don't check that tkwin is NULL here, because the pre-pass above
* guarantees that the input at this stage is good.
*/
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[i + 2]),
pwPtr->tkwin);
found = 0;
for (j = 0; j < pwPtr->numPanes; j++) {
if (pwPtr->panes[j] != NULL && pwPtr->panes[j]->tkwin == tkwin) {
int minSize;
Tk_SetOptions(interp, pwPtr->panes[j],
pwPtr->paneOpts, objc - firstOptionArg,
objv + firstOptionArg, pwPtr->tkwin, NULL, NULL);
Tk_GetPixelsFromObj(NULL, tkwin, pwPtr->panes[j]->minSizeObj, &minSize);
if (minSize < 0) {
Tcl_DecrRefCount(pwPtr->panes[j]->minSizeObj);
pwPtr->panes[j]->minSizeObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(pwPtr->panes[j]->minSizeObj);
}
found = 1;
/*
* If the pane is supposed to move, add it to the inserts
* array now; otherwise, leave it where it is.
*/
if (index != -1) {
inserts[insertIndex++] = pwPtr->panes[j];
pwPtr->panes[j] = NULL;
}
break;
}
}
if (found) {
continue;
}
/*
* Make sure this pane wasn't already put into the inserts array,
* i.e., when the user specifies the same window multiple times in a
* single add command.
*/
for (j = 0; j < insertIndex; j++) {
if (inserts[j]->tkwin == tkwin) {
found = 1;
break;
}
}
if (found) {
continue;
}
/*
* Create a new pane structure and initialize it. All panes start
* out with their "natural" dimensions.
*/
int minSize;
panePtr = (Pane *)ckalloc(sizeof(Pane));
memset(panePtr, 0, sizeof(Pane));
Tk_InitOptions(interp, panePtr, pwPtr->paneOpts,
pwPtr->tkwin);
Tk_SetOptions(interp, panePtr, pwPtr->paneOpts,
objc - firstOptionArg, objv + firstOptionArg,
pwPtr->tkwin, NULL, NULL);
panePtr->tkwin = tkwin;
panePtr->containerPtr = pwPtr;
doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
if (panePtr->width > 0) {
panePtr->paneWidth = panePtr->width;
} else {
panePtr->paneWidth = Tk_ReqWidth(tkwin) + doubleBw;
}
if (panePtr->height > 0) {
panePtr->paneHeight = panePtr->height;
} else {
panePtr->paneHeight = Tk_ReqHeight(tkwin) + doubleBw;
}
Tk_GetPixelsFromObj(NULL, panePtr->tkwin, panePtr->minSizeObj, &minSize);
if (minSize < 0) {
Tcl_DecrRefCount(panePtr->minSizeObj);
panePtr->minSizeObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(panePtr->minSizeObj);
}
/*
* Set up the geometry management callbacks for this pane.
*/
Tk_CreateEventHandler(panePtr->tkwin, StructureNotifyMask,
PaneStructureProc, panePtr);
Tk_ManageGeometry(panePtr->tkwin, &panedWindowMgrType, panePtr);