blob: 9d13b57b4e351cfe0b24753366f5beea23c754b9 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI/Motif support by Robert Webb
5 *
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
9 */
10
Bram Moolenaarf7506ca2017-02-25 16:01:49 +010011#include "vim.h"
12
Bram Moolenaar071d4272004-06-13 20:20:40 +000013#include <Xm/Form.h>
14#include <Xm/RowColumn.h>
15#include <Xm/PushB.h>
16#include <Xm/Text.h>
17#include <Xm/TextF.h>
18#include <Xm/Separator.h>
19#include <Xm/Label.h>
20#include <Xm/CascadeB.h>
21#include <Xm/ScrollBar.h>
22#include <Xm/MenuShell.h>
23#include <Xm/DrawingA.h>
24#if (XmVersion >= 1002)
25# include <Xm/RepType.h>
26#endif
27#include <Xm/Frame.h>
28#include <Xm/LabelG.h>
29#include <Xm/ToggleBG.h>
30#include <Xm/SeparatoG.h>
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000031#include <Xm/XmP.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33#include <X11/keysym.h>
34#include <X11/Xatom.h>
35#include <X11/StringDefs.h>
36#include <X11/Intrinsic.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#ifdef HAVE_X11_XPM_H
Bram Moolenaar88c86eb2019-01-17 17:13:30 +010038# if defined(VMS)
39# include <xpm.h>
40# else
41# include <X11/xpm.h>
42# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#else
44# ifdef HAVE_XM_XPMP_H
45# include <Xm/XpmP.h>
46# endif
47#endif
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000048#ifdef HAVE_XM_NOTEBOOK_H
49# include <Xm/Notebook.h>
50#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaar734a8672019-12-02 22:49:38 +010052#include "gui_xmebw.h" // for our Enhanced Button Widget
Bram Moolenaarb7fcef52005-01-02 11:31:05 +000053
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
55# include "../pixmaps/alert.xpm"
56# include "../pixmaps/error.xpm"
57# include "../pixmaps/generic.xpm"
58# include "../pixmaps/info.xpm"
59# include "../pixmaps/quest.xpm"
60#endif
61
62#define MOTIF_POPUP
63
64extern Widget vimShell;
65
66static Widget vimForm;
67static Widget textAreaForm;
68Widget textArea;
69#ifdef FEAT_TOOLBAR
70static Widget toolBarFrame;
71static Widget toolBar;
72#endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +000073#ifdef FEAT_GUI_TABLINE
74static Widget tabLine;
75static Widget tabLine_menu = 0;
76static int showing_tabline = 0;
77#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000078#ifdef FEAT_FOOTER
79static Widget footer;
80#endif
81#ifdef FEAT_MENU
82# if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +010083// remember the last set value for the tearoff item
Bram Moolenaar071d4272004-06-13 20:20:40 +000084static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
85# endif
86static Widget menuBar;
87#endif
88
Bram Moolenaar071d4272004-06-13 20:20:40 +000089#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000090# ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +010091static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
92static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000093# endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +010094static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
Bram Moolenaard25c16e2016-01-29 22:13:30 +010097static void gui_motif_menu_colors(Widget id);
98static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100#if (XmVersion >= 1002)
101# define STRING_TAG XmFONTLIST_DEFAULT_TAG
102#else
103# define STRING_TAG XmSTRING_DEFAULT_CHARSET
104#endif
105
106/*
107 * Call-back routines.
108 */
109
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110 static void
Bram Moolenaarc1ab6762016-01-30 19:45:49 +0100111scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112{
113 scrollbar_T *sb;
114 long value;
115 int dragging;
116
117 sb = gui_find_scrollbar((long)client_data);
118
119 value = ((XmScrollBarCallbackStruct *)call_data)->value;
120 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
121 (int)XmCR_DRAG);
122 gui_drag_scrollbar(sb, value, dragging);
123}
124
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000125#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000126 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100127tabline_cb(
128 Widget w UNUSED,
129 XtPointer client_data UNUSED,
130 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000131{
132 XmNotebookCallbackStruct *nptr;
133
134 nptr = (XmNotebookCallbackStruct *)call_data;
135 if (nptr->reason != (int)XmCR_NONE)
136 send_tabline_event(nptr->page_number);
137}
138
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000139 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100140tabline_button_cb(
141 Widget w,
142 XtPointer client_data UNUSED,
143 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000144{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000145 int cmd, tab_idx;
146
147 XtVaGetValues(w, XmNuserData, &cmd, NULL);
148 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
149
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000150 send_tabline_menu_event(tab_idx, cmd);
151}
152
153/*
154 * Tabline single mouse click timeout handler
155 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000156 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100157motif_tabline_timer_cb (
158 XtPointer timed_out,
159 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000160{
161 *((int *)timed_out) = TRUE;
162}
163
164/*
165 * check if the tabline tab scroller is clicked
166 */
167 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100168tabline_scroller_clicked(
169 char *scroller_name,
170 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000171{
172 Widget tab_scroll_w;
173 Position pos_x, pos_y;
174 Dimension width, height;
175
176 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
177 if (tab_scroll_w != (Widget)0) {
178 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
179 &width, XmNheight, &height, NULL);
180 if (pos_x >= 0) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100181 // Tab scroller (next) is visible
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000182 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
183 (event->y >= pos_y) && (event->y <= pos_y + height)) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100184 // Clicked on the scroller
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000185 return TRUE;
186 }
187 }
188 }
189 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000190}
191
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000192 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100193tabline_menu_cb(
194 Widget w,
195 XtPointer closure UNUSED,
196 XEvent *e,
197 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000198{
199 Widget tab_w;
200 XButtonPressedEvent *event;
201 int tab_idx = 0;
202 WidgetList children;
203 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000204 static XtIntervalId timer = (XtIntervalId)0;
205 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000206
207 event = (XButtonPressedEvent *)e;
208
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000209 if (event->button == Button1)
210 {
211 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
212 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
213 return;
214
215 if (!timed_out)
216 {
217 XtRemoveTimeOut(timer);
218 timed_out = TRUE;
219
220 /*
221 * Double click on the tabline gutter, add a new tab
222 */
223 send_tabline_menu_event(0, TABLINE_MENU_NEW);
224 }
225 else
226 {
227 /*
228 * Single click on the tabline gutter, start a timer to check
229 * for double clicks
230 */
231 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
232 motif_tabline_timer_cb, &timed_out);
233 timed_out = FALSE;
234 }
235 return;
236 }
237
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000238 if (event->button != Button3)
239 return;
240
Bram Moolenaar734a8672019-12-02 22:49:38 +0100241 // When ignoring events don't show the menu.
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000242 if (hold_gui_events
243# ifdef FEAT_CMDWIN
244 || cmdwin_type != 0
245# endif
246 )
247 return;
248
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000249 if (event->subwindow != None)
250 {
251 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaar734a8672019-12-02 22:49:38 +0100252 // LINTED: avoid warning: dubious operation on enum
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000253 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
254 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
255 }
256
257 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
258 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
259 &numChildren, NULL);
260 XtManageChildren(children, numChildren);
261 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
262 XtManageChild(tabLine_menu);
263}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000264
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000265 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100266tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000267{
268 int nr;
269 tabpage_T *tp;
270
271 if (beval->target == (Widget)0)
272 return;
273
274 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
275 tp = find_tabpage(nr);
276 if (tp == NULL)
277 return;
278
279 get_tabline_label(tp, TRUE);
280 gui_mch_post_balloon(beval, NameBuff);
281}
282
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000283#endif
284
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285/*
286 * End of call-back routines
287 */
288
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289/*
290 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000291 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000292 */
293
294#include <Xm/XmP.h>
295#include <Xm/LabelP.h>
296
297static XtExposeProc old_label_expose = NULL;
298
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000299 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100300label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000301{
302 GC insensitiveGC;
303 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000304 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000305
306 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
307
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000308 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000309 (*old_label_expose)(_w, _event, _region);
310 else
311 {
312 XGCValues values;
313 XtGCMask mask;
314 XtGCMask dynamic;
315 XFontStruct *fs;
316
317 _XmFontListGetDefaultFont(lw->label.font, &fs);
318
Bram Moolenaar734a8672019-12-02 22:49:38 +0100319 // FIXME: we should be doing the whole drawing ourself here.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000320 insensitiveGC = lw->label.insensitive_GC;
321
322 mask = GCForeground | GCBackground | GCGraphicsExposures;
323 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
324 values.graphics_exposures = False;
325
326 if (fs != 0)
327 {
328 mask |= GCFont;
329 values.font = fs->fid;
330 }
331
332 if (lw->primitive.top_shadow_pixmap != None
333 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
334 {
335 mask |= GCFillStyle | GCTile;
336 values.fill_style = FillTiled;
337 values.tile = lw->primitive.top_shadow_pixmap;
338 }
339
340 lw->label.TextRect.x += 1;
341 lw->label.TextRect.y += 1;
342 if (lw->label._acc_text != 0)
343 {
344 lw->label.acc_TextRect.x += 1;
345 lw->label.acc_TextRect.y += 1;
346 }
347
348 values.foreground = lw->primitive.top_shadow_color;
349 values.background = lw->core.background_pixel;
350
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000351 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
352 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000353 (*old_label_expose)(_w, _event, _region);
354 XtReleaseGC(_w, lw->label.insensitive_GC);
355
356 lw->label.TextRect.x -= 1;
357 lw->label.TextRect.y -= 1;
358 if (lw->label._acc_text != 0)
359 {
360 lw->label.acc_TextRect.x -= 1;
361 lw->label.acc_TextRect.y -= 1;
362 }
363
364 values.foreground = lw->primitive.bottom_shadow_color;
365 values.background = lw->core.background_pixel;
366
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000367 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
368 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000369 (*old_label_expose)(_w, _event, _region);
370 XtReleaseGC(_w, lw->label.insensitive_GC);
371
372 lw->label.insensitive_GC = insensitiveGC;
373 }
374}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000375
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376/*
377 * Create all the motif widgets necessary.
378 */
379 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100380gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000382#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000383 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000384 Arg args[10];
385 int n;
386 XmString xms;
387#endif
388
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000389 /*
390 * Install the 3D shade effect drawing routines.
391 */
392 if (old_label_expose == NULL)
393 {
394 old_label_expose = xmLabelWidgetClass->core_class.expose;
395 xmLabelWidgetClass->core_class.expose = label_expose;
396 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000397
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 /*
399 * Start out by adding the configured border width into the border offset
400 */
401 gui.border_offset = gui.border_width;
402
403 /*
404 * Install the tearOffModel resource converter.
405 */
406#if (XmVersion >= 1002)
407 XmRepTypeInstallTearOffModelConverter();
408#endif
409
Bram Moolenaar734a8672019-12-02 22:49:38 +0100410 // Make sure the "Quit" menu entry of the window manager is ignored
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
412
413 vimForm = XtVaCreateManagedWidget("vimForm",
414 xmFormWidgetClass, vimShell,
415 XmNborderWidth, 0,
416 XmNhighlightThickness, 0,
417 XmNshadowThickness, 0,
418 XmNmarginWidth, 0,
419 XmNmarginHeight, 0,
420 XmNresizePolicy, XmRESIZE_ANY,
421 NULL);
422 gui_motif_menu_colors(vimForm);
423
424#ifdef FEAT_MENU
425 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100426 Arg al[7]; // Make sure there is enough room for arguments!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427 int ac = 0;
428
429# if (XmVersion >= 1002)
430 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
431# endif
432 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
433 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
434 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
435# ifndef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100436 // Always stick to right hand side.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
438# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000439 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
441 XtManageChild(menuBar);
442
Bram Moolenaar734a8672019-12-02 22:49:38 +0100443 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 XtVaGetValues(menuBar,
445 XmNbackground, &gui.menu_def_bg_pixel,
446 XmNforeground, &gui.menu_def_fg_pixel,
447 NULL);
448 gui_motif_menu_colors(menuBar);
449 }
450#endif
451
452#ifdef FEAT_TOOLBAR
453 /*
454 * Create an empty ToolBar. We should get buttons defined from menu.vim.
455 */
456 toolBarFrame = XtVaCreateWidget("toolBarFrame",
457 xmFrameWidgetClass, vimForm,
458 XmNshadowThickness, 0,
459 XmNmarginHeight, 0,
460 XmNmarginWidth, 0,
461 XmNleftAttachment, XmATTACH_FORM,
462 XmNrightAttachment, XmATTACH_FORM,
463 NULL);
464 gui_motif_menu_colors(toolBarFrame);
465
466 toolBar = XtVaCreateManagedWidget("toolBar",
467 xmRowColumnWidgetClass, toolBarFrame,
468 XmNchildType, XmFRAME_WORKAREA_CHILD,
469 XmNrowColumnType, XmWORK_AREA,
470 XmNorientation, XmHORIZONTAL,
471 XmNtraversalOn, False,
472 XmNisHomogeneous, False,
473 XmNpacking, XmPACK_TIGHT,
474 XmNspacing, 0,
475 XmNshadowThickness, 0,
476 XmNhighlightThickness, 0,
477 XmNmarginHeight, 0,
478 XmNmarginWidth, 0,
479 XmNadjustLast, True,
480 NULL);
481 gui_motif_menu_colors(toolBar);
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483#endif
484
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000485#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100486 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000487 n = 0;
488 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
489 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
490 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
491 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
492 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
493 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
494 XtSetArg(args[n], XmNshadowThickness, 0); n++;
495 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
496 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
497 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
498
499 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
500 NULL);
501 XtAddEventHandler(tabLine, ButtonPressMask, False,
502 (XtEventHandler)tabline_menu_cb, NULL);
503
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000504 gui.tabline_height = TABLINE_HEIGHT;
505
Bram Moolenaar18144c82006-04-12 21:52:12 +0000506 /*
507 * Set the size of the minor next/prev scrollers to zero, so
508 * that they are not displayed. Due to a bug in OpenMotif 2.3,
509 * even if these children widget are unmanaged, they are again
510 * managed by the Notebook widget and the notebook widget geometry
511 * is adjusted to account for the minor scroller widgets.
512 */
513 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
514 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
515 XmNtraversalOn, False, NULL);
516 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
517 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
518 XmNtraversalOn, False, NULL);
519
Bram Moolenaar29547192018-12-11 20:39:19 +0100520 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000521 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
522
Bram Moolenaar29547192018-12-11 20:39:19 +0100523 // Add the buttons to the tabline popup menu
524 n = 0;
525 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
526 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
527 XtSetArg(args[n], XmNlabelString, xms); n++;
528 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
529 XtAddCallback(button, XmNactivateCallback,
530 (XtCallbackProc)tabline_button_cb, NULL);
531 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000532
533 n = 0;
534 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
535 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
536 XtSetArg(args[n], XmNlabelString, xms); n++;
537 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
538 XtAddCallback(button, XmNactivateCallback,
539 (XtCallbackProc)tabline_button_cb, NULL);
540 XmStringFree(xms);
541
542 n = 0;
543 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
544 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
545 XtSetArg(args[n], XmNlabelString, xms); n++;
546 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
547 XtAddCallback(button, XmNactivateCallback,
548 (XtCallbackProc)tabline_button_cb, NULL);
549 XmStringFree(xms);
550#endif
551
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
553 xmFormWidgetClass, vimForm,
554 XmNleftAttachment, XmATTACH_FORM,
555 XmNrightAttachment, XmATTACH_FORM,
556 XmNbottomAttachment, XmATTACH_FORM,
557 XmNtopAttachment, XmATTACH_FORM,
558 XmNmarginWidth, 0,
559 XmNmarginHeight, 0,
560 XmNresizePolicy, XmRESIZE_ANY,
561 NULL);
562 gui_motif_scroll_colors(textAreaForm);
563
564 textArea = XtVaCreateManagedWidget("textArea",
565 xmDrawingAreaWidgetClass, textAreaForm,
566 XmNforeground, gui.norm_pixel,
567 XmNbackground, gui.back_pixel,
568 XmNleftAttachment, XmATTACH_FORM,
569 XmNtopAttachment, XmATTACH_FORM,
570 XmNrightAttachment, XmATTACH_FORM,
571 XmNbottomAttachment, XmATTACH_FORM,
572
573 /*
574 * These take some control away from the user, but avoids making them
575 * add resources to get a decent looking setup.
576 */
577 XmNborderWidth, 0,
578 XmNhighlightThickness, 0,
579 XmNshadowThickness, 0,
580 NULL);
581
582#ifdef FEAT_FOOTER
583 /*
584 * Create the Footer.
585 */
586 footer = XtVaCreateWidget("footer",
587 xmLabelGadgetClass, vimForm,
588 XmNalignment, XmALIGNMENT_BEGINNING,
589 XmNmarginHeight, 0,
590 XmNmarginWidth, 0,
591 XmNtraversalOn, False,
592 XmNrecomputeSize, False,
593 XmNleftAttachment, XmATTACH_FORM,
594 XmNleftOffset, 5,
595 XmNrightAttachment, XmATTACH_FORM,
596 XmNbottomAttachment, XmATTACH_FORM,
597 NULL);
598 gui_mch_set_footer((char_u *) "");
599#endif
600
601 /*
602 * Install the callbacks.
603 */
604 gui_x11_callbacks(textArea, vimForm);
605
Bram Moolenaar734a8672019-12-02 22:49:38 +0100606 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 gui.in_focus = FALSE;
608}
609
610/*
611 * Called when the GUI is not going to start after all.
612 */
613 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100614gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615{
616 textArea = NULL;
617#ifdef FEAT_MENU
618 menuBar = NULL;
619#endif
620}
621
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100623gui_mch_set_text_area_pos(
624 int x UNUSED,
625 int y UNUSED,
626 int w UNUSED,
627 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628{
629#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100630 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000631 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
633}
634
635 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100636gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637{
638 if (textArea != NULL)
639#if (XmVersion >= 1002)
640 XmChangeColor(textArea, gui.back_pixel);
641#else
642 XtVaSetValues(textArea,
643 XmNbackground, gui.back_pixel,
644 NULL);
645#endif
646}
647
648/*
649 * Manage dialog centered on pointer. This could be used by the Athena code as
650 * well.
651 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000652 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100653manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654{
655 Widget shell = XtParent(dialog_child);
656 Window root, child;
657 unsigned int mask;
658 unsigned int width, height, border_width, depth;
659 int x, y, win_x, win_y, maxX, maxY;
660 Boolean mappedWhenManaged;
661
Bram Moolenaar734a8672019-12-02 22:49:38 +0100662 // Temporarily set value of XmNmappedWhenManaged
663 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000664 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
665 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666
667 XtManageChild(dialog_child);
668
Bram Moolenaar734a8672019-12-02 22:49:38 +0100669 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
671 &x, &y, &win_x, &win_y, &mask);
672
Bram Moolenaar734a8672019-12-02 22:49:38 +0100673 // Translate the pointer position (x, y) into a position for the new
674 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
676 &width, &height, &border_width, &depth);
677 width += 2 * border_width;
678 height += 2 * border_width;
679 x -= width / 2;
680 y -= height / 2;
681
Bram Moolenaar734a8672019-12-02 22:49:38 +0100682 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 maxX = XtScreen(shell)->width - width;
684 maxY = XtScreen(shell)->height - height;
685 if (x < 0)
686 x = 0;
687 if (x > maxX)
688 x = maxX;
689 if (y < 0)
690 y = 0;
691 if (y > maxY)
692 y = maxY;
693
Bram Moolenaar734a8672019-12-02 22:49:38 +0100694 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
696
Bram Moolenaar734a8672019-12-02 22:49:38 +0100697 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 XtMapWidget(shell);
699
Bram Moolenaar734a8672019-12-02 22:49:38 +0100700 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000701 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702}
703
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100704#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705
706/*
707 * Encapsulate the way an XmFontList is created.
708 */
709 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100710gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711{
712 XmFontList font_list;
713
714# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100715 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 font_list = XmFontListCreate(font, STRING_TAG);
717# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100718 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 XmFontListEntry font_list_entry;
720
721 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
722 (XtPointer)font);
723 font_list = XmFontListAppendEntry(NULL, font_list_entry);
724 XmFontListEntryFree(&font_list_entry);
725# endif
726 return font_list;
727}
728
729# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
730 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100731gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732{
733 XmFontList font_list;
734
Bram Moolenaar734a8672019-12-02 22:49:38 +0100735 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 XmFontListEntry font_list_entry;
737
738 font_list_entry = XmFontListEntryCreate(STRING_TAG,
739 XmFONT_IS_FONTSET,
740 (XtPointer)*fontset);
741 font_list = XmFontListAppendEntry(NULL, font_list_entry);
742 XmFontListEntryFree(&font_list_entry);
743 return font_list;
744}
745# endif
746
747#endif
748
749#if defined(FEAT_MENU) || defined(PROTO)
750/*
751 * Menu stuff.
752 */
753
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100754static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100756static void toggle_tearoff(Widget wid);
757static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100759static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100761static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762static int menu_enabled = TRUE;
763
764 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100765gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766{
767 if (flag)
768 {
769 XtManageChild(menuBar);
770#ifdef FEAT_TOOLBAR
771 if (XtIsManaged(XtParent(toolBar)))
772 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100773 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 XtVaSetValues(XtParent(toolBar),
775 XmNtopAttachment, XmATTACH_WIDGET,
776 XmNtopWidget, menuBar,
777 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000778#ifdef FEAT_GUI_TABLINE
779 if (showing_tabline)
780 {
781 XtVaSetValues(tabLine,
782 XmNtopAttachment, XmATTACH_WIDGET,
783 XmNtopWidget, XtParent(toolBar),
784 NULL);
785 XtVaSetValues(textAreaForm,
786 XmNtopAttachment, XmATTACH_WIDGET,
787 XmNtopWidget, tabLine,
788 NULL);
789 }
790 else
791#endif
792 XtVaSetValues(textAreaForm,
793 XmNtopAttachment, XmATTACH_WIDGET,
794 XmNtopWidget, XtParent(toolBar),
795 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 }
797 else
798#endif
799 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000800#ifdef FEAT_GUI_TABLINE
801 if (showing_tabline)
802 {
803 XtVaSetValues(tabLine,
804 XmNtopAttachment, XmATTACH_WIDGET,
805 XmNtopWidget, menuBar,
806 NULL);
807 XtVaSetValues(textAreaForm,
808 XmNtopAttachment, XmATTACH_WIDGET,
809 XmNtopWidget, tabLine,
810 NULL);
811 }
812 else
813#endif
814 XtVaSetValues(textAreaForm,
815 XmNtopAttachment, XmATTACH_WIDGET,
816 XmNtopWidget, menuBar,
817 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 }
819 }
820 else
821 {
822 XtUnmanageChild(menuBar);
823#ifdef FEAT_TOOLBAR
824 if (XtIsManaged(XtParent(toolBar)))
825 {
826 XtVaSetValues(XtParent(toolBar),
827 XmNtopAttachment, XmATTACH_FORM,
828 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000829#ifdef FEAT_GUI_TABLINE
830 if (showing_tabline)
831 {
832 XtVaSetValues(tabLine,
833 XmNtopAttachment, XmATTACH_WIDGET,
834 XmNtopWidget, XtParent(toolBar),
835 NULL);
836 XtVaSetValues(textAreaForm,
837 XmNtopAttachment, XmATTACH_WIDGET,
838 XmNtopWidget, tabLine,
839 NULL);
840 }
841 else
842#endif
843 XtVaSetValues(textAreaForm,
844 XmNtopAttachment, XmATTACH_WIDGET,
845 XmNtopWidget, XtParent(toolBar),
846 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 }
848 else
849#endif
850 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000851#ifdef FEAT_GUI_TABLINE
852 if (showing_tabline)
853 {
854 XtVaSetValues(tabLine,
855 XmNtopAttachment, XmATTACH_FORM,
856 NULL);
857 XtVaSetValues(textAreaForm,
858 XmNtopAttachment, XmATTACH_WIDGET,
859 XmNtopWidget, tabLine,
860 NULL);
861 }
862 else
863#endif
864 XtVaSetValues(textAreaForm,
865 XmNtopAttachment, XmATTACH_FORM,
866 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 }
868 }
869
870}
871
872/*
873 * Enable or disable mnemonics for the toplevel menus.
874 */
875 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100876gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000877{
878 /*
879 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
880 * crashes when using a mnemonic then.
881 */
882 if (!menu_enabled)
883 enable = FALSE;
884 do_set_mnemonics(enable);
885}
886
887 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100888do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889{
890 vimmenu_T *menu;
891
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200892 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 if (menu->id != (Widget)0)
894 XtVaSetValues(menu->id,
895 XmNmnemonic, enable ? menu->mnemonic : NUL,
896 NULL);
897}
898
899 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100900gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901{
902 XmString label;
903 Widget shell;
904 vimmenu_T *parent = menu->parent;
905
906#ifdef MOTIF_POPUP
907 if (menu_is_popup(menu->name))
908 {
909 Arg arg[2];
910 int n = 0;
911
Bram Moolenaar734a8672019-12-02 22:49:38 +0100912 // Only create the popup menu when it's actually used, otherwise there
913 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914# if (XmVersion <= 1002)
915 if (mouse_model_popup())
916# endif
917 {
918 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
923 arg, n);
924 menu->id = (Widget)0;
925 }
926 return;
927 }
928#endif
929
930 if (!menu_is_menubar(menu->name)
931 || (parent != NULL && parent->submenu_id == (Widget)0))
932 return;
933
934 label = XmStringCreate((char *)menu->dname, STRING_TAG);
935 if (label == NULL)
936 return;
937 menu->id = XtVaCreateWidget("subMenu",
938 xmCascadeButtonWidgetClass,
939 (parent == NULL) ? menuBar : parent->submenu_id,
940 XmNlabelString, label,
941 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
942#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100943 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 XmNpositionIndex, idx + (parent != NULL
945 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
946#endif
947 NULL);
948 gui_motif_menu_colors(menu->id);
949 gui_motif_menu_fontlist(menu->id);
950 XmStringFree(label);
951
Bram Moolenaar734a8672019-12-02 22:49:38 +0100952 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 return;
954
Bram Moolenaar734a8672019-12-02 22:49:38 +0100955 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 gui_motif_add_actext(menu);
957
958 shell = XtVaCreateWidget("subMenuShell",
959 xmMenuShellWidgetClass, menu->id,
960 XmNwidth, 1,
961 XmNheight, 1,
962 NULL);
963 gui_motif_menu_colors(shell);
964 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
965 xmRowColumnWidgetClass, shell,
966 XmNrowColumnType, XmMENU_PULLDOWN,
967 NULL);
968 gui_motif_menu_colors(menu->submenu_id);
969
Bram Moolenaar734a8672019-12-02 22:49:38 +0100970 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 return;
972
973#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100974 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 toggle_tearoff(menu->submenu_id);
976#endif
977
978 XtVaSetValues(menu->id,
979 XmNsubMenuId, menu->submenu_id,
980 NULL);
981
982 /*
983 * The "Help" menu is a special case, and should be placed at the far
984 * right hand side of the menu-bar. It's recognized by its high priority.
985 */
986 if (parent == NULL && menu->priority >= 9999)
987 XtVaSetValues(menuBar,
988 XmNmenuHelpWidget, menu->id,
989 NULL);
990
991 /*
992 * When we add a top-level item to the menu bar, we can figure out how
993 * high the menu bar should be.
994 */
995 if (parent == NULL)
996 gui_mch_compute_menu_height(menu->id);
997}
998
999
1000/*
1001 * Add mnemonic and accelerator text to a menu button.
1002 */
1003 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001004gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005{
1006 XmString label;
1007
Bram Moolenaar734a8672019-12-02 22:49:38 +01001008 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009 if (menu->actext != NULL && menu->id != (Widget)0)
1010 {
1011 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1012 if (label == NULL)
1013 return;
1014 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1015 XmStringFree(label);
1016 }
1017}
1018
1019 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001020gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021{
1022#if (XmVersion >= 1002)
1023 if (enable)
1024 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1025 else
1026 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1027 toggle_tearoff(menuBar);
1028 gui_mch_recurse_tearoffs(root_menu);
1029#endif
1030}
1031
1032#if (XmVersion >= 1002)
1033/*
1034 * Set the tearoff for one menu widget on or off, and set the color of the
1035 * tearoff widget.
1036 */
1037 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001038toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039{
1040 Widget w;
1041
1042 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1043 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1044 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1045 gui_motif_menu_colors(w);
1046}
1047
1048 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001049gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050{
1051 while (menu != NULL)
1052 {
1053 if (!menu_is_popup(menu->name))
1054 {
1055 if (menu->submenu_id != (Widget)0)
1056 toggle_tearoff(menu->submenu_id);
1057 gui_mch_recurse_tearoffs(menu->children);
1058 }
1059 menu = menu->next;
1060 }
1061}
1062#endif
1063
1064 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001065gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066{
1067 Dimension shadowHeight;
1068
1069 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1070 return shadowHeight;
1071}
1072
1073/*
1074 * Compute the height of the menu bar.
1075 * We need to check all the items for their position and height, for the case
1076 * there are several rows, and/or some characters extend higher or lower.
1077 */
1078 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001079gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001080 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081{
1082 Dimension y, maxy;
1083 Dimension margin, shadow;
1084 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001085 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086
1087 /*
1088 * Get the height of the new item, before managing it, because it will
1089 * still reflect the font size. After managing it depends on the menu
1090 * height, which is what we just wanted to get!.
1091 */
1092 if (id != (Widget)0)
1093 XtVaGetValues(id, XmNheight, &height, NULL);
1094
Bram Moolenaar734a8672019-12-02 22:49:38 +01001095 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001097 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1099 {
1100 id = mp->id;
1101 break;
1102 }
1103
1104 /*
1105 * Now manage the menu item, to make them all be positioned (makes an
1106 * extra row when needed, removes it when not needed).
1107 */
1108 if (id != (Widget)0)
1109 XtManageChild(id);
1110
1111 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001112 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 */
1114 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001115 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {
1117 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1118 {
1119 XtVaGetValues(mp->id, XmNy, &y, NULL);
1120 if (y > maxy)
1121 maxy = y;
1122 }
1123 }
1124
1125 XtVaGetValues(menuBar,
1126 XmNmarginHeight, &margin,
1127 XmNshadowThickness, &shadow,
1128 NULL);
1129
1130 /*
1131 * This computation is the result of trial-and-error:
1132 * maxy = The maximum position of an item; required for when there are
1133 * two or more rows
1134 * height = height of an item, before managing it; Hopefully this will
1135 * change with the font height. Includes shadow-border.
1136 * shadow = shadow-border; must be subtracted from the height.
1137 * margin = margin around the menu buttons; Must be added.
1138 * Add 4 for the underlining of shortcut keys.
1139 */
1140 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1141
Bram Moolenaar734a8672019-12-02 22:49:38 +01001142 // Somehow the menu bar doesn't resize automatically. Set it here,
1143 // even though this is a catch 22. Don't do this when starting up,
1144 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 if (gui.shell_created)
1146 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001147}
1148
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001149#ifdef FEAT_TOOLBAR
1150
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001151/*
1152 * Icons used by the toolbar code.
1153 */
1154#include "gui_x11_pm.h"
1155
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001156static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001157
1158/*
1159 * Read an Xpm file. Return OK or FAIL.
1160 */
1161 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001162check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001163{
1164 XpmAttributes attrs;
1165 int status;
1166 Pixmap mask;
1167 Pixmap map;
1168
1169 attrs.valuemask = 0;
1170
Bram Moolenaar734a8672019-12-02 22:49:38 +01001171 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001172 status = XpmReadFileToPixmap(gui.dpy,
1173 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1174 (char *)path, &map, &mask, &attrs);
1175 XpmFreeAttributes(&attrs);
1176
1177 if (status == XpmSuccess)
1178 return OK;
1179 return FAIL;
1180}
1181
1182
1183/*
1184 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001185 * When it's to be read from a file, "fname" is set to the file name
1186 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001187 * Return a blank pixmap if it fails.
1188 */
1189 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001190get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001191{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001192 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1193 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001194 int res;
1195
Bram Moolenaar7c626922005-02-07 22:01:03 +00001196 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001197 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001198
1199 if (menu->iconfile != NULL)
1200 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001201 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001202 gui_find_iconfile(menu->iconfile, buf, "xpm");
1203 res = check_xpm(buf);
1204
Bram Moolenaar734a8672019-12-02 22:49:38 +01001205 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001206 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1207 res = check_xpm(buf);
1208 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001209 {
1210 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001211 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001212 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001213 }
1214
1215 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1216 {
1217 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001218 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001219 xpm = built_in_pixmaps[menu->iconidx];
1220 else
1221 xpm = tb_blank_xpm;
1222 }
1223
1224 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001226
1227/*
1228 * Add arguments for the toolbar pixmap to a menu item.
1229 */
1230 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001231add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001232{
1233 vim_free(menu->xpm_fname);
1234 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1235 if (menu->xpm == NULL)
1236 {
1237 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1238 }
1239 else
1240 {
Bram Moolenaarfd615a32020-05-16 14:01:51 +02001241# if 0 // DISABLED - this causes a crash when running "make test_gui" in
1242 // Test_colorscheme()
Bram Moolenaar7c626922005-02-07 22:01:03 +00001243 if (menu->xpm_fname != NULL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001244 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaarfd615a32020-05-16 14:01:51 +02001245# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00001246 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1247 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1248 }
1249 return n;
1250}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001251#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252
1253 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001254gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255{
1256 XmString label;
1257 vimmenu_T *parent = menu->parent;
1258
1259# ifdef EBCDIC
1260 menu->mnemonic = 0;
1261# endif
1262
1263# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001264 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1266 return;
1267# endif
1268
1269# ifdef FEAT_TOOLBAR
1270 if (menu_is_toolbar(parent->name))
1271 {
1272 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001273 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274 int n;
1275 Arg args[18];
1276
1277 n = 0;
1278 if (menu_is_separator(menu->name))
1279 {
1280 char *cp;
1281 Dimension wid;
1282
1283 /*
1284 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1285 * a width specifier. If no width is specified then we choose one.
1286 */
1287 cp = (char *)vim_strchr(menu->name, ':');
1288 if (cp != NULL)
1289 wid = (Dimension)atoi(++cp);
1290 else
1291 wid = 4;
1292
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293 type = xmSeparatorWidgetClass;
1294 XtSetArg(args[n], XmNwidth, wid); n++;
1295 XtSetArg(args[n], XmNminWidth, wid); n++;
1296 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001297 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 }
1299 else
1300 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001301 // Without shadows one can't sense whatever the button has been
1302 // pressed or not! However we want to save a bit of space...
1303 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001304 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1306 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1307 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001308 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001309 // Set the label here, so that we can switch between icons/text
1310 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001311 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1312 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001313
Bram Moolenaar7c626922005-02-07 22:01:03 +00001314 n = add_pixmap_args(menu, args, n);
1315
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001316 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 }
1318
1319 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1320 if (menu->id == NULL)
1321 {
1322 menu->id = XtCreateManagedWidget((char *)menu->dname,
1323 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001324 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {
1326 XtAddCallback(menu->id,
1327 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328# ifdef FEAT_FOOTER
1329 XtAddEventHandler(menu->id, EnterWindowMask, False,
1330 toolbarbutton_enter_cb, menu);
1331 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1332 toolbarbutton_leave_cb, menu);
1333# endif
1334 }
1335 }
1336 else
1337 XtSetValues(menu->id, args, n);
1338 if (xms != NULL)
1339 XmStringFree(xms);
1340
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001341# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001343# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344
1345 menu->parent = parent;
1346 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001347 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 if (!XtIsManaged(XtParent(toolBar))
1349 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1350 gui_mch_show_toolbar(TRUE);
1351 gui.toolbar_height = gui_mch_compute_toolbar_height();
1352 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001353 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
1355
Bram Moolenaar734a8672019-12-02 22:49:38 +01001356 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 if (parent->submenu_id == (Widget)0)
1358 return;
1359
1360 menu->submenu_id = (Widget)0;
1361
Bram Moolenaar734a8672019-12-02 22:49:38 +01001362 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 if (menu_is_separator(menu->name))
1364 {
1365 menu->id = XtVaCreateWidget("subMenu",
1366 xmSeparatorGadgetClass, parent->submenu_id,
1367#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001368 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1370 ? 1 : 0),
1371#endif
1372 NULL);
1373 gui_motif_menu_colors(menu->id);
1374 return;
1375 }
1376
1377 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1378 if (label == NULL)
1379 return;
1380 menu->id = XtVaCreateWidget("subMenu",
1381 xmPushButtonWidgetClass, parent->submenu_id,
1382 XmNlabelString, label,
1383 XmNmnemonic, menu->mnemonic,
1384#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001385 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1387 ? 1 : 0),
1388#endif
1389 NULL);
1390 gui_motif_menu_colors(menu->id);
1391 gui_motif_menu_fontlist(menu->id);
1392 XmStringFree(label);
1393
1394 if (menu->id != (Widget)0)
1395 {
1396 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1397 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001398 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 gui_motif_add_actext(menu);
1400 }
1401}
1402
1403#if (XmVersion <= 1002) || defined(PROTO)
1404/*
1405 * This function will destroy/create the popup menus dynamically,
1406 * according to the value of 'mousemodel'.
1407 * This will fix the "right mouse button freeze" that occurs when
1408 * there exists a popup menu but it isn't managed.
1409 */
1410 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001411gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412{
1413 int idx = 0;
1414
Bram Moolenaar734a8672019-12-02 22:49:38 +01001415 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 if (!gui.in_use)
1417 return;
1418
1419 while (menu)
1420 {
1421 if (menu->children != NULL)
1422 {
1423 if (menu_is_popup(menu->name))
1424 {
1425 if (mouse_model_popup())
1426 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001427 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 gui_mch_add_menu(menu, idx);
1429 gui_motif_update_mousemodel(menu->children);
1430 }
1431 else
1432 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001433 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 gui_motif_update_mousemodel(menu->children);
1435 gui_mch_destroy_menu(menu);
1436 }
1437 }
1438 }
1439 else if (menu_is_child_of_popup(menu))
1440 {
1441 if (mouse_model_popup())
1442 gui_mch_add_menu_item(menu, idx);
1443 else
1444 gui_mch_destroy_menu(menu);
1445 }
1446 menu = menu->next;
1447 ++idx;
1448 }
1449}
1450#endif
1451
1452 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001453gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454{
1455 if (menuBar == (Widget)0)
1456 return;
1457 gui_motif_menu_colors(menuBar);
1458#ifdef FEAT_TOOLBAR
1459 gui_motif_menu_colors(toolBarFrame);
1460 gui_motif_menu_colors(toolBar);
1461#endif
1462
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001463 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464}
1465
1466 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001467gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468{
1469 if (menuBar == (Widget)0)
1470 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001471 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {
1473 Dimension height;
1474 Position w, h;
1475
1476 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1477 gui.menu_height = height;
1478
1479 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1480 gui_resize_shell(w, h
1481#ifdef FEAT_XIM
1482 - xim_get_status_area_height()
1483#endif
1484 );
1485 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001486 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 ui_new_shellsize();
1488}
1489
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001490#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001492gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493{
1494# ifdef FEAT_TOOLBAR
1495 vimmenu_T *menu;
1496
1497 if (toolBar == (Widget)0)
1498 return;
1499
1500 menu = gui_find_menu((char_u *)"ToolBar");
1501 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001502 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503# endif
1504}
1505
1506 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001507gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508{
1509# ifdef FEAT_TOOLBAR
1510 vimmenu_T *toolbar;
1511
1512 if (toolBar == (Widget)0)
1513 return;
1514
1515 toolbar = gui_find_menu((char_u *)"ToolBar");
1516 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001517 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518# endif
1519}
1520#endif
1521
1522 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001523submenu_change(
1524 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001525 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526{
1527 vimmenu_T *mp;
1528
1529 for (mp = menu; mp != NULL; mp = mp->next)
1530 {
1531 if (mp->id != (Widget)0)
1532 {
1533 if (colors)
1534 {
1535 gui_motif_menu_colors(mp->id);
1536#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001537 // For a toolbar item: Free the pixmap and allocate a new one,
1538 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001539 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001541 int n = 0;
1542 Arg args[18];
1543
Bram Moolenaar7c626922005-02-07 22:01:03 +00001544 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001545 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001547# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001548 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 if (mp->tip != NULL)
1550 {
1551 Arg args[2];
1552
1553 args[0].name = XmNbackground;
1554 args[0].value = gui.tooltip_bg_pixel;
1555 args[1].name = XmNforeground;
1556 args[1].value = gui.tooltip_fg_pixel;
1557 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1558 }
1559# endif
1560#endif
1561 }
1562 else
1563 {
1564 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001565#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001566 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 if (mp->tip != NULL)
1568 {
1569 Arg args[1];
1570
1571 args[0].name = XmNfontList;
1572 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1573 &gui.tooltip_fontset);
1574 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1575 }
1576#endif
1577 }
1578 }
1579
1580 if (mp->children != NULL)
1581 {
1582#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001583 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 if (mp->submenu_id != (Widget)0)
1585 {
1586 if (colors)
1587 gui_motif_menu_colors(mp->submenu_id);
1588 else
1589 gui_motif_menu_fontlist(mp->submenu_id);
1590 toggle_tearoff(mp->submenu_id);
1591 }
1592#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001593 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001594 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595 }
1596 }
1597}
1598
1599/*
1600 * Destroy the machine specific menu widget.
1601 */
1602 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001603gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001604{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001605 // Please be sure to destroy the parent widget first (i.e. menu->id).
1606 // On the other hand, problems have been reported that the submenu must be
1607 // deleted first...
1608 //
1609 // This code should be basically identical to that in the file gui_athena.c
1610 // because they are both Xt based.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 if (menu->submenu_id != (Widget)0)
1612 {
1613 XtDestroyWidget(menu->submenu_id);
1614 menu->submenu_id = (Widget)0;
1615 }
1616
1617 if (menu->id != (Widget)0)
1618 {
1619 Widget parent;
1620
1621 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001622#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001623 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001625 // We try to destroy this before the actual menu, because there are
1626 // callbacks, etc. that will be unregistered during the tooltip
1627 // destruction.
1628 //
1629 // If you call "gui_mch_destroy_beval_area()" after destroying
1630 // menu->id, then the tooltip's window will have already been
1631 // deallocated by Xt, and unknown behaviour will ensue (probably
1632 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 gui_mch_destroy_beval_area(menu->tip);
1634 menu->tip = NULL;
1635 }
1636#endif
1637 XtDestroyWidget(menu->id);
1638 menu->id = (Widget)0;
1639 if (parent == menuBar)
1640 gui_mch_compute_menu_height((Widget)0);
1641#ifdef FEAT_TOOLBAR
1642 else if (parent == toolBar)
1643 {
1644 Cardinal num_children;
1645
Bram Moolenaar734a8672019-12-02 22:49:38 +01001646 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1648 if (num_children == 0)
1649 gui_mch_show_toolbar(FALSE);
1650 else
1651 gui.toolbar_height = gui_mch_compute_toolbar_height();
1652 }
1653#endif
1654 }
1655}
1656
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001658gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659{
1660#ifdef MOTIF_POPUP
1661 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1662 XtManageChild(menu->submenu_id);
1663#endif
1664}
1665
Bram Moolenaar734a8672019-12-02 22:49:38 +01001666#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667
1668/*
1669 * Set the menu and scrollbar colors to their default values.
1670 */
1671 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001672gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673{
1674 if (gui.in_use)
1675 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001676 // Use the values saved when starting up. These should come from the
1677 // window manager or a resources file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1679 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1680 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1681 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001682#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 gui.tooltip_fg_pixel =
1684 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1685 gui.tooltip_bg_pixel =
1686 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1687#endif
1688 }
1689}
1690
1691
1692/*
1693 * Scrollbar stuff.
1694 */
1695
1696 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001697gui_mch_set_scrollbar_thumb(
1698 scrollbar_T *sb,
1699 long val,
1700 long size,
1701 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702{
1703 if (sb->id != (Widget)0)
1704 XtVaSetValues(sb->id,
1705 XmNvalue, val,
1706 XmNsliderSize, size,
1707 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001708 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 NULL);
1710}
1711
1712 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001713gui_mch_set_scrollbar_pos(
1714 scrollbar_T *sb,
1715 int x,
1716 int y,
1717 int w,
1718 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719{
1720 if (sb->id != (Widget)0)
1721 {
1722 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1723 {
1724 if (y == 0)
1725 h -= gui.border_offset;
1726 else
1727 y -= gui.border_offset;
1728 XtVaSetValues(sb->id,
1729 XmNtopOffset, y,
1730 XmNbottomOffset, -y - h,
1731 XmNwidth, w,
1732 NULL);
1733 }
1734 else
1735 XtVaSetValues(sb->id,
1736 XmNtopOffset, y,
1737 XmNleftOffset, x,
1738 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1739 ? gui.scrollbar_width : 0,
1740 XmNheight, h,
1741 NULL);
1742 XtManageChild(sb->id);
1743 }
1744}
1745
Bram Moolenaar203ec772020-07-17 20:43:43 +02001746 int
1747gui_mch_get_scrollbar_xpadding(void)
1748{
1749 // TODO: Calculate the padding for adjust scrollbar position when the
1750 // Window is maximized.
1751 return 0;
1752}
1753
1754 int
1755gui_mch_get_scrollbar_ypadding(void)
1756{
1757 // TODO: Calculate the padding for adjust scrollbar position when the
1758 // Window is maximized.
1759 return 0;
1760}
1761
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001763gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764{
1765 Arg args[16];
1766 int n;
1767
1768 if (sb->id != (Widget)0)
1769 {
1770 n = 0;
1771 if (flag)
1772 {
1773 switch (sb->type)
1774 {
1775 case SBAR_LEFT:
1776 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1777 break;
1778
1779 case SBAR_RIGHT:
1780 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1781 break;
1782
1783 case SBAR_BOTTOM:
1784 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1785 break;
1786 }
1787 XtSetValues(textArea, args, n);
1788 XtManageChild(sb->id);
1789 }
1790 else
1791 {
1792 if (!gui.which_scrollbars[sb->type])
1793 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001794 // The scrollbars of this type are all disabled, adjust the
1795 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 switch (sb->type)
1797 {
1798 case SBAR_LEFT:
1799 XtSetArg(args[n], XmNleftOffset, 0); n++;
1800 break;
1801
1802 case SBAR_RIGHT:
1803 XtSetArg(args[n], XmNrightOffset, 0); n++;
1804 break;
1805
1806 case SBAR_BOTTOM:
1807 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1808 break;
1809 }
1810 XtSetValues(textArea, args, n);
1811 }
1812 XtUnmanageChild(sb->id);
1813 }
1814 }
1815}
1816
1817 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001818gui_mch_create_scrollbar(
1819 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001820 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821{
1822 Arg args[16];
1823 int n;
1824
1825 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 XtSetArg(args[n], XmNminimum, 0); n++;
1827 XtSetArg(args[n], XmNorientation,
1828 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1829
1830 switch (sb->type)
1831 {
1832 case SBAR_LEFT:
1833 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1834 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1835 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1836 break;
1837
1838 case SBAR_RIGHT:
1839 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1840 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1841 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1842 break;
1843
1844 case SBAR_BOTTOM:
1845 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1846 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1847 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1848 break;
1849 }
1850
1851 sb->id = XtCreateWidget("scrollBar",
1852 xmScrollBarWidgetClass, textAreaForm, args, n);
1853
Bram Moolenaar734a8672019-12-02 22:49:38 +01001854 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1856 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1857 XtVaGetValues(sb->id,
1858 XmNbackground, &gui.scroll_def_bg_pixel,
1859 XmNforeground, &gui.scroll_def_fg_pixel,
1860 NULL);
1861
1862 if (sb->id != (Widget)0)
1863 {
1864 gui_mch_set_scrollbar_colors(sb);
1865 XtAddCallback(sb->id, XmNvalueChangedCallback,
1866 scroll_cb, (XtPointer)sb->ident);
1867 XtAddCallback(sb->id, XmNdragCallback,
1868 scroll_cb, (XtPointer)sb->ident);
1869 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1870 (XtPointer)0);
1871 }
1872}
1873
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001875gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876{
1877 if (sb->id != (Widget)0)
1878 XtDestroyWidget(sb->id);
1879}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880
1881 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001882gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883{
1884 if (sb->id != (Widget)0)
1885 {
1886 if (gui.scroll_bg_pixel != INVALCOLOR)
1887 {
1888#if (XmVersion>=1002)
1889 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1890#else
1891 XtVaSetValues(sb->id,
1892 XmNtroughColor, gui.scroll_bg_pixel,
1893 NULL);
1894#endif
1895 }
1896
1897 if (gui.scroll_fg_pixel != INVALCOLOR)
1898 XtVaSetValues(sb->id,
1899 XmNforeground, gui.scroll_fg_pixel,
1900#if (XmVersion<1002)
1901 XmNbackground, gui.scroll_fg_pixel,
1902#endif
1903 NULL);
1904 }
1905
Bram Moolenaar734a8672019-12-02 22:49:38 +01001906 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1908 gui_motif_scroll_colors(textAreaForm);
1909}
1910
1911/*
1912 * Miscellaneous stuff:
1913 */
1914
1915 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001916gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917{
1918 return(XtWindow(textArea));
1919}
1920
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001921/*
1922 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1923 * When one is found, simulate a button press on that widget and give it the
1924 * keyboard focus. If the mnemonic is on a label, look in the userData field
1925 * of the label to see if it points to another widget, and give that the focus.
1926 */
1927 static void
1928do_mnemonic(Widget w, unsigned int keycode)
1929{
1930 WidgetList children;
1931 int numChildren, i;
1932 Boolean isMenu;
1933 KeySym mnemonic = '\0';
1934 char mneString[2];
1935 Widget userData;
1936 unsigned char rowColType;
1937
1938 if (XtIsComposite(w))
1939 {
1940 if (XtClass(w) == xmRowColumnWidgetClass)
1941 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001942 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001943 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1944 }
1945 else
1946 isMenu = False;
1947 if (!isMenu)
1948 {
1949 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001950 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001951 for (i = 0; i < numChildren; i++)
1952 do_mnemonic(children[i], keycode);
1953 }
1954 }
1955 else
1956 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001957 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001958 if (mnemonic != '\0')
1959 {
1960 mneString[0] = mnemonic;
1961 mneString[1] = '\0';
1962 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1963 XStringToKeysym(mneString)) == keycode)
1964 {
1965 if (XtClass(w) == xmLabelWidgetClass
1966 || XtClass(w) == xmLabelGadgetClass)
1967 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001968 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001969 if (userData != NULL && XtIsWidget(userData))
1970 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1971 }
1972 else
1973 {
1974 XKeyPressedEvent keyEvent;
1975
1976 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1977
Bram Moolenaara80faa82020-04-12 19:37:17 +02001978 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001979 keyEvent.type = KeyPress;
1980 keyEvent.serial = 1;
1981 keyEvent.send_event = True;
1982 keyEvent.display = XtDisplay(w);
1983 keyEvent.window = XtWindow(w);
1984 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1985 NULL, 0);
1986 }
1987 }
1988 }
1989 }
1990}
1991
1992/*
1993 * Callback routine for dialog mnemonic processing.
1994 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001995 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001996mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001997{
1998 do_mnemonic(w, event->keycode);
1999}
2000
2001
2002/*
2003 * Search the widget tree under w for widgets with mnemonics. When found, add
2004 * a passive grab to the dialog widget for the mnemonic character, thus
2005 * directing mnemonic events to the dialog widget.
2006 */
2007 static void
2008add_mnemonic_grabs(Widget dialog, Widget w)
2009{
2010 char mneString[2];
2011 WidgetList children;
2012 int numChildren, i;
2013 Boolean isMenu;
2014 KeySym mnemonic = '\0';
2015 unsigned char rowColType;
2016
2017 if (XtIsComposite(w))
2018 {
2019 if (XtClass(w) == xmRowColumnWidgetClass)
2020 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002021 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002022 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2023 }
2024 else
2025 isMenu = False;
2026 if (!isMenu)
2027 {
2028 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002029 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002030 for (i = 0; i < numChildren; i++)
2031 add_mnemonic_grabs(dialog, children[i]);
2032 }
2033 }
2034 else
2035 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002036 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002037 if (mnemonic != '\0')
2038 {
2039 mneString[0] = mnemonic;
2040 mneString[1] = '\0';
2041 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2042 XStringToKeysym(mneString)),
2043 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2044 }
2045 }
2046}
2047
2048/*
2049 * Add a handler for mnemonics in a dialog. Motif itself only handles
2050 * mnemonics in menus. Mnemonics added or changed after this call will be
2051 * ignored.
2052 *
2053 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2054 * the appropriate label and set the XmNuserData resource of the label to the
2055 * widget to get the focus when the mnemonic is typed.
2056 */
2057 static void
2058activate_dialog_mnemonics(Widget dialog)
2059{
2060 if (!dialog)
2061 return;
2062
2063 XtAddEventHandler(dialog, KeyPressMask, False,
2064 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2065 add_mnemonic_grabs(dialog, dialog);
2066}
2067
2068/*
2069 * Removes the event handler and key-grabs for dialog mnemonic handling.
2070 */
2071 static void
2072suppress_dialog_mnemonics(Widget dialog)
2073{
2074 if (!dialog)
2075 return;
2076
2077 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2078 XtRemoveEventHandler(dialog, KeyPressMask, False,
2079 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2080}
2081
2082#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002083/*
2084 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2085 */
2086 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002087set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002088{
2089 XmFontList fl;
2090
2091#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002092 if (gui.fontset != NOFONTSET)
2093 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002094 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2095 if (fl != NULL)
2096 {
2097 if (XtIsManaged(id))
2098 {
2099 XtUnmanageChild(id);
2100 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002101 // We should force the widget to recalculate its
2102 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002103 XtManageChild(id);
2104 }
2105 else
2106 XtVaSetValues(id, XmNfontList, fl, NULL);
2107 XmFontListFree(fl);
2108 }
2109 }
2110#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002111 if (gui.norm_font != NOFONT)
2112 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002113 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2114 if (fl != NULL)
2115 {
2116 if (XtIsManaged(id))
2117 {
2118 XtUnmanageChild(id);
2119 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002120 // We should force the widget to recalculate its
2121 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002122 XtManageChild(id);
2123 }
2124 else
2125 XtVaSetValues(id, XmNfontList, fl, NULL);
2126 XmFontListFree(fl);
2127 }
2128 }
2129#endif
2130}
2131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132
2133#if defined(FEAT_BROWSE) || defined(PROTO)
2134
2135/*
2136 * file selector related stuff
2137 */
2138
2139#include <Xm/FileSB.h>
2140#include <Xm/XmStrDefs.h>
2141
2142typedef struct dialog_callback_arg
2143{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002144 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 int id;
2146} dcbarg_T;
2147
2148static Widget dialog_wgt;
2149static char *browse_fname = NULL;
2150static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002151 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002153static void DialogCancelCB(Widget, XtPointer, XtPointer);
2154static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155
2156/*
2157 * This function is used to translate the predefined label text of the
2158 * precomposed dialogs. We do this explicitly to allow:
2159 *
2160 * - usage of gettext for translation, as in all the other places.
2161 *
2162 * - equalize the messages between different GUI implementations as far as
2163 * possible.
2164 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002165 static void
2166set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002168 XmString str;
2169 Widget w;
2170 char_u *p, *next;
2171 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172
2173 w = XtNameToWidget(parent, name);
2174
2175 if (!w)
2176 return;
2177
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002178 p = vim_strsave((char_u *)new_label);
2179 if (p == NULL)
2180 return;
2181 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002183 if (*next == DLG_HOTKEY_CHAR)
2184 {
2185 int len = STRLEN(next);
2186
2187 if (len > 0)
2188 {
2189 mch_memmove(next, next + 1, len);
2190 mnemonic = next[0];
2191 }
2192 }
2193 }
2194
2195 str = XmStringCreate((char *)p, STRING_TAG);
2196 vim_free(p);
2197
2198 if (str != NULL)
2199 {
2200 XtVaSetValues(w,
2201 XmNlabelString, str,
2202 XmNmnemonic, mnemonic,
2203 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002204 XmStringFree(str);
2205 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002206 gui_motif_menu_fontlist(w);
2207}
2208
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002209 static void
2210set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002211{
2212 Widget w;
2213 w = XtNameToWidget(parent, name);
2214
2215 if (!w)
2216 return;
2217
2218 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219}
2220
2221/*
2222 * Put up a file requester.
2223 * Returns the selected name in allocated memory, or NULL for Cancel.
2224 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002226gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002227 int saving UNUSED, // select file to write
2228 char_u *title, // title for the window
2229 char_u *dflt, // default name
2230 char_u *ext UNUSED, // not used (extension added)
2231 char_u *initdir, // initial directory, NULL for current dir
2232 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002233{
2234 char_u dirbuf[MAXPATHL];
2235 char_u dfltbuf[MAXPATHL];
2236 char_u *pattern;
2237 char_u *tofree = NULL;
2238
Bram Moolenaar734a8672019-12-02 22:49:38 +01002239 // There a difference between the resource name and value, Therefore, we
2240 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2241 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002242
2243 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244
2245 if (initdir == NULL || *initdir == NUL)
2246 {
2247 mch_dirname(dirbuf, MAXPATHL);
2248 initdir = dirbuf;
2249 }
2250
2251 if (dflt == NULL)
2252 dflt = (char_u *)"";
2253 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2254 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002255 // The default selection should be the full path, "dflt" is only the
2256 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257 STRCPY(dfltbuf, initdir);
2258 add_pathsep(dfltbuf);
2259 STRCAT(dfltbuf, dflt);
2260 dflt = dfltbuf;
2261 }
2262
Bram Moolenaar734a8672019-12-02 22:49:38 +01002263 // Can only use one pattern for a file name. Get the first pattern out of
2264 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 if (filter == NULL)
2266 pattern = (char_u *)"";
2267 else
2268 {
2269 char_u *s, *p;
2270
2271 s = filter;
2272 for (p = filter; *p != NUL; ++p)
2273 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002274 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002276 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 break;
2278 }
2279 pattern = vim_strnsave(s, p - s);
2280 tofree = pattern;
2281 if (pattern == NULL)
2282 pattern = (char_u *)"";
2283 }
2284
2285 XtVaSetValues(dialog_wgt,
2286 XtVaTypedArg,
2287 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2288 XtVaTypedArg,
2289 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2290 XtVaTypedArg,
2291 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2292 XtVaTypedArg,
2293 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2294 NULL);
2295
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002296 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2297 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2299 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002300 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002302 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2304
Bram Moolenaar734a8672019-12-02 22:49:38 +01002305 // This is to save us from silly external settings using not fixed with
2306 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002307 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2308 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2309
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 gui_motif_menu_colors(dialog_wgt);
2311 if (gui.scroll_bg_pixel != INVALCOLOR)
2312 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2313
2314 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2315 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002316 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2318 (unsigned char)XmDIALOG_HELP_BUTTON));
2319
2320 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002321 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322
Bram Moolenaar734a8672019-12-02 22:49:38 +01002323 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 do
2325 {
2326 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2327 (XtInputMask)XtIMAll);
2328 } while (XtIsManaged(dialog_wgt));
2329
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002330 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 XtDestroyWidget(dialog_wgt);
2332 vim_free(tofree);
2333
2334 if (browse_fname == NULL)
2335 return NULL;
2336 return vim_strsave((char_u *)browse_fname);
2337}
2338
2339/*
2340 * The code below was originally taken from
2341 * /usr/examples/motif/xmsamplers/xmeditor.c
2342 * on Digital Unix 4.0d, but heavily modified.
2343 */
2344
2345/*
2346 * Process callback from Dialog cancel actions.
2347 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002349DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002350 Widget w UNUSED, // widget id
2351 XtPointer client_data UNUSED, // data from application
2352 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353{
2354 if (browse_fname != NULL)
2355 {
2356 XtFree(browse_fname);
2357 browse_fname = NULL;
2358 }
2359 XtUnmanageChild(dialog_wgt);
2360}
2361
2362/*
2363 * Process callback from Dialog actions.
2364 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002366DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002367 Widget w UNUSED, // widget id
2368 XtPointer client_data UNUSED, // data from application
2369 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370{
2371 XmFileSelectionBoxCallbackStruct *fcb;
2372
2373 if (browse_fname != NULL)
2374 {
2375 XtFree(browse_fname);
2376 browse_fname = NULL;
2377 }
2378 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2379
Bram Moolenaar734a8672019-12-02 22:49:38 +01002380 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2382
Bram Moolenaar734a8672019-12-02 22:49:38 +01002383 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 XtUnmanageChild(dialog_wgt);
2385}
2386
Bram Moolenaar734a8672019-12-02 22:49:38 +01002387#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388
2389#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2390
2391static int dialogStatus;
2392
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393/*
2394 * Callback function for the textfield. When CR is hit this works like
2395 * hitting the "OK" button, ESC like "Cancel".
2396 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002398keyhit_callback(
2399 Widget w,
2400 XtPointer client_data UNUSED,
2401 XEvent *event,
2402 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403{
2404 char buf[2];
2405 KeySym key_sym;
2406
2407 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2408 {
2409 if (*buf == CAR)
2410 dialogStatus = 1;
2411 else if (*buf == ESC)
2412 dialogStatus = 2;
2413 }
2414 if ((key_sym == XK_Left || key_sym == XK_Right)
2415 && !(event->xkey.state & ShiftMask))
2416 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2417}
2418
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002420butproc(
2421 Widget w UNUSED,
2422 XtPointer client_data,
2423 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424{
2425 dialogStatus = (int)(long)client_data + 1;
2426}
2427
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428#ifdef HAVE_XPM
2429
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002431create_pixmap_label(
2432 Widget parent,
2433 String name,
2434 char **data,
2435 ArgList args,
2436 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437{
2438 Widget label;
2439 Display *dsp;
2440 Screen *scr;
2441 int depth;
2442 Pixmap pixmap = 0;
2443 XpmAttributes attr;
2444 Boolean rs;
2445 XpmColorSymbol color[5] =
2446 {
2447 {"none", NULL, 0},
2448 {"iconColor1", NULL, 0},
2449 {"bottomShadowColor", NULL, 0},
2450 {"topShadowColor", NULL, 0},
2451 {"selectColor", NULL, 0}
2452 };
2453
2454 label = XmCreateLabelGadget(parent, name, args, arg);
2455
2456 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002457 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 * no way to get the background color directly from the widget itself.
2459 * In such cases we get it from The Core part of his parent instead.
2460 */
2461 dsp = XtDisplayOfObject(label);
2462 scr = XtScreenOfObject(label);
2463 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2464 ? label : XtParent(label),
2465 XmNdepth, &depth,
2466 XmNbackground, &color[0].pixel,
2467 XmNforeground, &color[1].pixel,
2468 XmNbottomShadowColor, &color[2].pixel,
2469 XmNtopShadowColor, &color[3].pixel,
2470 XmNhighlight, &color[4].pixel,
2471 NULL);
2472
2473 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2474 attr.colorsymbols = color;
2475 attr.numsymbols = 5;
2476 attr.closeness = 65535;
2477 attr.depth = depth;
2478 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2479 data, &pixmap, NULL, &attr);
2480
2481 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2482 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2483 XtVaSetValues(label,
2484 XmNlabelType, XmPIXMAP,
2485 XmNlabelPixmap, pixmap,
2486 NULL);
2487 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2488
2489 return label;
2490}
2491#endif
2492
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002494gui_mch_dialog(
2495 int type UNUSED,
2496 char_u *title,
2497 char_u *message,
2498 char_u *button_names,
2499 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002500 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002501 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502{
2503 char_u *buts;
2504 char_u *p, *next;
2505 XtAppContext app;
2506 XmString label;
2507 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002508 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 Widget dialogform = NULL;
2510 Widget form = NULL;
2511 Widget dialogtextfield = NULL;
2512 Widget *buttons;
2513 Widget sep_form = NULL;
2514 Boolean vertical;
2515 Widget separator = NULL;
2516 int n;
2517 Arg args[6];
2518#ifdef HAVE_XPM
2519 char **icon_data = NULL;
2520 Widget dialogpixmap = NULL;
2521#endif
2522
2523 if (title == NULL)
2524 title = (char_u *)_("Vim dialog");
2525
Bram Moolenaar734a8672019-12-02 22:49:38 +01002526 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 gui_mch_mousehide(FALSE);
2528
2529 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2530
Bram Moolenaar734a8672019-12-02 22:49:38 +01002531 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2533
Bram Moolenaar734a8672019-12-02 22:49:38 +01002534 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 label = XmStringCreateSimple((char *)title);
2536 if (label == NULL)
2537 return -1;
2538 XtVaSetValues(dialogform,
2539 XmNdialogTitle, label,
2540 XmNhorizontalSpacing, 4,
2541 XmNverticalSpacing, vertical ? 0 : 4,
2542 NULL);
2543 XmStringFree(label);
2544
Bram Moolenaar734a8672019-12-02 22:49:38 +01002545 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 buts = vim_strsave(button_names);
2547 if (buts == NULL)
2548 return -1;
2549
Bram Moolenaar734a8672019-12-02 22:49:38 +01002550 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 butcount = 1;
2552 for (p = buts; *p; ++p)
2553 if (*p == DLG_BUTTON_SEP)
2554 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002555 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 if (buttons == NULL)
2557 {
2558 vim_free(buts);
2559 return -1;
2560 }
2561
2562 /*
2563 * Create the buttons.
2564 */
2565 sep_form = (Widget) 0;
2566 p = buts;
2567 for (butcount = 0; *p; ++butcount)
2568 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002569 KeySym mnemonic = NUL;
2570
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 for (next = p; *next; ++next)
2572 {
2573 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002574 {
2575 int len = STRLEN(next);
2576
2577 if (len > 0)
2578 {
2579 mch_memmove(next, next + 1, len);
2580 mnemonic = next[0];
2581 }
2582 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 if (*next == DLG_BUTTON_SEP)
2584 {
2585 *next++ = NUL;
2586 break;
2587 }
2588 }
2589 label = XmStringCreate(_((char *)p), STRING_TAG);
2590 if (label == NULL)
2591 break;
2592
2593 buttons[butcount] = XtVaCreateManagedWidget("button",
2594 xmPushButtonWidgetClass, dialogform,
2595 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002596 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 XmNbottomAttachment, XmATTACH_FORM,
2598 XmNbottomOffset, 4,
2599 XmNshowAsDefault, butcount == dfltbutton - 1,
2600 XmNdefaultButtonShadowThickness, 1,
2601 NULL);
2602 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002603 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604
Bram Moolenaar734a8672019-12-02 22:49:38 +01002605 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606
2607 if (butcount > 0)
2608 {
2609 if (vertical)
2610 XtVaSetValues(buttons[butcount],
2611 XmNtopWidget, buttons[butcount - 1],
2612 NULL);
2613 else
2614 {
2615 if (*next == NUL)
2616 {
2617 XtVaSetValues(buttons[butcount],
2618 XmNrightAttachment, XmATTACH_FORM,
2619 XmNrightOffset, 4,
2620 NULL);
2621
Bram Moolenaar734a8672019-12-02 22:49:38 +01002622 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 sep_form = XtVaCreateWidget("separatorForm",
2624 xmFormWidgetClass, dialogform,
2625 XmNleftAttachment, XmATTACH_WIDGET,
2626 XmNleftWidget, buttons[butcount - 1],
2627 XmNrightAttachment, XmATTACH_WIDGET,
2628 XmNrightWidget, buttons[butcount],
2629 XmNbottomAttachment, XmATTACH_FORM,
2630 XmNbottomOffset, 4,
2631 NULL);
2632 XtManageChild(sep_form);
2633 }
2634 else
2635 {
2636 XtVaSetValues(buttons[butcount],
2637 XmNleftAttachment, XmATTACH_WIDGET,
2638 XmNleftWidget, buttons[butcount - 1],
2639 NULL);
2640 }
2641 }
2642 }
2643 else if (!vertical)
2644 {
2645 if (*next == NUL)
2646 {
2647 XtVaSetValues(buttons[0],
2648 XmNrightAttachment, XmATTACH_FORM,
2649 XmNrightOffset, 4,
2650 NULL);
2651
Bram Moolenaar734a8672019-12-02 22:49:38 +01002652 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 sep_form = XtVaCreateWidget("separatorForm",
2654 xmFormWidgetClass, dialogform,
2655 XmNleftAttachment, XmATTACH_FORM,
2656 XmNleftOffset, 4,
2657 XmNrightAttachment, XmATTACH_WIDGET,
2658 XmNrightWidget, buttons[0],
2659 XmNbottomAttachment, XmATTACH_FORM,
2660 XmNbottomOffset, 4,
2661 NULL);
2662 XtManageChild(sep_form);
2663 }
2664 else
2665 XtVaSetValues(buttons[0],
2666 XmNleftAttachment, XmATTACH_FORM,
2667 XmNleftOffset, 4,
2668 NULL);
2669 }
2670
2671 XtAddCallback(buttons[butcount], XmNactivateCallback,
2672 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2673 p = next;
2674 }
2675 vim_free(buts);
2676
2677 separator = (Widget) 0;
2678 if (butcount > 0)
2679 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002680 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 n = 0;
2682 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2683 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2684 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2685 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2686 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2687 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2688 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2689 XtManageChild(separator);
2690 }
2691
2692 if (textfield != NULL)
2693 {
2694 dialogtextfield = XtVaCreateWidget("textField",
2695 xmTextFieldWidgetClass, dialogform,
2696 XmNleftAttachment, XmATTACH_FORM,
2697 XmNrightAttachment, XmATTACH_FORM,
2698 NULL);
2699 if (butcount > 0)
2700 XtVaSetValues(dialogtextfield,
2701 XmNbottomAttachment, XmATTACH_WIDGET,
2702 XmNbottomWidget, separator,
2703 NULL);
2704 else
2705 XtVaSetValues(dialogtextfield,
2706 XmNbottomAttachment, XmATTACH_FORM,
2707 NULL);
2708
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002709 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2711 XtManageChild(dialogtextfield);
2712 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2713 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2714 }
2715
Bram Moolenaar734a8672019-12-02 22:49:38 +01002716 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 form = XtVaCreateWidget("separatorForm",
2718 xmFormWidgetClass, dialogform,
2719 XmNleftAttachment, XmATTACH_FORM,
2720 XmNrightAttachment, XmATTACH_FORM,
2721 XmNtopAttachment, XmATTACH_FORM,
2722 NULL);
2723 XtManageChild(form);
2724
2725#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002726 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 switch (type)
2728 {
2729 case VIM_GENERIC:
2730 icon_data = generic_xpm;
2731 break;
2732 case VIM_ERROR:
2733 icon_data = error_xpm;
2734 break;
2735 case VIM_WARNING:
2736 icon_data = alert_xpm;
2737 break;
2738 case VIM_INFO:
2739 icon_data = info_xpm;
2740 break;
2741 case VIM_QUESTION:
2742 icon_data = quest_xpm;
2743 break;
2744 default:
2745 icon_data = generic_xpm;
2746 }
2747
2748 n = 0;
2749 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2750 XtSetArg(args[n], XmNtopOffset, 8); n++;
2751 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2752 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2753 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2754 XtSetArg(args[n], XmNleftOffset, 8); n++;
2755
2756 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2757 icon_data, args, n);
2758 XtManageChild(dialogpixmap);
2759#endif
2760
Bram Moolenaar734a8672019-12-02 22:49:38 +01002761 // Create the dialog message.
2762 // Since LessTif is apparently having problems with the creation of
2763 // properly localized string, we use LtoR here. The symptom is that the
2764 // string sill not show properly in multiple lines as it does in native
2765 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002766 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 if (label == NULL)
2768 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002769 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 xmLabelGadgetClass, form,
2771 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002772 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 XmNtopAttachment, XmATTACH_FORM,
2774 XmNtopOffset, 8,
2775#ifdef HAVE_XPM
2776 XmNleftAttachment, XmATTACH_WIDGET,
2777 XmNleftWidget, dialogpixmap,
2778#else
2779 XmNleftAttachment, XmATTACH_FORM,
2780#endif
2781 XmNleftOffset, 8,
2782 XmNrightAttachment, XmATTACH_FORM,
2783 XmNrightOffset, 8,
2784 XmNbottomAttachment, XmATTACH_FORM,
2785 XmNbottomOffset, 8,
2786 NULL);
2787 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002788 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789
2790 if (textfield != NULL)
2791 {
2792 XtVaSetValues(form,
2793 XmNbottomAttachment, XmATTACH_WIDGET,
2794 XmNbottomWidget, dialogtextfield,
2795 NULL);
2796 }
2797 else
2798 {
2799 if (butcount > 0)
2800 XtVaSetValues(form,
2801 XmNbottomAttachment, XmATTACH_WIDGET,
2802 XmNbottomWidget, separator,
2803 NULL);
2804 else
2805 XtVaSetValues(form,
2806 XmNbottomAttachment, XmATTACH_FORM,
2807 NULL);
2808 }
2809
2810 if (dfltbutton < 1)
2811 dfltbutton = 1;
2812 if (dfltbutton > butcount)
2813 dfltbutton = butcount;
2814 XtVaSetValues(dialogform,
2815 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2816 if (textfield != NULL)
2817 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2818 else
2819 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2820 NULL);
2821
2822 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002823 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824
2825 if (textfield != NULL && *textfield != NUL)
2826 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002827 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 XmTextFieldSetSelection(dialogtextfield,
2829 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2830 XtLastTimestampProcessed(gui.dpy));
2831 XmTextFieldSetCursorPosition(dialogtextfield,
2832 (XmTextPosition)STRLEN(textfield));
2833 }
2834
2835 app = XtWidgetToApplicationContext(dialogform);
2836
Bram Moolenaar734a8672019-12-02 22:49:38 +01002837 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 dialogStatus = -1;
2839 for (;;)
2840 {
2841 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2842 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2843 break;
2844 }
2845
2846 vim_free(buttons);
2847
2848 if (textfield != NULL)
2849 {
2850 p = (char_u *)XmTextGetString(dialogtextfield);
2851 if (p == NULL || dialogStatus < 0)
2852 *textfield = NUL;
2853 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002854 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002855 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 }
2857
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002858 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 XtDestroyWidget(dialogform);
2860
2861 return dialogStatus;
2862}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002863#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864
2865#if defined(FEAT_FOOTER) || defined(PROTO)
2866
2867 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002868gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002870 Dimension height; // total Toolbar height
2871 Dimension top; // XmNmarginTop
2872 Dimension bottom; // XmNmarginBottom
2873 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874
2875 XtVaGetValues(footer,
2876 XmNheight, &height,
2877 XmNmarginTop, &top,
2878 XmNmarginBottom, &bottom,
2879 XmNshadowThickness, &shadow,
2880 NULL);
2881
2882 return (int) height + top + bottom + (shadow << 1);
2883}
2884
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002886gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887{
2888 if (showit)
2889 {
2890 gui.footer_height = gui_mch_compute_footer_height();
2891 XtManageChild(footer);
2892 }
2893 else
2894 {
2895 gui.footer_height = 0;
2896 XtUnmanageChild(footer);
2897 }
2898 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2899}
2900
2901 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002902gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903{
2904 XmString xms;
2905
2906 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002907 if (xms != NULL)
2908 {
2909 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2910 XmStringFree(xms);
2911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912}
2913
2914#endif
2915
2916
2917#if defined(FEAT_TOOLBAR) || defined(PROTO)
2918 void
2919gui_mch_show_toolbar(int showit)
2920{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002921 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922
2923 if (toolBar == (Widget)0)
2924 return;
2925 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2926 if (showit && numChildren > 0)
2927 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002928 // Assume that we want to show the toolbar if p_toolbar contains
2929 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 WidgetList children;
2931
2932 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2933 {
2934 void (*action)(BalloonEval *);
2935 int text = 0;
2936
2937 if (strstr((const char *)p_toolbar, "tooltips"))
2938 action = &gui_mch_enable_beval_area;
2939 else
2940 action = &gui_mch_disable_beval_area;
2941 if (strstr((const char *)p_toolbar, "text"))
2942 text = 1;
2943 else if (strstr((const char *)p_toolbar, "icons"))
2944 text = -1;
2945 if (text != 0)
2946 {
2947 vimmenu_T *toolbar;
2948 vimmenu_T *cur;
2949
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002950 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 if (menu_is_toolbar(toolbar->dname))
2952 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002953 // Assumption: toolbar is NULL if there is no toolbar,
2954 // otherwise it contains the toolbar menu structure.
2955 //
2956 // Assumption: "numChildren" == the number of items in the list
2957 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 if (toolbar)
2959 {
2960 for (cur = toolbar->children; cur; cur = cur->next)
2961 {
2962 Arg args[1];
2963 int n = 0;
2964
Bram Moolenaar734a8672019-12-02 22:49:38 +01002965 // Enable/Disable tooltip (OK to enable while
2966 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 if (cur->tip != NULL)
2968 (*action)(cur->tip);
2969 if (!menu_is_separator(cur->name))
2970 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002971 if (text == 1 || cur->xpm == NULL)
2972 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002974 ++n;
2975 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 if (cur->id != NULL)
2977 {
2978 XtUnmanageChild(cur->id);
2979 XtSetValues(cur->id, args, n);
2980 XtManageChild(cur->id);
2981 }
2982 }
2983 }
2984 }
2985 }
2986 }
2987 gui.toolbar_height = gui_mch_compute_toolbar_height();
2988 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002989#ifdef FEAT_GUI_TABLINE
2990 if (showing_tabline)
2991 {
2992 XtVaSetValues(tabLine,
2993 XmNtopAttachment, XmATTACH_WIDGET,
2994 XmNtopWidget, XtParent(toolBar),
2995 NULL);
2996 XtVaSetValues(textAreaForm,
2997 XmNtopAttachment, XmATTACH_WIDGET,
2998 XmNtopWidget, tabLine,
2999 NULL);
3000 }
3001 else
3002#endif
3003 XtVaSetValues(textAreaForm,
3004 XmNtopAttachment, XmATTACH_WIDGET,
3005 XmNtopWidget, XtParent(toolBar),
3006 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 if (XtIsManaged(menuBar))
3008 XtVaSetValues(XtParent(toolBar),
3009 XmNtopAttachment, XmATTACH_WIDGET,
3010 XmNtopWidget, menuBar,
3011 NULL);
3012 else
3013 XtVaSetValues(XtParent(toolBar),
3014 XmNtopAttachment, XmATTACH_FORM,
3015 NULL);
3016 }
3017 else
3018 {
3019 gui.toolbar_height = 0;
3020 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003021 {
3022#ifdef FEAT_GUI_TABLINE
3023 if (showing_tabline)
3024 {
3025 XtVaSetValues(tabLine,
3026 XmNtopAttachment, XmATTACH_WIDGET,
3027 XmNtopWidget, menuBar,
3028 NULL);
3029 XtVaSetValues(textAreaForm,
3030 XmNtopAttachment, XmATTACH_WIDGET,
3031 XmNtopWidget, tabLine,
3032 NULL);
3033 }
3034 else
3035#endif
3036 XtVaSetValues(textAreaForm,
3037 XmNtopAttachment, XmATTACH_WIDGET,
3038 XmNtopWidget, menuBar,
3039 NULL);
3040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003042 {
3043#ifdef FEAT_GUI_TABLINE
3044 if (showing_tabline)
3045 {
3046 XtVaSetValues(tabLine,
3047 XmNtopAttachment, XmATTACH_FORM,
3048 NULL);
3049 XtVaSetValues(textAreaForm,
3050 XmNtopAttachment, XmATTACH_WIDGET,
3051 XmNtopWidget, tabLine,
3052 NULL);
3053 }
3054 else
3055#endif
3056 XtVaSetValues(textAreaForm,
3057 XmNtopAttachment, XmATTACH_FORM,
3058 NULL);
3059 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060
3061 XtUnmanageChild(XtParent(toolBar));
3062 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003063 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064}
3065
3066/*
3067 * A toolbar button has been pushed; now reset the input focus
3068 * such that the user can type page up/down etc. and have the
3069 * input go to the editor window, not the button
3070 */
3071 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003072reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073{
3074 if (textArea != NULL)
3075 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3076}
3077
3078 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003079gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003081 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003082 Dimension height; // total Toolbar height
3083 Dimension whgt; // height of each widget
3084 WidgetList children; // list of toolBar's children
3085 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 int i;
3087
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003088 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003091 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003092 Dimension fst;
3093 Dimension fmh;
3094 Dimension tst;
3095 Dimension tmh;
3096
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003098 XmNshadowThickness, &fst,
3099 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003101 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003103 XmNshadowThickness, &tst,
3104 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 XmNchildren, &children,
3106 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003107 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003108 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 {
3110 whgt = 0;
3111 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3112 if (height < whgt)
3113 height = whgt;
3114 }
3115 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003116#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003117 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003118 if (height < 10)
3119 height = 24;
3120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003122 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123}
3124
Bram Moolenaar7c626922005-02-07 22:01:03 +00003125 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003126motif_get_toolbar_colors(
3127 Pixel *bgp,
3128 Pixel *fgp,
3129 Pixel *bsp,
3130 Pixel *tsp,
3131 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003132{
3133 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003134 XmNbackground, bgp,
3135 XmNforeground, fgp,
3136 XmNbottomShadowColor, bsp,
3137 XmNtopShadowColor, tsp,
3138 XmNhighlightColor, hsp,
3139 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003140}
3141
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142# ifdef FEAT_FOOTER
3143/*
3144 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003145 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 * get implemented and the user will have a choice.
3147 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003149toolbarbutton_enter_cb(
3150 Widget w UNUSED,
3151 XtPointer client_data,
3152 XEvent *event UNUSED,
3153 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154{
3155 vimmenu_T *menu = (vimmenu_T *) client_data;
3156
3157 if (menu->strings[MENU_INDEX_TIP] != NULL)
3158 {
3159 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3160 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3161 }
3162}
3163
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003165toolbarbutton_leave_cb(
3166 Widget w UNUSED,
3167 XtPointer client_data UNUSED,
3168 XEvent *event UNUSED,
3169 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170{
3171 gui_mch_set_footer((char_u *) "");
3172}
3173# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174#endif
3175
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003176#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3177/*
3178 * Show or hide the tabline.
3179 */
3180 void
3181gui_mch_show_tabline(int showit)
3182{
3183 if (tabLine == (Widget)0)
3184 return;
3185
3186 if (!showit != !showing_tabline)
3187 {
3188 if (showit)
3189 {
3190 XtManageChild(tabLine);
3191 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003192 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3193 XtUnmanageChild(XtNameToWidget(tabLine,
3194 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003195#ifdef FEAT_MENU
3196# ifdef FEAT_TOOLBAR
3197 if (XtIsManaged(XtParent(toolBar)))
3198 XtVaSetValues(tabLine,
3199 XmNtopAttachment, XmATTACH_WIDGET,
3200 XmNtopWidget, XtParent(toolBar), NULL);
3201 else
3202# endif
3203 if (XtIsManaged(menuBar))
3204 XtVaSetValues(tabLine,
3205 XmNtopAttachment, XmATTACH_WIDGET,
3206 XmNtopWidget, menuBar, NULL);
3207 else
3208#endif
3209 XtVaSetValues(tabLine,
3210 XmNtopAttachment, XmATTACH_FORM, NULL);
3211 XtVaSetValues(textAreaForm,
3212 XmNtopAttachment, XmATTACH_WIDGET,
3213 XmNtopWidget, tabLine,
3214 NULL);
3215 }
3216 else
3217 {
3218 XtUnmanageChild(tabLine);
3219#ifdef FEAT_MENU
3220# ifdef FEAT_TOOLBAR
3221 if (XtIsManaged(XtParent(toolBar)))
3222 XtVaSetValues(textAreaForm,
3223 XmNtopAttachment, XmATTACH_WIDGET,
3224 XmNtopWidget, XtParent(toolBar), NULL);
3225 else
3226# endif
3227 if (XtIsManaged(menuBar))
3228 XtVaSetValues(textAreaForm,
3229 XmNtopAttachment, XmATTACH_WIDGET,
3230 XmNtopWidget, menuBar, NULL);
3231 else
3232#endif
3233 XtVaSetValues(textAreaForm,
3234 XmNtopAttachment, XmATTACH_FORM, NULL);
3235 }
3236 showing_tabline = showit;
3237 }
3238}
3239
3240/*
3241 * Return TRUE when tabline is displayed.
3242 */
3243 int
3244gui_mch_showing_tabline(void)
3245{
3246 return tabLine != (Widget)0 && showing_tabline;
3247}
3248
3249/*
3250 * Update the labels of the tabline.
3251 */
3252 void
3253gui_mch_update_tabline(void)
3254{
3255 tabpage_T *tp;
3256 int nr = 1, n;
3257 Arg args[10];
3258 int curtabidx = 0, currentpage;
3259 Widget tab;
3260 XmNotebookPageInfo page_info;
3261 XmNotebookPageStatus page_status;
3262 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003263 XmString label_str;
3264 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003265 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003266
3267 if (tabLine == (Widget)0)
3268 return;
3269
Bram Moolenaar734a8672019-12-02 22:49:38 +01003270 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003271 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3272 {
3273 if (tp == curtab)
3274 curtabidx = nr;
3275
3276 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3277 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003278 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003279 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003280 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003281 n = 0;
3282 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3283 XtSetArg(args[n], XmNtraversalOn, False); n++;
3284 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3285 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3286 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3287 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3288 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003289 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3290 NULL);
3291 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003292 }
3293 else
3294 tab = page_info.major_tab_widget;
3295
3296 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003297
3298 /*
3299 * Change the label text only if it is different
3300 */
3301 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3302 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3303 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003304 get_tabline_label(tp, FALSE);
3305 if (STRCMP(label_cstr, NameBuff) != 0)
3306 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003307 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3308 NameBuff, STRLEN(NameBuff) + 1, NULL);
3309 /*
3310 * Force a resize of the tab label button
3311 */
3312 XtUnmanageChild(tab);
3313 XtManageChild(tab);
3314 }
3315 XtFree(label_cstr);
3316 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003317 }
3318
3319 tab_count = nr - 1;
3320
3321 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3322
Bram Moolenaar734a8672019-12-02 22:49:38 +01003323 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003324 while (nr <= last_page)
3325 {
3326 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3327 && page_info.page_number == nr
3328 && page_info.major_tab_widget != (Widget)0)
3329 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003330 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3331 if (beval != NULL)
3332 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003333 XtUnmanageChild(page_info.major_tab_widget);
3334 XtDestroyWidget(page_info.major_tab_widget);
3335 }
3336 nr++;
3337 }
3338
3339 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3340
3341 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3342 if (currentpage != curtabidx)
3343 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3344}
3345
3346/*
3347 * Set the current tab to "nr". First tab is 1.
3348 */
3349 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003350gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003351{
3352 int currentpage;
3353
3354 if (tabLine == (Widget)0)
3355 return;
3356
3357 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3358 if (currentpage != nr)
3359 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3360}
3361#endif
3362
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363/*
3364 * Set the colors of Widget "id" to the menu colors.
3365 */
3366 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003367gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368{
3369 if (gui.menu_bg_pixel != INVALCOLOR)
3370#if (XmVersion >= 1002)
3371 XmChangeColor(id, gui.menu_bg_pixel);
3372#else
3373 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3374#endif
3375 if (gui.menu_fg_pixel != INVALCOLOR)
3376 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3377}
3378
3379/*
3380 * Set the colors of Widget "id" to the scrollbar colors.
3381 */
3382 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003383gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384{
3385 if (gui.scroll_bg_pixel != INVALCOLOR)
3386#if (XmVersion >= 1002)
3387 XmChangeColor(id, gui.scroll_bg_pixel);
3388#else
3389 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3390#endif
3391 if (gui.scroll_fg_pixel != INVALCOLOR)
3392 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3393}
3394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395/*
3396 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3397 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003398 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003399gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003401#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402#ifdef FONTSET_ALWAYS
3403 if (gui.menu_fontset != NOFONTSET)
3404 {
3405 XmFontList fl;
3406
3407 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3408 if (fl != NULL)
3409 {
3410 if (XtIsManaged(id))
3411 {
3412 XtUnmanageChild(id);
3413 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003414 // We should force the widget to recalculate its
3415 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 XtManageChild(id);
3417 }
3418 else
3419 XtVaSetValues(id, XmNfontList, fl, NULL);
3420 XmFontListFree(fl);
3421 }
3422 }
3423#else
3424 if (gui.menu_font != NOFONT)
3425 {
3426 XmFontList fl;
3427
3428 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3429 if (fl != NULL)
3430 {
3431 if (XtIsManaged(id))
3432 {
3433 XtUnmanageChild(id);
3434 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003435 // We should force the widget to recalculate its
3436 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 XtManageChild(id);
3438 }
3439 else
3440 XtVaSetValues(id, XmNfontList, fl, NULL);
3441 XmFontListFree(fl);
3442 }
3443 }
3444#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446}
3447
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448
3449/*
3450 * We don't create it twice for the sake of speed.
3451 */
3452
3453typedef struct _SharedFindReplace
3454{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003455 Widget dialog; // the main dialog widget
3456 Widget wword; // 'Exact match' check button
3457 Widget mcase; // 'match case' check button
3458 Widget up; // search direction 'Up' radio button
3459 Widget down; // search direction 'Down' radio button
3460 Widget what; // 'Find what' entry text widget
3461 Widget with; // 'Replace with' entry text widget
3462 Widget find; // 'Find Next' action button
3463 Widget replace; // 'Replace With' action button
3464 Widget all; // 'Replace All' action button
3465 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466
3467 Widget cancel;
3468} SharedFindReplace;
3469
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003470static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3471static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003474find_replace_destroy_callback(
3475 Widget w UNUSED,
3476 XtPointer client_data,
3477 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478{
3479 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3480
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003481 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003482 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 cd->dialog = (Widget)0;
3484}
3485
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003487find_replace_dismiss_callback(
3488 Widget w UNUSED,
3489 XtPointer client_data,
3490 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491{
3492 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3493
3494 if (cd != NULL)
3495 XtUnmanageChild(cd->dialog);
3496}
3497
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003499entry_activate_callback(
3500 Widget w UNUSED,
3501 XtPointer client_data,
3502 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503{
3504 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3505}
3506
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003508find_replace_callback(
3509 Widget w UNUSED,
3510 XtPointer client_data,
3511 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003512{
3513 long_u flags = (long_u)client_data;
3514 char *find_text, *repl_text;
3515 Boolean direction_down = TRUE;
3516 Boolean wword;
3517 Boolean mcase;
3518 SharedFindReplace *sfr;
3519
3520 if (flags == FRD_UNDO)
3521 {
3522 char_u *save_cpo = p_cpo;
3523
Bram Moolenaar734a8672019-12-02 22:49:38 +01003524 // No need to be Vi compatible here.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525 p_cpo = (char_u *)"";
3526 u_undo(1);
3527 p_cpo = save_cpo;
3528 gui_update_screen();
3529 return;
3530 }
3531
Bram Moolenaar734a8672019-12-02 22:49:38 +01003532 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 if (flags == FRD_FINDNEXT)
3534 {
3535 repl_text = NULL;
3536 sfr = &find_widgets;
3537 }
3538 else
3539 {
3540 repl_text = XmTextFieldGetString(repl_widgets.with);
3541 sfr = &repl_widgets;
3542 }
3543 find_text = XmTextFieldGetString(sfr->what);
3544 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3545 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3546 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3547 if (wword)
3548 flags |= FRD_WHOLE_WORD;
3549 if (mcase)
3550 flags |= FRD_MATCH_CASE;
3551
3552 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3553 direction_down);
3554
3555 if (find_text != NULL)
3556 XtFree(find_text);
3557 if (repl_text != NULL)
3558 XtFree(repl_text);
3559}
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003562find_replace_keypress(
3563 Widget w UNUSED,
3564 SharedFindReplace *frdp,
3565 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003566{
3567 KeySym keysym;
3568
3569 if (frdp == NULL)
3570 return;
3571
3572 keysym = XLookupKeysym(event, 0);
3573
Bram Moolenaar734a8672019-12-02 22:49:38 +01003574 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575 if (keysym == XK_Escape)
3576 XtUnmanageChild(frdp->dialog);
3577}
3578
3579 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003580set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003581{
3582 XmString str;
3583 char_u *p, *next;
3584 KeySym mnemonic = NUL;
3585
3586 if (!w)
3587 return;
3588
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003589 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003590 if (p == NULL)
3591 return;
3592 for (next = p; *next; ++next)
3593 {
3594 if (*next == DLG_HOTKEY_CHAR)
3595 {
3596 int len = STRLEN(next);
3597
3598 if (len > 0)
3599 {
3600 mch_memmove(next, next + 1, len);
3601 mnemonic = next[0];
3602 }
3603 }
3604 }
3605
3606 str = XmStringCreateSimple((char *)p);
3607 vim_free(p);
3608 if (str)
3609 {
3610 XtVaSetValues(w,
3611 XmNlabelString, str,
3612 XmNmnemonic, mnemonic,
3613 NULL);
3614 XmStringFree(str);
3615 }
3616 gui_motif_menu_fontlist(w);
3617}
3618
3619 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003620find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621{
3622 SharedFindReplace *frdp;
3623 Widget separator;
3624 Widget input_form;
3625 Widget button_form;
3626 Widget toggle_form;
3627 Widget frame;
3628 XmString str;
3629 int n;
3630 Arg args[6];
3631 int wword = FALSE;
3632 int mcase = !p_ic;
3633 Dimension width;
3634 Dimension widest;
3635 char_u *entry_text;
3636
3637 frdp = do_replace ? &repl_widgets : &find_widgets;
3638
Bram Moolenaar734a8672019-12-02 22:49:38 +01003639 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3641
Bram Moolenaar734a8672019-12-02 22:49:38 +01003642 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 if (frdp->dialog)
3644 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003645 gui_motif_synch_fonts();
3646
Bram Moolenaar734a8672019-12-02 22:49:38 +01003647 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648 if (XtIsManaged(frdp->dialog))
3649 XMapRaised(XtDisplay(frdp->dialog),
3650 XtWindow(XtParent(frdp->dialog)));
3651 else
3652 XtManageChild(frdp->dialog);
3653 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3654 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3655
3656 if (entry_text != NULL)
3657 XmTextFieldSetString(frdp->what, (char *)entry_text);
3658 vim_free(entry_text);
3659
3660 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3661 return;
3662 }
3663
Bram Moolenaar734a8672019-12-02 22:49:38 +01003664 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 if (do_replace)
3666 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3667 else
3668 str = XmStringCreateSimple(_("VIM - Search..."));
3669
3670 n = 0;
3671 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3672 XtSetArg(args[n], XmNnoResize, True); n++;
3673 XtSetArg(args[n], XmNdialogTitle, str); n++;
3674
3675 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3676 XmStringFree(str);
3677 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3678 find_replace_destroy_callback, frdp);
3679
3680 button_form = XtVaCreateWidget("buttonForm",
3681 xmFormWidgetClass, frdp->dialog,
3682 XmNrightAttachment, XmATTACH_FORM,
3683 XmNrightOffset, 4,
3684 XmNtopAttachment, XmATTACH_FORM,
3685 XmNtopOffset, 4,
3686 XmNbottomAttachment, XmATTACH_FORM,
3687 XmNbottomOffset, 4,
3688 NULL);
3689
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690 frdp->find = XtVaCreateManagedWidget("findButton",
3691 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692 XmNsensitive, True,
3693 XmNtopAttachment, XmATTACH_FORM,
3694 XmNleftAttachment, XmATTACH_FORM,
3695 XmNrightAttachment, XmATTACH_FORM,
3696 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003697 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698
3699 XtAddCallback(frdp->find, XmNactivateCallback,
3700 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003701 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702
3703 if (do_replace)
3704 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3706 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 XmNtopAttachment, XmATTACH_WIDGET,
3708 XmNtopWidget, frdp->find,
3709 XmNleftAttachment, XmATTACH_FORM,
3710 XmNrightAttachment, XmATTACH_FORM,
3711 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003712 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 XtAddCallback(frdp->replace, XmNactivateCallback,
3714 find_replace_callback, (XtPointer)FRD_REPLACE);
3715
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3717 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 XmNtopAttachment, XmATTACH_WIDGET,
3719 XmNtopWidget, frdp->replace,
3720 XmNleftAttachment, XmATTACH_FORM,
3721 XmNrightAttachment, XmATTACH_FORM,
3722 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003723 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724 XtAddCallback(frdp->all, XmNactivateCallback,
3725 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3726
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 frdp->undo = XtVaCreateManagedWidget("undoButton",
3728 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 XmNtopAttachment, XmATTACH_WIDGET,
3730 XmNtopWidget, frdp->all,
3731 XmNleftAttachment, XmATTACH_FORM,
3732 XmNrightAttachment, XmATTACH_FORM,
3733 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003734 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 XtAddCallback(frdp->undo, XmNactivateCallback,
3736 find_replace_callback, (XtPointer)FRD_UNDO);
3737 }
3738
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3740 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741 XmNleftAttachment, XmATTACH_FORM,
3742 XmNrightAttachment, XmATTACH_FORM,
3743 XmNbottomAttachment, XmATTACH_FORM,
3744 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003745 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746 XtAddCallback(frdp->cancel, XmNactivateCallback,
3747 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003748 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749
3750 XtManageChild(button_form);
3751
3752 n = 0;
3753 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3754 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3755 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3756 XtSetArg(args[n], XmNrightOffset, 4); n++;
3757 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3758 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3759 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3760 XtManageChild(separator);
3761
3762 input_form = XtVaCreateWidget("inputForm",
3763 xmFormWidgetClass, frdp->dialog,
3764 XmNleftAttachment, XmATTACH_FORM,
3765 XmNleftOffset, 4,
3766 XmNrightAttachment, XmATTACH_WIDGET,
3767 XmNrightWidget, separator,
3768 XmNrightOffset, 4,
3769 XmNtopAttachment, XmATTACH_FORM,
3770 XmNtopOffset, 4,
3771 NULL);
3772
3773 {
3774 Widget label_what;
3775 Widget label_with = (Widget)0;
3776
3777 str = XmStringCreateSimple(_("Find what:"));
3778 label_what = XtVaCreateManagedWidget("whatLabel",
3779 xmLabelGadgetClass, input_form,
3780 XmNlabelString, str,
3781 XmNleftAttachment, XmATTACH_FORM,
3782 XmNtopAttachment, XmATTACH_FORM,
3783 XmNtopOffset, 4,
3784 NULL);
3785 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003786 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787
3788 frdp->what = XtVaCreateManagedWidget("whatText",
3789 xmTextFieldWidgetClass, input_form,
3790 XmNtopAttachment, XmATTACH_FORM,
3791 XmNrightAttachment, XmATTACH_FORM,
3792 XmNleftAttachment, XmATTACH_FORM,
3793 NULL);
3794
3795 if (do_replace)
3796 {
3797 frdp->with = XtVaCreateManagedWidget("withText",
3798 xmTextFieldWidgetClass, input_form,
3799 XmNtopAttachment, XmATTACH_WIDGET,
3800 XmNtopWidget, frdp->what,
3801 XmNtopOffset, 4,
3802 XmNleftAttachment, XmATTACH_FORM,
3803 XmNrightAttachment, XmATTACH_FORM,
3804 XmNbottomAttachment, XmATTACH_FORM,
3805 NULL);
3806
3807 XtAddCallback(frdp->with, XmNactivateCallback,
3808 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3809
3810 str = XmStringCreateSimple(_("Replace with:"));
3811 label_with = XtVaCreateManagedWidget("withLabel",
3812 xmLabelGadgetClass, input_form,
3813 XmNlabelString, str,
3814 XmNleftAttachment, XmATTACH_FORM,
3815 XmNtopAttachment, XmATTACH_WIDGET,
3816 XmNtopWidget, frdp->what,
3817 XmNtopOffset, 4,
3818 XmNbottomAttachment, XmATTACH_FORM,
3819 NULL);
3820 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003821 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822
3823 /*
3824 * Make the entry activation only change the input focus onto the
3825 * with item.
3826 */
3827 XtAddCallback(frdp->what, XmNactivateCallback,
3828 entry_activate_callback, frdp->with);
3829 XtAddEventHandler(frdp->with, KeyPressMask, False,
3830 (XtEventHandler)find_replace_keypress,
3831 (XtPointer) frdp);
3832
3833 }
3834 else
3835 {
3836 /*
3837 * Make the entry activation do the search.
3838 */
3839 XtAddCallback(frdp->what, XmNactivateCallback,
3840 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3841 }
3842 XtAddEventHandler(frdp->what, KeyPressMask, False,
3843 (XtEventHandler)find_replace_keypress,
3844 (XtPointer)frdp);
3845
Bram Moolenaar734a8672019-12-02 22:49:38 +01003846 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 n = 0;
3848 XtSetArg(args[n], XmNwidth, &width); n++;
3849 XtGetValues(label_what, args, n);
3850 widest = width;
3851 if (do_replace)
3852 {
3853 XtGetValues(label_with, args, n);
3854 if (width > widest)
3855 widest = width;
3856 }
3857
3858 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3859 if (do_replace)
3860 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3861
3862 }
3863
3864 XtManageChild(input_form);
3865
3866 {
3867 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003868 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869
3870 frame = XtVaCreateWidget("directionFrame",
3871 xmFrameWidgetClass, frdp->dialog,
3872 XmNtopAttachment, XmATTACH_WIDGET,
3873 XmNtopWidget, input_form,
3874 XmNtopOffset, 4,
3875 XmNbottomAttachment, XmATTACH_FORM,
3876 XmNbottomOffset, 4,
3877 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3878 XmNrightWidget, input_form,
3879 NULL);
3880
3881 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003882 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 xmLabelGadgetClass, frame,
3884 XmNlabelString, str,
3885 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3886 XmNchildType, XmFRAME_TITLE_CHILD,
3887 NULL);
3888 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003889 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890
3891 radio_box = XmCreateRadioBox(frame, "radioBox",
3892 (ArgList)NULL, 0);
3893
3894 str = XmStringCreateSimple( _("Up"));
3895 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3896 xmToggleButtonGadgetClass, radio_box,
3897 XmNlabelString, str,
3898 XmNset, False,
3899 NULL);
3900 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003901 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902
3903 str = XmStringCreateSimple(_("Down"));
3904 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3905 xmToggleButtonGadgetClass, radio_box,
3906 XmNlabelString, str,
3907 XmNset, True,
3908 NULL);
3909 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003910 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911
3912 XtManageChild(radio_box);
3913 XtManageChild(frame);
3914 }
3915
3916 toggle_form = XtVaCreateWidget("toggleForm",
3917 xmFormWidgetClass, frdp->dialog,
3918 XmNleftAttachment, XmATTACH_FORM,
3919 XmNleftOffset, 4,
3920 XmNrightAttachment, XmATTACH_WIDGET,
3921 XmNrightWidget, frame,
3922 XmNrightOffset, 4,
3923 XmNtopAttachment, XmATTACH_WIDGET,
3924 XmNtopWidget, input_form,
3925 XmNtopOffset, 4,
3926 XmNbottomAttachment, XmATTACH_FORM,
3927 XmNbottomOffset, 4,
3928 NULL);
3929
3930 str = XmStringCreateSimple(_("Match whole word only"));
3931 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3932 xmToggleButtonGadgetClass, toggle_form,
3933 XmNlabelString, str,
3934 XmNtopAttachment, XmATTACH_FORM,
3935 XmNtopOffset, 4,
3936 XmNleftAttachment, XmATTACH_FORM,
3937 XmNleftOffset, 4,
3938 XmNset, wword,
3939 NULL);
3940 XmStringFree(str);
3941
3942 str = XmStringCreateSimple(_("Match case"));
3943 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3944 xmToggleButtonGadgetClass, toggle_form,
3945 XmNlabelString, str,
3946 XmNleftAttachment, XmATTACH_FORM,
3947 XmNleftOffset, 4,
3948 XmNtopAttachment, XmATTACH_WIDGET,
3949 XmNtopWidget, frdp->wword,
3950 XmNtopOffset, 4,
3951 XmNset, mcase,
3952 NULL);
3953 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003954 gui_motif_menu_fontlist(frdp->wword);
3955 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956
3957 XtManageChild(toggle_form);
3958
3959 if (entry_text != NULL)
3960 XmTextFieldSetString(frdp->what, (char *)entry_text);
3961 vim_free(entry_text);
3962
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003963 gui_motif_synch_fonts();
3964
3965 manage_centered(frdp->dialog);
3966 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3968}
3969
3970 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003971gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972{
3973 if (!gui.in_use)
3974 return;
3975
3976 find_replace_dialog_create(eap->arg, FALSE);
3977}
3978
3979
3980 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003981gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982{
3983 if (!gui.in_use)
3984 return;
3985
3986 find_replace_dialog_create(eap->arg, TRUE);
3987}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003988
3989/*
3990 * Synchronize all gui elements, which are dependant upon the
3991 * main text font used. Those are in esp. the find/replace dialogs.
3992 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003993 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003994 */
3995 void
3996gui_motif_synch_fonts(void)
3997{
3998 SharedFindReplace *frdp;
3999 int do_replace;
4000 XFontStruct *font;
4001 XmFontList font_list;
4002
Bram Moolenaar734a8672019-12-02 22:49:38 +01004003 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4004 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004005 font = (XFontStruct *)gui.norm_font;
4006 if (font == NULL)
4007 return;
4008
4009 font_list = gui_motif_create_fontlist(font);
4010
Bram Moolenaar734a8672019-12-02 22:49:38 +01004011 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004012 for (do_replace = 0; do_replace <= 1; ++do_replace)
4013 {
4014 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4015 if (frdp->dialog)
4016 {
4017 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4018 if (do_replace)
4019 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4020 }
4021 }
4022
4023 XmFontListFree(font_list);
4024}