blob: b6c140be3890accfa001a6f887357d16210361c5 [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>
37
Bram Moolenaar071d4272004-06-13 20:20:40 +000038#ifdef HAVE_X11_XPM_H
39# include <X11/xpm.h>
40#else
41# ifdef HAVE_XM_XPMP_H
42# include <Xm/XpmP.h>
43# endif
44#endif
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000045#ifdef HAVE_XM_NOTEBOOK_H
46# include <Xm/Notebook.h>
47#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaarb7fcef52005-01-02 11:31:05 +000049#include "gui_xmebw.h" /* for our Enhanced Button Widget */
50
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
52# include "../pixmaps/alert.xpm"
53# include "../pixmaps/error.xpm"
54# include "../pixmaps/generic.xpm"
55# include "../pixmaps/info.xpm"
56# include "../pixmaps/quest.xpm"
57#endif
58
59#define MOTIF_POPUP
60
61extern Widget vimShell;
62
63static Widget vimForm;
64static Widget textAreaForm;
65Widget textArea;
66#ifdef FEAT_TOOLBAR
67static Widget toolBarFrame;
68static Widget toolBar;
69#endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +000070#ifdef FEAT_GUI_TABLINE
71static Widget tabLine;
72static Widget tabLine_menu = 0;
73static int showing_tabline = 0;
74#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000075#ifdef FEAT_FOOTER
76static Widget footer;
77#endif
78#ifdef FEAT_MENU
79# if (XmVersion >= 1002)
80/* remember the last set value for the tearoff item */
81static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
82# endif
83static Widget menuBar;
84#endif
85
Bram Moolenaar071d4272004-06-13 20:20:40 +000086#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000087# ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +010088static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
89static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000090# endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +010091static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
Bram Moolenaard25c16e2016-01-29 22:13:30 +010094static void gui_motif_menu_colors(Widget id);
95static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97#if (XmVersion >= 1002)
98# define STRING_TAG XmFONTLIST_DEFAULT_TAG
99#else
100# define STRING_TAG XmSTRING_DEFAULT_CHARSET
101#endif
102
103/*
104 * Call-back routines.
105 */
106
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107 static void
Bram Moolenaarc1ab6762016-01-30 19:45:49 +0100108scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109{
110 scrollbar_T *sb;
111 long value;
112 int dragging;
113
114 sb = gui_find_scrollbar((long)client_data);
115
116 value = ((XmScrollBarCallbackStruct *)call_data)->value;
117 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
118 (int)XmCR_DRAG);
119 gui_drag_scrollbar(sb, value, dragging);
120}
121
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000122#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000123 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100124tabline_cb(
125 Widget w UNUSED,
126 XtPointer client_data UNUSED,
127 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000128{
129 XmNotebookCallbackStruct *nptr;
130
131 nptr = (XmNotebookCallbackStruct *)call_data;
132 if (nptr->reason != (int)XmCR_NONE)
133 send_tabline_event(nptr->page_number);
134}
135
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000136 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100137tabline_button_cb(
138 Widget w,
139 XtPointer client_data UNUSED,
140 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000141{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000142 int cmd, tab_idx;
143
144 XtVaGetValues(w, XmNuserData, &cmd, NULL);
145 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
146
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000147 send_tabline_menu_event(tab_idx, cmd);
148}
149
150/*
151 * Tabline single mouse click timeout handler
152 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000153 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100154motif_tabline_timer_cb (
155 XtPointer timed_out,
156 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000157{
158 *((int *)timed_out) = TRUE;
159}
160
161/*
162 * check if the tabline tab scroller is clicked
163 */
164 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100165tabline_scroller_clicked(
166 char *scroller_name,
167 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000168{
169 Widget tab_scroll_w;
170 Position pos_x, pos_y;
171 Dimension width, height;
172
173 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
174 if (tab_scroll_w != (Widget)0) {
175 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
176 &width, XmNheight, &height, NULL);
177 if (pos_x >= 0) {
178 /* Tab scroller (next) is visible */
179 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
180 (event->y >= pos_y) && (event->y <= pos_y + height)) {
181 /* Clicked on the scroller */
182 return TRUE;
183 }
184 }
185 }
186 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000187}
188
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000189 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100190tabline_menu_cb(
191 Widget w,
192 XtPointer closure UNUSED,
193 XEvent *e,
194 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000195{
196 Widget tab_w;
197 XButtonPressedEvent *event;
198 int tab_idx = 0;
199 WidgetList children;
200 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000201 static XtIntervalId timer = (XtIntervalId)0;
202 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000203
204 event = (XButtonPressedEvent *)e;
205
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000206 if (event->button == Button1)
207 {
208 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
209 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
210 return;
211
212 if (!timed_out)
213 {
214 XtRemoveTimeOut(timer);
215 timed_out = TRUE;
216
217 /*
218 * Double click on the tabline gutter, add a new tab
219 */
220 send_tabline_menu_event(0, TABLINE_MENU_NEW);
221 }
222 else
223 {
224 /*
225 * Single click on the tabline gutter, start a timer to check
226 * for double clicks
227 */
228 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
229 motif_tabline_timer_cb, &timed_out);
230 timed_out = FALSE;
231 }
232 return;
233 }
234
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000235 if (event->button != Button3)
236 return;
237
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000238 /* When ignoring events don't show the menu. */
239 if (hold_gui_events
240# ifdef FEAT_CMDWIN
241 || cmdwin_type != 0
242# endif
243 )
244 return;
245
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000246 if (event->subwindow != None)
247 {
248 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000249 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000250 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
251 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
252 }
253
254 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
255 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
256 &numChildren, NULL);
257 XtManageChildren(children, numChildren);
258 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
259 XtManageChild(tabLine_menu);
260}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000261
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000262 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100263tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000264{
265 int nr;
266 tabpage_T *tp;
267
268 if (beval->target == (Widget)0)
269 return;
270
271 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
272 tp = find_tabpage(nr);
273 if (tp == NULL)
274 return;
275
276 get_tabline_label(tp, TRUE);
277 gui_mch_post_balloon(beval, NameBuff);
278}
279
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000280#endif
281
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282/*
283 * End of call-back routines
284 */
285
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000286/*
287 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000288 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289 */
290
291#include <Xm/XmP.h>
292#include <Xm/LabelP.h>
293
294static XtExposeProc old_label_expose = NULL;
295
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000296 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100297label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000298{
299 GC insensitiveGC;
300 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000301 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000302
303 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
304
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000305 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000306 (*old_label_expose)(_w, _event, _region);
307 else
308 {
309 XGCValues values;
310 XtGCMask mask;
311 XtGCMask dynamic;
312 XFontStruct *fs;
313
314 _XmFontListGetDefaultFont(lw->label.font, &fs);
315
316 /* FIXME: we should be doing the whole drawing ourself here. */
317 insensitiveGC = lw->label.insensitive_GC;
318
319 mask = GCForeground | GCBackground | GCGraphicsExposures;
320 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
321 values.graphics_exposures = False;
322
323 if (fs != 0)
324 {
325 mask |= GCFont;
326 values.font = fs->fid;
327 }
328
329 if (lw->primitive.top_shadow_pixmap != None
330 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
331 {
332 mask |= GCFillStyle | GCTile;
333 values.fill_style = FillTiled;
334 values.tile = lw->primitive.top_shadow_pixmap;
335 }
336
337 lw->label.TextRect.x += 1;
338 lw->label.TextRect.y += 1;
339 if (lw->label._acc_text != 0)
340 {
341 lw->label.acc_TextRect.x += 1;
342 lw->label.acc_TextRect.y += 1;
343 }
344
345 values.foreground = lw->primitive.top_shadow_color;
346 values.background = lw->core.background_pixel;
347
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000348 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
349 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000350 (*old_label_expose)(_w, _event, _region);
351 XtReleaseGC(_w, lw->label.insensitive_GC);
352
353 lw->label.TextRect.x -= 1;
354 lw->label.TextRect.y -= 1;
355 if (lw->label._acc_text != 0)
356 {
357 lw->label.acc_TextRect.x -= 1;
358 lw->label.acc_TextRect.y -= 1;
359 }
360
361 values.foreground = lw->primitive.bottom_shadow_color;
362 values.background = lw->core.background_pixel;
363
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000364 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
365 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000366 (*old_label_expose)(_w, _event, _region);
367 XtReleaseGC(_w, lw->label.insensitive_GC);
368
369 lw->label.insensitive_GC = insensitiveGC;
370 }
371}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000372
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373/*
374 * Create all the motif widgets necessary.
375 */
376 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100377gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000379#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000380 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000381 Arg args[10];
382 int n;
383 XmString xms;
384#endif
385
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000386 /*
387 * Install the 3D shade effect drawing routines.
388 */
389 if (old_label_expose == NULL)
390 {
391 old_label_expose = xmLabelWidgetClass->core_class.expose;
392 xmLabelWidgetClass->core_class.expose = label_expose;
393 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000394
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395 /*
396 * Start out by adding the configured border width into the border offset
397 */
398 gui.border_offset = gui.border_width;
399
400 /*
401 * Install the tearOffModel resource converter.
402 */
403#if (XmVersion >= 1002)
404 XmRepTypeInstallTearOffModelConverter();
405#endif
406
407 /* Make sure the "Quit" menu entry of the window manager is ignored */
408 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
409
410 vimForm = XtVaCreateManagedWidget("vimForm",
411 xmFormWidgetClass, vimShell,
412 XmNborderWidth, 0,
413 XmNhighlightThickness, 0,
414 XmNshadowThickness, 0,
415 XmNmarginWidth, 0,
416 XmNmarginHeight, 0,
417 XmNresizePolicy, XmRESIZE_ANY,
418 NULL);
419 gui_motif_menu_colors(vimForm);
420
421#ifdef FEAT_MENU
422 {
423 Arg al[7]; /* Make sure there is enough room for arguments! */
424 int ac = 0;
425
426# if (XmVersion >= 1002)
427 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
428# endif
429 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
430 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
431 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
432# ifndef FEAT_TOOLBAR
433 /* Always stick to right hand side. */
434 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
435# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000436 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
438 XtManageChild(menuBar);
439
440 /* Remember the default colors, needed for ":hi clear". */
441 XtVaGetValues(menuBar,
442 XmNbackground, &gui.menu_def_bg_pixel,
443 XmNforeground, &gui.menu_def_fg_pixel,
444 NULL);
445 gui_motif_menu_colors(menuBar);
446 }
447#endif
448
449#ifdef FEAT_TOOLBAR
450 /*
451 * Create an empty ToolBar. We should get buttons defined from menu.vim.
452 */
453 toolBarFrame = XtVaCreateWidget("toolBarFrame",
454 xmFrameWidgetClass, vimForm,
455 XmNshadowThickness, 0,
456 XmNmarginHeight, 0,
457 XmNmarginWidth, 0,
458 XmNleftAttachment, XmATTACH_FORM,
459 XmNrightAttachment, XmATTACH_FORM,
460 NULL);
461 gui_motif_menu_colors(toolBarFrame);
462
463 toolBar = XtVaCreateManagedWidget("toolBar",
464 xmRowColumnWidgetClass, toolBarFrame,
465 XmNchildType, XmFRAME_WORKAREA_CHILD,
466 XmNrowColumnType, XmWORK_AREA,
467 XmNorientation, XmHORIZONTAL,
468 XmNtraversalOn, False,
469 XmNisHomogeneous, False,
470 XmNpacking, XmPACK_TIGHT,
471 XmNspacing, 0,
472 XmNshadowThickness, 0,
473 XmNhighlightThickness, 0,
474 XmNmarginHeight, 0,
475 XmNmarginWidth, 0,
476 XmNadjustLast, True,
477 NULL);
478 gui_motif_menu_colors(toolBar);
479
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480#endif
481
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000482#ifdef FEAT_GUI_TABLINE
483 /* Create the Vim GUI tabline */
484 n = 0;
485 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
486 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
487 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
488 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
489 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
490 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
491 XtSetArg(args[n], XmNshadowThickness, 0); n++;
492 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
493 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
494 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
495
496 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
497 NULL);
498 XtAddEventHandler(tabLine, ButtonPressMask, False,
499 (XtEventHandler)tabline_menu_cb, NULL);
500
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000501 gui.tabline_height = TABLINE_HEIGHT;
502
Bram Moolenaar18144c82006-04-12 21:52:12 +0000503 /*
504 * Set the size of the minor next/prev scrollers to zero, so
505 * that they are not displayed. Due to a bug in OpenMotif 2.3,
506 * even if these children widget are unmanaged, they are again
507 * managed by the Notebook widget and the notebook widget geometry
508 * is adjusted to account for the minor scroller widgets.
509 */
510 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
511 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
512 XmNtraversalOn, False, NULL);
513 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
514 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
515 XmNtraversalOn, False, NULL);
516
Bram Moolenaar29547192018-12-11 20:39:19 +0100517 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000518 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
519
Bram Moolenaar29547192018-12-11 20:39:19 +0100520 // Add the buttons to the tabline popup menu
521 n = 0;
522 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
523 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
524 XtSetArg(args[n], XmNlabelString, xms); n++;
525 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
526 XtAddCallback(button, XmNactivateCallback,
527 (XtCallbackProc)tabline_button_cb, NULL);
528 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000529
530 n = 0;
531 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
532 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
533 XtSetArg(args[n], XmNlabelString, xms); n++;
534 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
535 XtAddCallback(button, XmNactivateCallback,
536 (XtCallbackProc)tabline_button_cb, NULL);
537 XmStringFree(xms);
538
539 n = 0;
540 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
541 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
542 XtSetArg(args[n], XmNlabelString, xms); n++;
543 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
544 XtAddCallback(button, XmNactivateCallback,
545 (XtCallbackProc)tabline_button_cb, NULL);
546 XmStringFree(xms);
547#endif
548
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
550 xmFormWidgetClass, vimForm,
551 XmNleftAttachment, XmATTACH_FORM,
552 XmNrightAttachment, XmATTACH_FORM,
553 XmNbottomAttachment, XmATTACH_FORM,
554 XmNtopAttachment, XmATTACH_FORM,
555 XmNmarginWidth, 0,
556 XmNmarginHeight, 0,
557 XmNresizePolicy, XmRESIZE_ANY,
558 NULL);
559 gui_motif_scroll_colors(textAreaForm);
560
561 textArea = XtVaCreateManagedWidget("textArea",
562 xmDrawingAreaWidgetClass, textAreaForm,
563 XmNforeground, gui.norm_pixel,
564 XmNbackground, gui.back_pixel,
565 XmNleftAttachment, XmATTACH_FORM,
566 XmNtopAttachment, XmATTACH_FORM,
567 XmNrightAttachment, XmATTACH_FORM,
568 XmNbottomAttachment, XmATTACH_FORM,
569
570 /*
571 * These take some control away from the user, but avoids making them
572 * add resources to get a decent looking setup.
573 */
574 XmNborderWidth, 0,
575 XmNhighlightThickness, 0,
576 XmNshadowThickness, 0,
577 NULL);
578
579#ifdef FEAT_FOOTER
580 /*
581 * Create the Footer.
582 */
583 footer = XtVaCreateWidget("footer",
584 xmLabelGadgetClass, vimForm,
585 XmNalignment, XmALIGNMENT_BEGINNING,
586 XmNmarginHeight, 0,
587 XmNmarginWidth, 0,
588 XmNtraversalOn, False,
589 XmNrecomputeSize, False,
590 XmNleftAttachment, XmATTACH_FORM,
591 XmNleftOffset, 5,
592 XmNrightAttachment, XmATTACH_FORM,
593 XmNbottomAttachment, XmATTACH_FORM,
594 NULL);
595 gui_mch_set_footer((char_u *) "");
596#endif
597
598 /*
599 * Install the callbacks.
600 */
601 gui_x11_callbacks(textArea, vimForm);
602
603 /* Pretend we don't have input focus, we will get an event if we do. */
604 gui.in_focus = FALSE;
605}
606
607/*
608 * Called when the GUI is not going to start after all.
609 */
610 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100611gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612{
613 textArea = NULL;
614#ifdef FEAT_MENU
615 menuBar = NULL;
616#endif
617}
618
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100620gui_mch_set_text_area_pos(
621 int x UNUSED,
622 int y UNUSED,
623 int w UNUSED,
624 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625{
626#ifdef FEAT_TOOLBAR
627 /* Give keyboard focus to the textArea instead of the toolbar. */
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000628 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#endif
630}
631
632 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100633gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634{
635 if (textArea != NULL)
636#if (XmVersion >= 1002)
637 XmChangeColor(textArea, gui.back_pixel);
638#else
639 XtVaSetValues(textArea,
640 XmNbackground, gui.back_pixel,
641 NULL);
642#endif
643}
644
645/*
646 * Manage dialog centered on pointer. This could be used by the Athena code as
647 * well.
648 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000649 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100650manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651{
652 Widget shell = XtParent(dialog_child);
653 Window root, child;
654 unsigned int mask;
655 unsigned int width, height, border_width, depth;
656 int x, y, win_x, win_y, maxX, maxY;
657 Boolean mappedWhenManaged;
658
659 /* Temporarily set value of XmNmappedWhenManaged
660 to stop the dialog from popping up right away */
Bram Moolenaar46784652008-06-20 09:40:11 +0000661 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
662 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663
664 XtManageChild(dialog_child);
665
666 /* Get the pointer position (x, y) */
667 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
668 &x, &y, &win_x, &win_y, &mask);
669
670 /* Translate the pointer position (x, y) into a position for the new
671 window that will place the pointer at its center */
672 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
673 &width, &height, &border_width, &depth);
674 width += 2 * border_width;
675 height += 2 * border_width;
676 x -= width / 2;
677 y -= height / 2;
678
679 /* Ensure that the dialog remains on screen */
680 maxX = XtScreen(shell)->width - width;
681 maxY = XtScreen(shell)->height - height;
682 if (x < 0)
683 x = 0;
684 if (x > maxX)
685 x = maxX;
686 if (y < 0)
687 y = 0;
688 if (y > maxY)
689 y = maxY;
690
691 /* Set desired window position in the DialogShell */
692 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
693
694 /* Map the widget */
695 XtMapWidget(shell);
696
697 /* Restore the value of XmNmappedWhenManaged */
Bram Moolenaar46784652008-06-20 09:40:11 +0000698 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699}
700
701#if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
702 || defined(FEAT_GUI_DIALOG) || defined(PROTO)
703
704/*
705 * Encapsulate the way an XmFontList is created.
706 */
707 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100708gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709{
710 XmFontList font_list;
711
712# if (XmVersion <= 1001)
713 /* Motif 1.1 method */
714 font_list = XmFontListCreate(font, STRING_TAG);
715# else
716 /* Motif 1.2 method */
717 XmFontListEntry font_list_entry;
718
719 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
720 (XtPointer)font);
721 font_list = XmFontListAppendEntry(NULL, font_list_entry);
722 XmFontListEntryFree(&font_list_entry);
723# endif
724 return font_list;
725}
726
727# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
728 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100729gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730{
731 XmFontList font_list;
732
733 /* Motif 1.2 method */
734 XmFontListEntry font_list_entry;
735
736 font_list_entry = XmFontListEntryCreate(STRING_TAG,
737 XmFONT_IS_FONTSET,
738 (XtPointer)*fontset);
739 font_list = XmFontListAppendEntry(NULL, font_list_entry);
740 XmFontListEntryFree(&font_list_entry);
741 return font_list;
742}
743# endif
744
745#endif
746
747#if defined(FEAT_MENU) || defined(PROTO)
748/*
749 * Menu stuff.
750 */
751
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100752static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100754static void toggle_tearoff(Widget wid);
755static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100757static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100759static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760static int menu_enabled = TRUE;
761
762 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100763gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764{
765 if (flag)
766 {
767 XtManageChild(menuBar);
768#ifdef FEAT_TOOLBAR
769 if (XtIsManaged(XtParent(toolBar)))
770 {
771 /* toolBar is attached to top form */
772 XtVaSetValues(XtParent(toolBar),
773 XmNtopAttachment, XmATTACH_WIDGET,
774 XmNtopWidget, menuBar,
775 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000776#ifdef FEAT_GUI_TABLINE
777 if (showing_tabline)
778 {
779 XtVaSetValues(tabLine,
780 XmNtopAttachment, XmATTACH_WIDGET,
781 XmNtopWidget, XtParent(toolBar),
782 NULL);
783 XtVaSetValues(textAreaForm,
784 XmNtopAttachment, XmATTACH_WIDGET,
785 XmNtopWidget, tabLine,
786 NULL);
787 }
788 else
789#endif
790 XtVaSetValues(textAreaForm,
791 XmNtopAttachment, XmATTACH_WIDGET,
792 XmNtopWidget, XtParent(toolBar),
793 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000794 }
795 else
796#endif
797 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000798#ifdef FEAT_GUI_TABLINE
799 if (showing_tabline)
800 {
801 XtVaSetValues(tabLine,
802 XmNtopAttachment, XmATTACH_WIDGET,
803 XmNtopWidget, menuBar,
804 NULL);
805 XtVaSetValues(textAreaForm,
806 XmNtopAttachment, XmATTACH_WIDGET,
807 XmNtopWidget, tabLine,
808 NULL);
809 }
810 else
811#endif
812 XtVaSetValues(textAreaForm,
813 XmNtopAttachment, XmATTACH_WIDGET,
814 XmNtopWidget, menuBar,
815 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 }
817 }
818 else
819 {
820 XtUnmanageChild(menuBar);
821#ifdef FEAT_TOOLBAR
822 if (XtIsManaged(XtParent(toolBar)))
823 {
824 XtVaSetValues(XtParent(toolBar),
825 XmNtopAttachment, XmATTACH_FORM,
826 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000827#ifdef FEAT_GUI_TABLINE
828 if (showing_tabline)
829 {
830 XtVaSetValues(tabLine,
831 XmNtopAttachment, XmATTACH_WIDGET,
832 XmNtopWidget, XtParent(toolBar),
833 NULL);
834 XtVaSetValues(textAreaForm,
835 XmNtopAttachment, XmATTACH_WIDGET,
836 XmNtopWidget, tabLine,
837 NULL);
838 }
839 else
840#endif
841 XtVaSetValues(textAreaForm,
842 XmNtopAttachment, XmATTACH_WIDGET,
843 XmNtopWidget, XtParent(toolBar),
844 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845 }
846 else
847#endif
848 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000849#ifdef FEAT_GUI_TABLINE
850 if (showing_tabline)
851 {
852 XtVaSetValues(tabLine,
853 XmNtopAttachment, XmATTACH_FORM,
854 NULL);
855 XtVaSetValues(textAreaForm,
856 XmNtopAttachment, XmATTACH_WIDGET,
857 XmNtopWidget, tabLine,
858 NULL);
859 }
860 else
861#endif
862 XtVaSetValues(textAreaForm,
863 XmNtopAttachment, XmATTACH_FORM,
864 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865 }
866 }
867
868}
869
870/*
871 * Enable or disable mnemonics for the toplevel menus.
872 */
873 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100874gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875{
876 /*
877 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
878 * crashes when using a mnemonic then.
879 */
880 if (!menu_enabled)
881 enable = FALSE;
882 do_set_mnemonics(enable);
883}
884
885 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100886do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887{
888 vimmenu_T *menu;
889
890 for (menu = root_menu; menu != NULL; menu = menu->next)
891 if (menu->id != (Widget)0)
892 XtVaSetValues(menu->id,
893 XmNmnemonic, enable ? menu->mnemonic : NUL,
894 NULL);
895}
896
897 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100898gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899{
900 XmString label;
901 Widget shell;
902 vimmenu_T *parent = menu->parent;
903
904#ifdef MOTIF_POPUP
905 if (menu_is_popup(menu->name))
906 {
907 Arg arg[2];
908 int n = 0;
909
910 /* Only create the popup menu when it's actually used, otherwise there
911 * is a delay when using the right mouse button. */
912# if (XmVersion <= 1002)
913 if (mouse_model_popup())
914# endif
915 {
916 if (gui.menu_bg_pixel != INVALCOLOR)
917 {
918 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
919 }
920 if (gui.menu_fg_pixel != INVALCOLOR)
921 {
922 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
923 }
924 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
925 arg, n);
926 menu->id = (Widget)0;
927 }
928 return;
929 }
930#endif
931
932 if (!menu_is_menubar(menu->name)
933 || (parent != NULL && parent->submenu_id == (Widget)0))
934 return;
935
936 label = XmStringCreate((char *)menu->dname, STRING_TAG);
937 if (label == NULL)
938 return;
939 menu->id = XtVaCreateWidget("subMenu",
940 xmCascadeButtonWidgetClass,
941 (parent == NULL) ? menuBar : parent->submenu_id,
942 XmNlabelString, label,
943 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
944#if (XmVersion >= 1002)
945 /* submenu: count the tearoff item (needed for LessTif) */
946 XmNpositionIndex, idx + (parent != NULL
947 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
948#endif
949 NULL);
950 gui_motif_menu_colors(menu->id);
951 gui_motif_menu_fontlist(menu->id);
952 XmStringFree(label);
953
954 if (menu->id == (Widget)0) /* failed */
955 return;
956
957 /* add accelerator text */
958 gui_motif_add_actext(menu);
959
960 shell = XtVaCreateWidget("subMenuShell",
961 xmMenuShellWidgetClass, menu->id,
962 XmNwidth, 1,
963 XmNheight, 1,
964 NULL);
965 gui_motif_menu_colors(shell);
966 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
967 xmRowColumnWidgetClass, shell,
968 XmNrowColumnType, XmMENU_PULLDOWN,
969 NULL);
970 gui_motif_menu_colors(menu->submenu_id);
971
972 if (menu->submenu_id == (Widget)0) /* failed */
973 return;
974
975#if (XmVersion >= 1002)
976 /* Set the colors for the tear off widget */
977 toggle_tearoff(menu->submenu_id);
978#endif
979
980 XtVaSetValues(menu->id,
981 XmNsubMenuId, menu->submenu_id,
982 NULL);
983
984 /*
985 * The "Help" menu is a special case, and should be placed at the far
986 * right hand side of the menu-bar. It's recognized by its high priority.
987 */
988 if (parent == NULL && menu->priority >= 9999)
989 XtVaSetValues(menuBar,
990 XmNmenuHelpWidget, menu->id,
991 NULL);
992
993 /*
994 * When we add a top-level item to the menu bar, we can figure out how
995 * high the menu bar should be.
996 */
997 if (parent == NULL)
998 gui_mch_compute_menu_height(menu->id);
999}
1000
1001
1002/*
1003 * Add mnemonic and accelerator text to a menu button.
1004 */
1005 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001006gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007{
1008 XmString label;
1009
Bram Moolenaar933eb392007-05-10 17:52:45 +00001010 /* Add accelerator text, if there is one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 if (menu->actext != NULL && menu->id != (Widget)0)
1012 {
1013 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1014 if (label == NULL)
1015 return;
1016 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1017 XmStringFree(label);
1018 }
1019}
1020
1021 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001022gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023{
1024#if (XmVersion >= 1002)
1025 if (enable)
1026 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1027 else
1028 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1029 toggle_tearoff(menuBar);
1030 gui_mch_recurse_tearoffs(root_menu);
1031#endif
1032}
1033
1034#if (XmVersion >= 1002)
1035/*
1036 * Set the tearoff for one menu widget on or off, and set the color of the
1037 * tearoff widget.
1038 */
1039 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001040toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041{
1042 Widget w;
1043
1044 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1045 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1046 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1047 gui_motif_menu_colors(w);
1048}
1049
1050 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001051gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052{
1053 while (menu != NULL)
1054 {
1055 if (!menu_is_popup(menu->name))
1056 {
1057 if (menu->submenu_id != (Widget)0)
1058 toggle_tearoff(menu->submenu_id);
1059 gui_mch_recurse_tearoffs(menu->children);
1060 }
1061 menu = menu->next;
1062 }
1063}
1064#endif
1065
1066 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001067gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068{
1069 Dimension shadowHeight;
1070
1071 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1072 return shadowHeight;
1073}
1074
1075/*
1076 * Compute the height of the menu bar.
1077 * We need to check all the items for their position and height, for the case
1078 * there are several rows, and/or some characters extend higher or lower.
1079 */
1080 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001081gui_mch_compute_menu_height(
1082 Widget id) /* can be NULL when deleting menu */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083{
1084 Dimension y, maxy;
1085 Dimension margin, shadow;
1086 vimmenu_T *mp;
1087 static Dimension height = 21; /* normal height of a menu item */
1088
1089 /*
1090 * Get the height of the new item, before managing it, because it will
1091 * still reflect the font size. After managing it depends on the menu
1092 * height, which is what we just wanted to get!.
1093 */
1094 if (id != (Widget)0)
1095 XtVaGetValues(id, XmNheight, &height, NULL);
1096
1097 /* Find any menu Widget, to be able to call XtManageChild() */
1098 else
1099 for (mp = root_menu; mp != NULL; mp = mp->next)
1100 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1101 {
1102 id = mp->id;
1103 break;
1104 }
1105
1106 /*
1107 * Now manage the menu item, to make them all be positioned (makes an
1108 * extra row when needed, removes it when not needed).
1109 */
1110 if (id != (Widget)0)
1111 XtManageChild(id);
1112
1113 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001114 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 */
1116 maxy = 0;
1117 for (mp = root_menu; mp != NULL; mp = mp->next)
1118 {
1119 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1120 {
1121 XtVaGetValues(mp->id, XmNy, &y, NULL);
1122 if (y > maxy)
1123 maxy = y;
1124 }
1125 }
1126
1127 XtVaGetValues(menuBar,
1128 XmNmarginHeight, &margin,
1129 XmNshadowThickness, &shadow,
1130 NULL);
1131
1132 /*
1133 * This computation is the result of trial-and-error:
1134 * maxy = The maximum position of an item; required for when there are
1135 * two or more rows
1136 * height = height of an item, before managing it; Hopefully this will
1137 * change with the font height. Includes shadow-border.
1138 * shadow = shadow-border; must be subtracted from the height.
1139 * margin = margin around the menu buttons; Must be added.
1140 * Add 4 for the underlining of shortcut keys.
1141 */
1142 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1143
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 /* Somehow the menu bar doesn't resize automatically. Set it here,
1145 * even though this is a catch 22. Don't do this when starting up,
1146 * somehow the menu gets very high then. */
1147 if (gui.shell_created)
1148 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001149}
1150
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001151#ifdef FEAT_TOOLBAR
1152
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001153/*
1154 * Icons used by the toolbar code.
1155 */
1156#include "gui_x11_pm.h"
1157
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001158static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001159
1160/*
1161 * Read an Xpm file. Return OK or FAIL.
1162 */
1163 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001164check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001165{
1166 XpmAttributes attrs;
1167 int status;
1168 Pixmap mask;
1169 Pixmap map;
1170
1171 attrs.valuemask = 0;
1172
1173 /* Create the "sensitive" pixmap */
1174 status = XpmReadFileToPixmap(gui.dpy,
1175 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1176 (char *)path, &map, &mask, &attrs);
1177 XpmFreeAttributes(&attrs);
1178
1179 if (status == XpmSuccess)
1180 return OK;
1181 return FAIL;
1182}
1183
1184
1185/*
1186 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001187 * When it's to be read from a file, "fname" is set to the file name
1188 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001189 * Return a blank pixmap if it fails.
1190 */
1191 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001192get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001193{
1194 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1195 char **xpm = NULL; /* xpm array */
1196 int res;
1197
Bram Moolenaar7c626922005-02-07 22:01:03 +00001198 *fname = NULL;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001199 buf[0] = NUL; /* start with NULL path */
1200
1201 if (menu->iconfile != NULL)
1202 {
1203 /* Use the "icon=" argument. */
1204 gui_find_iconfile(menu->iconfile, buf, "xpm");
1205 res = check_xpm(buf);
1206
1207 /* If it failed, try using the menu name. */
1208 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1209 res = check_xpm(buf);
1210 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001211 {
1212 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001213 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001214 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001215 }
1216
1217 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1218 {
1219 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001220 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001221 xpm = built_in_pixmaps[menu->iconidx];
1222 else
1223 xpm = tb_blank_xpm;
1224 }
1225
1226 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001228
1229/*
1230 * Add arguments for the toolbar pixmap to a menu item.
1231 */
1232 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001233add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001234{
1235 vim_free(menu->xpm_fname);
1236 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1237 if (menu->xpm == NULL)
1238 {
1239 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1240 }
1241 else
1242 {
1243 if (menu->xpm_fname != NULL)
1244 {
1245 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
1246 }
1247 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1248 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1249 }
1250 return n;
1251}
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001252#endif /* FEAT_TOOLBAR */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253
1254 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001255gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256{
1257 XmString label;
1258 vimmenu_T *parent = menu->parent;
1259
1260# ifdef EBCDIC
1261 menu->mnemonic = 0;
1262# endif
1263
1264# if (XmVersion <= 1002)
1265 /* Don't add Popup menu items when the popup menu isn't used. */
1266 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1267 return;
1268# endif
1269
1270# ifdef FEAT_TOOLBAR
1271 if (menu_is_toolbar(parent->name))
1272 {
1273 WidgetClass type;
1274 XmString xms = NULL; /* fallback label if pixmap not found */
1275 int n;
1276 Arg args[18];
1277
1278 n = 0;
1279 if (menu_is_separator(menu->name))
1280 {
1281 char *cp;
1282 Dimension wid;
1283
1284 /*
1285 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1286 * a width specifier. If no width is specified then we choose one.
1287 */
1288 cp = (char *)vim_strchr(menu->name, ':');
1289 if (cp != NULL)
1290 wid = (Dimension)atoi(++cp);
1291 else
1292 wid = 4;
1293
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 type = xmSeparatorWidgetClass;
1295 XtSetArg(args[n], XmNwidth, wid); n++;
1296 XtSetArg(args[n], XmNminWidth, wid); n++;
1297 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001298 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 }
1300 else
1301 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 /* Without shadows one can't sense whatever the button has been
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001303 * pressed or not! However we want to save a bit of space...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001304 * Need the highlightThickness to see the focus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001306 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1308 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1309 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001310 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001311 /* Set the label here, so that we can switch between icons/text
1312 * by changing the XmNlabelType resource. */
1313 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1314 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001315
Bram Moolenaar7c626922005-02-07 22:01:03 +00001316 n = add_pixmap_args(menu, args, n);
1317
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001318 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 }
1320
1321 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1322 if (menu->id == NULL)
1323 {
1324 menu->id = XtCreateManagedWidget((char *)menu->dname,
1325 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001326 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 {
1328 XtAddCallback(menu->id,
1329 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330# ifdef FEAT_FOOTER
1331 XtAddEventHandler(menu->id, EnterWindowMask, False,
1332 toolbarbutton_enter_cb, menu);
1333 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1334 toolbarbutton_leave_cb, menu);
1335# endif
1336 }
1337 }
1338 else
1339 XtSetValues(menu->id, args, n);
1340 if (xms != NULL)
1341 XmStringFree(xms);
1342
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001343# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001345# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346
1347 menu->parent = parent;
1348 menu->submenu_id = NULL;
1349 /* When adding first item to toolbar it might have to be enabled .*/
1350 if (!XtIsManaged(XtParent(toolBar))
1351 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1352 gui_mch_show_toolbar(TRUE);
1353 gui.toolbar_height = gui_mch_compute_toolbar_height();
1354 return;
1355 } /* toolbar menu item */
1356# endif
1357
1358 /* No parent, must be a non-menubar menu */
1359 if (parent->submenu_id == (Widget)0)
1360 return;
1361
1362 menu->submenu_id = (Widget)0;
1363
1364 /* Add menu separator */
1365 if (menu_is_separator(menu->name))
1366 {
1367 menu->id = XtVaCreateWidget("subMenu",
1368 xmSeparatorGadgetClass, parent->submenu_id,
1369#if (XmVersion >= 1002)
1370 /* count the tearoff item (needed for LessTif) */
1371 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1372 ? 1 : 0),
1373#endif
1374 NULL);
1375 gui_motif_menu_colors(menu->id);
1376 return;
1377 }
1378
1379 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1380 if (label == NULL)
1381 return;
1382 menu->id = XtVaCreateWidget("subMenu",
1383 xmPushButtonWidgetClass, parent->submenu_id,
1384 XmNlabelString, label,
1385 XmNmnemonic, menu->mnemonic,
1386#if (XmVersion >= 1002)
1387 /* count the tearoff item (needed for LessTif) */
1388 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1389 ? 1 : 0),
1390#endif
1391 NULL);
1392 gui_motif_menu_colors(menu->id);
1393 gui_motif_menu_fontlist(menu->id);
1394 XmStringFree(label);
1395
1396 if (menu->id != (Widget)0)
1397 {
1398 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1399 (XtPointer)menu);
1400 /* add accelerator text */
1401 gui_motif_add_actext(menu);
1402 }
1403}
1404
1405#if (XmVersion <= 1002) || defined(PROTO)
1406/*
1407 * This function will destroy/create the popup menus dynamically,
1408 * according to the value of 'mousemodel'.
1409 * This will fix the "right mouse button freeze" that occurs when
1410 * there exists a popup menu but it isn't managed.
1411 */
1412 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001413gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414{
1415 int idx = 0;
1416
1417 /* When GUI hasn't started the menus have not been created. */
1418 if (!gui.in_use)
1419 return;
1420
1421 while (menu)
1422 {
1423 if (menu->children != NULL)
1424 {
1425 if (menu_is_popup(menu->name))
1426 {
1427 if (mouse_model_popup())
1428 {
1429 /* Popup menu will be used. Create the popup menus. */
1430 gui_mch_add_menu(menu, idx);
1431 gui_motif_update_mousemodel(menu->children);
1432 }
1433 else
1434 {
1435 /* Popup menu will not be used. Destroy the popup menus. */
1436 gui_motif_update_mousemodel(menu->children);
1437 gui_mch_destroy_menu(menu);
1438 }
1439 }
1440 }
1441 else if (menu_is_child_of_popup(menu))
1442 {
1443 if (mouse_model_popup())
1444 gui_mch_add_menu_item(menu, idx);
1445 else
1446 gui_mch_destroy_menu(menu);
1447 }
1448 menu = menu->next;
1449 ++idx;
1450 }
1451}
1452#endif
1453
1454 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001455gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456{
1457 if (menuBar == (Widget)0)
1458 return;
1459 gui_motif_menu_colors(menuBar);
1460#ifdef FEAT_TOOLBAR
1461 gui_motif_menu_colors(toolBarFrame);
1462 gui_motif_menu_colors(toolBar);
1463#endif
1464
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001465 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466}
1467
1468 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001469gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470{
1471 if (menuBar == (Widget)0)
1472 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001473 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {
1475 Dimension height;
1476 Position w, h;
1477
1478 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1479 gui.menu_height = height;
1480
1481 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1482 gui_resize_shell(w, h
1483#ifdef FEAT_XIM
1484 - xim_get_status_area_height()
1485#endif
1486 );
1487 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001488 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 ui_new_shellsize();
1490}
1491
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001492#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001494gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495{
1496# ifdef FEAT_TOOLBAR
1497 vimmenu_T *menu;
1498
1499 if (toolBar == (Widget)0)
1500 return;
1501
1502 menu = gui_find_menu((char_u *)"ToolBar");
1503 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001504 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505# endif
1506}
1507
1508 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001509gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510{
1511# ifdef FEAT_TOOLBAR
1512 vimmenu_T *toolbar;
1513
1514 if (toolBar == (Widget)0)
1515 return;
1516
1517 toolbar = gui_find_menu((char_u *)"ToolBar");
1518 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001519 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520# endif
1521}
1522#endif
1523
1524 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001525submenu_change(
1526 vimmenu_T *menu,
1527 int colors) /* TRUE for colors, FALSE for font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528{
1529 vimmenu_T *mp;
1530
1531 for (mp = menu; mp != NULL; mp = mp->next)
1532 {
1533 if (mp->id != (Widget)0)
1534 {
1535 if (colors)
1536 {
1537 gui_motif_menu_colors(mp->id);
1538#ifdef FEAT_TOOLBAR
1539 /* For a toolbar item: Free the pixmap and allocate a new one,
1540 * so that the background color is right. */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001541 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001543 int n = 0;
1544 Arg args[18];
1545
Bram Moolenaar7c626922005-02-07 22:01:03 +00001546 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001547 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001549# ifdef FEAT_BEVAL_GUI
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001550 /* If we have a tooltip, then we need to change its font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 if (mp->tip != NULL)
1552 {
1553 Arg args[2];
1554
1555 args[0].name = XmNbackground;
1556 args[0].value = gui.tooltip_bg_pixel;
1557 args[1].name = XmNforeground;
1558 args[1].value = gui.tooltip_fg_pixel;
1559 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1560 }
1561# endif
1562#endif
1563 }
1564 else
1565 {
1566 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001567#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001568 /* If we have a tooltip, then we need to change its font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 if (mp->tip != NULL)
1570 {
1571 Arg args[1];
1572
1573 args[0].name = XmNfontList;
1574 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1575 &gui.tooltip_fontset);
1576 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1577 }
1578#endif
1579 }
1580 }
1581
1582 if (mp->children != NULL)
1583 {
1584#if (XmVersion >= 1002)
1585 /* Set the colors/font for the tear off widget */
1586 if (mp->submenu_id != (Widget)0)
1587 {
1588 if (colors)
1589 gui_motif_menu_colors(mp->submenu_id);
1590 else
1591 gui_motif_menu_fontlist(mp->submenu_id);
1592 toggle_tearoff(mp->submenu_id);
1593 }
1594#endif
1595 /* Set the colors for the children */
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001596 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 }
1598 }
1599}
1600
1601/*
1602 * Destroy the machine specific menu widget.
1603 */
1604 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001605gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606{
1607 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1608 * On the other hand, problems have been reported that the submenu must be
1609 * deleted first...
1610 *
1611 * This code should be basically identical to that in the file gui_athena.c
1612 * because they are both Xt based.
1613 */
1614 if (menu->submenu_id != (Widget)0)
1615 {
1616 XtDestroyWidget(menu->submenu_id);
1617 menu->submenu_id = (Widget)0;
1618 }
1619
1620 if (menu->id != (Widget)0)
1621 {
1622 Widget parent;
1623
1624 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001625#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001626 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {
1628 /* We try to destroy this before the actual menu, because there are
1629 * callbacks, etc. that will be unregistered during the tooltip
1630 * destruction.
1631 *
1632 * If you call "gui_mch_destroy_beval_area()" after destroying
1633 * menu->id, then the tooltip's window will have already been
1634 * deallocated by Xt, and unknown behaviour will ensue (probably
1635 * a core dump).
1636 */
1637 gui_mch_destroy_beval_area(menu->tip);
1638 menu->tip = NULL;
1639 }
1640#endif
1641 XtDestroyWidget(menu->id);
1642 menu->id = (Widget)0;
1643 if (parent == menuBar)
1644 gui_mch_compute_menu_height((Widget)0);
1645#ifdef FEAT_TOOLBAR
1646 else if (parent == toolBar)
1647 {
1648 Cardinal num_children;
1649
1650 /* When removing last toolbar item, don't display the toolbar. */
1651 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1652 if (num_children == 0)
1653 gui_mch_show_toolbar(FALSE);
1654 else
1655 gui.toolbar_height = gui_mch_compute_toolbar_height();
1656 }
1657#endif
1658 }
1659}
1660
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001662gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663{
1664#ifdef MOTIF_POPUP
1665 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1666 XtManageChild(menu->submenu_id);
1667#endif
1668}
1669
1670#endif /* FEAT_MENU */
1671
1672/*
1673 * Set the menu and scrollbar colors to their default values.
1674 */
1675 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001676gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677{
1678 if (gui.in_use)
1679 {
1680 /* Use the values saved when starting up. These should come from the
1681 * window manager or a resources file. */
1682 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1683 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1684 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1685 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001686#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 gui.tooltip_fg_pixel =
1688 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1689 gui.tooltip_bg_pixel =
1690 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1691#endif
1692 }
1693}
1694
1695
1696/*
1697 * Scrollbar stuff.
1698 */
1699
1700 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001701gui_mch_set_scrollbar_thumb(
1702 scrollbar_T *sb,
1703 long val,
1704 long size,
1705 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706{
1707 if (sb->id != (Widget)0)
1708 XtVaSetValues(sb->id,
1709 XmNvalue, val,
1710 XmNsliderSize, size,
1711 XmNpageIncrement, (size > 2 ? size - 2 : 1),
1712 XmNmaximum, max + 1, /* Motif has max one past the end */
1713 NULL);
1714}
1715
1716 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001717gui_mch_set_scrollbar_pos(
1718 scrollbar_T *sb,
1719 int x,
1720 int y,
1721 int w,
1722 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723{
1724 if (sb->id != (Widget)0)
1725 {
1726 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1727 {
1728 if (y == 0)
1729 h -= gui.border_offset;
1730 else
1731 y -= gui.border_offset;
1732 XtVaSetValues(sb->id,
1733 XmNtopOffset, y,
1734 XmNbottomOffset, -y - h,
1735 XmNwidth, w,
1736 NULL);
1737 }
1738 else
1739 XtVaSetValues(sb->id,
1740 XmNtopOffset, y,
1741 XmNleftOffset, x,
1742 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1743 ? gui.scrollbar_width : 0,
1744 XmNheight, h,
1745 NULL);
1746 XtManageChild(sb->id);
1747 }
1748}
1749
1750 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001751gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752{
1753 Arg args[16];
1754 int n;
1755
1756 if (sb->id != (Widget)0)
1757 {
1758 n = 0;
1759 if (flag)
1760 {
1761 switch (sb->type)
1762 {
1763 case SBAR_LEFT:
1764 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1765 break;
1766
1767 case SBAR_RIGHT:
1768 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1769 break;
1770
1771 case SBAR_BOTTOM:
1772 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1773 break;
1774 }
1775 XtSetValues(textArea, args, n);
1776 XtManageChild(sb->id);
1777 }
1778 else
1779 {
1780 if (!gui.which_scrollbars[sb->type])
1781 {
1782 /* The scrollbars of this type are all disabled, adjust the
1783 * textArea attachment offset. */
1784 switch (sb->type)
1785 {
1786 case SBAR_LEFT:
1787 XtSetArg(args[n], XmNleftOffset, 0); n++;
1788 break;
1789
1790 case SBAR_RIGHT:
1791 XtSetArg(args[n], XmNrightOffset, 0); n++;
1792 break;
1793
1794 case SBAR_BOTTOM:
1795 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1796 break;
1797 }
1798 XtSetValues(textArea, args, n);
1799 }
1800 XtUnmanageChild(sb->id);
1801 }
1802 }
1803}
1804
1805 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001806gui_mch_create_scrollbar(
1807 scrollbar_T *sb,
1808 int orient) /* SBAR_VERT or SBAR_HORIZ */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809{
1810 Arg args[16];
1811 int n;
1812
1813 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 XtSetArg(args[n], XmNminimum, 0); n++;
1815 XtSetArg(args[n], XmNorientation,
1816 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1817
1818 switch (sb->type)
1819 {
1820 case SBAR_LEFT:
1821 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1822 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1823 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1824 break;
1825
1826 case SBAR_RIGHT:
1827 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1828 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1829 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1830 break;
1831
1832 case SBAR_BOTTOM:
1833 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1834 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1835 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1836 break;
1837 }
1838
1839 sb->id = XtCreateWidget("scrollBar",
1840 xmScrollBarWidgetClass, textAreaForm, args, n);
1841
1842 /* Remember the default colors, needed for ":hi clear". */
1843 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1844 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1845 XtVaGetValues(sb->id,
1846 XmNbackground, &gui.scroll_def_bg_pixel,
1847 XmNforeground, &gui.scroll_def_fg_pixel,
1848 NULL);
1849
1850 if (sb->id != (Widget)0)
1851 {
1852 gui_mch_set_scrollbar_colors(sb);
1853 XtAddCallback(sb->id, XmNvalueChangedCallback,
1854 scroll_cb, (XtPointer)sb->ident);
1855 XtAddCallback(sb->id, XmNdragCallback,
1856 scroll_cb, (XtPointer)sb->ident);
1857 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1858 (XtPointer)0);
1859 }
1860}
1861
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001863gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864{
1865 if (sb->id != (Widget)0)
1866 XtDestroyWidget(sb->id);
1867}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868
1869 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001870gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871{
1872 if (sb->id != (Widget)0)
1873 {
1874 if (gui.scroll_bg_pixel != INVALCOLOR)
1875 {
1876#if (XmVersion>=1002)
1877 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1878#else
1879 XtVaSetValues(sb->id,
1880 XmNtroughColor, gui.scroll_bg_pixel,
1881 NULL);
1882#endif
1883 }
1884
1885 if (gui.scroll_fg_pixel != INVALCOLOR)
1886 XtVaSetValues(sb->id,
1887 XmNforeground, gui.scroll_fg_pixel,
1888#if (XmVersion<1002)
1889 XmNbackground, gui.scroll_fg_pixel,
1890#endif
1891 NULL);
1892 }
1893
1894 /* This is needed for the rectangle below the vertical scrollbars. */
1895 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1896 gui_motif_scroll_colors(textAreaForm);
1897}
1898
1899/*
1900 * Miscellaneous stuff:
1901 */
1902
1903 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001904gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905{
1906 return(XtWindow(textArea));
1907}
1908
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001909/*
1910 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1911 * When one is found, simulate a button press on that widget and give it the
1912 * keyboard focus. If the mnemonic is on a label, look in the userData field
1913 * of the label to see if it points to another widget, and give that the focus.
1914 */
1915 static void
1916do_mnemonic(Widget w, unsigned int keycode)
1917{
1918 WidgetList children;
1919 int numChildren, i;
1920 Boolean isMenu;
1921 KeySym mnemonic = '\0';
1922 char mneString[2];
1923 Widget userData;
1924 unsigned char rowColType;
1925
1926 if (XtIsComposite(w))
1927 {
1928 if (XtClass(w) == xmRowColumnWidgetClass)
1929 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001930 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001931 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1932 }
1933 else
1934 isMenu = False;
1935 if (!isMenu)
1936 {
1937 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001938 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001939 for (i = 0; i < numChildren; i++)
1940 do_mnemonic(children[i], keycode);
1941 }
1942 }
1943 else
1944 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001945 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001946 if (mnemonic != '\0')
1947 {
1948 mneString[0] = mnemonic;
1949 mneString[1] = '\0';
1950 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1951 XStringToKeysym(mneString)) == keycode)
1952 {
1953 if (XtClass(w) == xmLabelWidgetClass
1954 || XtClass(w) == xmLabelGadgetClass)
1955 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001956 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001957 if (userData != NULL && XtIsWidget(userData))
1958 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1959 }
1960 else
1961 {
1962 XKeyPressedEvent keyEvent;
1963
1964 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1965
Bram Moolenaar7db5fc82010-05-24 11:59:29 +02001966 vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001967 keyEvent.type = KeyPress;
1968 keyEvent.serial = 1;
1969 keyEvent.send_event = True;
1970 keyEvent.display = XtDisplay(w);
1971 keyEvent.window = XtWindow(w);
1972 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1973 NULL, 0);
1974 }
1975 }
1976 }
1977 }
1978}
1979
1980/*
1981 * Callback routine for dialog mnemonic processing.
1982 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001983 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001984mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001985{
1986 do_mnemonic(w, event->keycode);
1987}
1988
1989
1990/*
1991 * Search the widget tree under w for widgets with mnemonics. When found, add
1992 * a passive grab to the dialog widget for the mnemonic character, thus
1993 * directing mnemonic events to the dialog widget.
1994 */
1995 static void
1996add_mnemonic_grabs(Widget dialog, Widget w)
1997{
1998 char mneString[2];
1999 WidgetList children;
2000 int numChildren, i;
2001 Boolean isMenu;
2002 KeySym mnemonic = '\0';
2003 unsigned char rowColType;
2004
2005 if (XtIsComposite(w))
2006 {
2007 if (XtClass(w) == xmRowColumnWidgetClass)
2008 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002009 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002010 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2011 }
2012 else
2013 isMenu = False;
2014 if (!isMenu)
2015 {
2016 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002017 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002018 for (i = 0; i < numChildren; i++)
2019 add_mnemonic_grabs(dialog, children[i]);
2020 }
2021 }
2022 else
2023 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002024 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002025 if (mnemonic != '\0')
2026 {
2027 mneString[0] = mnemonic;
2028 mneString[1] = '\0';
2029 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2030 XStringToKeysym(mneString)),
2031 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2032 }
2033 }
2034}
2035
2036/*
2037 * Add a handler for mnemonics in a dialog. Motif itself only handles
2038 * mnemonics in menus. Mnemonics added or changed after this call will be
2039 * ignored.
2040 *
2041 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2042 * the appropriate label and set the XmNuserData resource of the label to the
2043 * widget to get the focus when the mnemonic is typed.
2044 */
2045 static void
2046activate_dialog_mnemonics(Widget dialog)
2047{
2048 if (!dialog)
2049 return;
2050
2051 XtAddEventHandler(dialog, KeyPressMask, False,
2052 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2053 add_mnemonic_grabs(dialog, dialog);
2054}
2055
2056/*
2057 * Removes the event handler and key-grabs for dialog mnemonic handling.
2058 */
2059 static void
2060suppress_dialog_mnemonics(Widget dialog)
2061{
2062 if (!dialog)
2063 return;
2064
2065 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2066 XtRemoveEventHandler(dialog, KeyPressMask, False,
2067 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2068}
2069
2070#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002071/*
2072 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2073 */
2074 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002075set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002076{
2077 XmFontList fl;
2078
2079#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002080 if (gui.fontset != NOFONTSET)
2081 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002082 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2083 if (fl != NULL)
2084 {
2085 if (XtIsManaged(id))
2086 {
2087 XtUnmanageChild(id);
2088 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01002089 /* We should force the widget to recalculate its
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002090 * geometry now. */
2091 XtManageChild(id);
2092 }
2093 else
2094 XtVaSetValues(id, XmNfontList, fl, NULL);
2095 XmFontListFree(fl);
2096 }
2097 }
2098#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002099 if (gui.norm_font != NOFONT)
2100 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002101 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2102 if (fl != NULL)
2103 {
2104 if (XtIsManaged(id))
2105 {
2106 XtUnmanageChild(id);
2107 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01002108 /* We should force the widget to recalculate its
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002109 * geometry now. */
2110 XtManageChild(id);
2111 }
2112 else
2113 XtVaSetValues(id, XmNfontList, fl, NULL);
2114 XmFontListFree(fl);
2115 }
2116 }
2117#endif
2118}
2119#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120
2121#if defined(FEAT_BROWSE) || defined(PROTO)
2122
2123/*
2124 * file selector related stuff
2125 */
2126
2127#include <Xm/FileSB.h>
2128#include <Xm/XmStrDefs.h>
2129
2130typedef struct dialog_callback_arg
2131{
2132 char * args; /* not used right now */
2133 int id;
2134} dcbarg_T;
2135
2136static Widget dialog_wgt;
2137static char *browse_fname = NULL;
2138static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2139 /* used to set up XmStrings */
2140
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002141static void DialogCancelCB(Widget, XtPointer, XtPointer);
2142static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143
2144/*
2145 * This function is used to translate the predefined label text of the
2146 * precomposed dialogs. We do this explicitly to allow:
2147 *
2148 * - usage of gettext for translation, as in all the other places.
2149 *
2150 * - equalize the messages between different GUI implementations as far as
2151 * possible.
2152 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002153 static void
2154set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002156 XmString str;
2157 Widget w;
2158 char_u *p, *next;
2159 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160
2161 w = XtNameToWidget(parent, name);
2162
2163 if (!w)
2164 return;
2165
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002166 p = vim_strsave((char_u *)new_label);
2167 if (p == NULL)
2168 return;
2169 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002171 if (*next == DLG_HOTKEY_CHAR)
2172 {
2173 int len = STRLEN(next);
2174
2175 if (len > 0)
2176 {
2177 mch_memmove(next, next + 1, len);
2178 mnemonic = next[0];
2179 }
2180 }
2181 }
2182
2183 str = XmStringCreate((char *)p, STRING_TAG);
2184 vim_free(p);
2185
2186 if (str != NULL)
2187 {
2188 XtVaSetValues(w,
2189 XmNlabelString, str,
2190 XmNmnemonic, mnemonic,
2191 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 XmStringFree(str);
2193 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002194 gui_motif_menu_fontlist(w);
2195}
2196
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002197 static void
2198set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002199{
2200 Widget w;
2201 w = XtNameToWidget(parent, name);
2202
2203 if (!w)
2204 return;
2205
2206 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207}
2208
2209/*
2210 * Put up a file requester.
2211 * Returns the selected name in allocated memory, or NULL for Cancel.
2212 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002213 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002214gui_mch_browse(
2215 int saving UNUSED, /* select file to write */
2216 char_u *title, /* title for the window */
2217 char_u *dflt, /* default name */
2218 char_u *ext UNUSED, /* not used (extension added) */
2219 char_u *initdir, /* initial directory, NULL for current dir */
2220 char_u *filter) /* file name filter */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221{
2222 char_u dirbuf[MAXPATHL];
2223 char_u dfltbuf[MAXPATHL];
2224 char_u *pattern;
2225 char_u *tofree = NULL;
2226
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002227 /* There a difference between the resource name and value, Therefore, we
2228 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2229 * dialog name.
2230 */
2231
2232 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002233
2234 if (initdir == NULL || *initdir == NUL)
2235 {
2236 mch_dirname(dirbuf, MAXPATHL);
2237 initdir = dirbuf;
2238 }
2239
2240 if (dflt == NULL)
2241 dflt = (char_u *)"";
2242 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2243 {
2244 /* The default selection should be the full path, "dflt" is only the
2245 * file name. */
2246 STRCPY(dfltbuf, initdir);
2247 add_pathsep(dfltbuf);
2248 STRCAT(dfltbuf, dflt);
2249 dflt = dfltbuf;
2250 }
2251
2252 /* Can only use one pattern for a file name. Get the first pattern out of
2253 * the filter. An empty pattern means everything matches. */
2254 if (filter == NULL)
2255 pattern = (char_u *)"";
2256 else
2257 {
2258 char_u *s, *p;
2259
2260 s = filter;
2261 for (p = filter; *p != NUL; ++p)
2262 {
2263 if (*p == '\t') /* end of description, start of pattern */
2264 s = p + 1;
2265 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2266 break;
2267 }
2268 pattern = vim_strnsave(s, p - s);
2269 tofree = pattern;
2270 if (pattern == NULL)
2271 pattern = (char_u *)"";
2272 }
2273
2274 XtVaSetValues(dialog_wgt,
2275 XtVaTypedArg,
2276 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2277 XtVaTypedArg,
2278 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2279 XtVaTypedArg,
2280 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2281 XtVaTypedArg,
2282 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2283 NULL);
2284
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002285 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2286 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2288 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002289 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002291 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2293
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002294 /* This is to save us from silly external settings using not fixed with
2295 * fonts for file selection.
2296 */
2297 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2298 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2299
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 gui_motif_menu_colors(dialog_wgt);
2301 if (gui.scroll_bg_pixel != INVALCOLOR)
2302 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2303
2304 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2305 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2306 /* We have no help in this window, so hide help button */
2307 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2308 (unsigned char)XmDIALOG_HELP_BUTTON));
2309
2310 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002311 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312
2313 /* sit in a loop until the dialog box has gone away */
2314 do
2315 {
2316 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2317 (XtInputMask)XtIMAll);
2318 } while (XtIsManaged(dialog_wgt));
2319
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002320 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 XtDestroyWidget(dialog_wgt);
2322 vim_free(tofree);
2323
2324 if (browse_fname == NULL)
2325 return NULL;
2326 return vim_strsave((char_u *)browse_fname);
2327}
2328
2329/*
2330 * The code below was originally taken from
2331 * /usr/examples/motif/xmsamplers/xmeditor.c
2332 * on Digital Unix 4.0d, but heavily modified.
2333 */
2334
2335/*
2336 * Process callback from Dialog cancel actions.
2337 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002339DialogCancelCB(
2340 Widget w UNUSED, /* widget id */
2341 XtPointer client_data UNUSED, /* data from application */
2342 XtPointer call_data UNUSED) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343{
2344 if (browse_fname != NULL)
2345 {
2346 XtFree(browse_fname);
2347 browse_fname = NULL;
2348 }
2349 XtUnmanageChild(dialog_wgt);
2350}
2351
2352/*
2353 * Process callback from Dialog actions.
2354 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002356DialogAcceptCB(
2357 Widget w UNUSED, /* widget id */
2358 XtPointer client_data UNUSED, /* data from application */
2359 XtPointer call_data) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360{
2361 XmFileSelectionBoxCallbackStruct *fcb;
2362
2363 if (browse_fname != NULL)
2364 {
2365 XtFree(browse_fname);
2366 browse_fname = NULL;
2367 }
2368 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2369
2370 /* get the filename from the file selection box */
2371 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2372
2373 /* popdown the file selection box */
2374 XtUnmanageChild(dialog_wgt);
2375}
2376
2377#endif /* FEAT_BROWSE */
2378
2379#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2380
2381static int dialogStatus;
2382
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383/*
2384 * Callback function for the textfield. When CR is hit this works like
2385 * hitting the "OK" button, ESC like "Cancel".
2386 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002388keyhit_callback(
2389 Widget w,
2390 XtPointer client_data UNUSED,
2391 XEvent *event,
2392 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393{
2394 char buf[2];
2395 KeySym key_sym;
2396
2397 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2398 {
2399 if (*buf == CAR)
2400 dialogStatus = 1;
2401 else if (*buf == ESC)
2402 dialogStatus = 2;
2403 }
2404 if ((key_sym == XK_Left || key_sym == XK_Right)
2405 && !(event->xkey.state & ShiftMask))
2406 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2407}
2408
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002410butproc(
2411 Widget w UNUSED,
2412 XtPointer client_data,
2413 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414{
2415 dialogStatus = (int)(long)client_data + 1;
2416}
2417
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418#ifdef HAVE_XPM
2419
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002421create_pixmap_label(
2422 Widget parent,
2423 String name,
2424 char **data,
2425 ArgList args,
2426 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427{
2428 Widget label;
2429 Display *dsp;
2430 Screen *scr;
2431 int depth;
2432 Pixmap pixmap = 0;
2433 XpmAttributes attr;
2434 Boolean rs;
2435 XpmColorSymbol color[5] =
2436 {
2437 {"none", NULL, 0},
2438 {"iconColor1", NULL, 0},
2439 {"bottomShadowColor", NULL, 0},
2440 {"topShadowColor", NULL, 0},
2441 {"selectColor", NULL, 0}
2442 };
2443
2444 label = XmCreateLabelGadget(parent, name, args, arg);
2445
2446 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002447 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 * no way to get the background color directly from the widget itself.
2449 * In such cases we get it from The Core part of his parent instead.
2450 */
2451 dsp = XtDisplayOfObject(label);
2452 scr = XtScreenOfObject(label);
2453 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2454 ? label : XtParent(label),
2455 XmNdepth, &depth,
2456 XmNbackground, &color[0].pixel,
2457 XmNforeground, &color[1].pixel,
2458 XmNbottomShadowColor, &color[2].pixel,
2459 XmNtopShadowColor, &color[3].pixel,
2460 XmNhighlight, &color[4].pixel,
2461 NULL);
2462
2463 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2464 attr.colorsymbols = color;
2465 attr.numsymbols = 5;
2466 attr.closeness = 65535;
2467 attr.depth = depth;
2468 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2469 data, &pixmap, NULL, &attr);
2470
2471 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2472 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2473 XtVaSetValues(label,
2474 XmNlabelType, XmPIXMAP,
2475 XmNlabelPixmap, pixmap,
2476 NULL);
2477 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2478
2479 return label;
2480}
2481#endif
2482
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002484gui_mch_dialog(
2485 int type UNUSED,
2486 char_u *title,
2487 char_u *message,
2488 char_u *button_names,
2489 int dfltbutton,
2490 char_u *textfield, /* buffer of size IOSIZE */
2491 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492{
2493 char_u *buts;
2494 char_u *p, *next;
2495 XtAppContext app;
2496 XmString label;
2497 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002498 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 Widget dialogform = NULL;
2500 Widget form = NULL;
2501 Widget dialogtextfield = NULL;
2502 Widget *buttons;
2503 Widget sep_form = NULL;
2504 Boolean vertical;
2505 Widget separator = NULL;
2506 int n;
2507 Arg args[6];
2508#ifdef HAVE_XPM
2509 char **icon_data = NULL;
2510 Widget dialogpixmap = NULL;
2511#endif
2512
2513 if (title == NULL)
2514 title = (char_u *)_("Vim dialog");
2515
2516 /* if our pointer is currently hidden, then we should show it. */
2517 gui_mch_mousehide(FALSE);
2518
2519 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2520
2521 /* Check 'v' flag in 'guioptions': vertical button placement. */
2522 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2523
2524 /* Set the title of the Dialog window */
2525 label = XmStringCreateSimple((char *)title);
2526 if (label == NULL)
2527 return -1;
2528 XtVaSetValues(dialogform,
2529 XmNdialogTitle, label,
2530 XmNhorizontalSpacing, 4,
2531 XmNverticalSpacing, vertical ? 0 : 4,
2532 NULL);
2533 XmStringFree(label);
2534
2535 /* make a copy, so that we can insert NULs */
2536 buts = vim_strsave(button_names);
2537 if (buts == NULL)
2538 return -1;
2539
2540 /* Count the number of buttons and allocate buttons[]. */
2541 butcount = 1;
2542 for (p = buts; *p; ++p)
2543 if (*p == DLG_BUTTON_SEP)
2544 ++butcount;
2545 buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
2546 if (buttons == NULL)
2547 {
2548 vim_free(buts);
2549 return -1;
2550 }
2551
2552 /*
2553 * Create the buttons.
2554 */
2555 sep_form = (Widget) 0;
2556 p = buts;
2557 for (butcount = 0; *p; ++butcount)
2558 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002559 KeySym mnemonic = NUL;
2560
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 for (next = p; *next; ++next)
2562 {
2563 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002564 {
2565 int len = STRLEN(next);
2566
2567 if (len > 0)
2568 {
2569 mch_memmove(next, next + 1, len);
2570 mnemonic = next[0];
2571 }
2572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 if (*next == DLG_BUTTON_SEP)
2574 {
2575 *next++ = NUL;
2576 break;
2577 }
2578 }
2579 label = XmStringCreate(_((char *)p), STRING_TAG);
2580 if (label == NULL)
2581 break;
2582
2583 buttons[butcount] = XtVaCreateManagedWidget("button",
2584 xmPushButtonWidgetClass, dialogform,
2585 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002586 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 XmNbottomAttachment, XmATTACH_FORM,
2588 XmNbottomOffset, 4,
2589 XmNshowAsDefault, butcount == dfltbutton - 1,
2590 XmNdefaultButtonShadowThickness, 1,
2591 NULL);
2592 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002593 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594
2595 /* Layout properly. */
2596
2597 if (butcount > 0)
2598 {
2599 if (vertical)
2600 XtVaSetValues(buttons[butcount],
2601 XmNtopWidget, buttons[butcount - 1],
2602 NULL);
2603 else
2604 {
2605 if (*next == NUL)
2606 {
2607 XtVaSetValues(buttons[butcount],
2608 XmNrightAttachment, XmATTACH_FORM,
2609 XmNrightOffset, 4,
2610 NULL);
2611
2612 /* fill in a form as invisible separator */
2613 sep_form = XtVaCreateWidget("separatorForm",
2614 xmFormWidgetClass, dialogform,
2615 XmNleftAttachment, XmATTACH_WIDGET,
2616 XmNleftWidget, buttons[butcount - 1],
2617 XmNrightAttachment, XmATTACH_WIDGET,
2618 XmNrightWidget, buttons[butcount],
2619 XmNbottomAttachment, XmATTACH_FORM,
2620 XmNbottomOffset, 4,
2621 NULL);
2622 XtManageChild(sep_form);
2623 }
2624 else
2625 {
2626 XtVaSetValues(buttons[butcount],
2627 XmNleftAttachment, XmATTACH_WIDGET,
2628 XmNleftWidget, buttons[butcount - 1],
2629 NULL);
2630 }
2631 }
2632 }
2633 else if (!vertical)
2634 {
2635 if (*next == NUL)
2636 {
2637 XtVaSetValues(buttons[0],
2638 XmNrightAttachment, XmATTACH_FORM,
2639 XmNrightOffset, 4,
2640 NULL);
2641
2642 /* fill in a form as invisible separator */
2643 sep_form = XtVaCreateWidget("separatorForm",
2644 xmFormWidgetClass, dialogform,
2645 XmNleftAttachment, XmATTACH_FORM,
2646 XmNleftOffset, 4,
2647 XmNrightAttachment, XmATTACH_WIDGET,
2648 XmNrightWidget, buttons[0],
2649 XmNbottomAttachment, XmATTACH_FORM,
2650 XmNbottomOffset, 4,
2651 NULL);
2652 XtManageChild(sep_form);
2653 }
2654 else
2655 XtVaSetValues(buttons[0],
2656 XmNleftAttachment, XmATTACH_FORM,
2657 XmNleftOffset, 4,
2658 NULL);
2659 }
2660
2661 XtAddCallback(buttons[butcount], XmNactivateCallback,
2662 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2663 p = next;
2664 }
2665 vim_free(buts);
2666
2667 separator = (Widget) 0;
2668 if (butcount > 0)
2669 {
2670 /* Create the separator for beauty. */
2671 n = 0;
2672 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2673 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2674 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2675 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2676 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2677 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2678 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2679 XtManageChild(separator);
2680 }
2681
2682 if (textfield != NULL)
2683 {
2684 dialogtextfield = XtVaCreateWidget("textField",
2685 xmTextFieldWidgetClass, dialogform,
2686 XmNleftAttachment, XmATTACH_FORM,
2687 XmNrightAttachment, XmATTACH_FORM,
2688 NULL);
2689 if (butcount > 0)
2690 XtVaSetValues(dialogtextfield,
2691 XmNbottomAttachment, XmATTACH_WIDGET,
2692 XmNbottomWidget, separator,
2693 NULL);
2694 else
2695 XtVaSetValues(dialogtextfield,
2696 XmNbottomAttachment, XmATTACH_FORM,
2697 NULL);
2698
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002699 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2701 XtManageChild(dialogtextfield);
2702 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2703 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2704 }
2705
2706 /* Form holding both message and pixmap labels */
2707 form = XtVaCreateWidget("separatorForm",
2708 xmFormWidgetClass, dialogform,
2709 XmNleftAttachment, XmATTACH_FORM,
2710 XmNrightAttachment, XmATTACH_FORM,
2711 XmNtopAttachment, XmATTACH_FORM,
2712 NULL);
2713 XtManageChild(form);
2714
2715#ifdef HAVE_XPM
2716 /* Add a pixmap, left of the message. */
2717 switch (type)
2718 {
2719 case VIM_GENERIC:
2720 icon_data = generic_xpm;
2721 break;
2722 case VIM_ERROR:
2723 icon_data = error_xpm;
2724 break;
2725 case VIM_WARNING:
2726 icon_data = alert_xpm;
2727 break;
2728 case VIM_INFO:
2729 icon_data = info_xpm;
2730 break;
2731 case VIM_QUESTION:
2732 icon_data = quest_xpm;
2733 break;
2734 default:
2735 icon_data = generic_xpm;
2736 }
2737
2738 n = 0;
2739 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2740 XtSetArg(args[n], XmNtopOffset, 8); n++;
2741 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2742 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2743 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2744 XtSetArg(args[n], XmNleftOffset, 8); n++;
2745
2746 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2747 icon_data, args, n);
2748 XtManageChild(dialogpixmap);
2749#endif
2750
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002751 /* Create the dialog message.
2752 * Since LessTif is apparently having problems with the creation of
2753 * properly localized string, we use LtoR here. The symptom is that the
2754 * string sill not show properly in multiple lines as it does in native
2755 * Motif.
2756 */
2757 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 if (label == NULL)
2759 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002760 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 xmLabelGadgetClass, form,
2762 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002763 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 XmNtopAttachment, XmATTACH_FORM,
2765 XmNtopOffset, 8,
2766#ifdef HAVE_XPM
2767 XmNleftAttachment, XmATTACH_WIDGET,
2768 XmNleftWidget, dialogpixmap,
2769#else
2770 XmNleftAttachment, XmATTACH_FORM,
2771#endif
2772 XmNleftOffset, 8,
2773 XmNrightAttachment, XmATTACH_FORM,
2774 XmNrightOffset, 8,
2775 XmNbottomAttachment, XmATTACH_FORM,
2776 XmNbottomOffset, 8,
2777 NULL);
2778 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002779 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780
2781 if (textfield != NULL)
2782 {
2783 XtVaSetValues(form,
2784 XmNbottomAttachment, XmATTACH_WIDGET,
2785 XmNbottomWidget, dialogtextfield,
2786 NULL);
2787 }
2788 else
2789 {
2790 if (butcount > 0)
2791 XtVaSetValues(form,
2792 XmNbottomAttachment, XmATTACH_WIDGET,
2793 XmNbottomWidget, separator,
2794 NULL);
2795 else
2796 XtVaSetValues(form,
2797 XmNbottomAttachment, XmATTACH_FORM,
2798 NULL);
2799 }
2800
2801 if (dfltbutton < 1)
2802 dfltbutton = 1;
2803 if (dfltbutton > butcount)
2804 dfltbutton = butcount;
2805 XtVaSetValues(dialogform,
2806 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2807 if (textfield != NULL)
2808 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2809 else
2810 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2811 NULL);
2812
2813 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002814 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815
2816 if (textfield != NULL && *textfield != NUL)
2817 {
2818 /* This only works after the textfield has been realised. */
2819 XmTextFieldSetSelection(dialogtextfield,
2820 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2821 XtLastTimestampProcessed(gui.dpy));
2822 XmTextFieldSetCursorPosition(dialogtextfield,
2823 (XmTextPosition)STRLEN(textfield));
2824 }
2825
2826 app = XtWidgetToApplicationContext(dialogform);
2827
2828 /* Loop until a button is pressed or the dialog is killed somehow. */
2829 dialogStatus = -1;
2830 for (;;)
2831 {
2832 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2833 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2834 break;
2835 }
2836
2837 vim_free(buttons);
2838
2839 if (textfield != NULL)
2840 {
2841 p = (char_u *)XmTextGetString(dialogtextfield);
2842 if (p == NULL || dialogStatus < 0)
2843 *textfield = NUL;
2844 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002845 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002846 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 }
2848
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002849 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 XtDestroyWidget(dialogform);
2851
2852 return dialogStatus;
2853}
2854#endif /* FEAT_GUI_DIALOG */
2855
2856#if defined(FEAT_FOOTER) || defined(PROTO)
2857
2858 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002859gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860{
2861 Dimension height; /* total Toolbar height */
2862 Dimension top; /* XmNmarginTop */
2863 Dimension bottom; /* XmNmarginBottom */
2864 Dimension shadow; /* XmNshadowThickness */
2865
2866 XtVaGetValues(footer,
2867 XmNheight, &height,
2868 XmNmarginTop, &top,
2869 XmNmarginBottom, &bottom,
2870 XmNshadowThickness, &shadow,
2871 NULL);
2872
2873 return (int) height + top + bottom + (shadow << 1);
2874}
2875
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002877gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878{
2879 if (showit)
2880 {
2881 gui.footer_height = gui_mch_compute_footer_height();
2882 XtManageChild(footer);
2883 }
2884 else
2885 {
2886 gui.footer_height = 0;
2887 XtUnmanageChild(footer);
2888 }
2889 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2890}
2891
2892 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002893gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894{
2895 XmString xms;
2896
2897 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002898 if (xms != NULL)
2899 {
2900 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2901 XmStringFree(xms);
2902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903}
2904
2905#endif
2906
2907
2908#if defined(FEAT_TOOLBAR) || defined(PROTO)
2909 void
2910gui_mch_show_toolbar(int showit)
2911{
2912 Cardinal numChildren; /* how many children toolBar has */
2913
2914 if (toolBar == (Widget)0)
2915 return;
2916 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2917 if (showit && numChildren > 0)
2918 {
2919 /* Assume that we want to show the toolbar if p_toolbar contains
2920 * valid option settings, therefore p_toolbar must not be NULL.
2921 */
2922 WidgetList children;
2923
2924 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2925 {
2926 void (*action)(BalloonEval *);
2927 int text = 0;
2928
2929 if (strstr((const char *)p_toolbar, "tooltips"))
2930 action = &gui_mch_enable_beval_area;
2931 else
2932 action = &gui_mch_disable_beval_area;
2933 if (strstr((const char *)p_toolbar, "text"))
2934 text = 1;
2935 else if (strstr((const char *)p_toolbar, "icons"))
2936 text = -1;
2937 if (text != 0)
2938 {
2939 vimmenu_T *toolbar;
2940 vimmenu_T *cur;
2941
2942 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
2943 if (menu_is_toolbar(toolbar->dname))
2944 break;
2945 /* Assumption: toolbar is NULL if there is no toolbar,
2946 * otherwise it contains the toolbar menu structure.
2947 *
2948 * Assumption: "numChildren" == the number of items in the list
2949 * of items beginning with toolbar->children.
2950 */
2951 if (toolbar)
2952 {
2953 for (cur = toolbar->children; cur; cur = cur->next)
2954 {
2955 Arg args[1];
2956 int n = 0;
2957
2958 /* Enable/Disable tooltip (OK to enable while
Bram Moolenaarf193fff2006-04-27 00:02:13 +00002959 * currently enabled). */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 if (cur->tip != NULL)
2961 (*action)(cur->tip);
2962 if (!menu_is_separator(cur->name))
2963 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002964 if (text == 1 || cur->xpm == NULL)
2965 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002967 ++n;
2968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 if (cur->id != NULL)
2970 {
2971 XtUnmanageChild(cur->id);
2972 XtSetValues(cur->id, args, n);
2973 XtManageChild(cur->id);
2974 }
2975 }
2976 }
2977 }
2978 }
2979 }
2980 gui.toolbar_height = gui_mch_compute_toolbar_height();
2981 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002982#ifdef FEAT_GUI_TABLINE
2983 if (showing_tabline)
2984 {
2985 XtVaSetValues(tabLine,
2986 XmNtopAttachment, XmATTACH_WIDGET,
2987 XmNtopWidget, XtParent(toolBar),
2988 NULL);
2989 XtVaSetValues(textAreaForm,
2990 XmNtopAttachment, XmATTACH_WIDGET,
2991 XmNtopWidget, tabLine,
2992 NULL);
2993 }
2994 else
2995#endif
2996 XtVaSetValues(textAreaForm,
2997 XmNtopAttachment, XmATTACH_WIDGET,
2998 XmNtopWidget, XtParent(toolBar),
2999 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 if (XtIsManaged(menuBar))
3001 XtVaSetValues(XtParent(toolBar),
3002 XmNtopAttachment, XmATTACH_WIDGET,
3003 XmNtopWidget, menuBar,
3004 NULL);
3005 else
3006 XtVaSetValues(XtParent(toolBar),
3007 XmNtopAttachment, XmATTACH_FORM,
3008 NULL);
3009 }
3010 else
3011 {
3012 gui.toolbar_height = 0;
3013 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003014 {
3015#ifdef FEAT_GUI_TABLINE
3016 if (showing_tabline)
3017 {
3018 XtVaSetValues(tabLine,
3019 XmNtopAttachment, XmATTACH_WIDGET,
3020 XmNtopWidget, menuBar,
3021 NULL);
3022 XtVaSetValues(textAreaForm,
3023 XmNtopAttachment, XmATTACH_WIDGET,
3024 XmNtopWidget, tabLine,
3025 NULL);
3026 }
3027 else
3028#endif
3029 XtVaSetValues(textAreaForm,
3030 XmNtopAttachment, XmATTACH_WIDGET,
3031 XmNtopWidget, menuBar,
3032 NULL);
3033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003035 {
3036#ifdef FEAT_GUI_TABLINE
3037 if (showing_tabline)
3038 {
3039 XtVaSetValues(tabLine,
3040 XmNtopAttachment, XmATTACH_FORM,
3041 NULL);
3042 XtVaSetValues(textAreaForm,
3043 XmNtopAttachment, XmATTACH_WIDGET,
3044 XmNtopWidget, tabLine,
3045 NULL);
3046 }
3047 else
3048#endif
3049 XtVaSetValues(textAreaForm,
3050 XmNtopAttachment, XmATTACH_FORM,
3051 NULL);
3052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053
3054 XtUnmanageChild(XtParent(toolBar));
3055 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003056 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057}
3058
3059/*
3060 * A toolbar button has been pushed; now reset the input focus
3061 * such that the user can type page up/down etc. and have the
3062 * input go to the editor window, not the button
3063 */
3064 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003065reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066{
3067 if (textArea != NULL)
3068 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3069}
3070
3071 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003072gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003074 Dimension borders;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 Dimension height; /* total Toolbar height */
3076 Dimension whgt; /* height of each widget */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 WidgetList children; /* list of toolBar's children */
3078 Cardinal numChildren; /* how many children toolBar has */
3079 int i;
3080
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003081 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3084 { /* get height of XmFrame parent */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003085 Dimension fst;
3086 Dimension fmh;
3087 Dimension tst;
3088 Dimension tmh;
3089
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003091 XmNshadowThickness, &fst,
3092 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003094 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003096 XmNshadowThickness, &tst,
3097 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 XmNchildren, &children,
3099 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003100 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003101 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {
3103 whgt = 0;
3104 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3105 if (height < whgt)
3106 height = whgt;
3107 }
3108 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003109#ifdef LESSTIF_VERSION
3110 /* Hack: When starting up we get wrong dimensions. */
3111 if (height < 10)
3112 height = 24;
3113#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003115 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116}
3117
Bram Moolenaar7c626922005-02-07 22:01:03 +00003118 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003119motif_get_toolbar_colors(
3120 Pixel *bgp,
3121 Pixel *fgp,
3122 Pixel *bsp,
3123 Pixel *tsp,
3124 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003125{
3126 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003127 XmNbackground, bgp,
3128 XmNforeground, fgp,
3129 XmNbottomShadowColor, bsp,
3130 XmNtopShadowColor, tsp,
3131 XmNhighlightColor, hsp,
3132 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003133}
3134
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135# ifdef FEAT_FOOTER
3136/*
3137 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003138 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 * get implemented and the user will have a choice.
3140 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003142toolbarbutton_enter_cb(
3143 Widget w UNUSED,
3144 XtPointer client_data,
3145 XEvent *event UNUSED,
3146 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147{
3148 vimmenu_T *menu = (vimmenu_T *) client_data;
3149
3150 if (menu->strings[MENU_INDEX_TIP] != NULL)
3151 {
3152 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3153 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3154 }
3155}
3156
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003158toolbarbutton_leave_cb(
3159 Widget w UNUSED,
3160 XtPointer client_data UNUSED,
3161 XEvent *event UNUSED,
3162 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163{
3164 gui_mch_set_footer((char_u *) "");
3165}
3166# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167#endif
3168
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003169#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3170/*
3171 * Show or hide the tabline.
3172 */
3173 void
3174gui_mch_show_tabline(int showit)
3175{
3176 if (tabLine == (Widget)0)
3177 return;
3178
3179 if (!showit != !showing_tabline)
3180 {
3181 if (showit)
3182 {
3183 XtManageChild(tabLine);
3184 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003185 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3186 XtUnmanageChild(XtNameToWidget(tabLine,
3187 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003188#ifdef FEAT_MENU
3189# ifdef FEAT_TOOLBAR
3190 if (XtIsManaged(XtParent(toolBar)))
3191 XtVaSetValues(tabLine,
3192 XmNtopAttachment, XmATTACH_WIDGET,
3193 XmNtopWidget, XtParent(toolBar), NULL);
3194 else
3195# endif
3196 if (XtIsManaged(menuBar))
3197 XtVaSetValues(tabLine,
3198 XmNtopAttachment, XmATTACH_WIDGET,
3199 XmNtopWidget, menuBar, NULL);
3200 else
3201#endif
3202 XtVaSetValues(tabLine,
3203 XmNtopAttachment, XmATTACH_FORM, NULL);
3204 XtVaSetValues(textAreaForm,
3205 XmNtopAttachment, XmATTACH_WIDGET,
3206 XmNtopWidget, tabLine,
3207 NULL);
3208 }
3209 else
3210 {
3211 XtUnmanageChild(tabLine);
3212#ifdef FEAT_MENU
3213# ifdef FEAT_TOOLBAR
3214 if (XtIsManaged(XtParent(toolBar)))
3215 XtVaSetValues(textAreaForm,
3216 XmNtopAttachment, XmATTACH_WIDGET,
3217 XmNtopWidget, XtParent(toolBar), NULL);
3218 else
3219# endif
3220 if (XtIsManaged(menuBar))
3221 XtVaSetValues(textAreaForm,
3222 XmNtopAttachment, XmATTACH_WIDGET,
3223 XmNtopWidget, menuBar, NULL);
3224 else
3225#endif
3226 XtVaSetValues(textAreaForm,
3227 XmNtopAttachment, XmATTACH_FORM, NULL);
3228 }
3229 showing_tabline = showit;
3230 }
3231}
3232
3233/*
3234 * Return TRUE when tabline is displayed.
3235 */
3236 int
3237gui_mch_showing_tabline(void)
3238{
3239 return tabLine != (Widget)0 && showing_tabline;
3240}
3241
3242/*
3243 * Update the labels of the tabline.
3244 */
3245 void
3246gui_mch_update_tabline(void)
3247{
3248 tabpage_T *tp;
3249 int nr = 1, n;
3250 Arg args[10];
3251 int curtabidx = 0, currentpage;
3252 Widget tab;
3253 XmNotebookPageInfo page_info;
3254 XmNotebookPageStatus page_status;
3255 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003256 XmString label_str;
3257 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003258 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003259
3260 if (tabLine == (Widget)0)
3261 return;
3262
3263 /* Add a label for each tab page. They all contain the same text area. */
3264 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3265 {
3266 if (tp == curtab)
3267 curtabidx = nr;
3268
3269 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3270 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003271 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003272 {
3273 /* Add the tab */
3274 n = 0;
3275 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3276 XtSetArg(args[n], XmNtraversalOn, False); n++;
3277 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3278 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3279 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3280 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3281 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003282 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3283 NULL);
3284 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003285 }
3286 else
3287 tab = page_info.major_tab_widget;
3288
3289 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003290
3291 /*
3292 * Change the label text only if it is different
3293 */
3294 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3295 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3296 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003297 get_tabline_label(tp, FALSE);
3298 if (STRCMP(label_cstr, NameBuff) != 0)
3299 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003300 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3301 NameBuff, STRLEN(NameBuff) + 1, NULL);
3302 /*
3303 * Force a resize of the tab label button
3304 */
3305 XtUnmanageChild(tab);
3306 XtManageChild(tab);
3307 }
3308 XtFree(label_cstr);
3309 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003310 }
3311
3312 tab_count = nr - 1;
3313
3314 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3315
3316 /* Remove any old labels. */
3317 while (nr <= last_page)
3318 {
3319 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3320 && page_info.page_number == nr
3321 && page_info.major_tab_widget != (Widget)0)
3322 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003323 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3324 if (beval != NULL)
3325 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003326 XtUnmanageChild(page_info.major_tab_widget);
3327 XtDestroyWidget(page_info.major_tab_widget);
3328 }
3329 nr++;
3330 }
3331
3332 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3333
3334 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3335 if (currentpage != curtabidx)
3336 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3337}
3338
3339/*
3340 * Set the current tab to "nr". First tab is 1.
3341 */
3342 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003343gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003344{
3345 int currentpage;
3346
3347 if (tabLine == (Widget)0)
3348 return;
3349
3350 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3351 if (currentpage != nr)
3352 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3353}
3354#endif
3355
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356/*
3357 * Set the colors of Widget "id" to the menu colors.
3358 */
3359 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003360gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361{
3362 if (gui.menu_bg_pixel != INVALCOLOR)
3363#if (XmVersion >= 1002)
3364 XmChangeColor(id, gui.menu_bg_pixel);
3365#else
3366 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3367#endif
3368 if (gui.menu_fg_pixel != INVALCOLOR)
3369 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3370}
3371
3372/*
3373 * Set the colors of Widget "id" to the scrollbar colors.
3374 */
3375 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003376gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377{
3378 if (gui.scroll_bg_pixel != INVALCOLOR)
3379#if (XmVersion >= 1002)
3380 XmChangeColor(id, gui.scroll_bg_pixel);
3381#else
3382 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3383#endif
3384 if (gui.scroll_fg_pixel != INVALCOLOR)
3385 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3386}
3387
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388/*
3389 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3390 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003391 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003392gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003394#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395#ifdef FONTSET_ALWAYS
3396 if (gui.menu_fontset != NOFONTSET)
3397 {
3398 XmFontList fl;
3399
3400 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3401 if (fl != NULL)
3402 {
3403 if (XtIsManaged(id))
3404 {
3405 XtUnmanageChild(id);
3406 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01003407 /* We should force the widget to recalculate its
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 * geometry now. */
3409 XtManageChild(id);
3410 }
3411 else
3412 XtVaSetValues(id, XmNfontList, fl, NULL);
3413 XmFontListFree(fl);
3414 }
3415 }
3416#else
3417 if (gui.menu_font != NOFONT)
3418 {
3419 XmFontList fl;
3420
3421 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3422 if (fl != NULL)
3423 {
3424 if (XtIsManaged(id))
3425 {
3426 XtUnmanageChild(id);
3427 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01003428 /* We should force the widget to recalculate its
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 * geometry now. */
3430 XtManageChild(id);
3431 }
3432 else
3433 XtVaSetValues(id, XmNfontList, fl, NULL);
3434 XmFontListFree(fl);
3435 }
3436 }
3437#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439}
3440
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441
3442/*
3443 * We don't create it twice for the sake of speed.
3444 */
3445
3446typedef struct _SharedFindReplace
3447{
3448 Widget dialog; /* the main dialog widget */
3449 Widget wword; /* 'Exact match' check button */
3450 Widget mcase; /* 'match case' check button */
3451 Widget up; /* search direction 'Up' radio button */
3452 Widget down; /* search direction 'Down' radio button */
3453 Widget what; /* 'Find what' entry text widget */
3454 Widget with; /* 'Replace with' entry text widget */
3455 Widget find; /* 'Find Next' action button */
3456 Widget replace; /* 'Replace With' action button */
3457 Widget all; /* 'Replace All' action button */
3458 Widget undo; /* 'Undo' action button */
3459
3460 Widget cancel;
3461} SharedFindReplace;
3462
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003463static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3464static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003467find_replace_destroy_callback(
3468 Widget w UNUSED,
3469 XtPointer client_data,
3470 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471{
3472 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3473
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003474 if (cd != NULL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003475 /* suppress_dialog_mnemonics(cd->dialog); */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 cd->dialog = (Widget)0;
3477}
3478
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003480find_replace_dismiss_callback(
3481 Widget w UNUSED,
3482 XtPointer client_data,
3483 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484{
3485 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3486
3487 if (cd != NULL)
3488 XtUnmanageChild(cd->dialog);
3489}
3490
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003492entry_activate_callback(
3493 Widget w UNUSED,
3494 XtPointer client_data,
3495 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496{
3497 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3498}
3499
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003501find_replace_callback(
3502 Widget w UNUSED,
3503 XtPointer client_data,
3504 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505{
3506 long_u flags = (long_u)client_data;
3507 char *find_text, *repl_text;
3508 Boolean direction_down = TRUE;
3509 Boolean wword;
3510 Boolean mcase;
3511 SharedFindReplace *sfr;
3512
3513 if (flags == FRD_UNDO)
3514 {
3515 char_u *save_cpo = p_cpo;
3516
3517 /* No need to be Vi compatible here. */
3518 p_cpo = (char_u *)"";
3519 u_undo(1);
3520 p_cpo = save_cpo;
3521 gui_update_screen();
3522 return;
3523 }
3524
3525 /* Get the search/replace strings from the dialog */
3526 if (flags == FRD_FINDNEXT)
3527 {
3528 repl_text = NULL;
3529 sfr = &find_widgets;
3530 }
3531 else
3532 {
3533 repl_text = XmTextFieldGetString(repl_widgets.with);
3534 sfr = &repl_widgets;
3535 }
3536 find_text = XmTextFieldGetString(sfr->what);
3537 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3538 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3539 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3540 if (wword)
3541 flags |= FRD_WHOLE_WORD;
3542 if (mcase)
3543 flags |= FRD_MATCH_CASE;
3544
3545 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3546 direction_down);
3547
3548 if (find_text != NULL)
3549 XtFree(find_text);
3550 if (repl_text != NULL)
3551 XtFree(repl_text);
3552}
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003555find_replace_keypress(
3556 Widget w UNUSED,
3557 SharedFindReplace *frdp,
3558 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559{
3560 KeySym keysym;
3561
3562 if (frdp == NULL)
3563 return;
3564
3565 keysym = XLookupKeysym(event, 0);
3566
3567 /* the scape key pops the whole dialog down */
3568 if (keysym == XK_Escape)
3569 XtUnmanageChild(frdp->dialog);
3570}
3571
3572 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003573set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003574{
3575 XmString str;
3576 char_u *p, *next;
3577 KeySym mnemonic = NUL;
3578
3579 if (!w)
3580 return;
3581
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003582 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003583 if (p == NULL)
3584 return;
3585 for (next = p; *next; ++next)
3586 {
3587 if (*next == DLG_HOTKEY_CHAR)
3588 {
3589 int len = STRLEN(next);
3590
3591 if (len > 0)
3592 {
3593 mch_memmove(next, next + 1, len);
3594 mnemonic = next[0];
3595 }
3596 }
3597 }
3598
3599 str = XmStringCreateSimple((char *)p);
3600 vim_free(p);
3601 if (str)
3602 {
3603 XtVaSetValues(w,
3604 XmNlabelString, str,
3605 XmNmnemonic, mnemonic,
3606 NULL);
3607 XmStringFree(str);
3608 }
3609 gui_motif_menu_fontlist(w);
3610}
3611
3612 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003613find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614{
3615 SharedFindReplace *frdp;
3616 Widget separator;
3617 Widget input_form;
3618 Widget button_form;
3619 Widget toggle_form;
3620 Widget frame;
3621 XmString str;
3622 int n;
3623 Arg args[6];
3624 int wword = FALSE;
3625 int mcase = !p_ic;
3626 Dimension width;
3627 Dimension widest;
3628 char_u *entry_text;
3629
3630 frdp = do_replace ? &repl_widgets : &find_widgets;
3631
3632 /* Get the search string to use. */
3633 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3634
3635 /* If the dialog already exists, just raise it. */
3636 if (frdp->dialog)
3637 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003638 gui_motif_synch_fonts();
3639
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 /* If the window is already up, just pop it to the top */
3641 if (XtIsManaged(frdp->dialog))
3642 XMapRaised(XtDisplay(frdp->dialog),
3643 XtWindow(XtParent(frdp->dialog)));
3644 else
3645 XtManageChild(frdp->dialog);
3646 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3647 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3648
3649 if (entry_text != NULL)
3650 XmTextFieldSetString(frdp->what, (char *)entry_text);
3651 vim_free(entry_text);
3652
3653 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3654 return;
3655 }
3656
3657 /* Create a fresh new dialog window */
3658 if (do_replace)
3659 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3660 else
3661 str = XmStringCreateSimple(_("VIM - Search..."));
3662
3663 n = 0;
3664 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3665 XtSetArg(args[n], XmNnoResize, True); n++;
3666 XtSetArg(args[n], XmNdialogTitle, str); n++;
3667
3668 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3669 XmStringFree(str);
3670 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3671 find_replace_destroy_callback, frdp);
3672
3673 button_form = XtVaCreateWidget("buttonForm",
3674 xmFormWidgetClass, frdp->dialog,
3675 XmNrightAttachment, XmATTACH_FORM,
3676 XmNrightOffset, 4,
3677 XmNtopAttachment, XmATTACH_FORM,
3678 XmNtopOffset, 4,
3679 XmNbottomAttachment, XmATTACH_FORM,
3680 XmNbottomOffset, 4,
3681 NULL);
3682
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 frdp->find = XtVaCreateManagedWidget("findButton",
3684 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 XmNsensitive, True,
3686 XmNtopAttachment, XmATTACH_FORM,
3687 XmNleftAttachment, XmATTACH_FORM,
3688 XmNrightAttachment, XmATTACH_FORM,
3689 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003690 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691
3692 XtAddCallback(frdp->find, XmNactivateCallback,
3693 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003694 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695
3696 if (do_replace)
3697 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3699 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 XmNtopAttachment, XmATTACH_WIDGET,
3701 XmNtopWidget, frdp->find,
3702 XmNleftAttachment, XmATTACH_FORM,
3703 XmNrightAttachment, XmATTACH_FORM,
3704 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003705 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 XtAddCallback(frdp->replace, XmNactivateCallback,
3707 find_replace_callback, (XtPointer)FRD_REPLACE);
3708
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3710 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 XmNtopAttachment, XmATTACH_WIDGET,
3712 XmNtopWidget, frdp->replace,
3713 XmNleftAttachment, XmATTACH_FORM,
3714 XmNrightAttachment, XmATTACH_FORM,
3715 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003716 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 XtAddCallback(frdp->all, XmNactivateCallback,
3718 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3719
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 frdp->undo = XtVaCreateManagedWidget("undoButton",
3721 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 XmNtopAttachment, XmATTACH_WIDGET,
3723 XmNtopWidget, frdp->all,
3724 XmNleftAttachment, XmATTACH_FORM,
3725 XmNrightAttachment, XmATTACH_FORM,
3726 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003727 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 XtAddCallback(frdp->undo, XmNactivateCallback,
3729 find_replace_callback, (XtPointer)FRD_UNDO);
3730 }
3731
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3733 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 XmNleftAttachment, XmATTACH_FORM,
3735 XmNrightAttachment, XmATTACH_FORM,
3736 XmNbottomAttachment, XmATTACH_FORM,
3737 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003738 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 XtAddCallback(frdp->cancel, XmNactivateCallback,
3740 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003741 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742
3743 XtManageChild(button_form);
3744
3745 n = 0;
3746 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3747 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3748 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3749 XtSetArg(args[n], XmNrightOffset, 4); n++;
3750 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3751 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3752 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3753 XtManageChild(separator);
3754
3755 input_form = XtVaCreateWidget("inputForm",
3756 xmFormWidgetClass, frdp->dialog,
3757 XmNleftAttachment, XmATTACH_FORM,
3758 XmNleftOffset, 4,
3759 XmNrightAttachment, XmATTACH_WIDGET,
3760 XmNrightWidget, separator,
3761 XmNrightOffset, 4,
3762 XmNtopAttachment, XmATTACH_FORM,
3763 XmNtopOffset, 4,
3764 NULL);
3765
3766 {
3767 Widget label_what;
3768 Widget label_with = (Widget)0;
3769
3770 str = XmStringCreateSimple(_("Find what:"));
3771 label_what = XtVaCreateManagedWidget("whatLabel",
3772 xmLabelGadgetClass, input_form,
3773 XmNlabelString, str,
3774 XmNleftAttachment, XmATTACH_FORM,
3775 XmNtopAttachment, XmATTACH_FORM,
3776 XmNtopOffset, 4,
3777 NULL);
3778 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003779 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780
3781 frdp->what = XtVaCreateManagedWidget("whatText",
3782 xmTextFieldWidgetClass, input_form,
3783 XmNtopAttachment, XmATTACH_FORM,
3784 XmNrightAttachment, XmATTACH_FORM,
3785 XmNleftAttachment, XmATTACH_FORM,
3786 NULL);
3787
3788 if (do_replace)
3789 {
3790 frdp->with = XtVaCreateManagedWidget("withText",
3791 xmTextFieldWidgetClass, input_form,
3792 XmNtopAttachment, XmATTACH_WIDGET,
3793 XmNtopWidget, frdp->what,
3794 XmNtopOffset, 4,
3795 XmNleftAttachment, XmATTACH_FORM,
3796 XmNrightAttachment, XmATTACH_FORM,
3797 XmNbottomAttachment, XmATTACH_FORM,
3798 NULL);
3799
3800 XtAddCallback(frdp->with, XmNactivateCallback,
3801 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3802
3803 str = XmStringCreateSimple(_("Replace with:"));
3804 label_with = XtVaCreateManagedWidget("withLabel",
3805 xmLabelGadgetClass, input_form,
3806 XmNlabelString, str,
3807 XmNleftAttachment, XmATTACH_FORM,
3808 XmNtopAttachment, XmATTACH_WIDGET,
3809 XmNtopWidget, frdp->what,
3810 XmNtopOffset, 4,
3811 XmNbottomAttachment, XmATTACH_FORM,
3812 NULL);
3813 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003814 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815
3816 /*
3817 * Make the entry activation only change the input focus onto the
3818 * with item.
3819 */
3820 XtAddCallback(frdp->what, XmNactivateCallback,
3821 entry_activate_callback, frdp->with);
3822 XtAddEventHandler(frdp->with, KeyPressMask, False,
3823 (XtEventHandler)find_replace_keypress,
3824 (XtPointer) frdp);
3825
3826 }
3827 else
3828 {
3829 /*
3830 * Make the entry activation do the search.
3831 */
3832 XtAddCallback(frdp->what, XmNactivateCallback,
3833 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3834 }
3835 XtAddEventHandler(frdp->what, KeyPressMask, False,
3836 (XtEventHandler)find_replace_keypress,
3837 (XtPointer)frdp);
3838
3839 /* Get the maximum width between the label widgets and line them up.
3840 */
3841 n = 0;
3842 XtSetArg(args[n], XmNwidth, &width); n++;
3843 XtGetValues(label_what, args, n);
3844 widest = width;
3845 if (do_replace)
3846 {
3847 XtGetValues(label_with, args, n);
3848 if (width > widest)
3849 widest = width;
3850 }
3851
3852 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3853 if (do_replace)
3854 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3855
3856 }
3857
3858 XtManageChild(input_form);
3859
3860 {
3861 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003862 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863
3864 frame = XtVaCreateWidget("directionFrame",
3865 xmFrameWidgetClass, frdp->dialog,
3866 XmNtopAttachment, XmATTACH_WIDGET,
3867 XmNtopWidget, input_form,
3868 XmNtopOffset, 4,
3869 XmNbottomAttachment, XmATTACH_FORM,
3870 XmNbottomOffset, 4,
3871 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3872 XmNrightWidget, input_form,
3873 NULL);
3874
3875 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003876 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 xmLabelGadgetClass, frame,
3878 XmNlabelString, str,
3879 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3880 XmNchildType, XmFRAME_TITLE_CHILD,
3881 NULL);
3882 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003883 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884
3885 radio_box = XmCreateRadioBox(frame, "radioBox",
3886 (ArgList)NULL, 0);
3887
3888 str = XmStringCreateSimple( _("Up"));
3889 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3890 xmToggleButtonGadgetClass, radio_box,
3891 XmNlabelString, str,
3892 XmNset, False,
3893 NULL);
3894 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003895 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896
3897 str = XmStringCreateSimple(_("Down"));
3898 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3899 xmToggleButtonGadgetClass, radio_box,
3900 XmNlabelString, str,
3901 XmNset, True,
3902 NULL);
3903 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003904 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905
3906 XtManageChild(radio_box);
3907 XtManageChild(frame);
3908 }
3909
3910 toggle_form = XtVaCreateWidget("toggleForm",
3911 xmFormWidgetClass, frdp->dialog,
3912 XmNleftAttachment, XmATTACH_FORM,
3913 XmNleftOffset, 4,
3914 XmNrightAttachment, XmATTACH_WIDGET,
3915 XmNrightWidget, frame,
3916 XmNrightOffset, 4,
3917 XmNtopAttachment, XmATTACH_WIDGET,
3918 XmNtopWidget, input_form,
3919 XmNtopOffset, 4,
3920 XmNbottomAttachment, XmATTACH_FORM,
3921 XmNbottomOffset, 4,
3922 NULL);
3923
3924 str = XmStringCreateSimple(_("Match whole word only"));
3925 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3926 xmToggleButtonGadgetClass, toggle_form,
3927 XmNlabelString, str,
3928 XmNtopAttachment, XmATTACH_FORM,
3929 XmNtopOffset, 4,
3930 XmNleftAttachment, XmATTACH_FORM,
3931 XmNleftOffset, 4,
3932 XmNset, wword,
3933 NULL);
3934 XmStringFree(str);
3935
3936 str = XmStringCreateSimple(_("Match case"));
3937 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3938 xmToggleButtonGadgetClass, toggle_form,
3939 XmNlabelString, str,
3940 XmNleftAttachment, XmATTACH_FORM,
3941 XmNleftOffset, 4,
3942 XmNtopAttachment, XmATTACH_WIDGET,
3943 XmNtopWidget, frdp->wword,
3944 XmNtopOffset, 4,
3945 XmNset, mcase,
3946 NULL);
3947 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003948 gui_motif_menu_fontlist(frdp->wword);
3949 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950
3951 XtManageChild(toggle_form);
3952
3953 if (entry_text != NULL)
3954 XmTextFieldSetString(frdp->what, (char *)entry_text);
3955 vim_free(entry_text);
3956
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003957 gui_motif_synch_fonts();
3958
3959 manage_centered(frdp->dialog);
3960 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3962}
3963
3964 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003965gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966{
3967 if (!gui.in_use)
3968 return;
3969
3970 find_replace_dialog_create(eap->arg, FALSE);
3971}
3972
3973
3974 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003975gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976{
3977 if (!gui.in_use)
3978 return;
3979
3980 find_replace_dialog_create(eap->arg, TRUE);
3981}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003982
3983/*
3984 * Synchronize all gui elements, which are dependant upon the
3985 * main text font used. Those are in esp. the find/replace dialogs.
3986 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003987 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003988 */
3989 void
3990gui_motif_synch_fonts(void)
3991{
3992 SharedFindReplace *frdp;
3993 int do_replace;
3994 XFontStruct *font;
3995 XmFontList font_list;
3996
3997 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3998 * we just give up here on font synchronization. */
3999 font = (XFontStruct *)gui.norm_font;
4000 if (font == NULL)
4001 return;
4002
4003 font_list = gui_motif_create_fontlist(font);
4004
4005 /* OK this loop is a bit tricky... */
4006 for (do_replace = 0; do_replace <= 1; ++do_replace)
4007 {
4008 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4009 if (frdp->dialog)
4010 {
4011 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4012 if (do_replace)
4013 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4014 }
4015 }
4016
4017 XmFontListFree(font_list);
4018}