FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython-source-deps/unix/tkUnixMenu.c at tk · python/cpython-source-deps · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
cpython-source-deps
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
48
Star
28
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython-source-deps
/
unix
/
tkUnixMenu.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
1951 lines (1777 loc) · 54 KB
Breadcrumbs
cpython-source-deps
/
unix
/
tkUnixMenu.c
Copy path
File metadata and controls
1951 lines (1777 loc) · 54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* tkUnixMenu.c --
*
* This module implements the UNIX platform-specific features of menus.
*
* Copyright © 1996-1998 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include
"tkUnixInt.h"
#include
"tkMenu.h"
/*
* Constants used for menu drawing.
*/
#define
MENU_MARGIN_WIDTH
2
#define
MENU_DIVIDER_HEIGHT
2
#define
CASCADE_ARROW_SIZE
4
/*
* Platform specific flags for Unix.
*/
#define
ENTRY_HELP_MENU
ENTRY_PLATFORM_FLAG1
/*
* Shared with button widget.
*/
MODULE_SCOPE
void
TkpDrawCheckIndicator
(
Tk_Window
tkwin
,
Display
*
display
,
Drawable
d
,
int
x
,
int
y
,
Tk_3DBorder
bgBorder
,
XColor
*
indicatorColor
,
XColor
*
selectColor
,
XColor
*
disColor
,
int
on
,
int
disabled
,
int
mode
);
/*
* Indicator Draw Modes
*/
#define
CHECK_BUTTON
0
#define
CHECK_MENU
1
#define
RADIO_BUTTON
2
#define
RADIO_MENU
3
/*
* Procedures used internally.
*/
static
void
SetHelpMenu
(
TkMenu
*
menuPtr
);
static
void
DrawMenuEntryAccelerator
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
GC
gc
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
,
int
drawArrow
);
static
void
DrawMenuEntryBackground
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
Tk_3DBorder
activeBorder
,
Tk_3DBorder
bgBorder
,
int
x
,
int
y
,
int
width
,
int
heigth
);
static
void
DrawMenuEntryIndicator
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
Tk_3DBorder
border
,
XColor
*
indicatorColor
,
XColor
*
disableColor
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
);
static
void
DrawMenuEntryLabel
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
GC
gc
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
);
static
void
DrawMenuSeparator
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
GC
gc
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
);
static
void
DrawTearoffEntry
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
GC
gc
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
);
static
void
DrawMenuUnderline
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Drawable
d
,
GC
gc
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
x
,
int
y
,
int
width
,
int
height
);
static
void
GetMenuAccelGeometry
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
*
widthPtr
,
int
*
heightPtr
);
static
void
GetMenuLabelGeometry
(
TkMenuEntry
*
mePtr
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
*
widthPtr
,
int
*
heightPtr
);
static
void
GetMenuIndicatorGeometry
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
*
widthPtr
,
int
*
heightPtr
);
static
void
GetMenuSeparatorGeometry
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
*
widthPtr
,
int
*
heightPtr
);
static
void
GetTearoffEntryGeometry
(
TkMenu
*
menuPtr
,
TkMenuEntry
*
mePtr
,
Tk_Font
tkfont
,
const
Tk_FontMetrics
*
fmPtr
,
int
*
widthPtr
,
int
*
heightPtr
);
/*
*----------------------------------------------------------------------
*
* TkpNewMenu --
*
* Gets the platform-specific piece of the menu. Invoked during idle
* after the generic part of the menu has been created.
*
* Results:
* Standard TCL error.
*
* Side effects:
* Allocates any platform specific allocations and places them in the
* platformData field of the menuPtr.
*
*----------------------------------------------------------------------
*/
int
TkpNewMenu
(
TkMenu
*
menuPtr
)
{
SetHelpMenu
(
menuPtr
);
return
TCL_OK
;
}
/*
*----------------------------------------------------------------------
*
* TkpDestroyMenu --
*
* Destroys platform-specific menu structures. Called when the generic
* menu structure is destroyed for the menu.
*
* Results:
* None.
*
* Side effects:
* All platform-specific allocations are freed up.
*
*----------------------------------------------------------------------
*/
void
TkpDestroyMenu
(
TCL_UNUSED
(
TkMenu
*
))
{
/*
* Nothing to do.
*/
}
/*
*----------------------------------------------------------------------
*
* TkpDestroyMenuEntry --
*
* Cleans up platform-specific menu entry items. Called when entry is
* destroyed in the generic code.
*
* Results:
* None.
*
* Side effects:
* All platform specific allocations are freed up.
*
*----------------------------------------------------------------------
*/
void
TkpDestroyMenuEntry
(
TCL_UNUSED
(
TkMenuEntry
*
))
{
/*
* Nothing to do.
*/
}
/*
*----------------------------------------------------------------------
*
* TkpConfigureMenuEntry --
*
* Processes configuration options for menu entries. Called when the
* generic options are processed for the menu.
*
* Results:
* Returns standard TCL result. If TCL_ERROR is returned, then the
* interp's result contains an error message.
*
* Side effects:
* Configuration information get set for mePtr; old resources get freed,
* if any need it.
*
*----------------------------------------------------------------------
*/
int
TkpConfigureMenuEntry
(
TkMenuEntry
*
mePtr
)
/* Information about menu entry; may or may
* not already have values for some fields. */
{
/*
* If this is a cascade menu, and the child menu exists, check to see if
* the child menu is a help menu.
*/
if
((
mePtr
->
type
==
CASCADE_ENTRY
)
&&
(
mePtr
->
namePtr
!=
NULL
)) {
TkMenuReferences
*
menuRefPtr
;
menuRefPtr
=
TkFindMenuReferencesObj
(
mePtr
->
menuPtr
->
interp
,
mePtr
->
namePtr
);
if
((
menuRefPtr
!=
NULL
)
&&
(
menuRefPtr
->
menuPtr
!=
NULL
)) {
SetHelpMenu
(
menuRefPtr
->
menuPtr
);
}
}
return
TCL_OK
;
}
/*
*----------------------------------------------------------------------
*
* TkpMenuNewEntry --
*
* Called when a new entry is created in a menu. Fills in platform
* specific data for the entry. The platformEntryData field is used to
* store the indicator diameter for radio button and check box entries.
*
* Results:
* Standard TCL error.
*
* Side effects:
* None on Unix.
*
*----------------------------------------------------------------------
*/
int
TkpMenuNewEntry
(
TCL_UNUSED
(
TkMenuEntry
*
))
{
return
TCL_OK
;
}
/*
*----------------------------------------------------------------------
*
* TkpSetWindowMenuBar --
*
* Sets up the menu as a menubar in the given window.
*
* Results:
* None.
*
* Side effects:
* Recomputes geometry of given window.
*
*----------------------------------------------------------------------
*/
void
TkpSetWindowMenuBar
(
Tk_Window
tkwin
,
/* The window we are setting */
TkMenu
*
menuPtr
)
/* The menu we are setting */
{
if
(
menuPtr
==
NULL
) {
TkUnixSetMenubar
(
tkwin
,
NULL
);
}
else
{
TkUnixSetMenubar
(
tkwin
,
menuPtr
->
tkwin
);
}
}
/*
*----------------------------------------------------------------------
*
* TkpSetMainMenuBar --
*
* Called when a toplevel widget is brought to front. On the Macintosh,
* sets up the menubar that goes accross the top of the main monitor. On
* other platforms, nothing is necessary.
*
* Results:
* None.
*
* Side effects:
* Recompute geometry of given window.
*
*----------------------------------------------------------------------
*/
void
Tk_SetMainMenubar
(
TCL_UNUSED
(
Tcl_Interp
*
),
TCL_UNUSED
(
Tk_Window
),
TCL_UNUSED
(
const
char
*
))
{
/*
* Nothing to do.
*/
}
/*
*----------------------------------------------------------------------
*
* GetMenuIndicatorGeometry --
*
* Fills out the geometry of the indicator in a menu item. Note that the
* mePtr->height field must have already been filled in by
* GetMenuLabelGeometry since this height depends on the label height.
*
* Results:
* widthPtr and heightPtr point to the new geometry values.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static
void
GetMenuIndicatorGeometry
(
TkMenu
*
menuPtr
,
/* The menu we are drawing. */
TkMenuEntry
*
mePtr
,
/* The entry we are interested in. */
TCL_UNUSED
(
Tk_Font
),
/* The precalculated font */
TCL_UNUSED
(
const
Tk_FontMetrics
*
),
/* The precalculated metrics */
int
*
widthPtr
,
/* The resulting width */
int
*
heightPtr
)
/* The resulting height */
{
int
borderWidth
;
if
((
mePtr
->
type
==
CHECK_BUTTON_ENTRY
)
||
(
mePtr
->
type
==
RADIO_BUTTON_ENTRY
)) {
if
(!
mePtr
->
hideMargin
&&
mePtr
->
indicatorOn
) {
if
((
mePtr
->
image
!=
NULL
)
||
(
mePtr
->
bitmapPtr
!=
NULL
)) {
*
widthPtr
=
(
14
*
mePtr
->
height
) /
10
;
*
heightPtr
=
mePtr
->
height
;
if
(
mePtr
->
type
==
CHECK_BUTTON_ENTRY
) {
mePtr
->
platformEntryData
=
(
TkMenuPlatformEntryData
)
INT2PTR
((
65
*
mePtr
->
height
) /
100
);
}
else
{
mePtr
->
platformEntryData
=
(
TkMenuPlatformEntryData
)
INT2PTR
((
75
*
mePtr
->
height
) /
100
);
}
}
else
{
*
widthPtr
=
*
heightPtr
=
mePtr
->
height
;
if
(
mePtr
->
type
==
CHECK_BUTTON_ENTRY
) {
mePtr
->
platformEntryData
=
(
TkMenuPlatformEntryData
)
INT2PTR
((
80
*
mePtr
->
height
) /
100
);
}
else
{
mePtr
->
platformEntryData
=
(
TkMenuPlatformEntryData
)
INT2PTR
(
mePtr
->
height
);
}
}
}
else
{
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
borderWidthObj
,
&
borderWidth
);
*
heightPtr
=
0
;
*
widthPtr
=
borderWidth
;
}
}
else
{
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
borderWidthObj
,
&
borderWidth
);
*
heightPtr
=
0
;
*
widthPtr
=
borderWidth
;
}
}
/*
*----------------------------------------------------------------------
*
* GetMenuAccelGeometry --
*
* Get the geometry of the accelerator area of a menu item.
*
* Results:
* heightPtr and widthPtr are set.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static
void
GetMenuAccelGeometry
(
TkMenu
*
menuPtr
,
/* The menu was are drawing */
TkMenuEntry
*
mePtr
,
/* The entry we are getting the geometry for */
Tk_Font
tkfont
,
/* The precalculated font */
const
Tk_FontMetrics
*
fmPtr
,
/* The precalculated font metrics */
int
*
widthPtr
,
/* The width of the acclerator area */
int
*
heightPtr
)
/* The height of the accelerator area */
{
*
heightPtr
=
fmPtr
->
linespace
;
if
(
mePtr
->
type
==
CASCADE_ENTRY
) {
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
int
arrowWidth
=
(
int
)(
CASCADE_ARROW_SIZE
*
scalingLevel
)
+
1
;
*
widthPtr
=
2
*
arrowWidth
;
}
else
if
((
menuPtr
->
menuType
!=
MENUBAR
)
&&
(
mePtr
->
accelPtr
!=
NULL
)) {
const
char
*
accel
=
Tcl_GetString
(
mePtr
->
accelPtr
);
*
widthPtr
=
Tk_TextWidth
(
tkfont
,
accel
,
mePtr
->
accelLength
);
}
else
{
*
widthPtr
=
0
;
}
}
/*
*----------------------------------------------------------------------
*
* DrawMenuEntryBackground --
*
* This procedure draws the background part of a menu.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuEntryBackground
(
TkMenu
*
menuPtr
,
/* The menu we are drawing */
TkMenuEntry
*
mePtr
,
/* The entry we are drawing. */
Drawable
d
,
/* The drawable we are drawing into */
Tk_3DBorder
activeBorder
,
/* The border for an active item */
Tk_3DBorder
bgBorder
,
/* The background border */
int
x
,
/* Left coordinate of entry rect */
int
y
,
/* Right coordinate of entry rect */
int
width
,
/* Width of entry rect */
int
height
)
/* Height of entry rect */
{
if
(
mePtr
->
state
==
ENTRY_ACTIVE
) {
int
relief
;
int
activeBorderWidth
;
bgBorder
=
activeBorder
;
if
((
menuPtr
->
menuType
==
MENUBAR
)
&&
((
menuPtr
->
postedCascade
==
NULL
)
||
(
menuPtr
->
postedCascade
!=
mePtr
))) {
relief
=
TK_RELIEF_FLAT
;
}
else
{
relief
=
menuPtr
->
activeRelief
;
}
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
Tk_Fill3DRectangle
(
menuPtr
->
tkwin
,
d
,
bgBorder
,
x
,
y
,
width
,
height
,
activeBorderWidth
,
relief
);
}
else
{
Tk_Fill3DRectangle
(
menuPtr
->
tkwin
,
d
,
bgBorder
,
x
,
y
,
width
,
height
,
0
,
TK_RELIEF_FLAT
);
}
}
/*
*----------------------------------------------------------------------
*
* DrawMenuEntryAccelerator --
*
* This procedure draws the background part of a menu.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuEntryAccelerator
(
TkMenu
*
menuPtr
,
/* The menu we are drawing */
TkMenuEntry
*
mePtr
,
/* The entry we are drawing */
Drawable
d
,
/* The drawable we are drawing into */
GC
gc
,
/* The precalculated gc to draw with */
Tk_Font
tkfont
,
/* The precalculated font */
const
Tk_FontMetrics
*
fmPtr
,
/* The precalculated metrics */
int
x
,
/* Left coordinate of entry rect */
int
y
,
/* Top coordinate of entry rect */
int
width
,
/* Width of entry */
int
height
,
/* Height of entry */
int
drawArrow
)
/* Whether or not to draw arrow. */
{
int
borderWidth
,
activeBorderWidth
;
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
int
arrowSize
=
(
int
)(
CASCADE_ARROW_SIZE
*
scalingLevel
);
int
arrowWidth
=
arrowSize
+
1
,
arrowHeight
=
2
*
arrowSize
+
1
;
XPoint
points
[
4
];
/*
* Draw accelerator or cascade arrow.
*/
if
(
menuPtr
->
menuType
==
MENUBAR
) {
return
;
}
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
borderWidthObj
,
&
borderWidth
);
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
if
((
mePtr
->
type
==
CASCADE_ENTRY
)
&&
drawArrow
) {
/*
* The value of points[0].x below is based on the following equations:
* points[0].x + arrowWidth + cascadeOffset = menuWidth
* cascadeOffset = borderWidth + activeBorderWidth + 2*scalingLevel
* (see function AdjustMenuCoords() in file tkMenuDraw.c)
* menuWidth = x + width + borderWidth
*/
points
[
0
].
x
=
x
+
width
-
activeBorderWidth
-
(
int
)
round
(
2
*
scalingLevel
)
-
arrowWidth
;
points
[
0
].
y
=
y
+
(
height
-
arrowHeight
)/
2
;
points
[
1
].
x
=
points
[
0
].
x
;
points
[
1
].
y
=
points
[
0
].
y
+
arrowHeight
-
1
;
points
[
2
].
x
=
points
[
0
].
x
+
arrowSize
;
points
[
2
].
y
=
points
[
0
].
y
+
arrowSize
;
points
[
3
].
x
=
points
[
0
].
x
;
points
[
3
].
y
=
points
[
0
].
y
;
XFillPolygon
(
Tk_Display
(
menuPtr
->
tkwin
),
d
,
gc
,
points
,
3
,
Complex
,
CoordModeOrigin
);
XDrawLines
(
Tk_Display
(
menuPtr
->
tkwin
),
d
,
gc
,
points
,
4
,
CoordModeOrigin
);
/* Work around bug [77527326e5] */
XDrawPoint
(
Tk_Display
(
menuPtr
->
tkwin
),
d
,
gc
,
points
[
2
].
x
,
points
[
2
].
y
);
}
else
if
(
mePtr
->
accelPtr
!=
NULL
) {
const
char
*
accel
=
Tcl_GetString
(
mePtr
->
accelPtr
);
int
left
=
x
+
mePtr
->
labelWidth
+
activeBorderWidth
+
mePtr
->
indicatorSpace
;
if
(
menuPtr
->
menuType
==
MENUBAR
) {
left
+=
(
int
)
round
(
5
*
scalingLevel
);
}
Tk_DrawChars
(
menuPtr
->
display
,
d
,
gc
,
tkfont
,
accel
,
mePtr
->
accelLength
,
left
,
(
y
+
(
height
+
fmPtr
->
ascent
-
fmPtr
->
descent
) /
2
));
}
}
/*
*----------------------------------------------------------------------
*
* DrawMenuEntryIndicator --
*
* This procedure draws the background part of a menu.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuEntryIndicator
(
TkMenu
*
menuPtr
,
/* The menu we are drawing */
TkMenuEntry
*
mePtr
,
/* The entry we are drawing */
Drawable
d
,
/* The drawable to draw into */
Tk_3DBorder
border
,
/* The background color */
XColor
*
indicatorColor
,
/* The color to draw indicators with */
XColor
*
disableColor
,
/* The color use use when disabled */
TCL_UNUSED
(
Tk_Font
),
/* The font to draw with */
TCL_UNUSED
(
const
Tk_FontMetrics
*
),
/* The font metrics of the font */
int
x
,
/* The left of the entry rect */
int
y
,
/* The top of the entry rect */
TCL_UNUSED
(
int
),
/* Width of menu entry */
int
height
)
/* Height of menu entry */
{
/*
* Draw check-button indicator.
*/
if
((
mePtr
->
type
==
CHECK_BUTTON_ENTRY
)
&&
mePtr
->
indicatorOn
) {
int
top
,
left
,
activeBorderWidth
;
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
int
disabled
=
(
mePtr
->
state
==
ENTRY_DISABLED
);
XColor
*
bg
;
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
bg
=
Tk_3DBorderColor
(
border
);
top
=
y
+
height
/
2
;
left
=
x
+
activeBorderWidth
+
(
int
)
round
(
DECORATION_BORDER_WIDTH
*
scalingLevel
)
+
mePtr
->
indicatorSpace
/
2
;
TkpDrawCheckIndicator
(
menuPtr
->
tkwin
,
menuPtr
->
display
,
d
,
left
,
top
,
border
,
indicatorColor
,
bg
,
disableColor
,
(
mePtr
->
entryFlags
&
ENTRY_SELECTED
),
disabled
,
CHECK_MENU
);
}
/*
* Draw radio-button indicator.
*/
if
((
mePtr
->
type
==
RADIO_BUTTON_ENTRY
)
&&
mePtr
->
indicatorOn
) {
int
top
,
left
,
activeBorderWidth
;
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
int
disabled
=
(
mePtr
->
state
==
ENTRY_DISABLED
);
XColor
*
bg
;
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
bg
=
Tk_3DBorderColor
(
border
);
top
=
y
+
height
/
2
;
left
=
x
+
activeBorderWidth
+
(
int
)
round
(
DECORATION_BORDER_WIDTH
*
scalingLevel
)
+
mePtr
->
indicatorSpace
/
2
;
TkpDrawCheckIndicator
(
menuPtr
->
tkwin
,
menuPtr
->
display
,
d
,
left
,
top
,
border
,
indicatorColor
,
bg
,
disableColor
,
(
mePtr
->
entryFlags
&
ENTRY_SELECTED
),
disabled
,
RADIO_MENU
);
}
}
/*
*----------------------------------------------------------------------
*
* DrawMenuSeparator --
*
* This procedure draws a separator menu item.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuSeparator
(
TkMenu
*
menuPtr
,
/* The menu we are drawing */
TCL_UNUSED
(
TkMenuEntry
*
),
/* The entry we are drawing */
Drawable
d
,
/* The drawable we are using */
TCL_UNUSED
(
GC
),
/* The gc to draw into */
TCL_UNUSED
(
Tk_Font
),
/* The font to draw with */
TCL_UNUSED
(
const
Tk_FontMetrics
*
),
/* The font metrics from the font */
int
x
,
int
y
,
int
width
,
int
height
)
{
XPoint
points
[
2
];
Tk_3DBorder
border
;
if
(
menuPtr
->
menuType
==
MENUBAR
) {
return
;
}
points
[
0
].
x
=
x
;
points
[
0
].
y
=
y
+
height
/
2
;
points
[
1
].
x
=
x
+
width
-
1
;
points
[
1
].
y
=
points
[
0
].
y
;
border
=
Tk_Get3DBorderFromObj
(
menuPtr
->
tkwin
,
menuPtr
->
borderPtr
);
Tk_Draw3DPolygon
(
menuPtr
->
tkwin
,
d
,
border
,
points
,
2
,
1
,
TK_RELIEF_RAISED
);
}
/*
*----------------------------------------------------------------------
*
* DrawMenuEntryLabel --
*
* This procedure draws the label part of a menu.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuEntryLabel
(
TkMenu
*
menuPtr
,
/* The menu we are drawing. */
TkMenuEntry
*
mePtr
,
/* The entry we are drawing. */
Drawable
d
,
/* What we are drawing into. */
GC
gc
,
/* The gc we are drawing into.*/
Tk_Font
tkfont
,
/* The precalculated font. */
const
Tk_FontMetrics
*
fmPtr
,
/* The precalculated font metrics. */
int
x
,
/* Left edge. */
int
y
,
/* Top edge. */
int
width
,
/* width of entry. */
int
height
)
/* height of entry. */
{
int
indicatorSpace
=
mePtr
->
indicatorSpace
;
int
activeBorderWidth
,
leftEdge
,
imageHeight
,
imageWidth
;
int
textHeight
=
0
,
textWidth
=
0
;
/* stop GCC warning */
int
haveImage
=
0
,
haveText
=
0
;
int
imageXOffset
=
0
,
imageYOffset
=
0
;
int
textXOffset
=
0
,
textYOffset
=
0
;
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
leftEdge
=
x
+
indicatorSpace
+
activeBorderWidth
;
if
(
menuPtr
->
menuType
==
MENUBAR
) {
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
leftEdge
+=
(
int
)
round
(
5
*
scalingLevel
);
}
/*
* Work out what we will need to draw first.
*/
if
(
mePtr
->
image
!=
NULL
) {
Tk_SizeOfImage
(
mePtr
->
image
,
&
imageWidth
,
&
imageHeight
);
haveImage
=
1
;
}
else
if
(
mePtr
->
bitmapPtr
!=
NULL
) {
Pixmap
bitmap
=
Tk_GetBitmapFromObj
(
menuPtr
->
tkwin
,
mePtr
->
bitmapPtr
);
Tk_SizeOfBitmap
(
menuPtr
->
display
,
bitmap
,
&
imageWidth
,
&
imageHeight
);
haveImage
=
1
;
}
if
(!
haveImage
||
(
mePtr
->
compound
!=
COMPOUND_NONE
)) {
if
(
mePtr
->
labelLength
>
0
) {
const
char
*
label
=
Tcl_GetString
(
mePtr
->
labelPtr
);
textWidth
=
Tk_TextWidth
(
tkfont
,
label
,
mePtr
->
labelLength
);
textHeight
=
fmPtr
->
linespace
;
haveText
=
1
;
}
}
/*
* Now work out what the relative positions are.
*/
if
(
haveImage
&&
haveText
) {
int
fullWidth
=
(
imageWidth
>
textWidth
?
imageWidth
:
textWidth
);
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
int
scaled2
=
(
int
)
round
(
2
*
scalingLevel
);
switch
((
enum
compound
)
mePtr
->
compound
) {
case
COMPOUND_TOP
:
textXOffset
=
(
fullWidth
-
textWidth
)/
2
;
textYOffset
=
imageHeight
/
2
+
scaled2
;
imageXOffset
=
(
fullWidth
-
imageWidth
)/
2
;
imageYOffset
=
-
textHeight
/
2
;
break
;
case
COMPOUND_BOTTOM
:
textXOffset
=
(
fullWidth
-
textWidth
)/
2
;
textYOffset
=
-
imageHeight
/
2
;
imageXOffset
=
(
fullWidth
-
imageWidth
)/
2
;
imageYOffset
=
textHeight
/
2
+
scaled2
;
break
;
case
COMPOUND_LEFT
:
/*
* Position image in the indicator space to the left of the
* entries, unless this entry is a radio|check button because then
* the indicator space will be used.
*/
textXOffset
=
imageWidth
+
scaled2
;
textYOffset
=
0
;
imageXOffset
=
0
;
imageYOffset
=
0
;
if
((
mePtr
->
type
!=
CHECK_BUTTON_ENTRY
)
&&
(
mePtr
->
type
!=
RADIO_BUTTON_ENTRY
)) {
textXOffset
-=
indicatorSpace
;
if
(
textXOffset
<
0
) {
textXOffset
=
0
;
}
imageXOffset
=
-
indicatorSpace
;
}
break
;
case
COMPOUND_RIGHT
:
textXOffset
=
0
;
textYOffset
=
0
;
imageXOffset
=
textWidth
+
scaled2
;
imageYOffset
=
0
;
break
;
case
COMPOUND_CENTER
:
textXOffset
=
(
fullWidth
-
textWidth
)/
2
;
textYOffset
=
0
;
imageXOffset
=
(
fullWidth
-
imageWidth
)/
2
;
imageYOffset
=
0
;
break
;
case
COMPOUND_NONE
:
break
;
}
}
else
{
textXOffset
=
0
;
textYOffset
=
0
;
imageXOffset
=
0
;
imageYOffset
=
0
;
}
/*
* Draw label and/or bitmap or image for entry.
*/
if
(
mePtr
->
image
!=
NULL
) {
if
((
mePtr
->
selectImage
!=
NULL
)
&&
(
mePtr
->
entryFlags
&
ENTRY_SELECTED
)) {
Tk_RedrawImage
(
mePtr
->
selectImage
,
0
,
0
,
imageWidth
,
imageHeight
,
d
,
leftEdge
+
imageXOffset
,
(
int
) (
y
+
(
mePtr
->
height
-
imageHeight
)/
2
+
imageYOffset
));
}
else
{
Tk_RedrawImage
(
mePtr
->
image
,
0
,
0
,
imageWidth
,
imageHeight
,
d
,
leftEdge
+
imageXOffset
,
(
int
) (
y
+
(
mePtr
->
height
-
imageHeight
)/
2
+
imageYOffset
));
}
}
else
if
(
mePtr
->
bitmapPtr
!=
NULL
) {
Pixmap
bitmap
=
Tk_GetBitmapFromObj
(
menuPtr
->
tkwin
,
mePtr
->
bitmapPtr
);
XCopyPlane
(
menuPtr
->
display
,
bitmap
,
d
,
gc
,
0
,
0
,
(
unsigned
)
imageWidth
, (
unsigned
)
imageHeight
,
leftEdge
+
imageXOffset
,
(
int
) (
y
+
(
mePtr
->
height
-
imageHeight
)/
2
+
imageYOffset
),
1
);
}
if
((
mePtr
->
compound
!=
COMPOUND_NONE
)
||
!
haveImage
) {
int
baseline
=
y
+
(
height
+
fmPtr
->
ascent
-
fmPtr
->
descent
) /
2
;
if
(
mePtr
->
labelLength
>
0
) {
const
char
*
label
=
Tcl_GetString
(
mePtr
->
labelPtr
);
Tk_DrawChars
(
menuPtr
->
display
,
d
,
gc
,
tkfont
,
label
,
mePtr
->
labelLength
,
leftEdge
+
textXOffset
,
baseline
+
textYOffset
);
DrawMenuUnderline
(
menuPtr
,
mePtr
,
d
,
gc
,
tkfont
,
fmPtr
,
x
+
textXOffset
,
y
+
textYOffset
,
width
,
height
);
}
}
if
(
mePtr
->
state
==
ENTRY_DISABLED
) {
if
(
menuPtr
->
disabledFgPtr
==
NULL
) {
XFillRectangle
(
menuPtr
->
display
,
d
,
menuPtr
->
disabledGC
,
x
,
y
,
(
unsigned
)
width
, (
unsigned
)
height
);
}
else
if
((
mePtr
->
image
!=
NULL
)
&&
(
menuPtr
->
disabledImageGC
!=
NULL
)) {
XFillRectangle
(
menuPtr
->
display
,
d
,
menuPtr
->
disabledImageGC
,
leftEdge
+
imageXOffset
,
(
int
) (
y
+
(
mePtr
->
height
-
imageHeight
)/
2
+
imageYOffset
),
(
unsigned
)
imageWidth
, (
unsigned
)
imageHeight
);
}
}
}
/*
*----------------------------------------------------------------------
*
* DrawMenuUnderline --
*
* On appropriate platforms, draw the underline character for the menu.
*
* Results:
* None.
*
* Side effects:
* Commands are output to X to display the menu in its current mode.
*
*----------------------------------------------------------------------
*/
static
void
DrawMenuUnderline
(
TkMenu
*
menuPtr
,
/* The menu to draw into */
TkMenuEntry
*
mePtr
,
/* The entry we are drawing */
Drawable
d
,
/* What we are drawing into */
GC
gc
,
/* The gc to draw into */
Tk_Font
tkfont
,
/* The precalculated font */
const
Tk_FontMetrics
*
fmPtr
,
/* The precalculated font metrics */
int
x
,
int
y
,
TCL_UNUSED
(
int
),
int
height
)
{
if
(
mePtr
->
labelPtr
!=
NULL
) {
int
len
;
len
=
Tcl_GetCharLength
(
mePtr
->
labelPtr
);
if
(
mePtr
->
underline
<
len
&&
mePtr
->
underline
>=
-
len
) {
int
activeBorderWidth
,
leftEdge
,
ch
;
const
char
*
label
,
*
start
,
*
end
;
label
=
Tcl_GetString
(
mePtr
->
labelPtr
);
start
=
Tcl_UtfAtIndex
(
label
, (
mePtr
->
underline
<
0
) ?
mePtr
->
underline
+
len
:
mePtr
->
underline
);
end
=
start
+
Tcl_UtfToUniChar
(
start
,
&
ch
);
Tk_GetPixelsFromObj
(
NULL
,
menuPtr
->
tkwin
,
menuPtr
->
activeBorderWidthPtr
,
&
activeBorderWidth
);
leftEdge
=
x
+
mePtr
->
indicatorSpace
+
activeBorderWidth
;
if
(
menuPtr
->
menuType
==
MENUBAR
) {
double
scalingLevel
=
TkScalingLevel
(
menuPtr
->
tkwin
);
leftEdge
+=
(
int
)
round
(
5
*
scalingLevel
);
}
Tk_UnderlineChars
(
menuPtr
->
display
,
d
,
gc
,
tkfont
,
label
,
leftEdge
,
y
+
(
height
+
fmPtr
->
ascent
-
fmPtr
->
descent
) /
2
,
start
-
label
,
end
-
label
);
}
}
}
/*
*----------------------------------------------------------------------
*
* TkpPostMenu --
*
* Posts a menu on the screen so that the top left corner of the
* specified entry is located at the point (x, y) in screen coordinates.
* If the entry parameter is negative, the upper left corner of the
* menu itself is placed at the point.
*
* Results:
* None.
*
* Side effects:
* The menu is posted and handled.
*
*----------------------------------------------------------------------
*/
int
TkpPostMenu
(
Tcl_Interp
*
interp
,
TkMenu
*
menuPtr
,
int
x
,
int
y
,
Tcl_Size
index
)
{
return
TkpPostTearoffMenu
(
interp
,
menuPtr
,
x
,
y
,
index
);
}
/*
*----------------------------------------------------------------------
*
* TkpPostTearoffMenu --
*
* Posts a tearoff menu on the screen so that the top left corner of the
* specified entry is located at the point (x, y) in screen coordinates.
* If the index parameter is negative, the upper left corner of the menu
* itself is placed at the point. On unix this is called when posting
* any menu. Adjusts the menu's position so that it fits on the screen,
* and maps and raises the menu.
*
* Results:
* Returns a standard Tcl Error.
*
* Side effects:
* The menu is posted.
*
*----------------------------------------------------------------------
*/
int
TkpPostTearoffMenu
(
TCL_UNUSED
(
Tcl_Interp
*
),
/* The interpreter of the menu */
TkMenu
*
menuPtr
,
/* The menu we are posting */
int
x
,
int
y
,
Tcl_Size
index
)
/* The root X,Y coordinates where the
* specified entry will be posted */
{
int
vRootX
,
vRootY
,
vRootWidth
,
vRootHeight
;
int
result
;
TkActivateMenuEntry
(
menuPtr
,
TCL_INDEX_NONE
);
TkRecomputeMenu
(
menuPtr
);
result
=
TkPostCommand
(
menuPtr
);
if
(
result
!=
TCL_OK
) {
return
result
;
}
/*
* The post commands could have deleted the menu, which means we are dead
* and should go away.
*/
if
(
menuPtr
->
tkwin
==
NULL
) {
return
TCL_OK
;
}
/*
* Adjust the menu y position so that the specified entry will be located
* at the given coordinates.
*/
if
(
index
>=
menuPtr
->
numEntries
) {
index
=
menuPtr
->
numEntries
-
1
;
}
if
(
index
>=
0
) {
y
-=
menuPtr
->
entries
[
index
]
->
y
;
}
/*
* Adjust the position of the menu if necessary to keep it visible on the
* screen. There are two special tricks to make this work right:
*
* 1. If a virtual root window manager is being used then the coordinates
* are in the virtual root window of menuPtr's parent; since the menu
* uses override-redirect mode it will be in the *real* root window for
* the screen, so we have to map the coordinates from the virtual root
* (if any) to the real root. Can't get the virtual root from the menu
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL