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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
|
/*
* tkUnixMenu.c --
*
* This module implements the UNIX platform-specific features of menus.
*
* Copyright (c) 1996-1997 by Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkUnixMenu.c 1.76 97/11/05 09:08:22
*/
#include "tkPort.h"
#include "default.h"
#include "tkInt.h"
#include "tkUnixInt.h"
#include "tkMenu.h"
/*
* Constants used for menu drawing.
*/
#define MENU_MARGIN_WIDTH 2
#define MENU_DIVIDER_HEIGHT 2
/*
* Platform specific flags for Unix.
*/
#define ENTRY_HELP_MENU ENTRY_PLATFORM_FLAG1
/*
* Procedures used internally.
*/
static void SetHelpMenu _ANSI_ARGS_((TkMenu *menuPtr));
static void DrawMenuEntryAccelerator _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Drawable d, GC gc, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr,
Tk_3DBorder activeBorder, int x, int y,
int width, int height, int drawArrow));
static void DrawMenuEntryBackground _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Drawable d, Tk_3DBorder activeBorder,
Tk_3DBorder bgBorder, int x, int y,
int width, int heigth));
static void DrawMenuEntryIndicator _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Drawable d, GC gc, GC indicatorGC,
Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int x, int y,
int width, int height));
static void DrawMenuEntryLabel _ANSI_ARGS_((
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 _ANSI_ARGS_((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 _ANSI_ARGS_((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 _ANSI_ARGS_((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 _ANSI_ARGS_((TkMenu *menuPtr,
TkMenuEntry *mePtr, Tk_Font tkfont,
CONST Tk_FontMetrics *fmPtr, int *widthPtr,
int *heightPtr));
static void GetMenuLabelGeometry _ANSI_ARGS_((TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
int *widthPtr, int *heightPtr));
static void GetMenuIndicatorGeometry _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
int *widthPtr, int *heightPtr));
static void GetMenuSeparatorGeometry _ANSI_ARGS_((
TkMenu *menuPtr, TkMenuEntry *mePtr,
Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr,
int *widthPtr, int *heightPtr));
static void GetTearoffEntryGeometry _ANSI_ARGS_((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(menuPtr)
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(menuPtr)
TkMenu *menuPtr;
{
/*
* 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(mEntryPtr)
TkMenuEntry *mEntryPtr;
{
/*
* 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
* interp->result contains an error message.
*
* Side effects:
* Configuration information get set for mePtr; old resources
* get freed, if any need it.
*
*----------------------------------------------------------------------
*/
int
TkpConfigureMenuEntry(mePtr)
register 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->name != NULL)) {
TkMenuReferences *menuRefPtr;
menuRefPtr = TkFindMenuReferences(mePtr->menuPtr->interp,
mePtr->name);
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(mePtr)
TkMenuEntry *mePtr;
{
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(tkwin, menuPtr)
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
TkpSetMainMenubar(interp, tkwin, menuName)
Tcl_Interp *interp;
Tk_Window tkwin;
char *menuName;
{
/*
* 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(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
TkMenu *menuPtr; /* The menu we are drawing. */
TkMenuEntry *mePtr; /* The entry we are interested in. */
Tk_Font tkfont; /* The precalculated font */
CONST Tk_FontMetrics *fmPtr; /* The precalculated metrics */
int *widthPtr; /* The resulting width */
int *heightPtr; /* The resulting height */
{
if (!mePtr->hideMargin && mePtr->indicatorOn &&
((mePtr->type == CHECK_BUTTON_ENTRY)
|| (mePtr->type == RADIO_BUTTON_ENTRY))) {
if ((mePtr->image != NULL) || (mePtr->bitmap != None)) {
*widthPtr = (14 * mePtr->height) / 10;
*heightPtr = mePtr->height;
if (mePtr->type == CHECK_BUTTON_ENTRY) {
mePtr->platformEntryData =
(TkMenuPlatformEntryData) ((65 * mePtr->height) / 100);
} else {
mePtr->platformEntryData =
(TkMenuPlatformEntryData) ((75 * mePtr->height) / 100);
}
} else {
*widthPtr = *heightPtr = mePtr->height;
if (mePtr->type == CHECK_BUTTON_ENTRY) {
mePtr->platformEntryData = (TkMenuPlatformEntryData)
((80 * mePtr->height) / 100);
} else {
mePtr->platformEntryData = (TkMenuPlatformEntryData)
mePtr->height;
}
}
} else {
*heightPtr = 0;
*widthPtr = menuPtr->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(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
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) {
*widthPtr = 2 * CASCADE_ARROW_WIDTH;
} else if ((menuPtr->menuType != MENUBAR) && (mePtr->accel != NULL)) {
*widthPtr = Tk_TextWidth(tkfont, mePtr->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(menuPtr, mePtr, d, activeBorder, bgBorder, x, y,
width, height)
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 == tkActiveUid) {
int relief;
bgBorder = activeBorder;
if ((menuPtr->menuType == MENUBAR)
&& ((menuPtr->postedCascade == NULL)
|| (menuPtr->postedCascade != mePtr))) {
relief = TK_RELIEF_FLAT;
} else {
relief = TK_RELIEF_RAISED;
}
Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height,
menuPtr->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(menuPtr, mePtr, d, gc, tkfont, fmPtr, activeBorder,
x, y, width, height, drawArrow)
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 */
Tk_3DBorder activeBorder; /* The border for an active item */
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. */
{
XPoint points[3];
/*
* Draw accelerator or cascade arrow.
*/
if (menuPtr->menuType == MENUBAR) {
return;
}
if ((mePtr->type == CASCADE_ENTRY) && drawArrow) {
points[0].x = x + width - menuPtr->borderWidth
- menuPtr->activeBorderWidth - CASCADE_ARROW_WIDTH;
points[0].y = y + (height - CASCADE_ARROW_HEIGHT)/2;
points[1].x = points[0].x;
points[1].y = points[0].y + CASCADE_ARROW_HEIGHT;
points[2].x = points[0].x + CASCADE_ARROW_WIDTH;
points[2].y = points[0].y + CASCADE_ARROW_HEIGHT/2;
Tk_Fill3DPolygon(menuPtr->tkwin, d, activeBorder, points, 3,
DECORATION_BORDER_WIDTH,
(menuPtr->postedCascade == mePtr)
? TK_RELIEF_SUNKEN : TK_RELIEF_RAISED);
} else if (mePtr->accel != NULL) {
int left = x + mePtr->labelWidth + menuPtr->activeBorderWidth
+ mePtr->indicatorSpace;
if (menuPtr->menuType == MENUBAR) {
left += 5;
}
Tk_DrawChars(menuPtr->display, d, gc, tkfont, mePtr->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(menuPtr, mePtr, d, gc, indicatorGC, tkfont, fmPtr,
x, y, width, height)
TkMenu *menuPtr; /* The menu we are drawing */
TkMenuEntry *mePtr; /* The entry we are drawing */
Drawable d; /* The drawable to draw into */
GC gc; /* The gc to draw with */
GC indicatorGC; /* The gc that indicators draw with */
Tk_Font tkfont; /* The font to draw with */
CONST Tk_FontMetrics *fmPtr; /* The font metrics of the font */
int x; /* The left of the entry rect */
int y; /* The top of the entry rect */
int width; /* Width of menu entry */
int height; /* Height of menu entry */
{
/*
* Draw check-button indicator.
*/
if ((mePtr->type == CHECK_BUTTON_ENTRY)
&& mePtr->indicatorOn) {
int dim, top, left;
dim = (int) mePtr->platformEntryData;
left = x + menuPtr->activeBorderWidth
+ (mePtr->indicatorSpace - dim)/2;
if (menuPtr->menuType == MENUBAR) {
left += 5;
}
top = y + (height - dim)/2;
Tk_Fill3DRectangle(menuPtr->tkwin, d, menuPtr->border, left, top, dim,
dim, DECORATION_BORDER_WIDTH, TK_RELIEF_SUNKEN);
left += DECORATION_BORDER_WIDTH;
top += DECORATION_BORDER_WIDTH;
dim -= 2*DECORATION_BORDER_WIDTH;
if ((dim > 0) && (mePtr->entryFlags
& ENTRY_SELECTED)) {
XFillRectangle(menuPtr->display, d, indicatorGC, left, top,
(unsigned int) dim, (unsigned int) dim);
}
}
/*
* Draw radio-button indicator.
*/
if ((mePtr->type == RADIO_BUTTON_ENTRY)
&& mePtr->indicatorOn) {
XPoint points[4];
int radius;
radius = ((int) mePtr->platformEntryData)/2;
points[0].x = x + (mePtr->indicatorSpace
- (int) mePtr->platformEntryData)/2;
points[0].y = y + (height)/2;
points[1].x = points[0].x + radius;
points[1].y = points[0].y + radius;
points[2].x = points[1].x + radius;
points[2].y = points[0].y;
points[3].x = points[1].x;
points[3].y = points[0].y - radius;
if (mePtr->entryFlags & ENTRY_SELECTED) {
XFillPolygon(menuPtr->display, d, indicatorGC, points, 4, Convex,
CoordModeOrigin);
} else {
Tk_Fill3DPolygon(menuPtr->tkwin, d, menuPtr->border, points, 4,
DECORATION_BORDER_WIDTH, TK_RELIEF_FLAT);
}
Tk_Draw3DPolygon(menuPtr->tkwin, d, menuPtr->border, points, 4,
DECORATION_BORDER_WIDTH, TK_RELIEF_SUNKEN);
}
}
/*
*----------------------------------------------------------------------
*
* 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(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
TkMenu *menuPtr; /* The menu we are drawing */
TkMenuEntry *mePtr; /* The entry we are drawing */
Drawable d; /* The drawable we are using */
GC gc; /* The gc to draw into */
Tk_Font tkfont; /* The font to draw with */
CONST Tk_FontMetrics *fmPtr; /* The font metrics from the font */
int x;
int y;
int width;
int height;
{
XPoint points[2];
int margin;
if (menuPtr->menuType == MENUBAR) {
return;
}
margin = (fmPtr->ascent + fmPtr->descent)/2;
points[0].x = x;
points[0].y = y + height/2;
points[1].x = width - 1;
points[1].y = points[0].y;
Tk_Draw3DPolygon(menuPtr->tkwin, d, menuPtr->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(
menuPtr, /* The menu we are drawing */
mePtr, /* The entry we are drawing */
d, /* What we are drawing into */
gc, /* The gc we are drawing into */
tkfont, /* The precalculated font */
fmPtr, /* The precalculated font metrics */
x, /* left edge */
y, /* right edge */
width, /* width of entry */
height) /* height of entry */
TkMenu *menuPtr;
TkMenuEntry *mePtr;
Drawable d;
GC gc;
Tk_Font tkfont;
CONST Tk_FontMetrics *fmPtr;
int x, y, width, height;
{
int baseline;
int indicatorSpace = mePtr->indicatorSpace;
int leftEdge = x + indicatorSpace + menuPtr->activeBorderWidth;
int imageHeight, imageWidth;
if (menuPtr->menuType == MENUBAR) {
leftEdge += 5;
}
/*
* Draw label or bitmap or image for entry.
*/
baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
if (mePtr->image != NULL) {
Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight);
if ((mePtr->selectImage != NULL)
&& (mePtr->entryFlags & ENTRY_SELECTED)) {
Tk_RedrawImage(mePtr->selectImage, 0, 0,
imageWidth, imageHeight, d, leftEdge,
(int) (y + (mePtr->height - imageHeight)/2));
} else {
Tk_RedrawImage(mePtr->image, 0, 0, imageWidth,
imageHeight, d, leftEdge,
(int) (y + (mePtr->height - imageHeight)/2));
}
} else if (mePtr->bitmap != None) {
int width, height;
Tk_SizeOfBitmap(menuPtr->display,
mePtr->bitmap, &width, &height);
XCopyPlane(menuPtr->display,
mePtr->bitmap, d,
gc, 0, 0, (unsigned) width, (unsigned) height, leftEdge,
(int) (y + (mePtr->height - height)/2), 1);
} else {
if (mePtr->labelLength > 0) {
Tk_DrawChars(menuPtr->display, d, gc,
tkfont, mePtr->label, mePtr->labelLength,
leftEdge, baseline);
DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y,
width, height);
}
}
if (mePtr->state == tkDisabledUid) {
if (menuPtr->disabledFg == NULL) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,
(unsigned) width, (unsigned) height);
} else if ((mePtr->image != NULL)
&& (menuPtr->disabledImageGC != None)) {
XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
leftEdge,
(int) (y + (mePtr->height - imageHeight)/2),
(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(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
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;
int width;
int height;
{
int indicatorSpace = mePtr->indicatorSpace;
if (mePtr->underline >= 0) {
int leftEdge = x + indicatorSpace + menuPtr->activeBorderWidth;
if (menuPtr->menuType == MENUBAR) {
leftEdge += 5;
}
Tk_UnderlineChars(menuPtr->display, d, gc, tkfont, mePtr->label,
leftEdge, y + (height + fmPtr->ascent - fmPtr->descent) / 2,
mePtr->underline, mePtr->underline + 1);
}
}
/*
*----------------------------------------------------------------------
*
* TkpPostMenu --
*
* Posts a menu on the screen
*
* Results:
* None.
*
* Side effects:
* The menu is posted and handled.
*
*----------------------------------------------------------------------
*/
int
TkpPostMenu(interp, menuPtr, x, y)
Tcl_Interp *interp;
TkMenu *menuPtr;
int x;
int y;
{
return TkPostTearoffMenu(interp, menuPtr, x, y);
}
/*
*----------------------------------------------------------------------
*
* GetMenuSeparatorGeometry --
*
* Gets the width and height of the indicator area of a menu.
*
* Results:
* widthPtr and heightPtr are set.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr,
heightPtr)
TkMenu *menuPtr; /* The menu we are measuring */
TkMenuEntry *mePtr; /* The entry we are measuring */
Tk_Font tkfont; /* The precalculated font */
CONST Tk_FontMetrics *fmPtr; /* The precalcualted font metrics */
int *widthPtr; /* The resulting width */
int *heightPtr; /* The resulting height */
{
*widthPtr = 0;
*heightPtr = fmPtr->linespace;
}
/*
*----------------------------------------------------------------------
*
* GetTearoffEntryGeometry --
*
* Gets the width and height of the indicator area of a menu.
*
* Results:
* widthPtr and heightPtr are set.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
GetTearoffEntryGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
TkMenu *menuPtr; /* The menu we are drawing */
TkMenuEntry *mePtr; /* The entry we are measuring */
Tk_Font tkfont; /* The precalculated font */
CONST Tk_FontMetrics *fmPtr; /* The precalculated font metrics */
int *widthPtr; /* The resulting width */
int *heightPtr; /* The resulting height */
{
if (menuPtr->menuType != MASTER_MENU) {
*heightPtr = 0;
*widthPtr = 0;
} else {
*heightPtr = fmPtr->linespace;
*widthPtr = Tk_TextWidth(tkfont, "W", -1);
}
}
/*
*--------------------------------------------------------------
*
* TkpComputeMenubarGeometry --
*
* This procedure is invoked to recompute the size and
* layout of a menu that is a menubar clone.
*
* Results:
* None.
*
* Side effects:
* Fields of menu entries are changed to reflect their
* current positions, and the size of the menu window
* itself may be changed.
*
*--------------------------------------------------------------
*/
void
TkpComputeMenubarGeometry(menuPtr)
TkMenu *menuPtr; /* Structure describing menu. */
{
Tk_Font tkfont;
Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
int width, height;
int i, j;
int x, y, currentRowHeight, currentRowWidth, maxWidth;
int maxWindowWidth;
int lastRowBreak;
int helpMenuIndex = -1;
TkMenuEntry *mePtr;
int lastEntry;
if (menuPtr->tkwin == NULL) {
return;
}
maxWidth = 0;
if (menuPtr->numEntries == 0) {
height = 0;
} else {
maxWindowWidth = Tk_Width(menuPtr->tkwin);
if (maxWindowWidth == 1) {
maxWindowWidth = 0x7ffffff;
}
currentRowHeight = 0;
x = y = menuPtr->borderWidth;
lastRowBreak = 0;
currentRowWidth = 0;
/*
* On the Mac especially, getting font metrics can be quite slow,
* so we want to do it intelligently. We are going to precalculate
* them and pass them down to all of the measureing and drawing
* routines. We will measure the font metrics of the menu once,
* and if an entry has a font set, we will measure it as we come
* to it, and then we decide which set to give the geometry routines.
*/
Tk_GetFontMetrics(menuPtr->tkfont, &menuMetrics);
for (i = 0; i < menuPtr->numEntries; i++) {
mePtr = menuPtr->entries[i];
mePtr->entryFlags &= ~ENTRY_LAST_COLUMN;
tkfont = mePtr->tkfont;
if (tkfont == NULL) {
tkfont = menuPtr->tkfont;
fmPtr = &menuMetrics;
} else {
Tk_GetFontMetrics(tkfont, &entryMetrics);
fmPtr = &entryMetrics;
}
/*
* For every entry, we need to check to see whether or not we
* wrap. If we do wrap, then we have to adjust all of the previous
* entries' height and y position, because when we see them
* the first time, we don't know how big its neighbor might
* be.
*/
if ((mePtr->type == SEPARATOR_ENTRY)
|| (mePtr->type == TEAROFF_ENTRY)) {
mePtr->height = mePtr->width = 0;
} else {
GetMenuLabelGeometry(mePtr, tkfont, fmPtr,
&width, &height);
mePtr->height = height + 2 * menuPtr->activeBorderWidth + 10;
mePtr->width = width;
GetMenuIndicatorGeometry(menuPtr, mePtr,
tkfont, fmPtr, &width, &height);
mePtr->indicatorSpace = width;
if (width > 0) {
mePtr->width += width;
}
mePtr->width += 2 * menuPtr->activeBorderWidth + 10;
}
if (mePtr->entryFlags & ENTRY_HELP_MENU) {
helpMenuIndex = i;
} else if (x + mePtr->width + menuPtr->borderWidth
> maxWindowWidth) {
if (i == lastRowBreak) {
mePtr->y = y;
mePtr->x = x;
lastRowBreak++;
y += mePtr->height;
currentRowHeight = 0;
} else {
x = menuPtr->borderWidth;
for (j = lastRowBreak; j < i; j++) {
menuPtr->entries[j]->y = y + currentRowHeight
- menuPtr->entries[j]->height;
menuPtr->entries[j]->x = x;
x += menuPtr->entries[j]->width;
}
lastRowBreak = i;
y += currentRowHeight;
currentRowHeight = mePtr->height;
}
if (x > maxWidth) {
maxWidth = x;
}
x = menuPtr->borderWidth;
} else {
x += mePtr->width;
if (mePtr->height > currentRowHeight) {
currentRowHeight = mePtr->height;
}
}
}
lastEntry = menuPtr->numEntries - 1;
if (helpMenuIndex == lastEntry) {
lastEntry--;
}
if ((lastEntry >= 0) && (x + menuPtr->entries[lastEntry]->width
+ menuPtr->borderWidth > maxWidth)) {
maxWidth = x + menuPtr->entries[lastEntry]->width
+ menuPtr->borderWidth;
}
x = menuPtr->borderWidth;
for (j = lastRowBreak; j < menuPtr->numEntries; j++) {
if (j == helpMenuIndex) {
continue;
}
menuPtr->entries[j]->y = y + currentRowHeight
- menuPtr->entries[j]->height;
menuPtr->entries[j]->x = x;
x += menuPtr->entries[j]->width;
}
if (helpMenuIndex != -1) {
mePtr = menuPtr->entries[helpMenuIndex];
if (x + mePtr->width + menuPtr->borderWidth > maxWindowWidth) {
y += currentRowHeight;
currentRowHeight = mePtr->height;
x = menuPtr->borderWidth;
} else if (mePtr->height > currentRowHeight) {
currentRowHeight = mePtr->height;
}
mePtr->x = maxWindowWidth - menuPtr->borderWidth - mePtr->width;
mePtr->y = y + currentRowHeight - mePtr->height;
}
height = y + currentRowHeight + menuPtr->borderWidth;
}
width = Tk_Width(menuPtr->tkwin);
/*
* The X server doesn't like zero dimensions, so round up to at least
* 1 (a zero-sized menu should never really occur, anyway).
*/
if (width <= 0) {
width = 1;
}
if (height <= 0) {
height = 1;
}
menuPtr->totalWidth = maxWidth;
menuPtr->totalHeight = height;
}
/*
*----------------------------------------------------------------------
*
* DrawTearoffEntry --
*
* 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
DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
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 gc we are drawing with */
Tk_Font tkfont; /* The font we are drawing with */
CONST Tk_FontMetrics *fmPtr; /* The metrics we are drawing with */
int x;
int y;
int width;
int height;
{
XPoint points[2];
int margin, segmentWidth, maxX;
if (menuPtr->menuType != MASTER_MENU) {
return;
}
margin = (fmPtr->ascent + fmPtr->descent)/2;
points[0].x = x;
points[0].y = y + height/2;
points[1].y = points[0].y;
segmentWidth = 6;
maxX = width - 1;
while (points[0].x < maxX) {
points[1].x = points[0].x + segmentWidth;
if (points[1].x > maxX) {
points[1].x = maxX;
}
Tk_Draw3DPolygon(menuPtr->tkwin, d, menuPtr->border, points, 2, 1,
TK_RELIEF_RAISED);
points[0].x += 2*segmentWidth;
}
}
/*
*--------------------------------------------------------------
*
* TkpInitializeMenuBindings --
*
* For every interp, initializes the bindings for Windows
* menus. Does nothing on Mac or XWindows.
*
* Results:
* None.
*
* Side effects:
* C-level bindings are setup for the interp which will
* handle Alt-key sequences for menus without beeping
* or interfering with user-defined Alt-key bindings.
*
*--------------------------------------------------------------
*/
void
TkpInitializeMenuBindings(interp, bindingTable)
Tcl_Interp *interp; /* The interpreter to set. */
Tk_BindingTable bindingTable; /* The table to add to. */
{
/*
* Nothing to do.
*/
}
/*
*----------------------------------------------------------------------
*
* SetHelpMenu --
*
* Given a menu, check to see whether or not it is a help menu
* cascade in a menubar. If it is, the entry that points to
* this menu will be marked.
*
* RESULTS:
* None.
*
* Side effects:
* Will set the ENTRY_HELP_MENU flag appropriately.
*
*----------------------------------------------------------------------
*/
static void
SetHelpMenu(menuPtr)
TkMenu *menuPtr; /* The menu we are checking */
{
TkMenuEntry *cascadeEntryPtr;
for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
cascadeEntryPtr != NULL;
cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
if ((cascadeEntryPtr->menuPtr->menuType == MENUBAR)
&& (cascadeEntryPtr->menuPtr->masterMenuPtr->tkwin != NULL)
&& (menuPtr->masterMenuPtr->tkwin != NULL)) {
TkMenu *masterMenuPtr = cascadeEntryPtr->menuPtr->masterMenuPtr;
char *helpMenuName = ckalloc(strlen(Tk_PathName(
masterMenuPtr->tkwin)) + strlen(".help") + 1);
strcpy(helpMenuName, Tk_PathName(masterMenuPtr->tkwin));
strcat(helpMenuName, ".help");
if (strcmp(helpMenuName,
Tk_PathName(menuPtr->masterMenuPtr->tkwin)) == 0) {
cascadeEntryPtr->entryFlags |= ENTRY_HELP_MENU;
} else {
cascadeEntryPtr->entryFlags &= ~ENTRY_HELP_MENU;
}
ckfree(helpMenuName);
}
}
}
/*
*----------------------------------------------------------------------
*
* TkpDrawMenuEntry --
*
* Draws the given menu entry at the given coordinates with the
* given attributes.
*
* Results:
* None.
*
* Side effects:
* X Server commands are executed to display the menu entry.
*
*----------------------------------------------------------------------
*/
void
TkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height,
strictMotif, drawArrow)
TkMenuEntry *mePtr; /* The entry to draw */
Drawable d; /* What to draw into */
Tk_Font tkfont; /* Precalculated font for menu */
CONST Tk_FontMetrics *menuMetricsPtr;
/* Precalculated metrics for menu */
int x; /* X-coordinate of topleft of entry */
int y; /* Y-coordinate of topleft of entry */
int width; /* Width of the entry rectangle */
int height; /* Height of the current rectangle */
int strictMotif; /* Boolean flag */
int drawArrow; /* Whether or not to draw the cascade
* arrow for cascade items. Only applies
* to Windows. */
{
GC gc, indicatorGC;
TkMenu *menuPtr = mePtr->menuPtr;
Tk_3DBorder bgBorder, activeBorder;
CONST Tk_FontMetrics *fmPtr;
Tk_FontMetrics entryMetrics;
int padY = (menuPtr->menuType == MENUBAR) ? 3 : 0;
int adjustedY = y + padY;
int adjustedHeight = height - 2 * padY;
/*
* Choose the gc for drawing the foreground part of the entry.
*/
if ((mePtr->state == tkActiveUid)
&& !strictMotif) {
gc = mePtr->activeGC;
if (gc == NULL) {
gc = menuPtr->activeGC;
}
} else {
TkMenuEntry *cascadeEntryPtr;
int parentDisabled = 0;
for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
cascadeEntryPtr != NULL;
cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
if (strcmp(cascadeEntryPtr->name,
Tk_PathName(menuPtr->tkwin)) == 0) {
if (cascadeEntryPtr->state == tkDisabledUid) {
parentDisabled = 1;
}
break;
}
}
if (((parentDisabled || (mePtr->state == tkDisabledUid)))
&& (menuPtr->disabledFg != NULL)) {
gc = mePtr->disabledGC;
if (gc == NULL) {
gc = menuPtr->disabledGC;
}
} else {
gc = mePtr->textGC;
if (gc == NULL) {
gc = menuPtr->textGC;
}
}
}
indicatorGC = mePtr->indicatorGC;
if (indicatorGC == NULL) {
indicatorGC = menuPtr->indicatorGC;
}
bgBorder = mePtr->border;
if (bgBorder == NULL) {
bgBorder = menuPtr->border;
}
if (strictMotif) {
activeBorder = bgBorder;
} else {
activeBorder = mePtr->activeBorder;
if (activeBorder == NULL) {
activeBorder = menuPtr->activeBorder;
}
}
if (mePtr->tkfont == NULL) {
fmPtr = menuMetricsPtr;
} else {
tkfont = mePtr->tkfont;
Tk_GetFontMetrics(tkfont, &entryMetrics);
fmPtr = &entryMetrics;
}
/*
* Need to draw the entire background, including padding. On Unix,
* for menubars, we have to draw the rest of the entry taking
* into account the padding.
*/
DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder,
bgBorder, x, y, width, height);
if (mePtr->type == SEPARATOR_ENTRY) {
DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont,
fmPtr, x, adjustedY, width, adjustedHeight);
} else if (mePtr->type == TEAROFF_ENTRY) {
DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
width, adjustedHeight);
} else {
DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
width, adjustedHeight);
DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr,
activeBorder, x, adjustedY, width, adjustedHeight, drawArrow);
if (!mePtr->hideMargin) {
DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont,
fmPtr, x, adjustedY, width, adjustedHeight);
}
}
}
/*
*----------------------------------------------------------------------
*
* GetMenuLabelGeometry --
*
* Figures out the size of the label portion of a menu item.
*
* Results:
* widthPtr and heightPtr are filled in with the correct geometry
* information.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
GetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr)
TkMenuEntry *mePtr; /* The entry we are computing */
Tk_Font tkfont; /* The precalculated font */
CONST Tk_FontMetrics *fmPtr; /* The precalculated metrics */
int *widthPtr; /* The resulting width of the label
* portion */
int *heightPtr; /* The resulting height of the label
* portion */
{
TkMenu *menuPtr = mePtr->menuPtr;
if (mePtr->image != NULL) {
Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr);
} else if (mePtr->bitmap != (Pixmap) NULL) {
Tk_SizeOfBitmap(menuPtr->display, mePtr->bitmap, widthPtr, heightPtr);
} else {
*heightPtr = fmPtr->linespace;
if (mePtr->label != NULL) {
*widthPtr = Tk_TextWidth(tkfont, mePtr->label, mePtr->labelLength);
} else {
*widthPtr = 0;
}
}
*heightPtr += 1;
}
/*
*--------------------------------------------------------------
*
* TkpComputeStandardMenuGeometry --
*
* This procedure is invoked to recompute the size and
* layout of a menu that is not a menubar clone.
*
* Results:
* None.
*
* Side effects:
* Fields of menu entries are changed to reflect their
* current positions, and the size of the menu window
* itself may be changed.
*
*--------------------------------------------------------------
*/
void
TkpComputeStandardMenuGeometry(
menuPtr) /* Structure describing menu. */
TkMenu *menuPtr;
{
Tk_Font tkfont;
Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
int x, y, height, width, indicatorSpace, labelWidth, accelWidth;
int windowWidth, windowHeight, accelSpace;
int i, j, lastColumnBreak = 0;
TkMenuEntry *mePtr;
if (menuPtr->tkwin == NULL) {
return;
}
x = y = menuPtr->borderWidth;
indicatorSpace = labelWidth = accelWidth = 0;
windowHeight = windowWidth = 0;
/*
* On the Mac especially, getting font metrics can be quite slow,
* so we want to do it intelligently. We are going to precalculate
* them and pass them down to all of the measuring and drawing
* routines. We will measure the font metrics of the menu once.
* If an entry does not have its own font set, then we give
* the geometry/drawing routines the menu's font and metrics.
* If an entry has its own font, we will measure that font and
* give all of the geometry/drawing the entry's font and metrics.
*/
Tk_GetFontMetrics(menuPtr->tkfont, &menuMetrics);
accelSpace = Tk_TextWidth(menuPtr->tkfont, "M", 1);
for (i = 0; i < menuPtr->numEntries; i++) {
mePtr = menuPtr->entries[i];
tkfont = mePtr->tkfont;
if (tkfont == NULL) {
tkfont = menuPtr->tkfont;
fmPtr = &menuMetrics;
} else {
Tk_GetFontMetrics(tkfont, &entryMetrics);
fmPtr = &entryMetrics;
}
if ((i > 0) && mePtr->columnBreak) {
if (accelWidth != 0) {
labelWidth += accelSpace;
}
for (j = lastColumnBreak; j < i; j++) {
menuPtr->entries[j]->indicatorSpace = indicatorSpace;
menuPtr->entries[j]->labelWidth = labelWidth;
menuPtr->entries[j]->width = indicatorSpace + labelWidth
+ accelWidth + 2 * menuPtr->activeBorderWidth;
menuPtr->entries[j]->x = x;
menuPtr->entries[j]->entryFlags &= ~ENTRY_LAST_COLUMN;
}
x += indicatorSpace + labelWidth + accelWidth
+ 2 * menuPtr->activeBorderWidth;
windowWidth = x;
indicatorSpace = labelWidth = accelWidth = 0;
lastColumnBreak = i;
y = menuPtr->borderWidth;
}
if (mePtr->type == SEPARATOR_ENTRY) {
GetMenuSeparatorGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
mePtr->height = height;
} else if (mePtr->type == TEAROFF_ENTRY) {
GetTearoffEntryGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
mePtr->height = height;
labelWidth = width;
} else {
/*
* For each entry, compute the height required by that
* particular entry, plus three widths: the width of the
* label, the width to allow for an indicator to be displayed
* to the left of the label (if any), and the width of the
* accelerator to be displayed to the right of the label
* (if any). These sizes depend, of course, on the type
* of the entry.
*/
GetMenuLabelGeometry(mePtr, tkfont, fmPtr, &width,
&height);
mePtr->height = height;
if (!mePtr->hideMargin) {
width += MENU_MARGIN_WIDTH;
}
if (width > labelWidth) {
labelWidth = width;
}
GetMenuAccelGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
if (height > mePtr->height) {
mePtr->height = height;
}
if (!mePtr->hideMargin) {
width += MENU_MARGIN_WIDTH;
}
if (width > accelWidth) {
accelWidth = width;
}
GetMenuIndicatorGeometry(menuPtr, mePtr, tkfont,
fmPtr, &width, &height);
if (height > mePtr->height) {
mePtr->height = height;
}
if (!mePtr->hideMargin) {
width += MENU_MARGIN_WIDTH;
}
if (width > indicatorSpace) {
indicatorSpace = width;
}
mePtr->height += 2 * menuPtr->activeBorderWidth +
MENU_DIVIDER_HEIGHT;
}
mePtr->y = y;
y += mePtr->height;
if (y > windowHeight) {
windowHeight = y;
}
}
if (accelWidth != 0) {
labelWidth += accelSpace;
}
for (j = lastColumnBreak; j < menuPtr->numEntries; j++) {
menuPtr->entries[j]->indicatorSpace = indicatorSpace;
menuPtr->entries[j]->labelWidth = labelWidth;
menuPtr->entries[j]->width = indicatorSpace + labelWidth
+ accelWidth + 2 * menuPtr->activeBorderWidth;
menuPtr->entries[j]->x = x;
menuPtr->entries[j]->entryFlags |= ENTRY_LAST_COLUMN;
}
windowWidth = x + indicatorSpace + labelWidth + accelWidth
+ 2 * menuPtr->activeBorderWidth + 2 * menuPtr->borderWidth;
windowHeight += menuPtr->borderWidth;
/*
* The X server doesn't like zero dimensions, so round up to at least
* 1 (a zero-sized menu should never really occur, anyway).
*/
if (windowWidth <= 0) {
windowWidth = 1;
}
if (windowHeight <= 0) {
windowHeight = 1;
}
menuPtr->totalWidth = windowWidth;
menuPtr->totalHeight = windowHeight;
}
/*
*----------------------------------------------------------------------
*
* TkpMenuNotifyToplevelCreate --
*
* This routine reconfigures the menu and the clones indicated by
* menuName becuase a toplevel has been created and any system
* menus need to be created. Not applicable to UNIX.
*
* Results:
* None.
*
* Side effects:
* An idle handler is set up to do the reconfiguration.
*
*----------------------------------------------------------------------
*/
void
TkpMenuNotifyToplevelCreate(interp, menuName)
Tcl_Interp *interp; /* The interp the menu lives in. */
char *menuName; /* The name of the menu to
* reconfigure. */
{
/*
* Nothing to do.
*/
}
/*
*----------------------------------------------------------------------
*
* TkpMenuInit --
*
* Does platform-specific initialization of menus.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TkpMenuInit()
{
/*
* Nothing to do.
*/
}
|