blob: 27c22d1b834c83a06572331fe66b04b5d03f5e02 [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/*
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100644 * Manage dialog centered on pointer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000646 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100647manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648{
649 Widget shell = XtParent(dialog_child);
650 Window root, child;
651 unsigned int mask;
652 unsigned int width, height, border_width, depth;
653 int x, y, win_x, win_y, maxX, maxY;
654 Boolean mappedWhenManaged;
655
Bram Moolenaar734a8672019-12-02 22:49:38 +0100656 // Temporarily set value of XmNmappedWhenManaged
657 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000658 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
659 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660
661 XtManageChild(dialog_child);
662
Bram Moolenaar734a8672019-12-02 22:49:38 +0100663 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
665 &x, &y, &win_x, &win_y, &mask);
666
Bram Moolenaar734a8672019-12-02 22:49:38 +0100667 // Translate the pointer position (x, y) into a position for the new
668 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
670 &width, &height, &border_width, &depth);
671 width += 2 * border_width;
672 height += 2 * border_width;
673 x -= width / 2;
674 y -= height / 2;
675
Bram Moolenaar734a8672019-12-02 22:49:38 +0100676 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 maxX = XtScreen(shell)->width - width;
678 maxY = XtScreen(shell)->height - height;
679 if (x < 0)
680 x = 0;
681 if (x > maxX)
682 x = maxX;
683 if (y < 0)
684 y = 0;
685 if (y > maxY)
686 y = maxY;
687
Bram Moolenaar734a8672019-12-02 22:49:38 +0100688 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
690
Bram Moolenaar734a8672019-12-02 22:49:38 +0100691 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 XtMapWidget(shell);
693
Bram Moolenaar734a8672019-12-02 22:49:38 +0100694 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000695 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696}
697
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100698#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699
700/*
701 * Encapsulate the way an XmFontList is created.
702 */
703 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100704gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705{
706 XmFontList font_list;
707
708# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100709 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 font_list = XmFontListCreate(font, STRING_TAG);
711# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100712 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 XmFontListEntry font_list_entry;
714
715 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
716 (XtPointer)font);
717 font_list = XmFontListAppendEntry(NULL, font_list_entry);
718 XmFontListEntryFree(&font_list_entry);
719# endif
720 return font_list;
721}
722
723# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
724 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100725gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726{
727 XmFontList font_list;
728
Bram Moolenaar734a8672019-12-02 22:49:38 +0100729 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 XmFontListEntry font_list_entry;
731
732 font_list_entry = XmFontListEntryCreate(STRING_TAG,
733 XmFONT_IS_FONTSET,
734 (XtPointer)*fontset);
735 font_list = XmFontListAppendEntry(NULL, font_list_entry);
736 XmFontListEntryFree(&font_list_entry);
737 return font_list;
738}
739# endif
740
741#endif
742
743#if defined(FEAT_MENU) || defined(PROTO)
744/*
745 * Menu stuff.
746 */
747
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100748static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100750static void toggle_tearoff(Widget wid);
751static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100753static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100755static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756static int menu_enabled = TRUE;
757
758 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100759gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760{
761 if (flag)
762 {
763 XtManageChild(menuBar);
764#ifdef FEAT_TOOLBAR
765 if (XtIsManaged(XtParent(toolBar)))
766 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100767 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 XtVaSetValues(XtParent(toolBar),
769 XmNtopAttachment, XmATTACH_WIDGET,
770 XmNtopWidget, menuBar,
771 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000772#ifdef FEAT_GUI_TABLINE
773 if (showing_tabline)
774 {
775 XtVaSetValues(tabLine,
776 XmNtopAttachment, XmATTACH_WIDGET,
777 XmNtopWidget, XtParent(toolBar),
778 NULL);
779 XtVaSetValues(textAreaForm,
780 XmNtopAttachment, XmATTACH_WIDGET,
781 XmNtopWidget, tabLine,
782 NULL);
783 }
784 else
785#endif
786 XtVaSetValues(textAreaForm,
787 XmNtopAttachment, XmATTACH_WIDGET,
788 XmNtopWidget, XtParent(toolBar),
789 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 }
791 else
792#endif
793 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000794#ifdef FEAT_GUI_TABLINE
795 if (showing_tabline)
796 {
797 XtVaSetValues(tabLine,
798 XmNtopAttachment, XmATTACH_WIDGET,
799 XmNtopWidget, menuBar,
800 NULL);
801 XtVaSetValues(textAreaForm,
802 XmNtopAttachment, XmATTACH_WIDGET,
803 XmNtopWidget, tabLine,
804 NULL);
805 }
806 else
807#endif
808 XtVaSetValues(textAreaForm,
809 XmNtopAttachment, XmATTACH_WIDGET,
810 XmNtopWidget, menuBar,
811 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 }
813 }
814 else
815 {
816 XtUnmanageChild(menuBar);
817#ifdef FEAT_TOOLBAR
818 if (XtIsManaged(XtParent(toolBar)))
819 {
820 XtVaSetValues(XtParent(toolBar),
821 XmNtopAttachment, XmATTACH_FORM,
822 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000823#ifdef FEAT_GUI_TABLINE
824 if (showing_tabline)
825 {
826 XtVaSetValues(tabLine,
827 XmNtopAttachment, XmATTACH_WIDGET,
828 XmNtopWidget, XtParent(toolBar),
829 NULL);
830 XtVaSetValues(textAreaForm,
831 XmNtopAttachment, XmATTACH_WIDGET,
832 XmNtopWidget, tabLine,
833 NULL);
834 }
835 else
836#endif
837 XtVaSetValues(textAreaForm,
838 XmNtopAttachment, XmATTACH_WIDGET,
839 XmNtopWidget, XtParent(toolBar),
840 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841 }
842 else
843#endif
844 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000845#ifdef FEAT_GUI_TABLINE
846 if (showing_tabline)
847 {
848 XtVaSetValues(tabLine,
849 XmNtopAttachment, XmATTACH_FORM,
850 NULL);
851 XtVaSetValues(textAreaForm,
852 XmNtopAttachment, XmATTACH_WIDGET,
853 XmNtopWidget, tabLine,
854 NULL);
855 }
856 else
857#endif
858 XtVaSetValues(textAreaForm,
859 XmNtopAttachment, XmATTACH_FORM,
860 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861 }
862 }
863
864}
865
866/*
867 * Enable or disable mnemonics for the toplevel menus.
868 */
869 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100870gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000871{
872 /*
873 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
874 * crashes when using a mnemonic then.
875 */
876 if (!menu_enabled)
877 enable = FALSE;
878 do_set_mnemonics(enable);
879}
880
881 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100882do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883{
884 vimmenu_T *menu;
885
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200886 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 if (menu->id != (Widget)0)
888 XtVaSetValues(menu->id,
889 XmNmnemonic, enable ? menu->mnemonic : NUL,
890 NULL);
891}
892
893 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100894gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895{
896 XmString label;
897 Widget shell;
898 vimmenu_T *parent = menu->parent;
899
900#ifdef MOTIF_POPUP
901 if (menu_is_popup(menu->name))
902 {
903 Arg arg[2];
904 int n = 0;
905
Bram Moolenaar734a8672019-12-02 22:49:38 +0100906 // Only create the popup menu when it's actually used, otherwise there
907 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908# if (XmVersion <= 1002)
909 if (mouse_model_popup())
910# endif
911 {
912 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200913 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200917 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
921 arg, n);
922 menu->id = (Widget)0;
923 }
924 return;
925 }
926#endif
927
928 if (!menu_is_menubar(menu->name)
929 || (parent != NULL && parent->submenu_id == (Widget)0))
930 return;
931
932 label = XmStringCreate((char *)menu->dname, STRING_TAG);
933 if (label == NULL)
934 return;
935 menu->id = XtVaCreateWidget("subMenu",
936 xmCascadeButtonWidgetClass,
937 (parent == NULL) ? menuBar : parent->submenu_id,
938 XmNlabelString, label,
939 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
940#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100941 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942 XmNpositionIndex, idx + (parent != NULL
943 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
944#endif
945 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 XmStringFree(label);
947
Bram Moolenaar734a8672019-12-02 22:49:38 +0100948 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 return;
950
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100951 // The "Help" menu is a special case, and should be placed at the far
952 // right hand side of the menu-bar. It's recognized by its high priority.
953 if (parent == NULL && menu->priority >= 9999)
954 XtVaSetValues(menuBar,
955 XmNmenuHelpWidget, menu->id,
956 NULL);
957
958 gui_motif_menu_colors(menu->id);
959 gui_motif_menu_fontlist(menu->id);
960
Bram Moolenaar734a8672019-12-02 22:49:38 +0100961 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 gui_motif_add_actext(menu);
963
964 shell = XtVaCreateWidget("subMenuShell",
965 xmMenuShellWidgetClass, menu->id,
966 XmNwidth, 1,
967 XmNheight, 1,
968 NULL);
969 gui_motif_menu_colors(shell);
970 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
971 xmRowColumnWidgetClass, shell,
972 XmNrowColumnType, XmMENU_PULLDOWN,
973 NULL);
974 gui_motif_menu_colors(menu->submenu_id);
975
Bram Moolenaar734a8672019-12-02 22:49:38 +0100976 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 return;
978
979#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100980 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000981 toggle_tearoff(menu->submenu_id);
982#endif
983
984 XtVaSetValues(menu->id,
985 XmNsubMenuId, menu->submenu_id,
986 NULL);
987
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100988 // When we add a top-level item to the menu bar, we can figure out how
989 // high the menu bar should be.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 if (parent == NULL)
991 gui_mch_compute_menu_height(menu->id);
992}
993
994
995/*
996 * Add mnemonic and accelerator text to a menu button.
997 */
998 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100999gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000{
1001 XmString label;
1002
Bram Moolenaar734a8672019-12-02 22:49:38 +01001003 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 if (menu->actext != NULL && menu->id != (Widget)0)
1005 {
1006 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1007 if (label == NULL)
1008 return;
1009 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1010 XmStringFree(label);
1011 }
1012}
1013
1014 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001015gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016{
1017#if (XmVersion >= 1002)
1018 if (enable)
1019 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1020 else
1021 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1022 toggle_tearoff(menuBar);
1023 gui_mch_recurse_tearoffs(root_menu);
1024#endif
1025}
1026
1027#if (XmVersion >= 1002)
1028/*
1029 * Set the tearoff for one menu widget on or off, and set the color of the
1030 * tearoff widget.
1031 */
1032 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001033toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034{
1035 Widget w;
1036
1037 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1038 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1039 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1040 gui_motif_menu_colors(w);
1041}
1042
1043 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001044gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045{
1046 while (menu != NULL)
1047 {
1048 if (!menu_is_popup(menu->name))
1049 {
1050 if (menu->submenu_id != (Widget)0)
1051 toggle_tearoff(menu->submenu_id);
1052 gui_mch_recurse_tearoffs(menu->children);
1053 }
1054 menu = menu->next;
1055 }
1056}
1057#endif
1058
1059 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001060gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061{
1062 Dimension shadowHeight;
1063
1064 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1065 return shadowHeight;
1066}
1067
1068/*
1069 * Compute the height of the menu bar.
1070 * We need to check all the items for their position and height, for the case
1071 * there are several rows, and/or some characters extend higher or lower.
1072 */
1073 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001074gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001075 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076{
1077 Dimension y, maxy;
1078 Dimension margin, shadow;
1079 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001080 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081
1082 /*
1083 * Get the height of the new item, before managing it, because it will
1084 * still reflect the font size. After managing it depends on the menu
1085 * height, which is what we just wanted to get!.
1086 */
1087 if (id != (Widget)0)
1088 XtVaGetValues(id, XmNheight, &height, NULL);
1089
Bram Moolenaar734a8672019-12-02 22:49:38 +01001090 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001092 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1094 {
1095 id = mp->id;
1096 break;
1097 }
1098
1099 /*
1100 * Now manage the menu item, to make them all be positioned (makes an
1101 * extra row when needed, removes it when not needed).
1102 */
1103 if (id != (Widget)0)
1104 XtManageChild(id);
1105
1106 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001107 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 */
1109 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001110 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {
1112 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1113 {
1114 XtVaGetValues(mp->id, XmNy, &y, NULL);
1115 if (y > maxy)
1116 maxy = y;
1117 }
1118 }
1119
1120 XtVaGetValues(menuBar,
1121 XmNmarginHeight, &margin,
1122 XmNshadowThickness, &shadow,
1123 NULL);
1124
1125 /*
1126 * This computation is the result of trial-and-error:
1127 * maxy = The maximum position of an item; required for when there are
1128 * two or more rows
1129 * height = height of an item, before managing it; Hopefully this will
1130 * change with the font height. Includes shadow-border.
1131 * shadow = shadow-border; must be subtracted from the height.
1132 * margin = margin around the menu buttons; Must be added.
1133 * Add 4 for the underlining of shortcut keys.
1134 */
1135 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1136
Bram Moolenaar734a8672019-12-02 22:49:38 +01001137 // Somehow the menu bar doesn't resize automatically. Set it here,
1138 // even though this is a catch 22. Don't do this when starting up,
1139 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 if (gui.shell_created)
1141 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001142}
1143
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001144#ifdef FEAT_TOOLBAR
1145
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001146/*
1147 * Icons used by the toolbar code.
1148 */
1149#include "gui_x11_pm.h"
1150
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001151static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001152
1153/*
1154 * Read an Xpm file. Return OK or FAIL.
1155 */
1156 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001157check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001158{
1159 XpmAttributes attrs;
1160 int status;
1161 Pixmap mask;
1162 Pixmap map;
1163
1164 attrs.valuemask = 0;
1165
Bram Moolenaar734a8672019-12-02 22:49:38 +01001166 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001167 status = XpmReadFileToPixmap(gui.dpy,
1168 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1169 (char *)path, &map, &mask, &attrs);
1170 XpmFreeAttributes(&attrs);
1171
1172 if (status == XpmSuccess)
1173 return OK;
1174 return FAIL;
1175}
1176
1177
1178/*
1179 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001180 * When it's to be read from a file, "fname" is set to the file name
1181 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001182 * Return a blank pixmap if it fails.
1183 */
1184 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001185get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001186{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001187 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1188 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001189 int res;
1190
Bram Moolenaar7c626922005-02-07 22:01:03 +00001191 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001192 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001193
1194 if (menu->iconfile != NULL)
1195 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001196 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001197 gui_find_iconfile(menu->iconfile, buf, "xpm");
1198 res = check_xpm(buf);
1199
Bram Moolenaar734a8672019-12-02 22:49:38 +01001200 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001201 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1202 res = check_xpm(buf);
1203 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001204 {
1205 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001206 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001207 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001208 }
1209
1210 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1211 {
1212 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001213 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001214 xpm = built_in_pixmaps[menu->iconidx];
1215 else
1216 xpm = tb_blank_xpm;
1217 }
1218
1219 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001221
1222/*
1223 * Add arguments for the toolbar pixmap to a menu item.
1224 */
1225 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001226add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001227{
1228 vim_free(menu->xpm_fname);
1229 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1230 if (menu->xpm == NULL)
1231 {
1232 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1233 }
1234 else
1235 {
1236 if (menu->xpm_fname != NULL)
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001237 {
Bram Moolenaar7c626922005-02-07 22:01:03 +00001238 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001239 }
Bram Moolenaar7c626922005-02-07 22:01:03 +00001240 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1241 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1242 }
1243 return n;
1244}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001245#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246
1247 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001248gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249{
1250 XmString label;
1251 vimmenu_T *parent = menu->parent;
1252
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001254 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1256 return;
1257# endif
1258
1259# ifdef FEAT_TOOLBAR
1260 if (menu_is_toolbar(parent->name))
1261 {
1262 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001263 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 int n;
1265 Arg args[18];
1266
1267 n = 0;
1268 if (menu_is_separator(menu->name))
1269 {
1270 char *cp;
1271 Dimension wid;
1272
1273 /*
1274 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1275 * a width specifier. If no width is specified then we choose one.
1276 */
1277 cp = (char *)vim_strchr(menu->name, ':');
1278 if (cp != NULL)
1279 wid = (Dimension)atoi(++cp);
1280 else
1281 wid = 4;
1282
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 type = xmSeparatorWidgetClass;
1284 XtSetArg(args[n], XmNwidth, wid); n++;
1285 XtSetArg(args[n], XmNminWidth, wid); n++;
1286 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001287 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 }
1289 else
1290 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001291 // Without shadows one can't sense whatever the button has been
1292 // pressed or not! However we want to save a bit of space...
1293 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001294 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1296 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1297 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001298 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001299 // Set the label here, so that we can switch between icons/text
1300 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001301 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1302 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001303
Bram Moolenaar7c626922005-02-07 22:01:03 +00001304 n = add_pixmap_args(menu, args, n);
1305
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001306 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307 }
1308
1309 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1310 if (menu->id == NULL)
1311 {
1312 menu->id = XtCreateManagedWidget((char *)menu->dname,
1313 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001314 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 {
1316 XtAddCallback(menu->id,
1317 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318# ifdef FEAT_FOOTER
1319 XtAddEventHandler(menu->id, EnterWindowMask, False,
1320 toolbarbutton_enter_cb, menu);
1321 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1322 toolbarbutton_leave_cb, menu);
1323# endif
1324 }
1325 }
1326 else
1327 XtSetValues(menu->id, args, n);
1328 if (xms != NULL)
1329 XmStringFree(xms);
1330
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001331# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001333# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334
1335 menu->parent = parent;
1336 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001337 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 if (!XtIsManaged(XtParent(toolBar))
1339 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1340 gui_mch_show_toolbar(TRUE);
1341 gui.toolbar_height = gui_mch_compute_toolbar_height();
1342 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001343 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344# endif
1345
Bram Moolenaar734a8672019-12-02 22:49:38 +01001346 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 if (parent->submenu_id == (Widget)0)
1348 return;
1349
1350 menu->submenu_id = (Widget)0;
1351
Bram Moolenaar734a8672019-12-02 22:49:38 +01001352 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 if (menu_is_separator(menu->name))
1354 {
1355 menu->id = XtVaCreateWidget("subMenu",
1356 xmSeparatorGadgetClass, parent->submenu_id,
1357#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001358 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1360 ? 1 : 0),
1361#endif
1362 NULL);
1363 gui_motif_menu_colors(menu->id);
1364 return;
1365 }
1366
1367 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1368 if (label == NULL)
1369 return;
1370 menu->id = XtVaCreateWidget("subMenu",
1371 xmPushButtonWidgetClass, parent->submenu_id,
1372 XmNlabelString, label,
1373 XmNmnemonic, menu->mnemonic,
1374#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001375 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1377 ? 1 : 0),
1378#endif
1379 NULL);
1380 gui_motif_menu_colors(menu->id);
1381 gui_motif_menu_fontlist(menu->id);
1382 XmStringFree(label);
1383
1384 if (menu->id != (Widget)0)
1385 {
1386 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1387 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001388 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 gui_motif_add_actext(menu);
1390 }
1391}
1392
1393#if (XmVersion <= 1002) || defined(PROTO)
1394/*
1395 * This function will destroy/create the popup menus dynamically,
1396 * according to the value of 'mousemodel'.
1397 * This will fix the "right mouse button freeze" that occurs when
1398 * there exists a popup menu but it isn't managed.
1399 */
1400 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001401gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402{
1403 int idx = 0;
1404
Bram Moolenaar734a8672019-12-02 22:49:38 +01001405 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 if (!gui.in_use)
1407 return;
1408
1409 while (menu)
1410 {
1411 if (menu->children != NULL)
1412 {
1413 if (menu_is_popup(menu->name))
1414 {
1415 if (mouse_model_popup())
1416 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001417 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 gui_mch_add_menu(menu, idx);
1419 gui_motif_update_mousemodel(menu->children);
1420 }
1421 else
1422 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001423 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 gui_motif_update_mousemodel(menu->children);
1425 gui_mch_destroy_menu(menu);
1426 }
1427 }
1428 }
1429 else if (menu_is_child_of_popup(menu))
1430 {
1431 if (mouse_model_popup())
1432 gui_mch_add_menu_item(menu, idx);
1433 else
1434 gui_mch_destroy_menu(menu);
1435 }
1436 menu = menu->next;
1437 ++idx;
1438 }
1439}
1440#endif
1441
1442 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001443gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444{
1445 if (menuBar == (Widget)0)
1446 return;
1447 gui_motif_menu_colors(menuBar);
1448#ifdef FEAT_TOOLBAR
1449 gui_motif_menu_colors(toolBarFrame);
1450 gui_motif_menu_colors(toolBar);
1451#endif
1452
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001453 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454}
1455
1456 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001457gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458{
1459 if (menuBar == (Widget)0)
1460 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001461 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {
1463 Dimension height;
1464 Position w, h;
1465
1466 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1467 gui.menu_height = height;
1468
1469 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1470 gui_resize_shell(w, h
1471#ifdef FEAT_XIM
1472 - xim_get_status_area_height()
1473#endif
1474 );
1475 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001476 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 ui_new_shellsize();
1478}
1479
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001480#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001482gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483{
1484# ifdef FEAT_TOOLBAR
1485 vimmenu_T *menu;
1486
1487 if (toolBar == (Widget)0)
1488 return;
1489
1490 menu = gui_find_menu((char_u *)"ToolBar");
1491 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001492 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493# endif
1494}
1495
1496 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001497gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498{
1499# ifdef FEAT_TOOLBAR
1500 vimmenu_T *toolbar;
1501
1502 if (toolBar == (Widget)0)
1503 return;
1504
1505 toolbar = gui_find_menu((char_u *)"ToolBar");
1506 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001507 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508# endif
1509}
1510#endif
1511
1512 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001513submenu_change(
1514 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001515 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516{
1517 vimmenu_T *mp;
1518
1519 for (mp = menu; mp != NULL; mp = mp->next)
1520 {
1521 if (mp->id != (Widget)0)
1522 {
1523 if (colors)
1524 {
1525 gui_motif_menu_colors(mp->id);
1526#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001527 // For a toolbar item: Free the pixmap and allocate a new one,
1528 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001529 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001531 int n = 0;
1532 Arg args[18];
1533
Bram Moolenaar7c626922005-02-07 22:01:03 +00001534 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001535 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001537# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001538 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 if (mp->tip != NULL)
1540 {
1541 Arg args[2];
1542
1543 args[0].name = XmNbackground;
1544 args[0].value = gui.tooltip_bg_pixel;
1545 args[1].name = XmNforeground;
1546 args[1].value = gui.tooltip_fg_pixel;
1547 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1548 }
1549# endif
1550#endif
1551 }
1552 else
1553 {
1554 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001555#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001556 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 if (mp->tip != NULL)
1558 {
1559 Arg args[1];
1560
1561 args[0].name = XmNfontList;
1562 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1563 &gui.tooltip_fontset);
1564 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1565 }
1566#endif
1567 }
1568 }
1569
1570 if (mp->children != NULL)
1571 {
1572#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001573 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 if (mp->submenu_id != (Widget)0)
1575 {
1576 if (colors)
1577 gui_motif_menu_colors(mp->submenu_id);
1578 else
1579 gui_motif_menu_fontlist(mp->submenu_id);
1580 toggle_tearoff(mp->submenu_id);
1581 }
1582#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001583 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001584 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 }
1586 }
1587}
1588
1589/*
1590 * Destroy the machine specific menu widget.
1591 */
1592 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001593gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001595 // Please be sure to destroy the parent widget first (i.e. menu->id).
1596 // On the other hand, problems have been reported that the submenu must be
1597 // deleted first...
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 if (menu->submenu_id != (Widget)0)
1599 {
1600 XtDestroyWidget(menu->submenu_id);
1601 menu->submenu_id = (Widget)0;
1602 }
1603
1604 if (menu->id != (Widget)0)
1605 {
1606 Widget parent;
1607
1608 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001609#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001610 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001612 // We try to destroy this before the actual menu, because there are
1613 // callbacks, etc. that will be unregistered during the tooltip
1614 // destruction.
1615 //
1616 // If you call "gui_mch_destroy_beval_area()" after destroying
1617 // menu->id, then the tooltip's window will have already been
1618 // deallocated by Xt, and unknown behaviour will ensue (probably
1619 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 gui_mch_destroy_beval_area(menu->tip);
1621 menu->tip = NULL;
1622 }
1623#endif
1624 XtDestroyWidget(menu->id);
1625 menu->id = (Widget)0;
1626 if (parent == menuBar)
1627 gui_mch_compute_menu_height((Widget)0);
1628#ifdef FEAT_TOOLBAR
1629 else if (parent == toolBar)
1630 {
1631 Cardinal num_children;
1632
Bram Moolenaar734a8672019-12-02 22:49:38 +01001633 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1635 if (num_children == 0)
1636 gui_mch_show_toolbar(FALSE);
1637 else
1638 gui.toolbar_height = gui_mch_compute_toolbar_height();
1639 }
1640#endif
1641 }
1642}
1643
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001645gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646{
1647#ifdef MOTIF_POPUP
1648 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1649 XtManageChild(menu->submenu_id);
1650#endif
1651}
1652
Bram Moolenaar734a8672019-12-02 22:49:38 +01001653#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654
1655/*
1656 * Set the menu and scrollbar colors to their default values.
1657 */
1658 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001659gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660{
1661 if (gui.in_use)
1662 {
Bram Moolenaare8504392022-03-13 14:45:03 +00001663 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
1664 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
1665 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
1666 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001667#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 gui.tooltip_fg_pixel =
1669 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1670 gui.tooltip_bg_pixel =
1671 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1672#endif
1673 }
1674}
1675
1676
1677/*
1678 * Scrollbar stuff.
1679 */
1680
1681 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001682gui_mch_set_scrollbar_thumb(
1683 scrollbar_T *sb,
1684 long val,
1685 long size,
1686 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687{
1688 if (sb->id != (Widget)0)
1689 XtVaSetValues(sb->id,
1690 XmNvalue, val,
1691 XmNsliderSize, size,
1692 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001693 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 NULL);
1695}
1696
1697 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001698gui_mch_set_scrollbar_pos(
1699 scrollbar_T *sb,
1700 int x,
1701 int y,
1702 int w,
1703 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704{
1705 if (sb->id != (Widget)0)
1706 {
1707 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1708 {
1709 if (y == 0)
1710 h -= gui.border_offset;
1711 else
1712 y -= gui.border_offset;
1713 XtVaSetValues(sb->id,
1714 XmNtopOffset, y,
1715 XmNbottomOffset, -y - h,
1716 XmNwidth, w,
1717 NULL);
1718 }
1719 else
1720 XtVaSetValues(sb->id,
1721 XmNtopOffset, y,
1722 XmNleftOffset, x,
1723 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1724 ? gui.scrollbar_width : 0,
1725 XmNheight, h,
1726 NULL);
1727 XtManageChild(sb->id);
1728 }
1729}
1730
Bram Moolenaar203ec772020-07-17 20:43:43 +02001731 int
1732gui_mch_get_scrollbar_xpadding(void)
1733{
qsmodo28f1a512022-02-07 15:57:50 +00001734 int xpad;
1735 Dimension tw, ww;
1736 Position tx;
1737
1738 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL);
1739 XtVaGetValues(vimShell, XtNwidth, &ww, NULL);
1740 xpad = ww - tw - tx - gui.scrollbar_width;
1741 return (xpad < 0) ? 0 : xpad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001742}
1743
1744 int
1745gui_mch_get_scrollbar_ypadding(void)
1746{
qsmodo28f1a512022-02-07 15:57:50 +00001747 int ypad;
1748 Dimension th, wh;
1749 Position ty;
1750
1751 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL);
1752 XtVaGetValues(vimShell, XtNheight, &wh, NULL);
1753 ypad = wh - th - ty - gui.scrollbar_height;
1754 return (ypad < 0) ? 0 : ypad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001755}
1756
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001758gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759{
1760 Arg args[16];
1761 int n;
1762
1763 if (sb->id != (Widget)0)
1764 {
1765 n = 0;
1766 if (flag)
1767 {
1768 switch (sb->type)
1769 {
1770 case SBAR_LEFT:
1771 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1772 break;
1773
1774 case SBAR_RIGHT:
1775 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1776 break;
1777
1778 case SBAR_BOTTOM:
1779 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1780 break;
1781 }
1782 XtSetValues(textArea, args, n);
1783 XtManageChild(sb->id);
1784 }
1785 else
1786 {
1787 if (!gui.which_scrollbars[sb->type])
1788 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001789 // The scrollbars of this type are all disabled, adjust the
1790 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 switch (sb->type)
1792 {
1793 case SBAR_LEFT:
1794 XtSetArg(args[n], XmNleftOffset, 0); n++;
1795 break;
1796
1797 case SBAR_RIGHT:
1798 XtSetArg(args[n], XmNrightOffset, 0); n++;
1799 break;
1800
1801 case SBAR_BOTTOM:
1802 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1803 break;
1804 }
1805 XtSetValues(textArea, args, n);
1806 }
1807 XtUnmanageChild(sb->id);
1808 }
1809 }
1810}
1811
1812 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001813gui_mch_create_scrollbar(
1814 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001815 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816{
1817 Arg args[16];
1818 int n;
1819
1820 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 XtSetArg(args[n], XmNminimum, 0); n++;
1822 XtSetArg(args[n], XmNorientation,
1823 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1824
1825 switch (sb->type)
1826 {
1827 case SBAR_LEFT:
1828 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1829 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1830 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1831 break;
1832
1833 case SBAR_RIGHT:
1834 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1835 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1836 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1837 break;
1838
1839 case SBAR_BOTTOM:
1840 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1841 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1842 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1843 break;
1844 }
1845
1846 sb->id = XtCreateWidget("scrollBar",
1847 xmScrollBarWidgetClass, textAreaForm, args, n);
1848
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 if (sb->id != (Widget)0)
1850 {
1851 gui_mch_set_scrollbar_colors(sb);
1852 XtAddCallback(sb->id, XmNvalueChangedCallback,
1853 scroll_cb, (XtPointer)sb->ident);
1854 XtAddCallback(sb->id, XmNdragCallback,
1855 scroll_cb, (XtPointer)sb->ident);
1856 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1857 (XtPointer)0);
1858 }
1859}
1860
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001862gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863{
1864 if (sb->id != (Widget)0)
1865 XtDestroyWidget(sb->id);
1866}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867
1868 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001869gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870{
1871 if (sb->id != (Widget)0)
1872 {
1873 if (gui.scroll_bg_pixel != INVALCOLOR)
1874 {
1875#if (XmVersion>=1002)
Bram Moolenaare8504392022-03-13 14:45:03 +00001876 // This should not only set the through color but also adjust
1877 // related colors, such as shadows.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 XmChangeColor(sb->id, gui.scroll_bg_pixel);
Bram Moolenaare8504392022-03-13 14:45:03 +00001879#endif
1880
1881 // Set the through color directly, in case XmChangeColor() decided
1882 // to change it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 XtVaSetValues(sb->id,
1884 XmNtroughColor, gui.scroll_bg_pixel,
1885 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 }
1887
1888 if (gui.scroll_fg_pixel != INVALCOLOR)
1889 XtVaSetValues(sb->id,
1890 XmNforeground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 XmNbackground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 NULL);
1893 }
1894
Bram Moolenaar734a8672019-12-02 22:49:38 +01001895 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1897 gui_motif_scroll_colors(textAreaForm);
1898}
1899
1900/*
1901 * Miscellaneous stuff:
1902 */
1903
1904 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001905gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906{
1907 return(XtWindow(textArea));
1908}
1909
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001910/*
1911 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1912 * When one is found, simulate a button press on that widget and give it the
1913 * keyboard focus. If the mnemonic is on a label, look in the userData field
1914 * of the label to see if it points to another widget, and give that the focus.
1915 */
1916 static void
1917do_mnemonic(Widget w, unsigned int keycode)
1918{
1919 WidgetList children;
1920 int numChildren, i;
1921 Boolean isMenu;
1922 KeySym mnemonic = '\0';
1923 char mneString[2];
1924 Widget userData;
1925 unsigned char rowColType;
1926
1927 if (XtIsComposite(w))
1928 {
1929 if (XtClass(w) == xmRowColumnWidgetClass)
1930 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001931 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001932 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1933 }
1934 else
1935 isMenu = False;
1936 if (!isMenu)
1937 {
1938 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001939 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001940 for (i = 0; i < numChildren; i++)
1941 do_mnemonic(children[i], keycode);
1942 }
1943 }
1944 else
1945 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001946 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001947 if (mnemonic != '\0')
1948 {
1949 mneString[0] = mnemonic;
1950 mneString[1] = '\0';
1951 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1952 XStringToKeysym(mneString)) == keycode)
1953 {
1954 if (XtClass(w) == xmLabelWidgetClass
1955 || XtClass(w) == xmLabelGadgetClass)
1956 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001957 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001958 if (userData != NULL && XtIsWidget(userData))
1959 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1960 }
1961 else
1962 {
1963 XKeyPressedEvent keyEvent;
1964
1965 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1966
Bram Moolenaara80faa82020-04-12 19:37:17 +02001967 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001968 keyEvent.type = KeyPress;
1969 keyEvent.serial = 1;
1970 keyEvent.send_event = True;
1971 keyEvent.display = XtDisplay(w);
1972 keyEvent.window = XtWindow(w);
1973 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1974 NULL, 0);
1975 }
1976 }
1977 }
1978 }
1979}
1980
1981/*
1982 * Callback routine for dialog mnemonic processing.
1983 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001984 static void
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02001985mnemonic_event(
1986 Widget w,
1987 XtPointer call_data UNUSED,
1988 XKeyEvent *event,
1989 Boolean *b UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001990{
1991 do_mnemonic(w, event->keycode);
1992}
1993
1994
1995/*
1996 * Search the widget tree under w for widgets with mnemonics. When found, add
1997 * a passive grab to the dialog widget for the mnemonic character, thus
1998 * directing mnemonic events to the dialog widget.
1999 */
2000 static void
2001add_mnemonic_grabs(Widget dialog, Widget w)
2002{
2003 char mneString[2];
2004 WidgetList children;
2005 int numChildren, i;
2006 Boolean isMenu;
2007 KeySym mnemonic = '\0';
2008 unsigned char rowColType;
2009
2010 if (XtIsComposite(w))
2011 {
2012 if (XtClass(w) == xmRowColumnWidgetClass)
2013 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002014 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002015 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2016 }
2017 else
2018 isMenu = False;
2019 if (!isMenu)
2020 {
2021 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002022 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002023 for (i = 0; i < numChildren; i++)
2024 add_mnemonic_grabs(dialog, children[i]);
2025 }
2026 }
2027 else
2028 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002029 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002030 if (mnemonic != '\0')
2031 {
2032 mneString[0] = mnemonic;
2033 mneString[1] = '\0';
2034 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2035 XStringToKeysym(mneString)),
2036 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2037 }
2038 }
2039}
2040
2041/*
2042 * Add a handler for mnemonics in a dialog. Motif itself only handles
2043 * mnemonics in menus. Mnemonics added or changed after this call will be
2044 * ignored.
2045 *
2046 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2047 * the appropriate label and set the XmNuserData resource of the label to the
2048 * widget to get the focus when the mnemonic is typed.
2049 */
2050 static void
2051activate_dialog_mnemonics(Widget dialog)
2052{
2053 if (!dialog)
2054 return;
2055
2056 XtAddEventHandler(dialog, KeyPressMask, False,
2057 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2058 add_mnemonic_grabs(dialog, dialog);
2059}
2060
2061/*
2062 * Removes the event handler and key-grabs for dialog mnemonic handling.
2063 */
2064 static void
2065suppress_dialog_mnemonics(Widget dialog)
2066{
2067 if (!dialog)
2068 return;
2069
2070 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2071 XtRemoveEventHandler(dialog, KeyPressMask, False,
2072 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2073}
2074
2075#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002076/*
2077 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2078 */
2079 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002080set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002081{
2082 XmFontList fl;
2083
2084#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002085 if (gui.fontset != NOFONTSET)
2086 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002087 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2088 if (fl != NULL)
2089 {
2090 if (XtIsManaged(id))
2091 {
2092 XtUnmanageChild(id);
2093 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002094 // We should force the widget to recalculate its
2095 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002096 XtManageChild(id);
2097 }
2098 else
2099 XtVaSetValues(id, XmNfontList, fl, NULL);
2100 XmFontListFree(fl);
2101 }
2102 }
2103#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002104 if (gui.norm_font != NOFONT)
2105 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002106 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2107 if (fl != NULL)
2108 {
2109 if (XtIsManaged(id))
2110 {
2111 XtUnmanageChild(id);
2112 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002113 // We should force the widget to recalculate its
2114 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002115 XtManageChild(id);
2116 }
2117 else
2118 XtVaSetValues(id, XmNfontList, fl, NULL);
2119 XmFontListFree(fl);
2120 }
2121 }
2122#endif
2123}
2124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125
2126#if defined(FEAT_BROWSE) || defined(PROTO)
2127
2128/*
2129 * file selector related stuff
2130 */
2131
2132#include <Xm/FileSB.h>
2133#include <Xm/XmStrDefs.h>
2134
2135typedef struct dialog_callback_arg
2136{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002137 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 int id;
2139} dcbarg_T;
2140
2141static Widget dialog_wgt;
2142static char *browse_fname = NULL;
2143static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002144 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002146static void DialogCancelCB(Widget, XtPointer, XtPointer);
2147static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148
2149/*
2150 * This function is used to translate the predefined label text of the
2151 * precomposed dialogs. We do this explicitly to allow:
2152 *
2153 * - usage of gettext for translation, as in all the other places.
2154 *
2155 * - equalize the messages between different GUI implementations as far as
2156 * possible.
2157 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002158 static void
2159set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002161 XmString str;
2162 Widget w;
2163 char_u *p, *next;
2164 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165
2166 w = XtNameToWidget(parent, name);
2167
2168 if (!w)
2169 return;
2170
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002171 p = vim_strsave((char_u *)new_label);
2172 if (p == NULL)
2173 return;
2174 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002176 if (*next == DLG_HOTKEY_CHAR)
2177 {
2178 int len = STRLEN(next);
2179
2180 if (len > 0)
2181 {
2182 mch_memmove(next, next + 1, len);
2183 mnemonic = next[0];
2184 }
2185 }
2186 }
2187
2188 str = XmStringCreate((char *)p, STRING_TAG);
2189 vim_free(p);
2190
2191 if (str != NULL)
2192 {
2193 XtVaSetValues(w,
2194 XmNlabelString, str,
2195 XmNmnemonic, mnemonic,
2196 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 XmStringFree(str);
2198 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002199 gui_motif_menu_fontlist(w);
2200}
2201
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002202 static void
2203set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002204{
2205 Widget w;
2206 w = XtNameToWidget(parent, name);
2207
2208 if (!w)
2209 return;
2210
2211 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212}
2213
2214/*
2215 * Put up a file requester.
2216 * Returns the selected name in allocated memory, or NULL for Cancel.
2217 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002219gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002220 int saving UNUSED, // select file to write
2221 char_u *title, // title for the window
2222 char_u *dflt, // default name
2223 char_u *ext UNUSED, // not used (extension added)
2224 char_u *initdir, // initial directory, NULL for current dir
2225 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226{
2227 char_u dirbuf[MAXPATHL];
2228 char_u dfltbuf[MAXPATHL];
2229 char_u *pattern;
2230 char_u *tofree = NULL;
2231
Bram Moolenaar734a8672019-12-02 22:49:38 +01002232 // There a difference between the resource name and value, Therefore, we
2233 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2234 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002235
2236 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237
2238 if (initdir == NULL || *initdir == NUL)
2239 {
2240 mch_dirname(dirbuf, MAXPATHL);
2241 initdir = dirbuf;
2242 }
2243
2244 if (dflt == NULL)
2245 dflt = (char_u *)"";
2246 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2247 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002248 // The default selection should be the full path, "dflt" is only the
2249 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 STRCPY(dfltbuf, initdir);
2251 add_pathsep(dfltbuf);
2252 STRCAT(dfltbuf, dflt);
2253 dflt = dfltbuf;
2254 }
2255
Bram Moolenaar734a8672019-12-02 22:49:38 +01002256 // Can only use one pattern for a file name. Get the first pattern out of
2257 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 if (filter == NULL)
2259 pattern = (char_u *)"";
2260 else
2261 {
2262 char_u *s, *p;
2263
2264 s = filter;
2265 for (p = filter; *p != NUL; ++p)
2266 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002267 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002269 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 break;
2271 }
2272 pattern = vim_strnsave(s, p - s);
2273 tofree = pattern;
2274 if (pattern == NULL)
2275 pattern = (char_u *)"";
2276 }
2277
2278 XtVaSetValues(dialog_wgt,
2279 XtVaTypedArg,
2280 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2281 XtVaTypedArg,
2282 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2283 XtVaTypedArg,
2284 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2285 XtVaTypedArg,
2286 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2287 NULL);
2288
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002289 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2290 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2292 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002293 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002295 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2297
Bram Moolenaar734a8672019-12-02 22:49:38 +01002298 // This is to save us from silly external settings using not fixed with
2299 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002300 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2301 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2302
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 gui_motif_menu_colors(dialog_wgt);
2304 if (gui.scroll_bg_pixel != INVALCOLOR)
2305 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2306
2307 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2308 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002309 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2311 (unsigned char)XmDIALOG_HELP_BUTTON));
2312
2313 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002314 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315
Bram Moolenaar734a8672019-12-02 22:49:38 +01002316 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 do
2318 {
2319 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2320 (XtInputMask)XtIMAll);
2321 } while (XtIsManaged(dialog_wgt));
2322
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002323 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 XtDestroyWidget(dialog_wgt);
2325 vim_free(tofree);
2326
2327 if (browse_fname == NULL)
2328 return NULL;
2329 return vim_strsave((char_u *)browse_fname);
2330}
2331
2332/*
2333 * The code below was originally taken from
2334 * /usr/examples/motif/xmsamplers/xmeditor.c
2335 * on Digital Unix 4.0d, but heavily modified.
2336 */
2337
2338/*
2339 * Process callback from Dialog cancel actions.
2340 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002342DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002343 Widget w UNUSED, // widget id
2344 XtPointer client_data UNUSED, // data from application
2345 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346{
2347 if (browse_fname != NULL)
2348 {
2349 XtFree(browse_fname);
2350 browse_fname = NULL;
2351 }
2352 XtUnmanageChild(dialog_wgt);
2353}
2354
2355/*
2356 * Process callback from Dialog actions.
2357 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002359DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002360 Widget w UNUSED, // widget id
2361 XtPointer client_data UNUSED, // data from application
2362 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363{
2364 XmFileSelectionBoxCallbackStruct *fcb;
2365
2366 if (browse_fname != NULL)
2367 {
2368 XtFree(browse_fname);
2369 browse_fname = NULL;
2370 }
2371 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2372
Bram Moolenaar734a8672019-12-02 22:49:38 +01002373 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2375
Bram Moolenaar734a8672019-12-02 22:49:38 +01002376 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 XtUnmanageChild(dialog_wgt);
2378}
2379
Bram Moolenaar734a8672019-12-02 22:49:38 +01002380#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381
2382#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2383
2384static int dialogStatus;
2385
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386/*
2387 * Callback function for the textfield. When CR is hit this works like
2388 * hitting the "OK" button, ESC like "Cancel".
2389 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002391keyhit_callback(
2392 Widget w,
2393 XtPointer client_data UNUSED,
2394 XEvent *event,
2395 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396{
2397 char buf[2];
2398 KeySym key_sym;
2399
2400 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2401 {
2402 if (*buf == CAR)
2403 dialogStatus = 1;
2404 else if (*buf == ESC)
2405 dialogStatus = 2;
2406 }
2407 if ((key_sym == XK_Left || key_sym == XK_Right)
2408 && !(event->xkey.state & ShiftMask))
2409 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2410}
2411
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002413butproc(
2414 Widget w UNUSED,
2415 XtPointer client_data,
2416 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417{
2418 dialogStatus = (int)(long)client_data + 1;
2419}
2420
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421#ifdef HAVE_XPM
2422
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002424create_pixmap_label(
2425 Widget parent,
2426 String name,
2427 char **data,
2428 ArgList args,
2429 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430{
2431 Widget label;
2432 Display *dsp;
2433 Screen *scr;
2434 int depth;
2435 Pixmap pixmap = 0;
2436 XpmAttributes attr;
2437 Boolean rs;
2438 XpmColorSymbol color[5] =
2439 {
2440 {"none", NULL, 0},
2441 {"iconColor1", NULL, 0},
2442 {"bottomShadowColor", NULL, 0},
2443 {"topShadowColor", NULL, 0},
2444 {"selectColor", NULL, 0}
2445 };
2446
2447 label = XmCreateLabelGadget(parent, name, args, arg);
2448
2449 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002450 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 * no way to get the background color directly from the widget itself.
2452 * In such cases we get it from The Core part of his parent instead.
2453 */
2454 dsp = XtDisplayOfObject(label);
2455 scr = XtScreenOfObject(label);
2456 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2457 ? label : XtParent(label),
2458 XmNdepth, &depth,
2459 XmNbackground, &color[0].pixel,
2460 XmNforeground, &color[1].pixel,
2461 XmNbottomShadowColor, &color[2].pixel,
2462 XmNtopShadowColor, &color[3].pixel,
2463 XmNhighlight, &color[4].pixel,
2464 NULL);
2465
2466 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2467 attr.colorsymbols = color;
2468 attr.numsymbols = 5;
2469 attr.closeness = 65535;
2470 attr.depth = depth;
2471 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2472 data, &pixmap, NULL, &attr);
2473
2474 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2475 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2476 XtVaSetValues(label,
2477 XmNlabelType, XmPIXMAP,
2478 XmNlabelPixmap, pixmap,
2479 NULL);
2480 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2481
2482 return label;
2483}
2484#endif
2485
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002487gui_mch_dialog(
2488 int type UNUSED,
2489 char_u *title,
2490 char_u *message,
2491 char_u *button_names,
2492 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002493 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002494 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495{
2496 char_u *buts;
2497 char_u *p, *next;
2498 XtAppContext app;
2499 XmString label;
2500 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002501 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 Widget dialogform = NULL;
2503 Widget form = NULL;
2504 Widget dialogtextfield = NULL;
2505 Widget *buttons;
2506 Widget sep_form = NULL;
2507 Boolean vertical;
2508 Widget separator = NULL;
2509 int n;
2510 Arg args[6];
2511#ifdef HAVE_XPM
2512 char **icon_data = NULL;
2513 Widget dialogpixmap = NULL;
2514#endif
2515
2516 if (title == NULL)
2517 title = (char_u *)_("Vim dialog");
2518
Bram Moolenaar734a8672019-12-02 22:49:38 +01002519 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 gui_mch_mousehide(FALSE);
2521
2522 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2523
Bram Moolenaar734a8672019-12-02 22:49:38 +01002524 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2526
Bram Moolenaar734a8672019-12-02 22:49:38 +01002527 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 label = XmStringCreateSimple((char *)title);
2529 if (label == NULL)
2530 return -1;
2531 XtVaSetValues(dialogform,
2532 XmNdialogTitle, label,
2533 XmNhorizontalSpacing, 4,
2534 XmNverticalSpacing, vertical ? 0 : 4,
2535 NULL);
2536 XmStringFree(label);
2537
Bram Moolenaar734a8672019-12-02 22:49:38 +01002538 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 buts = vim_strsave(button_names);
2540 if (buts == NULL)
2541 return -1;
2542
Bram Moolenaar734a8672019-12-02 22:49:38 +01002543 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 butcount = 1;
2545 for (p = buts; *p; ++p)
2546 if (*p == DLG_BUTTON_SEP)
2547 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002548 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 if (buttons == NULL)
2550 {
2551 vim_free(buts);
2552 return -1;
2553 }
2554
2555 /*
2556 * Create the buttons.
2557 */
2558 sep_form = (Widget) 0;
2559 p = buts;
2560 for (butcount = 0; *p; ++butcount)
2561 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002562 KeySym mnemonic = NUL;
2563
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 for (next = p; *next; ++next)
2565 {
2566 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002567 {
2568 int len = STRLEN(next);
2569
2570 if (len > 0)
2571 {
2572 mch_memmove(next, next + 1, len);
2573 mnemonic = next[0];
2574 }
2575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 if (*next == DLG_BUTTON_SEP)
2577 {
2578 *next++ = NUL;
2579 break;
2580 }
2581 }
2582 label = XmStringCreate(_((char *)p), STRING_TAG);
2583 if (label == NULL)
2584 break;
2585
2586 buttons[butcount] = XtVaCreateManagedWidget("button",
2587 xmPushButtonWidgetClass, dialogform,
2588 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002589 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 XmNbottomAttachment, XmATTACH_FORM,
2591 XmNbottomOffset, 4,
2592 XmNshowAsDefault, butcount == dfltbutton - 1,
2593 XmNdefaultButtonShadowThickness, 1,
2594 NULL);
2595 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002596 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597
Bram Moolenaar734a8672019-12-02 22:49:38 +01002598 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599
2600 if (butcount > 0)
2601 {
2602 if (vertical)
2603 XtVaSetValues(buttons[butcount],
2604 XmNtopWidget, buttons[butcount - 1],
2605 NULL);
2606 else
2607 {
2608 if (*next == NUL)
2609 {
2610 XtVaSetValues(buttons[butcount],
2611 XmNrightAttachment, XmATTACH_FORM,
2612 XmNrightOffset, 4,
2613 NULL);
2614
Bram Moolenaar734a8672019-12-02 22:49:38 +01002615 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 sep_form = XtVaCreateWidget("separatorForm",
2617 xmFormWidgetClass, dialogform,
2618 XmNleftAttachment, XmATTACH_WIDGET,
2619 XmNleftWidget, buttons[butcount - 1],
2620 XmNrightAttachment, XmATTACH_WIDGET,
2621 XmNrightWidget, buttons[butcount],
2622 XmNbottomAttachment, XmATTACH_FORM,
2623 XmNbottomOffset, 4,
2624 NULL);
2625 XtManageChild(sep_form);
2626 }
2627 else
2628 {
2629 XtVaSetValues(buttons[butcount],
2630 XmNleftAttachment, XmATTACH_WIDGET,
2631 XmNleftWidget, buttons[butcount - 1],
2632 NULL);
2633 }
2634 }
2635 }
2636 else if (!vertical)
2637 {
2638 if (*next == NUL)
2639 {
2640 XtVaSetValues(buttons[0],
2641 XmNrightAttachment, XmATTACH_FORM,
2642 XmNrightOffset, 4,
2643 NULL);
2644
Bram Moolenaar734a8672019-12-02 22:49:38 +01002645 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 sep_form = XtVaCreateWidget("separatorForm",
2647 xmFormWidgetClass, dialogform,
2648 XmNleftAttachment, XmATTACH_FORM,
2649 XmNleftOffset, 4,
2650 XmNrightAttachment, XmATTACH_WIDGET,
2651 XmNrightWidget, buttons[0],
2652 XmNbottomAttachment, XmATTACH_FORM,
2653 XmNbottomOffset, 4,
2654 NULL);
2655 XtManageChild(sep_form);
2656 }
2657 else
2658 XtVaSetValues(buttons[0],
2659 XmNleftAttachment, XmATTACH_FORM,
2660 XmNleftOffset, 4,
2661 NULL);
2662 }
2663
2664 XtAddCallback(buttons[butcount], XmNactivateCallback,
2665 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2666 p = next;
2667 }
2668 vim_free(buts);
2669
2670 separator = (Widget) 0;
2671 if (butcount > 0)
2672 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002673 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 n = 0;
2675 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2676 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2677 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2678 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2679 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2680 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2681 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2682 XtManageChild(separator);
2683 }
2684
2685 if (textfield != NULL)
2686 {
2687 dialogtextfield = XtVaCreateWidget("textField",
2688 xmTextFieldWidgetClass, dialogform,
2689 XmNleftAttachment, XmATTACH_FORM,
2690 XmNrightAttachment, XmATTACH_FORM,
2691 NULL);
2692 if (butcount > 0)
2693 XtVaSetValues(dialogtextfield,
2694 XmNbottomAttachment, XmATTACH_WIDGET,
2695 XmNbottomWidget, separator,
2696 NULL);
2697 else
2698 XtVaSetValues(dialogtextfield,
2699 XmNbottomAttachment, XmATTACH_FORM,
2700 NULL);
2701
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002702 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2704 XtManageChild(dialogtextfield);
2705 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2706 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2707 }
2708
Bram Moolenaar734a8672019-12-02 22:49:38 +01002709 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 form = XtVaCreateWidget("separatorForm",
2711 xmFormWidgetClass, dialogform,
2712 XmNleftAttachment, XmATTACH_FORM,
2713 XmNrightAttachment, XmATTACH_FORM,
2714 XmNtopAttachment, XmATTACH_FORM,
2715 NULL);
2716 XtManageChild(form);
2717
2718#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002719 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 switch (type)
2721 {
2722 case VIM_GENERIC:
2723 icon_data = generic_xpm;
2724 break;
2725 case VIM_ERROR:
2726 icon_data = error_xpm;
2727 break;
2728 case VIM_WARNING:
2729 icon_data = alert_xpm;
2730 break;
2731 case VIM_INFO:
2732 icon_data = info_xpm;
2733 break;
2734 case VIM_QUESTION:
2735 icon_data = quest_xpm;
2736 break;
2737 default:
2738 icon_data = generic_xpm;
2739 }
2740
2741 n = 0;
2742 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2743 XtSetArg(args[n], XmNtopOffset, 8); n++;
2744 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2745 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2746 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2747 XtSetArg(args[n], XmNleftOffset, 8); n++;
2748
2749 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2750 icon_data, args, n);
2751 XtManageChild(dialogpixmap);
2752#endif
2753
Bram Moolenaar734a8672019-12-02 22:49:38 +01002754 // Create the dialog message.
2755 // Since LessTif is apparently having problems with the creation of
2756 // properly localized string, we use LtoR here. The symptom is that the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002757 // string is not shown properly in multiple lines as it does in native
Bram Moolenaar734a8672019-12-02 22:49:38 +01002758 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002759 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 if (label == NULL)
2761 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002762 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 xmLabelGadgetClass, form,
2764 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002765 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 XmNtopAttachment, XmATTACH_FORM,
2767 XmNtopOffset, 8,
2768#ifdef HAVE_XPM
2769 XmNleftAttachment, XmATTACH_WIDGET,
2770 XmNleftWidget, dialogpixmap,
2771#else
2772 XmNleftAttachment, XmATTACH_FORM,
2773#endif
2774 XmNleftOffset, 8,
2775 XmNrightAttachment, XmATTACH_FORM,
2776 XmNrightOffset, 8,
2777 XmNbottomAttachment, XmATTACH_FORM,
2778 XmNbottomOffset, 8,
2779 NULL);
2780 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002781 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782
2783 if (textfield != NULL)
2784 {
2785 XtVaSetValues(form,
2786 XmNbottomAttachment, XmATTACH_WIDGET,
2787 XmNbottomWidget, dialogtextfield,
2788 NULL);
2789 }
2790 else
2791 {
2792 if (butcount > 0)
2793 XtVaSetValues(form,
2794 XmNbottomAttachment, XmATTACH_WIDGET,
2795 XmNbottomWidget, separator,
2796 NULL);
2797 else
2798 XtVaSetValues(form,
2799 XmNbottomAttachment, XmATTACH_FORM,
2800 NULL);
2801 }
2802
2803 if (dfltbutton < 1)
2804 dfltbutton = 1;
2805 if (dfltbutton > butcount)
2806 dfltbutton = butcount;
2807 XtVaSetValues(dialogform,
2808 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2809 if (textfield != NULL)
2810 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2811 else
2812 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2813 NULL);
2814
2815 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002816 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817
2818 if (textfield != NULL && *textfield != NUL)
2819 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002820 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 XmTextFieldSetSelection(dialogtextfield,
2822 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2823 XtLastTimestampProcessed(gui.dpy));
2824 XmTextFieldSetCursorPosition(dialogtextfield,
2825 (XmTextPosition)STRLEN(textfield));
2826 }
2827
2828 app = XtWidgetToApplicationContext(dialogform);
2829
Bram Moolenaar734a8672019-12-02 22:49:38 +01002830 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 dialogStatus = -1;
2832 for (;;)
2833 {
2834 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2835 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2836 break;
2837 }
2838
2839 vim_free(buttons);
2840
2841 if (textfield != NULL)
2842 {
2843 p = (char_u *)XmTextGetString(dialogtextfield);
2844 if (p == NULL || dialogStatus < 0)
2845 *textfield = NUL;
2846 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002847 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002848 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 }
2850
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002851 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 XtDestroyWidget(dialogform);
2853
2854 return dialogStatus;
2855}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002856#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857
2858#if defined(FEAT_FOOTER) || defined(PROTO)
2859
2860 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002861gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002863 Dimension height; // total Toolbar height
2864 Dimension top; // XmNmarginTop
2865 Dimension bottom; // XmNmarginBottom
2866 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867
2868 XtVaGetValues(footer,
2869 XmNheight, &height,
2870 XmNmarginTop, &top,
2871 XmNmarginBottom, &bottom,
2872 XmNshadowThickness, &shadow,
2873 NULL);
2874
2875 return (int) height + top + bottom + (shadow << 1);
2876}
2877
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002879gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880{
2881 if (showit)
2882 {
2883 gui.footer_height = gui_mch_compute_footer_height();
2884 XtManageChild(footer);
2885 }
2886 else
2887 {
2888 gui.footer_height = 0;
2889 XtUnmanageChild(footer);
2890 }
2891 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2892}
2893
2894 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002895gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896{
2897 XmString xms;
2898
2899 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002900 if (xms != NULL)
2901 {
2902 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2903 XmStringFree(xms);
2904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905}
2906
2907#endif
2908
2909
2910#if defined(FEAT_TOOLBAR) || defined(PROTO)
2911 void
2912gui_mch_show_toolbar(int showit)
2913{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002914 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915
2916 if (toolBar == (Widget)0)
2917 return;
2918 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2919 if (showit && numChildren > 0)
2920 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002921 // Assume that we want to show the toolbar if p_toolbar contains
2922 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 WidgetList children;
2924
2925 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2926 {
2927 void (*action)(BalloonEval *);
2928 int text = 0;
2929
2930 if (strstr((const char *)p_toolbar, "tooltips"))
2931 action = &gui_mch_enable_beval_area;
2932 else
2933 action = &gui_mch_disable_beval_area;
2934 if (strstr((const char *)p_toolbar, "text"))
2935 text = 1;
2936 else if (strstr((const char *)p_toolbar, "icons"))
2937 text = -1;
2938 if (text != 0)
2939 {
2940 vimmenu_T *toolbar;
2941 vimmenu_T *cur;
2942
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002943 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 if (menu_is_toolbar(toolbar->dname))
2945 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002946 // Assumption: toolbar is NULL if there is no toolbar,
2947 // otherwise it contains the toolbar menu structure.
2948 //
2949 // Assumption: "numChildren" == the number of items in the list
2950 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 if (toolbar)
2952 {
2953 for (cur = toolbar->children; cur; cur = cur->next)
2954 {
2955 Arg args[1];
2956 int n = 0;
2957
Bram Moolenaar734a8672019-12-02 22:49:38 +01002958 // Enable/Disable tooltip (OK to enable while
2959 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 if (cur->tip != NULL)
2961 (*action)(cur->tip);
2962 if (!menu_is_separator(cur->name))
2963 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002964 if (text == 1 || cur->xpm == NULL)
2965 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002967 ++n;
2968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 if (cur->id != NULL)
2970 {
2971 XtUnmanageChild(cur->id);
2972 XtSetValues(cur->id, args, n);
2973 XtManageChild(cur->id);
2974 }
2975 }
2976 }
2977 }
2978 }
2979 }
2980 gui.toolbar_height = gui_mch_compute_toolbar_height();
2981 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002982#ifdef FEAT_GUI_TABLINE
2983 if (showing_tabline)
2984 {
2985 XtVaSetValues(tabLine,
2986 XmNtopAttachment, XmATTACH_WIDGET,
2987 XmNtopWidget, XtParent(toolBar),
2988 NULL);
2989 XtVaSetValues(textAreaForm,
2990 XmNtopAttachment, XmATTACH_WIDGET,
2991 XmNtopWidget, tabLine,
2992 NULL);
2993 }
2994 else
2995#endif
2996 XtVaSetValues(textAreaForm,
2997 XmNtopAttachment, XmATTACH_WIDGET,
2998 XmNtopWidget, XtParent(toolBar),
2999 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 if (XtIsManaged(menuBar))
3001 XtVaSetValues(XtParent(toolBar),
3002 XmNtopAttachment, XmATTACH_WIDGET,
3003 XmNtopWidget, menuBar,
3004 NULL);
3005 else
3006 XtVaSetValues(XtParent(toolBar),
3007 XmNtopAttachment, XmATTACH_FORM,
3008 NULL);
3009 }
3010 else
3011 {
3012 gui.toolbar_height = 0;
3013 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003014 {
3015#ifdef FEAT_GUI_TABLINE
3016 if (showing_tabline)
3017 {
3018 XtVaSetValues(tabLine,
3019 XmNtopAttachment, XmATTACH_WIDGET,
3020 XmNtopWidget, menuBar,
3021 NULL);
3022 XtVaSetValues(textAreaForm,
3023 XmNtopAttachment, XmATTACH_WIDGET,
3024 XmNtopWidget, tabLine,
3025 NULL);
3026 }
3027 else
3028#endif
3029 XtVaSetValues(textAreaForm,
3030 XmNtopAttachment, XmATTACH_WIDGET,
3031 XmNtopWidget, menuBar,
3032 NULL);
3033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003035 {
3036#ifdef FEAT_GUI_TABLINE
3037 if (showing_tabline)
3038 {
3039 XtVaSetValues(tabLine,
3040 XmNtopAttachment, XmATTACH_FORM,
3041 NULL);
3042 XtVaSetValues(textAreaForm,
3043 XmNtopAttachment, XmATTACH_WIDGET,
3044 XmNtopWidget, tabLine,
3045 NULL);
3046 }
3047 else
3048#endif
3049 XtVaSetValues(textAreaForm,
3050 XmNtopAttachment, XmATTACH_FORM,
3051 NULL);
3052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053
3054 XtUnmanageChild(XtParent(toolBar));
3055 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003056 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057}
3058
3059/*
3060 * A toolbar button has been pushed; now reset the input focus
3061 * such that the user can type page up/down etc. and have the
3062 * input go to the editor window, not the button
3063 */
3064 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003065reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066{
3067 if (textArea != NULL)
3068 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3069}
3070
3071 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003072gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003074 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003075 Dimension height; // total Toolbar height
3076 Dimension whgt; // height of each widget
3077 WidgetList children; // list of toolBar's children
3078 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 int i;
3080
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003081 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003084 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003085 Dimension fst;
3086 Dimension fmh;
3087 Dimension tst;
3088 Dimension tmh;
3089
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003091 XmNshadowThickness, &fst,
3092 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003094 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003096 XmNshadowThickness, &tst,
3097 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 XmNchildren, &children,
3099 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003100 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003101 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {
3103 whgt = 0;
3104 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3105 if (height < whgt)
3106 height = whgt;
3107 }
3108 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003109#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003110 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003111 if (height < 10)
3112 height = 24;
3113#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003115 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116}
3117
Bram Moolenaar7c626922005-02-07 22:01:03 +00003118 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003119motif_get_toolbar_colors(
3120 Pixel *bgp,
3121 Pixel *fgp,
3122 Pixel *bsp,
3123 Pixel *tsp,
3124 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003125{
3126 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003127 XmNbackground, bgp,
3128 XmNforeground, fgp,
3129 XmNbottomShadowColor, bsp,
3130 XmNtopShadowColor, tsp,
3131 XmNhighlightColor, hsp,
3132 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003133}
3134
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135# ifdef FEAT_FOOTER
3136/*
3137 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003138 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 * get implemented and the user will have a choice.
3140 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003142toolbarbutton_enter_cb(
3143 Widget w UNUSED,
3144 XtPointer client_data,
3145 XEvent *event UNUSED,
3146 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147{
3148 vimmenu_T *menu = (vimmenu_T *) client_data;
3149
3150 if (menu->strings[MENU_INDEX_TIP] != NULL)
3151 {
3152 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3153 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3154 }
3155}
3156
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003158toolbarbutton_leave_cb(
3159 Widget w UNUSED,
3160 XtPointer client_data UNUSED,
3161 XEvent *event UNUSED,
3162 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163{
3164 gui_mch_set_footer((char_u *) "");
3165}
3166# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167#endif
3168
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003169#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3170/*
3171 * Show or hide the tabline.
3172 */
3173 void
3174gui_mch_show_tabline(int showit)
3175{
3176 if (tabLine == (Widget)0)
3177 return;
3178
3179 if (!showit != !showing_tabline)
3180 {
3181 if (showit)
3182 {
3183 XtManageChild(tabLine);
3184 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003185 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3186 XtUnmanageChild(XtNameToWidget(tabLine,
3187 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003188#ifdef FEAT_MENU
3189# ifdef FEAT_TOOLBAR
3190 if (XtIsManaged(XtParent(toolBar)))
3191 XtVaSetValues(tabLine,
3192 XmNtopAttachment, XmATTACH_WIDGET,
3193 XmNtopWidget, XtParent(toolBar), NULL);
3194 else
3195# endif
3196 if (XtIsManaged(menuBar))
3197 XtVaSetValues(tabLine,
3198 XmNtopAttachment, XmATTACH_WIDGET,
3199 XmNtopWidget, menuBar, NULL);
3200 else
3201#endif
3202 XtVaSetValues(tabLine,
3203 XmNtopAttachment, XmATTACH_FORM, NULL);
3204 XtVaSetValues(textAreaForm,
3205 XmNtopAttachment, XmATTACH_WIDGET,
3206 XmNtopWidget, tabLine,
3207 NULL);
3208 }
3209 else
3210 {
3211 XtUnmanageChild(tabLine);
3212#ifdef FEAT_MENU
3213# ifdef FEAT_TOOLBAR
3214 if (XtIsManaged(XtParent(toolBar)))
3215 XtVaSetValues(textAreaForm,
3216 XmNtopAttachment, XmATTACH_WIDGET,
3217 XmNtopWidget, XtParent(toolBar), NULL);
3218 else
3219# endif
3220 if (XtIsManaged(menuBar))
3221 XtVaSetValues(textAreaForm,
3222 XmNtopAttachment, XmATTACH_WIDGET,
3223 XmNtopWidget, menuBar, NULL);
3224 else
3225#endif
3226 XtVaSetValues(textAreaForm,
3227 XmNtopAttachment, XmATTACH_FORM, NULL);
3228 }
3229 showing_tabline = showit;
3230 }
3231}
3232
3233/*
3234 * Return TRUE when tabline is displayed.
3235 */
3236 int
3237gui_mch_showing_tabline(void)
3238{
3239 return tabLine != (Widget)0 && showing_tabline;
3240}
3241
3242/*
3243 * Update the labels of the tabline.
3244 */
3245 void
3246gui_mch_update_tabline(void)
3247{
3248 tabpage_T *tp;
3249 int nr = 1, n;
3250 Arg args[10];
3251 int curtabidx = 0, currentpage;
3252 Widget tab;
3253 XmNotebookPageInfo page_info;
3254 XmNotebookPageStatus page_status;
3255 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003256 XmString label_str;
3257 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003258 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003259
3260 if (tabLine == (Widget)0)
3261 return;
3262
Bram Moolenaar734a8672019-12-02 22:49:38 +01003263 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003264 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3265 {
3266 if (tp == curtab)
3267 curtabidx = nr;
3268
3269 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3270 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003271 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003272 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003273 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003274 n = 0;
3275 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3276 XtSetArg(args[n], XmNtraversalOn, False); n++;
3277 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3278 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3279 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3280 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3281 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003282 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3283 NULL);
3284 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003285 }
3286 else
3287 tab = page_info.major_tab_widget;
3288
3289 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003290
3291 /*
3292 * Change the label text only if it is different
3293 */
3294 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3295 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3296 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003297 get_tabline_label(tp, FALSE);
3298 if (STRCMP(label_cstr, NameBuff) != 0)
3299 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003300 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3301 NameBuff, STRLEN(NameBuff) + 1, NULL);
3302 /*
3303 * Force a resize of the tab label button
3304 */
3305 XtUnmanageChild(tab);
3306 XtManageChild(tab);
3307 }
3308 XtFree(label_cstr);
3309 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003310 }
3311
3312 tab_count = nr - 1;
3313
3314 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3315
Bram Moolenaar734a8672019-12-02 22:49:38 +01003316 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003317 while (nr <= last_page)
3318 {
3319 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3320 && page_info.page_number == nr
3321 && page_info.major_tab_widget != (Widget)0)
3322 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003323 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3324 if (beval != NULL)
3325 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003326 XtUnmanageChild(page_info.major_tab_widget);
3327 XtDestroyWidget(page_info.major_tab_widget);
3328 }
3329 nr++;
3330 }
3331
3332 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3333
3334 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3335 if (currentpage != curtabidx)
3336 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3337}
3338
3339/*
3340 * Set the current tab to "nr". First tab is 1.
3341 */
3342 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003343gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003344{
3345 int currentpage;
3346
3347 if (tabLine == (Widget)0)
3348 return;
3349
3350 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3351 if (currentpage != nr)
3352 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3353}
3354#endif
3355
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356/*
3357 * Set the colors of Widget "id" to the menu colors.
3358 */
3359 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003360gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361{
3362 if (gui.menu_bg_pixel != INVALCOLOR)
3363#if (XmVersion >= 1002)
3364 XmChangeColor(id, gui.menu_bg_pixel);
3365#else
3366 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3367#endif
3368 if (gui.menu_fg_pixel != INVALCOLOR)
3369 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3370}
3371
3372/*
3373 * Set the colors of Widget "id" to the scrollbar colors.
3374 */
3375 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003376gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377{
3378 if (gui.scroll_bg_pixel != INVALCOLOR)
3379#if (XmVersion >= 1002)
3380 XmChangeColor(id, gui.scroll_bg_pixel);
3381#else
3382 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3383#endif
3384 if (gui.scroll_fg_pixel != INVALCOLOR)
3385 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3386}
3387
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388/*
3389 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3390 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003391 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003392gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003394#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395#ifdef FONTSET_ALWAYS
3396 if (gui.menu_fontset != NOFONTSET)
3397 {
3398 XmFontList fl;
3399
3400 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3401 if (fl != NULL)
3402 {
3403 if (XtIsManaged(id))
3404 {
3405 XtUnmanageChild(id);
3406 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003407 // We should force the widget to recalculate its
3408 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 XtManageChild(id);
3410 }
3411 else
3412 XtVaSetValues(id, XmNfontList, fl, NULL);
3413 XmFontListFree(fl);
3414 }
3415 }
3416#else
3417 if (gui.menu_font != NOFONT)
3418 {
3419 XmFontList fl;
3420
3421 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3422 if (fl != NULL)
3423 {
3424 if (XtIsManaged(id))
3425 {
3426 XtUnmanageChild(id);
3427 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003428 // We should force the widget to recalculate its
3429 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 XtManageChild(id);
3431 }
3432 else
3433 XtVaSetValues(id, XmNfontList, fl, NULL);
3434 XmFontListFree(fl);
3435 }
3436 }
3437#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439}
3440
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441
3442/*
3443 * We don't create it twice for the sake of speed.
3444 */
3445
3446typedef struct _SharedFindReplace
3447{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003448 Widget dialog; // the main dialog widget
3449 Widget wword; // 'Exact match' check button
3450 Widget mcase; // 'match case' check button
3451 Widget up; // search direction 'Up' radio button
3452 Widget down; // search direction 'Down' radio button
3453 Widget what; // 'Find what' entry text widget
3454 Widget with; // 'Replace with' entry text widget
3455 Widget find; // 'Find Next' action button
3456 Widget replace; // 'Replace With' action button
3457 Widget all; // 'Replace All' action button
3458 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459
3460 Widget cancel;
3461} SharedFindReplace;
3462
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003463static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3464static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003467find_replace_destroy_callback(
3468 Widget w UNUSED,
3469 XtPointer client_data,
3470 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471{
3472 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3473
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003474 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003475 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 cd->dialog = (Widget)0;
3477}
3478
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003480find_replace_dismiss_callback(
3481 Widget w UNUSED,
3482 XtPointer client_data,
3483 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484{
3485 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3486
3487 if (cd != NULL)
3488 XtUnmanageChild(cd->dialog);
3489}
3490
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003492entry_activate_callback(
3493 Widget w UNUSED,
3494 XtPointer client_data,
3495 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496{
3497 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3498}
3499
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003501find_replace_callback(
3502 Widget w UNUSED,
3503 XtPointer client_data,
3504 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505{
3506 long_u flags = (long_u)client_data;
3507 char *find_text, *repl_text;
3508 Boolean direction_down = TRUE;
3509 Boolean wword;
3510 Boolean mcase;
3511 SharedFindReplace *sfr;
3512
3513 if (flags == FRD_UNDO)
3514 {
3515 char_u *save_cpo = p_cpo;
3516
Bram Moolenaar734a8672019-12-02 22:49:38 +01003517 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003518 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519 u_undo(1);
3520 p_cpo = save_cpo;
3521 gui_update_screen();
3522 return;
3523 }
3524
Bram Moolenaar734a8672019-12-02 22:49:38 +01003525 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 if (flags == FRD_FINDNEXT)
3527 {
3528 repl_text = NULL;
3529 sfr = &find_widgets;
3530 }
3531 else
3532 {
3533 repl_text = XmTextFieldGetString(repl_widgets.with);
3534 sfr = &repl_widgets;
3535 }
3536 find_text = XmTextFieldGetString(sfr->what);
3537 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3538 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3539 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3540 if (wword)
3541 flags |= FRD_WHOLE_WORD;
3542 if (mcase)
3543 flags |= FRD_MATCH_CASE;
3544
3545 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3546 direction_down);
3547
3548 if (find_text != NULL)
3549 XtFree(find_text);
3550 if (repl_text != NULL)
3551 XtFree(repl_text);
3552}
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003555find_replace_keypress(
3556 Widget w UNUSED,
3557 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003558 XKeyEvent *event,
3559 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003560{
3561 KeySym keysym;
3562
3563 if (frdp == NULL)
3564 return;
3565
3566 keysym = XLookupKeysym(event, 0);
3567
Bram Moolenaar734a8672019-12-02 22:49:38 +01003568 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 if (keysym == XK_Escape)
3570 XtUnmanageChild(frdp->dialog);
3571}
3572
3573 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003574set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003575{
3576 XmString str;
3577 char_u *p, *next;
3578 KeySym mnemonic = NUL;
3579
3580 if (!w)
3581 return;
3582
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003583 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003584 if (p == NULL)
3585 return;
3586 for (next = p; *next; ++next)
3587 {
3588 if (*next == DLG_HOTKEY_CHAR)
3589 {
3590 int len = STRLEN(next);
3591
3592 if (len > 0)
3593 {
3594 mch_memmove(next, next + 1, len);
3595 mnemonic = next[0];
3596 }
3597 }
3598 }
3599
3600 str = XmStringCreateSimple((char *)p);
3601 vim_free(p);
3602 if (str)
3603 {
3604 XtVaSetValues(w,
3605 XmNlabelString, str,
3606 XmNmnemonic, mnemonic,
3607 NULL);
3608 XmStringFree(str);
3609 }
3610 gui_motif_menu_fontlist(w);
3611}
3612
3613 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003614find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615{
3616 SharedFindReplace *frdp;
3617 Widget separator;
3618 Widget input_form;
3619 Widget button_form;
3620 Widget toggle_form;
3621 Widget frame;
3622 XmString str;
3623 int n;
3624 Arg args[6];
3625 int wword = FALSE;
3626 int mcase = !p_ic;
3627 Dimension width;
3628 Dimension widest;
3629 char_u *entry_text;
3630
3631 frdp = do_replace ? &repl_widgets : &find_widgets;
3632
Bram Moolenaar734a8672019-12-02 22:49:38 +01003633 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3635
Bram Moolenaar734a8672019-12-02 22:49:38 +01003636 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637 if (frdp->dialog)
3638 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003639 gui_motif_synch_fonts();
3640
Bram Moolenaar734a8672019-12-02 22:49:38 +01003641 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642 if (XtIsManaged(frdp->dialog))
3643 XMapRaised(XtDisplay(frdp->dialog),
3644 XtWindow(XtParent(frdp->dialog)));
3645 else
3646 XtManageChild(frdp->dialog);
3647 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3648 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3649
3650 if (entry_text != NULL)
3651 XmTextFieldSetString(frdp->what, (char *)entry_text);
3652 vim_free(entry_text);
3653
3654 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3655 return;
3656 }
3657
Bram Moolenaar734a8672019-12-02 22:49:38 +01003658 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659 if (do_replace)
3660 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3661 else
3662 str = XmStringCreateSimple(_("VIM - Search..."));
3663
3664 n = 0;
3665 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3666 XtSetArg(args[n], XmNnoResize, True); n++;
3667 XtSetArg(args[n], XmNdialogTitle, str); n++;
3668
3669 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3670 XmStringFree(str);
3671 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3672 find_replace_destroy_callback, frdp);
3673
3674 button_form = XtVaCreateWidget("buttonForm",
3675 xmFormWidgetClass, frdp->dialog,
3676 XmNrightAttachment, XmATTACH_FORM,
3677 XmNrightOffset, 4,
3678 XmNtopAttachment, XmATTACH_FORM,
3679 XmNtopOffset, 4,
3680 XmNbottomAttachment, XmATTACH_FORM,
3681 XmNbottomOffset, 4,
3682 NULL);
3683
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684 frdp->find = XtVaCreateManagedWidget("findButton",
3685 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 XmNsensitive, True,
3687 XmNtopAttachment, XmATTACH_FORM,
3688 XmNleftAttachment, XmATTACH_FORM,
3689 XmNrightAttachment, XmATTACH_FORM,
3690 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003691 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692
3693 XtAddCallback(frdp->find, XmNactivateCallback,
3694 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003695 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696
3697 if (do_replace)
3698 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003699 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3700 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701 XmNtopAttachment, XmATTACH_WIDGET,
3702 XmNtopWidget, frdp->find,
3703 XmNleftAttachment, XmATTACH_FORM,
3704 XmNrightAttachment, XmATTACH_FORM,
3705 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003706 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 XtAddCallback(frdp->replace, XmNactivateCallback,
3708 find_replace_callback, (XtPointer)FRD_REPLACE);
3709
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3711 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712 XmNtopAttachment, XmATTACH_WIDGET,
3713 XmNtopWidget, frdp->replace,
3714 XmNleftAttachment, XmATTACH_FORM,
3715 XmNrightAttachment, XmATTACH_FORM,
3716 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003717 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 XtAddCallback(frdp->all, XmNactivateCallback,
3719 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3720
Bram Moolenaar071d4272004-06-13 20:20:40 +00003721 frdp->undo = XtVaCreateManagedWidget("undoButton",
3722 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 XmNtopAttachment, XmATTACH_WIDGET,
3724 XmNtopWidget, frdp->all,
3725 XmNleftAttachment, XmATTACH_FORM,
3726 XmNrightAttachment, XmATTACH_FORM,
3727 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003728 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 XtAddCallback(frdp->undo, XmNactivateCallback,
3730 find_replace_callback, (XtPointer)FRD_UNDO);
3731 }
3732
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3734 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 XmNleftAttachment, XmATTACH_FORM,
3736 XmNrightAttachment, XmATTACH_FORM,
3737 XmNbottomAttachment, XmATTACH_FORM,
3738 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003739 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 XtAddCallback(frdp->cancel, XmNactivateCallback,
3741 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003742 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743
3744 XtManageChild(button_form);
3745
3746 n = 0;
3747 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3748 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3749 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3750 XtSetArg(args[n], XmNrightOffset, 4); n++;
3751 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3752 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3753 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3754 XtManageChild(separator);
3755
3756 input_form = XtVaCreateWidget("inputForm",
3757 xmFormWidgetClass, frdp->dialog,
3758 XmNleftAttachment, XmATTACH_FORM,
3759 XmNleftOffset, 4,
3760 XmNrightAttachment, XmATTACH_WIDGET,
3761 XmNrightWidget, separator,
3762 XmNrightOffset, 4,
3763 XmNtopAttachment, XmATTACH_FORM,
3764 XmNtopOffset, 4,
3765 NULL);
3766
3767 {
3768 Widget label_what;
3769 Widget label_with = (Widget)0;
3770
3771 str = XmStringCreateSimple(_("Find what:"));
3772 label_what = XtVaCreateManagedWidget("whatLabel",
3773 xmLabelGadgetClass, input_form,
3774 XmNlabelString, str,
3775 XmNleftAttachment, XmATTACH_FORM,
3776 XmNtopAttachment, XmATTACH_FORM,
3777 XmNtopOffset, 4,
3778 NULL);
3779 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003780 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781
3782 frdp->what = XtVaCreateManagedWidget("whatText",
3783 xmTextFieldWidgetClass, input_form,
3784 XmNtopAttachment, XmATTACH_FORM,
3785 XmNrightAttachment, XmATTACH_FORM,
3786 XmNleftAttachment, XmATTACH_FORM,
3787 NULL);
3788
3789 if (do_replace)
3790 {
3791 frdp->with = XtVaCreateManagedWidget("withText",
3792 xmTextFieldWidgetClass, input_form,
3793 XmNtopAttachment, XmATTACH_WIDGET,
3794 XmNtopWidget, frdp->what,
3795 XmNtopOffset, 4,
3796 XmNleftAttachment, XmATTACH_FORM,
3797 XmNrightAttachment, XmATTACH_FORM,
3798 XmNbottomAttachment, XmATTACH_FORM,
3799 NULL);
3800
3801 XtAddCallback(frdp->with, XmNactivateCallback,
3802 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3803
3804 str = XmStringCreateSimple(_("Replace with:"));
3805 label_with = XtVaCreateManagedWidget("withLabel",
3806 xmLabelGadgetClass, input_form,
3807 XmNlabelString, str,
3808 XmNleftAttachment, XmATTACH_FORM,
3809 XmNtopAttachment, XmATTACH_WIDGET,
3810 XmNtopWidget, frdp->what,
3811 XmNtopOffset, 4,
3812 XmNbottomAttachment, XmATTACH_FORM,
3813 NULL);
3814 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003815 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816
3817 /*
3818 * Make the entry activation only change the input focus onto the
3819 * with item.
3820 */
3821 XtAddCallback(frdp->what, XmNactivateCallback,
3822 entry_activate_callback, frdp->with);
3823 XtAddEventHandler(frdp->with, KeyPressMask, False,
3824 (XtEventHandler)find_replace_keypress,
3825 (XtPointer) frdp);
3826
3827 }
3828 else
3829 {
3830 /*
3831 * Make the entry activation do the search.
3832 */
3833 XtAddCallback(frdp->what, XmNactivateCallback,
3834 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3835 }
3836 XtAddEventHandler(frdp->what, KeyPressMask, False,
3837 (XtEventHandler)find_replace_keypress,
3838 (XtPointer)frdp);
3839
Bram Moolenaar734a8672019-12-02 22:49:38 +01003840 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 n = 0;
3842 XtSetArg(args[n], XmNwidth, &width); n++;
3843 XtGetValues(label_what, args, n);
3844 widest = width;
3845 if (do_replace)
3846 {
3847 XtGetValues(label_with, args, n);
3848 if (width > widest)
3849 widest = width;
3850 }
3851
3852 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3853 if (do_replace)
3854 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3855
3856 }
3857
3858 XtManageChild(input_form);
3859
3860 {
3861 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003862 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863
3864 frame = XtVaCreateWidget("directionFrame",
3865 xmFrameWidgetClass, frdp->dialog,
3866 XmNtopAttachment, XmATTACH_WIDGET,
3867 XmNtopWidget, input_form,
3868 XmNtopOffset, 4,
3869 XmNbottomAttachment, XmATTACH_FORM,
3870 XmNbottomOffset, 4,
3871 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3872 XmNrightWidget, input_form,
3873 NULL);
3874
3875 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003876 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 xmLabelGadgetClass, frame,
3878 XmNlabelString, str,
3879 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3880 XmNchildType, XmFRAME_TITLE_CHILD,
3881 NULL);
3882 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003883 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884
3885 radio_box = XmCreateRadioBox(frame, "radioBox",
3886 (ArgList)NULL, 0);
3887
3888 str = XmStringCreateSimple( _("Up"));
3889 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3890 xmToggleButtonGadgetClass, radio_box,
3891 XmNlabelString, str,
3892 XmNset, False,
3893 NULL);
3894 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003895 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896
3897 str = XmStringCreateSimple(_("Down"));
3898 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3899 xmToggleButtonGadgetClass, radio_box,
3900 XmNlabelString, str,
3901 XmNset, True,
3902 NULL);
3903 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003904 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905
3906 XtManageChild(radio_box);
3907 XtManageChild(frame);
3908 }
3909
3910 toggle_form = XtVaCreateWidget("toggleForm",
3911 xmFormWidgetClass, frdp->dialog,
3912 XmNleftAttachment, XmATTACH_FORM,
3913 XmNleftOffset, 4,
3914 XmNrightAttachment, XmATTACH_WIDGET,
3915 XmNrightWidget, frame,
3916 XmNrightOffset, 4,
3917 XmNtopAttachment, XmATTACH_WIDGET,
3918 XmNtopWidget, input_form,
3919 XmNtopOffset, 4,
3920 XmNbottomAttachment, XmATTACH_FORM,
3921 XmNbottomOffset, 4,
3922 NULL);
3923
3924 str = XmStringCreateSimple(_("Match whole word only"));
3925 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3926 xmToggleButtonGadgetClass, toggle_form,
3927 XmNlabelString, str,
3928 XmNtopAttachment, XmATTACH_FORM,
3929 XmNtopOffset, 4,
3930 XmNleftAttachment, XmATTACH_FORM,
3931 XmNleftOffset, 4,
3932 XmNset, wword,
3933 NULL);
3934 XmStringFree(str);
3935
3936 str = XmStringCreateSimple(_("Match case"));
3937 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3938 xmToggleButtonGadgetClass, toggle_form,
3939 XmNlabelString, str,
3940 XmNleftAttachment, XmATTACH_FORM,
3941 XmNleftOffset, 4,
3942 XmNtopAttachment, XmATTACH_WIDGET,
3943 XmNtopWidget, frdp->wword,
3944 XmNtopOffset, 4,
3945 XmNset, mcase,
3946 NULL);
3947 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003948 gui_motif_menu_fontlist(frdp->wword);
3949 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950
3951 XtManageChild(toggle_form);
3952
3953 if (entry_text != NULL)
3954 XmTextFieldSetString(frdp->what, (char *)entry_text);
3955 vim_free(entry_text);
3956
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003957 gui_motif_synch_fonts();
3958
3959 manage_centered(frdp->dialog);
3960 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3962}
3963
3964 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003965gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966{
3967 if (!gui.in_use)
3968 return;
3969
3970 find_replace_dialog_create(eap->arg, FALSE);
3971}
3972
3973
3974 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003975gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976{
3977 if (!gui.in_use)
3978 return;
3979
3980 find_replace_dialog_create(eap->arg, TRUE);
3981}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003982
3983/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00003984 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003985 * main text font used. Those are in esp. the find/replace dialogs.
3986 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003987 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003988 */
3989 void
3990gui_motif_synch_fonts(void)
3991{
3992 SharedFindReplace *frdp;
3993 int do_replace;
3994 XFontStruct *font;
3995 XmFontList font_list;
3996
Bram Moolenaar734a8672019-12-02 22:49:38 +01003997 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3998 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003999 font = (XFontStruct *)gui.norm_font;
4000 if (font == NULL)
4001 return;
4002
4003 font_list = gui_motif_create_fontlist(font);
4004
Bram Moolenaar734a8672019-12-02 22:49:38 +01004005 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004006 for (do_replace = 0; do_replace <= 1; ++do_replace)
4007 {
4008 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4009 if (frdp->dialog)
4010 {
4011 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4012 if (do_replace)
4013 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4014 }
4015 }
4016
4017 XmFontListFree(font_list);
4018}