blob: 57d50b0eed5a6e653ddd58222b38fea2bb56eb1a [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI/Motif support by Robert Webb
5 *
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
9 */
10
Bram Moolenaarf7506ca2017-02-25 16:01:49 +010011#include "vim.h"
12
Bram Moolenaar071d4272004-06-13 20:20:40 +000013#include <Xm/Form.h>
14#include <Xm/RowColumn.h>
15#include <Xm/PushB.h>
16#include <Xm/Text.h>
17#include <Xm/TextF.h>
18#include <Xm/Separator.h>
19#include <Xm/Label.h>
20#include <Xm/CascadeB.h>
21#include <Xm/ScrollBar.h>
22#include <Xm/MenuShell.h>
23#include <Xm/DrawingA.h>
24#if (XmVersion >= 1002)
25# include <Xm/RepType.h>
26#endif
27#include <Xm/Frame.h>
28#include <Xm/LabelG.h>
29#include <Xm/ToggleBG.h>
30#include <Xm/SeparatoG.h>
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000031#include <Xm/XmP.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33#include <X11/keysym.h>
34#include <X11/Xatom.h>
35#include <X11/StringDefs.h>
36#include <X11/Intrinsic.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#ifdef HAVE_X11_XPM_H
Bram Moolenaar88c86eb2019-01-17 17:13:30 +010038# if defined(VMS)
39# include <xpm.h>
40# else
41# include <X11/xpm.h>
42# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#else
44# ifdef HAVE_XM_XPMP_H
45# include <Xm/XpmP.h>
46# endif
47#endif
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000048#ifdef HAVE_XM_NOTEBOOK_H
49# include <Xm/Notebook.h>
50#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaar734a8672019-12-02 22:49:38 +010052#include "gui_xmebw.h" // for our Enhanced Button Widget
Bram Moolenaarb7fcef52005-01-02 11:31:05 +000053
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
55# include "../pixmaps/alert.xpm"
56# include "../pixmaps/error.xpm"
57# include "../pixmaps/generic.xpm"
58# include "../pixmaps/info.xpm"
59# include "../pixmaps/quest.xpm"
60#endif
61
62#define MOTIF_POPUP
63
64extern Widget vimShell;
65
66static Widget vimForm;
67static Widget textAreaForm;
68Widget textArea;
69#ifdef FEAT_TOOLBAR
70static Widget toolBarFrame;
71static Widget toolBar;
72#endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +000073#ifdef FEAT_GUI_TABLINE
74static Widget tabLine;
75static Widget tabLine_menu = 0;
76static int showing_tabline = 0;
77#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000078#ifdef FEAT_FOOTER
79static Widget footer;
80#endif
81#ifdef FEAT_MENU
82# if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +010083// remember the last set value for the tearoff item
Bram Moolenaar071d4272004-06-13 20:20:40 +000084static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
85# endif
86static Widget menuBar;
87#endif
88
Bram Moolenaar071d4272004-06-13 20:20:40 +000089#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000090# ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +010091static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
92static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000093# endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +010094static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
Bram Moolenaard25c16e2016-01-29 22:13:30 +010097static void gui_motif_menu_colors(Widget id);
98static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100#if (XmVersion >= 1002)
101# define STRING_TAG XmFONTLIST_DEFAULT_TAG
102#else
103# define STRING_TAG XmSTRING_DEFAULT_CHARSET
104#endif
105
106/*
107 * Call-back routines.
108 */
109
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110 static void
Bram Moolenaarc1ab6762016-01-30 19:45:49 +0100111scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112{
113 scrollbar_T *sb;
114 long value;
115 int dragging;
116
117 sb = gui_find_scrollbar((long)client_data);
118
119 value = ((XmScrollBarCallbackStruct *)call_data)->value;
120 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
121 (int)XmCR_DRAG);
122 gui_drag_scrollbar(sb, value, dragging);
123}
124
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000125#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000126 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100127tabline_cb(
128 Widget w UNUSED,
129 XtPointer client_data UNUSED,
130 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000131{
132 XmNotebookCallbackStruct *nptr;
133
134 nptr = (XmNotebookCallbackStruct *)call_data;
135 if (nptr->reason != (int)XmCR_NONE)
136 send_tabline_event(nptr->page_number);
137}
138
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000139 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100140tabline_button_cb(
141 Widget w,
142 XtPointer client_data UNUSED,
143 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000144{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000145 int cmd, tab_idx;
146
147 XtVaGetValues(w, XmNuserData, &cmd, NULL);
148 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
149
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000150 send_tabline_menu_event(tab_idx, cmd);
151}
152
153/*
154 * Tabline single mouse click timeout handler
155 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000156 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100157motif_tabline_timer_cb (
158 XtPointer timed_out,
159 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000160{
161 *((int *)timed_out) = TRUE;
162}
163
164/*
165 * check if the tabline tab scroller is clicked
166 */
167 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100168tabline_scroller_clicked(
169 char *scroller_name,
170 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000171{
172 Widget tab_scroll_w;
173 Position pos_x, pos_y;
174 Dimension width, height;
175
176 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
177 if (tab_scroll_w != (Widget)0) {
178 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
179 &width, XmNheight, &height, NULL);
180 if (pos_x >= 0) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100181 // Tab scroller (next) is visible
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000182 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
183 (event->y >= pos_y) && (event->y <= pos_y + height)) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100184 // Clicked on the scroller
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000185 return TRUE;
186 }
187 }
188 }
189 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000190}
191
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000192 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100193tabline_menu_cb(
194 Widget w,
195 XtPointer closure UNUSED,
196 XEvent *e,
197 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000198{
199 Widget tab_w;
200 XButtonPressedEvent *event;
201 int tab_idx = 0;
202 WidgetList children;
203 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000204 static XtIntervalId timer = (XtIntervalId)0;
205 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000206
207 event = (XButtonPressedEvent *)e;
208
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000209 if (event->button == Button1)
210 {
211 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
212 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
213 return;
214
215 if (!timed_out)
216 {
217 XtRemoveTimeOut(timer);
218 timed_out = TRUE;
219
220 /*
221 * Double click on the tabline gutter, add a new tab
222 */
223 send_tabline_menu_event(0, TABLINE_MENU_NEW);
224 }
225 else
226 {
227 /*
228 * Single click on the tabline gutter, start a timer to check
229 * for double clicks
230 */
231 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
232 motif_tabline_timer_cb, &timed_out);
233 timed_out = FALSE;
234 }
235 return;
236 }
237
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000238 if (event->button != Button3)
239 return;
240
Bram Moolenaar734a8672019-12-02 22:49:38 +0100241 // When ignoring events don't show the menu.
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000242 if (hold_gui_events
243# ifdef FEAT_CMDWIN
244 || cmdwin_type != 0
245# endif
246 )
247 return;
248
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000249 if (event->subwindow != None)
250 {
251 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaar734a8672019-12-02 22:49:38 +0100252 // LINTED: avoid warning: dubious operation on enum
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000253 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
254 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
255 }
256
257 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
258 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
259 &numChildren, NULL);
260 XtManageChildren(children, numChildren);
261 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
262 XtManageChild(tabLine_menu);
263}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000264
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000265 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100266tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000267{
268 int nr;
269 tabpage_T *tp;
270
271 if (beval->target == (Widget)0)
272 return;
273
274 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
275 tp = find_tabpage(nr);
276 if (tp == NULL)
277 return;
278
279 get_tabline_label(tp, TRUE);
280 gui_mch_post_balloon(beval, NameBuff);
281}
282
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000283#endif
284
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285/*
286 * End of call-back routines
287 */
288
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289/*
290 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000291 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000292 */
293
294#include <Xm/XmP.h>
295#include <Xm/LabelP.h>
296
297static XtExposeProc old_label_expose = NULL;
298
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000299 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100300label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000301{
302 GC insensitiveGC;
303 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000304 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000305
306 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
307
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000308 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000309 (*old_label_expose)(_w, _event, _region);
310 else
311 {
312 XGCValues values;
313 XtGCMask mask;
314 XtGCMask dynamic;
315 XFontStruct *fs;
316
317 _XmFontListGetDefaultFont(lw->label.font, &fs);
318
Bram Moolenaar734a8672019-12-02 22:49:38 +0100319 // FIXME: we should be doing the whole drawing ourself here.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000320 insensitiveGC = lw->label.insensitive_GC;
321
322 mask = GCForeground | GCBackground | GCGraphicsExposures;
323 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
324 values.graphics_exposures = False;
325
326 if (fs != 0)
327 {
328 mask |= GCFont;
329 values.font = fs->fid;
330 }
331
332 if (lw->primitive.top_shadow_pixmap != None
333 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
334 {
335 mask |= GCFillStyle | GCTile;
336 values.fill_style = FillTiled;
337 values.tile = lw->primitive.top_shadow_pixmap;
338 }
339
340 lw->label.TextRect.x += 1;
341 lw->label.TextRect.y += 1;
342 if (lw->label._acc_text != 0)
343 {
344 lw->label.acc_TextRect.x += 1;
345 lw->label.acc_TextRect.y += 1;
346 }
347
348 values.foreground = lw->primitive.top_shadow_color;
349 values.background = lw->core.background_pixel;
350
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000351 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
352 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000353 (*old_label_expose)(_w, _event, _region);
354 XtReleaseGC(_w, lw->label.insensitive_GC);
355
356 lw->label.TextRect.x -= 1;
357 lw->label.TextRect.y -= 1;
358 if (lw->label._acc_text != 0)
359 {
360 lw->label.acc_TextRect.x -= 1;
361 lw->label.acc_TextRect.y -= 1;
362 }
363
364 values.foreground = lw->primitive.bottom_shadow_color;
365 values.background = lw->core.background_pixel;
366
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000367 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
368 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000369 (*old_label_expose)(_w, _event, _region);
370 XtReleaseGC(_w, lw->label.insensitive_GC);
371
372 lw->label.insensitive_GC = insensitiveGC;
373 }
374}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000375
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376/*
377 * Create all the motif widgets necessary.
378 */
379 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100380gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000382#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000383 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000384 Arg args[10];
385 int n;
386 XmString xms;
387#endif
388
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000389 /*
390 * Install the 3D shade effect drawing routines.
391 */
392 if (old_label_expose == NULL)
393 {
394 old_label_expose = xmLabelWidgetClass->core_class.expose;
395 xmLabelWidgetClass->core_class.expose = label_expose;
396 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000397
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 /*
399 * Start out by adding the configured border width into the border offset
400 */
401 gui.border_offset = gui.border_width;
402
403 /*
404 * Install the tearOffModel resource converter.
405 */
406#if (XmVersion >= 1002)
407 XmRepTypeInstallTearOffModelConverter();
408#endif
409
Bram Moolenaar734a8672019-12-02 22:49:38 +0100410 // Make sure the "Quit" menu entry of the window manager is ignored
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
412
413 vimForm = XtVaCreateManagedWidget("vimForm",
414 xmFormWidgetClass, vimShell,
415 XmNborderWidth, 0,
416 XmNhighlightThickness, 0,
417 XmNshadowThickness, 0,
418 XmNmarginWidth, 0,
419 XmNmarginHeight, 0,
420 XmNresizePolicy, XmRESIZE_ANY,
421 NULL);
422 gui_motif_menu_colors(vimForm);
423
424#ifdef FEAT_MENU
425 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100426 Arg al[7]; // Make sure there is enough room for arguments!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427 int ac = 0;
428
429# if (XmVersion >= 1002)
430 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
431# endif
432 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
433 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
434 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
435# ifndef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100436 // Always stick to right hand side.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
438# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000439 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
441 XtManageChild(menuBar);
442
Bram Moolenaar734a8672019-12-02 22:49:38 +0100443 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 XtVaGetValues(menuBar,
445 XmNbackground, &gui.menu_def_bg_pixel,
446 XmNforeground, &gui.menu_def_fg_pixel,
447 NULL);
448 gui_motif_menu_colors(menuBar);
449 }
450#endif
451
452#ifdef FEAT_TOOLBAR
453 /*
454 * Create an empty ToolBar. We should get buttons defined from menu.vim.
455 */
456 toolBarFrame = XtVaCreateWidget("toolBarFrame",
457 xmFrameWidgetClass, vimForm,
458 XmNshadowThickness, 0,
459 XmNmarginHeight, 0,
460 XmNmarginWidth, 0,
461 XmNleftAttachment, XmATTACH_FORM,
462 XmNrightAttachment, XmATTACH_FORM,
463 NULL);
464 gui_motif_menu_colors(toolBarFrame);
465
466 toolBar = XtVaCreateManagedWidget("toolBar",
467 xmRowColumnWidgetClass, toolBarFrame,
468 XmNchildType, XmFRAME_WORKAREA_CHILD,
469 XmNrowColumnType, XmWORK_AREA,
470 XmNorientation, XmHORIZONTAL,
471 XmNtraversalOn, False,
472 XmNisHomogeneous, False,
473 XmNpacking, XmPACK_TIGHT,
474 XmNspacing, 0,
475 XmNshadowThickness, 0,
476 XmNhighlightThickness, 0,
477 XmNmarginHeight, 0,
478 XmNmarginWidth, 0,
479 XmNadjustLast, True,
480 NULL);
481 gui_motif_menu_colors(toolBar);
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483#endif
484
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000485#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100486 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000487 n = 0;
488 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
489 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
490 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
491 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
492 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
493 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
494 XtSetArg(args[n], XmNshadowThickness, 0); n++;
495 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
496 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
497 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
498
499 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
500 NULL);
501 XtAddEventHandler(tabLine, ButtonPressMask, False,
502 (XtEventHandler)tabline_menu_cb, NULL);
503
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000504 gui.tabline_height = TABLINE_HEIGHT;
505
Bram Moolenaar18144c82006-04-12 21:52:12 +0000506 /*
507 * Set the size of the minor next/prev scrollers to zero, so
508 * that they are not displayed. Due to a bug in OpenMotif 2.3,
509 * even if these children widget are unmanaged, they are again
510 * managed by the Notebook widget and the notebook widget geometry
511 * is adjusted to account for the minor scroller widgets.
512 */
513 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
514 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
515 XmNtraversalOn, False, NULL);
516 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
517 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
518 XmNtraversalOn, False, NULL);
519
Bram Moolenaar29547192018-12-11 20:39:19 +0100520 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000521 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
522
Bram Moolenaar29547192018-12-11 20:39:19 +0100523 // Add the buttons to the tabline popup menu
524 n = 0;
525 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
526 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
527 XtSetArg(args[n], XmNlabelString, xms); n++;
528 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
529 XtAddCallback(button, XmNactivateCallback,
530 (XtCallbackProc)tabline_button_cb, NULL);
531 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000532
533 n = 0;
534 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
535 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
536 XtSetArg(args[n], XmNlabelString, xms); n++;
537 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
538 XtAddCallback(button, XmNactivateCallback,
539 (XtCallbackProc)tabline_button_cb, NULL);
540 XmStringFree(xms);
541
542 n = 0;
543 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
544 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
545 XtSetArg(args[n], XmNlabelString, xms); n++;
546 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
547 XtAddCallback(button, XmNactivateCallback,
548 (XtCallbackProc)tabline_button_cb, NULL);
549 XmStringFree(xms);
550#endif
551
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
553 xmFormWidgetClass, vimForm,
554 XmNleftAttachment, XmATTACH_FORM,
555 XmNrightAttachment, XmATTACH_FORM,
556 XmNbottomAttachment, XmATTACH_FORM,
557 XmNtopAttachment, XmATTACH_FORM,
558 XmNmarginWidth, 0,
559 XmNmarginHeight, 0,
560 XmNresizePolicy, XmRESIZE_ANY,
561 NULL);
562 gui_motif_scroll_colors(textAreaForm);
563
564 textArea = XtVaCreateManagedWidget("textArea",
565 xmDrawingAreaWidgetClass, textAreaForm,
566 XmNforeground, gui.norm_pixel,
567 XmNbackground, gui.back_pixel,
568 XmNleftAttachment, XmATTACH_FORM,
569 XmNtopAttachment, XmATTACH_FORM,
570 XmNrightAttachment, XmATTACH_FORM,
571 XmNbottomAttachment, XmATTACH_FORM,
572
573 /*
574 * These take some control away from the user, but avoids making them
575 * add resources to get a decent looking setup.
576 */
577 XmNborderWidth, 0,
578 XmNhighlightThickness, 0,
579 XmNshadowThickness, 0,
580 NULL);
581
582#ifdef FEAT_FOOTER
583 /*
584 * Create the Footer.
585 */
586 footer = XtVaCreateWidget("footer",
587 xmLabelGadgetClass, vimForm,
588 XmNalignment, XmALIGNMENT_BEGINNING,
589 XmNmarginHeight, 0,
590 XmNmarginWidth, 0,
591 XmNtraversalOn, False,
592 XmNrecomputeSize, False,
593 XmNleftAttachment, XmATTACH_FORM,
594 XmNleftOffset, 5,
595 XmNrightAttachment, XmATTACH_FORM,
596 XmNbottomAttachment, XmATTACH_FORM,
597 NULL);
598 gui_mch_set_footer((char_u *) "");
599#endif
600
601 /*
602 * Install the callbacks.
603 */
604 gui_x11_callbacks(textArea, vimForm);
605
Bram Moolenaar734a8672019-12-02 22:49:38 +0100606 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 gui.in_focus = FALSE;
608}
609
610/*
611 * Called when the GUI is not going to start after all.
612 */
613 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100614gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615{
616 textArea = NULL;
617#ifdef FEAT_MENU
618 menuBar = NULL;
619#endif
620}
621
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100623gui_mch_set_text_area_pos(
624 int x UNUSED,
625 int y UNUSED,
626 int w UNUSED,
627 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628{
629#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100630 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000631 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
633}
634
635 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100636gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637{
638 if (textArea != NULL)
639#if (XmVersion >= 1002)
640 XmChangeColor(textArea, gui.back_pixel);
641#else
642 XtVaSetValues(textArea,
643 XmNbackground, gui.back_pixel,
644 NULL);
645#endif
646}
647
648/*
649 * Manage dialog centered on pointer. This could be used by the Athena code as
650 * well.
651 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000652 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100653manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654{
655 Widget shell = XtParent(dialog_child);
656 Window root, child;
657 unsigned int mask;
658 unsigned int width, height, border_width, depth;
659 int x, y, win_x, win_y, maxX, maxY;
660 Boolean mappedWhenManaged;
661
Bram Moolenaar734a8672019-12-02 22:49:38 +0100662 // Temporarily set value of XmNmappedWhenManaged
663 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000664 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
665 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666
667 XtManageChild(dialog_child);
668
Bram Moolenaar734a8672019-12-02 22:49:38 +0100669 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
671 &x, &y, &win_x, &win_y, &mask);
672
Bram Moolenaar734a8672019-12-02 22:49:38 +0100673 // Translate the pointer position (x, y) into a position for the new
674 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
676 &width, &height, &border_width, &depth);
677 width += 2 * border_width;
678 height += 2 * border_width;
679 x -= width / 2;
680 y -= height / 2;
681
Bram Moolenaar734a8672019-12-02 22:49:38 +0100682 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 maxX = XtScreen(shell)->width - width;
684 maxY = XtScreen(shell)->height - height;
685 if (x < 0)
686 x = 0;
687 if (x > maxX)
688 x = maxX;
689 if (y < 0)
690 y = 0;
691 if (y > maxY)
692 y = maxY;
693
Bram Moolenaar734a8672019-12-02 22:49:38 +0100694 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
696
Bram Moolenaar734a8672019-12-02 22:49:38 +0100697 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 XtMapWidget(shell);
699
Bram Moolenaar734a8672019-12-02 22:49:38 +0100700 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000701 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702}
703
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100704#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705
706/*
707 * Encapsulate the way an XmFontList is created.
708 */
709 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100710gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711{
712 XmFontList font_list;
713
714# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100715 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 font_list = XmFontListCreate(font, STRING_TAG);
717# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100718 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 XmFontListEntry font_list_entry;
720
721 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
722 (XtPointer)font);
723 font_list = XmFontListAppendEntry(NULL, font_list_entry);
724 XmFontListEntryFree(&font_list_entry);
725# endif
726 return font_list;
727}
728
729# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
730 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100731gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732{
733 XmFontList font_list;
734
Bram Moolenaar734a8672019-12-02 22:49:38 +0100735 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 XmFontListEntry font_list_entry;
737
738 font_list_entry = XmFontListEntryCreate(STRING_TAG,
739 XmFONT_IS_FONTSET,
740 (XtPointer)*fontset);
741 font_list = XmFontListAppendEntry(NULL, font_list_entry);
742 XmFontListEntryFree(&font_list_entry);
743 return font_list;
744}
745# endif
746
747#endif
748
749#if defined(FEAT_MENU) || defined(PROTO)
750/*
751 * Menu stuff.
752 */
753
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100754static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100756static void toggle_tearoff(Widget wid);
757static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100759static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100761static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762static int menu_enabled = TRUE;
763
764 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100765gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766{
767 if (flag)
768 {
769 XtManageChild(menuBar);
770#ifdef FEAT_TOOLBAR
771 if (XtIsManaged(XtParent(toolBar)))
772 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100773 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 XtVaSetValues(XtParent(toolBar),
775 XmNtopAttachment, XmATTACH_WIDGET,
776 XmNtopWidget, menuBar,
777 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000778#ifdef FEAT_GUI_TABLINE
779 if (showing_tabline)
780 {
781 XtVaSetValues(tabLine,
782 XmNtopAttachment, XmATTACH_WIDGET,
783 XmNtopWidget, XtParent(toolBar),
784 NULL);
785 XtVaSetValues(textAreaForm,
786 XmNtopAttachment, XmATTACH_WIDGET,
787 XmNtopWidget, tabLine,
788 NULL);
789 }
790 else
791#endif
792 XtVaSetValues(textAreaForm,
793 XmNtopAttachment, XmATTACH_WIDGET,
794 XmNtopWidget, XtParent(toolBar),
795 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 }
797 else
798#endif
799 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000800#ifdef FEAT_GUI_TABLINE
801 if (showing_tabline)
802 {
803 XtVaSetValues(tabLine,
804 XmNtopAttachment, XmATTACH_WIDGET,
805 XmNtopWidget, menuBar,
806 NULL);
807 XtVaSetValues(textAreaForm,
808 XmNtopAttachment, XmATTACH_WIDGET,
809 XmNtopWidget, tabLine,
810 NULL);
811 }
812 else
813#endif
814 XtVaSetValues(textAreaForm,
815 XmNtopAttachment, XmATTACH_WIDGET,
816 XmNtopWidget, menuBar,
817 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 }
819 }
820 else
821 {
822 XtUnmanageChild(menuBar);
823#ifdef FEAT_TOOLBAR
824 if (XtIsManaged(XtParent(toolBar)))
825 {
826 XtVaSetValues(XtParent(toolBar),
827 XmNtopAttachment, XmATTACH_FORM,
828 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000829#ifdef FEAT_GUI_TABLINE
830 if (showing_tabline)
831 {
832 XtVaSetValues(tabLine,
833 XmNtopAttachment, XmATTACH_WIDGET,
834 XmNtopWidget, XtParent(toolBar),
835 NULL);
836 XtVaSetValues(textAreaForm,
837 XmNtopAttachment, XmATTACH_WIDGET,
838 XmNtopWidget, tabLine,
839 NULL);
840 }
841 else
842#endif
843 XtVaSetValues(textAreaForm,
844 XmNtopAttachment, XmATTACH_WIDGET,
845 XmNtopWidget, XtParent(toolBar),
846 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 }
848 else
849#endif
850 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000851#ifdef FEAT_GUI_TABLINE
852 if (showing_tabline)
853 {
854 XtVaSetValues(tabLine,
855 XmNtopAttachment, XmATTACH_FORM,
856 NULL);
857 XtVaSetValues(textAreaForm,
858 XmNtopAttachment, XmATTACH_WIDGET,
859 XmNtopWidget, tabLine,
860 NULL);
861 }
862 else
863#endif
864 XtVaSetValues(textAreaForm,
865 XmNtopAttachment, XmATTACH_FORM,
866 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 }
868 }
869
870}
871
872/*
873 * Enable or disable mnemonics for the toplevel menus.
874 */
875 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100876gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000877{
878 /*
879 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
880 * crashes when using a mnemonic then.
881 */
882 if (!menu_enabled)
883 enable = FALSE;
884 do_set_mnemonics(enable);
885}
886
887 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100888do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889{
890 vimmenu_T *menu;
891
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200892 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 if (menu->id != (Widget)0)
894 XtVaSetValues(menu->id,
895 XmNmnemonic, enable ? menu->mnemonic : NUL,
896 NULL);
897}
898
899 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100900gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901{
902 XmString label;
903 Widget shell;
904 vimmenu_T *parent = menu->parent;
905
906#ifdef MOTIF_POPUP
907 if (menu_is_popup(menu->name))
908 {
909 Arg arg[2];
910 int n = 0;
911
Bram Moolenaar734a8672019-12-02 22:49:38 +0100912 // Only create the popup menu when it's actually used, otherwise there
913 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914# if (XmVersion <= 1002)
915 if (mouse_model_popup())
916# endif
917 {
918 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200919 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200923 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
927 arg, n);
928 menu->id = (Widget)0;
929 }
930 return;
931 }
932#endif
933
934 if (!menu_is_menubar(menu->name)
935 || (parent != NULL && parent->submenu_id == (Widget)0))
936 return;
937
938 label = XmStringCreate((char *)menu->dname, STRING_TAG);
939 if (label == NULL)
940 return;
941 menu->id = XtVaCreateWidget("subMenu",
942 xmCascadeButtonWidgetClass,
943 (parent == NULL) ? menuBar : parent->submenu_id,
944 XmNlabelString, label,
945 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
946#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100947 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 XmNpositionIndex, idx + (parent != NULL
949 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
950#endif
951 NULL);
952 gui_motif_menu_colors(menu->id);
953 gui_motif_menu_fontlist(menu->id);
954 XmStringFree(label);
955
Bram Moolenaar734a8672019-12-02 22:49:38 +0100956 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 return;
958
Bram Moolenaar734a8672019-12-02 22:49:38 +0100959 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 gui_motif_add_actext(menu);
961
962 shell = XtVaCreateWidget("subMenuShell",
963 xmMenuShellWidgetClass, menu->id,
964 XmNwidth, 1,
965 XmNheight, 1,
966 NULL);
967 gui_motif_menu_colors(shell);
968 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
969 xmRowColumnWidgetClass, shell,
970 XmNrowColumnType, XmMENU_PULLDOWN,
971 NULL);
972 gui_motif_menu_colors(menu->submenu_id);
973
Bram Moolenaar734a8672019-12-02 22:49:38 +0100974 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 return;
976
977#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100978 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 toggle_tearoff(menu->submenu_id);
980#endif
981
982 XtVaSetValues(menu->id,
983 XmNsubMenuId, menu->submenu_id,
984 NULL);
985
986 /*
987 * The "Help" menu is a special case, and should be placed at the far
988 * right hand side of the menu-bar. It's recognized by its high priority.
989 */
990 if (parent == NULL && menu->priority >= 9999)
991 XtVaSetValues(menuBar,
992 XmNmenuHelpWidget, menu->id,
993 NULL);
994
995 /*
996 * When we add a top-level item to the menu bar, we can figure out how
997 * high the menu bar should be.
998 */
999 if (parent == NULL)
1000 gui_mch_compute_menu_height(menu->id);
1001}
1002
1003
1004/*
1005 * Add mnemonic and accelerator text to a menu button.
1006 */
1007 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001008gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009{
1010 XmString label;
1011
Bram Moolenaar734a8672019-12-02 22:49:38 +01001012 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 if (menu->actext != NULL && menu->id != (Widget)0)
1014 {
1015 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1016 if (label == NULL)
1017 return;
1018 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1019 XmStringFree(label);
1020 }
1021}
1022
1023 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001024gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025{
1026#if (XmVersion >= 1002)
1027 if (enable)
1028 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1029 else
1030 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1031 toggle_tearoff(menuBar);
1032 gui_mch_recurse_tearoffs(root_menu);
1033#endif
1034}
1035
1036#if (XmVersion >= 1002)
1037/*
1038 * Set the tearoff for one menu widget on or off, and set the color of the
1039 * tearoff widget.
1040 */
1041 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001042toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043{
1044 Widget w;
1045
1046 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1047 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1048 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1049 gui_motif_menu_colors(w);
1050}
1051
1052 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001053gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054{
1055 while (menu != NULL)
1056 {
1057 if (!menu_is_popup(menu->name))
1058 {
1059 if (menu->submenu_id != (Widget)0)
1060 toggle_tearoff(menu->submenu_id);
1061 gui_mch_recurse_tearoffs(menu->children);
1062 }
1063 menu = menu->next;
1064 }
1065}
1066#endif
1067
1068 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001069gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070{
1071 Dimension shadowHeight;
1072
1073 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1074 return shadowHeight;
1075}
1076
1077/*
1078 * Compute the height of the menu bar.
1079 * We need to check all the items for their position and height, for the case
1080 * there are several rows, and/or some characters extend higher or lower.
1081 */
1082 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001083gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001084 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085{
1086 Dimension y, maxy;
1087 Dimension margin, shadow;
1088 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001089 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090
1091 /*
1092 * Get the height of the new item, before managing it, because it will
1093 * still reflect the font size. After managing it depends on the menu
1094 * height, which is what we just wanted to get!.
1095 */
1096 if (id != (Widget)0)
1097 XtVaGetValues(id, XmNheight, &height, NULL);
1098
Bram Moolenaar734a8672019-12-02 22:49:38 +01001099 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001101 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1103 {
1104 id = mp->id;
1105 break;
1106 }
1107
1108 /*
1109 * Now manage the menu item, to make them all be positioned (makes an
1110 * extra row when needed, removes it when not needed).
1111 */
1112 if (id != (Widget)0)
1113 XtManageChild(id);
1114
1115 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001116 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 */
1118 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001119 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {
1121 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1122 {
1123 XtVaGetValues(mp->id, XmNy, &y, NULL);
1124 if (y > maxy)
1125 maxy = y;
1126 }
1127 }
1128
1129 XtVaGetValues(menuBar,
1130 XmNmarginHeight, &margin,
1131 XmNshadowThickness, &shadow,
1132 NULL);
1133
1134 /*
1135 * This computation is the result of trial-and-error:
1136 * maxy = The maximum position of an item; required for when there are
1137 * two or more rows
1138 * height = height of an item, before managing it; Hopefully this will
1139 * change with the font height. Includes shadow-border.
1140 * shadow = shadow-border; must be subtracted from the height.
1141 * margin = margin around the menu buttons; Must be added.
1142 * Add 4 for the underlining of shortcut keys.
1143 */
1144 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1145
Bram Moolenaar734a8672019-12-02 22:49:38 +01001146 // Somehow the menu bar doesn't resize automatically. Set it here,
1147 // even though this is a catch 22. Don't do this when starting up,
1148 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 if (gui.shell_created)
1150 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001151}
1152
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001153#ifdef FEAT_TOOLBAR
1154
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001155/*
1156 * Icons used by the toolbar code.
1157 */
1158#include "gui_x11_pm.h"
1159
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001160static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001161
1162/*
1163 * Read an Xpm file. Return OK or FAIL.
1164 */
1165 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001166check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001167{
1168 XpmAttributes attrs;
1169 int status;
1170 Pixmap mask;
1171 Pixmap map;
1172
1173 attrs.valuemask = 0;
1174
Bram Moolenaar734a8672019-12-02 22:49:38 +01001175 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001176 status = XpmReadFileToPixmap(gui.dpy,
1177 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1178 (char *)path, &map, &mask, &attrs);
1179 XpmFreeAttributes(&attrs);
1180
1181 if (status == XpmSuccess)
1182 return OK;
1183 return FAIL;
1184}
1185
1186
1187/*
1188 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001189 * When it's to be read from a file, "fname" is set to the file name
1190 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001191 * Return a blank pixmap if it fails.
1192 */
1193 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001194get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001195{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001196 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1197 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001198 int res;
1199
Bram Moolenaar7c626922005-02-07 22:01:03 +00001200 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001201 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001202
1203 if (menu->iconfile != NULL)
1204 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001205 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001206 gui_find_iconfile(menu->iconfile, buf, "xpm");
1207 res = check_xpm(buf);
1208
Bram Moolenaar734a8672019-12-02 22:49:38 +01001209 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001210 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1211 res = check_xpm(buf);
1212 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001213 {
1214 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001215 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001216 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001217 }
1218
1219 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1220 {
1221 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001222 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001223 xpm = built_in_pixmaps[menu->iconidx];
1224 else
1225 xpm = tb_blank_xpm;
1226 }
1227
1228 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001230
1231/*
1232 * Add arguments for the toolbar pixmap to a menu item.
1233 */
1234 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001235add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001236{
1237 vim_free(menu->xpm_fname);
1238 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1239 if (menu->xpm == NULL)
1240 {
1241 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1242 }
1243 else
1244 {
Bram Moolenaarfd615a32020-05-16 14:01:51 +02001245# if 0 // DISABLED - this causes a crash when running "make test_gui" in
1246 // Test_colorscheme()
Bram Moolenaar7c626922005-02-07 22:01:03 +00001247 if (menu->xpm_fname != NULL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001248 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaarfd615a32020-05-16 14:01:51 +02001249# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00001250 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1251 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1252 }
1253 return n;
1254}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001255#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256
1257 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001258gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259{
1260 XmString label;
1261 vimmenu_T *parent = menu->parent;
1262
1263# ifdef EBCDIC
1264 menu->mnemonic = 0;
1265# endif
1266
1267# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001268 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1270 return;
1271# endif
1272
1273# ifdef FEAT_TOOLBAR
1274 if (menu_is_toolbar(parent->name))
1275 {
1276 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001277 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278 int n;
1279 Arg args[18];
1280
1281 n = 0;
1282 if (menu_is_separator(menu->name))
1283 {
1284 char *cp;
1285 Dimension wid;
1286
1287 /*
1288 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1289 * a width specifier. If no width is specified then we choose one.
1290 */
1291 cp = (char *)vim_strchr(menu->name, ':');
1292 if (cp != NULL)
1293 wid = (Dimension)atoi(++cp);
1294 else
1295 wid = 4;
1296
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297 type = xmSeparatorWidgetClass;
1298 XtSetArg(args[n], XmNwidth, wid); n++;
1299 XtSetArg(args[n], XmNminWidth, wid); n++;
1300 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001301 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 }
1303 else
1304 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001305 // Without shadows one can't sense whatever the button has been
1306 // pressed or not! However we want to save a bit of space...
1307 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001308 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1310 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1311 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001312 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001313 // Set the label here, so that we can switch between icons/text
1314 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001315 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1316 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001317
Bram Moolenaar7c626922005-02-07 22:01:03 +00001318 n = add_pixmap_args(menu, args, n);
1319
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001320 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 }
1322
1323 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1324 if (menu->id == NULL)
1325 {
1326 menu->id = XtCreateManagedWidget((char *)menu->dname,
1327 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001328 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 {
1330 XtAddCallback(menu->id,
1331 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332# ifdef FEAT_FOOTER
1333 XtAddEventHandler(menu->id, EnterWindowMask, False,
1334 toolbarbutton_enter_cb, menu);
1335 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1336 toolbarbutton_leave_cb, menu);
1337# endif
1338 }
1339 }
1340 else
1341 XtSetValues(menu->id, args, n);
1342 if (xms != NULL)
1343 XmStringFree(xms);
1344
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001345# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001347# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348
1349 menu->parent = parent;
1350 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001351 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 if (!XtIsManaged(XtParent(toolBar))
1353 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1354 gui_mch_show_toolbar(TRUE);
1355 gui.toolbar_height = gui_mch_compute_toolbar_height();
1356 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001357 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358# endif
1359
Bram Moolenaar734a8672019-12-02 22:49:38 +01001360 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 if (parent->submenu_id == (Widget)0)
1362 return;
1363
1364 menu->submenu_id = (Widget)0;
1365
Bram Moolenaar734a8672019-12-02 22:49:38 +01001366 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 if (menu_is_separator(menu->name))
1368 {
1369 menu->id = XtVaCreateWidget("subMenu",
1370 xmSeparatorGadgetClass, parent->submenu_id,
1371#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001372 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1374 ? 1 : 0),
1375#endif
1376 NULL);
1377 gui_motif_menu_colors(menu->id);
1378 return;
1379 }
1380
1381 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1382 if (label == NULL)
1383 return;
1384 menu->id = XtVaCreateWidget("subMenu",
1385 xmPushButtonWidgetClass, parent->submenu_id,
1386 XmNlabelString, label,
1387 XmNmnemonic, menu->mnemonic,
1388#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001389 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1391 ? 1 : 0),
1392#endif
1393 NULL);
1394 gui_motif_menu_colors(menu->id);
1395 gui_motif_menu_fontlist(menu->id);
1396 XmStringFree(label);
1397
1398 if (menu->id != (Widget)0)
1399 {
1400 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1401 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001402 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 gui_motif_add_actext(menu);
1404 }
1405}
1406
1407#if (XmVersion <= 1002) || defined(PROTO)
1408/*
1409 * This function will destroy/create the popup menus dynamically,
1410 * according to the value of 'mousemodel'.
1411 * This will fix the "right mouse button freeze" that occurs when
1412 * there exists a popup menu but it isn't managed.
1413 */
1414 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001415gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416{
1417 int idx = 0;
1418
Bram Moolenaar734a8672019-12-02 22:49:38 +01001419 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 if (!gui.in_use)
1421 return;
1422
1423 while (menu)
1424 {
1425 if (menu->children != NULL)
1426 {
1427 if (menu_is_popup(menu->name))
1428 {
1429 if (mouse_model_popup())
1430 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001431 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 gui_mch_add_menu(menu, idx);
1433 gui_motif_update_mousemodel(menu->children);
1434 }
1435 else
1436 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001437 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 gui_motif_update_mousemodel(menu->children);
1439 gui_mch_destroy_menu(menu);
1440 }
1441 }
1442 }
1443 else if (menu_is_child_of_popup(menu))
1444 {
1445 if (mouse_model_popup())
1446 gui_mch_add_menu_item(menu, idx);
1447 else
1448 gui_mch_destroy_menu(menu);
1449 }
1450 menu = menu->next;
1451 ++idx;
1452 }
1453}
1454#endif
1455
1456 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001457gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458{
1459 if (menuBar == (Widget)0)
1460 return;
1461 gui_motif_menu_colors(menuBar);
1462#ifdef FEAT_TOOLBAR
1463 gui_motif_menu_colors(toolBarFrame);
1464 gui_motif_menu_colors(toolBar);
1465#endif
1466
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001467 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468}
1469
1470 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001471gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472{
1473 if (menuBar == (Widget)0)
1474 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001475 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {
1477 Dimension height;
1478 Position w, h;
1479
1480 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1481 gui.menu_height = height;
1482
1483 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1484 gui_resize_shell(w, h
1485#ifdef FEAT_XIM
1486 - xim_get_status_area_height()
1487#endif
1488 );
1489 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001490 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 ui_new_shellsize();
1492}
1493
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001494#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001496gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497{
1498# ifdef FEAT_TOOLBAR
1499 vimmenu_T *menu;
1500
1501 if (toolBar == (Widget)0)
1502 return;
1503
1504 menu = gui_find_menu((char_u *)"ToolBar");
1505 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001506 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507# endif
1508}
1509
1510 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001511gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512{
1513# ifdef FEAT_TOOLBAR
1514 vimmenu_T *toolbar;
1515
1516 if (toolBar == (Widget)0)
1517 return;
1518
1519 toolbar = gui_find_menu((char_u *)"ToolBar");
1520 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001521 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522# endif
1523}
1524#endif
1525
1526 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001527submenu_change(
1528 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001529 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530{
1531 vimmenu_T *mp;
1532
1533 for (mp = menu; mp != NULL; mp = mp->next)
1534 {
1535 if (mp->id != (Widget)0)
1536 {
1537 if (colors)
1538 {
1539 gui_motif_menu_colors(mp->id);
1540#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001541 // For a toolbar item: Free the pixmap and allocate a new one,
1542 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001543 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001545 int n = 0;
1546 Arg args[18];
1547
Bram Moolenaar7c626922005-02-07 22:01:03 +00001548 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001549 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001551# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001552 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 if (mp->tip != NULL)
1554 {
1555 Arg args[2];
1556
1557 args[0].name = XmNbackground;
1558 args[0].value = gui.tooltip_bg_pixel;
1559 args[1].name = XmNforeground;
1560 args[1].value = gui.tooltip_fg_pixel;
1561 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1562 }
1563# endif
1564#endif
1565 }
1566 else
1567 {
1568 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001569#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001570 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 if (mp->tip != NULL)
1572 {
1573 Arg args[1];
1574
1575 args[0].name = XmNfontList;
1576 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1577 &gui.tooltip_fontset);
1578 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1579 }
1580#endif
1581 }
1582 }
1583
1584 if (mp->children != NULL)
1585 {
1586#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001587 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 if (mp->submenu_id != (Widget)0)
1589 {
1590 if (colors)
1591 gui_motif_menu_colors(mp->submenu_id);
1592 else
1593 gui_motif_menu_fontlist(mp->submenu_id);
1594 toggle_tearoff(mp->submenu_id);
1595 }
1596#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001597 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001598 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 }
1600 }
1601}
1602
1603/*
1604 * Destroy the machine specific menu widget.
1605 */
1606 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001607gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001608{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001609 // Please be sure to destroy the parent widget first (i.e. menu->id).
1610 // On the other hand, problems have been reported that the submenu must be
1611 // deleted first...
1612 //
1613 // This code should be basically identical to that in the file gui_athena.c
1614 // because they are both Xt based.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 if (menu->submenu_id != (Widget)0)
1616 {
1617 XtDestroyWidget(menu->submenu_id);
1618 menu->submenu_id = (Widget)0;
1619 }
1620
1621 if (menu->id != (Widget)0)
1622 {
1623 Widget parent;
1624
1625 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001626#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001627 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001629 // We try to destroy this before the actual menu, because there are
1630 // callbacks, etc. that will be unregistered during the tooltip
1631 // destruction.
1632 //
1633 // If you call "gui_mch_destroy_beval_area()" after destroying
1634 // menu->id, then the tooltip's window will have already been
1635 // deallocated by Xt, and unknown behaviour will ensue (probably
1636 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 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
Bram Moolenaar734a8672019-12-02 22:49:38 +01001650 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 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
Bram Moolenaar734a8672019-12-02 22:49:38 +01001670#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671
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 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001680 // Use the values saved when starting up. These should come from the
1681 // window manager or a resources file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 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),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001712 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 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
Bram Moolenaar203ec772020-07-17 20:43:43 +02001750 int
1751gui_mch_get_scrollbar_xpadding(void)
1752{
1753 // TODO: Calculate the padding for adjust scrollbar position when the
1754 // Window is maximized.
1755 return 0;
1756}
1757
1758 int
1759gui_mch_get_scrollbar_ypadding(void)
1760{
1761 // TODO: Calculate the padding for adjust scrollbar position when the
1762 // Window is maximized.
1763 return 0;
1764}
1765
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001767gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768{
1769 Arg args[16];
1770 int n;
1771
1772 if (sb->id != (Widget)0)
1773 {
1774 n = 0;
1775 if (flag)
1776 {
1777 switch (sb->type)
1778 {
1779 case SBAR_LEFT:
1780 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1781 break;
1782
1783 case SBAR_RIGHT:
1784 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1785 break;
1786
1787 case SBAR_BOTTOM:
1788 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1789 break;
1790 }
1791 XtSetValues(textArea, args, n);
1792 XtManageChild(sb->id);
1793 }
1794 else
1795 {
1796 if (!gui.which_scrollbars[sb->type])
1797 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001798 // The scrollbars of this type are all disabled, adjust the
1799 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 switch (sb->type)
1801 {
1802 case SBAR_LEFT:
1803 XtSetArg(args[n], XmNleftOffset, 0); n++;
1804 break;
1805
1806 case SBAR_RIGHT:
1807 XtSetArg(args[n], XmNrightOffset, 0); n++;
1808 break;
1809
1810 case SBAR_BOTTOM:
1811 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1812 break;
1813 }
1814 XtSetValues(textArea, args, n);
1815 }
1816 XtUnmanageChild(sb->id);
1817 }
1818 }
1819}
1820
1821 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001822gui_mch_create_scrollbar(
1823 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001824 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825{
1826 Arg args[16];
1827 int n;
1828
1829 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 XtSetArg(args[n], XmNminimum, 0); n++;
1831 XtSetArg(args[n], XmNorientation,
1832 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1833
1834 switch (sb->type)
1835 {
1836 case SBAR_LEFT:
1837 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1838 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1839 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1840 break;
1841
1842 case SBAR_RIGHT:
1843 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1844 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1845 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1846 break;
1847
1848 case SBAR_BOTTOM:
1849 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1850 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1851 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1852 break;
1853 }
1854
1855 sb->id = XtCreateWidget("scrollBar",
1856 xmScrollBarWidgetClass, textAreaForm, args, n);
1857
Bram Moolenaar734a8672019-12-02 22:49:38 +01001858 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1860 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1861 XtVaGetValues(sb->id,
1862 XmNbackground, &gui.scroll_def_bg_pixel,
1863 XmNforeground, &gui.scroll_def_fg_pixel,
1864 NULL);
1865
1866 if (sb->id != (Widget)0)
1867 {
1868 gui_mch_set_scrollbar_colors(sb);
1869 XtAddCallback(sb->id, XmNvalueChangedCallback,
1870 scroll_cb, (XtPointer)sb->ident);
1871 XtAddCallback(sb->id, XmNdragCallback,
1872 scroll_cb, (XtPointer)sb->ident);
1873 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1874 (XtPointer)0);
1875 }
1876}
1877
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001879gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880{
1881 if (sb->id != (Widget)0)
1882 XtDestroyWidget(sb->id);
1883}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884
1885 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001886gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887{
1888 if (sb->id != (Widget)0)
1889 {
1890 if (gui.scroll_bg_pixel != INVALCOLOR)
1891 {
1892#if (XmVersion>=1002)
1893 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1894#else
1895 XtVaSetValues(sb->id,
1896 XmNtroughColor, gui.scroll_bg_pixel,
1897 NULL);
1898#endif
1899 }
1900
1901 if (gui.scroll_fg_pixel != INVALCOLOR)
1902 XtVaSetValues(sb->id,
1903 XmNforeground, gui.scroll_fg_pixel,
1904#if (XmVersion<1002)
1905 XmNbackground, gui.scroll_fg_pixel,
1906#endif
1907 NULL);
1908 }
1909
Bram Moolenaar734a8672019-12-02 22:49:38 +01001910 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1912 gui_motif_scroll_colors(textAreaForm);
1913}
1914
1915/*
1916 * Miscellaneous stuff:
1917 */
1918
1919 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001920gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921{
1922 return(XtWindow(textArea));
1923}
1924
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001925/*
1926 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1927 * When one is found, simulate a button press on that widget and give it the
1928 * keyboard focus. If the mnemonic is on a label, look in the userData field
1929 * of the label to see if it points to another widget, and give that the focus.
1930 */
1931 static void
1932do_mnemonic(Widget w, unsigned int keycode)
1933{
1934 WidgetList children;
1935 int numChildren, i;
1936 Boolean isMenu;
1937 KeySym mnemonic = '\0';
1938 char mneString[2];
1939 Widget userData;
1940 unsigned char rowColType;
1941
1942 if (XtIsComposite(w))
1943 {
1944 if (XtClass(w) == xmRowColumnWidgetClass)
1945 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001946 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001947 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1948 }
1949 else
1950 isMenu = False;
1951 if (!isMenu)
1952 {
1953 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001954 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001955 for (i = 0; i < numChildren; i++)
1956 do_mnemonic(children[i], keycode);
1957 }
1958 }
1959 else
1960 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001961 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001962 if (mnemonic != '\0')
1963 {
1964 mneString[0] = mnemonic;
1965 mneString[1] = '\0';
1966 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1967 XStringToKeysym(mneString)) == keycode)
1968 {
1969 if (XtClass(w) == xmLabelWidgetClass
1970 || XtClass(w) == xmLabelGadgetClass)
1971 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001972 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001973 if (userData != NULL && XtIsWidget(userData))
1974 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1975 }
1976 else
1977 {
1978 XKeyPressedEvent keyEvent;
1979
1980 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1981
Bram Moolenaara80faa82020-04-12 19:37:17 +02001982 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001983 keyEvent.type = KeyPress;
1984 keyEvent.serial = 1;
1985 keyEvent.send_event = True;
1986 keyEvent.display = XtDisplay(w);
1987 keyEvent.window = XtWindow(w);
1988 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1989 NULL, 0);
1990 }
1991 }
1992 }
1993 }
1994}
1995
1996/*
1997 * Callback routine for dialog mnemonic processing.
1998 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001999 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002000mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002001{
2002 do_mnemonic(w, event->keycode);
2003}
2004
2005
2006/*
2007 * Search the widget tree under w for widgets with mnemonics. When found, add
2008 * a passive grab to the dialog widget for the mnemonic character, thus
2009 * directing mnemonic events to the dialog widget.
2010 */
2011 static void
2012add_mnemonic_grabs(Widget dialog, Widget w)
2013{
2014 char mneString[2];
2015 WidgetList children;
2016 int numChildren, i;
2017 Boolean isMenu;
2018 KeySym mnemonic = '\0';
2019 unsigned char rowColType;
2020
2021 if (XtIsComposite(w))
2022 {
2023 if (XtClass(w) == xmRowColumnWidgetClass)
2024 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002025 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002026 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2027 }
2028 else
2029 isMenu = False;
2030 if (!isMenu)
2031 {
2032 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002033 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002034 for (i = 0; i < numChildren; i++)
2035 add_mnemonic_grabs(dialog, children[i]);
2036 }
2037 }
2038 else
2039 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002040 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002041 if (mnemonic != '\0')
2042 {
2043 mneString[0] = mnemonic;
2044 mneString[1] = '\0';
2045 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2046 XStringToKeysym(mneString)),
2047 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2048 }
2049 }
2050}
2051
2052/*
2053 * Add a handler for mnemonics in a dialog. Motif itself only handles
2054 * mnemonics in menus. Mnemonics added or changed after this call will be
2055 * ignored.
2056 *
2057 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2058 * the appropriate label and set the XmNuserData resource of the label to the
2059 * widget to get the focus when the mnemonic is typed.
2060 */
2061 static void
2062activate_dialog_mnemonics(Widget dialog)
2063{
2064 if (!dialog)
2065 return;
2066
2067 XtAddEventHandler(dialog, KeyPressMask, False,
2068 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2069 add_mnemonic_grabs(dialog, dialog);
2070}
2071
2072/*
2073 * Removes the event handler and key-grabs for dialog mnemonic handling.
2074 */
2075 static void
2076suppress_dialog_mnemonics(Widget dialog)
2077{
2078 if (!dialog)
2079 return;
2080
2081 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2082 XtRemoveEventHandler(dialog, KeyPressMask, False,
2083 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2084}
2085
2086#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002087/*
2088 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2089 */
2090 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002091set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002092{
2093 XmFontList fl;
2094
2095#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002096 if (gui.fontset != NOFONTSET)
2097 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002098 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2099 if (fl != NULL)
2100 {
2101 if (XtIsManaged(id))
2102 {
2103 XtUnmanageChild(id);
2104 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002105 // We should force the widget to recalculate its
2106 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002107 XtManageChild(id);
2108 }
2109 else
2110 XtVaSetValues(id, XmNfontList, fl, NULL);
2111 XmFontListFree(fl);
2112 }
2113 }
2114#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002115 if (gui.norm_font != NOFONT)
2116 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002117 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2118 if (fl != NULL)
2119 {
2120 if (XtIsManaged(id))
2121 {
2122 XtUnmanageChild(id);
2123 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002124 // We should force the widget to recalculate its
2125 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002126 XtManageChild(id);
2127 }
2128 else
2129 XtVaSetValues(id, XmNfontList, fl, NULL);
2130 XmFontListFree(fl);
2131 }
2132 }
2133#endif
2134}
2135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136
2137#if defined(FEAT_BROWSE) || defined(PROTO)
2138
2139/*
2140 * file selector related stuff
2141 */
2142
2143#include <Xm/FileSB.h>
2144#include <Xm/XmStrDefs.h>
2145
2146typedef struct dialog_callback_arg
2147{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002148 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 int id;
2150} dcbarg_T;
2151
2152static Widget dialog_wgt;
2153static char *browse_fname = NULL;
2154static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002155 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002157static void DialogCancelCB(Widget, XtPointer, XtPointer);
2158static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159
2160/*
2161 * This function is used to translate the predefined label text of the
2162 * precomposed dialogs. We do this explicitly to allow:
2163 *
2164 * - usage of gettext for translation, as in all the other places.
2165 *
2166 * - equalize the messages between different GUI implementations as far as
2167 * possible.
2168 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002169 static void
2170set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002172 XmString str;
2173 Widget w;
2174 char_u *p, *next;
2175 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176
2177 w = XtNameToWidget(parent, name);
2178
2179 if (!w)
2180 return;
2181
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002182 p = vim_strsave((char_u *)new_label);
2183 if (p == NULL)
2184 return;
2185 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002187 if (*next == DLG_HOTKEY_CHAR)
2188 {
2189 int len = STRLEN(next);
2190
2191 if (len > 0)
2192 {
2193 mch_memmove(next, next + 1, len);
2194 mnemonic = next[0];
2195 }
2196 }
2197 }
2198
2199 str = XmStringCreate((char *)p, STRING_TAG);
2200 vim_free(p);
2201
2202 if (str != NULL)
2203 {
2204 XtVaSetValues(w,
2205 XmNlabelString, str,
2206 XmNmnemonic, mnemonic,
2207 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 XmStringFree(str);
2209 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002210 gui_motif_menu_fontlist(w);
2211}
2212
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002213 static void
2214set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002215{
2216 Widget w;
2217 w = XtNameToWidget(parent, name);
2218
2219 if (!w)
2220 return;
2221
2222 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223}
2224
2225/*
2226 * Put up a file requester.
2227 * Returns the selected name in allocated memory, or NULL for Cancel.
2228 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002230gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002231 int saving UNUSED, // select file to write
2232 char_u *title, // title for the window
2233 char_u *dflt, // default name
2234 char_u *ext UNUSED, // not used (extension added)
2235 char_u *initdir, // initial directory, NULL for current dir
2236 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237{
2238 char_u dirbuf[MAXPATHL];
2239 char_u dfltbuf[MAXPATHL];
2240 char_u *pattern;
2241 char_u *tofree = NULL;
2242
Bram Moolenaar734a8672019-12-02 22:49:38 +01002243 // There a difference between the resource name and value, Therefore, we
2244 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2245 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002246
2247 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248
2249 if (initdir == NULL || *initdir == NUL)
2250 {
2251 mch_dirname(dirbuf, MAXPATHL);
2252 initdir = dirbuf;
2253 }
2254
2255 if (dflt == NULL)
2256 dflt = (char_u *)"";
2257 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2258 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002259 // The default selection should be the full path, "dflt" is only the
2260 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 STRCPY(dfltbuf, initdir);
2262 add_pathsep(dfltbuf);
2263 STRCAT(dfltbuf, dflt);
2264 dflt = dfltbuf;
2265 }
2266
Bram Moolenaar734a8672019-12-02 22:49:38 +01002267 // Can only use one pattern for a file name. Get the first pattern out of
2268 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 if (filter == NULL)
2270 pattern = (char_u *)"";
2271 else
2272 {
2273 char_u *s, *p;
2274
2275 s = filter;
2276 for (p = filter; *p != NUL; ++p)
2277 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002278 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002280 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 break;
2282 }
2283 pattern = vim_strnsave(s, p - s);
2284 tofree = pattern;
2285 if (pattern == NULL)
2286 pattern = (char_u *)"";
2287 }
2288
2289 XtVaSetValues(dialog_wgt,
2290 XtVaTypedArg,
2291 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2292 XtVaTypedArg,
2293 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2294 XtVaTypedArg,
2295 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2296 XtVaTypedArg,
2297 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2298 NULL);
2299
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002300 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2301 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2303 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002304 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002306 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2308
Bram Moolenaar734a8672019-12-02 22:49:38 +01002309 // This is to save us from silly external settings using not fixed with
2310 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002311 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2312 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2313
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 gui_motif_menu_colors(dialog_wgt);
2315 if (gui.scroll_bg_pixel != INVALCOLOR)
2316 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2317
2318 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2319 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002320 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2322 (unsigned char)XmDIALOG_HELP_BUTTON));
2323
2324 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002325 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326
Bram Moolenaar734a8672019-12-02 22:49:38 +01002327 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 do
2329 {
2330 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2331 (XtInputMask)XtIMAll);
2332 } while (XtIsManaged(dialog_wgt));
2333
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002334 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 XtDestroyWidget(dialog_wgt);
2336 vim_free(tofree);
2337
2338 if (browse_fname == NULL)
2339 return NULL;
2340 return vim_strsave((char_u *)browse_fname);
2341}
2342
2343/*
2344 * The code below was originally taken from
2345 * /usr/examples/motif/xmsamplers/xmeditor.c
2346 * on Digital Unix 4.0d, but heavily modified.
2347 */
2348
2349/*
2350 * Process callback from Dialog cancel actions.
2351 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002353DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002354 Widget w UNUSED, // widget id
2355 XtPointer client_data UNUSED, // data from application
2356 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357{
2358 if (browse_fname != NULL)
2359 {
2360 XtFree(browse_fname);
2361 browse_fname = NULL;
2362 }
2363 XtUnmanageChild(dialog_wgt);
2364}
2365
2366/*
2367 * Process callback from Dialog actions.
2368 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002370DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002371 Widget w UNUSED, // widget id
2372 XtPointer client_data UNUSED, // data from application
2373 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374{
2375 XmFileSelectionBoxCallbackStruct *fcb;
2376
2377 if (browse_fname != NULL)
2378 {
2379 XtFree(browse_fname);
2380 browse_fname = NULL;
2381 }
2382 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2383
Bram Moolenaar734a8672019-12-02 22:49:38 +01002384 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2386
Bram Moolenaar734a8672019-12-02 22:49:38 +01002387 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 XtUnmanageChild(dialog_wgt);
2389}
2390
Bram Moolenaar734a8672019-12-02 22:49:38 +01002391#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392
2393#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2394
2395static int dialogStatus;
2396
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397/*
2398 * Callback function for the textfield. When CR is hit this works like
2399 * hitting the "OK" button, ESC like "Cancel".
2400 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002402keyhit_callback(
2403 Widget w,
2404 XtPointer client_data UNUSED,
2405 XEvent *event,
2406 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407{
2408 char buf[2];
2409 KeySym key_sym;
2410
2411 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2412 {
2413 if (*buf == CAR)
2414 dialogStatus = 1;
2415 else if (*buf == ESC)
2416 dialogStatus = 2;
2417 }
2418 if ((key_sym == XK_Left || key_sym == XK_Right)
2419 && !(event->xkey.state & ShiftMask))
2420 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2421}
2422
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002424butproc(
2425 Widget w UNUSED,
2426 XtPointer client_data,
2427 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428{
2429 dialogStatus = (int)(long)client_data + 1;
2430}
2431
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432#ifdef HAVE_XPM
2433
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002435create_pixmap_label(
2436 Widget parent,
2437 String name,
2438 char **data,
2439 ArgList args,
2440 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441{
2442 Widget label;
2443 Display *dsp;
2444 Screen *scr;
2445 int depth;
2446 Pixmap pixmap = 0;
2447 XpmAttributes attr;
2448 Boolean rs;
2449 XpmColorSymbol color[5] =
2450 {
2451 {"none", NULL, 0},
2452 {"iconColor1", NULL, 0},
2453 {"bottomShadowColor", NULL, 0},
2454 {"topShadowColor", NULL, 0},
2455 {"selectColor", NULL, 0}
2456 };
2457
2458 label = XmCreateLabelGadget(parent, name, args, arg);
2459
2460 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002461 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 * no way to get the background color directly from the widget itself.
2463 * In such cases we get it from The Core part of his parent instead.
2464 */
2465 dsp = XtDisplayOfObject(label);
2466 scr = XtScreenOfObject(label);
2467 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2468 ? label : XtParent(label),
2469 XmNdepth, &depth,
2470 XmNbackground, &color[0].pixel,
2471 XmNforeground, &color[1].pixel,
2472 XmNbottomShadowColor, &color[2].pixel,
2473 XmNtopShadowColor, &color[3].pixel,
2474 XmNhighlight, &color[4].pixel,
2475 NULL);
2476
2477 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2478 attr.colorsymbols = color;
2479 attr.numsymbols = 5;
2480 attr.closeness = 65535;
2481 attr.depth = depth;
2482 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2483 data, &pixmap, NULL, &attr);
2484
2485 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2486 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2487 XtVaSetValues(label,
2488 XmNlabelType, XmPIXMAP,
2489 XmNlabelPixmap, pixmap,
2490 NULL);
2491 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2492
2493 return label;
2494}
2495#endif
2496
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002498gui_mch_dialog(
2499 int type UNUSED,
2500 char_u *title,
2501 char_u *message,
2502 char_u *button_names,
2503 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002504 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002505 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506{
2507 char_u *buts;
2508 char_u *p, *next;
2509 XtAppContext app;
2510 XmString label;
2511 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002512 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 Widget dialogform = NULL;
2514 Widget form = NULL;
2515 Widget dialogtextfield = NULL;
2516 Widget *buttons;
2517 Widget sep_form = NULL;
2518 Boolean vertical;
2519 Widget separator = NULL;
2520 int n;
2521 Arg args[6];
2522#ifdef HAVE_XPM
2523 char **icon_data = NULL;
2524 Widget dialogpixmap = NULL;
2525#endif
2526
2527 if (title == NULL)
2528 title = (char_u *)_("Vim dialog");
2529
Bram Moolenaar734a8672019-12-02 22:49:38 +01002530 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 gui_mch_mousehide(FALSE);
2532
2533 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2534
Bram Moolenaar734a8672019-12-02 22:49:38 +01002535 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2537
Bram Moolenaar734a8672019-12-02 22:49:38 +01002538 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 label = XmStringCreateSimple((char *)title);
2540 if (label == NULL)
2541 return -1;
2542 XtVaSetValues(dialogform,
2543 XmNdialogTitle, label,
2544 XmNhorizontalSpacing, 4,
2545 XmNverticalSpacing, vertical ? 0 : 4,
2546 NULL);
2547 XmStringFree(label);
2548
Bram Moolenaar734a8672019-12-02 22:49:38 +01002549 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 buts = vim_strsave(button_names);
2551 if (buts == NULL)
2552 return -1;
2553
Bram Moolenaar734a8672019-12-02 22:49:38 +01002554 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 butcount = 1;
2556 for (p = buts; *p; ++p)
2557 if (*p == DLG_BUTTON_SEP)
2558 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002559 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 if (buttons == NULL)
2561 {
2562 vim_free(buts);
2563 return -1;
2564 }
2565
2566 /*
2567 * Create the buttons.
2568 */
2569 sep_form = (Widget) 0;
2570 p = buts;
2571 for (butcount = 0; *p; ++butcount)
2572 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002573 KeySym mnemonic = NUL;
2574
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 for (next = p; *next; ++next)
2576 {
2577 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002578 {
2579 int len = STRLEN(next);
2580
2581 if (len > 0)
2582 {
2583 mch_memmove(next, next + 1, len);
2584 mnemonic = next[0];
2585 }
2586 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 if (*next == DLG_BUTTON_SEP)
2588 {
2589 *next++ = NUL;
2590 break;
2591 }
2592 }
2593 label = XmStringCreate(_((char *)p), STRING_TAG);
2594 if (label == NULL)
2595 break;
2596
2597 buttons[butcount] = XtVaCreateManagedWidget("button",
2598 xmPushButtonWidgetClass, dialogform,
2599 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002600 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 XmNbottomAttachment, XmATTACH_FORM,
2602 XmNbottomOffset, 4,
2603 XmNshowAsDefault, butcount == dfltbutton - 1,
2604 XmNdefaultButtonShadowThickness, 1,
2605 NULL);
2606 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002607 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608
Bram Moolenaar734a8672019-12-02 22:49:38 +01002609 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610
2611 if (butcount > 0)
2612 {
2613 if (vertical)
2614 XtVaSetValues(buttons[butcount],
2615 XmNtopWidget, buttons[butcount - 1],
2616 NULL);
2617 else
2618 {
2619 if (*next == NUL)
2620 {
2621 XtVaSetValues(buttons[butcount],
2622 XmNrightAttachment, XmATTACH_FORM,
2623 XmNrightOffset, 4,
2624 NULL);
2625
Bram Moolenaar734a8672019-12-02 22:49:38 +01002626 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 sep_form = XtVaCreateWidget("separatorForm",
2628 xmFormWidgetClass, dialogform,
2629 XmNleftAttachment, XmATTACH_WIDGET,
2630 XmNleftWidget, buttons[butcount - 1],
2631 XmNrightAttachment, XmATTACH_WIDGET,
2632 XmNrightWidget, buttons[butcount],
2633 XmNbottomAttachment, XmATTACH_FORM,
2634 XmNbottomOffset, 4,
2635 NULL);
2636 XtManageChild(sep_form);
2637 }
2638 else
2639 {
2640 XtVaSetValues(buttons[butcount],
2641 XmNleftAttachment, XmATTACH_WIDGET,
2642 XmNleftWidget, buttons[butcount - 1],
2643 NULL);
2644 }
2645 }
2646 }
2647 else if (!vertical)
2648 {
2649 if (*next == NUL)
2650 {
2651 XtVaSetValues(buttons[0],
2652 XmNrightAttachment, XmATTACH_FORM,
2653 XmNrightOffset, 4,
2654 NULL);
2655
Bram Moolenaar734a8672019-12-02 22:49:38 +01002656 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657 sep_form = XtVaCreateWidget("separatorForm",
2658 xmFormWidgetClass, dialogform,
2659 XmNleftAttachment, XmATTACH_FORM,
2660 XmNleftOffset, 4,
2661 XmNrightAttachment, XmATTACH_WIDGET,
2662 XmNrightWidget, buttons[0],
2663 XmNbottomAttachment, XmATTACH_FORM,
2664 XmNbottomOffset, 4,
2665 NULL);
2666 XtManageChild(sep_form);
2667 }
2668 else
2669 XtVaSetValues(buttons[0],
2670 XmNleftAttachment, XmATTACH_FORM,
2671 XmNleftOffset, 4,
2672 NULL);
2673 }
2674
2675 XtAddCallback(buttons[butcount], XmNactivateCallback,
2676 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2677 p = next;
2678 }
2679 vim_free(buts);
2680
2681 separator = (Widget) 0;
2682 if (butcount > 0)
2683 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002684 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 n = 0;
2686 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2687 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2688 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2689 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2690 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2691 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2692 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2693 XtManageChild(separator);
2694 }
2695
2696 if (textfield != NULL)
2697 {
2698 dialogtextfield = XtVaCreateWidget("textField",
2699 xmTextFieldWidgetClass, dialogform,
2700 XmNleftAttachment, XmATTACH_FORM,
2701 XmNrightAttachment, XmATTACH_FORM,
2702 NULL);
2703 if (butcount > 0)
2704 XtVaSetValues(dialogtextfield,
2705 XmNbottomAttachment, XmATTACH_WIDGET,
2706 XmNbottomWidget, separator,
2707 NULL);
2708 else
2709 XtVaSetValues(dialogtextfield,
2710 XmNbottomAttachment, XmATTACH_FORM,
2711 NULL);
2712
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002713 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2715 XtManageChild(dialogtextfield);
2716 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2717 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2718 }
2719
Bram Moolenaar734a8672019-12-02 22:49:38 +01002720 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 form = XtVaCreateWidget("separatorForm",
2722 xmFormWidgetClass, dialogform,
2723 XmNleftAttachment, XmATTACH_FORM,
2724 XmNrightAttachment, XmATTACH_FORM,
2725 XmNtopAttachment, XmATTACH_FORM,
2726 NULL);
2727 XtManageChild(form);
2728
2729#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002730 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 switch (type)
2732 {
2733 case VIM_GENERIC:
2734 icon_data = generic_xpm;
2735 break;
2736 case VIM_ERROR:
2737 icon_data = error_xpm;
2738 break;
2739 case VIM_WARNING:
2740 icon_data = alert_xpm;
2741 break;
2742 case VIM_INFO:
2743 icon_data = info_xpm;
2744 break;
2745 case VIM_QUESTION:
2746 icon_data = quest_xpm;
2747 break;
2748 default:
2749 icon_data = generic_xpm;
2750 }
2751
2752 n = 0;
2753 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2754 XtSetArg(args[n], XmNtopOffset, 8); n++;
2755 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2756 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2757 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2758 XtSetArg(args[n], XmNleftOffset, 8); n++;
2759
2760 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2761 icon_data, args, n);
2762 XtManageChild(dialogpixmap);
2763#endif
2764
Bram Moolenaar734a8672019-12-02 22:49:38 +01002765 // Create the dialog message.
2766 // Since LessTif is apparently having problems with the creation of
2767 // properly localized string, we use LtoR here. The symptom is that the
2768 // string sill not show properly in multiple lines as it does in native
2769 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002770 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 if (label == NULL)
2772 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002773 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 xmLabelGadgetClass, form,
2775 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002776 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 XmNtopAttachment, XmATTACH_FORM,
2778 XmNtopOffset, 8,
2779#ifdef HAVE_XPM
2780 XmNleftAttachment, XmATTACH_WIDGET,
2781 XmNleftWidget, dialogpixmap,
2782#else
2783 XmNleftAttachment, XmATTACH_FORM,
2784#endif
2785 XmNleftOffset, 8,
2786 XmNrightAttachment, XmATTACH_FORM,
2787 XmNrightOffset, 8,
2788 XmNbottomAttachment, XmATTACH_FORM,
2789 XmNbottomOffset, 8,
2790 NULL);
2791 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002792 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793
2794 if (textfield != NULL)
2795 {
2796 XtVaSetValues(form,
2797 XmNbottomAttachment, XmATTACH_WIDGET,
2798 XmNbottomWidget, dialogtextfield,
2799 NULL);
2800 }
2801 else
2802 {
2803 if (butcount > 0)
2804 XtVaSetValues(form,
2805 XmNbottomAttachment, XmATTACH_WIDGET,
2806 XmNbottomWidget, separator,
2807 NULL);
2808 else
2809 XtVaSetValues(form,
2810 XmNbottomAttachment, XmATTACH_FORM,
2811 NULL);
2812 }
2813
2814 if (dfltbutton < 1)
2815 dfltbutton = 1;
2816 if (dfltbutton > butcount)
2817 dfltbutton = butcount;
2818 XtVaSetValues(dialogform,
2819 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2820 if (textfield != NULL)
2821 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2822 else
2823 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2824 NULL);
2825
2826 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002827 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828
2829 if (textfield != NULL && *textfield != NUL)
2830 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002831 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 XmTextFieldSetSelection(dialogtextfield,
2833 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2834 XtLastTimestampProcessed(gui.dpy));
2835 XmTextFieldSetCursorPosition(dialogtextfield,
2836 (XmTextPosition)STRLEN(textfield));
2837 }
2838
2839 app = XtWidgetToApplicationContext(dialogform);
2840
Bram Moolenaar734a8672019-12-02 22:49:38 +01002841 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 dialogStatus = -1;
2843 for (;;)
2844 {
2845 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2846 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2847 break;
2848 }
2849
2850 vim_free(buttons);
2851
2852 if (textfield != NULL)
2853 {
2854 p = (char_u *)XmTextGetString(dialogtextfield);
2855 if (p == NULL || dialogStatus < 0)
2856 *textfield = NUL;
2857 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002858 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002859 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 }
2861
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002862 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 XtDestroyWidget(dialogform);
2864
2865 return dialogStatus;
2866}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002867#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868
2869#if defined(FEAT_FOOTER) || defined(PROTO)
2870
2871 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002872gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002874 Dimension height; // total Toolbar height
2875 Dimension top; // XmNmarginTop
2876 Dimension bottom; // XmNmarginBottom
2877 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878
2879 XtVaGetValues(footer,
2880 XmNheight, &height,
2881 XmNmarginTop, &top,
2882 XmNmarginBottom, &bottom,
2883 XmNshadowThickness, &shadow,
2884 NULL);
2885
2886 return (int) height + top + bottom + (shadow << 1);
2887}
2888
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002890gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891{
2892 if (showit)
2893 {
2894 gui.footer_height = gui_mch_compute_footer_height();
2895 XtManageChild(footer);
2896 }
2897 else
2898 {
2899 gui.footer_height = 0;
2900 XtUnmanageChild(footer);
2901 }
2902 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2903}
2904
2905 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002906gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907{
2908 XmString xms;
2909
2910 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002911 if (xms != NULL)
2912 {
2913 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2914 XmStringFree(xms);
2915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916}
2917
2918#endif
2919
2920
2921#if defined(FEAT_TOOLBAR) || defined(PROTO)
2922 void
2923gui_mch_show_toolbar(int showit)
2924{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002925 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926
2927 if (toolBar == (Widget)0)
2928 return;
2929 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2930 if (showit && numChildren > 0)
2931 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002932 // Assume that we want to show the toolbar if p_toolbar contains
2933 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 WidgetList children;
2935
2936 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2937 {
2938 void (*action)(BalloonEval *);
2939 int text = 0;
2940
2941 if (strstr((const char *)p_toolbar, "tooltips"))
2942 action = &gui_mch_enable_beval_area;
2943 else
2944 action = &gui_mch_disable_beval_area;
2945 if (strstr((const char *)p_toolbar, "text"))
2946 text = 1;
2947 else if (strstr((const char *)p_toolbar, "icons"))
2948 text = -1;
2949 if (text != 0)
2950 {
2951 vimmenu_T *toolbar;
2952 vimmenu_T *cur;
2953
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002954 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 if (menu_is_toolbar(toolbar->dname))
2956 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002957 // Assumption: toolbar is NULL if there is no toolbar,
2958 // otherwise it contains the toolbar menu structure.
2959 //
2960 // Assumption: "numChildren" == the number of items in the list
2961 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 if (toolbar)
2963 {
2964 for (cur = toolbar->children; cur; cur = cur->next)
2965 {
2966 Arg args[1];
2967 int n = 0;
2968
Bram Moolenaar734a8672019-12-02 22:49:38 +01002969 // Enable/Disable tooltip (OK to enable while
2970 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 if (cur->tip != NULL)
2972 (*action)(cur->tip);
2973 if (!menu_is_separator(cur->name))
2974 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002975 if (text == 1 || cur->xpm == NULL)
2976 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002978 ++n;
2979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 if (cur->id != NULL)
2981 {
2982 XtUnmanageChild(cur->id);
2983 XtSetValues(cur->id, args, n);
2984 XtManageChild(cur->id);
2985 }
2986 }
2987 }
2988 }
2989 }
2990 }
2991 gui.toolbar_height = gui_mch_compute_toolbar_height();
2992 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002993#ifdef FEAT_GUI_TABLINE
2994 if (showing_tabline)
2995 {
2996 XtVaSetValues(tabLine,
2997 XmNtopAttachment, XmATTACH_WIDGET,
2998 XmNtopWidget, XtParent(toolBar),
2999 NULL);
3000 XtVaSetValues(textAreaForm,
3001 XmNtopAttachment, XmATTACH_WIDGET,
3002 XmNtopWidget, tabLine,
3003 NULL);
3004 }
3005 else
3006#endif
3007 XtVaSetValues(textAreaForm,
3008 XmNtopAttachment, XmATTACH_WIDGET,
3009 XmNtopWidget, XtParent(toolBar),
3010 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 if (XtIsManaged(menuBar))
3012 XtVaSetValues(XtParent(toolBar),
3013 XmNtopAttachment, XmATTACH_WIDGET,
3014 XmNtopWidget, menuBar,
3015 NULL);
3016 else
3017 XtVaSetValues(XtParent(toolBar),
3018 XmNtopAttachment, XmATTACH_FORM,
3019 NULL);
3020 }
3021 else
3022 {
3023 gui.toolbar_height = 0;
3024 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003025 {
3026#ifdef FEAT_GUI_TABLINE
3027 if (showing_tabline)
3028 {
3029 XtVaSetValues(tabLine,
3030 XmNtopAttachment, XmATTACH_WIDGET,
3031 XmNtopWidget, menuBar,
3032 NULL);
3033 XtVaSetValues(textAreaForm,
3034 XmNtopAttachment, XmATTACH_WIDGET,
3035 XmNtopWidget, tabLine,
3036 NULL);
3037 }
3038 else
3039#endif
3040 XtVaSetValues(textAreaForm,
3041 XmNtopAttachment, XmATTACH_WIDGET,
3042 XmNtopWidget, menuBar,
3043 NULL);
3044 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003046 {
3047#ifdef FEAT_GUI_TABLINE
3048 if (showing_tabline)
3049 {
3050 XtVaSetValues(tabLine,
3051 XmNtopAttachment, XmATTACH_FORM,
3052 NULL);
3053 XtVaSetValues(textAreaForm,
3054 XmNtopAttachment, XmATTACH_WIDGET,
3055 XmNtopWidget, tabLine,
3056 NULL);
3057 }
3058 else
3059#endif
3060 XtVaSetValues(textAreaForm,
3061 XmNtopAttachment, XmATTACH_FORM,
3062 NULL);
3063 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064
3065 XtUnmanageChild(XtParent(toolBar));
3066 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003067 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068}
3069
3070/*
3071 * A toolbar button has been pushed; now reset the input focus
3072 * such that the user can type page up/down etc. and have the
3073 * input go to the editor window, not the button
3074 */
3075 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003076reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077{
3078 if (textArea != NULL)
3079 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3080}
3081
3082 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003083gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003085 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003086 Dimension height; // total Toolbar height
3087 Dimension whgt; // height of each widget
3088 WidgetList children; // list of toolBar's children
3089 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 int i;
3091
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003092 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003095 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003096 Dimension fst;
3097 Dimension fmh;
3098 Dimension tst;
3099 Dimension tmh;
3100
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003102 XmNshadowThickness, &fst,
3103 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003105 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003107 XmNshadowThickness, &tst,
3108 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 XmNchildren, &children,
3110 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003111 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003112 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 {
3114 whgt = 0;
3115 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3116 if (height < whgt)
3117 height = whgt;
3118 }
3119 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003120#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003121 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003122 if (height < 10)
3123 height = 24;
3124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003126 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127}
3128
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003130motif_get_toolbar_colors(
3131 Pixel *bgp,
3132 Pixel *fgp,
3133 Pixel *bsp,
3134 Pixel *tsp,
3135 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003136{
3137 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003138 XmNbackground, bgp,
3139 XmNforeground, fgp,
3140 XmNbottomShadowColor, bsp,
3141 XmNtopShadowColor, tsp,
3142 XmNhighlightColor, hsp,
3143 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003144}
3145
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146# ifdef FEAT_FOOTER
3147/*
3148 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003149 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 * get implemented and the user will have a choice.
3151 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003153toolbarbutton_enter_cb(
3154 Widget w UNUSED,
3155 XtPointer client_data,
3156 XEvent *event UNUSED,
3157 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158{
3159 vimmenu_T *menu = (vimmenu_T *) client_data;
3160
3161 if (menu->strings[MENU_INDEX_TIP] != NULL)
3162 {
3163 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3164 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3165 }
3166}
3167
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003169toolbarbutton_leave_cb(
3170 Widget w UNUSED,
3171 XtPointer client_data UNUSED,
3172 XEvent *event UNUSED,
3173 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174{
3175 gui_mch_set_footer((char_u *) "");
3176}
3177# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178#endif
3179
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003180#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3181/*
3182 * Show or hide the tabline.
3183 */
3184 void
3185gui_mch_show_tabline(int showit)
3186{
3187 if (tabLine == (Widget)0)
3188 return;
3189
3190 if (!showit != !showing_tabline)
3191 {
3192 if (showit)
3193 {
3194 XtManageChild(tabLine);
3195 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003196 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3197 XtUnmanageChild(XtNameToWidget(tabLine,
3198 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003199#ifdef FEAT_MENU
3200# ifdef FEAT_TOOLBAR
3201 if (XtIsManaged(XtParent(toolBar)))
3202 XtVaSetValues(tabLine,
3203 XmNtopAttachment, XmATTACH_WIDGET,
3204 XmNtopWidget, XtParent(toolBar), NULL);
3205 else
3206# endif
3207 if (XtIsManaged(menuBar))
3208 XtVaSetValues(tabLine,
3209 XmNtopAttachment, XmATTACH_WIDGET,
3210 XmNtopWidget, menuBar, NULL);
3211 else
3212#endif
3213 XtVaSetValues(tabLine,
3214 XmNtopAttachment, XmATTACH_FORM, NULL);
3215 XtVaSetValues(textAreaForm,
3216 XmNtopAttachment, XmATTACH_WIDGET,
3217 XmNtopWidget, tabLine,
3218 NULL);
3219 }
3220 else
3221 {
3222 XtUnmanageChild(tabLine);
3223#ifdef FEAT_MENU
3224# ifdef FEAT_TOOLBAR
3225 if (XtIsManaged(XtParent(toolBar)))
3226 XtVaSetValues(textAreaForm,
3227 XmNtopAttachment, XmATTACH_WIDGET,
3228 XmNtopWidget, XtParent(toolBar), NULL);
3229 else
3230# endif
3231 if (XtIsManaged(menuBar))
3232 XtVaSetValues(textAreaForm,
3233 XmNtopAttachment, XmATTACH_WIDGET,
3234 XmNtopWidget, menuBar, NULL);
3235 else
3236#endif
3237 XtVaSetValues(textAreaForm,
3238 XmNtopAttachment, XmATTACH_FORM, NULL);
3239 }
3240 showing_tabline = showit;
3241 }
3242}
3243
3244/*
3245 * Return TRUE when tabline is displayed.
3246 */
3247 int
3248gui_mch_showing_tabline(void)
3249{
3250 return tabLine != (Widget)0 && showing_tabline;
3251}
3252
3253/*
3254 * Update the labels of the tabline.
3255 */
3256 void
3257gui_mch_update_tabline(void)
3258{
3259 tabpage_T *tp;
3260 int nr = 1, n;
3261 Arg args[10];
3262 int curtabidx = 0, currentpage;
3263 Widget tab;
3264 XmNotebookPageInfo page_info;
3265 XmNotebookPageStatus page_status;
3266 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003267 XmString label_str;
3268 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003269 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003270
3271 if (tabLine == (Widget)0)
3272 return;
3273
Bram Moolenaar734a8672019-12-02 22:49:38 +01003274 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003275 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3276 {
3277 if (tp == curtab)
3278 curtabidx = nr;
3279
3280 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3281 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003282 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003283 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003284 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003285 n = 0;
3286 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3287 XtSetArg(args[n], XmNtraversalOn, False); n++;
3288 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3289 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3290 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3291 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3292 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003293 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3294 NULL);
3295 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003296 }
3297 else
3298 tab = page_info.major_tab_widget;
3299
3300 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003301
3302 /*
3303 * Change the label text only if it is different
3304 */
3305 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3306 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3307 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003308 get_tabline_label(tp, FALSE);
3309 if (STRCMP(label_cstr, NameBuff) != 0)
3310 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003311 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3312 NameBuff, STRLEN(NameBuff) + 1, NULL);
3313 /*
3314 * Force a resize of the tab label button
3315 */
3316 XtUnmanageChild(tab);
3317 XtManageChild(tab);
3318 }
3319 XtFree(label_cstr);
3320 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003321 }
3322
3323 tab_count = nr - 1;
3324
3325 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3326
Bram Moolenaar734a8672019-12-02 22:49:38 +01003327 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003328 while (nr <= last_page)
3329 {
3330 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3331 && page_info.page_number == nr
3332 && page_info.major_tab_widget != (Widget)0)
3333 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003334 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3335 if (beval != NULL)
3336 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003337 XtUnmanageChild(page_info.major_tab_widget);
3338 XtDestroyWidget(page_info.major_tab_widget);
3339 }
3340 nr++;
3341 }
3342
3343 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3344
3345 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3346 if (currentpage != curtabidx)
3347 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3348}
3349
3350/*
3351 * Set the current tab to "nr". First tab is 1.
3352 */
3353 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003354gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003355{
3356 int currentpage;
3357
3358 if (tabLine == (Widget)0)
3359 return;
3360
3361 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3362 if (currentpage != nr)
3363 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3364}
3365#endif
3366
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367/*
3368 * Set the colors of Widget "id" to the menu colors.
3369 */
3370 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003371gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372{
3373 if (gui.menu_bg_pixel != INVALCOLOR)
3374#if (XmVersion >= 1002)
3375 XmChangeColor(id, gui.menu_bg_pixel);
3376#else
3377 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3378#endif
3379 if (gui.menu_fg_pixel != INVALCOLOR)
3380 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3381}
3382
3383/*
3384 * Set the colors of Widget "id" to the scrollbar colors.
3385 */
3386 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003387gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388{
3389 if (gui.scroll_bg_pixel != INVALCOLOR)
3390#if (XmVersion >= 1002)
3391 XmChangeColor(id, gui.scroll_bg_pixel);
3392#else
3393 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3394#endif
3395 if (gui.scroll_fg_pixel != INVALCOLOR)
3396 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3397}
3398
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399/*
3400 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3401 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003402 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003403gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003405#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406#ifdef FONTSET_ALWAYS
3407 if (gui.menu_fontset != NOFONTSET)
3408 {
3409 XmFontList fl;
3410
3411 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3412 if (fl != NULL)
3413 {
3414 if (XtIsManaged(id))
3415 {
3416 XtUnmanageChild(id);
3417 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003418 // We should force the widget to recalculate its
3419 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420 XtManageChild(id);
3421 }
3422 else
3423 XtVaSetValues(id, XmNfontList, fl, NULL);
3424 XmFontListFree(fl);
3425 }
3426 }
3427#else
3428 if (gui.menu_font != NOFONT)
3429 {
3430 XmFontList fl;
3431
3432 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3433 if (fl != NULL)
3434 {
3435 if (XtIsManaged(id))
3436 {
3437 XtUnmanageChild(id);
3438 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003439 // We should force the widget to recalculate its
3440 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 XtManageChild(id);
3442 }
3443 else
3444 XtVaSetValues(id, XmNfontList, fl, NULL);
3445 XmFontListFree(fl);
3446 }
3447 }
3448#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450}
3451
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452
3453/*
3454 * We don't create it twice for the sake of speed.
3455 */
3456
3457typedef struct _SharedFindReplace
3458{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003459 Widget dialog; // the main dialog widget
3460 Widget wword; // 'Exact match' check button
3461 Widget mcase; // 'match case' check button
3462 Widget up; // search direction 'Up' radio button
3463 Widget down; // search direction 'Down' radio button
3464 Widget what; // 'Find what' entry text widget
3465 Widget with; // 'Replace with' entry text widget
3466 Widget find; // 'Find Next' action button
3467 Widget replace; // 'Replace With' action button
3468 Widget all; // 'Replace All' action button
3469 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470
3471 Widget cancel;
3472} SharedFindReplace;
3473
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003474static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3475static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003478find_replace_destroy_callback(
3479 Widget w UNUSED,
3480 XtPointer client_data,
3481 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482{
3483 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3484
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003485 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003486 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 cd->dialog = (Widget)0;
3488}
3489
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003491find_replace_dismiss_callback(
3492 Widget w UNUSED,
3493 XtPointer client_data,
3494 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495{
3496 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3497
3498 if (cd != NULL)
3499 XtUnmanageChild(cd->dialog);
3500}
3501
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003503entry_activate_callback(
3504 Widget w UNUSED,
3505 XtPointer client_data,
3506 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507{
3508 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3509}
3510
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003512find_replace_callback(
3513 Widget w UNUSED,
3514 XtPointer client_data,
3515 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516{
3517 long_u flags = (long_u)client_data;
3518 char *find_text, *repl_text;
3519 Boolean direction_down = TRUE;
3520 Boolean wword;
3521 Boolean mcase;
3522 SharedFindReplace *sfr;
3523
3524 if (flags == FRD_UNDO)
3525 {
3526 char_u *save_cpo = p_cpo;
3527
Bram Moolenaar734a8672019-12-02 22:49:38 +01003528 // No need to be Vi compatible here.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 p_cpo = (char_u *)"";
3530 u_undo(1);
3531 p_cpo = save_cpo;
3532 gui_update_screen();
3533 return;
3534 }
3535
Bram Moolenaar734a8672019-12-02 22:49:38 +01003536 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 if (flags == FRD_FINDNEXT)
3538 {
3539 repl_text = NULL;
3540 sfr = &find_widgets;
3541 }
3542 else
3543 {
3544 repl_text = XmTextFieldGetString(repl_widgets.with);
3545 sfr = &repl_widgets;
3546 }
3547 find_text = XmTextFieldGetString(sfr->what);
3548 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3549 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3550 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3551 if (wword)
3552 flags |= FRD_WHOLE_WORD;
3553 if (mcase)
3554 flags |= FRD_MATCH_CASE;
3555
3556 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3557 direction_down);
3558
3559 if (find_text != NULL)
3560 XtFree(find_text);
3561 if (repl_text != NULL)
3562 XtFree(repl_text);
3563}
3564
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003566find_replace_keypress(
3567 Widget w UNUSED,
3568 SharedFindReplace *frdp,
3569 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570{
3571 KeySym keysym;
3572
3573 if (frdp == NULL)
3574 return;
3575
3576 keysym = XLookupKeysym(event, 0);
3577
Bram Moolenaar734a8672019-12-02 22:49:38 +01003578 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579 if (keysym == XK_Escape)
3580 XtUnmanageChild(frdp->dialog);
3581}
3582
3583 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003584set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003585{
3586 XmString str;
3587 char_u *p, *next;
3588 KeySym mnemonic = NUL;
3589
3590 if (!w)
3591 return;
3592
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003593 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003594 if (p == NULL)
3595 return;
3596 for (next = p; *next; ++next)
3597 {
3598 if (*next == DLG_HOTKEY_CHAR)
3599 {
3600 int len = STRLEN(next);
3601
3602 if (len > 0)
3603 {
3604 mch_memmove(next, next + 1, len);
3605 mnemonic = next[0];
3606 }
3607 }
3608 }
3609
3610 str = XmStringCreateSimple((char *)p);
3611 vim_free(p);
3612 if (str)
3613 {
3614 XtVaSetValues(w,
3615 XmNlabelString, str,
3616 XmNmnemonic, mnemonic,
3617 NULL);
3618 XmStringFree(str);
3619 }
3620 gui_motif_menu_fontlist(w);
3621}
3622
3623 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003624find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625{
3626 SharedFindReplace *frdp;
3627 Widget separator;
3628 Widget input_form;
3629 Widget button_form;
3630 Widget toggle_form;
3631 Widget frame;
3632 XmString str;
3633 int n;
3634 Arg args[6];
3635 int wword = FALSE;
3636 int mcase = !p_ic;
3637 Dimension width;
3638 Dimension widest;
3639 char_u *entry_text;
3640
3641 frdp = do_replace ? &repl_widgets : &find_widgets;
3642
Bram Moolenaar734a8672019-12-02 22:49:38 +01003643 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3645
Bram Moolenaar734a8672019-12-02 22:49:38 +01003646 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 if (frdp->dialog)
3648 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003649 gui_motif_synch_fonts();
3650
Bram Moolenaar734a8672019-12-02 22:49:38 +01003651 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 if (XtIsManaged(frdp->dialog))
3653 XMapRaised(XtDisplay(frdp->dialog),
3654 XtWindow(XtParent(frdp->dialog)));
3655 else
3656 XtManageChild(frdp->dialog);
3657 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3658 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3659
3660 if (entry_text != NULL)
3661 XmTextFieldSetString(frdp->what, (char *)entry_text);
3662 vim_free(entry_text);
3663
3664 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3665 return;
3666 }
3667
Bram Moolenaar734a8672019-12-02 22:49:38 +01003668 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669 if (do_replace)
3670 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3671 else
3672 str = XmStringCreateSimple(_("VIM - Search..."));
3673
3674 n = 0;
3675 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3676 XtSetArg(args[n], XmNnoResize, True); n++;
3677 XtSetArg(args[n], XmNdialogTitle, str); n++;
3678
3679 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3680 XmStringFree(str);
3681 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3682 find_replace_destroy_callback, frdp);
3683
3684 button_form = XtVaCreateWidget("buttonForm",
3685 xmFormWidgetClass, frdp->dialog,
3686 XmNrightAttachment, XmATTACH_FORM,
3687 XmNrightOffset, 4,
3688 XmNtopAttachment, XmATTACH_FORM,
3689 XmNtopOffset, 4,
3690 XmNbottomAttachment, XmATTACH_FORM,
3691 XmNbottomOffset, 4,
3692 NULL);
3693
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 frdp->find = XtVaCreateManagedWidget("findButton",
3695 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 XmNsensitive, True,
3697 XmNtopAttachment, XmATTACH_FORM,
3698 XmNleftAttachment, XmATTACH_FORM,
3699 XmNrightAttachment, XmATTACH_FORM,
3700 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003701 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702
3703 XtAddCallback(frdp->find, XmNactivateCallback,
3704 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003705 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706
3707 if (do_replace)
3708 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3710 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 XmNtopAttachment, XmATTACH_WIDGET,
3712 XmNtopWidget, frdp->find,
3713 XmNleftAttachment, XmATTACH_FORM,
3714 XmNrightAttachment, XmATTACH_FORM,
3715 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003716 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 XtAddCallback(frdp->replace, XmNactivateCallback,
3718 find_replace_callback, (XtPointer)FRD_REPLACE);
3719
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3721 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 XmNtopAttachment, XmATTACH_WIDGET,
3723 XmNtopWidget, frdp->replace,
3724 XmNleftAttachment, XmATTACH_FORM,
3725 XmNrightAttachment, XmATTACH_FORM,
3726 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003727 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 XtAddCallback(frdp->all, XmNactivateCallback,
3729 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3730
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 frdp->undo = XtVaCreateManagedWidget("undoButton",
3732 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 XmNtopAttachment, XmATTACH_WIDGET,
3734 XmNtopWidget, frdp->all,
3735 XmNleftAttachment, XmATTACH_FORM,
3736 XmNrightAttachment, XmATTACH_FORM,
3737 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003738 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 XtAddCallback(frdp->undo, XmNactivateCallback,
3740 find_replace_callback, (XtPointer)FRD_UNDO);
3741 }
3742
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3744 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745 XmNleftAttachment, XmATTACH_FORM,
3746 XmNrightAttachment, XmATTACH_FORM,
3747 XmNbottomAttachment, XmATTACH_FORM,
3748 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003749 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 XtAddCallback(frdp->cancel, XmNactivateCallback,
3751 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003752 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753
3754 XtManageChild(button_form);
3755
3756 n = 0;
3757 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3758 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3759 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3760 XtSetArg(args[n], XmNrightOffset, 4); n++;
3761 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3762 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3763 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3764 XtManageChild(separator);
3765
3766 input_form = XtVaCreateWidget("inputForm",
3767 xmFormWidgetClass, frdp->dialog,
3768 XmNleftAttachment, XmATTACH_FORM,
3769 XmNleftOffset, 4,
3770 XmNrightAttachment, XmATTACH_WIDGET,
3771 XmNrightWidget, separator,
3772 XmNrightOffset, 4,
3773 XmNtopAttachment, XmATTACH_FORM,
3774 XmNtopOffset, 4,
3775 NULL);
3776
3777 {
3778 Widget label_what;
3779 Widget label_with = (Widget)0;
3780
3781 str = XmStringCreateSimple(_("Find what:"));
3782 label_what = XtVaCreateManagedWidget("whatLabel",
3783 xmLabelGadgetClass, input_form,
3784 XmNlabelString, str,
3785 XmNleftAttachment, XmATTACH_FORM,
3786 XmNtopAttachment, XmATTACH_FORM,
3787 XmNtopOffset, 4,
3788 NULL);
3789 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003790 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791
3792 frdp->what = XtVaCreateManagedWidget("whatText",
3793 xmTextFieldWidgetClass, input_form,
3794 XmNtopAttachment, XmATTACH_FORM,
3795 XmNrightAttachment, XmATTACH_FORM,
3796 XmNleftAttachment, XmATTACH_FORM,
3797 NULL);
3798
3799 if (do_replace)
3800 {
3801 frdp->with = XtVaCreateManagedWidget("withText",
3802 xmTextFieldWidgetClass, input_form,
3803 XmNtopAttachment, XmATTACH_WIDGET,
3804 XmNtopWidget, frdp->what,
3805 XmNtopOffset, 4,
3806 XmNleftAttachment, XmATTACH_FORM,
3807 XmNrightAttachment, XmATTACH_FORM,
3808 XmNbottomAttachment, XmATTACH_FORM,
3809 NULL);
3810
3811 XtAddCallback(frdp->with, XmNactivateCallback,
3812 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3813
3814 str = XmStringCreateSimple(_("Replace with:"));
3815 label_with = XtVaCreateManagedWidget("withLabel",
3816 xmLabelGadgetClass, input_form,
3817 XmNlabelString, str,
3818 XmNleftAttachment, XmATTACH_FORM,
3819 XmNtopAttachment, XmATTACH_WIDGET,
3820 XmNtopWidget, frdp->what,
3821 XmNtopOffset, 4,
3822 XmNbottomAttachment, XmATTACH_FORM,
3823 NULL);
3824 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003825 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826
3827 /*
3828 * Make the entry activation only change the input focus onto the
3829 * with item.
3830 */
3831 XtAddCallback(frdp->what, XmNactivateCallback,
3832 entry_activate_callback, frdp->with);
3833 XtAddEventHandler(frdp->with, KeyPressMask, False,
3834 (XtEventHandler)find_replace_keypress,
3835 (XtPointer) frdp);
3836
3837 }
3838 else
3839 {
3840 /*
3841 * Make the entry activation do the search.
3842 */
3843 XtAddCallback(frdp->what, XmNactivateCallback,
3844 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3845 }
3846 XtAddEventHandler(frdp->what, KeyPressMask, False,
3847 (XtEventHandler)find_replace_keypress,
3848 (XtPointer)frdp);
3849
Bram Moolenaar734a8672019-12-02 22:49:38 +01003850 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 n = 0;
3852 XtSetArg(args[n], XmNwidth, &width); n++;
3853 XtGetValues(label_what, args, n);
3854 widest = width;
3855 if (do_replace)
3856 {
3857 XtGetValues(label_with, args, n);
3858 if (width > widest)
3859 widest = width;
3860 }
3861
3862 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3863 if (do_replace)
3864 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3865
3866 }
3867
3868 XtManageChild(input_form);
3869
3870 {
3871 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003872 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873
3874 frame = XtVaCreateWidget("directionFrame",
3875 xmFrameWidgetClass, frdp->dialog,
3876 XmNtopAttachment, XmATTACH_WIDGET,
3877 XmNtopWidget, input_form,
3878 XmNtopOffset, 4,
3879 XmNbottomAttachment, XmATTACH_FORM,
3880 XmNbottomOffset, 4,
3881 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3882 XmNrightWidget, input_form,
3883 NULL);
3884
3885 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003886 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 xmLabelGadgetClass, frame,
3888 XmNlabelString, str,
3889 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3890 XmNchildType, XmFRAME_TITLE_CHILD,
3891 NULL);
3892 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003893 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894
3895 radio_box = XmCreateRadioBox(frame, "radioBox",
3896 (ArgList)NULL, 0);
3897
3898 str = XmStringCreateSimple( _("Up"));
3899 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3900 xmToggleButtonGadgetClass, radio_box,
3901 XmNlabelString, str,
3902 XmNset, False,
3903 NULL);
3904 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003905 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906
3907 str = XmStringCreateSimple(_("Down"));
3908 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3909 xmToggleButtonGadgetClass, radio_box,
3910 XmNlabelString, str,
3911 XmNset, True,
3912 NULL);
3913 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003914 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915
3916 XtManageChild(radio_box);
3917 XtManageChild(frame);
3918 }
3919
3920 toggle_form = XtVaCreateWidget("toggleForm",
3921 xmFormWidgetClass, frdp->dialog,
3922 XmNleftAttachment, XmATTACH_FORM,
3923 XmNleftOffset, 4,
3924 XmNrightAttachment, XmATTACH_WIDGET,
3925 XmNrightWidget, frame,
3926 XmNrightOffset, 4,
3927 XmNtopAttachment, XmATTACH_WIDGET,
3928 XmNtopWidget, input_form,
3929 XmNtopOffset, 4,
3930 XmNbottomAttachment, XmATTACH_FORM,
3931 XmNbottomOffset, 4,
3932 NULL);
3933
3934 str = XmStringCreateSimple(_("Match whole word only"));
3935 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3936 xmToggleButtonGadgetClass, toggle_form,
3937 XmNlabelString, str,
3938 XmNtopAttachment, XmATTACH_FORM,
3939 XmNtopOffset, 4,
3940 XmNleftAttachment, XmATTACH_FORM,
3941 XmNleftOffset, 4,
3942 XmNset, wword,
3943 NULL);
3944 XmStringFree(str);
3945
3946 str = XmStringCreateSimple(_("Match case"));
3947 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3948 xmToggleButtonGadgetClass, toggle_form,
3949 XmNlabelString, str,
3950 XmNleftAttachment, XmATTACH_FORM,
3951 XmNleftOffset, 4,
3952 XmNtopAttachment, XmATTACH_WIDGET,
3953 XmNtopWidget, frdp->wword,
3954 XmNtopOffset, 4,
3955 XmNset, mcase,
3956 NULL);
3957 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003958 gui_motif_menu_fontlist(frdp->wword);
3959 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960
3961 XtManageChild(toggle_form);
3962
3963 if (entry_text != NULL)
3964 XmTextFieldSetString(frdp->what, (char *)entry_text);
3965 vim_free(entry_text);
3966
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003967 gui_motif_synch_fonts();
3968
3969 manage_centered(frdp->dialog);
3970 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3972}
3973
3974 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003975gui_mch_find_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, FALSE);
3981}
3982
3983
3984 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003985gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986{
3987 if (!gui.in_use)
3988 return;
3989
3990 find_replace_dialog_create(eap->arg, TRUE);
3991}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003992
3993/*
3994 * Synchronize all gui elements, which are dependant upon the
3995 * main text font used. Those are in esp. the find/replace dialogs.
3996 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003997 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003998 */
3999 void
4000gui_motif_synch_fonts(void)
4001{
4002 SharedFindReplace *frdp;
4003 int do_replace;
4004 XFontStruct *font;
4005 XmFontList font_list;
4006
Bram Moolenaar734a8672019-12-02 22:49:38 +01004007 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4008 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004009 font = (XFontStruct *)gui.norm_font;
4010 if (font == NULL)
4011 return;
4012
4013 font_list = gui_motif_create_fontlist(font);
4014
Bram Moolenaar734a8672019-12-02 22:49:38 +01004015 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004016 for (do_replace = 0; do_replace <= 1; ++do_replace)
4017 {
4018 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4019 if (frdp->dialog)
4020 {
4021 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4022 if (do_replace)
4023 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4024 }
4025 }
4026
4027 XmFontListFree(font_list);
4028}