-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui_motif.c
3907 lines (3459 loc) · 98.8 KB
/
gui_motif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
* GUI/Motif support by Robert Webb
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
#include "vim.h"
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Separator.h>
#include <Xm/Label.h>
#include <Xm/CascadeB.h>
#include <Xm/ScrollBar.h>
#include <Xm/MenuShell.h>
#include <Xm/DrawingA.h>
#if (XmVersion >= 1002)
# include <Xm/RepType.h>
#endif
#include <Xm/Frame.h>
#include <Xm/LabelG.h>
#include <Xm/ToggleBG.h>
#include <Xm/SeparatoG.h>
#include <Xm/XmP.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#ifdef HAVE_X11_XPM_H
# if defined(VMS)
# include <xpm.h>
# else
# include <X11/xpm.h>
# endif
#else
# ifdef HAVE_XM_XPMP_H
# include <Xm/XpmP.h>
# endif
#endif
#ifdef HAVE_XM_NOTEBOOK_H
# include <Xm/Notebook.h>
#endif
#include "gui_xmebw.h" // for our Enhanced Button Widget
#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
# include "../pixmaps/alert.xpm"
# include "../pixmaps/error.xpm"
# include "../pixmaps/generic.xpm"
# include "../pixmaps/info.xpm"
# include "../pixmaps/quest.xpm"
#endif
#define MOTIF_POPUP
extern Widget vimShell;
static Widget vimForm;
static Widget textAreaForm;
Widget textArea;
#ifdef FEAT_TOOLBAR
static Widget toolBarFrame;
static Widget toolBar;
#endif
#ifdef FEAT_GUI_TABLINE
static Widget tabLine;
static Widget tabLine_menu = 0;
static int showing_tabline = 0;
#endif
#ifdef FEAT_MENU
# if (XmVersion >= 1002)
// remember the last set value for the tearoff item
static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
# endif
static Widget menuBar;
#endif
#ifdef FEAT_TOOLBAR
static void reset_focus(void);
#endif
static void gui_motif_menu_colors(Widget id);
static void gui_motif_scroll_colors(Widget id);
#if (XmVersion >= 1002)
# define STRING_TAG XmFONTLIST_DEFAULT_TAG
#else
# define STRING_TAG XmSTRING_DEFAULT_CHARSET
#endif
/*
* Call-back routines.
*/
static void
scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
{
scrollbar_T *sb;
long value;
int dragging;
sb = gui_find_scrollbar((long)client_data);
value = ((XmScrollBarCallbackStruct *)call_data)->value;
dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
(int)XmCR_DRAG);
gui_drag_scrollbar(sb, value, dragging);
}
#ifdef FEAT_GUI_TABLINE
static void
tabline_cb(
Widget w UNUSED,
XtPointer client_data UNUSED,
XtPointer call_data)
{
XmNotebookCallbackStruct *nptr;
nptr = (XmNotebookCallbackStruct *)call_data;
if (nptr->reason != (int)XmCR_NONE)
send_tabline_event(nptr->page_number);
}
static void
tabline_button_cb(
Widget w,
XtPointer client_data UNUSED,
XtPointer call_data UNUSED)
{
XtPointer cmd, tab_idx;
XtVaGetValues(w, XmNuserData, &cmd, NULL);
XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
send_tabline_menu_event((int)(long)tab_idx, (int)(long)cmd);
}
/*
* Tabline single mouse click timeout handler
*/
static void
motif_tabline_timer_cb (
XtPointer timed_out,
XtIntervalId *interval_id UNUSED)
{
*((int *)timed_out) = TRUE;
}
/*
* check if the tabline tab scroller is clicked
*/
static int
tabline_scroller_clicked(
char *scroller_name,
XButtonPressedEvent *event)
{
Widget tab_scroll_w;
Position pos_x, pos_y;
Dimension width, height;
tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
if (tab_scroll_w != (Widget)0)
{
XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
&width, XmNheight, &height, NULL);
if (pos_x >= 0)
{
// Tab scroller (next) is visible
if (event->x >= pos_x && event->x <= pos_x + width
&& event->y >= pos_y && event->y <= pos_y + height)
// Clicked on the scroller
return TRUE;
}
}
return FALSE;
}
static void
tabline_menu_cb(
Widget w,
XtPointer closure UNUSED,
XEvent *e,
Boolean *continue_dispatch UNUSED)
{
Widget tab_w;
XButtonPressedEvent *event;
int tab_idx = 0;
WidgetList children;
Cardinal numChildren;
static XtIntervalId timer = (XtIntervalId)0;
static int timed_out = TRUE;
event = (XButtonPressedEvent *)e;
if (event->button == Button1)
{
if (tabline_scroller_clicked("MajorTabScrollerNext", event)
|| tabline_scroller_clicked("MajorTabScrollerPrevious", event))
return;
if (!timed_out)
{
XtRemoveTimeOut(timer);
timed_out = TRUE;
/*
* Double click on the tabline gutter, add a new tab
*/
send_tabline_menu_event(0, TABLINE_MENU_NEW);
}
else
{
/*
* Single click on the tabline gutter, start a timer to check
* for double clicks
*/
timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
motif_tabline_timer_cb, &timed_out);
timed_out = FALSE;
}
return;
}
if (event->button == Button2)
{
// Middle mouse click on tabpage label closes that tab.
XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
send_tabline_menu_event(tab_idx, (int)TABLINE_MENU_CLOSE);
return;
}
if (event->button != Button3)
return;
// When ignoring events don't show the menu.
if (hold_gui_events || cmdwin_type != 0)
return;
if (event->subwindow != None)
{
tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
// LINTED: avoid warning: dubious operation on enum
if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
}
XtVaSetValues(tabLine_menu, XmNuserData, (XtPointer)(long)tab_idx, NULL);
XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
&numChildren, NULL);
XtManageChildren(children, numChildren);
XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
XtManageChild(tabLine_menu);
}
static void
tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
{
int nr;
tabpage_T *tp;
if (beval->target == (Widget)0)
return;
XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
tp = find_tabpage(nr);
if (tp == NULL)
return;
get_tabline_label(tp, TRUE);
gui_mch_post_balloon(beval, NameBuff);
}
#endif
/*
* End of call-back routines
*/
/*
* Implement three dimensional shading of insensitive labels.
* By Marcin Dalecki.
*/
#include <Xm/XmP.h>
#include <Xm/LabelP.h>
static XtExposeProc old_label_expose = NULL;
static void
label_expose(Widget _w, XEvent *_event, Region _region)
{
GC insensitiveGC;
XmLabelWidget lw = (XmLabelWidget)_w;
unsigned char label_type = (int)XmSTRING;
XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
(*old_label_expose)(_w, _event, _region);
else
{
XGCValues values;
XtGCMask mask;
XtGCMask dynamic;
XFontStruct *fs;
_XmFontListGetDefaultFont(lw->label.font, &fs);
// FIXME: we should be doing the whole drawing ourself here.
insensitiveGC = lw->label.insensitive_GC;
mask = GCForeground | GCBackground | GCGraphicsExposures;
dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
values.graphics_exposures = False;
if (fs != 0)
{
mask |= GCFont;
values.font = fs->fid;
}
if (lw->primitive.top_shadow_pixmap != None
&& lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
{
mask |= GCFillStyle | GCTile;
values.fill_style = FillTiled;
values.tile = lw->primitive.top_shadow_pixmap;
}
lw->label.TextRect.x += 1;
lw->label.TextRect.y += 1;
if (lw->label._acc_text != 0)
{
lw->label.acc_TextRect.x += 1;
lw->label.acc_TextRect.y += 1;
}
values.foreground = lw->primitive.top_shadow_color;
values.background = lw->core.background_pixel;
lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
&values, dynamic, (XtGCMask)0);
(*old_label_expose)(_w, _event, _region);
XtReleaseGC(_w, lw->label.insensitive_GC);
lw->label.TextRect.x -= 1;
lw->label.TextRect.y -= 1;
if (lw->label._acc_text != 0)
{
lw->label.acc_TextRect.x -= 1;
lw->label.acc_TextRect.y -= 1;
}
values.foreground = lw->primitive.bottom_shadow_color;
values.background = lw->core.background_pixel;
lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
&values, dynamic, (XtGCMask)0);
(*old_label_expose)(_w, _event, _region);
XtReleaseGC(_w, lw->label.insensitive_GC);
lw->label.insensitive_GC = insensitiveGC;
}
}
/*
* Create all the motif widgets necessary.
*/
void
gui_x11_create_widgets(void)
{
#ifdef FEAT_GUI_TABLINE
Widget button, scroller;
Arg args[10];
int n;
XmString xms;
#endif
/*
* Install the 3D shade effect drawing routines.
*/
if (old_label_expose == NULL)
{
old_label_expose = xmLabelWidgetClass->core_class.expose;
xmLabelWidgetClass->core_class.expose = label_expose;
}
/*
* Start out by adding the configured border width into the border offset
*/
gui.border_offset = gui.border_width;
/*
* Install the tearOffModel resource converter.
*/
#if (XmVersion >= 1002)
XmRepTypeInstallTearOffModelConverter();
#endif
// Make sure the "Quit" menu entry of the window manager is ignored
XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
vimForm = XtVaCreateManagedWidget("vimForm",
xmFormWidgetClass, vimShell,
XmNborderWidth, 0,
XmNhighlightThickness, 0,
XmNshadowThickness, 0,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNresizePolicy, XmRESIZE_ANY,
NULL);
gui_motif_menu_colors(vimForm);
#ifdef FEAT_MENU
{
Arg al[7]; // Make sure there is enough room for arguments!
int ac = 0;
# if (XmVersion >= 1002)
XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
# endif
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
# ifndef FEAT_TOOLBAR
// Always stick to right hand side.
XtSetArg(al[ac], XmNrightOffset, 0); ac++;
# endif
XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
XtManageChild(menuBar);
gui_motif_menu_colors(menuBar);
}
#endif
#ifdef FEAT_TOOLBAR
/*
* Create an empty ToolBar. We should get buttons defined from menu.vim.
*/
toolBarFrame = XtVaCreateWidget("toolBarFrame",
xmFrameWidgetClass, vimForm,
XmNshadowThickness, 0,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
gui_motif_menu_colors(toolBarFrame);
toolBar = XtVaCreateManagedWidget("toolBar",
xmRowColumnWidgetClass, toolBarFrame,
XmNchildType, XmFRAME_WORKAREA_CHILD,
XmNrowColumnType, XmWORK_AREA,
XmNorientation, XmHORIZONTAL,
XmNtraversalOn, False,
XmNisHomogeneous, False,
XmNpacking, XmPACK_TIGHT,
XmNspacing, 0,
XmNshadowThickness, 0,
XmNhighlightThickness, 0,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNadjustLast, True,
NULL);
gui_motif_menu_colors(toolBar);
#endif
#ifdef FEAT_GUI_TABLINE
// Create the Vim GUI tabline
n = 0;
XtSetArg(args[n], XmNbindingType, XmNONE); n++;
XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
XtSetArg(args[n], XmNbackPageNumber, 0); n++;
XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
XtSetArg(args[n], XmNshadowThickness, 0); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
NULL);
XtAddEventHandler(tabLine, ButtonPressMask, False,
(XtEventHandler)tabline_menu_cb, NULL);
gui.tabline_height = TABLINE_HEIGHT;
/*
* Set the size of the minor next/prev scrollers to zero, so
* that they are not displayed. Due to a bug in OpenMotif 2.3,
* even if these children widget are unmanaged, they are again
* managed by the Notebook widget and the notebook widget geometry
* is adjusted to account for the minor scroller widgets.
*/
scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
XmNtraversalOn, False, NULL);
scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
XmNtraversalOn, False, NULL);
// Create the tabline popup menu
tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
// Add the buttons to the tabline popup menu
n = 0;
XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_CLOSE); n++;
xms = XmStringCreate((char *)"Close tab", STRING_TAG);
XtSetArg(args[n], XmNlabelString, xms); n++;
button = XmCreatePushButton(tabLine_menu, "Close", args, n);
XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
XmStringFree(xms);
n = 0;
XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_NEW); n++;
xms = XmStringCreate((char *)"New Tab", STRING_TAG);
XtSetArg(args[n], XmNlabelString, xms); n++;
button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
XmStringFree(xms);
n = 0;
XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_OPEN); n++;
xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
XtSetArg(args[n], XmNlabelString, xms); n++;
button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
XmStringFree(xms);
#endif
textAreaForm = XtVaCreateManagedWidget("textAreaForm",
xmFormWidgetClass, vimForm,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNresizePolicy, XmRESIZE_ANY,
NULL);
gui_motif_scroll_colors(textAreaForm);
textArea = XtVaCreateManagedWidget("textArea",
xmDrawingAreaWidgetClass, textAreaForm,
XmNforeground, gui.norm_pixel,
XmNbackground, gui.back_pixel,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
/*
* These take some control away from the user, but avoids making them
* add resources to get a decent looking setup.
*/
XmNborderWidth, 0,
XmNhighlightThickness, 0,
XmNshadowThickness, 0,
NULL);
/*
* Install the callbacks.
*/
gui_x11_callbacks(textArea, vimForm);
// Pretend we don't have input focus, we will get an event if we do.
gui.in_focus = FALSE;
}
/*
* Called when the GUI is not going to start after all.
*/
void
gui_x11_destroy_widgets(void)
{
textArea = NULL;
#ifdef FEAT_MENU
menuBar = NULL;
#endif
}
void
gui_mch_set_text_area_pos(
int x UNUSED,
int y UNUSED,
int w UNUSED,
int h UNUSED)
{
#ifdef FEAT_TOOLBAR
// Give keyboard focus to the textArea instead of the toolbar.
reset_focus();
#endif
}
void
gui_x11_set_back_color(void)
{
if (textArea != NULL)
#if (XmVersion >= 1002)
XmChangeColor(textArea, gui.back_pixel);
#else
XtVaSetValues(textArea,
XmNbackground, gui.back_pixel,
NULL);
#endif
}
/*
* Manage dialog centered on pointer.
*/
void
manage_centered(Widget dialog_child)
{
Widget shell = XtParent(dialog_child);
Window root, child;
unsigned int mask;
unsigned int width, height, border_width, depth;
int x, y, win_x, win_y, maxX, maxY;
Boolean mappedWhenManaged;
// Temporarily set value of XmNmappedWhenManaged
// to stop the dialog from popping up right away
XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
XtManageChild(dialog_child);
// Get the pointer position (x, y)
XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
&x, &y, &win_x, &win_y, &mask);
// Translate the pointer position (x, y) into a position for the new
// window that will place the pointer at its center
XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
&width, &height, &border_width, &depth);
width += 2 * border_width;
height += 2 * border_width;
x -= width / 2;
y -= height / 2;
// Ensure that the dialog remains on screen
maxX = XtScreen(shell)->width - width;
maxY = XtScreen(shell)->height - height;
if (x < 0)
x = 0;
if (x > maxX)
x = maxX;
if (y < 0)
y = 0;
if (y > maxY)
y = maxY;
// Set desired window position in the DialogShell
XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
// Map the widget
XtMapWidget(shell);
// Restore the value of XmNmappedWhenManaged
XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
}
#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
/*
* Encapsulate the way an XmFontList is created.
*/
XmFontList
gui_motif_create_fontlist(XFontStruct *font)
{
XmFontList font_list;
# if (XmVersion <= 1001)
// Motif 1.1 method
font_list = XmFontListCreate(font, STRING_TAG);
# else
// Motif 1.2 method
XmFontListEntry font_list_entry;
font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
(XtPointer)font);
font_list = XmFontListAppendEntry(NULL, font_list_entry);
XmFontListEntryFree(&font_list_entry);
# endif
return font_list;
}
# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
XmFontList
gui_motif_fontset2fontlist(XFontSet *fontset)
{
XmFontList font_list;
// Motif 1.2 method
XmFontListEntry font_list_entry;
font_list_entry = XmFontListEntryCreate(STRING_TAG,
XmFONT_IS_FONTSET,
(XtPointer)*fontset);
font_list = XmFontListAppendEntry(NULL, font_list_entry);
XmFontListEntryFree(&font_list_entry);
return font_list;
}
# endif
#endif
#if defined(FEAT_MENU) || defined(PROTO)
/*
* Menu stuff.
*/
static void gui_motif_add_actext(vimmenu_T *menu);
#if (XmVersion >= 1002)
static void toggle_tearoff(Widget wid);
static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
#endif
static void submenu_change(vimmenu_T *mp, int colors);
static void do_set_mnemonics(int enable);
static int menu_enabled = TRUE;
void
gui_mch_enable_menu(int flag)
{
if (flag)
{
XtManageChild(menuBar);
#ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
{
// toolBar is attached to top form
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
}
else
#endif
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
}
}
else
{
XtUnmanageChild(menuBar);
#ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
{
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_FORM,
NULL);
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
}
else
#endif
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_FORM,
NULL);
}
}
}
/*
* Enable or disable mnemonics for the toplevel menus.
*/
void
gui_motif_set_mnemonics(int enable)
{
/*
* Don't enable menu mnemonics when the menu bar is disabled, LessTif
* crashes when using a mnemonic then.
*/
if (!menu_enabled)
enable = FALSE;
do_set_mnemonics(enable);
}
static void
do_set_mnemonics(int enable)
{
vimmenu_T *menu;
FOR_ALL_MENUS(menu)
if (menu->id != (Widget)0)
XtVaSetValues(menu->id,
XmNmnemonic, enable ? menu->mnemonic : NUL,
NULL);
}
void
gui_mch_add_menu(vimmenu_T *menu, int idx)
{
XmString label;
Widget shell;
vimmenu_T *parent = menu->parent;
#ifdef MOTIF_POPUP
if (menu_is_popup(menu->name))
{
Arg arg[2];
int n = 0;
// Only create the popup menu when it's actually used, otherwise there
// is a delay when using the right mouse button.
# if (XmVersion <= 1002)
if (mouse_model_popup())
# endif
{
if (gui.menu_bg_pixel != INVALCOLOR)
{
XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
}
if (gui.menu_fg_pixel != INVALCOLOR)
{
XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
}
menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
arg, n);
menu->id = (Widget)0;
}
return;
}
#endif
if (!menu_is_menubar(menu->name)
|| (parent != NULL && parent->submenu_id == (Widget)0))
return;
label = XmStringCreate((char *)menu->dname, STRING_TAG);
if (label == NULL)
return;
menu->id = XtVaCreateWidget("subMenu",
xmCascadeButtonWidgetClass,
(parent == NULL) ? menuBar : parent->submenu_id,
XmNlabelString, label,
XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
#if (XmVersion >= 1002)
// submenu: count the tearoff item (needed for LessTif)
XmNpositionIndex, idx + (parent != NULL
&& tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
#endif
NULL);
XmStringFree(label);
if (menu->id == (Widget)0) // failed
return;
// The "Help" menu is a special case, and should be placed at the far
// right hand side of the menu-bar. It's recognized by its high priority.
if (parent == NULL && menu->priority >= 9999)
XtVaSetValues(menuBar,
XmNmenuHelpWidget, menu->id,
NULL);
gui_motif_menu_colors(menu->id);
gui_motif_menu_fontlist(menu->id);
// add accelerator text
gui_motif_add_actext(menu);
shell = XtVaCreateWidget("subMenuShell",
xmMenuShellWidgetClass, menu->id,
XmNwidth, 1,
XmNheight, 1,
NULL);
gui_motif_menu_colors(shell);
menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
xmRowColumnWidgetClass, shell,
XmNrowColumnType, XmMENU_PULLDOWN,
NULL);
gui_motif_menu_colors(menu->submenu_id);
if (menu->submenu_id == (Widget)0) // failed
return;
#if (XmVersion >= 1002)
// Set the colors for the tear off widget
toggle_tearoff(menu->submenu_id);
#endif
XtVaSetValues(menu->id,
XmNsubMenuId, menu->submenu_id,
NULL);
// When we add a top-level item to the menu bar, we can figure out how
// high the menu bar should be.
if (parent == NULL)
gui_mch_compute_menu_height(menu->id);
}
/*
* Add mnemonic and accelerator text to a menu button.
*/
static void
gui_motif_add_actext(vimmenu_T *menu)
{
XmString label;
// Add accelerator text, if there is one
if (menu->actext == NULL || menu->id == (Widget)0)
return;
label = XmStringCreate((char *)menu->actext, STRING_TAG);
if (label == NULL)
return;
XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
XmStringFree(label);
}
void
gui_mch_toggle_tearoffs(int enable)
{
#if (XmVersion >= 1002)
if (enable)
tearoff_val = (int)XmTEAR_OFF_ENABLED;
else
tearoff_val = (int)XmTEAR_OFF_DISABLED;