blob: 97b0bf98e6d39a695119bd1bd3b215b1fc4bb3bf [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 Moolenaar9dd42a62022-03-24 18:04:49 +0000145 XtPointer cmd, tab_idx;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000146
147 XtVaGetValues(w, XmNuserData, &cmd, NULL);
148 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
149
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000150 send_tabline_menu_event((int)(long)tab_idx, (int)(long)cmd);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000151}
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
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000257 XtVaSetValues(tabLine_menu, XmNuserData, (XtPointer)(long)tab_idx, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000258 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 Moolenaar071d4272004-06-13 20:20:40 +0000443 gui_motif_menu_colors(menuBar);
444 }
445#endif
446
447#ifdef FEAT_TOOLBAR
448 /*
449 * Create an empty ToolBar. We should get buttons defined from menu.vim.
450 */
451 toolBarFrame = XtVaCreateWidget("toolBarFrame",
452 xmFrameWidgetClass, vimForm,
453 XmNshadowThickness, 0,
454 XmNmarginHeight, 0,
455 XmNmarginWidth, 0,
456 XmNleftAttachment, XmATTACH_FORM,
457 XmNrightAttachment, XmATTACH_FORM,
458 NULL);
459 gui_motif_menu_colors(toolBarFrame);
460
461 toolBar = XtVaCreateManagedWidget("toolBar",
462 xmRowColumnWidgetClass, toolBarFrame,
463 XmNchildType, XmFRAME_WORKAREA_CHILD,
464 XmNrowColumnType, XmWORK_AREA,
465 XmNorientation, XmHORIZONTAL,
466 XmNtraversalOn, False,
467 XmNisHomogeneous, False,
468 XmNpacking, XmPACK_TIGHT,
469 XmNspacing, 0,
470 XmNshadowThickness, 0,
471 XmNhighlightThickness, 0,
472 XmNmarginHeight, 0,
473 XmNmarginWidth, 0,
474 XmNadjustLast, True,
475 NULL);
476 gui_motif_menu_colors(toolBar);
477
Bram Moolenaar071d4272004-06-13 20:20:40 +0000478#endif
479
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000480#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100481 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000482 n = 0;
483 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
484 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
485 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
486 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
487 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
488 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
489 XtSetArg(args[n], XmNshadowThickness, 0); n++;
490 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
491 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
492 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
493
494 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
495 NULL);
496 XtAddEventHandler(tabLine, ButtonPressMask, False,
497 (XtEventHandler)tabline_menu_cb, NULL);
498
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000499 gui.tabline_height = TABLINE_HEIGHT;
500
Bram Moolenaar18144c82006-04-12 21:52:12 +0000501 /*
502 * Set the size of the minor next/prev scrollers to zero, so
503 * that they are not displayed. Due to a bug in OpenMotif 2.3,
504 * even if these children widget are unmanaged, they are again
505 * managed by the Notebook widget and the notebook widget geometry
506 * is adjusted to account for the minor scroller widgets.
507 */
508 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
509 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
510 XmNtraversalOn, False, NULL);
511 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
512 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
513 XmNtraversalOn, False, NULL);
514
Bram Moolenaar29547192018-12-11 20:39:19 +0100515 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000516 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
517
Bram Moolenaar29547192018-12-11 20:39:19 +0100518 // Add the buttons to the tabline popup menu
519 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000520 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_CLOSE); n++;
Bram Moolenaar29547192018-12-11 20:39:19 +0100521 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
522 XtSetArg(args[n], XmNlabelString, xms); n++;
523 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
524 XtAddCallback(button, XmNactivateCallback,
525 (XtCallbackProc)tabline_button_cb, NULL);
526 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000527
528 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000529 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_NEW); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000530 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
531 XtSetArg(args[n], XmNlabelString, xms); n++;
532 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
533 XtAddCallback(button, XmNactivateCallback,
534 (XtCallbackProc)tabline_button_cb, NULL);
535 XmStringFree(xms);
536
537 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000538 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_OPEN); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000539 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
540 XtSetArg(args[n], XmNlabelString, xms); n++;
541 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
542 XtAddCallback(button, XmNactivateCallback,
543 (XtCallbackProc)tabline_button_cb, NULL);
544 XmStringFree(xms);
545#endif
546
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
548 xmFormWidgetClass, vimForm,
549 XmNleftAttachment, XmATTACH_FORM,
550 XmNrightAttachment, XmATTACH_FORM,
551 XmNbottomAttachment, XmATTACH_FORM,
552 XmNtopAttachment, XmATTACH_FORM,
553 XmNmarginWidth, 0,
554 XmNmarginHeight, 0,
555 XmNresizePolicy, XmRESIZE_ANY,
556 NULL);
557 gui_motif_scroll_colors(textAreaForm);
558
559 textArea = XtVaCreateManagedWidget("textArea",
560 xmDrawingAreaWidgetClass, textAreaForm,
561 XmNforeground, gui.norm_pixel,
562 XmNbackground, gui.back_pixel,
563 XmNleftAttachment, XmATTACH_FORM,
564 XmNtopAttachment, XmATTACH_FORM,
565 XmNrightAttachment, XmATTACH_FORM,
566 XmNbottomAttachment, XmATTACH_FORM,
567
568 /*
569 * These take some control away from the user, but avoids making them
570 * add resources to get a decent looking setup.
571 */
572 XmNborderWidth, 0,
573 XmNhighlightThickness, 0,
574 XmNshadowThickness, 0,
575 NULL);
576
577#ifdef FEAT_FOOTER
578 /*
579 * Create the Footer.
580 */
581 footer = XtVaCreateWidget("footer",
582 xmLabelGadgetClass, vimForm,
583 XmNalignment, XmALIGNMENT_BEGINNING,
584 XmNmarginHeight, 0,
585 XmNmarginWidth, 0,
586 XmNtraversalOn, False,
587 XmNrecomputeSize, False,
588 XmNleftAttachment, XmATTACH_FORM,
589 XmNleftOffset, 5,
590 XmNrightAttachment, XmATTACH_FORM,
591 XmNbottomAttachment, XmATTACH_FORM,
592 NULL);
593 gui_mch_set_footer((char_u *) "");
594#endif
595
596 /*
597 * Install the callbacks.
598 */
599 gui_x11_callbacks(textArea, vimForm);
600
Bram Moolenaar734a8672019-12-02 22:49:38 +0100601 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 gui.in_focus = FALSE;
603}
604
605/*
606 * Called when the GUI is not going to start after all.
607 */
608 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100609gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610{
611 textArea = NULL;
612#ifdef FEAT_MENU
613 menuBar = NULL;
614#endif
615}
616
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100618gui_mch_set_text_area_pos(
619 int x UNUSED,
620 int y UNUSED,
621 int w UNUSED,
622 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623{
624#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100625 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000626 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627#endif
628}
629
630 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100631gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632{
633 if (textArea != NULL)
634#if (XmVersion >= 1002)
635 XmChangeColor(textArea, gui.back_pixel);
636#else
637 XtVaSetValues(textArea,
638 XmNbackground, gui.back_pixel,
639 NULL);
640#endif
641}
642
643/*
644 * Manage dialog centered on pointer. This could be used by the Athena code as
645 * well.
646 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000647 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100648manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649{
650 Widget shell = XtParent(dialog_child);
651 Window root, child;
652 unsigned int mask;
653 unsigned int width, height, border_width, depth;
654 int x, y, win_x, win_y, maxX, maxY;
655 Boolean mappedWhenManaged;
656
Bram Moolenaar734a8672019-12-02 22:49:38 +0100657 // Temporarily set value of XmNmappedWhenManaged
658 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000659 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
660 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661
662 XtManageChild(dialog_child);
663
Bram Moolenaar734a8672019-12-02 22:49:38 +0100664 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
666 &x, &y, &win_x, &win_y, &mask);
667
Bram Moolenaar734a8672019-12-02 22:49:38 +0100668 // Translate the pointer position (x, y) into a position for the new
669 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
671 &width, &height, &border_width, &depth);
672 width += 2 * border_width;
673 height += 2 * border_width;
674 x -= width / 2;
675 y -= height / 2;
676
Bram Moolenaar734a8672019-12-02 22:49:38 +0100677 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 maxX = XtScreen(shell)->width - width;
679 maxY = XtScreen(shell)->height - height;
680 if (x < 0)
681 x = 0;
682 if (x > maxX)
683 x = maxX;
684 if (y < 0)
685 y = 0;
686 if (y > maxY)
687 y = maxY;
688
Bram Moolenaar734a8672019-12-02 22:49:38 +0100689 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000690 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
691
Bram Moolenaar734a8672019-12-02 22:49:38 +0100692 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693 XtMapWidget(shell);
694
Bram Moolenaar734a8672019-12-02 22:49:38 +0100695 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000696 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000697}
698
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100699#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000700
701/*
702 * Encapsulate the way an XmFontList is created.
703 */
704 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100705gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706{
707 XmFontList font_list;
708
709# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100710 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 font_list = XmFontListCreate(font, STRING_TAG);
712# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100713 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 XmFontListEntry font_list_entry;
715
716 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
717 (XtPointer)font);
718 font_list = XmFontListAppendEntry(NULL, font_list_entry);
719 XmFontListEntryFree(&font_list_entry);
720# endif
721 return font_list;
722}
723
724# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
725 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100726gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727{
728 XmFontList font_list;
729
Bram Moolenaar734a8672019-12-02 22:49:38 +0100730 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 XmFontListEntry font_list_entry;
732
733 font_list_entry = XmFontListEntryCreate(STRING_TAG,
734 XmFONT_IS_FONTSET,
735 (XtPointer)*fontset);
736 font_list = XmFontListAppendEntry(NULL, font_list_entry);
737 XmFontListEntryFree(&font_list_entry);
738 return font_list;
739}
740# endif
741
742#endif
743
744#if defined(FEAT_MENU) || defined(PROTO)
745/*
746 * Menu stuff.
747 */
748
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100749static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100751static void toggle_tearoff(Widget wid);
752static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100754static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100756static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757static int menu_enabled = TRUE;
758
759 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100760gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761{
762 if (flag)
763 {
764 XtManageChild(menuBar);
765#ifdef FEAT_TOOLBAR
766 if (XtIsManaged(XtParent(toolBar)))
767 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100768 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 XtVaSetValues(XtParent(toolBar),
770 XmNtopAttachment, XmATTACH_WIDGET,
771 XmNtopWidget, menuBar,
772 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000773#ifdef FEAT_GUI_TABLINE
774 if (showing_tabline)
775 {
776 XtVaSetValues(tabLine,
777 XmNtopAttachment, XmATTACH_WIDGET,
778 XmNtopWidget, XtParent(toolBar),
779 NULL);
780 XtVaSetValues(textAreaForm,
781 XmNtopAttachment, XmATTACH_WIDGET,
782 XmNtopWidget, tabLine,
783 NULL);
784 }
785 else
786#endif
787 XtVaSetValues(textAreaForm,
788 XmNtopAttachment, XmATTACH_WIDGET,
789 XmNtopWidget, XtParent(toolBar),
790 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 }
792 else
793#endif
794 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000795#ifdef FEAT_GUI_TABLINE
796 if (showing_tabline)
797 {
798 XtVaSetValues(tabLine,
799 XmNtopAttachment, XmATTACH_WIDGET,
800 XmNtopWidget, menuBar,
801 NULL);
802 XtVaSetValues(textAreaForm,
803 XmNtopAttachment, XmATTACH_WIDGET,
804 XmNtopWidget, tabLine,
805 NULL);
806 }
807 else
808#endif
809 XtVaSetValues(textAreaForm,
810 XmNtopAttachment, XmATTACH_WIDGET,
811 XmNtopWidget, menuBar,
812 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813 }
814 }
815 else
816 {
817 XtUnmanageChild(menuBar);
818#ifdef FEAT_TOOLBAR
819 if (XtIsManaged(XtParent(toolBar)))
820 {
821 XtVaSetValues(XtParent(toolBar),
822 XmNtopAttachment, XmATTACH_FORM,
823 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000824#ifdef FEAT_GUI_TABLINE
825 if (showing_tabline)
826 {
827 XtVaSetValues(tabLine,
828 XmNtopAttachment, XmATTACH_WIDGET,
829 XmNtopWidget, XtParent(toolBar),
830 NULL);
831 XtVaSetValues(textAreaForm,
832 XmNtopAttachment, XmATTACH_WIDGET,
833 XmNtopWidget, tabLine,
834 NULL);
835 }
836 else
837#endif
838 XtVaSetValues(textAreaForm,
839 XmNtopAttachment, XmATTACH_WIDGET,
840 XmNtopWidget, XtParent(toolBar),
841 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842 }
843 else
844#endif
845 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000846#ifdef FEAT_GUI_TABLINE
847 if (showing_tabline)
848 {
849 XtVaSetValues(tabLine,
850 XmNtopAttachment, XmATTACH_FORM,
851 NULL);
852 XtVaSetValues(textAreaForm,
853 XmNtopAttachment, XmATTACH_WIDGET,
854 XmNtopWidget, tabLine,
855 NULL);
856 }
857 else
858#endif
859 XtVaSetValues(textAreaForm,
860 XmNtopAttachment, XmATTACH_FORM,
861 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862 }
863 }
864
865}
866
867/*
868 * Enable or disable mnemonics for the toplevel menus.
869 */
870 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100871gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000872{
873 /*
874 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
875 * crashes when using a mnemonic then.
876 */
877 if (!menu_enabled)
878 enable = FALSE;
879 do_set_mnemonics(enable);
880}
881
882 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100883do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884{
885 vimmenu_T *menu;
886
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200887 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 if (menu->id != (Widget)0)
889 XtVaSetValues(menu->id,
890 XmNmnemonic, enable ? menu->mnemonic : NUL,
891 NULL);
892}
893
894 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100895gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896{
897 XmString label;
898 Widget shell;
899 vimmenu_T *parent = menu->parent;
900
901#ifdef MOTIF_POPUP
902 if (menu_is_popup(menu->name))
903 {
904 Arg arg[2];
905 int n = 0;
906
Bram Moolenaar734a8672019-12-02 22:49:38 +0100907 // Only create the popup menu when it's actually used, otherwise there
908 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909# if (XmVersion <= 1002)
910 if (mouse_model_popup())
911# endif
912 {
913 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200914 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200918 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
922 arg, n);
923 menu->id = (Widget)0;
924 }
925 return;
926 }
927#endif
928
929 if (!menu_is_menubar(menu->name)
930 || (parent != NULL && parent->submenu_id == (Widget)0))
931 return;
932
933 label = XmStringCreate((char *)menu->dname, STRING_TAG);
934 if (label == NULL)
935 return;
936 menu->id = XtVaCreateWidget("subMenu",
937 xmCascadeButtonWidgetClass,
938 (parent == NULL) ? menuBar : parent->submenu_id,
939 XmNlabelString, label,
940 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
941#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100942 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943 XmNpositionIndex, idx + (parent != NULL
944 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
945#endif
946 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 XmStringFree(label);
948
Bram Moolenaar734a8672019-12-02 22:49:38 +0100949 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 return;
951
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100952 // The "Help" menu is a special case, and should be placed at the far
953 // right hand side of the menu-bar. It's recognized by its high priority.
954 if (parent == NULL && menu->priority >= 9999)
955 XtVaSetValues(menuBar,
956 XmNmenuHelpWidget, menu->id,
957 NULL);
958
959 gui_motif_menu_colors(menu->id);
960 gui_motif_menu_fontlist(menu->id);
961
Bram Moolenaar734a8672019-12-02 22:49:38 +0100962 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 gui_motif_add_actext(menu);
964
965 shell = XtVaCreateWidget("subMenuShell",
966 xmMenuShellWidgetClass, menu->id,
967 XmNwidth, 1,
968 XmNheight, 1,
969 NULL);
970 gui_motif_menu_colors(shell);
971 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
972 xmRowColumnWidgetClass, shell,
973 XmNrowColumnType, XmMENU_PULLDOWN,
974 NULL);
975 gui_motif_menu_colors(menu->submenu_id);
976
Bram Moolenaar734a8672019-12-02 22:49:38 +0100977 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978 return;
979
980#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100981 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 toggle_tearoff(menu->submenu_id);
983#endif
984
985 XtVaSetValues(menu->id,
986 XmNsubMenuId, menu->submenu_id,
987 NULL);
988
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100989 // When we add a top-level item to the menu bar, we can figure out how
990 // high the menu bar should be.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 if (parent == NULL)
992 gui_mch_compute_menu_height(menu->id);
993}
994
995
996/*
997 * Add mnemonic and accelerator text to a menu button.
998 */
999 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001000gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001{
1002 XmString label;
1003
Bram Moolenaar734a8672019-12-02 22:49:38 +01001004 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 if (menu->actext != NULL && menu->id != (Widget)0)
1006 {
1007 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1008 if (label == NULL)
1009 return;
1010 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1011 XmStringFree(label);
1012 }
1013}
1014
1015 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001016gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017{
1018#if (XmVersion >= 1002)
1019 if (enable)
1020 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1021 else
1022 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1023 toggle_tearoff(menuBar);
1024 gui_mch_recurse_tearoffs(root_menu);
1025#endif
1026}
1027
1028#if (XmVersion >= 1002)
1029/*
1030 * Set the tearoff for one menu widget on or off, and set the color of the
1031 * tearoff widget.
1032 */
1033 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001034toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035{
1036 Widget w;
1037
1038 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1039 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1040 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1041 gui_motif_menu_colors(w);
1042}
1043
1044 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001045gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046{
1047 while (menu != NULL)
1048 {
1049 if (!menu_is_popup(menu->name))
1050 {
1051 if (menu->submenu_id != (Widget)0)
1052 toggle_tearoff(menu->submenu_id);
1053 gui_mch_recurse_tearoffs(menu->children);
1054 }
1055 menu = menu->next;
1056 }
1057}
1058#endif
1059
1060 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001061gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062{
1063 Dimension shadowHeight;
1064
1065 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1066 return shadowHeight;
1067}
1068
1069/*
1070 * Compute the height of the menu bar.
1071 * We need to check all the items for their position and height, for the case
1072 * there are several rows, and/or some characters extend higher or lower.
1073 */
1074 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001075gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001076 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077{
1078 Dimension y, maxy;
1079 Dimension margin, shadow;
1080 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001081 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082
1083 /*
1084 * Get the height of the new item, before managing it, because it will
1085 * still reflect the font size. After managing it depends on the menu
1086 * height, which is what we just wanted to get!.
1087 */
1088 if (id != (Widget)0)
1089 XtVaGetValues(id, XmNheight, &height, NULL);
1090
Bram Moolenaar734a8672019-12-02 22:49:38 +01001091 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001093 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1095 {
1096 id = mp->id;
1097 break;
1098 }
1099
1100 /*
1101 * Now manage the menu item, to make them all be positioned (makes an
1102 * extra row when needed, removes it when not needed).
1103 */
1104 if (id != (Widget)0)
1105 XtManageChild(id);
1106
1107 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001108 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 */
1110 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001111 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {
1113 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1114 {
1115 XtVaGetValues(mp->id, XmNy, &y, NULL);
1116 if (y > maxy)
1117 maxy = y;
1118 }
1119 }
1120
1121 XtVaGetValues(menuBar,
1122 XmNmarginHeight, &margin,
1123 XmNshadowThickness, &shadow,
1124 NULL);
1125
1126 /*
1127 * This computation is the result of trial-and-error:
1128 * maxy = The maximum position of an item; required for when there are
1129 * two or more rows
1130 * height = height of an item, before managing it; Hopefully this will
1131 * change with the font height. Includes shadow-border.
1132 * shadow = shadow-border; must be subtracted from the height.
1133 * margin = margin around the menu buttons; Must be added.
1134 * Add 4 for the underlining of shortcut keys.
1135 */
1136 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1137
Bram Moolenaar734a8672019-12-02 22:49:38 +01001138 // Somehow the menu bar doesn't resize automatically. Set it here,
1139 // even though this is a catch 22. Don't do this when starting up,
1140 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 if (gui.shell_created)
1142 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001143}
1144
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001145#ifdef FEAT_TOOLBAR
1146
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001147/*
1148 * Icons used by the toolbar code.
1149 */
1150#include "gui_x11_pm.h"
1151
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001152static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001153
1154/*
1155 * Read an Xpm file. Return OK or FAIL.
1156 */
1157 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001158check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001159{
1160 XpmAttributes attrs;
1161 int status;
1162 Pixmap mask;
1163 Pixmap map;
1164
1165 attrs.valuemask = 0;
1166
Bram Moolenaar734a8672019-12-02 22:49:38 +01001167 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001168 status = XpmReadFileToPixmap(gui.dpy,
1169 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1170 (char *)path, &map, &mask, &attrs);
1171 XpmFreeAttributes(&attrs);
1172
1173 if (status == XpmSuccess)
1174 return OK;
1175 return FAIL;
1176}
1177
1178
1179/*
1180 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001181 * When it's to be read from a file, "fname" is set to the file name
1182 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001183 * Return a blank pixmap if it fails.
1184 */
1185 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001186get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001187{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001188 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1189 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001190 int res;
1191
Bram Moolenaar7c626922005-02-07 22:01:03 +00001192 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001193 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001194
1195 if (menu->iconfile != NULL)
1196 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001197 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001198 gui_find_iconfile(menu->iconfile, buf, "xpm");
1199 res = check_xpm(buf);
1200
Bram Moolenaar734a8672019-12-02 22:49:38 +01001201 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001202 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1203 res = check_xpm(buf);
1204 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001205 {
1206 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001207 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001208 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001209 }
1210
1211 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1212 {
1213 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001214 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001215 xpm = built_in_pixmaps[menu->iconidx];
1216 else
1217 xpm = tb_blank_xpm;
1218 }
1219
1220 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001222
1223/*
1224 * Add arguments for the toolbar pixmap to a menu item.
1225 */
1226 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001227add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001228{
1229 vim_free(menu->xpm_fname);
1230 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1231 if (menu->xpm == NULL)
1232 {
1233 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1234 }
1235 else
1236 {
1237 if (menu->xpm_fname != NULL)
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001238 {
Bram Moolenaar7c626922005-02-07 22:01:03 +00001239 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001240 }
Bram Moolenaar7c626922005-02-07 22:01:03 +00001241 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1242 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1243 }
1244 return n;
1245}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001246#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247
1248 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001249gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250{
1251 XmString label;
1252 vimmenu_T *parent = menu->parent;
1253
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001255 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1257 return;
1258# endif
1259
1260# ifdef FEAT_TOOLBAR
1261 if (menu_is_toolbar(parent->name))
1262 {
1263 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001264 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 int n;
1266 Arg args[18];
1267
1268 n = 0;
1269 if (menu_is_separator(menu->name))
1270 {
1271 char *cp;
1272 Dimension wid;
1273
1274 /*
1275 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1276 * a width specifier. If no width is specified then we choose one.
1277 */
1278 cp = (char *)vim_strchr(menu->name, ':');
1279 if (cp != NULL)
1280 wid = (Dimension)atoi(++cp);
1281 else
1282 wid = 4;
1283
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284 type = xmSeparatorWidgetClass;
1285 XtSetArg(args[n], XmNwidth, wid); n++;
1286 XtSetArg(args[n], XmNminWidth, wid); n++;
1287 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001288 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 }
1290 else
1291 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001292 // Without shadows one can't sense whatever the button has been
1293 // pressed or not! However we want to save a bit of space...
1294 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001295 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1297 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1298 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001299 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001300 // Set the label here, so that we can switch between icons/text
1301 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001302 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1303 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001304
Bram Moolenaar7c626922005-02-07 22:01:03 +00001305 n = add_pixmap_args(menu, args, n);
1306
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001307 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308 }
1309
1310 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1311 if (menu->id == NULL)
1312 {
1313 menu->id = XtCreateManagedWidget((char *)menu->dname,
1314 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001315 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {
1317 XtAddCallback(menu->id,
1318 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319# ifdef FEAT_FOOTER
1320 XtAddEventHandler(menu->id, EnterWindowMask, False,
1321 toolbarbutton_enter_cb, menu);
1322 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1323 toolbarbutton_leave_cb, menu);
1324# endif
1325 }
1326 }
1327 else
1328 XtSetValues(menu->id, args, n);
1329 if (xms != NULL)
1330 XmStringFree(xms);
1331
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001332# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001334# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335
1336 menu->parent = parent;
1337 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001338 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 if (!XtIsManaged(XtParent(toolBar))
1340 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1341 gui_mch_show_toolbar(TRUE);
1342 gui.toolbar_height = gui_mch_compute_toolbar_height();
1343 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001344 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345# endif
1346
Bram Moolenaar734a8672019-12-02 22:49:38 +01001347 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 if (parent->submenu_id == (Widget)0)
1349 return;
1350
1351 menu->submenu_id = (Widget)0;
1352
Bram Moolenaar734a8672019-12-02 22:49:38 +01001353 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354 if (menu_is_separator(menu->name))
1355 {
1356 menu->id = XtVaCreateWidget("subMenu",
1357 xmSeparatorGadgetClass, parent->submenu_id,
1358#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001359 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1361 ? 1 : 0),
1362#endif
1363 NULL);
1364 gui_motif_menu_colors(menu->id);
1365 return;
1366 }
1367
1368 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1369 if (label == NULL)
1370 return;
1371 menu->id = XtVaCreateWidget("subMenu",
1372 xmPushButtonWidgetClass, parent->submenu_id,
1373 XmNlabelString, label,
1374 XmNmnemonic, menu->mnemonic,
1375#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001376 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1378 ? 1 : 0),
1379#endif
1380 NULL);
1381 gui_motif_menu_colors(menu->id);
1382 gui_motif_menu_fontlist(menu->id);
1383 XmStringFree(label);
1384
1385 if (menu->id != (Widget)0)
1386 {
1387 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1388 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001389 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 gui_motif_add_actext(menu);
1391 }
1392}
1393
1394#if (XmVersion <= 1002) || defined(PROTO)
1395/*
1396 * This function will destroy/create the popup menus dynamically,
1397 * according to the value of 'mousemodel'.
1398 * This will fix the "right mouse button freeze" that occurs when
1399 * there exists a popup menu but it isn't managed.
1400 */
1401 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001402gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403{
1404 int idx = 0;
1405
Bram Moolenaar734a8672019-12-02 22:49:38 +01001406 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 if (!gui.in_use)
1408 return;
1409
1410 while (menu)
1411 {
1412 if (menu->children != NULL)
1413 {
1414 if (menu_is_popup(menu->name))
1415 {
1416 if (mouse_model_popup())
1417 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001418 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 gui_mch_add_menu(menu, idx);
1420 gui_motif_update_mousemodel(menu->children);
1421 }
1422 else
1423 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001424 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 gui_motif_update_mousemodel(menu->children);
1426 gui_mch_destroy_menu(menu);
1427 }
1428 }
1429 }
1430 else if (menu_is_child_of_popup(menu))
1431 {
1432 if (mouse_model_popup())
1433 gui_mch_add_menu_item(menu, idx);
1434 else
1435 gui_mch_destroy_menu(menu);
1436 }
1437 menu = menu->next;
1438 ++idx;
1439 }
1440}
1441#endif
1442
1443 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001444gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445{
1446 if (menuBar == (Widget)0)
1447 return;
1448 gui_motif_menu_colors(menuBar);
1449#ifdef FEAT_TOOLBAR
1450 gui_motif_menu_colors(toolBarFrame);
1451 gui_motif_menu_colors(toolBar);
1452#endif
1453
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001454 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455}
1456
1457 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001458gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459{
1460 if (menuBar == (Widget)0)
1461 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001462 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 {
1464 Dimension height;
1465 Position w, h;
1466
1467 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1468 gui.menu_height = height;
1469
1470 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1471 gui_resize_shell(w, h
1472#ifdef FEAT_XIM
1473 - xim_get_status_area_height()
1474#endif
1475 );
1476 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001477 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 ui_new_shellsize();
1479}
1480
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001481#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001483gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484{
1485# ifdef FEAT_TOOLBAR
1486 vimmenu_T *menu;
1487
1488 if (toolBar == (Widget)0)
1489 return;
1490
1491 menu = gui_find_menu((char_u *)"ToolBar");
1492 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001493 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494# endif
1495}
1496
1497 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001498gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499{
1500# ifdef FEAT_TOOLBAR
1501 vimmenu_T *toolbar;
1502
1503 if (toolBar == (Widget)0)
1504 return;
1505
1506 toolbar = gui_find_menu((char_u *)"ToolBar");
1507 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001508 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509# endif
1510}
1511#endif
1512
1513 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001514submenu_change(
1515 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001516 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517{
1518 vimmenu_T *mp;
1519
1520 for (mp = menu; mp != NULL; mp = mp->next)
1521 {
1522 if (mp->id != (Widget)0)
1523 {
1524 if (colors)
1525 {
1526 gui_motif_menu_colors(mp->id);
1527#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001528 // For a toolbar item: Free the pixmap and allocate a new one,
1529 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001530 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001532 int n = 0;
1533 Arg args[18];
1534
Bram Moolenaar7c626922005-02-07 22:01:03 +00001535 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001536 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001538# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001539 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 if (mp->tip != NULL)
1541 {
1542 Arg args[2];
1543
1544 args[0].name = XmNbackground;
1545 args[0].value = gui.tooltip_bg_pixel;
1546 args[1].name = XmNforeground;
1547 args[1].value = gui.tooltip_fg_pixel;
1548 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1549 }
1550# endif
1551#endif
1552 }
1553 else
1554 {
1555 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001556#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001557 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 if (mp->tip != NULL)
1559 {
1560 Arg args[1];
1561
1562 args[0].name = XmNfontList;
1563 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1564 &gui.tooltip_fontset);
1565 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1566 }
1567#endif
1568 }
1569 }
1570
1571 if (mp->children != NULL)
1572 {
1573#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001574 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 if (mp->submenu_id != (Widget)0)
1576 {
1577 if (colors)
1578 gui_motif_menu_colors(mp->submenu_id);
1579 else
1580 gui_motif_menu_fontlist(mp->submenu_id);
1581 toggle_tearoff(mp->submenu_id);
1582 }
1583#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001584 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001585 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586 }
1587 }
1588}
1589
1590/*
1591 * Destroy the machine specific menu widget.
1592 */
1593 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001594gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001596 // Please be sure to destroy the parent widget first (i.e. menu->id).
1597 // On the other hand, problems have been reported that the submenu must be
1598 // deleted first...
1599 //
1600 // This code should be basically identical to that in the file gui_athena.c
1601 // because they are both Xt based.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 if (menu->submenu_id != (Widget)0)
1603 {
1604 XtDestroyWidget(menu->submenu_id);
1605 menu->submenu_id = (Widget)0;
1606 }
1607
1608 if (menu->id != (Widget)0)
1609 {
1610 Widget parent;
1611
1612 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001613#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001614 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001616 // We try to destroy this before the actual menu, because there are
1617 // callbacks, etc. that will be unregistered during the tooltip
1618 // destruction.
1619 //
1620 // If you call "gui_mch_destroy_beval_area()" after destroying
1621 // menu->id, then the tooltip's window will have already been
1622 // deallocated by Xt, and unknown behaviour will ensue (probably
1623 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 gui_mch_destroy_beval_area(menu->tip);
1625 menu->tip = NULL;
1626 }
1627#endif
1628 XtDestroyWidget(menu->id);
1629 menu->id = (Widget)0;
1630 if (parent == menuBar)
1631 gui_mch_compute_menu_height((Widget)0);
1632#ifdef FEAT_TOOLBAR
1633 else if (parent == toolBar)
1634 {
1635 Cardinal num_children;
1636
Bram Moolenaar734a8672019-12-02 22:49:38 +01001637 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1639 if (num_children == 0)
1640 gui_mch_show_toolbar(FALSE);
1641 else
1642 gui.toolbar_height = gui_mch_compute_toolbar_height();
1643 }
1644#endif
1645 }
1646}
1647
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001649gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650{
1651#ifdef MOTIF_POPUP
1652 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1653 XtManageChild(menu->submenu_id);
1654#endif
1655}
1656
Bram Moolenaar734a8672019-12-02 22:49:38 +01001657#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658
1659/*
1660 * Set the menu and scrollbar colors to their default values.
1661 */
1662 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001663gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664{
1665 if (gui.in_use)
1666 {
Bram Moolenaare8504392022-03-13 14:45:03 +00001667 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
1668 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
1669 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
1670 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001671#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 gui.tooltip_fg_pixel =
1673 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1674 gui.tooltip_bg_pixel =
1675 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1676#endif
1677 }
1678}
1679
1680
1681/*
1682 * Scrollbar stuff.
1683 */
1684
1685 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001686gui_mch_set_scrollbar_thumb(
1687 scrollbar_T *sb,
1688 long val,
1689 long size,
1690 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691{
1692 if (sb->id != (Widget)0)
1693 XtVaSetValues(sb->id,
1694 XmNvalue, val,
1695 XmNsliderSize, size,
1696 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001697 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 NULL);
1699}
1700
1701 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001702gui_mch_set_scrollbar_pos(
1703 scrollbar_T *sb,
1704 int x,
1705 int y,
1706 int w,
1707 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708{
1709 if (sb->id != (Widget)0)
1710 {
1711 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1712 {
1713 if (y == 0)
1714 h -= gui.border_offset;
1715 else
1716 y -= gui.border_offset;
1717 XtVaSetValues(sb->id,
1718 XmNtopOffset, y,
1719 XmNbottomOffset, -y - h,
1720 XmNwidth, w,
1721 NULL);
1722 }
1723 else
1724 XtVaSetValues(sb->id,
1725 XmNtopOffset, y,
1726 XmNleftOffset, x,
1727 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1728 ? gui.scrollbar_width : 0,
1729 XmNheight, h,
1730 NULL);
1731 XtManageChild(sb->id);
1732 }
1733}
1734
Bram Moolenaar203ec772020-07-17 20:43:43 +02001735 int
1736gui_mch_get_scrollbar_xpadding(void)
1737{
qsmodo28f1a512022-02-07 15:57:50 +00001738 int xpad;
1739 Dimension tw, ww;
1740 Position tx;
1741
1742 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL);
1743 XtVaGetValues(vimShell, XtNwidth, &ww, NULL);
1744 xpad = ww - tw - tx - gui.scrollbar_width;
1745 return (xpad < 0) ? 0 : xpad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001746}
1747
1748 int
1749gui_mch_get_scrollbar_ypadding(void)
1750{
qsmodo28f1a512022-02-07 15:57:50 +00001751 int ypad;
1752 Dimension th, wh;
1753 Position ty;
1754
1755 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL);
1756 XtVaGetValues(vimShell, XtNheight, &wh, NULL);
1757 ypad = wh - th - ty - gui.scrollbar_height;
1758 return (ypad < 0) ? 0 : ypad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001759}
1760
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001762gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763{
1764 Arg args[16];
1765 int n;
1766
1767 if (sb->id != (Widget)0)
1768 {
1769 n = 0;
1770 if (flag)
1771 {
1772 switch (sb->type)
1773 {
1774 case SBAR_LEFT:
1775 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1776 break;
1777
1778 case SBAR_RIGHT:
1779 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1780 break;
1781
1782 case SBAR_BOTTOM:
1783 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1784 break;
1785 }
1786 XtSetValues(textArea, args, n);
1787 XtManageChild(sb->id);
1788 }
1789 else
1790 {
1791 if (!gui.which_scrollbars[sb->type])
1792 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001793 // The scrollbars of this type are all disabled, adjust the
1794 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 switch (sb->type)
1796 {
1797 case SBAR_LEFT:
1798 XtSetArg(args[n], XmNleftOffset, 0); n++;
1799 break;
1800
1801 case SBAR_RIGHT:
1802 XtSetArg(args[n], XmNrightOffset, 0); n++;
1803 break;
1804
1805 case SBAR_BOTTOM:
1806 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1807 break;
1808 }
1809 XtSetValues(textArea, args, n);
1810 }
1811 XtUnmanageChild(sb->id);
1812 }
1813 }
1814}
1815
1816 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001817gui_mch_create_scrollbar(
1818 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001819 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820{
1821 Arg args[16];
1822 int n;
1823
1824 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 XtSetArg(args[n], XmNminimum, 0); n++;
1826 XtSetArg(args[n], XmNorientation,
1827 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1828
1829 switch (sb->type)
1830 {
1831 case SBAR_LEFT:
1832 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1833 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1834 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1835 break;
1836
1837 case SBAR_RIGHT:
1838 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1839 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1840 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1841 break;
1842
1843 case SBAR_BOTTOM:
1844 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1845 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1846 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1847 break;
1848 }
1849
1850 sb->id = XtCreateWidget("scrollBar",
1851 xmScrollBarWidgetClass, textAreaForm, args, n);
1852
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 if (sb->id != (Widget)0)
1854 {
1855 gui_mch_set_scrollbar_colors(sb);
1856 XtAddCallback(sb->id, XmNvalueChangedCallback,
1857 scroll_cb, (XtPointer)sb->ident);
1858 XtAddCallback(sb->id, XmNdragCallback,
1859 scroll_cb, (XtPointer)sb->ident);
1860 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1861 (XtPointer)0);
1862 }
1863}
1864
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001866gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867{
1868 if (sb->id != (Widget)0)
1869 XtDestroyWidget(sb->id);
1870}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871
1872 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001873gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874{
1875 if (sb->id != (Widget)0)
1876 {
1877 if (gui.scroll_bg_pixel != INVALCOLOR)
1878 {
1879#if (XmVersion>=1002)
Bram Moolenaare8504392022-03-13 14:45:03 +00001880 // This should not only set the through color but also adjust
1881 // related colors, such as shadows.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 XmChangeColor(sb->id, gui.scroll_bg_pixel);
Bram Moolenaare8504392022-03-13 14:45:03 +00001883#endif
1884
1885 // Set the through color directly, in case XmChangeColor() decided
1886 // to change it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 XtVaSetValues(sb->id,
1888 XmNtroughColor, gui.scroll_bg_pixel,
1889 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 }
1891
1892 if (gui.scroll_fg_pixel != INVALCOLOR)
1893 XtVaSetValues(sb->id,
1894 XmNforeground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 XmNbackground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 NULL);
1897 }
1898
Bram Moolenaar734a8672019-12-02 22:49:38 +01001899 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1901 gui_motif_scroll_colors(textAreaForm);
1902}
1903
1904/*
1905 * Miscellaneous stuff:
1906 */
1907
1908 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001909gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910{
1911 return(XtWindow(textArea));
1912}
1913
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001914/*
1915 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1916 * When one is found, simulate a button press on that widget and give it the
1917 * keyboard focus. If the mnemonic is on a label, look in the userData field
1918 * of the label to see if it points to another widget, and give that the focus.
1919 */
1920 static void
1921do_mnemonic(Widget w, unsigned int keycode)
1922{
1923 WidgetList children;
1924 int numChildren, i;
1925 Boolean isMenu;
1926 KeySym mnemonic = '\0';
1927 char mneString[2];
1928 Widget userData;
1929 unsigned char rowColType;
1930
1931 if (XtIsComposite(w))
1932 {
1933 if (XtClass(w) == xmRowColumnWidgetClass)
1934 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001935 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001936 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1937 }
1938 else
1939 isMenu = False;
1940 if (!isMenu)
1941 {
1942 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001943 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001944 for (i = 0; i < numChildren; i++)
1945 do_mnemonic(children[i], keycode);
1946 }
1947 }
1948 else
1949 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001950 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001951 if (mnemonic != '\0')
1952 {
1953 mneString[0] = mnemonic;
1954 mneString[1] = '\0';
1955 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1956 XStringToKeysym(mneString)) == keycode)
1957 {
1958 if (XtClass(w) == xmLabelWidgetClass
1959 || XtClass(w) == xmLabelGadgetClass)
1960 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001961 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001962 if (userData != NULL && XtIsWidget(userData))
1963 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1964 }
1965 else
1966 {
1967 XKeyPressedEvent keyEvent;
1968
1969 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1970
Bram Moolenaara80faa82020-04-12 19:37:17 +02001971 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001972 keyEvent.type = KeyPress;
1973 keyEvent.serial = 1;
1974 keyEvent.send_event = True;
1975 keyEvent.display = XtDisplay(w);
1976 keyEvent.window = XtWindow(w);
1977 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1978 NULL, 0);
1979 }
1980 }
1981 }
1982 }
1983}
1984
1985/*
1986 * Callback routine for dialog mnemonic processing.
1987 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001988 static void
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02001989mnemonic_event(
1990 Widget w,
1991 XtPointer call_data UNUSED,
1992 XKeyEvent *event,
1993 Boolean *b UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001994{
1995 do_mnemonic(w, event->keycode);
1996}
1997
1998
1999/*
2000 * Search the widget tree under w for widgets with mnemonics. When found, add
2001 * a passive grab to the dialog widget for the mnemonic character, thus
2002 * directing mnemonic events to the dialog widget.
2003 */
2004 static void
2005add_mnemonic_grabs(Widget dialog, Widget w)
2006{
2007 char mneString[2];
2008 WidgetList children;
2009 int numChildren, i;
2010 Boolean isMenu;
2011 KeySym mnemonic = '\0';
2012 unsigned char rowColType;
2013
2014 if (XtIsComposite(w))
2015 {
2016 if (XtClass(w) == xmRowColumnWidgetClass)
2017 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002018 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002019 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2020 }
2021 else
2022 isMenu = False;
2023 if (!isMenu)
2024 {
2025 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002026 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002027 for (i = 0; i < numChildren; i++)
2028 add_mnemonic_grabs(dialog, children[i]);
2029 }
2030 }
2031 else
2032 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002033 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002034 if (mnemonic != '\0')
2035 {
2036 mneString[0] = mnemonic;
2037 mneString[1] = '\0';
2038 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2039 XStringToKeysym(mneString)),
2040 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2041 }
2042 }
2043}
2044
2045/*
2046 * Add a handler for mnemonics in a dialog. Motif itself only handles
2047 * mnemonics in menus. Mnemonics added or changed after this call will be
2048 * ignored.
2049 *
2050 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2051 * the appropriate label and set the XmNuserData resource of the label to the
2052 * widget to get the focus when the mnemonic is typed.
2053 */
2054 static void
2055activate_dialog_mnemonics(Widget dialog)
2056{
2057 if (!dialog)
2058 return;
2059
2060 XtAddEventHandler(dialog, KeyPressMask, False,
2061 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2062 add_mnemonic_grabs(dialog, dialog);
2063}
2064
2065/*
2066 * Removes the event handler and key-grabs for dialog mnemonic handling.
2067 */
2068 static void
2069suppress_dialog_mnemonics(Widget dialog)
2070{
2071 if (!dialog)
2072 return;
2073
2074 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2075 XtRemoveEventHandler(dialog, KeyPressMask, False,
2076 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2077}
2078
2079#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002080/*
2081 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2082 */
2083 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002084set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002085{
2086 XmFontList fl;
2087
2088#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002089 if (gui.fontset != NOFONTSET)
2090 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002091 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2092 if (fl != NULL)
2093 {
2094 if (XtIsManaged(id))
2095 {
2096 XtUnmanageChild(id);
2097 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002098 // We should force the widget to recalculate its
2099 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002100 XtManageChild(id);
2101 }
2102 else
2103 XtVaSetValues(id, XmNfontList, fl, NULL);
2104 XmFontListFree(fl);
2105 }
2106 }
2107#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002108 if (gui.norm_font != NOFONT)
2109 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002110 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2111 if (fl != NULL)
2112 {
2113 if (XtIsManaged(id))
2114 {
2115 XtUnmanageChild(id);
2116 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002117 // We should force the widget to recalculate its
2118 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002119 XtManageChild(id);
2120 }
2121 else
2122 XtVaSetValues(id, XmNfontList, fl, NULL);
2123 XmFontListFree(fl);
2124 }
2125 }
2126#endif
2127}
2128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129
2130#if defined(FEAT_BROWSE) || defined(PROTO)
2131
2132/*
2133 * file selector related stuff
2134 */
2135
2136#include <Xm/FileSB.h>
2137#include <Xm/XmStrDefs.h>
2138
2139typedef struct dialog_callback_arg
2140{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002141 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 int id;
2143} dcbarg_T;
2144
2145static Widget dialog_wgt;
2146static char *browse_fname = NULL;
2147static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002148 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002150static void DialogCancelCB(Widget, XtPointer, XtPointer);
2151static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152
2153/*
2154 * This function is used to translate the predefined label text of the
2155 * precomposed dialogs. We do this explicitly to allow:
2156 *
2157 * - usage of gettext for translation, as in all the other places.
2158 *
2159 * - equalize the messages between different GUI implementations as far as
2160 * possible.
2161 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002162 static void
2163set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002165 XmString str;
2166 Widget w;
2167 char_u *p, *next;
2168 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169
2170 w = XtNameToWidget(parent, name);
2171
2172 if (!w)
2173 return;
2174
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002175 p = vim_strsave((char_u *)new_label);
2176 if (p == NULL)
2177 return;
2178 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002180 if (*next == DLG_HOTKEY_CHAR)
2181 {
2182 int len = STRLEN(next);
2183
2184 if (len > 0)
2185 {
2186 mch_memmove(next, next + 1, len);
2187 mnemonic = next[0];
2188 }
2189 }
2190 }
2191
2192 str = XmStringCreate((char *)p, STRING_TAG);
2193 vim_free(p);
2194
2195 if (str != NULL)
2196 {
2197 XtVaSetValues(w,
2198 XmNlabelString, str,
2199 XmNmnemonic, mnemonic,
2200 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 XmStringFree(str);
2202 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002203 gui_motif_menu_fontlist(w);
2204}
2205
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002206 static void
2207set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002208{
2209 Widget w;
2210 w = XtNameToWidget(parent, name);
2211
2212 if (!w)
2213 return;
2214
2215 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216}
2217
2218/*
2219 * Put up a file requester.
2220 * Returns the selected name in allocated memory, or NULL for Cancel.
2221 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002223gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002224 int saving UNUSED, // select file to write
2225 char_u *title, // title for the window
2226 char_u *dflt, // default name
2227 char_u *ext UNUSED, // not used (extension added)
2228 char_u *initdir, // initial directory, NULL for current dir
2229 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230{
2231 char_u dirbuf[MAXPATHL];
2232 char_u dfltbuf[MAXPATHL];
2233 char_u *pattern;
2234 char_u *tofree = NULL;
2235
Bram Moolenaar734a8672019-12-02 22:49:38 +01002236 // There a difference between the resource name and value, Therefore, we
2237 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2238 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002239
2240 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241
2242 if (initdir == NULL || *initdir == NUL)
2243 {
2244 mch_dirname(dirbuf, MAXPATHL);
2245 initdir = dirbuf;
2246 }
2247
2248 if (dflt == NULL)
2249 dflt = (char_u *)"";
2250 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2251 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002252 // The default selection should be the full path, "dflt" is only the
2253 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 STRCPY(dfltbuf, initdir);
2255 add_pathsep(dfltbuf);
2256 STRCAT(dfltbuf, dflt);
2257 dflt = dfltbuf;
2258 }
2259
Bram Moolenaar734a8672019-12-02 22:49:38 +01002260 // Can only use one pattern for a file name. Get the first pattern out of
2261 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 if (filter == NULL)
2263 pattern = (char_u *)"";
2264 else
2265 {
2266 char_u *s, *p;
2267
2268 s = filter;
2269 for (p = filter; *p != NUL; ++p)
2270 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002271 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002273 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 break;
2275 }
2276 pattern = vim_strnsave(s, p - s);
2277 tofree = pattern;
2278 if (pattern == NULL)
2279 pattern = (char_u *)"";
2280 }
2281
2282 XtVaSetValues(dialog_wgt,
2283 XtVaTypedArg,
2284 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2285 XtVaTypedArg,
2286 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2287 XtVaTypedArg,
2288 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2289 XtVaTypedArg,
2290 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2291 NULL);
2292
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002293 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2294 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2296 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002297 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002299 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2301
Bram Moolenaar734a8672019-12-02 22:49:38 +01002302 // This is to save us from silly external settings using not fixed with
2303 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002304 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2305 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2306
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 gui_motif_menu_colors(dialog_wgt);
2308 if (gui.scroll_bg_pixel != INVALCOLOR)
2309 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2310
2311 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2312 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002313 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2315 (unsigned char)XmDIALOG_HELP_BUTTON));
2316
2317 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002318 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319
Bram Moolenaar734a8672019-12-02 22:49:38 +01002320 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 do
2322 {
2323 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2324 (XtInputMask)XtIMAll);
2325 } while (XtIsManaged(dialog_wgt));
2326
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002327 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 XtDestroyWidget(dialog_wgt);
2329 vim_free(tofree);
2330
2331 if (browse_fname == NULL)
2332 return NULL;
2333 return vim_strsave((char_u *)browse_fname);
2334}
2335
2336/*
2337 * The code below was originally taken from
2338 * /usr/examples/motif/xmsamplers/xmeditor.c
2339 * on Digital Unix 4.0d, but heavily modified.
2340 */
2341
2342/*
2343 * Process callback from Dialog cancel actions.
2344 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002346DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002347 Widget w UNUSED, // widget id
2348 XtPointer client_data UNUSED, // data from application
2349 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350{
2351 if (browse_fname != NULL)
2352 {
2353 XtFree(browse_fname);
2354 browse_fname = NULL;
2355 }
2356 XtUnmanageChild(dialog_wgt);
2357}
2358
2359/*
2360 * Process callback from Dialog actions.
2361 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002363DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002364 Widget w UNUSED, // widget id
2365 XtPointer client_data UNUSED, // data from application
2366 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367{
2368 XmFileSelectionBoxCallbackStruct *fcb;
2369
2370 if (browse_fname != NULL)
2371 {
2372 XtFree(browse_fname);
2373 browse_fname = NULL;
2374 }
2375 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2376
Bram Moolenaar734a8672019-12-02 22:49:38 +01002377 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2379
Bram Moolenaar734a8672019-12-02 22:49:38 +01002380 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 XtUnmanageChild(dialog_wgt);
2382}
2383
Bram Moolenaar734a8672019-12-02 22:49:38 +01002384#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385
2386#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2387
2388static int dialogStatus;
2389
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390/*
2391 * Callback function for the textfield. When CR is hit this works like
2392 * hitting the "OK" button, ESC like "Cancel".
2393 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002395keyhit_callback(
2396 Widget w,
2397 XtPointer client_data UNUSED,
2398 XEvent *event,
2399 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400{
2401 char buf[2];
2402 KeySym key_sym;
2403
2404 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2405 {
2406 if (*buf == CAR)
2407 dialogStatus = 1;
2408 else if (*buf == ESC)
2409 dialogStatus = 2;
2410 }
2411 if ((key_sym == XK_Left || key_sym == XK_Right)
2412 && !(event->xkey.state & ShiftMask))
2413 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2414}
2415
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002417butproc(
2418 Widget w UNUSED,
2419 XtPointer client_data,
2420 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421{
2422 dialogStatus = (int)(long)client_data + 1;
2423}
2424
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425#ifdef HAVE_XPM
2426
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002428create_pixmap_label(
2429 Widget parent,
2430 String name,
2431 char **data,
2432 ArgList args,
2433 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434{
2435 Widget label;
2436 Display *dsp;
2437 Screen *scr;
2438 int depth;
2439 Pixmap pixmap = 0;
2440 XpmAttributes attr;
2441 Boolean rs;
2442 XpmColorSymbol color[5] =
2443 {
2444 {"none", NULL, 0},
2445 {"iconColor1", NULL, 0},
2446 {"bottomShadowColor", NULL, 0},
2447 {"topShadowColor", NULL, 0},
2448 {"selectColor", NULL, 0}
2449 };
2450
2451 label = XmCreateLabelGadget(parent, name, args, arg);
2452
2453 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002454 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 * no way to get the background color directly from the widget itself.
2456 * In such cases we get it from The Core part of his parent instead.
2457 */
2458 dsp = XtDisplayOfObject(label);
2459 scr = XtScreenOfObject(label);
2460 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2461 ? label : XtParent(label),
2462 XmNdepth, &depth,
2463 XmNbackground, &color[0].pixel,
2464 XmNforeground, &color[1].pixel,
2465 XmNbottomShadowColor, &color[2].pixel,
2466 XmNtopShadowColor, &color[3].pixel,
2467 XmNhighlight, &color[4].pixel,
2468 NULL);
2469
2470 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2471 attr.colorsymbols = color;
2472 attr.numsymbols = 5;
2473 attr.closeness = 65535;
2474 attr.depth = depth;
2475 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2476 data, &pixmap, NULL, &attr);
2477
2478 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2479 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2480 XtVaSetValues(label,
2481 XmNlabelType, XmPIXMAP,
2482 XmNlabelPixmap, pixmap,
2483 NULL);
2484 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2485
2486 return label;
2487}
2488#endif
2489
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002491gui_mch_dialog(
2492 int type UNUSED,
2493 char_u *title,
2494 char_u *message,
2495 char_u *button_names,
2496 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002497 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002498 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499{
2500 char_u *buts;
2501 char_u *p, *next;
2502 XtAppContext app;
2503 XmString label;
2504 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002505 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 Widget dialogform = NULL;
2507 Widget form = NULL;
2508 Widget dialogtextfield = NULL;
2509 Widget *buttons;
2510 Widget sep_form = NULL;
2511 Boolean vertical;
2512 Widget separator = NULL;
2513 int n;
2514 Arg args[6];
2515#ifdef HAVE_XPM
2516 char **icon_data = NULL;
2517 Widget dialogpixmap = NULL;
2518#endif
2519
2520 if (title == NULL)
2521 title = (char_u *)_("Vim dialog");
2522
Bram Moolenaar734a8672019-12-02 22:49:38 +01002523 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 gui_mch_mousehide(FALSE);
2525
2526 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2527
Bram Moolenaar734a8672019-12-02 22:49:38 +01002528 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2530
Bram Moolenaar734a8672019-12-02 22:49:38 +01002531 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 label = XmStringCreateSimple((char *)title);
2533 if (label == NULL)
2534 return -1;
2535 XtVaSetValues(dialogform,
2536 XmNdialogTitle, label,
2537 XmNhorizontalSpacing, 4,
2538 XmNverticalSpacing, vertical ? 0 : 4,
2539 NULL);
2540 XmStringFree(label);
2541
Bram Moolenaar734a8672019-12-02 22:49:38 +01002542 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 buts = vim_strsave(button_names);
2544 if (buts == NULL)
2545 return -1;
2546
Bram Moolenaar734a8672019-12-02 22:49:38 +01002547 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 butcount = 1;
2549 for (p = buts; *p; ++p)
2550 if (*p == DLG_BUTTON_SEP)
2551 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002552 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 if (buttons == NULL)
2554 {
2555 vim_free(buts);
2556 return -1;
2557 }
2558
2559 /*
2560 * Create the buttons.
2561 */
2562 sep_form = (Widget) 0;
2563 p = buts;
2564 for (butcount = 0; *p; ++butcount)
2565 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002566 KeySym mnemonic = NUL;
2567
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 for (next = p; *next; ++next)
2569 {
2570 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002571 {
2572 int len = STRLEN(next);
2573
2574 if (len > 0)
2575 {
2576 mch_memmove(next, next + 1, len);
2577 mnemonic = next[0];
2578 }
2579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 if (*next == DLG_BUTTON_SEP)
2581 {
2582 *next++ = NUL;
2583 break;
2584 }
2585 }
2586 label = XmStringCreate(_((char *)p), STRING_TAG);
2587 if (label == NULL)
2588 break;
2589
2590 buttons[butcount] = XtVaCreateManagedWidget("button",
2591 xmPushButtonWidgetClass, dialogform,
2592 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002593 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 XmNbottomAttachment, XmATTACH_FORM,
2595 XmNbottomOffset, 4,
2596 XmNshowAsDefault, butcount == dfltbutton - 1,
2597 XmNdefaultButtonShadowThickness, 1,
2598 NULL);
2599 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002600 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601
Bram Moolenaar734a8672019-12-02 22:49:38 +01002602 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603
2604 if (butcount > 0)
2605 {
2606 if (vertical)
2607 XtVaSetValues(buttons[butcount],
2608 XmNtopWidget, buttons[butcount - 1],
2609 NULL);
2610 else
2611 {
2612 if (*next == NUL)
2613 {
2614 XtVaSetValues(buttons[butcount],
2615 XmNrightAttachment, XmATTACH_FORM,
2616 XmNrightOffset, 4,
2617 NULL);
2618
Bram Moolenaar734a8672019-12-02 22:49:38 +01002619 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 sep_form = XtVaCreateWidget("separatorForm",
2621 xmFormWidgetClass, dialogform,
2622 XmNleftAttachment, XmATTACH_WIDGET,
2623 XmNleftWidget, buttons[butcount - 1],
2624 XmNrightAttachment, XmATTACH_WIDGET,
2625 XmNrightWidget, buttons[butcount],
2626 XmNbottomAttachment, XmATTACH_FORM,
2627 XmNbottomOffset, 4,
2628 NULL);
2629 XtManageChild(sep_form);
2630 }
2631 else
2632 {
2633 XtVaSetValues(buttons[butcount],
2634 XmNleftAttachment, XmATTACH_WIDGET,
2635 XmNleftWidget, buttons[butcount - 1],
2636 NULL);
2637 }
2638 }
2639 }
2640 else if (!vertical)
2641 {
2642 if (*next == NUL)
2643 {
2644 XtVaSetValues(buttons[0],
2645 XmNrightAttachment, XmATTACH_FORM,
2646 XmNrightOffset, 4,
2647 NULL);
2648
Bram Moolenaar734a8672019-12-02 22:49:38 +01002649 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 sep_form = XtVaCreateWidget("separatorForm",
2651 xmFormWidgetClass, dialogform,
2652 XmNleftAttachment, XmATTACH_FORM,
2653 XmNleftOffset, 4,
2654 XmNrightAttachment, XmATTACH_WIDGET,
2655 XmNrightWidget, buttons[0],
2656 XmNbottomAttachment, XmATTACH_FORM,
2657 XmNbottomOffset, 4,
2658 NULL);
2659 XtManageChild(sep_form);
2660 }
2661 else
2662 XtVaSetValues(buttons[0],
2663 XmNleftAttachment, XmATTACH_FORM,
2664 XmNleftOffset, 4,
2665 NULL);
2666 }
2667
2668 XtAddCallback(buttons[butcount], XmNactivateCallback,
2669 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2670 p = next;
2671 }
2672 vim_free(buts);
2673
2674 separator = (Widget) 0;
2675 if (butcount > 0)
2676 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002677 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 n = 0;
2679 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2680 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2681 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2682 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2683 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2684 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2685 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2686 XtManageChild(separator);
2687 }
2688
2689 if (textfield != NULL)
2690 {
2691 dialogtextfield = XtVaCreateWidget("textField",
2692 xmTextFieldWidgetClass, dialogform,
2693 XmNleftAttachment, XmATTACH_FORM,
2694 XmNrightAttachment, XmATTACH_FORM,
2695 NULL);
2696 if (butcount > 0)
2697 XtVaSetValues(dialogtextfield,
2698 XmNbottomAttachment, XmATTACH_WIDGET,
2699 XmNbottomWidget, separator,
2700 NULL);
2701 else
2702 XtVaSetValues(dialogtextfield,
2703 XmNbottomAttachment, XmATTACH_FORM,
2704 NULL);
2705
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002706 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2708 XtManageChild(dialogtextfield);
2709 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2710 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2711 }
2712
Bram Moolenaar734a8672019-12-02 22:49:38 +01002713 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 form = XtVaCreateWidget("separatorForm",
2715 xmFormWidgetClass, dialogform,
2716 XmNleftAttachment, XmATTACH_FORM,
2717 XmNrightAttachment, XmATTACH_FORM,
2718 XmNtopAttachment, XmATTACH_FORM,
2719 NULL);
2720 XtManageChild(form);
2721
2722#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002723 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 switch (type)
2725 {
2726 case VIM_GENERIC:
2727 icon_data = generic_xpm;
2728 break;
2729 case VIM_ERROR:
2730 icon_data = error_xpm;
2731 break;
2732 case VIM_WARNING:
2733 icon_data = alert_xpm;
2734 break;
2735 case VIM_INFO:
2736 icon_data = info_xpm;
2737 break;
2738 case VIM_QUESTION:
2739 icon_data = quest_xpm;
2740 break;
2741 default:
2742 icon_data = generic_xpm;
2743 }
2744
2745 n = 0;
2746 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2747 XtSetArg(args[n], XmNtopOffset, 8); n++;
2748 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2749 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2750 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2751 XtSetArg(args[n], XmNleftOffset, 8); n++;
2752
2753 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2754 icon_data, args, n);
2755 XtManageChild(dialogpixmap);
2756#endif
2757
Bram Moolenaar734a8672019-12-02 22:49:38 +01002758 // Create the dialog message.
2759 // Since LessTif is apparently having problems with the creation of
2760 // properly localized string, we use LtoR here. The symptom is that the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002761 // string is not shown properly in multiple lines as it does in native
Bram Moolenaar734a8672019-12-02 22:49:38 +01002762 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002763 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 if (label == NULL)
2765 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002766 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 xmLabelGadgetClass, form,
2768 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002769 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 XmNtopAttachment, XmATTACH_FORM,
2771 XmNtopOffset, 8,
2772#ifdef HAVE_XPM
2773 XmNleftAttachment, XmATTACH_WIDGET,
2774 XmNleftWidget, dialogpixmap,
2775#else
2776 XmNleftAttachment, XmATTACH_FORM,
2777#endif
2778 XmNleftOffset, 8,
2779 XmNrightAttachment, XmATTACH_FORM,
2780 XmNrightOffset, 8,
2781 XmNbottomAttachment, XmATTACH_FORM,
2782 XmNbottomOffset, 8,
2783 NULL);
2784 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002785 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786
2787 if (textfield != NULL)
2788 {
2789 XtVaSetValues(form,
2790 XmNbottomAttachment, XmATTACH_WIDGET,
2791 XmNbottomWidget, dialogtextfield,
2792 NULL);
2793 }
2794 else
2795 {
2796 if (butcount > 0)
2797 XtVaSetValues(form,
2798 XmNbottomAttachment, XmATTACH_WIDGET,
2799 XmNbottomWidget, separator,
2800 NULL);
2801 else
2802 XtVaSetValues(form,
2803 XmNbottomAttachment, XmATTACH_FORM,
2804 NULL);
2805 }
2806
2807 if (dfltbutton < 1)
2808 dfltbutton = 1;
2809 if (dfltbutton > butcount)
2810 dfltbutton = butcount;
2811 XtVaSetValues(dialogform,
2812 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2813 if (textfield != NULL)
2814 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2815 else
2816 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2817 NULL);
2818
2819 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002820 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821
2822 if (textfield != NULL && *textfield != NUL)
2823 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002824 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 XmTextFieldSetSelection(dialogtextfield,
2826 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2827 XtLastTimestampProcessed(gui.dpy));
2828 XmTextFieldSetCursorPosition(dialogtextfield,
2829 (XmTextPosition)STRLEN(textfield));
2830 }
2831
2832 app = XtWidgetToApplicationContext(dialogform);
2833
Bram Moolenaar734a8672019-12-02 22:49:38 +01002834 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 dialogStatus = -1;
2836 for (;;)
2837 {
2838 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2839 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2840 break;
2841 }
2842
2843 vim_free(buttons);
2844
2845 if (textfield != NULL)
2846 {
2847 p = (char_u *)XmTextGetString(dialogtextfield);
2848 if (p == NULL || dialogStatus < 0)
2849 *textfield = NUL;
2850 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002851 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002852 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 }
2854
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002855 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 XtDestroyWidget(dialogform);
2857
2858 return dialogStatus;
2859}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002860#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861
2862#if defined(FEAT_FOOTER) || defined(PROTO)
2863
2864 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002865gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002867 Dimension height; // total Toolbar height
2868 Dimension top; // XmNmarginTop
2869 Dimension bottom; // XmNmarginBottom
2870 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871
2872 XtVaGetValues(footer,
2873 XmNheight, &height,
2874 XmNmarginTop, &top,
2875 XmNmarginBottom, &bottom,
2876 XmNshadowThickness, &shadow,
2877 NULL);
2878
2879 return (int) height + top + bottom + (shadow << 1);
2880}
2881
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002883gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884{
2885 if (showit)
2886 {
2887 gui.footer_height = gui_mch_compute_footer_height();
2888 XtManageChild(footer);
2889 }
2890 else
2891 {
2892 gui.footer_height = 0;
2893 XtUnmanageChild(footer);
2894 }
2895 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2896}
2897
2898 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002899gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900{
2901 XmString xms;
2902
2903 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002904 if (xms != NULL)
2905 {
2906 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2907 XmStringFree(xms);
2908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909}
2910
2911#endif
2912
2913
2914#if defined(FEAT_TOOLBAR) || defined(PROTO)
2915 void
2916gui_mch_show_toolbar(int showit)
2917{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002918 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919
2920 if (toolBar == (Widget)0)
2921 return;
2922 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2923 if (showit && numChildren > 0)
2924 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002925 // Assume that we want to show the toolbar if p_toolbar contains
2926 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 WidgetList children;
2928
2929 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2930 {
2931 void (*action)(BalloonEval *);
2932 int text = 0;
2933
2934 if (strstr((const char *)p_toolbar, "tooltips"))
2935 action = &gui_mch_enable_beval_area;
2936 else
2937 action = &gui_mch_disable_beval_area;
2938 if (strstr((const char *)p_toolbar, "text"))
2939 text = 1;
2940 else if (strstr((const char *)p_toolbar, "icons"))
2941 text = -1;
2942 if (text != 0)
2943 {
2944 vimmenu_T *toolbar;
2945 vimmenu_T *cur;
2946
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002947 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 if (menu_is_toolbar(toolbar->dname))
2949 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002950 // Assumption: toolbar is NULL if there is no toolbar,
2951 // otherwise it contains the toolbar menu structure.
2952 //
2953 // Assumption: "numChildren" == the number of items in the list
2954 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 if (toolbar)
2956 {
2957 for (cur = toolbar->children; cur; cur = cur->next)
2958 {
2959 Arg args[1];
2960 int n = 0;
2961
Bram Moolenaar734a8672019-12-02 22:49:38 +01002962 // Enable/Disable tooltip (OK to enable while
2963 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 if (cur->tip != NULL)
2965 (*action)(cur->tip);
2966 if (!menu_is_separator(cur->name))
2967 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002968 if (text == 1 || cur->xpm == NULL)
2969 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002971 ++n;
2972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 if (cur->id != NULL)
2974 {
2975 XtUnmanageChild(cur->id);
2976 XtSetValues(cur->id, args, n);
2977 XtManageChild(cur->id);
2978 }
2979 }
2980 }
2981 }
2982 }
2983 }
2984 gui.toolbar_height = gui_mch_compute_toolbar_height();
2985 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002986#ifdef FEAT_GUI_TABLINE
2987 if (showing_tabline)
2988 {
2989 XtVaSetValues(tabLine,
2990 XmNtopAttachment, XmATTACH_WIDGET,
2991 XmNtopWidget, XtParent(toolBar),
2992 NULL);
2993 XtVaSetValues(textAreaForm,
2994 XmNtopAttachment, XmATTACH_WIDGET,
2995 XmNtopWidget, tabLine,
2996 NULL);
2997 }
2998 else
2999#endif
3000 XtVaSetValues(textAreaForm,
3001 XmNtopAttachment, XmATTACH_WIDGET,
3002 XmNtopWidget, XtParent(toolBar),
3003 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 if (XtIsManaged(menuBar))
3005 XtVaSetValues(XtParent(toolBar),
3006 XmNtopAttachment, XmATTACH_WIDGET,
3007 XmNtopWidget, menuBar,
3008 NULL);
3009 else
3010 XtVaSetValues(XtParent(toolBar),
3011 XmNtopAttachment, XmATTACH_FORM,
3012 NULL);
3013 }
3014 else
3015 {
3016 gui.toolbar_height = 0;
3017 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003018 {
3019#ifdef FEAT_GUI_TABLINE
3020 if (showing_tabline)
3021 {
3022 XtVaSetValues(tabLine,
3023 XmNtopAttachment, XmATTACH_WIDGET,
3024 XmNtopWidget, menuBar,
3025 NULL);
3026 XtVaSetValues(textAreaForm,
3027 XmNtopAttachment, XmATTACH_WIDGET,
3028 XmNtopWidget, tabLine,
3029 NULL);
3030 }
3031 else
3032#endif
3033 XtVaSetValues(textAreaForm,
3034 XmNtopAttachment, XmATTACH_WIDGET,
3035 XmNtopWidget, menuBar,
3036 NULL);
3037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003039 {
3040#ifdef FEAT_GUI_TABLINE
3041 if (showing_tabline)
3042 {
3043 XtVaSetValues(tabLine,
3044 XmNtopAttachment, XmATTACH_FORM,
3045 NULL);
3046 XtVaSetValues(textAreaForm,
3047 XmNtopAttachment, XmATTACH_WIDGET,
3048 XmNtopWidget, tabLine,
3049 NULL);
3050 }
3051 else
3052#endif
3053 XtVaSetValues(textAreaForm,
3054 XmNtopAttachment, XmATTACH_FORM,
3055 NULL);
3056 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057
3058 XtUnmanageChild(XtParent(toolBar));
3059 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003060 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061}
3062
3063/*
3064 * A toolbar button has been pushed; now reset the input focus
3065 * such that the user can type page up/down etc. and have the
3066 * input go to the editor window, not the button
3067 */
3068 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003069reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070{
3071 if (textArea != NULL)
3072 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3073}
3074
3075 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003076gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003078 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003079 Dimension height; // total Toolbar height
3080 Dimension whgt; // height of each widget
3081 WidgetList children; // list of toolBar's children
3082 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 int i;
3084
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003085 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003088 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003089 Dimension fst;
3090 Dimension fmh;
3091 Dimension tst;
3092 Dimension tmh;
3093
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003095 XmNshadowThickness, &fst,
3096 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003098 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003100 XmNshadowThickness, &tst,
3101 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 XmNchildren, &children,
3103 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003104 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003105 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 {
3107 whgt = 0;
3108 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3109 if (height < whgt)
3110 height = whgt;
3111 }
3112 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003113#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003114 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003115 if (height < 10)
3116 height = 24;
3117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003119 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120}
3121
Bram Moolenaar7c626922005-02-07 22:01:03 +00003122 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003123motif_get_toolbar_colors(
3124 Pixel *bgp,
3125 Pixel *fgp,
3126 Pixel *bsp,
3127 Pixel *tsp,
3128 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129{
3130 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003131 XmNbackground, bgp,
3132 XmNforeground, fgp,
3133 XmNbottomShadowColor, bsp,
3134 XmNtopShadowColor, tsp,
3135 XmNhighlightColor, hsp,
3136 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003137}
3138
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139# ifdef FEAT_FOOTER
3140/*
3141 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003142 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 * get implemented and the user will have a choice.
3144 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003146toolbarbutton_enter_cb(
3147 Widget w UNUSED,
3148 XtPointer client_data,
3149 XEvent *event UNUSED,
3150 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151{
3152 vimmenu_T *menu = (vimmenu_T *) client_data;
3153
3154 if (menu->strings[MENU_INDEX_TIP] != NULL)
3155 {
3156 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3157 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3158 }
3159}
3160
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003162toolbarbutton_leave_cb(
3163 Widget w UNUSED,
3164 XtPointer client_data UNUSED,
3165 XEvent *event UNUSED,
3166 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167{
3168 gui_mch_set_footer((char_u *) "");
3169}
3170# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171#endif
3172
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003173#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3174/*
3175 * Show or hide the tabline.
3176 */
3177 void
3178gui_mch_show_tabline(int showit)
3179{
3180 if (tabLine == (Widget)0)
3181 return;
3182
3183 if (!showit != !showing_tabline)
3184 {
3185 if (showit)
3186 {
3187 XtManageChild(tabLine);
3188 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003189 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3190 XtUnmanageChild(XtNameToWidget(tabLine,
3191 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003192#ifdef FEAT_MENU
3193# ifdef FEAT_TOOLBAR
3194 if (XtIsManaged(XtParent(toolBar)))
3195 XtVaSetValues(tabLine,
3196 XmNtopAttachment, XmATTACH_WIDGET,
3197 XmNtopWidget, XtParent(toolBar), NULL);
3198 else
3199# endif
3200 if (XtIsManaged(menuBar))
3201 XtVaSetValues(tabLine,
3202 XmNtopAttachment, XmATTACH_WIDGET,
3203 XmNtopWidget, menuBar, NULL);
3204 else
3205#endif
3206 XtVaSetValues(tabLine,
3207 XmNtopAttachment, XmATTACH_FORM, NULL);
3208 XtVaSetValues(textAreaForm,
3209 XmNtopAttachment, XmATTACH_WIDGET,
3210 XmNtopWidget, tabLine,
3211 NULL);
3212 }
3213 else
3214 {
3215 XtUnmanageChild(tabLine);
3216#ifdef FEAT_MENU
3217# ifdef FEAT_TOOLBAR
3218 if (XtIsManaged(XtParent(toolBar)))
3219 XtVaSetValues(textAreaForm,
3220 XmNtopAttachment, XmATTACH_WIDGET,
3221 XmNtopWidget, XtParent(toolBar), NULL);
3222 else
3223# endif
3224 if (XtIsManaged(menuBar))
3225 XtVaSetValues(textAreaForm,
3226 XmNtopAttachment, XmATTACH_WIDGET,
3227 XmNtopWidget, menuBar, NULL);
3228 else
3229#endif
3230 XtVaSetValues(textAreaForm,
3231 XmNtopAttachment, XmATTACH_FORM, NULL);
3232 }
3233 showing_tabline = showit;
3234 }
3235}
3236
3237/*
3238 * Return TRUE when tabline is displayed.
3239 */
3240 int
3241gui_mch_showing_tabline(void)
3242{
3243 return tabLine != (Widget)0 && showing_tabline;
3244}
3245
3246/*
3247 * Update the labels of the tabline.
3248 */
3249 void
3250gui_mch_update_tabline(void)
3251{
3252 tabpage_T *tp;
3253 int nr = 1, n;
3254 Arg args[10];
3255 int curtabidx = 0, currentpage;
3256 Widget tab;
3257 XmNotebookPageInfo page_info;
3258 XmNotebookPageStatus page_status;
3259 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003260 XmString label_str;
3261 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003262 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003263
3264 if (tabLine == (Widget)0)
3265 return;
3266
Bram Moolenaar734a8672019-12-02 22:49:38 +01003267 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003268 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3269 {
3270 if (tp == curtab)
3271 curtabidx = nr;
3272
3273 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3274 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003275 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003276 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003277 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003278 n = 0;
3279 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3280 XtSetArg(args[n], XmNtraversalOn, False); n++;
3281 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3282 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3283 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3284 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3285 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003286 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3287 NULL);
3288 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003289 }
3290 else
3291 tab = page_info.major_tab_widget;
3292
3293 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003294
3295 /*
3296 * Change the label text only if it is different
3297 */
3298 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3299 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3300 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003301 get_tabline_label(tp, FALSE);
3302 if (STRCMP(label_cstr, NameBuff) != 0)
3303 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003304 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3305 NameBuff, STRLEN(NameBuff) + 1, NULL);
3306 /*
3307 * Force a resize of the tab label button
3308 */
3309 XtUnmanageChild(tab);
3310 XtManageChild(tab);
3311 }
3312 XtFree(label_cstr);
3313 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003314 }
3315
3316 tab_count = nr - 1;
3317
3318 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3319
Bram Moolenaar734a8672019-12-02 22:49:38 +01003320 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003321 while (nr <= last_page)
3322 {
3323 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3324 && page_info.page_number == nr
3325 && page_info.major_tab_widget != (Widget)0)
3326 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003327 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3328 if (beval != NULL)
3329 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003330 XtUnmanageChild(page_info.major_tab_widget);
3331 XtDestroyWidget(page_info.major_tab_widget);
3332 }
3333 nr++;
3334 }
3335
3336 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3337
3338 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3339 if (currentpage != curtabidx)
3340 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3341}
3342
3343/*
3344 * Set the current tab to "nr". First tab is 1.
3345 */
3346 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003347gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003348{
3349 int currentpage;
3350
3351 if (tabLine == (Widget)0)
3352 return;
3353
3354 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3355 if (currentpage != nr)
3356 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3357}
3358#endif
3359
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360/*
3361 * Set the colors of Widget "id" to the menu colors.
3362 */
3363 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003364gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365{
3366 if (gui.menu_bg_pixel != INVALCOLOR)
3367#if (XmVersion >= 1002)
3368 XmChangeColor(id, gui.menu_bg_pixel);
3369#else
3370 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3371#endif
3372 if (gui.menu_fg_pixel != INVALCOLOR)
3373 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3374}
3375
3376/*
3377 * Set the colors of Widget "id" to the scrollbar colors.
3378 */
3379 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003380gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381{
3382 if (gui.scroll_bg_pixel != INVALCOLOR)
3383#if (XmVersion >= 1002)
3384 XmChangeColor(id, gui.scroll_bg_pixel);
3385#else
3386 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3387#endif
3388 if (gui.scroll_fg_pixel != INVALCOLOR)
3389 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3390}
3391
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392/*
3393 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3394 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003395 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003396gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003398#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399#ifdef FONTSET_ALWAYS
3400 if (gui.menu_fontset != NOFONTSET)
3401 {
3402 XmFontList fl;
3403
3404 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3405 if (fl != NULL)
3406 {
3407 if (XtIsManaged(id))
3408 {
3409 XtUnmanageChild(id);
3410 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003411 // We should force the widget to recalculate its
3412 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 XtManageChild(id);
3414 }
3415 else
3416 XtVaSetValues(id, XmNfontList, fl, NULL);
3417 XmFontListFree(fl);
3418 }
3419 }
3420#else
3421 if (gui.menu_font != NOFONT)
3422 {
3423 XmFontList fl;
3424
3425 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3426 if (fl != NULL)
3427 {
3428 if (XtIsManaged(id))
3429 {
3430 XtUnmanageChild(id);
3431 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003432 // We should force the widget to recalculate its
3433 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 XtManageChild(id);
3435 }
3436 else
3437 XtVaSetValues(id, XmNfontList, fl, NULL);
3438 XmFontListFree(fl);
3439 }
3440 }
3441#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443}
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445
3446/*
3447 * We don't create it twice for the sake of speed.
3448 */
3449
3450typedef struct _SharedFindReplace
3451{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003452 Widget dialog; // the main dialog widget
3453 Widget wword; // 'Exact match' check button
3454 Widget mcase; // 'match case' check button
3455 Widget up; // search direction 'Up' radio button
3456 Widget down; // search direction 'Down' radio button
3457 Widget what; // 'Find what' entry text widget
3458 Widget with; // 'Replace with' entry text widget
3459 Widget find; // 'Find Next' action button
3460 Widget replace; // 'Replace With' action button
3461 Widget all; // 'Replace All' action button
3462 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463
3464 Widget cancel;
3465} SharedFindReplace;
3466
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003467static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3468static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003471find_replace_destroy_callback(
3472 Widget w UNUSED,
3473 XtPointer client_data,
3474 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475{
3476 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3477
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003478 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003479 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 cd->dialog = (Widget)0;
3481}
3482
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003484find_replace_dismiss_callback(
3485 Widget w UNUSED,
3486 XtPointer client_data,
3487 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488{
3489 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3490
3491 if (cd != NULL)
3492 XtUnmanageChild(cd->dialog);
3493}
3494
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003496entry_activate_callback(
3497 Widget w UNUSED,
3498 XtPointer client_data,
3499 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500{
3501 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3502}
3503
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003505find_replace_callback(
3506 Widget w UNUSED,
3507 XtPointer client_data,
3508 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509{
3510 long_u flags = (long_u)client_data;
3511 char *find_text, *repl_text;
3512 Boolean direction_down = TRUE;
3513 Boolean wword;
3514 Boolean mcase;
3515 SharedFindReplace *sfr;
3516
3517 if (flags == FRD_UNDO)
3518 {
3519 char_u *save_cpo = p_cpo;
3520
Bram Moolenaar734a8672019-12-02 22:49:38 +01003521 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003522 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523 u_undo(1);
3524 p_cpo = save_cpo;
3525 gui_update_screen();
3526 return;
3527 }
3528
Bram Moolenaar734a8672019-12-02 22:49:38 +01003529 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530 if (flags == FRD_FINDNEXT)
3531 {
3532 repl_text = NULL;
3533 sfr = &find_widgets;
3534 }
3535 else
3536 {
3537 repl_text = XmTextFieldGetString(repl_widgets.with);
3538 sfr = &repl_widgets;
3539 }
3540 find_text = XmTextFieldGetString(sfr->what);
3541 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3542 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3543 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3544 if (wword)
3545 flags |= FRD_WHOLE_WORD;
3546 if (mcase)
3547 flags |= FRD_MATCH_CASE;
3548
3549 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3550 direction_down);
3551
3552 if (find_text != NULL)
3553 XtFree(find_text);
3554 if (repl_text != NULL)
3555 XtFree(repl_text);
3556}
3557
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003559find_replace_keypress(
3560 Widget w UNUSED,
3561 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003562 XKeyEvent *event,
3563 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564{
3565 KeySym keysym;
3566
3567 if (frdp == NULL)
3568 return;
3569
3570 keysym = XLookupKeysym(event, 0);
3571
Bram Moolenaar734a8672019-12-02 22:49:38 +01003572 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 if (keysym == XK_Escape)
3574 XtUnmanageChild(frdp->dialog);
3575}
3576
3577 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003578set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003579{
3580 XmString str;
3581 char_u *p, *next;
3582 KeySym mnemonic = NUL;
3583
3584 if (!w)
3585 return;
3586
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003587 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003588 if (p == NULL)
3589 return;
3590 for (next = p; *next; ++next)
3591 {
3592 if (*next == DLG_HOTKEY_CHAR)
3593 {
3594 int len = STRLEN(next);
3595
3596 if (len > 0)
3597 {
3598 mch_memmove(next, next + 1, len);
3599 mnemonic = next[0];
3600 }
3601 }
3602 }
3603
3604 str = XmStringCreateSimple((char *)p);
3605 vim_free(p);
3606 if (str)
3607 {
3608 XtVaSetValues(w,
3609 XmNlabelString, str,
3610 XmNmnemonic, mnemonic,
3611 NULL);
3612 XmStringFree(str);
3613 }
3614 gui_motif_menu_fontlist(w);
3615}
3616
3617 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003618find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003619{
3620 SharedFindReplace *frdp;
3621 Widget separator;
3622 Widget input_form;
3623 Widget button_form;
3624 Widget toggle_form;
3625 Widget frame;
3626 XmString str;
3627 int n;
3628 Arg args[6];
3629 int wword = FALSE;
3630 int mcase = !p_ic;
3631 Dimension width;
3632 Dimension widest;
3633 char_u *entry_text;
3634
3635 frdp = do_replace ? &repl_widgets : &find_widgets;
3636
Bram Moolenaar734a8672019-12-02 22:49:38 +01003637 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3639
Bram Moolenaar734a8672019-12-02 22:49:38 +01003640 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 if (frdp->dialog)
3642 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003643 gui_motif_synch_fonts();
3644
Bram Moolenaar734a8672019-12-02 22:49:38 +01003645 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 if (XtIsManaged(frdp->dialog))
3647 XMapRaised(XtDisplay(frdp->dialog),
3648 XtWindow(XtParent(frdp->dialog)));
3649 else
3650 XtManageChild(frdp->dialog);
3651 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3652 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3653
3654 if (entry_text != NULL)
3655 XmTextFieldSetString(frdp->what, (char *)entry_text);
3656 vim_free(entry_text);
3657
3658 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3659 return;
3660 }
3661
Bram Moolenaar734a8672019-12-02 22:49:38 +01003662 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003663 if (do_replace)
3664 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3665 else
3666 str = XmStringCreateSimple(_("VIM - Search..."));
3667
3668 n = 0;
3669 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3670 XtSetArg(args[n], XmNnoResize, True); n++;
3671 XtSetArg(args[n], XmNdialogTitle, str); n++;
3672
3673 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3674 XmStringFree(str);
3675 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3676 find_replace_destroy_callback, frdp);
3677
3678 button_form = XtVaCreateWidget("buttonForm",
3679 xmFormWidgetClass, frdp->dialog,
3680 XmNrightAttachment, XmATTACH_FORM,
3681 XmNrightOffset, 4,
3682 XmNtopAttachment, XmATTACH_FORM,
3683 XmNtopOffset, 4,
3684 XmNbottomAttachment, XmATTACH_FORM,
3685 XmNbottomOffset, 4,
3686 NULL);
3687
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 frdp->find = XtVaCreateManagedWidget("findButton",
3689 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690 XmNsensitive, True,
3691 XmNtopAttachment, XmATTACH_FORM,
3692 XmNleftAttachment, XmATTACH_FORM,
3693 XmNrightAttachment, XmATTACH_FORM,
3694 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003695 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696
3697 XtAddCallback(frdp->find, XmNactivateCallback,
3698 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003699 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700
3701 if (do_replace)
3702 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3704 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 XmNtopAttachment, XmATTACH_WIDGET,
3706 XmNtopWidget, frdp->find,
3707 XmNleftAttachment, XmATTACH_FORM,
3708 XmNrightAttachment, XmATTACH_FORM,
3709 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003710 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 XtAddCallback(frdp->replace, XmNactivateCallback,
3712 find_replace_callback, (XtPointer)FRD_REPLACE);
3713
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3715 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 XmNtopAttachment, XmATTACH_WIDGET,
3717 XmNtopWidget, frdp->replace,
3718 XmNleftAttachment, XmATTACH_FORM,
3719 XmNrightAttachment, XmATTACH_FORM,
3720 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003721 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 XtAddCallback(frdp->all, XmNactivateCallback,
3723 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3724
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 frdp->undo = XtVaCreateManagedWidget("undoButton",
3726 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 XmNtopAttachment, XmATTACH_WIDGET,
3728 XmNtopWidget, frdp->all,
3729 XmNleftAttachment, XmATTACH_FORM,
3730 XmNrightAttachment, XmATTACH_FORM,
3731 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003732 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 XtAddCallback(frdp->undo, XmNactivateCallback,
3734 find_replace_callback, (XtPointer)FRD_UNDO);
3735 }
3736
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3738 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 XmNleftAttachment, XmATTACH_FORM,
3740 XmNrightAttachment, XmATTACH_FORM,
3741 XmNbottomAttachment, XmATTACH_FORM,
3742 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003743 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 XtAddCallback(frdp->cancel, XmNactivateCallback,
3745 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003746 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747
3748 XtManageChild(button_form);
3749
3750 n = 0;
3751 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3752 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3753 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3754 XtSetArg(args[n], XmNrightOffset, 4); n++;
3755 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3756 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3757 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3758 XtManageChild(separator);
3759
3760 input_form = XtVaCreateWidget("inputForm",
3761 xmFormWidgetClass, frdp->dialog,
3762 XmNleftAttachment, XmATTACH_FORM,
3763 XmNleftOffset, 4,
3764 XmNrightAttachment, XmATTACH_WIDGET,
3765 XmNrightWidget, separator,
3766 XmNrightOffset, 4,
3767 XmNtopAttachment, XmATTACH_FORM,
3768 XmNtopOffset, 4,
3769 NULL);
3770
3771 {
3772 Widget label_what;
3773 Widget label_with = (Widget)0;
3774
3775 str = XmStringCreateSimple(_("Find what:"));
3776 label_what = XtVaCreateManagedWidget("whatLabel",
3777 xmLabelGadgetClass, input_form,
3778 XmNlabelString, str,
3779 XmNleftAttachment, XmATTACH_FORM,
3780 XmNtopAttachment, XmATTACH_FORM,
3781 XmNtopOffset, 4,
3782 NULL);
3783 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003784 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785
3786 frdp->what = XtVaCreateManagedWidget("whatText",
3787 xmTextFieldWidgetClass, input_form,
3788 XmNtopAttachment, XmATTACH_FORM,
3789 XmNrightAttachment, XmATTACH_FORM,
3790 XmNleftAttachment, XmATTACH_FORM,
3791 NULL);
3792
3793 if (do_replace)
3794 {
3795 frdp->with = XtVaCreateManagedWidget("withText",
3796 xmTextFieldWidgetClass, input_form,
3797 XmNtopAttachment, XmATTACH_WIDGET,
3798 XmNtopWidget, frdp->what,
3799 XmNtopOffset, 4,
3800 XmNleftAttachment, XmATTACH_FORM,
3801 XmNrightAttachment, XmATTACH_FORM,
3802 XmNbottomAttachment, XmATTACH_FORM,
3803 NULL);
3804
3805 XtAddCallback(frdp->with, XmNactivateCallback,
3806 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3807
3808 str = XmStringCreateSimple(_("Replace with:"));
3809 label_with = XtVaCreateManagedWidget("withLabel",
3810 xmLabelGadgetClass, input_form,
3811 XmNlabelString, str,
3812 XmNleftAttachment, XmATTACH_FORM,
3813 XmNtopAttachment, XmATTACH_WIDGET,
3814 XmNtopWidget, frdp->what,
3815 XmNtopOffset, 4,
3816 XmNbottomAttachment, XmATTACH_FORM,
3817 NULL);
3818 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003819 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820
3821 /*
3822 * Make the entry activation only change the input focus onto the
3823 * with item.
3824 */
3825 XtAddCallback(frdp->what, XmNactivateCallback,
3826 entry_activate_callback, frdp->with);
3827 XtAddEventHandler(frdp->with, KeyPressMask, False,
3828 (XtEventHandler)find_replace_keypress,
3829 (XtPointer) frdp);
3830
3831 }
3832 else
3833 {
3834 /*
3835 * Make the entry activation do the search.
3836 */
3837 XtAddCallback(frdp->what, XmNactivateCallback,
3838 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3839 }
3840 XtAddEventHandler(frdp->what, KeyPressMask, False,
3841 (XtEventHandler)find_replace_keypress,
3842 (XtPointer)frdp);
3843
Bram Moolenaar734a8672019-12-02 22:49:38 +01003844 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845 n = 0;
3846 XtSetArg(args[n], XmNwidth, &width); n++;
3847 XtGetValues(label_what, args, n);
3848 widest = width;
3849 if (do_replace)
3850 {
3851 XtGetValues(label_with, args, n);
3852 if (width > widest)
3853 widest = width;
3854 }
3855
3856 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3857 if (do_replace)
3858 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3859
3860 }
3861
3862 XtManageChild(input_form);
3863
3864 {
3865 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003866 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867
3868 frame = XtVaCreateWidget("directionFrame",
3869 xmFrameWidgetClass, frdp->dialog,
3870 XmNtopAttachment, XmATTACH_WIDGET,
3871 XmNtopWidget, input_form,
3872 XmNtopOffset, 4,
3873 XmNbottomAttachment, XmATTACH_FORM,
3874 XmNbottomOffset, 4,
3875 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3876 XmNrightWidget, input_form,
3877 NULL);
3878
3879 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003880 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881 xmLabelGadgetClass, frame,
3882 XmNlabelString, str,
3883 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3884 XmNchildType, XmFRAME_TITLE_CHILD,
3885 NULL);
3886 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003887 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888
3889 radio_box = XmCreateRadioBox(frame, "radioBox",
3890 (ArgList)NULL, 0);
3891
3892 str = XmStringCreateSimple( _("Up"));
3893 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3894 xmToggleButtonGadgetClass, radio_box,
3895 XmNlabelString, str,
3896 XmNset, False,
3897 NULL);
3898 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003899 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900
3901 str = XmStringCreateSimple(_("Down"));
3902 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3903 xmToggleButtonGadgetClass, radio_box,
3904 XmNlabelString, str,
3905 XmNset, True,
3906 NULL);
3907 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003908 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909
3910 XtManageChild(radio_box);
3911 XtManageChild(frame);
3912 }
3913
3914 toggle_form = XtVaCreateWidget("toggleForm",
3915 xmFormWidgetClass, frdp->dialog,
3916 XmNleftAttachment, XmATTACH_FORM,
3917 XmNleftOffset, 4,
3918 XmNrightAttachment, XmATTACH_WIDGET,
3919 XmNrightWidget, frame,
3920 XmNrightOffset, 4,
3921 XmNtopAttachment, XmATTACH_WIDGET,
3922 XmNtopWidget, input_form,
3923 XmNtopOffset, 4,
3924 XmNbottomAttachment, XmATTACH_FORM,
3925 XmNbottomOffset, 4,
3926 NULL);
3927
3928 str = XmStringCreateSimple(_("Match whole word only"));
3929 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3930 xmToggleButtonGadgetClass, toggle_form,
3931 XmNlabelString, str,
3932 XmNtopAttachment, XmATTACH_FORM,
3933 XmNtopOffset, 4,
3934 XmNleftAttachment, XmATTACH_FORM,
3935 XmNleftOffset, 4,
3936 XmNset, wword,
3937 NULL);
3938 XmStringFree(str);
3939
3940 str = XmStringCreateSimple(_("Match case"));
3941 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3942 xmToggleButtonGadgetClass, toggle_form,
3943 XmNlabelString, str,
3944 XmNleftAttachment, XmATTACH_FORM,
3945 XmNleftOffset, 4,
3946 XmNtopAttachment, XmATTACH_WIDGET,
3947 XmNtopWidget, frdp->wword,
3948 XmNtopOffset, 4,
3949 XmNset, mcase,
3950 NULL);
3951 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003952 gui_motif_menu_fontlist(frdp->wword);
3953 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954
3955 XtManageChild(toggle_form);
3956
3957 if (entry_text != NULL)
3958 XmTextFieldSetString(frdp->what, (char *)entry_text);
3959 vim_free(entry_text);
3960
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003961 gui_motif_synch_fonts();
3962
3963 manage_centered(frdp->dialog);
3964 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3966}
3967
3968 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003969gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970{
3971 if (!gui.in_use)
3972 return;
3973
3974 find_replace_dialog_create(eap->arg, FALSE);
3975}
3976
3977
3978 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003979gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980{
3981 if (!gui.in_use)
3982 return;
3983
3984 find_replace_dialog_create(eap->arg, TRUE);
3985}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003986
3987/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00003988 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003989 * main text font used. Those are in esp. the find/replace dialogs.
3990 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003991 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003992 */
3993 void
3994gui_motif_synch_fonts(void)
3995{
3996 SharedFindReplace *frdp;
3997 int do_replace;
3998 XFontStruct *font;
3999 XmFontList font_list;
4000
Bram Moolenaar734a8672019-12-02 22:49:38 +01004001 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4002 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004003 font = (XFontStruct *)gui.norm_font;
4004 if (font == NULL)
4005 return;
4006
4007 font_list = gui_motif_create_fontlist(font);
4008
Bram Moolenaar734a8672019-12-02 22:49:38 +01004009 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004010 for (do_replace = 0; do_replace <= 1; ++do_replace)
4011 {
4012 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4013 if (frdp->dialog)
4014 {
4015 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4016 if (do_replace)
4017 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4018 }
4019 }
4020
4021 XmFontListFree(font_list);
4022}