blob: 1693df974d4ee49dd50aecb9d04312ddb55e1ebf [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 Moolenaarb7fcef52005-01-02 11:31:05 +000052#include "gui_xmebw.h" /* for our Enhanced Button Widget */
53
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)
83/* remember the last set value for the tearoff item */
84static 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) {
181 /* Tab scroller (next) is visible */
182 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
183 (event->y >= pos_y) && (event->y <= pos_y + height)) {
184 /* Clicked on the scroller */
185 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 Moolenaarf193fff2006-04-27 00:02:13 +0000241 /* When ignoring events don't show the menu. */
242 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 Moolenaarc6fe9192006-04-09 21:54:49 +0000252 /* 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
319 /* FIXME: we should be doing the whole drawing ourself here. */
320 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
410 /* Make sure the "Quit" menu entry of the window manager is ignored */
411 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 {
426 Arg al[7]; /* Make sure there is enough room for arguments! */
427 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
436 /* Always stick to right hand side. */
437 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
443 /* Remember the default colors, needed for ":hi clear". */
444 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
486 /* Create the Vim GUI tabline */
487 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
606 /* Pretend we don't have input focus, we will get an event if we do. */
607 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
630 /* 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
662 /* 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
669 /* Get the pointer position (x, y) */
670 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
671 &x, &y, &win_x, &win_y, &mask);
672
673 /* Translate the pointer position (x, y) into a position for the new
674 window that will place the pointer at its center */
675 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
682 /* Ensure that the dialog remains on screen */
683 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
694 /* Set desired window position in the DialogShell */
695 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
696
697 /* Map the widget */
698 XtMapWidget(shell);
699
700 /* 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)
715 /* Motif 1.1 method */
716 font_list = XmFontListCreate(font, STRING_TAG);
717# else
718 /* Motif 1.2 method */
719 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
735 /* Motif 1.2 method */
736 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 {
773 /* toolBar is attached to top form */
774 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
892 for (menu = root_menu; menu != NULL; menu = menu->next)
893 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
912 /* Only create the popup menu when it's actually used, otherwise there
913 * is a delay when using the right mouse button. */
914# 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)
943 /* submenu: count the tearoff item (needed for LessTif) */
944 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
952 if (menu->id == (Widget)0) /* failed */
953 return;
954
955 /* add accelerator text */
956 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
970 if (menu->submenu_id == (Widget)0) /* failed */
971 return;
972
973#if (XmVersion >= 1002)
974 /* Set the colors for the tear off widget */
975 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 Moolenaar933eb392007-05-10 17:52:45 +00001008 /* 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(
1080 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;
1085 static Dimension height = 21; /* normal height of a menu item */
1086
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
1095 /* Find any menu Widget, to be able to call XtManageChild() */
1096 else
1097 for (mp = root_menu; mp != NULL; mp = mp->next)
1098 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;
1115 for (mp = root_menu; mp != NULL; mp = mp->next)
1116 {
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 Moolenaar071d4272004-06-13 20:20:40 +00001142 /* 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. */
1145 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
1171 /* Create the "sensitive" pixmap */
1172 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{
1192 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1193 char **xpm = NULL; /* xpm array */
1194 int res;
1195
Bram Moolenaar7c626922005-02-07 22:01:03 +00001196 *fname = NULL;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001197 buf[0] = NUL; /* start with NULL path */
1198
1199 if (menu->iconfile != NULL)
1200 {
1201 /* Use the "icon=" argument. */
1202 gui_find_iconfile(menu->iconfile, buf, "xpm");
1203 res = check_xpm(buf);
1204
1205 /* If it failed, try using the menu name. */
1206 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 {
1241 if (menu->xpm_fname != NULL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001242 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001243 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1244 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1245 }
1246 return n;
1247}
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001248#endif /* FEAT_TOOLBAR */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249
1250 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001251gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252{
1253 XmString label;
1254 vimmenu_T *parent = menu->parent;
1255
1256# ifdef EBCDIC
1257 menu->mnemonic = 0;
1258# endif
1259
1260# if (XmVersion <= 1002)
1261 /* Don't add Popup menu items when the popup menu isn't used. */
1262 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1263 return;
1264# endif
1265
1266# ifdef FEAT_TOOLBAR
1267 if (menu_is_toolbar(parent->name))
1268 {
1269 WidgetClass type;
1270 XmString xms = NULL; /* fallback label if pixmap not found */
1271 int n;
1272 Arg args[18];
1273
1274 n = 0;
1275 if (menu_is_separator(menu->name))
1276 {
1277 char *cp;
1278 Dimension wid;
1279
1280 /*
1281 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1282 * a width specifier. If no width is specified then we choose one.
1283 */
1284 cp = (char *)vim_strchr(menu->name, ':');
1285 if (cp != NULL)
1286 wid = (Dimension)atoi(++cp);
1287 else
1288 wid = 4;
1289
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 type = xmSeparatorWidgetClass;
1291 XtSetArg(args[n], XmNwidth, wid); n++;
1292 XtSetArg(args[n], XmNminWidth, wid); n++;
1293 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001294 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 }
1296 else
1297 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 /* Without shadows one can't sense whatever the button has been
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001299 * pressed or not! However we want to save a bit of space...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001300 * Need the highlightThickness to see the focus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001302 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1304 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1305 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001306 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001307 /* Set the label here, so that we can switch between icons/text
1308 * by changing the XmNlabelType resource. */
1309 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1310 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001311
Bram Moolenaar7c626922005-02-07 22:01:03 +00001312 n = add_pixmap_args(menu, args, n);
1313
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001314 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 }
1316
1317 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1318 if (menu->id == NULL)
1319 {
1320 menu->id = XtCreateManagedWidget((char *)menu->dname,
1321 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001322 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {
1324 XtAddCallback(menu->id,
1325 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326# ifdef FEAT_FOOTER
1327 XtAddEventHandler(menu->id, EnterWindowMask, False,
1328 toolbarbutton_enter_cb, menu);
1329 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1330 toolbarbutton_leave_cb, menu);
1331# endif
1332 }
1333 }
1334 else
1335 XtSetValues(menu->id, args, n);
1336 if (xms != NULL)
1337 XmStringFree(xms);
1338
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001339# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001341# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342
1343 menu->parent = parent;
1344 menu->submenu_id = NULL;
1345 /* When adding first item to toolbar it might have to be enabled .*/
1346 if (!XtIsManaged(XtParent(toolBar))
1347 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1348 gui_mch_show_toolbar(TRUE);
1349 gui.toolbar_height = gui_mch_compute_toolbar_height();
1350 return;
1351 } /* toolbar menu item */
1352# endif
1353
1354 /* No parent, must be a non-menubar menu */
1355 if (parent->submenu_id == (Widget)0)
1356 return;
1357
1358 menu->submenu_id = (Widget)0;
1359
1360 /* Add menu separator */
1361 if (menu_is_separator(menu->name))
1362 {
1363 menu->id = XtVaCreateWidget("subMenu",
1364 xmSeparatorGadgetClass, parent->submenu_id,
1365#if (XmVersion >= 1002)
1366 /* count the tearoff item (needed for LessTif) */
1367 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1368 ? 1 : 0),
1369#endif
1370 NULL);
1371 gui_motif_menu_colors(menu->id);
1372 return;
1373 }
1374
1375 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1376 if (label == NULL)
1377 return;
1378 menu->id = XtVaCreateWidget("subMenu",
1379 xmPushButtonWidgetClass, parent->submenu_id,
1380 XmNlabelString, label,
1381 XmNmnemonic, menu->mnemonic,
1382#if (XmVersion >= 1002)
1383 /* count the tearoff item (needed for LessTif) */
1384 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1385 ? 1 : 0),
1386#endif
1387 NULL);
1388 gui_motif_menu_colors(menu->id);
1389 gui_motif_menu_fontlist(menu->id);
1390 XmStringFree(label);
1391
1392 if (menu->id != (Widget)0)
1393 {
1394 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1395 (XtPointer)menu);
1396 /* add accelerator text */
1397 gui_motif_add_actext(menu);
1398 }
1399}
1400
1401#if (XmVersion <= 1002) || defined(PROTO)
1402/*
1403 * This function will destroy/create the popup menus dynamically,
1404 * according to the value of 'mousemodel'.
1405 * This will fix the "right mouse button freeze" that occurs when
1406 * there exists a popup menu but it isn't managed.
1407 */
1408 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001409gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410{
1411 int idx = 0;
1412
1413 /* When GUI hasn't started the menus have not been created. */
1414 if (!gui.in_use)
1415 return;
1416
1417 while (menu)
1418 {
1419 if (menu->children != NULL)
1420 {
1421 if (menu_is_popup(menu->name))
1422 {
1423 if (mouse_model_popup())
1424 {
1425 /* Popup menu will be used. Create the popup menus. */
1426 gui_mch_add_menu(menu, idx);
1427 gui_motif_update_mousemodel(menu->children);
1428 }
1429 else
1430 {
1431 /* Popup menu will not be used. Destroy the popup menus. */
1432 gui_motif_update_mousemodel(menu->children);
1433 gui_mch_destroy_menu(menu);
1434 }
1435 }
1436 }
1437 else if (menu_is_child_of_popup(menu))
1438 {
1439 if (mouse_model_popup())
1440 gui_mch_add_menu_item(menu, idx);
1441 else
1442 gui_mch_destroy_menu(menu);
1443 }
1444 menu = menu->next;
1445 ++idx;
1446 }
1447}
1448#endif
1449
1450 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001451gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452{
1453 if (menuBar == (Widget)0)
1454 return;
1455 gui_motif_menu_colors(menuBar);
1456#ifdef FEAT_TOOLBAR
1457 gui_motif_menu_colors(toolBarFrame);
1458 gui_motif_menu_colors(toolBar);
1459#endif
1460
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001461 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462}
1463
1464 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001465gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466{
1467 if (menuBar == (Widget)0)
1468 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001469 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {
1471 Dimension height;
1472 Position w, h;
1473
1474 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1475 gui.menu_height = height;
1476
1477 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1478 gui_resize_shell(w, h
1479#ifdef FEAT_XIM
1480 - xim_get_status_area_height()
1481#endif
1482 );
1483 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001484 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 ui_new_shellsize();
1486}
1487
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001488#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001490gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491{
1492# ifdef FEAT_TOOLBAR
1493 vimmenu_T *menu;
1494
1495 if (toolBar == (Widget)0)
1496 return;
1497
1498 menu = gui_find_menu((char_u *)"ToolBar");
1499 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001500 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501# endif
1502}
1503
1504 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001505gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506{
1507# ifdef FEAT_TOOLBAR
1508 vimmenu_T *toolbar;
1509
1510 if (toolBar == (Widget)0)
1511 return;
1512
1513 toolbar = gui_find_menu((char_u *)"ToolBar");
1514 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001515 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516# endif
1517}
1518#endif
1519
1520 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001521submenu_change(
1522 vimmenu_T *menu,
1523 int colors) /* TRUE for colors, FALSE for font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524{
1525 vimmenu_T *mp;
1526
1527 for (mp = menu; mp != NULL; mp = mp->next)
1528 {
1529 if (mp->id != (Widget)0)
1530 {
1531 if (colors)
1532 {
1533 gui_motif_menu_colors(mp->id);
1534#ifdef FEAT_TOOLBAR
1535 /* For a toolbar item: Free the pixmap and allocate a new one,
1536 * so that the background color is right. */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001537 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001539 int n = 0;
1540 Arg args[18];
1541
Bram Moolenaar7c626922005-02-07 22:01:03 +00001542 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001543 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001545# ifdef FEAT_BEVAL_GUI
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001546 /* If we have a tooltip, then we need to change its font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 if (mp->tip != NULL)
1548 {
1549 Arg args[2];
1550
1551 args[0].name = XmNbackground;
1552 args[0].value = gui.tooltip_bg_pixel;
1553 args[1].name = XmNforeground;
1554 args[1].value = gui.tooltip_fg_pixel;
1555 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1556 }
1557# endif
1558#endif
1559 }
1560 else
1561 {
1562 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001563#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001564 /* If we have a tooltip, then we need to change its font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565 if (mp->tip != NULL)
1566 {
1567 Arg args[1];
1568
1569 args[0].name = XmNfontList;
1570 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1571 &gui.tooltip_fontset);
1572 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1573 }
1574#endif
1575 }
1576 }
1577
1578 if (mp->children != NULL)
1579 {
1580#if (XmVersion >= 1002)
1581 /* Set the colors/font for the tear off widget */
1582 if (mp->submenu_id != (Widget)0)
1583 {
1584 if (colors)
1585 gui_motif_menu_colors(mp->submenu_id);
1586 else
1587 gui_motif_menu_fontlist(mp->submenu_id);
1588 toggle_tearoff(mp->submenu_id);
1589 }
1590#endif
1591 /* Set the colors for the children */
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001592 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 }
1594 }
1595}
1596
1597/*
1598 * Destroy the machine specific menu widget.
1599 */
1600 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001601gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602{
1603 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1604 * On the other hand, problems have been reported that the submenu must be
1605 * deleted first...
1606 *
1607 * This code should be basically identical to that in the file gui_athena.c
1608 * because they are both Xt based.
1609 */
1610 if (menu->submenu_id != (Widget)0)
1611 {
1612 XtDestroyWidget(menu->submenu_id);
1613 menu->submenu_id = (Widget)0;
1614 }
1615
1616 if (menu->id != (Widget)0)
1617 {
1618 Widget parent;
1619
1620 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001621#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001622 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {
1624 /* We try to destroy this before the actual menu, because there are
1625 * callbacks, etc. that will be unregistered during the tooltip
1626 * destruction.
1627 *
1628 * If you call "gui_mch_destroy_beval_area()" after destroying
1629 * menu->id, then the tooltip's window will have already been
1630 * deallocated by Xt, and unknown behaviour will ensue (probably
1631 * a core dump).
1632 */
1633 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
1646 /* When removing last toolbar item, don't display the toolbar. */
1647 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
1666#endif /* FEAT_MENU */
1667
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 {
1676 /* Use the values saved when starting up. These should come from the
1677 * window manager or a resources file. */
1678 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),
1708 XmNmaximum, max + 1, /* Motif has max one past the end */
1709 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
1746 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001747gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748{
1749 Arg args[16];
1750 int n;
1751
1752 if (sb->id != (Widget)0)
1753 {
1754 n = 0;
1755 if (flag)
1756 {
1757 switch (sb->type)
1758 {
1759 case SBAR_LEFT:
1760 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1761 break;
1762
1763 case SBAR_RIGHT:
1764 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1765 break;
1766
1767 case SBAR_BOTTOM:
1768 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1769 break;
1770 }
1771 XtSetValues(textArea, args, n);
1772 XtManageChild(sb->id);
1773 }
1774 else
1775 {
1776 if (!gui.which_scrollbars[sb->type])
1777 {
1778 /* The scrollbars of this type are all disabled, adjust the
1779 * textArea attachment offset. */
1780 switch (sb->type)
1781 {
1782 case SBAR_LEFT:
1783 XtSetArg(args[n], XmNleftOffset, 0); n++;
1784 break;
1785
1786 case SBAR_RIGHT:
1787 XtSetArg(args[n], XmNrightOffset, 0); n++;
1788 break;
1789
1790 case SBAR_BOTTOM:
1791 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1792 break;
1793 }
1794 XtSetValues(textArea, args, n);
1795 }
1796 XtUnmanageChild(sb->id);
1797 }
1798 }
1799}
1800
1801 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001802gui_mch_create_scrollbar(
1803 scrollbar_T *sb,
1804 int orient) /* SBAR_VERT or SBAR_HORIZ */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805{
1806 Arg args[16];
1807 int n;
1808
1809 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 XtSetArg(args[n], XmNminimum, 0); n++;
1811 XtSetArg(args[n], XmNorientation,
1812 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1813
1814 switch (sb->type)
1815 {
1816 case SBAR_LEFT:
1817 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1818 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1819 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1820 break;
1821
1822 case SBAR_RIGHT:
1823 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1824 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1825 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1826 break;
1827
1828 case SBAR_BOTTOM:
1829 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1830 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1831 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1832 break;
1833 }
1834
1835 sb->id = XtCreateWidget("scrollBar",
1836 xmScrollBarWidgetClass, textAreaForm, args, n);
1837
1838 /* Remember the default colors, needed for ":hi clear". */
1839 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1840 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1841 XtVaGetValues(sb->id,
1842 XmNbackground, &gui.scroll_def_bg_pixel,
1843 XmNforeground, &gui.scroll_def_fg_pixel,
1844 NULL);
1845
1846 if (sb->id != (Widget)0)
1847 {
1848 gui_mch_set_scrollbar_colors(sb);
1849 XtAddCallback(sb->id, XmNvalueChangedCallback,
1850 scroll_cb, (XtPointer)sb->ident);
1851 XtAddCallback(sb->id, XmNdragCallback,
1852 scroll_cb, (XtPointer)sb->ident);
1853 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1854 (XtPointer)0);
1855 }
1856}
1857
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001859gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860{
1861 if (sb->id != (Widget)0)
1862 XtDestroyWidget(sb->id);
1863}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864
1865 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001866gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867{
1868 if (sb->id != (Widget)0)
1869 {
1870 if (gui.scroll_bg_pixel != INVALCOLOR)
1871 {
1872#if (XmVersion>=1002)
1873 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1874#else
1875 XtVaSetValues(sb->id,
1876 XmNtroughColor, gui.scroll_bg_pixel,
1877 NULL);
1878#endif
1879 }
1880
1881 if (gui.scroll_fg_pixel != INVALCOLOR)
1882 XtVaSetValues(sb->id,
1883 XmNforeground, gui.scroll_fg_pixel,
1884#if (XmVersion<1002)
1885 XmNbackground, gui.scroll_fg_pixel,
1886#endif
1887 NULL);
1888 }
1889
1890 /* This is needed for the rectangle below the vertical scrollbars. */
1891 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1892 gui_motif_scroll_colors(textAreaForm);
1893}
1894
1895/*
1896 * Miscellaneous stuff:
1897 */
1898
1899 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001900gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901{
1902 return(XtWindow(textArea));
1903}
1904
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001905/*
1906 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1907 * When one is found, simulate a button press on that widget and give it the
1908 * keyboard focus. If the mnemonic is on a label, look in the userData field
1909 * of the label to see if it points to another widget, and give that the focus.
1910 */
1911 static void
1912do_mnemonic(Widget w, unsigned int keycode)
1913{
1914 WidgetList children;
1915 int numChildren, i;
1916 Boolean isMenu;
1917 KeySym mnemonic = '\0';
1918 char mneString[2];
1919 Widget userData;
1920 unsigned char rowColType;
1921
1922 if (XtIsComposite(w))
1923 {
1924 if (XtClass(w) == xmRowColumnWidgetClass)
1925 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001926 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001927 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1928 }
1929 else
1930 isMenu = False;
1931 if (!isMenu)
1932 {
1933 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001934 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001935 for (i = 0; i < numChildren; i++)
1936 do_mnemonic(children[i], keycode);
1937 }
1938 }
1939 else
1940 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001941 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001942 if (mnemonic != '\0')
1943 {
1944 mneString[0] = mnemonic;
1945 mneString[1] = '\0';
1946 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1947 XStringToKeysym(mneString)) == keycode)
1948 {
1949 if (XtClass(w) == xmLabelWidgetClass
1950 || XtClass(w) == xmLabelGadgetClass)
1951 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001952 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001953 if (userData != NULL && XtIsWidget(userData))
1954 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1955 }
1956 else
1957 {
1958 XKeyPressedEvent keyEvent;
1959
1960 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1961
Bram Moolenaar7db5fc82010-05-24 11:59:29 +02001962 vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001963 keyEvent.type = KeyPress;
1964 keyEvent.serial = 1;
1965 keyEvent.send_event = True;
1966 keyEvent.display = XtDisplay(w);
1967 keyEvent.window = XtWindow(w);
1968 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1969 NULL, 0);
1970 }
1971 }
1972 }
1973 }
1974}
1975
1976/*
1977 * Callback routine for dialog mnemonic processing.
1978 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001979 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001980mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001981{
1982 do_mnemonic(w, event->keycode);
1983}
1984
1985
1986/*
1987 * Search the widget tree under w for widgets with mnemonics. When found, add
1988 * a passive grab to the dialog widget for the mnemonic character, thus
1989 * directing mnemonic events to the dialog widget.
1990 */
1991 static void
1992add_mnemonic_grabs(Widget dialog, Widget w)
1993{
1994 char mneString[2];
1995 WidgetList children;
1996 int numChildren, i;
1997 Boolean isMenu;
1998 KeySym mnemonic = '\0';
1999 unsigned char rowColType;
2000
2001 if (XtIsComposite(w))
2002 {
2003 if (XtClass(w) == xmRowColumnWidgetClass)
2004 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002005 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002006 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2007 }
2008 else
2009 isMenu = False;
2010 if (!isMenu)
2011 {
2012 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002013 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002014 for (i = 0; i < numChildren; i++)
2015 add_mnemonic_grabs(dialog, children[i]);
2016 }
2017 }
2018 else
2019 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002020 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002021 if (mnemonic != '\0')
2022 {
2023 mneString[0] = mnemonic;
2024 mneString[1] = '\0';
2025 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2026 XStringToKeysym(mneString)),
2027 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2028 }
2029 }
2030}
2031
2032/*
2033 * Add a handler for mnemonics in a dialog. Motif itself only handles
2034 * mnemonics in menus. Mnemonics added or changed after this call will be
2035 * ignored.
2036 *
2037 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2038 * the appropriate label and set the XmNuserData resource of the label to the
2039 * widget to get the focus when the mnemonic is typed.
2040 */
2041 static void
2042activate_dialog_mnemonics(Widget dialog)
2043{
2044 if (!dialog)
2045 return;
2046
2047 XtAddEventHandler(dialog, KeyPressMask, False,
2048 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2049 add_mnemonic_grabs(dialog, dialog);
2050}
2051
2052/*
2053 * Removes the event handler and key-grabs for dialog mnemonic handling.
2054 */
2055 static void
2056suppress_dialog_mnemonics(Widget dialog)
2057{
2058 if (!dialog)
2059 return;
2060
2061 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2062 XtRemoveEventHandler(dialog, KeyPressMask, False,
2063 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2064}
2065
2066#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002067/*
2068 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2069 */
2070 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002071set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002072{
2073 XmFontList fl;
2074
2075#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002076 if (gui.fontset != NOFONTSET)
2077 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002078 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2079 if (fl != NULL)
2080 {
2081 if (XtIsManaged(id))
2082 {
2083 XtUnmanageChild(id);
2084 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01002085 /* We should force the widget to recalculate its
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002086 * geometry now. */
2087 XtManageChild(id);
2088 }
2089 else
2090 XtVaSetValues(id, XmNfontList, fl, NULL);
2091 XmFontListFree(fl);
2092 }
2093 }
2094#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002095 if (gui.norm_font != NOFONT)
2096 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002097 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2098 if (fl != NULL)
2099 {
2100 if (XtIsManaged(id))
2101 {
2102 XtUnmanageChild(id);
2103 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01002104 /* We should force the widget to recalculate its
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002105 * geometry now. */
2106 XtManageChild(id);
2107 }
2108 else
2109 XtVaSetValues(id, XmNfontList, fl, NULL);
2110 XmFontListFree(fl);
2111 }
2112 }
2113#endif
2114}
2115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116
2117#if defined(FEAT_BROWSE) || defined(PROTO)
2118
2119/*
2120 * file selector related stuff
2121 */
2122
2123#include <Xm/FileSB.h>
2124#include <Xm/XmStrDefs.h>
2125
2126typedef struct dialog_callback_arg
2127{
2128 char * args; /* not used right now */
2129 int id;
2130} dcbarg_T;
2131
2132static Widget dialog_wgt;
2133static char *browse_fname = NULL;
2134static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2135 /* used to set up XmStrings */
2136
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002137static void DialogCancelCB(Widget, XtPointer, XtPointer);
2138static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139
2140/*
2141 * This function is used to translate the predefined label text of the
2142 * precomposed dialogs. We do this explicitly to allow:
2143 *
2144 * - usage of gettext for translation, as in all the other places.
2145 *
2146 * - equalize the messages between different GUI implementations as far as
2147 * possible.
2148 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002149 static void
2150set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002152 XmString str;
2153 Widget w;
2154 char_u *p, *next;
2155 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156
2157 w = XtNameToWidget(parent, name);
2158
2159 if (!w)
2160 return;
2161
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002162 p = vim_strsave((char_u *)new_label);
2163 if (p == NULL)
2164 return;
2165 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002167 if (*next == DLG_HOTKEY_CHAR)
2168 {
2169 int len = STRLEN(next);
2170
2171 if (len > 0)
2172 {
2173 mch_memmove(next, next + 1, len);
2174 mnemonic = next[0];
2175 }
2176 }
2177 }
2178
2179 str = XmStringCreate((char *)p, STRING_TAG);
2180 vim_free(p);
2181
2182 if (str != NULL)
2183 {
2184 XtVaSetValues(w,
2185 XmNlabelString, str,
2186 XmNmnemonic, mnemonic,
2187 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 XmStringFree(str);
2189 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002190 gui_motif_menu_fontlist(w);
2191}
2192
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002193 static void
2194set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002195{
2196 Widget w;
2197 w = XtNameToWidget(parent, name);
2198
2199 if (!w)
2200 return;
2201
2202 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203}
2204
2205/*
2206 * Put up a file requester.
2207 * Returns the selected name in allocated memory, or NULL for Cancel.
2208 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002209 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002210gui_mch_browse(
2211 int saving UNUSED, /* select file to write */
2212 char_u *title, /* title for the window */
2213 char_u *dflt, /* default name */
2214 char_u *ext UNUSED, /* not used (extension added) */
2215 char_u *initdir, /* initial directory, NULL for current dir */
2216 char_u *filter) /* file name filter */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217{
2218 char_u dirbuf[MAXPATHL];
2219 char_u dfltbuf[MAXPATHL];
2220 char_u *pattern;
2221 char_u *tofree = NULL;
2222
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002223 /* There a difference between the resource name and value, Therefore, we
2224 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2225 * dialog name.
2226 */
2227
2228 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229
2230 if (initdir == NULL || *initdir == NUL)
2231 {
2232 mch_dirname(dirbuf, MAXPATHL);
2233 initdir = dirbuf;
2234 }
2235
2236 if (dflt == NULL)
2237 dflt = (char_u *)"";
2238 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2239 {
2240 /* The default selection should be the full path, "dflt" is only the
2241 * file name. */
2242 STRCPY(dfltbuf, initdir);
2243 add_pathsep(dfltbuf);
2244 STRCAT(dfltbuf, dflt);
2245 dflt = dfltbuf;
2246 }
2247
2248 /* Can only use one pattern for a file name. Get the first pattern out of
2249 * the filter. An empty pattern means everything matches. */
2250 if (filter == NULL)
2251 pattern = (char_u *)"";
2252 else
2253 {
2254 char_u *s, *p;
2255
2256 s = filter;
2257 for (p = filter; *p != NUL; ++p)
2258 {
2259 if (*p == '\t') /* end of description, start of pattern */
2260 s = p + 1;
2261 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2262 break;
2263 }
2264 pattern = vim_strnsave(s, p - s);
2265 tofree = pattern;
2266 if (pattern == NULL)
2267 pattern = (char_u *)"";
2268 }
2269
2270 XtVaSetValues(dialog_wgt,
2271 XtVaTypedArg,
2272 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2273 XtVaTypedArg,
2274 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2275 XtVaTypedArg,
2276 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2277 XtVaTypedArg,
2278 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2279 NULL);
2280
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002281 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2282 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2284 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002285 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002287 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2289
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002290 /* This is to save us from silly external settings using not fixed with
2291 * fonts for file selection.
2292 */
2293 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2294 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2295
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 gui_motif_menu_colors(dialog_wgt);
2297 if (gui.scroll_bg_pixel != INVALCOLOR)
2298 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2299
2300 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2301 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2302 /* We have no help in this window, so hide help button */
2303 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2304 (unsigned char)XmDIALOG_HELP_BUTTON));
2305
2306 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002307 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308
2309 /* sit in a loop until the dialog box has gone away */
2310 do
2311 {
2312 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2313 (XtInputMask)XtIMAll);
2314 } while (XtIsManaged(dialog_wgt));
2315
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002316 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 XtDestroyWidget(dialog_wgt);
2318 vim_free(tofree);
2319
2320 if (browse_fname == NULL)
2321 return NULL;
2322 return vim_strsave((char_u *)browse_fname);
2323}
2324
2325/*
2326 * The code below was originally taken from
2327 * /usr/examples/motif/xmsamplers/xmeditor.c
2328 * on Digital Unix 4.0d, but heavily modified.
2329 */
2330
2331/*
2332 * Process callback from Dialog cancel actions.
2333 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002335DialogCancelCB(
2336 Widget w UNUSED, /* widget id */
2337 XtPointer client_data UNUSED, /* data from application */
2338 XtPointer call_data UNUSED) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339{
2340 if (browse_fname != NULL)
2341 {
2342 XtFree(browse_fname);
2343 browse_fname = NULL;
2344 }
2345 XtUnmanageChild(dialog_wgt);
2346}
2347
2348/*
2349 * Process callback from Dialog actions.
2350 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002352DialogAcceptCB(
2353 Widget w UNUSED, /* widget id */
2354 XtPointer client_data UNUSED, /* data from application */
2355 XtPointer call_data) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356{
2357 XmFileSelectionBoxCallbackStruct *fcb;
2358
2359 if (browse_fname != NULL)
2360 {
2361 XtFree(browse_fname);
2362 browse_fname = NULL;
2363 }
2364 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2365
2366 /* get the filename from the file selection box */
2367 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2368
2369 /* popdown the file selection box */
2370 XtUnmanageChild(dialog_wgt);
2371}
2372
2373#endif /* FEAT_BROWSE */
2374
2375#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2376
2377static int dialogStatus;
2378
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379/*
2380 * Callback function for the textfield. When CR is hit this works like
2381 * hitting the "OK" button, ESC like "Cancel".
2382 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002384keyhit_callback(
2385 Widget w,
2386 XtPointer client_data UNUSED,
2387 XEvent *event,
2388 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389{
2390 char buf[2];
2391 KeySym key_sym;
2392
2393 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2394 {
2395 if (*buf == CAR)
2396 dialogStatus = 1;
2397 else if (*buf == ESC)
2398 dialogStatus = 2;
2399 }
2400 if ((key_sym == XK_Left || key_sym == XK_Right)
2401 && !(event->xkey.state & ShiftMask))
2402 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2403}
2404
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002406butproc(
2407 Widget w UNUSED,
2408 XtPointer client_data,
2409 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410{
2411 dialogStatus = (int)(long)client_data + 1;
2412}
2413
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414#ifdef HAVE_XPM
2415
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002417create_pixmap_label(
2418 Widget parent,
2419 String name,
2420 char **data,
2421 ArgList args,
2422 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423{
2424 Widget label;
2425 Display *dsp;
2426 Screen *scr;
2427 int depth;
2428 Pixmap pixmap = 0;
2429 XpmAttributes attr;
2430 Boolean rs;
2431 XpmColorSymbol color[5] =
2432 {
2433 {"none", NULL, 0},
2434 {"iconColor1", NULL, 0},
2435 {"bottomShadowColor", NULL, 0},
2436 {"topShadowColor", NULL, 0},
2437 {"selectColor", NULL, 0}
2438 };
2439
2440 label = XmCreateLabelGadget(parent, name, args, arg);
2441
2442 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002443 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 * no way to get the background color directly from the widget itself.
2445 * In such cases we get it from The Core part of his parent instead.
2446 */
2447 dsp = XtDisplayOfObject(label);
2448 scr = XtScreenOfObject(label);
2449 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2450 ? label : XtParent(label),
2451 XmNdepth, &depth,
2452 XmNbackground, &color[0].pixel,
2453 XmNforeground, &color[1].pixel,
2454 XmNbottomShadowColor, &color[2].pixel,
2455 XmNtopShadowColor, &color[3].pixel,
2456 XmNhighlight, &color[4].pixel,
2457 NULL);
2458
2459 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2460 attr.colorsymbols = color;
2461 attr.numsymbols = 5;
2462 attr.closeness = 65535;
2463 attr.depth = depth;
2464 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2465 data, &pixmap, NULL, &attr);
2466
2467 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2468 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2469 XtVaSetValues(label,
2470 XmNlabelType, XmPIXMAP,
2471 XmNlabelPixmap, pixmap,
2472 NULL);
2473 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2474
2475 return label;
2476}
2477#endif
2478
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002480gui_mch_dialog(
2481 int type UNUSED,
2482 char_u *title,
2483 char_u *message,
2484 char_u *button_names,
2485 int dfltbutton,
2486 char_u *textfield, /* buffer of size IOSIZE */
2487 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488{
2489 char_u *buts;
2490 char_u *p, *next;
2491 XtAppContext app;
2492 XmString label;
2493 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002494 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 Widget dialogform = NULL;
2496 Widget form = NULL;
2497 Widget dialogtextfield = NULL;
2498 Widget *buttons;
2499 Widget sep_form = NULL;
2500 Boolean vertical;
2501 Widget separator = NULL;
2502 int n;
2503 Arg args[6];
2504#ifdef HAVE_XPM
2505 char **icon_data = NULL;
2506 Widget dialogpixmap = NULL;
2507#endif
2508
2509 if (title == NULL)
2510 title = (char_u *)_("Vim dialog");
2511
2512 /* if our pointer is currently hidden, then we should show it. */
2513 gui_mch_mousehide(FALSE);
2514
2515 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2516
2517 /* Check 'v' flag in 'guioptions': vertical button placement. */
2518 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2519
2520 /* Set the title of the Dialog window */
2521 label = XmStringCreateSimple((char *)title);
2522 if (label == NULL)
2523 return -1;
2524 XtVaSetValues(dialogform,
2525 XmNdialogTitle, label,
2526 XmNhorizontalSpacing, 4,
2527 XmNverticalSpacing, vertical ? 0 : 4,
2528 NULL);
2529 XmStringFree(label);
2530
2531 /* make a copy, so that we can insert NULs */
2532 buts = vim_strsave(button_names);
2533 if (buts == NULL)
2534 return -1;
2535
2536 /* Count the number of buttons and allocate buttons[]. */
2537 butcount = 1;
2538 for (p = buts; *p; ++p)
2539 if (*p == DLG_BUTTON_SEP)
2540 ++butcount;
Bram Moolenaar964b3742019-05-24 18:54:09 +02002541 buttons = (Widget *)alloc(butcount * sizeof(Widget));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 if (buttons == NULL)
2543 {
2544 vim_free(buts);
2545 return -1;
2546 }
2547
2548 /*
2549 * Create the buttons.
2550 */
2551 sep_form = (Widget) 0;
2552 p = buts;
2553 for (butcount = 0; *p; ++butcount)
2554 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002555 KeySym mnemonic = NUL;
2556
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 for (next = p; *next; ++next)
2558 {
2559 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002560 {
2561 int len = STRLEN(next);
2562
2563 if (len > 0)
2564 {
2565 mch_memmove(next, next + 1, len);
2566 mnemonic = next[0];
2567 }
2568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 if (*next == DLG_BUTTON_SEP)
2570 {
2571 *next++ = NUL;
2572 break;
2573 }
2574 }
2575 label = XmStringCreate(_((char *)p), STRING_TAG);
2576 if (label == NULL)
2577 break;
2578
2579 buttons[butcount] = XtVaCreateManagedWidget("button",
2580 xmPushButtonWidgetClass, dialogform,
2581 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002582 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 XmNbottomAttachment, XmATTACH_FORM,
2584 XmNbottomOffset, 4,
2585 XmNshowAsDefault, butcount == dfltbutton - 1,
2586 XmNdefaultButtonShadowThickness, 1,
2587 NULL);
2588 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002589 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590
2591 /* Layout properly. */
2592
2593 if (butcount > 0)
2594 {
2595 if (vertical)
2596 XtVaSetValues(buttons[butcount],
2597 XmNtopWidget, buttons[butcount - 1],
2598 NULL);
2599 else
2600 {
2601 if (*next == NUL)
2602 {
2603 XtVaSetValues(buttons[butcount],
2604 XmNrightAttachment, XmATTACH_FORM,
2605 XmNrightOffset, 4,
2606 NULL);
2607
2608 /* fill in a form as invisible separator */
2609 sep_form = XtVaCreateWidget("separatorForm",
2610 xmFormWidgetClass, dialogform,
2611 XmNleftAttachment, XmATTACH_WIDGET,
2612 XmNleftWidget, buttons[butcount - 1],
2613 XmNrightAttachment, XmATTACH_WIDGET,
2614 XmNrightWidget, buttons[butcount],
2615 XmNbottomAttachment, XmATTACH_FORM,
2616 XmNbottomOffset, 4,
2617 NULL);
2618 XtManageChild(sep_form);
2619 }
2620 else
2621 {
2622 XtVaSetValues(buttons[butcount],
2623 XmNleftAttachment, XmATTACH_WIDGET,
2624 XmNleftWidget, buttons[butcount - 1],
2625 NULL);
2626 }
2627 }
2628 }
2629 else if (!vertical)
2630 {
2631 if (*next == NUL)
2632 {
2633 XtVaSetValues(buttons[0],
2634 XmNrightAttachment, XmATTACH_FORM,
2635 XmNrightOffset, 4,
2636 NULL);
2637
2638 /* fill in a form as invisible separator */
2639 sep_form = XtVaCreateWidget("separatorForm",
2640 xmFormWidgetClass, dialogform,
2641 XmNleftAttachment, XmATTACH_FORM,
2642 XmNleftOffset, 4,
2643 XmNrightAttachment, XmATTACH_WIDGET,
2644 XmNrightWidget, buttons[0],
2645 XmNbottomAttachment, XmATTACH_FORM,
2646 XmNbottomOffset, 4,
2647 NULL);
2648 XtManageChild(sep_form);
2649 }
2650 else
2651 XtVaSetValues(buttons[0],
2652 XmNleftAttachment, XmATTACH_FORM,
2653 XmNleftOffset, 4,
2654 NULL);
2655 }
2656
2657 XtAddCallback(buttons[butcount], XmNactivateCallback,
2658 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2659 p = next;
2660 }
2661 vim_free(buts);
2662
2663 separator = (Widget) 0;
2664 if (butcount > 0)
2665 {
2666 /* Create the separator for beauty. */
2667 n = 0;
2668 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2669 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2670 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2671 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2672 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2673 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2674 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2675 XtManageChild(separator);
2676 }
2677
2678 if (textfield != NULL)
2679 {
2680 dialogtextfield = XtVaCreateWidget("textField",
2681 xmTextFieldWidgetClass, dialogform,
2682 XmNleftAttachment, XmATTACH_FORM,
2683 XmNrightAttachment, XmATTACH_FORM,
2684 NULL);
2685 if (butcount > 0)
2686 XtVaSetValues(dialogtextfield,
2687 XmNbottomAttachment, XmATTACH_WIDGET,
2688 XmNbottomWidget, separator,
2689 NULL);
2690 else
2691 XtVaSetValues(dialogtextfield,
2692 XmNbottomAttachment, XmATTACH_FORM,
2693 NULL);
2694
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002695 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2697 XtManageChild(dialogtextfield);
2698 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2699 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2700 }
2701
2702 /* Form holding both message and pixmap labels */
2703 form = XtVaCreateWidget("separatorForm",
2704 xmFormWidgetClass, dialogform,
2705 XmNleftAttachment, XmATTACH_FORM,
2706 XmNrightAttachment, XmATTACH_FORM,
2707 XmNtopAttachment, XmATTACH_FORM,
2708 NULL);
2709 XtManageChild(form);
2710
2711#ifdef HAVE_XPM
2712 /* Add a pixmap, left of the message. */
2713 switch (type)
2714 {
2715 case VIM_GENERIC:
2716 icon_data = generic_xpm;
2717 break;
2718 case VIM_ERROR:
2719 icon_data = error_xpm;
2720 break;
2721 case VIM_WARNING:
2722 icon_data = alert_xpm;
2723 break;
2724 case VIM_INFO:
2725 icon_data = info_xpm;
2726 break;
2727 case VIM_QUESTION:
2728 icon_data = quest_xpm;
2729 break;
2730 default:
2731 icon_data = generic_xpm;
2732 }
2733
2734 n = 0;
2735 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2736 XtSetArg(args[n], XmNtopOffset, 8); n++;
2737 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2738 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2739 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2740 XtSetArg(args[n], XmNleftOffset, 8); n++;
2741
2742 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2743 icon_data, args, n);
2744 XtManageChild(dialogpixmap);
2745#endif
2746
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002747 /* Create the dialog message.
2748 * Since LessTif is apparently having problems with the creation of
2749 * properly localized string, we use LtoR here. The symptom is that the
2750 * string sill not show properly in multiple lines as it does in native
2751 * Motif.
2752 */
2753 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 if (label == NULL)
2755 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002756 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 xmLabelGadgetClass, form,
2758 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002759 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 XmNtopAttachment, XmATTACH_FORM,
2761 XmNtopOffset, 8,
2762#ifdef HAVE_XPM
2763 XmNleftAttachment, XmATTACH_WIDGET,
2764 XmNleftWidget, dialogpixmap,
2765#else
2766 XmNleftAttachment, XmATTACH_FORM,
2767#endif
2768 XmNleftOffset, 8,
2769 XmNrightAttachment, XmATTACH_FORM,
2770 XmNrightOffset, 8,
2771 XmNbottomAttachment, XmATTACH_FORM,
2772 XmNbottomOffset, 8,
2773 NULL);
2774 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002775 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776
2777 if (textfield != NULL)
2778 {
2779 XtVaSetValues(form,
2780 XmNbottomAttachment, XmATTACH_WIDGET,
2781 XmNbottomWidget, dialogtextfield,
2782 NULL);
2783 }
2784 else
2785 {
2786 if (butcount > 0)
2787 XtVaSetValues(form,
2788 XmNbottomAttachment, XmATTACH_WIDGET,
2789 XmNbottomWidget, separator,
2790 NULL);
2791 else
2792 XtVaSetValues(form,
2793 XmNbottomAttachment, XmATTACH_FORM,
2794 NULL);
2795 }
2796
2797 if (dfltbutton < 1)
2798 dfltbutton = 1;
2799 if (dfltbutton > butcount)
2800 dfltbutton = butcount;
2801 XtVaSetValues(dialogform,
2802 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2803 if (textfield != NULL)
2804 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2805 else
2806 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2807 NULL);
2808
2809 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002810 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811
2812 if (textfield != NULL && *textfield != NUL)
2813 {
2814 /* This only works after the textfield has been realised. */
2815 XmTextFieldSetSelection(dialogtextfield,
2816 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2817 XtLastTimestampProcessed(gui.dpy));
2818 XmTextFieldSetCursorPosition(dialogtextfield,
2819 (XmTextPosition)STRLEN(textfield));
2820 }
2821
2822 app = XtWidgetToApplicationContext(dialogform);
2823
2824 /* Loop until a button is pressed or the dialog is killed somehow. */
2825 dialogStatus = -1;
2826 for (;;)
2827 {
2828 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2829 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2830 break;
2831 }
2832
2833 vim_free(buttons);
2834
2835 if (textfield != NULL)
2836 {
2837 p = (char_u *)XmTextGetString(dialogtextfield);
2838 if (p == NULL || dialogStatus < 0)
2839 *textfield = NUL;
2840 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002841 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002842 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 }
2844
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002845 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 XtDestroyWidget(dialogform);
2847
2848 return dialogStatus;
2849}
2850#endif /* FEAT_GUI_DIALOG */
2851
2852#if defined(FEAT_FOOTER) || defined(PROTO)
2853
2854 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002855gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856{
2857 Dimension height; /* total Toolbar height */
2858 Dimension top; /* XmNmarginTop */
2859 Dimension bottom; /* XmNmarginBottom */
2860 Dimension shadow; /* XmNshadowThickness */
2861
2862 XtVaGetValues(footer,
2863 XmNheight, &height,
2864 XmNmarginTop, &top,
2865 XmNmarginBottom, &bottom,
2866 XmNshadowThickness, &shadow,
2867 NULL);
2868
2869 return (int) height + top + bottom + (shadow << 1);
2870}
2871
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002873gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874{
2875 if (showit)
2876 {
2877 gui.footer_height = gui_mch_compute_footer_height();
2878 XtManageChild(footer);
2879 }
2880 else
2881 {
2882 gui.footer_height = 0;
2883 XtUnmanageChild(footer);
2884 }
2885 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2886}
2887
2888 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002889gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890{
2891 XmString xms;
2892
2893 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002894 if (xms != NULL)
2895 {
2896 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2897 XmStringFree(xms);
2898 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899}
2900
2901#endif
2902
2903
2904#if defined(FEAT_TOOLBAR) || defined(PROTO)
2905 void
2906gui_mch_show_toolbar(int showit)
2907{
2908 Cardinal numChildren; /* how many children toolBar has */
2909
2910 if (toolBar == (Widget)0)
2911 return;
2912 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2913 if (showit && numChildren > 0)
2914 {
2915 /* Assume that we want to show the toolbar if p_toolbar contains
2916 * valid option settings, therefore p_toolbar must not be NULL.
2917 */
2918 WidgetList children;
2919
2920 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2921 {
2922 void (*action)(BalloonEval *);
2923 int text = 0;
2924
2925 if (strstr((const char *)p_toolbar, "tooltips"))
2926 action = &gui_mch_enable_beval_area;
2927 else
2928 action = &gui_mch_disable_beval_area;
2929 if (strstr((const char *)p_toolbar, "text"))
2930 text = 1;
2931 else if (strstr((const char *)p_toolbar, "icons"))
2932 text = -1;
2933 if (text != 0)
2934 {
2935 vimmenu_T *toolbar;
2936 vimmenu_T *cur;
2937
2938 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
2939 if (menu_is_toolbar(toolbar->dname))
2940 break;
2941 /* Assumption: toolbar is NULL if there is no toolbar,
2942 * otherwise it contains the toolbar menu structure.
2943 *
2944 * Assumption: "numChildren" == the number of items in the list
2945 * of items beginning with toolbar->children.
2946 */
2947 if (toolbar)
2948 {
2949 for (cur = toolbar->children; cur; cur = cur->next)
2950 {
2951 Arg args[1];
2952 int n = 0;
2953
2954 /* Enable/Disable tooltip (OK to enable while
Bram Moolenaarf193fff2006-04-27 00:02:13 +00002955 * currently enabled). */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 if (cur->tip != NULL)
2957 (*action)(cur->tip);
2958 if (!menu_is_separator(cur->name))
2959 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002960 if (text == 1 || cur->xpm == NULL)
2961 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002963 ++n;
2964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 if (cur->id != NULL)
2966 {
2967 XtUnmanageChild(cur->id);
2968 XtSetValues(cur->id, args, n);
2969 XtManageChild(cur->id);
2970 }
2971 }
2972 }
2973 }
2974 }
2975 }
2976 gui.toolbar_height = gui_mch_compute_toolbar_height();
2977 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002978#ifdef FEAT_GUI_TABLINE
2979 if (showing_tabline)
2980 {
2981 XtVaSetValues(tabLine,
2982 XmNtopAttachment, XmATTACH_WIDGET,
2983 XmNtopWidget, XtParent(toolBar),
2984 NULL);
2985 XtVaSetValues(textAreaForm,
2986 XmNtopAttachment, XmATTACH_WIDGET,
2987 XmNtopWidget, tabLine,
2988 NULL);
2989 }
2990 else
2991#endif
2992 XtVaSetValues(textAreaForm,
2993 XmNtopAttachment, XmATTACH_WIDGET,
2994 XmNtopWidget, XtParent(toolBar),
2995 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 if (XtIsManaged(menuBar))
2997 XtVaSetValues(XtParent(toolBar),
2998 XmNtopAttachment, XmATTACH_WIDGET,
2999 XmNtopWidget, menuBar,
3000 NULL);
3001 else
3002 XtVaSetValues(XtParent(toolBar),
3003 XmNtopAttachment, XmATTACH_FORM,
3004 NULL);
3005 }
3006 else
3007 {
3008 gui.toolbar_height = 0;
3009 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003010 {
3011#ifdef FEAT_GUI_TABLINE
3012 if (showing_tabline)
3013 {
3014 XtVaSetValues(tabLine,
3015 XmNtopAttachment, XmATTACH_WIDGET,
3016 XmNtopWidget, menuBar,
3017 NULL);
3018 XtVaSetValues(textAreaForm,
3019 XmNtopAttachment, XmATTACH_WIDGET,
3020 XmNtopWidget, tabLine,
3021 NULL);
3022 }
3023 else
3024#endif
3025 XtVaSetValues(textAreaForm,
3026 XmNtopAttachment, XmATTACH_WIDGET,
3027 XmNtopWidget, menuBar,
3028 NULL);
3029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003031 {
3032#ifdef FEAT_GUI_TABLINE
3033 if (showing_tabline)
3034 {
3035 XtVaSetValues(tabLine,
3036 XmNtopAttachment, XmATTACH_FORM,
3037 NULL);
3038 XtVaSetValues(textAreaForm,
3039 XmNtopAttachment, XmATTACH_WIDGET,
3040 XmNtopWidget, tabLine,
3041 NULL);
3042 }
3043 else
3044#endif
3045 XtVaSetValues(textAreaForm,
3046 XmNtopAttachment, XmATTACH_FORM,
3047 NULL);
3048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049
3050 XtUnmanageChild(XtParent(toolBar));
3051 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003052 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053}
3054
3055/*
3056 * A toolbar button has been pushed; now reset the input focus
3057 * such that the user can type page up/down etc. and have the
3058 * input go to the editor window, not the button
3059 */
3060 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003061reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062{
3063 if (textArea != NULL)
3064 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3065}
3066
3067 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003068gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003070 Dimension borders;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 Dimension height; /* total Toolbar height */
3072 Dimension whgt; /* height of each widget */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 WidgetList children; /* list of toolBar's children */
3074 Cardinal numChildren; /* how many children toolBar has */
3075 int i;
3076
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003077 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3080 { /* get height of XmFrame parent */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003081 Dimension fst;
3082 Dimension fmh;
3083 Dimension tst;
3084 Dimension tmh;
3085
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003087 XmNshadowThickness, &fst,
3088 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003090 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003092 XmNshadowThickness, &tst,
3093 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 XmNchildren, &children,
3095 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003096 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003097 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {
3099 whgt = 0;
3100 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3101 if (height < whgt)
3102 height = whgt;
3103 }
3104 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003105#ifdef LESSTIF_VERSION
3106 /* Hack: When starting up we get wrong dimensions. */
3107 if (height < 10)
3108 height = 24;
3109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003111 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112}
3113
Bram Moolenaar7c626922005-02-07 22:01:03 +00003114 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003115motif_get_toolbar_colors(
3116 Pixel *bgp,
3117 Pixel *fgp,
3118 Pixel *bsp,
3119 Pixel *tsp,
3120 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003121{
3122 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003123 XmNbackground, bgp,
3124 XmNforeground, fgp,
3125 XmNbottomShadowColor, bsp,
3126 XmNtopShadowColor, tsp,
3127 XmNhighlightColor, hsp,
3128 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129}
3130
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131# ifdef FEAT_FOOTER
3132/*
3133 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003134 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 * get implemented and the user will have a choice.
3136 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003138toolbarbutton_enter_cb(
3139 Widget w UNUSED,
3140 XtPointer client_data,
3141 XEvent *event UNUSED,
3142 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143{
3144 vimmenu_T *menu = (vimmenu_T *) client_data;
3145
3146 if (menu->strings[MENU_INDEX_TIP] != NULL)
3147 {
3148 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3149 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3150 }
3151}
3152
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003154toolbarbutton_leave_cb(
3155 Widget w UNUSED,
3156 XtPointer client_data UNUSED,
3157 XEvent *event UNUSED,
3158 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159{
3160 gui_mch_set_footer((char_u *) "");
3161}
3162# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163#endif
3164
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003165#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3166/*
3167 * Show or hide the tabline.
3168 */
3169 void
3170gui_mch_show_tabline(int showit)
3171{
3172 if (tabLine == (Widget)0)
3173 return;
3174
3175 if (!showit != !showing_tabline)
3176 {
3177 if (showit)
3178 {
3179 XtManageChild(tabLine);
3180 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003181 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3182 XtUnmanageChild(XtNameToWidget(tabLine,
3183 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003184#ifdef FEAT_MENU
3185# ifdef FEAT_TOOLBAR
3186 if (XtIsManaged(XtParent(toolBar)))
3187 XtVaSetValues(tabLine,
3188 XmNtopAttachment, XmATTACH_WIDGET,
3189 XmNtopWidget, XtParent(toolBar), NULL);
3190 else
3191# endif
3192 if (XtIsManaged(menuBar))
3193 XtVaSetValues(tabLine,
3194 XmNtopAttachment, XmATTACH_WIDGET,
3195 XmNtopWidget, menuBar, NULL);
3196 else
3197#endif
3198 XtVaSetValues(tabLine,
3199 XmNtopAttachment, XmATTACH_FORM, NULL);
3200 XtVaSetValues(textAreaForm,
3201 XmNtopAttachment, XmATTACH_WIDGET,
3202 XmNtopWidget, tabLine,
3203 NULL);
3204 }
3205 else
3206 {
3207 XtUnmanageChild(tabLine);
3208#ifdef FEAT_MENU
3209# ifdef FEAT_TOOLBAR
3210 if (XtIsManaged(XtParent(toolBar)))
3211 XtVaSetValues(textAreaForm,
3212 XmNtopAttachment, XmATTACH_WIDGET,
3213 XmNtopWidget, XtParent(toolBar), NULL);
3214 else
3215# endif
3216 if (XtIsManaged(menuBar))
3217 XtVaSetValues(textAreaForm,
3218 XmNtopAttachment, XmATTACH_WIDGET,
3219 XmNtopWidget, menuBar, NULL);
3220 else
3221#endif
3222 XtVaSetValues(textAreaForm,
3223 XmNtopAttachment, XmATTACH_FORM, NULL);
3224 }
3225 showing_tabline = showit;
3226 }
3227}
3228
3229/*
3230 * Return TRUE when tabline is displayed.
3231 */
3232 int
3233gui_mch_showing_tabline(void)
3234{
3235 return tabLine != (Widget)0 && showing_tabline;
3236}
3237
3238/*
3239 * Update the labels of the tabline.
3240 */
3241 void
3242gui_mch_update_tabline(void)
3243{
3244 tabpage_T *tp;
3245 int nr = 1, n;
3246 Arg args[10];
3247 int curtabidx = 0, currentpage;
3248 Widget tab;
3249 XmNotebookPageInfo page_info;
3250 XmNotebookPageStatus page_status;
3251 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003252 XmString label_str;
3253 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003254 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003255
3256 if (tabLine == (Widget)0)
3257 return;
3258
3259 /* Add a label for each tab page. They all contain the same text area. */
3260 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3261 {
3262 if (tp == curtab)
3263 curtabidx = nr;
3264
3265 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3266 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003267 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003268 {
3269 /* Add the tab */
3270 n = 0;
3271 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3272 XtSetArg(args[n], XmNtraversalOn, False); n++;
3273 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3274 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3275 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3276 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3277 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003278 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3279 NULL);
3280 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003281 }
3282 else
3283 tab = page_info.major_tab_widget;
3284
3285 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003286
3287 /*
3288 * Change the label text only if it is different
3289 */
3290 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3291 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3292 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003293 get_tabline_label(tp, FALSE);
3294 if (STRCMP(label_cstr, NameBuff) != 0)
3295 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003296 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3297 NameBuff, STRLEN(NameBuff) + 1, NULL);
3298 /*
3299 * Force a resize of the tab label button
3300 */
3301 XtUnmanageChild(tab);
3302 XtManageChild(tab);
3303 }
3304 XtFree(label_cstr);
3305 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003306 }
3307
3308 tab_count = nr - 1;
3309
3310 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3311
3312 /* Remove any old labels. */
3313 while (nr <= last_page)
3314 {
3315 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3316 && page_info.page_number == nr
3317 && page_info.major_tab_widget != (Widget)0)
3318 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003319 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3320 if (beval != NULL)
3321 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003322 XtUnmanageChild(page_info.major_tab_widget);
3323 XtDestroyWidget(page_info.major_tab_widget);
3324 }
3325 nr++;
3326 }
3327
3328 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3329
3330 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3331 if (currentpage != curtabidx)
3332 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3333}
3334
3335/*
3336 * Set the current tab to "nr". First tab is 1.
3337 */
3338 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003339gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003340{
3341 int currentpage;
3342
3343 if (tabLine == (Widget)0)
3344 return;
3345
3346 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3347 if (currentpage != nr)
3348 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3349}
3350#endif
3351
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352/*
3353 * Set the colors of Widget "id" to the menu colors.
3354 */
3355 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003356gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357{
3358 if (gui.menu_bg_pixel != INVALCOLOR)
3359#if (XmVersion >= 1002)
3360 XmChangeColor(id, gui.menu_bg_pixel);
3361#else
3362 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3363#endif
3364 if (gui.menu_fg_pixel != INVALCOLOR)
3365 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3366}
3367
3368/*
3369 * Set the colors of Widget "id" to the scrollbar colors.
3370 */
3371 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003372gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373{
3374 if (gui.scroll_bg_pixel != INVALCOLOR)
3375#if (XmVersion >= 1002)
3376 XmChangeColor(id, gui.scroll_bg_pixel);
3377#else
3378 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3379#endif
3380 if (gui.scroll_fg_pixel != INVALCOLOR)
3381 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3382}
3383
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384/*
3385 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3386 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003387 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003388gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003390#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391#ifdef FONTSET_ALWAYS
3392 if (gui.menu_fontset != NOFONTSET)
3393 {
3394 XmFontList fl;
3395
3396 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3397 if (fl != NULL)
3398 {
3399 if (XtIsManaged(id))
3400 {
3401 XtUnmanageChild(id);
3402 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01003403 /* We should force the widget to recalculate its
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 * geometry now. */
3405 XtManageChild(id);
3406 }
3407 else
3408 XtVaSetValues(id, XmNfontList, fl, NULL);
3409 XmFontListFree(fl);
3410 }
3411 }
3412#else
3413 if (gui.menu_font != NOFONT)
3414 {
3415 XmFontList fl;
3416
3417 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3418 if (fl != NULL)
3419 {
3420 if (XtIsManaged(id))
3421 {
3422 XtUnmanageChild(id);
3423 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01003424 /* We should force the widget to recalculate its
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425 * geometry now. */
3426 XtManageChild(id);
3427 }
3428 else
3429 XtVaSetValues(id, XmNfontList, fl, NULL);
3430 XmFontListFree(fl);
3431 }
3432 }
3433#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003434#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435}
3436
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437
3438/*
3439 * We don't create it twice for the sake of speed.
3440 */
3441
3442typedef struct _SharedFindReplace
3443{
3444 Widget dialog; /* the main dialog widget */
3445 Widget wword; /* 'Exact match' check button */
3446 Widget mcase; /* 'match case' check button */
3447 Widget up; /* search direction 'Up' radio button */
3448 Widget down; /* search direction 'Down' radio button */
3449 Widget what; /* 'Find what' entry text widget */
3450 Widget with; /* 'Replace with' entry text widget */
3451 Widget find; /* 'Find Next' action button */
3452 Widget replace; /* 'Replace With' action button */
3453 Widget all; /* 'Replace All' action button */
3454 Widget undo; /* 'Undo' action button */
3455
3456 Widget cancel;
3457} SharedFindReplace;
3458
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003459static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3460static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003463find_replace_destroy_callback(
3464 Widget w UNUSED,
3465 XtPointer client_data,
3466 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467{
3468 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3469
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003470 if (cd != NULL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003471 /* suppress_dialog_mnemonics(cd->dialog); */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 cd->dialog = (Widget)0;
3473}
3474
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003476find_replace_dismiss_callback(
3477 Widget w UNUSED,
3478 XtPointer client_data,
3479 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480{
3481 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3482
3483 if (cd != NULL)
3484 XtUnmanageChild(cd->dialog);
3485}
3486
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003488entry_activate_callback(
3489 Widget w UNUSED,
3490 XtPointer client_data,
3491 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492{
3493 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3494}
3495
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003497find_replace_callback(
3498 Widget w UNUSED,
3499 XtPointer client_data,
3500 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003501{
3502 long_u flags = (long_u)client_data;
3503 char *find_text, *repl_text;
3504 Boolean direction_down = TRUE;
3505 Boolean wword;
3506 Boolean mcase;
3507 SharedFindReplace *sfr;
3508
3509 if (flags == FRD_UNDO)
3510 {
3511 char_u *save_cpo = p_cpo;
3512
3513 /* No need to be Vi compatible here. */
3514 p_cpo = (char_u *)"";
3515 u_undo(1);
3516 p_cpo = save_cpo;
3517 gui_update_screen();
3518 return;
3519 }
3520
3521 /* Get the search/replace strings from the dialog */
3522 if (flags == FRD_FINDNEXT)
3523 {
3524 repl_text = NULL;
3525 sfr = &find_widgets;
3526 }
3527 else
3528 {
3529 repl_text = XmTextFieldGetString(repl_widgets.with);
3530 sfr = &repl_widgets;
3531 }
3532 find_text = XmTextFieldGetString(sfr->what);
3533 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3534 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3535 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3536 if (wword)
3537 flags |= FRD_WHOLE_WORD;
3538 if (mcase)
3539 flags |= FRD_MATCH_CASE;
3540
3541 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3542 direction_down);
3543
3544 if (find_text != NULL)
3545 XtFree(find_text);
3546 if (repl_text != NULL)
3547 XtFree(repl_text);
3548}
3549
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003551find_replace_keypress(
3552 Widget w UNUSED,
3553 SharedFindReplace *frdp,
3554 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555{
3556 KeySym keysym;
3557
3558 if (frdp == NULL)
3559 return;
3560
3561 keysym = XLookupKeysym(event, 0);
3562
3563 /* the scape key pops the whole dialog down */
3564 if (keysym == XK_Escape)
3565 XtUnmanageChild(frdp->dialog);
3566}
3567
3568 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003569set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003570{
3571 XmString str;
3572 char_u *p, *next;
3573 KeySym mnemonic = NUL;
3574
3575 if (!w)
3576 return;
3577
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003578 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003579 if (p == NULL)
3580 return;
3581 for (next = p; *next; ++next)
3582 {
3583 if (*next == DLG_HOTKEY_CHAR)
3584 {
3585 int len = STRLEN(next);
3586
3587 if (len > 0)
3588 {
3589 mch_memmove(next, next + 1, len);
3590 mnemonic = next[0];
3591 }
3592 }
3593 }
3594
3595 str = XmStringCreateSimple((char *)p);
3596 vim_free(p);
3597 if (str)
3598 {
3599 XtVaSetValues(w,
3600 XmNlabelString, str,
3601 XmNmnemonic, mnemonic,
3602 NULL);
3603 XmStringFree(str);
3604 }
3605 gui_motif_menu_fontlist(w);
3606}
3607
3608 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003609find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610{
3611 SharedFindReplace *frdp;
3612 Widget separator;
3613 Widget input_form;
3614 Widget button_form;
3615 Widget toggle_form;
3616 Widget frame;
3617 XmString str;
3618 int n;
3619 Arg args[6];
3620 int wword = FALSE;
3621 int mcase = !p_ic;
3622 Dimension width;
3623 Dimension widest;
3624 char_u *entry_text;
3625
3626 frdp = do_replace ? &repl_widgets : &find_widgets;
3627
3628 /* Get the search string to use. */
3629 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3630
3631 /* If the dialog already exists, just raise it. */
3632 if (frdp->dialog)
3633 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003634 gui_motif_synch_fonts();
3635
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 /* If the window is already up, just pop it to the top */
3637 if (XtIsManaged(frdp->dialog))
3638 XMapRaised(XtDisplay(frdp->dialog),
3639 XtWindow(XtParent(frdp->dialog)));
3640 else
3641 XtManageChild(frdp->dialog);
3642 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3643 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3644
3645 if (entry_text != NULL)
3646 XmTextFieldSetString(frdp->what, (char *)entry_text);
3647 vim_free(entry_text);
3648
3649 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3650 return;
3651 }
3652
3653 /* Create a fresh new dialog window */
3654 if (do_replace)
3655 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3656 else
3657 str = XmStringCreateSimple(_("VIM - Search..."));
3658
3659 n = 0;
3660 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3661 XtSetArg(args[n], XmNnoResize, True); n++;
3662 XtSetArg(args[n], XmNdialogTitle, str); n++;
3663
3664 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3665 XmStringFree(str);
3666 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3667 find_replace_destroy_callback, frdp);
3668
3669 button_form = XtVaCreateWidget("buttonForm",
3670 xmFormWidgetClass, frdp->dialog,
3671 XmNrightAttachment, XmATTACH_FORM,
3672 XmNrightOffset, 4,
3673 XmNtopAttachment, XmATTACH_FORM,
3674 XmNtopOffset, 4,
3675 XmNbottomAttachment, XmATTACH_FORM,
3676 XmNbottomOffset, 4,
3677 NULL);
3678
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 frdp->find = XtVaCreateManagedWidget("findButton",
3680 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 XmNsensitive, True,
3682 XmNtopAttachment, XmATTACH_FORM,
3683 XmNleftAttachment, XmATTACH_FORM,
3684 XmNrightAttachment, XmATTACH_FORM,
3685 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003686 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687
3688 XtAddCallback(frdp->find, XmNactivateCallback,
3689 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003690 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691
3692 if (do_replace)
3693 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3695 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 XmNtopAttachment, XmATTACH_WIDGET,
3697 XmNtopWidget, frdp->find,
3698 XmNleftAttachment, XmATTACH_FORM,
3699 XmNrightAttachment, XmATTACH_FORM,
3700 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003701 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702 XtAddCallback(frdp->replace, XmNactivateCallback,
3703 find_replace_callback, (XtPointer)FRD_REPLACE);
3704
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3706 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 XmNtopAttachment, XmATTACH_WIDGET,
3708 XmNtopWidget, frdp->replace,
3709 XmNleftAttachment, XmATTACH_FORM,
3710 XmNrightAttachment, XmATTACH_FORM,
3711 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003712 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 XtAddCallback(frdp->all, XmNactivateCallback,
3714 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3715
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 frdp->undo = XtVaCreateManagedWidget("undoButton",
3717 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 XmNtopAttachment, XmATTACH_WIDGET,
3719 XmNtopWidget, frdp->all,
3720 XmNleftAttachment, XmATTACH_FORM,
3721 XmNrightAttachment, XmATTACH_FORM,
3722 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003723 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724 XtAddCallback(frdp->undo, XmNactivateCallback,
3725 find_replace_callback, (XtPointer)FRD_UNDO);
3726 }
3727
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3729 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730 XmNleftAttachment, XmATTACH_FORM,
3731 XmNrightAttachment, XmATTACH_FORM,
3732 XmNbottomAttachment, XmATTACH_FORM,
3733 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003734 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 XtAddCallback(frdp->cancel, XmNactivateCallback,
3736 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003737 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738
3739 XtManageChild(button_form);
3740
3741 n = 0;
3742 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3743 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3744 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3745 XtSetArg(args[n], XmNrightOffset, 4); n++;
3746 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3747 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3748 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3749 XtManageChild(separator);
3750
3751 input_form = XtVaCreateWidget("inputForm",
3752 xmFormWidgetClass, frdp->dialog,
3753 XmNleftAttachment, XmATTACH_FORM,
3754 XmNleftOffset, 4,
3755 XmNrightAttachment, XmATTACH_WIDGET,
3756 XmNrightWidget, separator,
3757 XmNrightOffset, 4,
3758 XmNtopAttachment, XmATTACH_FORM,
3759 XmNtopOffset, 4,
3760 NULL);
3761
3762 {
3763 Widget label_what;
3764 Widget label_with = (Widget)0;
3765
3766 str = XmStringCreateSimple(_("Find what:"));
3767 label_what = XtVaCreateManagedWidget("whatLabel",
3768 xmLabelGadgetClass, input_form,
3769 XmNlabelString, str,
3770 XmNleftAttachment, XmATTACH_FORM,
3771 XmNtopAttachment, XmATTACH_FORM,
3772 XmNtopOffset, 4,
3773 NULL);
3774 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003775 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776
3777 frdp->what = XtVaCreateManagedWidget("whatText",
3778 xmTextFieldWidgetClass, input_form,
3779 XmNtopAttachment, XmATTACH_FORM,
3780 XmNrightAttachment, XmATTACH_FORM,
3781 XmNleftAttachment, XmATTACH_FORM,
3782 NULL);
3783
3784 if (do_replace)
3785 {
3786 frdp->with = XtVaCreateManagedWidget("withText",
3787 xmTextFieldWidgetClass, input_form,
3788 XmNtopAttachment, XmATTACH_WIDGET,
3789 XmNtopWidget, frdp->what,
3790 XmNtopOffset, 4,
3791 XmNleftAttachment, XmATTACH_FORM,
3792 XmNrightAttachment, XmATTACH_FORM,
3793 XmNbottomAttachment, XmATTACH_FORM,
3794 NULL);
3795
3796 XtAddCallback(frdp->with, XmNactivateCallback,
3797 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3798
3799 str = XmStringCreateSimple(_("Replace with:"));
3800 label_with = XtVaCreateManagedWidget("withLabel",
3801 xmLabelGadgetClass, input_form,
3802 XmNlabelString, str,
3803 XmNleftAttachment, XmATTACH_FORM,
3804 XmNtopAttachment, XmATTACH_WIDGET,
3805 XmNtopWidget, frdp->what,
3806 XmNtopOffset, 4,
3807 XmNbottomAttachment, XmATTACH_FORM,
3808 NULL);
3809 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003810 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811
3812 /*
3813 * Make the entry activation only change the input focus onto the
3814 * with item.
3815 */
3816 XtAddCallback(frdp->what, XmNactivateCallback,
3817 entry_activate_callback, frdp->with);
3818 XtAddEventHandler(frdp->with, KeyPressMask, False,
3819 (XtEventHandler)find_replace_keypress,
3820 (XtPointer) frdp);
3821
3822 }
3823 else
3824 {
3825 /*
3826 * Make the entry activation do the search.
3827 */
3828 XtAddCallback(frdp->what, XmNactivateCallback,
3829 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3830 }
3831 XtAddEventHandler(frdp->what, KeyPressMask, False,
3832 (XtEventHandler)find_replace_keypress,
3833 (XtPointer)frdp);
3834
3835 /* Get the maximum width between the label widgets and line them up.
3836 */
3837 n = 0;
3838 XtSetArg(args[n], XmNwidth, &width); n++;
3839 XtGetValues(label_what, args, n);
3840 widest = width;
3841 if (do_replace)
3842 {
3843 XtGetValues(label_with, args, n);
3844 if (width > widest)
3845 widest = width;
3846 }
3847
3848 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3849 if (do_replace)
3850 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3851
3852 }
3853
3854 XtManageChild(input_form);
3855
3856 {
3857 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003858 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859
3860 frame = XtVaCreateWidget("directionFrame",
3861 xmFrameWidgetClass, frdp->dialog,
3862 XmNtopAttachment, XmATTACH_WIDGET,
3863 XmNtopWidget, input_form,
3864 XmNtopOffset, 4,
3865 XmNbottomAttachment, XmATTACH_FORM,
3866 XmNbottomOffset, 4,
3867 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3868 XmNrightWidget, input_form,
3869 NULL);
3870
3871 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003872 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 xmLabelGadgetClass, frame,
3874 XmNlabelString, str,
3875 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3876 XmNchildType, XmFRAME_TITLE_CHILD,
3877 NULL);
3878 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003879 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880
3881 radio_box = XmCreateRadioBox(frame, "radioBox",
3882 (ArgList)NULL, 0);
3883
3884 str = XmStringCreateSimple( _("Up"));
3885 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3886 xmToggleButtonGadgetClass, radio_box,
3887 XmNlabelString, str,
3888 XmNset, False,
3889 NULL);
3890 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003891 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892
3893 str = XmStringCreateSimple(_("Down"));
3894 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3895 xmToggleButtonGadgetClass, radio_box,
3896 XmNlabelString, str,
3897 XmNset, True,
3898 NULL);
3899 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003900 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901
3902 XtManageChild(radio_box);
3903 XtManageChild(frame);
3904 }
3905
3906 toggle_form = XtVaCreateWidget("toggleForm",
3907 xmFormWidgetClass, frdp->dialog,
3908 XmNleftAttachment, XmATTACH_FORM,
3909 XmNleftOffset, 4,
3910 XmNrightAttachment, XmATTACH_WIDGET,
3911 XmNrightWidget, frame,
3912 XmNrightOffset, 4,
3913 XmNtopAttachment, XmATTACH_WIDGET,
3914 XmNtopWidget, input_form,
3915 XmNtopOffset, 4,
3916 XmNbottomAttachment, XmATTACH_FORM,
3917 XmNbottomOffset, 4,
3918 NULL);
3919
3920 str = XmStringCreateSimple(_("Match whole word only"));
3921 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3922 xmToggleButtonGadgetClass, toggle_form,
3923 XmNlabelString, str,
3924 XmNtopAttachment, XmATTACH_FORM,
3925 XmNtopOffset, 4,
3926 XmNleftAttachment, XmATTACH_FORM,
3927 XmNleftOffset, 4,
3928 XmNset, wword,
3929 NULL);
3930 XmStringFree(str);
3931
3932 str = XmStringCreateSimple(_("Match case"));
3933 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3934 xmToggleButtonGadgetClass, toggle_form,
3935 XmNlabelString, str,
3936 XmNleftAttachment, XmATTACH_FORM,
3937 XmNleftOffset, 4,
3938 XmNtopAttachment, XmATTACH_WIDGET,
3939 XmNtopWidget, frdp->wword,
3940 XmNtopOffset, 4,
3941 XmNset, mcase,
3942 NULL);
3943 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003944 gui_motif_menu_fontlist(frdp->wword);
3945 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946
3947 XtManageChild(toggle_form);
3948
3949 if (entry_text != NULL)
3950 XmTextFieldSetString(frdp->what, (char *)entry_text);
3951 vim_free(entry_text);
3952
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003953 gui_motif_synch_fonts();
3954
3955 manage_centered(frdp->dialog);
3956 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3958}
3959
3960 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003961gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962{
3963 if (!gui.in_use)
3964 return;
3965
3966 find_replace_dialog_create(eap->arg, FALSE);
3967}
3968
3969
3970 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003971gui_mch_replace_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, TRUE);
3977}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003978
3979/*
3980 * Synchronize all gui elements, which are dependant upon the
3981 * main text font used. Those are in esp. the find/replace dialogs.
3982 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003983 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003984 */
3985 void
3986gui_motif_synch_fonts(void)
3987{
3988 SharedFindReplace *frdp;
3989 int do_replace;
3990 XFontStruct *font;
3991 XmFontList font_list;
3992
3993 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3994 * we just give up here on font synchronization. */
3995 font = (XFontStruct *)gui.norm_font;
3996 if (font == NULL)
3997 return;
3998
3999 font_list = gui_motif_create_fontlist(font);
4000
4001 /* OK this loop is a bit tricky... */
4002 for (do_replace = 0; do_replace <= 1; ++do_replace)
4003 {
4004 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4005 if (frdp->dialog)
4006 {
4007 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4008 if (do_replace)
4009 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4010 }
4011 }
4012
4013 XmFontListFree(font_list);
4014}