blob: ef3747d8d2c4a587cbcfb8004c142b983ea3ba5d [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 {
1245 if (menu->xpm_fname != NULL)
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001246 {
Bram Moolenaar7c626922005-02-07 22:01:03 +00001247 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001248 }
Bram Moolenaar7c626922005-02-07 22:01:03 +00001249 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1250 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1251 }
1252 return n;
1253}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001254#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255
1256 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001257gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258{
1259 XmString label;
1260 vimmenu_T *parent = menu->parent;
1261
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001263 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1265 return;
1266# endif
1267
1268# ifdef FEAT_TOOLBAR
1269 if (menu_is_toolbar(parent->name))
1270 {
1271 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001272 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 int n;
1274 Arg args[18];
1275
1276 n = 0;
1277 if (menu_is_separator(menu->name))
1278 {
1279 char *cp;
1280 Dimension wid;
1281
1282 /*
1283 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1284 * a width specifier. If no width is specified then we choose one.
1285 */
1286 cp = (char *)vim_strchr(menu->name, ':');
1287 if (cp != NULL)
1288 wid = (Dimension)atoi(++cp);
1289 else
1290 wid = 4;
1291
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292 type = xmSeparatorWidgetClass;
1293 XtSetArg(args[n], XmNwidth, wid); n++;
1294 XtSetArg(args[n], XmNminWidth, wid); n++;
1295 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001296 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297 }
1298 else
1299 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001300 // Without shadows one can't sense whatever the button has been
1301 // pressed or not! However we want to save a bit of space...
1302 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001303 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1305 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1306 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001307 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001308 // Set the label here, so that we can switch between icons/text
1309 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001310 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1311 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001312
Bram Moolenaar7c626922005-02-07 22:01:03 +00001313 n = add_pixmap_args(menu, args, n);
1314
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001315 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 }
1317
1318 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1319 if (menu->id == NULL)
1320 {
1321 menu->id = XtCreateManagedWidget((char *)menu->dname,
1322 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001323 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324 {
1325 XtAddCallback(menu->id,
1326 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327# ifdef FEAT_FOOTER
1328 XtAddEventHandler(menu->id, EnterWindowMask, False,
1329 toolbarbutton_enter_cb, menu);
1330 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1331 toolbarbutton_leave_cb, menu);
1332# endif
1333 }
1334 }
1335 else
1336 XtSetValues(menu->id, args, n);
1337 if (xms != NULL)
1338 XmStringFree(xms);
1339
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001340# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001342# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343
1344 menu->parent = parent;
1345 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001346 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 if (!XtIsManaged(XtParent(toolBar))
1348 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1349 gui_mch_show_toolbar(TRUE);
1350 gui.toolbar_height = gui_mch_compute_toolbar_height();
1351 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001352 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353# endif
1354
Bram Moolenaar734a8672019-12-02 22:49:38 +01001355 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 if (parent->submenu_id == (Widget)0)
1357 return;
1358
1359 menu->submenu_id = (Widget)0;
1360
Bram Moolenaar734a8672019-12-02 22:49:38 +01001361 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 if (menu_is_separator(menu->name))
1363 {
1364 menu->id = XtVaCreateWidget("subMenu",
1365 xmSeparatorGadgetClass, parent->submenu_id,
1366#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001367 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1369 ? 1 : 0),
1370#endif
1371 NULL);
1372 gui_motif_menu_colors(menu->id);
1373 return;
1374 }
1375
1376 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1377 if (label == NULL)
1378 return;
1379 menu->id = XtVaCreateWidget("subMenu",
1380 xmPushButtonWidgetClass, parent->submenu_id,
1381 XmNlabelString, label,
1382 XmNmnemonic, menu->mnemonic,
1383#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001384 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1386 ? 1 : 0),
1387#endif
1388 NULL);
1389 gui_motif_menu_colors(menu->id);
1390 gui_motif_menu_fontlist(menu->id);
1391 XmStringFree(label);
1392
1393 if (menu->id != (Widget)0)
1394 {
1395 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1396 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001397 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 gui_motif_add_actext(menu);
1399 }
1400}
1401
1402#if (XmVersion <= 1002) || defined(PROTO)
1403/*
1404 * This function will destroy/create the popup menus dynamically,
1405 * according to the value of 'mousemodel'.
1406 * This will fix the "right mouse button freeze" that occurs when
1407 * there exists a popup menu but it isn't managed.
1408 */
1409 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001410gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411{
1412 int idx = 0;
1413
Bram Moolenaar734a8672019-12-02 22:49:38 +01001414 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 if (!gui.in_use)
1416 return;
1417
1418 while (menu)
1419 {
1420 if (menu->children != NULL)
1421 {
1422 if (menu_is_popup(menu->name))
1423 {
1424 if (mouse_model_popup())
1425 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001426 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 gui_mch_add_menu(menu, idx);
1428 gui_motif_update_mousemodel(menu->children);
1429 }
1430 else
1431 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001432 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 gui_motif_update_mousemodel(menu->children);
1434 gui_mch_destroy_menu(menu);
1435 }
1436 }
1437 }
1438 else if (menu_is_child_of_popup(menu))
1439 {
1440 if (mouse_model_popup())
1441 gui_mch_add_menu_item(menu, idx);
1442 else
1443 gui_mch_destroy_menu(menu);
1444 }
1445 menu = menu->next;
1446 ++idx;
1447 }
1448}
1449#endif
1450
1451 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001452gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453{
1454 if (menuBar == (Widget)0)
1455 return;
1456 gui_motif_menu_colors(menuBar);
1457#ifdef FEAT_TOOLBAR
1458 gui_motif_menu_colors(toolBarFrame);
1459 gui_motif_menu_colors(toolBar);
1460#endif
1461
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001462 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463}
1464
1465 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001466gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467{
1468 if (menuBar == (Widget)0)
1469 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001470 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {
1472 Dimension height;
1473 Position w, h;
1474
1475 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1476 gui.menu_height = height;
1477
1478 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1479 gui_resize_shell(w, h
1480#ifdef FEAT_XIM
1481 - xim_get_status_area_height()
1482#endif
1483 );
1484 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001485 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 ui_new_shellsize();
1487}
1488
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001489#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001491gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492{
1493# ifdef FEAT_TOOLBAR
1494 vimmenu_T *menu;
1495
1496 if (toolBar == (Widget)0)
1497 return;
1498
1499 menu = gui_find_menu((char_u *)"ToolBar");
1500 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001501 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502# endif
1503}
1504
1505 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001506gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507{
1508# ifdef FEAT_TOOLBAR
1509 vimmenu_T *toolbar;
1510
1511 if (toolBar == (Widget)0)
1512 return;
1513
1514 toolbar = gui_find_menu((char_u *)"ToolBar");
1515 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001516 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517# endif
1518}
1519#endif
1520
1521 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001522submenu_change(
1523 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001524 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525{
1526 vimmenu_T *mp;
1527
1528 for (mp = menu; mp != NULL; mp = mp->next)
1529 {
1530 if (mp->id != (Widget)0)
1531 {
1532 if (colors)
1533 {
1534 gui_motif_menu_colors(mp->id);
1535#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001536 // For a toolbar item: Free the pixmap and allocate a new one,
1537 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001538 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001540 int n = 0;
1541 Arg args[18];
1542
Bram Moolenaar7c626922005-02-07 22:01:03 +00001543 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001544 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001546# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001547 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 if (mp->tip != NULL)
1549 {
1550 Arg args[2];
1551
1552 args[0].name = XmNbackground;
1553 args[0].value = gui.tooltip_bg_pixel;
1554 args[1].name = XmNforeground;
1555 args[1].value = gui.tooltip_fg_pixel;
1556 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1557 }
1558# endif
1559#endif
1560 }
1561 else
1562 {
1563 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001564#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001565 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 if (mp->tip != NULL)
1567 {
1568 Arg args[1];
1569
1570 args[0].name = XmNfontList;
1571 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1572 &gui.tooltip_fontset);
1573 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1574 }
1575#endif
1576 }
1577 }
1578
1579 if (mp->children != NULL)
1580 {
1581#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001582 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 if (mp->submenu_id != (Widget)0)
1584 {
1585 if (colors)
1586 gui_motif_menu_colors(mp->submenu_id);
1587 else
1588 gui_motif_menu_fontlist(mp->submenu_id);
1589 toggle_tearoff(mp->submenu_id);
1590 }
1591#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001592 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001593 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 }
1595 }
1596}
1597
1598/*
1599 * Destroy the machine specific menu widget.
1600 */
1601 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001602gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001604 // Please be sure to destroy the parent widget first (i.e. menu->id).
1605 // On the other hand, problems have been reported that the submenu must be
1606 // deleted first...
1607 //
1608 // This code should be basically identical to that in the file gui_athena.c
1609 // because they are both Xt based.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 if (menu->submenu_id != (Widget)0)
1611 {
1612 XtDestroyWidget(menu->submenu_id);
1613 menu->submenu_id = (Widget)0;
1614 }
1615
1616 if (menu->id != (Widget)0)
1617 {
1618 Widget parent;
1619
1620 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001621#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001622 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001624 // We try to destroy this before the actual menu, because there are
1625 // callbacks, etc. that will be unregistered during the tooltip
1626 // destruction.
1627 //
1628 // If you call "gui_mch_destroy_beval_area()" after destroying
1629 // menu->id, then the tooltip's window will have already been
1630 // deallocated by Xt, and unknown behaviour will ensue (probably
1631 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 gui_mch_destroy_beval_area(menu->tip);
1633 menu->tip = NULL;
1634 }
1635#endif
1636 XtDestroyWidget(menu->id);
1637 menu->id = (Widget)0;
1638 if (parent == menuBar)
1639 gui_mch_compute_menu_height((Widget)0);
1640#ifdef FEAT_TOOLBAR
1641 else if (parent == toolBar)
1642 {
1643 Cardinal num_children;
1644
Bram Moolenaar734a8672019-12-02 22:49:38 +01001645 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1647 if (num_children == 0)
1648 gui_mch_show_toolbar(FALSE);
1649 else
1650 gui.toolbar_height = gui_mch_compute_toolbar_height();
1651 }
1652#endif
1653 }
1654}
1655
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001657gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658{
1659#ifdef MOTIF_POPUP
1660 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1661 XtManageChild(menu->submenu_id);
1662#endif
1663}
1664
Bram Moolenaar734a8672019-12-02 22:49:38 +01001665#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666
1667/*
1668 * Set the menu and scrollbar colors to their default values.
1669 */
1670 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001671gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672{
1673 if (gui.in_use)
1674 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001675 // Use the values saved when starting up. These should come from the
1676 // window manager or a resources file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1678 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1679 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1680 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001681#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 gui.tooltip_fg_pixel =
1683 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1684 gui.tooltip_bg_pixel =
1685 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1686#endif
1687 }
1688}
1689
1690
1691/*
1692 * Scrollbar stuff.
1693 */
1694
1695 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001696gui_mch_set_scrollbar_thumb(
1697 scrollbar_T *sb,
1698 long val,
1699 long size,
1700 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701{
1702 if (sb->id != (Widget)0)
1703 XtVaSetValues(sb->id,
1704 XmNvalue, val,
1705 XmNsliderSize, size,
1706 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001707 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 NULL);
1709}
1710
1711 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001712gui_mch_set_scrollbar_pos(
1713 scrollbar_T *sb,
1714 int x,
1715 int y,
1716 int w,
1717 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718{
1719 if (sb->id != (Widget)0)
1720 {
1721 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1722 {
1723 if (y == 0)
1724 h -= gui.border_offset;
1725 else
1726 y -= gui.border_offset;
1727 XtVaSetValues(sb->id,
1728 XmNtopOffset, y,
1729 XmNbottomOffset, -y - h,
1730 XmNwidth, w,
1731 NULL);
1732 }
1733 else
1734 XtVaSetValues(sb->id,
1735 XmNtopOffset, y,
1736 XmNleftOffset, x,
1737 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1738 ? gui.scrollbar_width : 0,
1739 XmNheight, h,
1740 NULL);
1741 XtManageChild(sb->id);
1742 }
1743}
1744
Bram Moolenaar203ec772020-07-17 20:43:43 +02001745 int
1746gui_mch_get_scrollbar_xpadding(void)
1747{
qsmodo28f1a512022-02-07 15:57:50 +00001748 int xpad;
1749 Dimension tw, ww;
1750 Position tx;
1751
1752 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL);
1753 XtVaGetValues(vimShell, XtNwidth, &ww, NULL);
1754 xpad = ww - tw - tx - gui.scrollbar_width;
1755 return (xpad < 0) ? 0 : xpad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001756}
1757
1758 int
1759gui_mch_get_scrollbar_ypadding(void)
1760{
qsmodo28f1a512022-02-07 15:57:50 +00001761 int ypad;
1762 Dimension th, wh;
1763 Position ty;
1764
1765 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL);
1766 XtVaGetValues(vimShell, XtNheight, &wh, NULL);
1767 ypad = wh - th - ty - gui.scrollbar_height;
1768 return (ypad < 0) ? 0 : ypad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001769}
1770
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001772gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773{
1774 Arg args[16];
1775 int n;
1776
1777 if (sb->id != (Widget)0)
1778 {
1779 n = 0;
1780 if (flag)
1781 {
1782 switch (sb->type)
1783 {
1784 case SBAR_LEFT:
1785 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1786 break;
1787
1788 case SBAR_RIGHT:
1789 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1790 break;
1791
1792 case SBAR_BOTTOM:
1793 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1794 break;
1795 }
1796 XtSetValues(textArea, args, n);
1797 XtManageChild(sb->id);
1798 }
1799 else
1800 {
1801 if (!gui.which_scrollbars[sb->type])
1802 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001803 // The scrollbars of this type are all disabled, adjust the
1804 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 switch (sb->type)
1806 {
1807 case SBAR_LEFT:
1808 XtSetArg(args[n], XmNleftOffset, 0); n++;
1809 break;
1810
1811 case SBAR_RIGHT:
1812 XtSetArg(args[n], XmNrightOffset, 0); n++;
1813 break;
1814
1815 case SBAR_BOTTOM:
1816 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1817 break;
1818 }
1819 XtSetValues(textArea, args, n);
1820 }
1821 XtUnmanageChild(sb->id);
1822 }
1823 }
1824}
1825
1826 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001827gui_mch_create_scrollbar(
1828 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001829 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830{
1831 Arg args[16];
1832 int n;
1833
1834 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 XtSetArg(args[n], XmNminimum, 0); n++;
1836 XtSetArg(args[n], XmNorientation,
1837 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1838
1839 switch (sb->type)
1840 {
1841 case SBAR_LEFT:
1842 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1843 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1844 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1845 break;
1846
1847 case SBAR_RIGHT:
1848 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1849 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1850 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1851 break;
1852
1853 case SBAR_BOTTOM:
1854 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1855 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1856 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1857 break;
1858 }
1859
1860 sb->id = XtCreateWidget("scrollBar",
1861 xmScrollBarWidgetClass, textAreaForm, args, n);
1862
Bram Moolenaar734a8672019-12-02 22:49:38 +01001863 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1865 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1866 XtVaGetValues(sb->id,
1867 XmNbackground, &gui.scroll_def_bg_pixel,
1868 XmNforeground, &gui.scroll_def_fg_pixel,
1869 NULL);
1870
1871 if (sb->id != (Widget)0)
1872 {
1873 gui_mch_set_scrollbar_colors(sb);
1874 XtAddCallback(sb->id, XmNvalueChangedCallback,
1875 scroll_cb, (XtPointer)sb->ident);
1876 XtAddCallback(sb->id, XmNdragCallback,
1877 scroll_cb, (XtPointer)sb->ident);
1878 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1879 (XtPointer)0);
1880 }
1881}
1882
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001884gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885{
1886 if (sb->id != (Widget)0)
1887 XtDestroyWidget(sb->id);
1888}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889
1890 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001891gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892{
1893 if (sb->id != (Widget)0)
1894 {
1895 if (gui.scroll_bg_pixel != INVALCOLOR)
1896 {
1897#if (XmVersion>=1002)
1898 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1899#else
1900 XtVaSetValues(sb->id,
1901 XmNtroughColor, gui.scroll_bg_pixel,
1902 NULL);
1903#endif
1904 }
1905
1906 if (gui.scroll_fg_pixel != INVALCOLOR)
1907 XtVaSetValues(sb->id,
1908 XmNforeground, gui.scroll_fg_pixel,
1909#if (XmVersion<1002)
1910 XmNbackground, gui.scroll_fg_pixel,
1911#endif
1912 NULL);
1913 }
1914
Bram Moolenaar734a8672019-12-02 22:49:38 +01001915 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1917 gui_motif_scroll_colors(textAreaForm);
1918}
1919
1920/*
1921 * Miscellaneous stuff:
1922 */
1923
1924 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001925gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926{
1927 return(XtWindow(textArea));
1928}
1929
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001930/*
1931 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1932 * When one is found, simulate a button press on that widget and give it the
1933 * keyboard focus. If the mnemonic is on a label, look in the userData field
1934 * of the label to see if it points to another widget, and give that the focus.
1935 */
1936 static void
1937do_mnemonic(Widget w, unsigned int keycode)
1938{
1939 WidgetList children;
1940 int numChildren, i;
1941 Boolean isMenu;
1942 KeySym mnemonic = '\0';
1943 char mneString[2];
1944 Widget userData;
1945 unsigned char rowColType;
1946
1947 if (XtIsComposite(w))
1948 {
1949 if (XtClass(w) == xmRowColumnWidgetClass)
1950 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001951 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001952 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1953 }
1954 else
1955 isMenu = False;
1956 if (!isMenu)
1957 {
1958 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001959 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001960 for (i = 0; i < numChildren; i++)
1961 do_mnemonic(children[i], keycode);
1962 }
1963 }
1964 else
1965 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001966 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001967 if (mnemonic != '\0')
1968 {
1969 mneString[0] = mnemonic;
1970 mneString[1] = '\0';
1971 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1972 XStringToKeysym(mneString)) == keycode)
1973 {
1974 if (XtClass(w) == xmLabelWidgetClass
1975 || XtClass(w) == xmLabelGadgetClass)
1976 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001977 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001978 if (userData != NULL && XtIsWidget(userData))
1979 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1980 }
1981 else
1982 {
1983 XKeyPressedEvent keyEvent;
1984
1985 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1986
Bram Moolenaara80faa82020-04-12 19:37:17 +02001987 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001988 keyEvent.type = KeyPress;
1989 keyEvent.serial = 1;
1990 keyEvent.send_event = True;
1991 keyEvent.display = XtDisplay(w);
1992 keyEvent.window = XtWindow(w);
1993 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1994 NULL, 0);
1995 }
1996 }
1997 }
1998 }
1999}
2000
2001/*
2002 * Callback routine for dialog mnemonic processing.
2003 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002004 static void
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02002005mnemonic_event(
2006 Widget w,
2007 XtPointer call_data UNUSED,
2008 XKeyEvent *event,
2009 Boolean *b UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002010{
2011 do_mnemonic(w, event->keycode);
2012}
2013
2014
2015/*
2016 * Search the widget tree under w for widgets with mnemonics. When found, add
2017 * a passive grab to the dialog widget for the mnemonic character, thus
2018 * directing mnemonic events to the dialog widget.
2019 */
2020 static void
2021add_mnemonic_grabs(Widget dialog, Widget w)
2022{
2023 char mneString[2];
2024 WidgetList children;
2025 int numChildren, i;
2026 Boolean isMenu;
2027 KeySym mnemonic = '\0';
2028 unsigned char rowColType;
2029
2030 if (XtIsComposite(w))
2031 {
2032 if (XtClass(w) == xmRowColumnWidgetClass)
2033 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002034 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002035 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2036 }
2037 else
2038 isMenu = False;
2039 if (!isMenu)
2040 {
2041 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002042 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002043 for (i = 0; i < numChildren; i++)
2044 add_mnemonic_grabs(dialog, children[i]);
2045 }
2046 }
2047 else
2048 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002049 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002050 if (mnemonic != '\0')
2051 {
2052 mneString[0] = mnemonic;
2053 mneString[1] = '\0';
2054 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2055 XStringToKeysym(mneString)),
2056 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2057 }
2058 }
2059}
2060
2061/*
2062 * Add a handler for mnemonics in a dialog. Motif itself only handles
2063 * mnemonics in menus. Mnemonics added or changed after this call will be
2064 * ignored.
2065 *
2066 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2067 * the appropriate label and set the XmNuserData resource of the label to the
2068 * widget to get the focus when the mnemonic is typed.
2069 */
2070 static void
2071activate_dialog_mnemonics(Widget dialog)
2072{
2073 if (!dialog)
2074 return;
2075
2076 XtAddEventHandler(dialog, KeyPressMask, False,
2077 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2078 add_mnemonic_grabs(dialog, dialog);
2079}
2080
2081/*
2082 * Removes the event handler and key-grabs for dialog mnemonic handling.
2083 */
2084 static void
2085suppress_dialog_mnemonics(Widget dialog)
2086{
2087 if (!dialog)
2088 return;
2089
2090 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2091 XtRemoveEventHandler(dialog, KeyPressMask, False,
2092 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2093}
2094
2095#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002096/*
2097 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2098 */
2099 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002100set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002101{
2102 XmFontList fl;
2103
2104#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002105 if (gui.fontset != NOFONTSET)
2106 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002107 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2108 if (fl != NULL)
2109 {
2110 if (XtIsManaged(id))
2111 {
2112 XtUnmanageChild(id);
2113 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002114 // We should force the widget to recalculate its
2115 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002116 XtManageChild(id);
2117 }
2118 else
2119 XtVaSetValues(id, XmNfontList, fl, NULL);
2120 XmFontListFree(fl);
2121 }
2122 }
2123#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002124 if (gui.norm_font != NOFONT)
2125 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002126 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2127 if (fl != NULL)
2128 {
2129 if (XtIsManaged(id))
2130 {
2131 XtUnmanageChild(id);
2132 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002133 // We should force the widget to recalculate its
2134 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002135 XtManageChild(id);
2136 }
2137 else
2138 XtVaSetValues(id, XmNfontList, fl, NULL);
2139 XmFontListFree(fl);
2140 }
2141 }
2142#endif
2143}
2144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145
2146#if defined(FEAT_BROWSE) || defined(PROTO)
2147
2148/*
2149 * file selector related stuff
2150 */
2151
2152#include <Xm/FileSB.h>
2153#include <Xm/XmStrDefs.h>
2154
2155typedef struct dialog_callback_arg
2156{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002157 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 int id;
2159} dcbarg_T;
2160
2161static Widget dialog_wgt;
2162static char *browse_fname = NULL;
2163static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002164 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002166static void DialogCancelCB(Widget, XtPointer, XtPointer);
2167static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168
2169/*
2170 * This function is used to translate the predefined label text of the
2171 * precomposed dialogs. We do this explicitly to allow:
2172 *
2173 * - usage of gettext for translation, as in all the other places.
2174 *
2175 * - equalize the messages between different GUI implementations as far as
2176 * possible.
2177 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002178 static void
2179set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002181 XmString str;
2182 Widget w;
2183 char_u *p, *next;
2184 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185
2186 w = XtNameToWidget(parent, name);
2187
2188 if (!w)
2189 return;
2190
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002191 p = vim_strsave((char_u *)new_label);
2192 if (p == NULL)
2193 return;
2194 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002196 if (*next == DLG_HOTKEY_CHAR)
2197 {
2198 int len = STRLEN(next);
2199
2200 if (len > 0)
2201 {
2202 mch_memmove(next, next + 1, len);
2203 mnemonic = next[0];
2204 }
2205 }
2206 }
2207
2208 str = XmStringCreate((char *)p, STRING_TAG);
2209 vim_free(p);
2210
2211 if (str != NULL)
2212 {
2213 XtVaSetValues(w,
2214 XmNlabelString, str,
2215 XmNmnemonic, mnemonic,
2216 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 XmStringFree(str);
2218 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002219 gui_motif_menu_fontlist(w);
2220}
2221
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002222 static void
2223set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002224{
2225 Widget w;
2226 w = XtNameToWidget(parent, name);
2227
2228 if (!w)
2229 return;
2230
2231 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232}
2233
2234/*
2235 * Put up a file requester.
2236 * Returns the selected name in allocated memory, or NULL for Cancel.
2237 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002239gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002240 int saving UNUSED, // select file to write
2241 char_u *title, // title for the window
2242 char_u *dflt, // default name
2243 char_u *ext UNUSED, // not used (extension added)
2244 char_u *initdir, // initial directory, NULL for current dir
2245 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246{
2247 char_u dirbuf[MAXPATHL];
2248 char_u dfltbuf[MAXPATHL];
2249 char_u *pattern;
2250 char_u *tofree = NULL;
2251
Bram Moolenaar734a8672019-12-02 22:49:38 +01002252 // There a difference between the resource name and value, Therefore, we
2253 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2254 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002255
2256 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257
2258 if (initdir == NULL || *initdir == NUL)
2259 {
2260 mch_dirname(dirbuf, MAXPATHL);
2261 initdir = dirbuf;
2262 }
2263
2264 if (dflt == NULL)
2265 dflt = (char_u *)"";
2266 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2267 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002268 // The default selection should be the full path, "dflt" is only the
2269 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 STRCPY(dfltbuf, initdir);
2271 add_pathsep(dfltbuf);
2272 STRCAT(dfltbuf, dflt);
2273 dflt = dfltbuf;
2274 }
2275
Bram Moolenaar734a8672019-12-02 22:49:38 +01002276 // Can only use one pattern for a file name. Get the first pattern out of
2277 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 if (filter == NULL)
2279 pattern = (char_u *)"";
2280 else
2281 {
2282 char_u *s, *p;
2283
2284 s = filter;
2285 for (p = filter; *p != NUL; ++p)
2286 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002287 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002289 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 break;
2291 }
2292 pattern = vim_strnsave(s, p - s);
2293 tofree = pattern;
2294 if (pattern == NULL)
2295 pattern = (char_u *)"";
2296 }
2297
2298 XtVaSetValues(dialog_wgt,
2299 XtVaTypedArg,
2300 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2301 XtVaTypedArg,
2302 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2303 XtVaTypedArg,
2304 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2305 XtVaTypedArg,
2306 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2307 NULL);
2308
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002309 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2310 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2312 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002313 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002315 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2317
Bram Moolenaar734a8672019-12-02 22:49:38 +01002318 // This is to save us from silly external settings using not fixed with
2319 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002320 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2321 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2322
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 gui_motif_menu_colors(dialog_wgt);
2324 if (gui.scroll_bg_pixel != INVALCOLOR)
2325 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2326
2327 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2328 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002329 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2331 (unsigned char)XmDIALOG_HELP_BUTTON));
2332
2333 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002334 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335
Bram Moolenaar734a8672019-12-02 22:49:38 +01002336 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 do
2338 {
2339 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2340 (XtInputMask)XtIMAll);
2341 } while (XtIsManaged(dialog_wgt));
2342
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002343 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 XtDestroyWidget(dialog_wgt);
2345 vim_free(tofree);
2346
2347 if (browse_fname == NULL)
2348 return NULL;
2349 return vim_strsave((char_u *)browse_fname);
2350}
2351
2352/*
2353 * The code below was originally taken from
2354 * /usr/examples/motif/xmsamplers/xmeditor.c
2355 * on Digital Unix 4.0d, but heavily modified.
2356 */
2357
2358/*
2359 * Process callback from Dialog cancel actions.
2360 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002362DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002363 Widget w UNUSED, // widget id
2364 XtPointer client_data UNUSED, // data from application
2365 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366{
2367 if (browse_fname != NULL)
2368 {
2369 XtFree(browse_fname);
2370 browse_fname = NULL;
2371 }
2372 XtUnmanageChild(dialog_wgt);
2373}
2374
2375/*
2376 * Process callback from Dialog actions.
2377 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002379DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002380 Widget w UNUSED, // widget id
2381 XtPointer client_data UNUSED, // data from application
2382 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383{
2384 XmFileSelectionBoxCallbackStruct *fcb;
2385
2386 if (browse_fname != NULL)
2387 {
2388 XtFree(browse_fname);
2389 browse_fname = NULL;
2390 }
2391 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2392
Bram Moolenaar734a8672019-12-02 22:49:38 +01002393 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2395
Bram Moolenaar734a8672019-12-02 22:49:38 +01002396 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 XtUnmanageChild(dialog_wgt);
2398}
2399
Bram Moolenaar734a8672019-12-02 22:49:38 +01002400#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401
2402#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2403
2404static int dialogStatus;
2405
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406/*
2407 * Callback function for the textfield. When CR is hit this works like
2408 * hitting the "OK" button, ESC like "Cancel".
2409 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002411keyhit_callback(
2412 Widget w,
2413 XtPointer client_data UNUSED,
2414 XEvent *event,
2415 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416{
2417 char buf[2];
2418 KeySym key_sym;
2419
2420 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2421 {
2422 if (*buf == CAR)
2423 dialogStatus = 1;
2424 else if (*buf == ESC)
2425 dialogStatus = 2;
2426 }
2427 if ((key_sym == XK_Left || key_sym == XK_Right)
2428 && !(event->xkey.state & ShiftMask))
2429 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2430}
2431
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002433butproc(
2434 Widget w UNUSED,
2435 XtPointer client_data,
2436 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437{
2438 dialogStatus = (int)(long)client_data + 1;
2439}
2440
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441#ifdef HAVE_XPM
2442
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002444create_pixmap_label(
2445 Widget parent,
2446 String name,
2447 char **data,
2448 ArgList args,
2449 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450{
2451 Widget label;
2452 Display *dsp;
2453 Screen *scr;
2454 int depth;
2455 Pixmap pixmap = 0;
2456 XpmAttributes attr;
2457 Boolean rs;
2458 XpmColorSymbol color[5] =
2459 {
2460 {"none", NULL, 0},
2461 {"iconColor1", NULL, 0},
2462 {"bottomShadowColor", NULL, 0},
2463 {"topShadowColor", NULL, 0},
2464 {"selectColor", NULL, 0}
2465 };
2466
2467 label = XmCreateLabelGadget(parent, name, args, arg);
2468
2469 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002470 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 * no way to get the background color directly from the widget itself.
2472 * In such cases we get it from The Core part of his parent instead.
2473 */
2474 dsp = XtDisplayOfObject(label);
2475 scr = XtScreenOfObject(label);
2476 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2477 ? label : XtParent(label),
2478 XmNdepth, &depth,
2479 XmNbackground, &color[0].pixel,
2480 XmNforeground, &color[1].pixel,
2481 XmNbottomShadowColor, &color[2].pixel,
2482 XmNtopShadowColor, &color[3].pixel,
2483 XmNhighlight, &color[4].pixel,
2484 NULL);
2485
2486 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2487 attr.colorsymbols = color;
2488 attr.numsymbols = 5;
2489 attr.closeness = 65535;
2490 attr.depth = depth;
2491 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2492 data, &pixmap, NULL, &attr);
2493
2494 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2495 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2496 XtVaSetValues(label,
2497 XmNlabelType, XmPIXMAP,
2498 XmNlabelPixmap, pixmap,
2499 NULL);
2500 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2501
2502 return label;
2503}
2504#endif
2505
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002507gui_mch_dialog(
2508 int type UNUSED,
2509 char_u *title,
2510 char_u *message,
2511 char_u *button_names,
2512 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002513 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002514 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515{
2516 char_u *buts;
2517 char_u *p, *next;
2518 XtAppContext app;
2519 XmString label;
2520 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002521 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 Widget dialogform = NULL;
2523 Widget form = NULL;
2524 Widget dialogtextfield = NULL;
2525 Widget *buttons;
2526 Widget sep_form = NULL;
2527 Boolean vertical;
2528 Widget separator = NULL;
2529 int n;
2530 Arg args[6];
2531#ifdef HAVE_XPM
2532 char **icon_data = NULL;
2533 Widget dialogpixmap = NULL;
2534#endif
2535
2536 if (title == NULL)
2537 title = (char_u *)_("Vim dialog");
2538
Bram Moolenaar734a8672019-12-02 22:49:38 +01002539 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 gui_mch_mousehide(FALSE);
2541
2542 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2543
Bram Moolenaar734a8672019-12-02 22:49:38 +01002544 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2546
Bram Moolenaar734a8672019-12-02 22:49:38 +01002547 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 label = XmStringCreateSimple((char *)title);
2549 if (label == NULL)
2550 return -1;
2551 XtVaSetValues(dialogform,
2552 XmNdialogTitle, label,
2553 XmNhorizontalSpacing, 4,
2554 XmNverticalSpacing, vertical ? 0 : 4,
2555 NULL);
2556 XmStringFree(label);
2557
Bram Moolenaar734a8672019-12-02 22:49:38 +01002558 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 buts = vim_strsave(button_names);
2560 if (buts == NULL)
2561 return -1;
2562
Bram Moolenaar734a8672019-12-02 22:49:38 +01002563 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 butcount = 1;
2565 for (p = buts; *p; ++p)
2566 if (*p == DLG_BUTTON_SEP)
2567 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002568 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 if (buttons == NULL)
2570 {
2571 vim_free(buts);
2572 return -1;
2573 }
2574
2575 /*
2576 * Create the buttons.
2577 */
2578 sep_form = (Widget) 0;
2579 p = buts;
2580 for (butcount = 0; *p; ++butcount)
2581 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002582 KeySym mnemonic = NUL;
2583
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 for (next = p; *next; ++next)
2585 {
2586 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002587 {
2588 int len = STRLEN(next);
2589
2590 if (len > 0)
2591 {
2592 mch_memmove(next, next + 1, len);
2593 mnemonic = next[0];
2594 }
2595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 if (*next == DLG_BUTTON_SEP)
2597 {
2598 *next++ = NUL;
2599 break;
2600 }
2601 }
2602 label = XmStringCreate(_((char *)p), STRING_TAG);
2603 if (label == NULL)
2604 break;
2605
2606 buttons[butcount] = XtVaCreateManagedWidget("button",
2607 xmPushButtonWidgetClass, dialogform,
2608 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002609 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 XmNbottomAttachment, XmATTACH_FORM,
2611 XmNbottomOffset, 4,
2612 XmNshowAsDefault, butcount == dfltbutton - 1,
2613 XmNdefaultButtonShadowThickness, 1,
2614 NULL);
2615 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002616 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617
Bram Moolenaar734a8672019-12-02 22:49:38 +01002618 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619
2620 if (butcount > 0)
2621 {
2622 if (vertical)
2623 XtVaSetValues(buttons[butcount],
2624 XmNtopWidget, buttons[butcount - 1],
2625 NULL);
2626 else
2627 {
2628 if (*next == NUL)
2629 {
2630 XtVaSetValues(buttons[butcount],
2631 XmNrightAttachment, XmATTACH_FORM,
2632 XmNrightOffset, 4,
2633 NULL);
2634
Bram Moolenaar734a8672019-12-02 22:49:38 +01002635 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 sep_form = XtVaCreateWidget("separatorForm",
2637 xmFormWidgetClass, dialogform,
2638 XmNleftAttachment, XmATTACH_WIDGET,
2639 XmNleftWidget, buttons[butcount - 1],
2640 XmNrightAttachment, XmATTACH_WIDGET,
2641 XmNrightWidget, buttons[butcount],
2642 XmNbottomAttachment, XmATTACH_FORM,
2643 XmNbottomOffset, 4,
2644 NULL);
2645 XtManageChild(sep_form);
2646 }
2647 else
2648 {
2649 XtVaSetValues(buttons[butcount],
2650 XmNleftAttachment, XmATTACH_WIDGET,
2651 XmNleftWidget, buttons[butcount - 1],
2652 NULL);
2653 }
2654 }
2655 }
2656 else if (!vertical)
2657 {
2658 if (*next == NUL)
2659 {
2660 XtVaSetValues(buttons[0],
2661 XmNrightAttachment, XmATTACH_FORM,
2662 XmNrightOffset, 4,
2663 NULL);
2664
Bram Moolenaar734a8672019-12-02 22:49:38 +01002665 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 sep_form = XtVaCreateWidget("separatorForm",
2667 xmFormWidgetClass, dialogform,
2668 XmNleftAttachment, XmATTACH_FORM,
2669 XmNleftOffset, 4,
2670 XmNrightAttachment, XmATTACH_WIDGET,
2671 XmNrightWidget, buttons[0],
2672 XmNbottomAttachment, XmATTACH_FORM,
2673 XmNbottomOffset, 4,
2674 NULL);
2675 XtManageChild(sep_form);
2676 }
2677 else
2678 XtVaSetValues(buttons[0],
2679 XmNleftAttachment, XmATTACH_FORM,
2680 XmNleftOffset, 4,
2681 NULL);
2682 }
2683
2684 XtAddCallback(buttons[butcount], XmNactivateCallback,
2685 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2686 p = next;
2687 }
2688 vim_free(buts);
2689
2690 separator = (Widget) 0;
2691 if (butcount > 0)
2692 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002693 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 n = 0;
2695 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2696 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2697 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2698 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2699 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2700 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2701 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2702 XtManageChild(separator);
2703 }
2704
2705 if (textfield != NULL)
2706 {
2707 dialogtextfield = XtVaCreateWidget("textField",
2708 xmTextFieldWidgetClass, dialogform,
2709 XmNleftAttachment, XmATTACH_FORM,
2710 XmNrightAttachment, XmATTACH_FORM,
2711 NULL);
2712 if (butcount > 0)
2713 XtVaSetValues(dialogtextfield,
2714 XmNbottomAttachment, XmATTACH_WIDGET,
2715 XmNbottomWidget, separator,
2716 NULL);
2717 else
2718 XtVaSetValues(dialogtextfield,
2719 XmNbottomAttachment, XmATTACH_FORM,
2720 NULL);
2721
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002722 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2724 XtManageChild(dialogtextfield);
2725 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2726 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2727 }
2728
Bram Moolenaar734a8672019-12-02 22:49:38 +01002729 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 form = XtVaCreateWidget("separatorForm",
2731 xmFormWidgetClass, dialogform,
2732 XmNleftAttachment, XmATTACH_FORM,
2733 XmNrightAttachment, XmATTACH_FORM,
2734 XmNtopAttachment, XmATTACH_FORM,
2735 NULL);
2736 XtManageChild(form);
2737
2738#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002739 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 switch (type)
2741 {
2742 case VIM_GENERIC:
2743 icon_data = generic_xpm;
2744 break;
2745 case VIM_ERROR:
2746 icon_data = error_xpm;
2747 break;
2748 case VIM_WARNING:
2749 icon_data = alert_xpm;
2750 break;
2751 case VIM_INFO:
2752 icon_data = info_xpm;
2753 break;
2754 case VIM_QUESTION:
2755 icon_data = quest_xpm;
2756 break;
2757 default:
2758 icon_data = generic_xpm;
2759 }
2760
2761 n = 0;
2762 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2763 XtSetArg(args[n], XmNtopOffset, 8); n++;
2764 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2765 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2766 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2767 XtSetArg(args[n], XmNleftOffset, 8); n++;
2768
2769 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2770 icon_data, args, n);
2771 XtManageChild(dialogpixmap);
2772#endif
2773
Bram Moolenaar734a8672019-12-02 22:49:38 +01002774 // Create the dialog message.
2775 // Since LessTif is apparently having problems with the creation of
2776 // properly localized string, we use LtoR here. The symptom is that the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002777 // string is not shown properly in multiple lines as it does in native
Bram Moolenaar734a8672019-12-02 22:49:38 +01002778 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002779 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 if (label == NULL)
2781 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002782 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 xmLabelGadgetClass, form,
2784 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002785 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 XmNtopAttachment, XmATTACH_FORM,
2787 XmNtopOffset, 8,
2788#ifdef HAVE_XPM
2789 XmNleftAttachment, XmATTACH_WIDGET,
2790 XmNleftWidget, dialogpixmap,
2791#else
2792 XmNleftAttachment, XmATTACH_FORM,
2793#endif
2794 XmNleftOffset, 8,
2795 XmNrightAttachment, XmATTACH_FORM,
2796 XmNrightOffset, 8,
2797 XmNbottomAttachment, XmATTACH_FORM,
2798 XmNbottomOffset, 8,
2799 NULL);
2800 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002801 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802
2803 if (textfield != NULL)
2804 {
2805 XtVaSetValues(form,
2806 XmNbottomAttachment, XmATTACH_WIDGET,
2807 XmNbottomWidget, dialogtextfield,
2808 NULL);
2809 }
2810 else
2811 {
2812 if (butcount > 0)
2813 XtVaSetValues(form,
2814 XmNbottomAttachment, XmATTACH_WIDGET,
2815 XmNbottomWidget, separator,
2816 NULL);
2817 else
2818 XtVaSetValues(form,
2819 XmNbottomAttachment, XmATTACH_FORM,
2820 NULL);
2821 }
2822
2823 if (dfltbutton < 1)
2824 dfltbutton = 1;
2825 if (dfltbutton > butcount)
2826 dfltbutton = butcount;
2827 XtVaSetValues(dialogform,
2828 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2829 if (textfield != NULL)
2830 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2831 else
2832 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2833 NULL);
2834
2835 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002836 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837
2838 if (textfield != NULL && *textfield != NUL)
2839 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002840 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 XmTextFieldSetSelection(dialogtextfield,
2842 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2843 XtLastTimestampProcessed(gui.dpy));
2844 XmTextFieldSetCursorPosition(dialogtextfield,
2845 (XmTextPosition)STRLEN(textfield));
2846 }
2847
2848 app = XtWidgetToApplicationContext(dialogform);
2849
Bram Moolenaar734a8672019-12-02 22:49:38 +01002850 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 dialogStatus = -1;
2852 for (;;)
2853 {
2854 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2855 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2856 break;
2857 }
2858
2859 vim_free(buttons);
2860
2861 if (textfield != NULL)
2862 {
2863 p = (char_u *)XmTextGetString(dialogtextfield);
2864 if (p == NULL || dialogStatus < 0)
2865 *textfield = NUL;
2866 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002867 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002868 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 }
2870
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002871 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 XtDestroyWidget(dialogform);
2873
2874 return dialogStatus;
2875}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002876#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877
2878#if defined(FEAT_FOOTER) || defined(PROTO)
2879
2880 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002881gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002883 Dimension height; // total Toolbar height
2884 Dimension top; // XmNmarginTop
2885 Dimension bottom; // XmNmarginBottom
2886 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887
2888 XtVaGetValues(footer,
2889 XmNheight, &height,
2890 XmNmarginTop, &top,
2891 XmNmarginBottom, &bottom,
2892 XmNshadowThickness, &shadow,
2893 NULL);
2894
2895 return (int) height + top + bottom + (shadow << 1);
2896}
2897
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002899gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900{
2901 if (showit)
2902 {
2903 gui.footer_height = gui_mch_compute_footer_height();
2904 XtManageChild(footer);
2905 }
2906 else
2907 {
2908 gui.footer_height = 0;
2909 XtUnmanageChild(footer);
2910 }
2911 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2912}
2913
2914 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002915gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916{
2917 XmString xms;
2918
2919 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002920 if (xms != NULL)
2921 {
2922 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2923 XmStringFree(xms);
2924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925}
2926
2927#endif
2928
2929
2930#if defined(FEAT_TOOLBAR) || defined(PROTO)
2931 void
2932gui_mch_show_toolbar(int showit)
2933{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002934 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935
2936 if (toolBar == (Widget)0)
2937 return;
2938 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2939 if (showit && numChildren > 0)
2940 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002941 // Assume that we want to show the toolbar if p_toolbar contains
2942 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 WidgetList children;
2944
2945 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2946 {
2947 void (*action)(BalloonEval *);
2948 int text = 0;
2949
2950 if (strstr((const char *)p_toolbar, "tooltips"))
2951 action = &gui_mch_enable_beval_area;
2952 else
2953 action = &gui_mch_disable_beval_area;
2954 if (strstr((const char *)p_toolbar, "text"))
2955 text = 1;
2956 else if (strstr((const char *)p_toolbar, "icons"))
2957 text = -1;
2958 if (text != 0)
2959 {
2960 vimmenu_T *toolbar;
2961 vimmenu_T *cur;
2962
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002963 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 if (menu_is_toolbar(toolbar->dname))
2965 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002966 // Assumption: toolbar is NULL if there is no toolbar,
2967 // otherwise it contains the toolbar menu structure.
2968 //
2969 // Assumption: "numChildren" == the number of items in the list
2970 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 if (toolbar)
2972 {
2973 for (cur = toolbar->children; cur; cur = cur->next)
2974 {
2975 Arg args[1];
2976 int n = 0;
2977
Bram Moolenaar734a8672019-12-02 22:49:38 +01002978 // Enable/Disable tooltip (OK to enable while
2979 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 if (cur->tip != NULL)
2981 (*action)(cur->tip);
2982 if (!menu_is_separator(cur->name))
2983 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002984 if (text == 1 || cur->xpm == NULL)
2985 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002987 ++n;
2988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 if (cur->id != NULL)
2990 {
2991 XtUnmanageChild(cur->id);
2992 XtSetValues(cur->id, args, n);
2993 XtManageChild(cur->id);
2994 }
2995 }
2996 }
2997 }
2998 }
2999 }
3000 gui.toolbar_height = gui_mch_compute_toolbar_height();
3001 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003002#ifdef FEAT_GUI_TABLINE
3003 if (showing_tabline)
3004 {
3005 XtVaSetValues(tabLine,
3006 XmNtopAttachment, XmATTACH_WIDGET,
3007 XmNtopWidget, XtParent(toolBar),
3008 NULL);
3009 XtVaSetValues(textAreaForm,
3010 XmNtopAttachment, XmATTACH_WIDGET,
3011 XmNtopWidget, tabLine,
3012 NULL);
3013 }
3014 else
3015#endif
3016 XtVaSetValues(textAreaForm,
3017 XmNtopAttachment, XmATTACH_WIDGET,
3018 XmNtopWidget, XtParent(toolBar),
3019 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 if (XtIsManaged(menuBar))
3021 XtVaSetValues(XtParent(toolBar),
3022 XmNtopAttachment, XmATTACH_WIDGET,
3023 XmNtopWidget, menuBar,
3024 NULL);
3025 else
3026 XtVaSetValues(XtParent(toolBar),
3027 XmNtopAttachment, XmATTACH_FORM,
3028 NULL);
3029 }
3030 else
3031 {
3032 gui.toolbar_height = 0;
3033 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003034 {
3035#ifdef FEAT_GUI_TABLINE
3036 if (showing_tabline)
3037 {
3038 XtVaSetValues(tabLine,
3039 XmNtopAttachment, XmATTACH_WIDGET,
3040 XmNtopWidget, menuBar,
3041 NULL);
3042 XtVaSetValues(textAreaForm,
3043 XmNtopAttachment, XmATTACH_WIDGET,
3044 XmNtopWidget, tabLine,
3045 NULL);
3046 }
3047 else
3048#endif
3049 XtVaSetValues(textAreaForm,
3050 XmNtopAttachment, XmATTACH_WIDGET,
3051 XmNtopWidget, menuBar,
3052 NULL);
3053 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003055 {
3056#ifdef FEAT_GUI_TABLINE
3057 if (showing_tabline)
3058 {
3059 XtVaSetValues(tabLine,
3060 XmNtopAttachment, XmATTACH_FORM,
3061 NULL);
3062 XtVaSetValues(textAreaForm,
3063 XmNtopAttachment, XmATTACH_WIDGET,
3064 XmNtopWidget, tabLine,
3065 NULL);
3066 }
3067 else
3068#endif
3069 XtVaSetValues(textAreaForm,
3070 XmNtopAttachment, XmATTACH_FORM,
3071 NULL);
3072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073
3074 XtUnmanageChild(XtParent(toolBar));
3075 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003076 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077}
3078
3079/*
3080 * A toolbar button has been pushed; now reset the input focus
3081 * such that the user can type page up/down etc. and have the
3082 * input go to the editor window, not the button
3083 */
3084 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003085reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086{
3087 if (textArea != NULL)
3088 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3089}
3090
3091 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003092gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003094 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003095 Dimension height; // total Toolbar height
3096 Dimension whgt; // height of each widget
3097 WidgetList children; // list of toolBar's children
3098 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 int i;
3100
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003101 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003104 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003105 Dimension fst;
3106 Dimension fmh;
3107 Dimension tst;
3108 Dimension tmh;
3109
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003111 XmNshadowThickness, &fst,
3112 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003114 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003116 XmNshadowThickness, &tst,
3117 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 XmNchildren, &children,
3119 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003120 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003121 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 {
3123 whgt = 0;
3124 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3125 if (height < whgt)
3126 height = whgt;
3127 }
3128 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003129#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003130 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003131 if (height < 10)
3132 height = 24;
3133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003135 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136}
3137
Bram Moolenaar7c626922005-02-07 22:01:03 +00003138 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003139motif_get_toolbar_colors(
3140 Pixel *bgp,
3141 Pixel *fgp,
3142 Pixel *bsp,
3143 Pixel *tsp,
3144 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003145{
3146 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003147 XmNbackground, bgp,
3148 XmNforeground, fgp,
3149 XmNbottomShadowColor, bsp,
3150 XmNtopShadowColor, tsp,
3151 XmNhighlightColor, hsp,
3152 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003153}
3154
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155# ifdef FEAT_FOOTER
3156/*
3157 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003158 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 * get implemented and the user will have a choice.
3160 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003162toolbarbutton_enter_cb(
3163 Widget w UNUSED,
3164 XtPointer client_data,
3165 XEvent *event UNUSED,
3166 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167{
3168 vimmenu_T *menu = (vimmenu_T *) client_data;
3169
3170 if (menu->strings[MENU_INDEX_TIP] != NULL)
3171 {
3172 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3173 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3174 }
3175}
3176
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003178toolbarbutton_leave_cb(
3179 Widget w UNUSED,
3180 XtPointer client_data UNUSED,
3181 XEvent *event UNUSED,
3182 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183{
3184 gui_mch_set_footer((char_u *) "");
3185}
3186# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187#endif
3188
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003189#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3190/*
3191 * Show or hide the tabline.
3192 */
3193 void
3194gui_mch_show_tabline(int showit)
3195{
3196 if (tabLine == (Widget)0)
3197 return;
3198
3199 if (!showit != !showing_tabline)
3200 {
3201 if (showit)
3202 {
3203 XtManageChild(tabLine);
3204 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003205 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3206 XtUnmanageChild(XtNameToWidget(tabLine,
3207 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003208#ifdef FEAT_MENU
3209# ifdef FEAT_TOOLBAR
3210 if (XtIsManaged(XtParent(toolBar)))
3211 XtVaSetValues(tabLine,
3212 XmNtopAttachment, XmATTACH_WIDGET,
3213 XmNtopWidget, XtParent(toolBar), NULL);
3214 else
3215# endif
3216 if (XtIsManaged(menuBar))
3217 XtVaSetValues(tabLine,
3218 XmNtopAttachment, XmATTACH_WIDGET,
3219 XmNtopWidget, menuBar, NULL);
3220 else
3221#endif
3222 XtVaSetValues(tabLine,
3223 XmNtopAttachment, XmATTACH_FORM, NULL);
3224 XtVaSetValues(textAreaForm,
3225 XmNtopAttachment, XmATTACH_WIDGET,
3226 XmNtopWidget, tabLine,
3227 NULL);
3228 }
3229 else
3230 {
3231 XtUnmanageChild(tabLine);
3232#ifdef FEAT_MENU
3233# ifdef FEAT_TOOLBAR
3234 if (XtIsManaged(XtParent(toolBar)))
3235 XtVaSetValues(textAreaForm,
3236 XmNtopAttachment, XmATTACH_WIDGET,
3237 XmNtopWidget, XtParent(toolBar), NULL);
3238 else
3239# endif
3240 if (XtIsManaged(menuBar))
3241 XtVaSetValues(textAreaForm,
3242 XmNtopAttachment, XmATTACH_WIDGET,
3243 XmNtopWidget, menuBar, NULL);
3244 else
3245#endif
3246 XtVaSetValues(textAreaForm,
3247 XmNtopAttachment, XmATTACH_FORM, NULL);
3248 }
3249 showing_tabline = showit;
3250 }
3251}
3252
3253/*
3254 * Return TRUE when tabline is displayed.
3255 */
3256 int
3257gui_mch_showing_tabline(void)
3258{
3259 return tabLine != (Widget)0 && showing_tabline;
3260}
3261
3262/*
3263 * Update the labels of the tabline.
3264 */
3265 void
3266gui_mch_update_tabline(void)
3267{
3268 tabpage_T *tp;
3269 int nr = 1, n;
3270 Arg args[10];
3271 int curtabidx = 0, currentpage;
3272 Widget tab;
3273 XmNotebookPageInfo page_info;
3274 XmNotebookPageStatus page_status;
3275 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003276 XmString label_str;
3277 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003278 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003279
3280 if (tabLine == (Widget)0)
3281 return;
3282
Bram Moolenaar734a8672019-12-02 22:49:38 +01003283 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003284 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3285 {
3286 if (tp == curtab)
3287 curtabidx = nr;
3288
3289 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3290 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003291 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003292 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003293 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003294 n = 0;
3295 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3296 XtSetArg(args[n], XmNtraversalOn, False); n++;
3297 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3298 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3299 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3300 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3301 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003302 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3303 NULL);
3304 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003305 }
3306 else
3307 tab = page_info.major_tab_widget;
3308
3309 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003310
3311 /*
3312 * Change the label text only if it is different
3313 */
3314 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3315 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3316 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003317 get_tabline_label(tp, FALSE);
3318 if (STRCMP(label_cstr, NameBuff) != 0)
3319 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003320 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3321 NameBuff, STRLEN(NameBuff) + 1, NULL);
3322 /*
3323 * Force a resize of the tab label button
3324 */
3325 XtUnmanageChild(tab);
3326 XtManageChild(tab);
3327 }
3328 XtFree(label_cstr);
3329 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003330 }
3331
3332 tab_count = nr - 1;
3333
3334 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3335
Bram Moolenaar734a8672019-12-02 22:49:38 +01003336 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003337 while (nr <= last_page)
3338 {
3339 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3340 && page_info.page_number == nr
3341 && page_info.major_tab_widget != (Widget)0)
3342 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003343 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3344 if (beval != NULL)
3345 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003346 XtUnmanageChild(page_info.major_tab_widget);
3347 XtDestroyWidget(page_info.major_tab_widget);
3348 }
3349 nr++;
3350 }
3351
3352 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3353
3354 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3355 if (currentpage != curtabidx)
3356 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3357}
3358
3359/*
3360 * Set the current tab to "nr". First tab is 1.
3361 */
3362 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003363gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003364{
3365 int currentpage;
3366
3367 if (tabLine == (Widget)0)
3368 return;
3369
3370 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3371 if (currentpage != nr)
3372 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3373}
3374#endif
3375
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376/*
3377 * Set the colors of Widget "id" to the menu colors.
3378 */
3379 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003380gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381{
3382 if (gui.menu_bg_pixel != INVALCOLOR)
3383#if (XmVersion >= 1002)
3384 XmChangeColor(id, gui.menu_bg_pixel);
3385#else
3386 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3387#endif
3388 if (gui.menu_fg_pixel != INVALCOLOR)
3389 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3390}
3391
3392/*
3393 * Set the colors of Widget "id" to the scrollbar colors.
3394 */
3395 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003396gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397{
3398 if (gui.scroll_bg_pixel != INVALCOLOR)
3399#if (XmVersion >= 1002)
3400 XmChangeColor(id, gui.scroll_bg_pixel);
3401#else
3402 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3403#endif
3404 if (gui.scroll_fg_pixel != INVALCOLOR)
3405 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3406}
3407
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408/*
3409 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3410 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003411 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003412gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003414#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415#ifdef FONTSET_ALWAYS
3416 if (gui.menu_fontset != NOFONTSET)
3417 {
3418 XmFontList fl;
3419
3420 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3421 if (fl != NULL)
3422 {
3423 if (XtIsManaged(id))
3424 {
3425 XtUnmanageChild(id);
3426 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003427 // We should force the widget to recalculate its
3428 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 XtManageChild(id);
3430 }
3431 else
3432 XtVaSetValues(id, XmNfontList, fl, NULL);
3433 XmFontListFree(fl);
3434 }
3435 }
3436#else
3437 if (gui.menu_font != NOFONT)
3438 {
3439 XmFontList fl;
3440
3441 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3442 if (fl != NULL)
3443 {
3444 if (XtIsManaged(id))
3445 {
3446 XtUnmanageChild(id);
3447 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003448 // We should force the widget to recalculate its
3449 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 XtManageChild(id);
3451 }
3452 else
3453 XtVaSetValues(id, XmNfontList, fl, NULL);
3454 XmFontListFree(fl);
3455 }
3456 }
3457#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459}
3460
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461
3462/*
3463 * We don't create it twice for the sake of speed.
3464 */
3465
3466typedef struct _SharedFindReplace
3467{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003468 Widget dialog; // the main dialog widget
3469 Widget wword; // 'Exact match' check button
3470 Widget mcase; // 'match case' check button
3471 Widget up; // search direction 'Up' radio button
3472 Widget down; // search direction 'Down' radio button
3473 Widget what; // 'Find what' entry text widget
3474 Widget with; // 'Replace with' entry text widget
3475 Widget find; // 'Find Next' action button
3476 Widget replace; // 'Replace With' action button
3477 Widget all; // 'Replace All' action button
3478 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479
3480 Widget cancel;
3481} SharedFindReplace;
3482
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003483static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3484static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003487find_replace_destroy_callback(
3488 Widget w UNUSED,
3489 XtPointer client_data,
3490 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491{
3492 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3493
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003494 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003495 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 cd->dialog = (Widget)0;
3497}
3498
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003500find_replace_dismiss_callback(
3501 Widget w UNUSED,
3502 XtPointer client_data,
3503 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504{
3505 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3506
3507 if (cd != NULL)
3508 XtUnmanageChild(cd->dialog);
3509}
3510
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003512entry_activate_callback(
3513 Widget w UNUSED,
3514 XtPointer client_data,
3515 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516{
3517 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3518}
3519
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003521find_replace_callback(
3522 Widget w UNUSED,
3523 XtPointer client_data,
3524 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003525{
3526 long_u flags = (long_u)client_data;
3527 char *find_text, *repl_text;
3528 Boolean direction_down = TRUE;
3529 Boolean wword;
3530 Boolean mcase;
3531 SharedFindReplace *sfr;
3532
3533 if (flags == FRD_UNDO)
3534 {
3535 char_u *save_cpo = p_cpo;
3536
Bram Moolenaar734a8672019-12-02 22:49:38 +01003537 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003538 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539 u_undo(1);
3540 p_cpo = save_cpo;
3541 gui_update_screen();
3542 return;
3543 }
3544
Bram Moolenaar734a8672019-12-02 22:49:38 +01003545 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 if (flags == FRD_FINDNEXT)
3547 {
3548 repl_text = NULL;
3549 sfr = &find_widgets;
3550 }
3551 else
3552 {
3553 repl_text = XmTextFieldGetString(repl_widgets.with);
3554 sfr = &repl_widgets;
3555 }
3556 find_text = XmTextFieldGetString(sfr->what);
3557 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3558 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3559 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3560 if (wword)
3561 flags |= FRD_WHOLE_WORD;
3562 if (mcase)
3563 flags |= FRD_MATCH_CASE;
3564
3565 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3566 direction_down);
3567
3568 if (find_text != NULL)
3569 XtFree(find_text);
3570 if (repl_text != NULL)
3571 XtFree(repl_text);
3572}
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003575find_replace_keypress(
3576 Widget w UNUSED,
3577 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003578 XKeyEvent *event,
3579 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580{
3581 KeySym keysym;
3582
3583 if (frdp == NULL)
3584 return;
3585
3586 keysym = XLookupKeysym(event, 0);
3587
Bram Moolenaar734a8672019-12-02 22:49:38 +01003588 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 if (keysym == XK_Escape)
3590 XtUnmanageChild(frdp->dialog);
3591}
3592
3593 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003594set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003595{
3596 XmString str;
3597 char_u *p, *next;
3598 KeySym mnemonic = NUL;
3599
3600 if (!w)
3601 return;
3602
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003603 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003604 if (p == NULL)
3605 return;
3606 for (next = p; *next; ++next)
3607 {
3608 if (*next == DLG_HOTKEY_CHAR)
3609 {
3610 int len = STRLEN(next);
3611
3612 if (len > 0)
3613 {
3614 mch_memmove(next, next + 1, len);
3615 mnemonic = next[0];
3616 }
3617 }
3618 }
3619
3620 str = XmStringCreateSimple((char *)p);
3621 vim_free(p);
3622 if (str)
3623 {
3624 XtVaSetValues(w,
3625 XmNlabelString, str,
3626 XmNmnemonic, mnemonic,
3627 NULL);
3628 XmStringFree(str);
3629 }
3630 gui_motif_menu_fontlist(w);
3631}
3632
3633 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003634find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635{
3636 SharedFindReplace *frdp;
3637 Widget separator;
3638 Widget input_form;
3639 Widget button_form;
3640 Widget toggle_form;
3641 Widget frame;
3642 XmString str;
3643 int n;
3644 Arg args[6];
3645 int wword = FALSE;
3646 int mcase = !p_ic;
3647 Dimension width;
3648 Dimension widest;
3649 char_u *entry_text;
3650
3651 frdp = do_replace ? &repl_widgets : &find_widgets;
3652
Bram Moolenaar734a8672019-12-02 22:49:38 +01003653 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3655
Bram Moolenaar734a8672019-12-02 22:49:38 +01003656 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 if (frdp->dialog)
3658 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003659 gui_motif_synch_fonts();
3660
Bram Moolenaar734a8672019-12-02 22:49:38 +01003661 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 if (XtIsManaged(frdp->dialog))
3663 XMapRaised(XtDisplay(frdp->dialog),
3664 XtWindow(XtParent(frdp->dialog)));
3665 else
3666 XtManageChild(frdp->dialog);
3667 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3668 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3669
3670 if (entry_text != NULL)
3671 XmTextFieldSetString(frdp->what, (char *)entry_text);
3672 vim_free(entry_text);
3673
3674 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3675 return;
3676 }
3677
Bram Moolenaar734a8672019-12-02 22:49:38 +01003678 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 if (do_replace)
3680 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3681 else
3682 str = XmStringCreateSimple(_("VIM - Search..."));
3683
3684 n = 0;
3685 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3686 XtSetArg(args[n], XmNnoResize, True); n++;
3687 XtSetArg(args[n], XmNdialogTitle, str); n++;
3688
3689 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3690 XmStringFree(str);
3691 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3692 find_replace_destroy_callback, frdp);
3693
3694 button_form = XtVaCreateWidget("buttonForm",
3695 xmFormWidgetClass, frdp->dialog,
3696 XmNrightAttachment, XmATTACH_FORM,
3697 XmNrightOffset, 4,
3698 XmNtopAttachment, XmATTACH_FORM,
3699 XmNtopOffset, 4,
3700 XmNbottomAttachment, XmATTACH_FORM,
3701 XmNbottomOffset, 4,
3702 NULL);
3703
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 frdp->find = XtVaCreateManagedWidget("findButton",
3705 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 XmNsensitive, True,
3707 XmNtopAttachment, XmATTACH_FORM,
3708 XmNleftAttachment, XmATTACH_FORM,
3709 XmNrightAttachment, XmATTACH_FORM,
3710 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003711 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712
3713 XtAddCallback(frdp->find, XmNactivateCallback,
3714 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003715 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716
3717 if (do_replace)
3718 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003719 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3720 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003721 XmNtopAttachment, XmATTACH_WIDGET,
3722 XmNtopWidget, frdp->find,
3723 XmNleftAttachment, XmATTACH_FORM,
3724 XmNrightAttachment, XmATTACH_FORM,
3725 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003726 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 XtAddCallback(frdp->replace, XmNactivateCallback,
3728 find_replace_callback, (XtPointer)FRD_REPLACE);
3729
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3731 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 XmNtopAttachment, XmATTACH_WIDGET,
3733 XmNtopWidget, frdp->replace,
3734 XmNleftAttachment, XmATTACH_FORM,
3735 XmNrightAttachment, XmATTACH_FORM,
3736 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003737 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 XtAddCallback(frdp->all, XmNactivateCallback,
3739 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3740
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741 frdp->undo = XtVaCreateManagedWidget("undoButton",
3742 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 XmNtopAttachment, XmATTACH_WIDGET,
3744 XmNtopWidget, frdp->all,
3745 XmNleftAttachment, XmATTACH_FORM,
3746 XmNrightAttachment, XmATTACH_FORM,
3747 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003748 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 XtAddCallback(frdp->undo, XmNactivateCallback,
3750 find_replace_callback, (XtPointer)FRD_UNDO);
3751 }
3752
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3754 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 XmNleftAttachment, XmATTACH_FORM,
3756 XmNrightAttachment, XmATTACH_FORM,
3757 XmNbottomAttachment, XmATTACH_FORM,
3758 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003759 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 XtAddCallback(frdp->cancel, XmNactivateCallback,
3761 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003762 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763
3764 XtManageChild(button_form);
3765
3766 n = 0;
3767 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3768 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3769 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3770 XtSetArg(args[n], XmNrightOffset, 4); n++;
3771 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3772 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3773 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3774 XtManageChild(separator);
3775
3776 input_form = XtVaCreateWidget("inputForm",
3777 xmFormWidgetClass, frdp->dialog,
3778 XmNleftAttachment, XmATTACH_FORM,
3779 XmNleftOffset, 4,
3780 XmNrightAttachment, XmATTACH_WIDGET,
3781 XmNrightWidget, separator,
3782 XmNrightOffset, 4,
3783 XmNtopAttachment, XmATTACH_FORM,
3784 XmNtopOffset, 4,
3785 NULL);
3786
3787 {
3788 Widget label_what;
3789 Widget label_with = (Widget)0;
3790
3791 str = XmStringCreateSimple(_("Find what:"));
3792 label_what = XtVaCreateManagedWidget("whatLabel",
3793 xmLabelGadgetClass, input_form,
3794 XmNlabelString, str,
3795 XmNleftAttachment, XmATTACH_FORM,
3796 XmNtopAttachment, XmATTACH_FORM,
3797 XmNtopOffset, 4,
3798 NULL);
3799 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003800 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801
3802 frdp->what = XtVaCreateManagedWidget("whatText",
3803 xmTextFieldWidgetClass, input_form,
3804 XmNtopAttachment, XmATTACH_FORM,
3805 XmNrightAttachment, XmATTACH_FORM,
3806 XmNleftAttachment, XmATTACH_FORM,
3807 NULL);
3808
3809 if (do_replace)
3810 {
3811 frdp->with = XtVaCreateManagedWidget("withText",
3812 xmTextFieldWidgetClass, input_form,
3813 XmNtopAttachment, XmATTACH_WIDGET,
3814 XmNtopWidget, frdp->what,
3815 XmNtopOffset, 4,
3816 XmNleftAttachment, XmATTACH_FORM,
3817 XmNrightAttachment, XmATTACH_FORM,
3818 XmNbottomAttachment, XmATTACH_FORM,
3819 NULL);
3820
3821 XtAddCallback(frdp->with, XmNactivateCallback,
3822 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3823
3824 str = XmStringCreateSimple(_("Replace with:"));
3825 label_with = XtVaCreateManagedWidget("withLabel",
3826 xmLabelGadgetClass, input_form,
3827 XmNlabelString, str,
3828 XmNleftAttachment, XmATTACH_FORM,
3829 XmNtopAttachment, XmATTACH_WIDGET,
3830 XmNtopWidget, frdp->what,
3831 XmNtopOffset, 4,
3832 XmNbottomAttachment, XmATTACH_FORM,
3833 NULL);
3834 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003835 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836
3837 /*
3838 * Make the entry activation only change the input focus onto the
3839 * with item.
3840 */
3841 XtAddCallback(frdp->what, XmNactivateCallback,
3842 entry_activate_callback, frdp->with);
3843 XtAddEventHandler(frdp->with, KeyPressMask, False,
3844 (XtEventHandler)find_replace_keypress,
3845 (XtPointer) frdp);
3846
3847 }
3848 else
3849 {
3850 /*
3851 * Make the entry activation do the search.
3852 */
3853 XtAddCallback(frdp->what, XmNactivateCallback,
3854 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3855 }
3856 XtAddEventHandler(frdp->what, KeyPressMask, False,
3857 (XtEventHandler)find_replace_keypress,
3858 (XtPointer)frdp);
3859
Bram Moolenaar734a8672019-12-02 22:49:38 +01003860 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 n = 0;
3862 XtSetArg(args[n], XmNwidth, &width); n++;
3863 XtGetValues(label_what, args, n);
3864 widest = width;
3865 if (do_replace)
3866 {
3867 XtGetValues(label_with, args, n);
3868 if (width > widest)
3869 widest = width;
3870 }
3871
3872 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3873 if (do_replace)
3874 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3875
3876 }
3877
3878 XtManageChild(input_form);
3879
3880 {
3881 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003882 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883
3884 frame = XtVaCreateWidget("directionFrame",
3885 xmFrameWidgetClass, frdp->dialog,
3886 XmNtopAttachment, XmATTACH_WIDGET,
3887 XmNtopWidget, input_form,
3888 XmNtopOffset, 4,
3889 XmNbottomAttachment, XmATTACH_FORM,
3890 XmNbottomOffset, 4,
3891 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3892 XmNrightWidget, input_form,
3893 NULL);
3894
3895 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003896 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 xmLabelGadgetClass, frame,
3898 XmNlabelString, str,
3899 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3900 XmNchildType, XmFRAME_TITLE_CHILD,
3901 NULL);
3902 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003903 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904
3905 radio_box = XmCreateRadioBox(frame, "radioBox",
3906 (ArgList)NULL, 0);
3907
3908 str = XmStringCreateSimple( _("Up"));
3909 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3910 xmToggleButtonGadgetClass, radio_box,
3911 XmNlabelString, str,
3912 XmNset, False,
3913 NULL);
3914 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003915 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916
3917 str = XmStringCreateSimple(_("Down"));
3918 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3919 xmToggleButtonGadgetClass, radio_box,
3920 XmNlabelString, str,
3921 XmNset, True,
3922 NULL);
3923 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003924 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925
3926 XtManageChild(radio_box);
3927 XtManageChild(frame);
3928 }
3929
3930 toggle_form = XtVaCreateWidget("toggleForm",
3931 xmFormWidgetClass, frdp->dialog,
3932 XmNleftAttachment, XmATTACH_FORM,
3933 XmNleftOffset, 4,
3934 XmNrightAttachment, XmATTACH_WIDGET,
3935 XmNrightWidget, frame,
3936 XmNrightOffset, 4,
3937 XmNtopAttachment, XmATTACH_WIDGET,
3938 XmNtopWidget, input_form,
3939 XmNtopOffset, 4,
3940 XmNbottomAttachment, XmATTACH_FORM,
3941 XmNbottomOffset, 4,
3942 NULL);
3943
3944 str = XmStringCreateSimple(_("Match whole word only"));
3945 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3946 xmToggleButtonGadgetClass, toggle_form,
3947 XmNlabelString, str,
3948 XmNtopAttachment, XmATTACH_FORM,
3949 XmNtopOffset, 4,
3950 XmNleftAttachment, XmATTACH_FORM,
3951 XmNleftOffset, 4,
3952 XmNset, wword,
3953 NULL);
3954 XmStringFree(str);
3955
3956 str = XmStringCreateSimple(_("Match case"));
3957 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3958 xmToggleButtonGadgetClass, toggle_form,
3959 XmNlabelString, str,
3960 XmNleftAttachment, XmATTACH_FORM,
3961 XmNleftOffset, 4,
3962 XmNtopAttachment, XmATTACH_WIDGET,
3963 XmNtopWidget, frdp->wword,
3964 XmNtopOffset, 4,
3965 XmNset, mcase,
3966 NULL);
3967 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003968 gui_motif_menu_fontlist(frdp->wword);
3969 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970
3971 XtManageChild(toggle_form);
3972
3973 if (entry_text != NULL)
3974 XmTextFieldSetString(frdp->what, (char *)entry_text);
3975 vim_free(entry_text);
3976
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003977 gui_motif_synch_fonts();
3978
3979 manage_centered(frdp->dialog);
3980 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3982}
3983
3984 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003985gui_mch_find_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, FALSE);
3991}
3992
3993
3994 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003995gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996{
3997 if (!gui.in_use)
3998 return;
3999
4000 find_replace_dialog_create(eap->arg, TRUE);
4001}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004002
4003/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00004004 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004005 * main text font used. Those are in esp. the find/replace dialogs.
4006 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01004007 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004008 */
4009 void
4010gui_motif_synch_fonts(void)
4011{
4012 SharedFindReplace *frdp;
4013 int do_replace;
4014 XFontStruct *font;
4015 XmFontList font_list;
4016
Bram Moolenaar734a8672019-12-02 22:49:38 +01004017 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4018 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004019 font = (XFontStruct *)gui.norm_font;
4020 if (font == NULL)
4021 return;
4022
4023 font_list = gui_motif_create_fontlist(font);
4024
Bram Moolenaar734a8672019-12-02 22:49:38 +01004025 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004026 for (do_replace = 0; do_replace <= 1; ++do_replace)
4027 {
4028 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4029 if (frdp->dialog)
4030 {
4031 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4032 if (do_replace)
4033 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4034 }
4035 }
4036
4037 XmFontListFree(font_list);
4038}