blob: 94633b18780ba4611ac2aaabbcfb857b3419c356 [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_MENU
79# if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +010080// remember the last set value for the tearoff item
Bram Moolenaar071d4272004-06-13 20:20:40 +000081static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
82# endif
83static Widget menuBar;
84#endif
85
Bram Moolenaar071d4272004-06-13 20:20:40 +000086#ifdef FEAT_TOOLBAR
Bram Moolenaard25c16e2016-01-29 22:13:30 +010087static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaard25c16e2016-01-29 22:13:30 +010090static void gui_motif_menu_colors(Widget id);
91static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93#if (XmVersion >= 1002)
94# define STRING_TAG XmFONTLIST_DEFAULT_TAG
95#else
96# define STRING_TAG XmSTRING_DEFAULT_CHARSET
97#endif
98
99/*
100 * Call-back routines.
101 */
102
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103 static void
Bram Moolenaarc1ab6762016-01-30 19:45:49 +0100104scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105{
106 scrollbar_T *sb;
107 long value;
108 int dragging;
109
110 sb = gui_find_scrollbar((long)client_data);
111
112 value = ((XmScrollBarCallbackStruct *)call_data)->value;
113 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
114 (int)XmCR_DRAG);
115 gui_drag_scrollbar(sb, value, dragging);
116}
117
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000118#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000119 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100120tabline_cb(
121 Widget w UNUSED,
122 XtPointer client_data UNUSED,
123 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000124{
125 XmNotebookCallbackStruct *nptr;
126
127 nptr = (XmNotebookCallbackStruct *)call_data;
128 if (nptr->reason != (int)XmCR_NONE)
129 send_tabline_event(nptr->page_number);
130}
131
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000132 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100133tabline_button_cb(
134 Widget w,
135 XtPointer client_data UNUSED,
136 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000137{
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000138 XtPointer cmd, tab_idx;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000139
140 XtVaGetValues(w, XmNuserData, &cmd, NULL);
141 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
142
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000143 send_tabline_menu_event((int)(long)tab_idx, (int)(long)cmd);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000144}
145
146/*
147 * Tabline single mouse click timeout handler
148 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000149 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100150motif_tabline_timer_cb (
151 XtPointer timed_out,
152 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000153{
154 *((int *)timed_out) = TRUE;
155}
156
157/*
158 * check if the tabline tab scroller is clicked
159 */
160 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100161tabline_scroller_clicked(
162 char *scroller_name,
163 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000164{
165 Widget tab_scroll_w;
166 Position pos_x, pos_y;
167 Dimension width, height;
168
169 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
Bram Moolenaarebfec1c2023-01-22 21:14:53 +0000170 if (tab_scroll_w != (Widget)0)
171 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000172 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
173 &width, XmNheight, &height, NULL);
Bram Moolenaarebfec1c2023-01-22 21:14:53 +0000174 if (pos_x >= 0)
175 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100176 // Tab scroller (next) is visible
Bram Moolenaarebfec1c2023-01-22 21:14:53 +0000177 if (event->x >= pos_x && event->x <= pos_x + width
178 && event->y >= pos_y && event->y <= pos_y + height)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100179 // Clicked on the scroller
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000180 return TRUE;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000181 }
182 }
183 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000184}
185
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000186 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100187tabline_menu_cb(
188 Widget w,
189 XtPointer closure UNUSED,
190 XEvent *e,
191 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000192{
193 Widget tab_w;
194 XButtonPressedEvent *event;
195 int tab_idx = 0;
196 WidgetList children;
197 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000198 static XtIntervalId timer = (XtIntervalId)0;
199 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000200
201 event = (XButtonPressedEvent *)e;
202
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000203 if (event->button == Button1)
204 {
205 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
206 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
207 return;
208
209 if (!timed_out)
210 {
211 XtRemoveTimeOut(timer);
212 timed_out = TRUE;
213
214 /*
215 * Double click on the tabline gutter, add a new tab
216 */
217 send_tabline_menu_event(0, TABLINE_MENU_NEW);
218 }
219 else
220 {
221 /*
222 * Single click on the tabline gutter, start a timer to check
223 * for double clicks
224 */
225 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
226 motif_tabline_timer_cb, &timed_out);
227 timed_out = FALSE;
228 }
229 return;
230 }
231
Martin Tournoij7904fa42022-10-04 16:28:45 +0100232 if (event->button == Button2)
233 {
234 // Middle mouse click on tabpage label closes that tab.
235 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
236 send_tabline_menu_event(tab_idx, (int)TABLINE_MENU_CLOSE);
237 return;
238 }
239
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000240 if (event->button != Button3)
241 return;
242
Bram Moolenaar734a8672019-12-02 22:49:38 +0100243 // When ignoring events don't show the menu.
Martin Tournoij7904fa42022-10-04 16:28:45 +0100244 if (hold_gui_events || cmdwin_type != 0)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000245 return;
246
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000247 if (event->subwindow != None)
248 {
249 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaar734a8672019-12-02 22:49:38 +0100250 // LINTED: avoid warning: dubious operation on enum
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000251 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
252 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
253 }
254
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000255 XtVaSetValues(tabLine_menu, XmNuserData, (XtPointer)(long)tab_idx, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000256 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
257 &numChildren, NULL);
258 XtManageChildren(children, numChildren);
259 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
260 XtManageChild(tabLine_menu);
261}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000262
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000263 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100264tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000265{
266 int nr;
267 tabpage_T *tp;
268
269 if (beval->target == (Widget)0)
270 return;
271
272 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
273 tp = find_tabpage(nr);
274 if (tp == NULL)
275 return;
276
277 get_tabline_label(tp, TRUE);
278 gui_mch_post_balloon(beval, NameBuff);
279}
280
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000281#endif
282
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283/*
284 * End of call-back routines
285 */
286
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000287/*
288 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000289 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000290 */
291
292#include <Xm/XmP.h>
293#include <Xm/LabelP.h>
294
295static XtExposeProc old_label_expose = NULL;
296
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000297 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100298label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000299{
300 GC insensitiveGC;
301 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000302 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000303
304 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
305
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000306 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000307 (*old_label_expose)(_w, _event, _region);
308 else
309 {
310 XGCValues values;
311 XtGCMask mask;
312 XtGCMask dynamic;
313 XFontStruct *fs;
314
315 _XmFontListGetDefaultFont(lw->label.font, &fs);
316
Bram Moolenaar734a8672019-12-02 22:49:38 +0100317 // FIXME: we should be doing the whole drawing ourself here.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000318 insensitiveGC = lw->label.insensitive_GC;
319
320 mask = GCForeground | GCBackground | GCGraphicsExposures;
321 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
322 values.graphics_exposures = False;
323
324 if (fs != 0)
325 {
326 mask |= GCFont;
327 values.font = fs->fid;
328 }
329
330 if (lw->primitive.top_shadow_pixmap != None
331 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
332 {
333 mask |= GCFillStyle | GCTile;
334 values.fill_style = FillTiled;
335 values.tile = lw->primitive.top_shadow_pixmap;
336 }
337
338 lw->label.TextRect.x += 1;
339 lw->label.TextRect.y += 1;
340 if (lw->label._acc_text != 0)
341 {
342 lw->label.acc_TextRect.x += 1;
343 lw->label.acc_TextRect.y += 1;
344 }
345
346 values.foreground = lw->primitive.top_shadow_color;
347 values.background = lw->core.background_pixel;
348
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000349 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
350 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000351 (*old_label_expose)(_w, _event, _region);
352 XtReleaseGC(_w, lw->label.insensitive_GC);
353
354 lw->label.TextRect.x -= 1;
355 lw->label.TextRect.y -= 1;
356 if (lw->label._acc_text != 0)
357 {
358 lw->label.acc_TextRect.x -= 1;
359 lw->label.acc_TextRect.y -= 1;
360 }
361
362 values.foreground = lw->primitive.bottom_shadow_color;
363 values.background = lw->core.background_pixel;
364
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000365 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
366 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000367 (*old_label_expose)(_w, _event, _region);
368 XtReleaseGC(_w, lw->label.insensitive_GC);
369
370 lw->label.insensitive_GC = insensitiveGC;
371 }
372}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000373
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374/*
375 * Create all the motif widgets necessary.
376 */
377 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100378gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000380#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000381 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000382 Arg args[10];
383 int n;
384 XmString xms;
385#endif
386
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000387 /*
388 * Install the 3D shade effect drawing routines.
389 */
390 if (old_label_expose == NULL)
391 {
392 old_label_expose = xmLabelWidgetClass->core_class.expose;
393 xmLabelWidgetClass->core_class.expose = label_expose;
394 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000395
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396 /*
397 * Start out by adding the configured border width into the border offset
398 */
399 gui.border_offset = gui.border_width;
400
401 /*
402 * Install the tearOffModel resource converter.
403 */
404#if (XmVersion >= 1002)
405 XmRepTypeInstallTearOffModelConverter();
406#endif
407
Bram Moolenaar734a8672019-12-02 22:49:38 +0100408 // Make sure the "Quit" menu entry of the window manager is ignored
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
410
411 vimForm = XtVaCreateManagedWidget("vimForm",
412 xmFormWidgetClass, vimShell,
413 XmNborderWidth, 0,
414 XmNhighlightThickness, 0,
415 XmNshadowThickness, 0,
416 XmNmarginWidth, 0,
417 XmNmarginHeight, 0,
418 XmNresizePolicy, XmRESIZE_ANY,
419 NULL);
420 gui_motif_menu_colors(vimForm);
421
422#ifdef FEAT_MENU
423 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100424 Arg al[7]; // Make sure there is enough room for arguments!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425 int ac = 0;
426
427# if (XmVersion >= 1002)
428 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
429# endif
430 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
431 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
432 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
433# ifndef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100434 // Always stick to right hand side.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
436# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000437 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
439 XtManageChild(menuBar);
440
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441 gui_motif_menu_colors(menuBar);
442 }
443#endif
444
445#ifdef FEAT_TOOLBAR
446 /*
447 * Create an empty ToolBar. We should get buttons defined from menu.vim.
448 */
449 toolBarFrame = XtVaCreateWidget("toolBarFrame",
450 xmFrameWidgetClass, vimForm,
451 XmNshadowThickness, 0,
452 XmNmarginHeight, 0,
453 XmNmarginWidth, 0,
454 XmNleftAttachment, XmATTACH_FORM,
455 XmNrightAttachment, XmATTACH_FORM,
456 NULL);
457 gui_motif_menu_colors(toolBarFrame);
458
459 toolBar = XtVaCreateManagedWidget("toolBar",
460 xmRowColumnWidgetClass, toolBarFrame,
461 XmNchildType, XmFRAME_WORKAREA_CHILD,
462 XmNrowColumnType, XmWORK_AREA,
463 XmNorientation, XmHORIZONTAL,
464 XmNtraversalOn, False,
465 XmNisHomogeneous, False,
466 XmNpacking, XmPACK_TIGHT,
467 XmNspacing, 0,
468 XmNshadowThickness, 0,
469 XmNhighlightThickness, 0,
470 XmNmarginHeight, 0,
471 XmNmarginWidth, 0,
472 XmNadjustLast, True,
473 NULL);
474 gui_motif_menu_colors(toolBar);
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476#endif
477
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000478#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100479 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000480 n = 0;
481 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
482 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
483 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
484 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
485 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
486 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
487 XtSetArg(args[n], XmNshadowThickness, 0); n++;
488 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
489 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
490 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
491
492 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
493 NULL);
494 XtAddEventHandler(tabLine, ButtonPressMask, False,
495 (XtEventHandler)tabline_menu_cb, NULL);
496
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000497 gui.tabline_height = TABLINE_HEIGHT;
498
Bram Moolenaar18144c82006-04-12 21:52:12 +0000499 /*
500 * Set the size of the minor next/prev scrollers to zero, so
501 * that they are not displayed. Due to a bug in OpenMotif 2.3,
502 * even if these children widget are unmanaged, they are again
503 * managed by the Notebook widget and the notebook widget geometry
504 * is adjusted to account for the minor scroller widgets.
505 */
506 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
507 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
508 XmNtraversalOn, False, NULL);
509 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
510 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
511 XmNtraversalOn, False, NULL);
512
Bram Moolenaar29547192018-12-11 20:39:19 +0100513 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000514 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
515
Bram Moolenaar29547192018-12-11 20:39:19 +0100516 // Add the buttons to the tabline popup menu
517 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000518 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_CLOSE); n++;
Bram Moolenaar29547192018-12-11 20:39:19 +0100519 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
520 XtSetArg(args[n], XmNlabelString, xms); n++;
521 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
522 XtAddCallback(button, XmNactivateCallback,
523 (XtCallbackProc)tabline_button_cb, NULL);
524 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000525
526 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000527 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_NEW); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000528 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
529 XtSetArg(args[n], XmNlabelString, xms); n++;
530 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
531 XtAddCallback(button, XmNactivateCallback,
532 (XtCallbackProc)tabline_button_cb, NULL);
533 XmStringFree(xms);
534
535 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000536 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_OPEN); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000537 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
538 XtSetArg(args[n], XmNlabelString, xms); n++;
539 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
540 XtAddCallback(button, XmNactivateCallback,
541 (XtCallbackProc)tabline_button_cb, NULL);
542 XmStringFree(xms);
543#endif
544
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
546 xmFormWidgetClass, vimForm,
547 XmNleftAttachment, XmATTACH_FORM,
548 XmNrightAttachment, XmATTACH_FORM,
549 XmNbottomAttachment, XmATTACH_FORM,
550 XmNtopAttachment, XmATTACH_FORM,
551 XmNmarginWidth, 0,
552 XmNmarginHeight, 0,
553 XmNresizePolicy, XmRESIZE_ANY,
554 NULL);
555 gui_motif_scroll_colors(textAreaForm);
556
557 textArea = XtVaCreateManagedWidget("textArea",
558 xmDrawingAreaWidgetClass, textAreaForm,
559 XmNforeground, gui.norm_pixel,
560 XmNbackground, gui.back_pixel,
561 XmNleftAttachment, XmATTACH_FORM,
562 XmNtopAttachment, XmATTACH_FORM,
563 XmNrightAttachment, XmATTACH_FORM,
564 XmNbottomAttachment, XmATTACH_FORM,
565
566 /*
567 * These take some control away from the user, but avoids making them
568 * add resources to get a decent looking setup.
569 */
570 XmNborderWidth, 0,
571 XmNhighlightThickness, 0,
572 XmNshadowThickness, 0,
573 NULL);
574
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 /*
576 * Install the callbacks.
577 */
578 gui_x11_callbacks(textArea, vimForm);
579
Bram Moolenaar734a8672019-12-02 22:49:38 +0100580 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 gui.in_focus = FALSE;
582}
583
584/*
585 * Called when the GUI is not going to start after all.
586 */
587 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100588gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589{
590 textArea = NULL;
591#ifdef FEAT_MENU
592 menuBar = NULL;
593#endif
594}
595
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100597gui_mch_set_text_area_pos(
598 int x UNUSED,
599 int y UNUSED,
600 int w UNUSED,
601 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602{
603#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100604 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000605 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#endif
607}
608
609 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100610gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611{
612 if (textArea != NULL)
613#if (XmVersion >= 1002)
614 XmChangeColor(textArea, gui.back_pixel);
615#else
616 XtVaSetValues(textArea,
617 XmNbackground, gui.back_pixel,
618 NULL);
619#endif
620}
621
622/*
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100623 * Manage dialog centered on pointer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000625 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100626manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627{
628 Widget shell = XtParent(dialog_child);
629 Window root, child;
630 unsigned int mask;
631 unsigned int width, height, border_width, depth;
632 int x, y, win_x, win_y, maxX, maxY;
633 Boolean mappedWhenManaged;
634
Bram Moolenaar734a8672019-12-02 22:49:38 +0100635 // Temporarily set value of XmNmappedWhenManaged
636 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000637 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
638 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639
640 XtManageChild(dialog_child);
641
Bram Moolenaar734a8672019-12-02 22:49:38 +0100642 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
644 &x, &y, &win_x, &win_y, &mask);
645
Bram Moolenaar734a8672019-12-02 22:49:38 +0100646 // Translate the pointer position (x, y) into a position for the new
647 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
649 &width, &height, &border_width, &depth);
650 width += 2 * border_width;
651 height += 2 * border_width;
652 x -= width / 2;
653 y -= height / 2;
654
Bram Moolenaar734a8672019-12-02 22:49:38 +0100655 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 maxX = XtScreen(shell)->width - width;
657 maxY = XtScreen(shell)->height - height;
658 if (x < 0)
659 x = 0;
660 if (x > maxX)
661 x = maxX;
662 if (y < 0)
663 y = 0;
664 if (y > maxY)
665 y = maxY;
666
Bram Moolenaar734a8672019-12-02 22:49:38 +0100667 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
669
Bram Moolenaar734a8672019-12-02 22:49:38 +0100670 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 XtMapWidget(shell);
672
Bram Moolenaar734a8672019-12-02 22:49:38 +0100673 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000674 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675}
676
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100677#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678
679/*
680 * Encapsulate the way an XmFontList is created.
681 */
682 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100683gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684{
685 XmFontList font_list;
686
687# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100688 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 font_list = XmFontListCreate(font, STRING_TAG);
690# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100691 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 XmFontListEntry font_list_entry;
693
694 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
695 (XtPointer)font);
696 font_list = XmFontListAppendEntry(NULL, font_list_entry);
697 XmFontListEntryFree(&font_list_entry);
698# endif
699 return font_list;
700}
701
702# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
703 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100704gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705{
706 XmFontList font_list;
707
Bram Moolenaar734a8672019-12-02 22:49:38 +0100708 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 XmFontListEntry font_list_entry;
710
711 font_list_entry = XmFontListEntryCreate(STRING_TAG,
712 XmFONT_IS_FONTSET,
713 (XtPointer)*fontset);
714 font_list = XmFontListAppendEntry(NULL, font_list_entry);
715 XmFontListEntryFree(&font_list_entry);
716 return font_list;
717}
718# endif
719
720#endif
721
722#if defined(FEAT_MENU) || defined(PROTO)
723/*
724 * Menu stuff.
725 */
726
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100727static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100729static void toggle_tearoff(Widget wid);
730static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100732static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100734static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735static int menu_enabled = TRUE;
736
737 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100738gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739{
740 if (flag)
741 {
742 XtManageChild(menuBar);
743#ifdef FEAT_TOOLBAR
744 if (XtIsManaged(XtParent(toolBar)))
745 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100746 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 XtVaSetValues(XtParent(toolBar),
748 XmNtopAttachment, XmATTACH_WIDGET,
749 XmNtopWidget, menuBar,
750 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000751#ifdef FEAT_GUI_TABLINE
752 if (showing_tabline)
753 {
754 XtVaSetValues(tabLine,
755 XmNtopAttachment, XmATTACH_WIDGET,
756 XmNtopWidget, XtParent(toolBar),
757 NULL);
758 XtVaSetValues(textAreaForm,
759 XmNtopAttachment, XmATTACH_WIDGET,
760 XmNtopWidget, tabLine,
761 NULL);
762 }
763 else
764#endif
765 XtVaSetValues(textAreaForm,
766 XmNtopAttachment, XmATTACH_WIDGET,
767 XmNtopWidget, XtParent(toolBar),
768 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 }
770 else
771#endif
772 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000773#ifdef FEAT_GUI_TABLINE
774 if (showing_tabline)
775 {
776 XtVaSetValues(tabLine,
777 XmNtopAttachment, XmATTACH_WIDGET,
778 XmNtopWidget, menuBar,
779 NULL);
780 XtVaSetValues(textAreaForm,
781 XmNtopAttachment, XmATTACH_WIDGET,
782 XmNtopWidget, tabLine,
783 NULL);
784 }
785 else
786#endif
787 XtVaSetValues(textAreaForm,
788 XmNtopAttachment, XmATTACH_WIDGET,
789 XmNtopWidget, menuBar,
790 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 }
792 }
793 else
794 {
795 XtUnmanageChild(menuBar);
796#ifdef FEAT_TOOLBAR
797 if (XtIsManaged(XtParent(toolBar)))
798 {
799 XtVaSetValues(XtParent(toolBar),
800 XmNtopAttachment, XmATTACH_FORM,
801 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000802#ifdef FEAT_GUI_TABLINE
803 if (showing_tabline)
804 {
805 XtVaSetValues(tabLine,
806 XmNtopAttachment, XmATTACH_WIDGET,
807 XmNtopWidget, XtParent(toolBar),
808 NULL);
809 XtVaSetValues(textAreaForm,
810 XmNtopAttachment, XmATTACH_WIDGET,
811 XmNtopWidget, tabLine,
812 NULL);
813 }
814 else
815#endif
816 XtVaSetValues(textAreaForm,
817 XmNtopAttachment, XmATTACH_WIDGET,
818 XmNtopWidget, XtParent(toolBar),
819 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820 }
821 else
822#endif
823 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000824#ifdef FEAT_GUI_TABLINE
825 if (showing_tabline)
826 {
827 XtVaSetValues(tabLine,
828 XmNtopAttachment, XmATTACH_FORM,
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_FORM,
839 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840 }
841 }
842
843}
844
845/*
846 * Enable or disable mnemonics for the toplevel menus.
847 */
848 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100849gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000850{
851 /*
852 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
853 * crashes when using a mnemonic then.
854 */
855 if (!menu_enabled)
856 enable = FALSE;
857 do_set_mnemonics(enable);
858}
859
860 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100861do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862{
863 vimmenu_T *menu;
864
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200865 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000866 if (menu->id != (Widget)0)
867 XtVaSetValues(menu->id,
868 XmNmnemonic, enable ? menu->mnemonic : NUL,
869 NULL);
870}
871
872 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100873gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000874{
875 XmString label;
876 Widget shell;
877 vimmenu_T *parent = menu->parent;
878
879#ifdef MOTIF_POPUP
880 if (menu_is_popup(menu->name))
881 {
882 Arg arg[2];
883 int n = 0;
884
Bram Moolenaar734a8672019-12-02 22:49:38 +0100885 // Only create the popup menu when it's actually used, otherwise there
886 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887# if (XmVersion <= 1002)
888 if (mouse_model_popup())
889# endif
890 {
891 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200892 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200896 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200898 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
900 arg, n);
901 menu->id = (Widget)0;
902 }
903 return;
904 }
905#endif
906
907 if (!menu_is_menubar(menu->name)
908 || (parent != NULL && parent->submenu_id == (Widget)0))
909 return;
910
911 label = XmStringCreate((char *)menu->dname, STRING_TAG);
912 if (label == NULL)
913 return;
914 menu->id = XtVaCreateWidget("subMenu",
915 xmCascadeButtonWidgetClass,
916 (parent == NULL) ? menuBar : parent->submenu_id,
917 XmNlabelString, label,
918 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
919#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100920 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 XmNpositionIndex, idx + (parent != NULL
922 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
923#endif
924 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 XmStringFree(label);
926
Bram Moolenaar734a8672019-12-02 22:49:38 +0100927 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 return;
929
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100930 // The "Help" menu is a special case, and should be placed at the far
931 // right hand side of the menu-bar. It's recognized by its high priority.
932 if (parent == NULL && menu->priority >= 9999)
933 XtVaSetValues(menuBar,
934 XmNmenuHelpWidget, menu->id,
935 NULL);
936
937 gui_motif_menu_colors(menu->id);
938 gui_motif_menu_fontlist(menu->id);
939
Bram Moolenaar734a8672019-12-02 22:49:38 +0100940 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941 gui_motif_add_actext(menu);
942
943 shell = XtVaCreateWidget("subMenuShell",
944 xmMenuShellWidgetClass, menu->id,
945 XmNwidth, 1,
946 XmNheight, 1,
947 NULL);
948 gui_motif_menu_colors(shell);
949 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
950 xmRowColumnWidgetClass, shell,
951 XmNrowColumnType, XmMENU_PULLDOWN,
952 NULL);
953 gui_motif_menu_colors(menu->submenu_id);
954
Bram Moolenaar734a8672019-12-02 22:49:38 +0100955 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 return;
957
958#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100959 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 toggle_tearoff(menu->submenu_id);
961#endif
962
963 XtVaSetValues(menu->id,
964 XmNsubMenuId, menu->submenu_id,
965 NULL);
966
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100967 // When we add a top-level item to the menu bar, we can figure out how
968 // high the menu bar should be.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 if (parent == NULL)
970 gui_mch_compute_menu_height(menu->id);
971}
972
973
974/*
975 * Add mnemonic and accelerator text to a menu button.
976 */
977 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100978gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979{
980 XmString label;
981
Bram Moolenaar734a8672019-12-02 22:49:38 +0100982 // Add accelerator text, if there is one
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +0000983 if (menu->actext == NULL || menu->id == (Widget)0)
984 return;
985
986 label = XmStringCreate((char *)menu->actext, STRING_TAG);
987 if (label == NULL)
988 return;
989 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
990 XmStringFree(label);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991}
992
993 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100994gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995{
996#if (XmVersion >= 1002)
997 if (enable)
998 tearoff_val = (int)XmTEAR_OFF_ENABLED;
999 else
1000 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1001 toggle_tearoff(menuBar);
1002 gui_mch_recurse_tearoffs(root_menu);
1003#endif
1004}
1005
1006#if (XmVersion >= 1002)
1007/*
1008 * Set the tearoff for one menu widget on or off, and set the color of the
1009 * tearoff widget.
1010 */
1011 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001012toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013{
1014 Widget w;
1015
1016 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1017 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1018 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1019 gui_motif_menu_colors(w);
1020}
1021
1022 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001023gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024{
1025 while (menu != NULL)
1026 {
1027 if (!menu_is_popup(menu->name))
1028 {
1029 if (menu->submenu_id != (Widget)0)
1030 toggle_tearoff(menu->submenu_id);
1031 gui_mch_recurse_tearoffs(menu->children);
1032 }
1033 menu = menu->next;
1034 }
1035}
1036#endif
1037
1038 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001039gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040{
1041 Dimension shadowHeight;
1042
1043 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1044 return shadowHeight;
1045}
1046
1047/*
1048 * Compute the height of the menu bar.
1049 * We need to check all the items for their position and height, for the case
1050 * there are several rows, and/or some characters extend higher or lower.
1051 */
1052 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001053gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001054 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055{
1056 Dimension y, maxy;
1057 Dimension margin, shadow;
1058 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001059 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060
1061 /*
1062 * Get the height of the new item, before managing it, because it will
1063 * still reflect the font size. After managing it depends on the menu
1064 * height, which is what we just wanted to get!.
1065 */
1066 if (id != (Widget)0)
1067 XtVaGetValues(id, XmNheight, &height, NULL);
1068
Bram Moolenaar734a8672019-12-02 22:49:38 +01001069 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001071 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1073 {
1074 id = mp->id;
1075 break;
1076 }
1077
1078 /*
1079 * Now manage the menu item, to make them all be positioned (makes an
1080 * extra row when needed, removes it when not needed).
1081 */
1082 if (id != (Widget)0)
1083 XtManageChild(id);
1084
1085 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001086 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 */
1088 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001089 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090 {
1091 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1092 {
1093 XtVaGetValues(mp->id, XmNy, &y, NULL);
1094 if (y > maxy)
1095 maxy = y;
1096 }
1097 }
1098
1099 XtVaGetValues(menuBar,
1100 XmNmarginHeight, &margin,
1101 XmNshadowThickness, &shadow,
1102 NULL);
1103
1104 /*
1105 * This computation is the result of trial-and-error:
1106 * maxy = The maximum position of an item; required for when there are
1107 * two or more rows
1108 * height = height of an item, before managing it; Hopefully this will
1109 * change with the font height. Includes shadow-border.
1110 * shadow = shadow-border; must be subtracted from the height.
1111 * margin = margin around the menu buttons; Must be added.
1112 * Add 4 for the underlining of shortcut keys.
1113 */
1114 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1115
Bram Moolenaar734a8672019-12-02 22:49:38 +01001116 // Somehow the menu bar doesn't resize automatically. Set it here,
1117 // even though this is a catch 22. Don't do this when starting up,
1118 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 if (gui.shell_created)
1120 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001121}
1122
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001123#ifdef FEAT_TOOLBAR
1124
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001125/*
1126 * Icons used by the toolbar code.
1127 */
1128#include "gui_x11_pm.h"
1129
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001130static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001131
1132/*
1133 * Read an Xpm file. Return OK or FAIL.
1134 */
1135 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001136check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001137{
1138 XpmAttributes attrs;
1139 int status;
1140 Pixmap mask;
1141 Pixmap map;
1142
1143 attrs.valuemask = 0;
1144
Bram Moolenaar734a8672019-12-02 22:49:38 +01001145 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001146 status = XpmReadFileToPixmap(gui.dpy,
1147 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1148 (char *)path, &map, &mask, &attrs);
1149 XpmFreeAttributes(&attrs);
1150
1151 if (status == XpmSuccess)
1152 return OK;
1153 return FAIL;
1154}
1155
1156
1157/*
1158 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001159 * When it's to be read from a file, "fname" is set to the file name
1160 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001161 * Return a blank pixmap if it fails.
1162 */
1163 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001164get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001165{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001166 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1167 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001168 int res;
1169
Bram Moolenaar7c626922005-02-07 22:01:03 +00001170 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001171 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001172
1173 if (menu->iconfile != NULL)
1174 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001175 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001176 gui_find_iconfile(menu->iconfile, buf, "xpm");
1177 res = check_xpm(buf);
1178
Bram Moolenaar734a8672019-12-02 22:49:38 +01001179 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001180 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1181 res = check_xpm(buf);
1182 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001183 {
1184 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001185 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001186 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001187 }
1188
1189 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1190 {
1191 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001192 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001193 xpm = built_in_pixmaps[menu->iconidx];
1194 else
1195 xpm = tb_blank_xpm;
1196 }
1197
1198 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001200
1201/*
1202 * Add arguments for the toolbar pixmap to a menu item.
1203 */
1204 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001205add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001206{
1207 vim_free(menu->xpm_fname);
1208 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1209 if (menu->xpm == NULL)
1210 {
1211 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1212 }
1213 else
1214 {
1215 if (menu->xpm_fname != NULL)
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001216 {
Bram Moolenaar7c626922005-02-07 22:01:03 +00001217 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001218 }
Bram Moolenaar7c626922005-02-07 22:01:03 +00001219 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1220 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1221 }
1222 return n;
1223}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001224#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225
1226 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001227gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228{
1229 XmString label;
1230 vimmenu_T *parent = menu->parent;
1231
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001233 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1235 return;
1236# endif
1237
1238# ifdef FEAT_TOOLBAR
1239 if (menu_is_toolbar(parent->name))
1240 {
1241 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001242 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 int n;
1244 Arg args[18];
1245
1246 n = 0;
1247 if (menu_is_separator(menu->name))
1248 {
1249 char *cp;
1250 Dimension wid;
1251
1252 /*
1253 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1254 * a width specifier. If no width is specified then we choose one.
1255 */
1256 cp = (char *)vim_strchr(menu->name, ':');
1257 if (cp != NULL)
1258 wid = (Dimension)atoi(++cp);
1259 else
1260 wid = 4;
1261
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 type = xmSeparatorWidgetClass;
1263 XtSetArg(args[n], XmNwidth, wid); n++;
1264 XtSetArg(args[n], XmNminWidth, wid); n++;
1265 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001266 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 }
1268 else
1269 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001270 // Without shadows one can't sense whatever the button has been
1271 // pressed or not! However we want to save a bit of space...
1272 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001273 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1275 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1276 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001277 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001278 // Set the label here, so that we can switch between icons/text
1279 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001280 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1281 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001282
Bram Moolenaar7c626922005-02-07 22:01:03 +00001283 n = add_pixmap_args(menu, args, n);
1284
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001285 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 }
1287
1288 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1289 if (menu->id == NULL)
1290 {
1291 menu->id = XtCreateManagedWidget((char *)menu->dname,
1292 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001293 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 {
1295 XtAddCallback(menu->id,
1296 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001297 }
1298 }
1299 else
1300 XtSetValues(menu->id, args, n);
1301 if (xms != NULL)
1302 XmStringFree(xms);
1303
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001304# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001306# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307
1308 menu->parent = parent;
1309 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001310 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 if (!XtIsManaged(XtParent(toolBar))
1312 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1313 gui_mch_show_toolbar(TRUE);
1314 gui.toolbar_height = gui_mch_compute_toolbar_height();
1315 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001316 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317# endif
1318
Bram Moolenaar734a8672019-12-02 22:49:38 +01001319 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 if (parent->submenu_id == (Widget)0)
1321 return;
1322
1323 menu->submenu_id = (Widget)0;
1324
Bram Moolenaar734a8672019-12-02 22:49:38 +01001325 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326 if (menu_is_separator(menu->name))
1327 {
1328 menu->id = XtVaCreateWidget("subMenu",
1329 xmSeparatorGadgetClass, parent->submenu_id,
1330#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001331 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1333 ? 1 : 0),
1334#endif
1335 NULL);
1336 gui_motif_menu_colors(menu->id);
1337 return;
1338 }
1339
1340 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1341 if (label == NULL)
1342 return;
1343 menu->id = XtVaCreateWidget("subMenu",
1344 xmPushButtonWidgetClass, parent->submenu_id,
1345 XmNlabelString, label,
1346 XmNmnemonic, menu->mnemonic,
1347#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001348 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1350 ? 1 : 0),
1351#endif
1352 NULL);
1353 gui_motif_menu_colors(menu->id);
1354 gui_motif_menu_fontlist(menu->id);
1355 XmStringFree(label);
1356
1357 if (menu->id != (Widget)0)
1358 {
1359 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1360 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001361 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 gui_motif_add_actext(menu);
1363 }
1364}
1365
1366#if (XmVersion <= 1002) || defined(PROTO)
1367/*
1368 * This function will destroy/create the popup menus dynamically,
1369 * according to the value of 'mousemodel'.
1370 * This will fix the "right mouse button freeze" that occurs when
1371 * there exists a popup menu but it isn't managed.
1372 */
1373 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001374gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375{
1376 int idx = 0;
1377
Bram Moolenaar734a8672019-12-02 22:49:38 +01001378 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 if (!gui.in_use)
Yegappan Lakshmanane89aef32025-05-14 20:31:55 +02001380 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381
1382 while (menu)
1383 {
1384 if (menu->children != NULL)
1385 {
1386 if (menu_is_popup(menu->name))
1387 {
1388 if (mouse_model_popup())
1389 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001390 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 gui_mch_add_menu(menu, idx);
1392 gui_motif_update_mousemodel(menu->children);
1393 }
1394 else
1395 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001396 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397 gui_motif_update_mousemodel(menu->children);
1398 gui_mch_destroy_menu(menu);
1399 }
1400 }
1401 }
1402 else if (menu_is_child_of_popup(menu))
1403 {
1404 if (mouse_model_popup())
1405 gui_mch_add_menu_item(menu, idx);
1406 else
1407 gui_mch_destroy_menu(menu);
1408 }
1409 menu = menu->next;
1410 ++idx;
1411 }
1412}
1413#endif
1414
1415 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001416gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417{
1418 if (menuBar == (Widget)0)
1419 return;
1420 gui_motif_menu_colors(menuBar);
1421#ifdef FEAT_TOOLBAR
1422 gui_motif_menu_colors(toolBarFrame);
1423 gui_motif_menu_colors(toolBar);
1424#endif
1425
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001426 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427}
1428
1429 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001430gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431{
1432 if (menuBar == (Widget)0)
1433 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001434 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {
1436 Dimension height;
1437 Position w, h;
1438
1439 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1440 gui.menu_height = height;
1441
1442 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1443 gui_resize_shell(w, h
1444#ifdef FEAT_XIM
1445 - xim_get_status_area_height()
1446#endif
1447 );
1448 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001449 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 ui_new_shellsize();
1451}
1452
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001453#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001455gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456{
1457# ifdef FEAT_TOOLBAR
1458 vimmenu_T *menu;
1459
1460 if (toolBar == (Widget)0)
1461 return;
1462
1463 menu = gui_find_menu((char_u *)"ToolBar");
1464 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001465 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466# endif
1467}
1468
1469 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001470gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471{
1472# ifdef FEAT_TOOLBAR
1473 vimmenu_T *toolbar;
1474
1475 if (toolBar == (Widget)0)
1476 return;
1477
1478 toolbar = gui_find_menu((char_u *)"ToolBar");
1479 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001480 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481# endif
1482}
1483#endif
1484
1485 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001486submenu_change(
1487 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001488 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489{
1490 vimmenu_T *mp;
1491
1492 for (mp = menu; mp != NULL; mp = mp->next)
1493 {
1494 if (mp->id != (Widget)0)
1495 {
1496 if (colors)
1497 {
1498 gui_motif_menu_colors(mp->id);
1499#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001500 // For a toolbar item: Free the pixmap and allocate a new one,
1501 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001502 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001504 int n = 0;
1505 Arg args[18];
1506
Bram Moolenaar7c626922005-02-07 22:01:03 +00001507 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001508 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001510# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001511 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 if (mp->tip != NULL)
1513 {
1514 Arg args[2];
1515
1516 args[0].name = XmNbackground;
1517 args[0].value = gui.tooltip_bg_pixel;
1518 args[1].name = XmNforeground;
1519 args[1].value = gui.tooltip_fg_pixel;
1520 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1521 }
1522# endif
1523#endif
1524 }
1525 else
1526 {
1527 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001528#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001529 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 if (mp->tip != NULL)
1531 {
1532 Arg args[1];
1533
1534 args[0].name = XmNfontList;
1535 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1536 &gui.tooltip_fontset);
1537 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1538 }
1539#endif
1540 }
1541 }
1542
1543 if (mp->children != NULL)
1544 {
1545#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001546 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 if (mp->submenu_id != (Widget)0)
1548 {
1549 if (colors)
1550 gui_motif_menu_colors(mp->submenu_id);
1551 else
1552 gui_motif_menu_fontlist(mp->submenu_id);
1553 toggle_tearoff(mp->submenu_id);
1554 }
1555#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001556 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001557 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 }
1559 }
1560}
1561
1562/*
1563 * Destroy the machine specific menu widget.
1564 */
1565 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001566gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001568 // Please be sure to destroy the parent widget first (i.e. menu->id).
1569 // On the other hand, problems have been reported that the submenu must be
1570 // deleted first...
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 if (menu->submenu_id != (Widget)0)
1572 {
1573 XtDestroyWidget(menu->submenu_id);
1574 menu->submenu_id = (Widget)0;
1575 }
1576
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001577 if (menu->id == (Widget)0)
1578 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001580 Widget parent;
1581
1582 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001583#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001584 if (parent == toolBar && menu->tip != NULL)
1585 {
1586 // We try to destroy this before the actual menu, because there are
1587 // callbacks, etc. that will be unregistered during the tooltip
1588 // destruction.
1589 //
1590 // If you call "gui_mch_destroy_beval_area()" after destroying
1591 // menu->id, then the tooltip's window will have already been
1592 // deallocated by Xt, and unknown behaviour will ensue (probably
1593 // a core dump).
1594 gui_mch_destroy_beval_area(menu->tip);
1595 menu->tip = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 }
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001597#endif
1598 XtDestroyWidget(menu->id);
1599 menu->id = (Widget)0;
1600 if (parent == menuBar)
1601 gui_mch_compute_menu_height((Widget)0);
1602#ifdef FEAT_TOOLBAR
1603 else if (parent == toolBar)
1604 {
1605 Cardinal num_children;
1606
1607 // When removing last toolbar item, don't display the toolbar.
1608 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1609 if (num_children == 0)
1610 gui_mch_show_toolbar(FALSE);
1611 else
1612 gui.toolbar_height = gui_mch_compute_toolbar_height();
1613 }
1614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615}
1616
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001618gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001619{
1620#ifdef MOTIF_POPUP
1621 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1622 XtManageChild(menu->submenu_id);
1623#endif
1624}
1625
Bram Moolenaar734a8672019-12-02 22:49:38 +01001626#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627
1628/*
1629 * Set the menu and scrollbar colors to their default values.
1630 */
1631 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001632gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633{
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001634 if (!gui.in_use)
1635 return;
1636
1637 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
1638 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
1639 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
1640 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001641#ifdef FEAT_BEVAL_GUI
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001642 gui.tooltip_fg_pixel =
1643 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1644 gui.tooltip_bg_pixel =
1645 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647}
1648
1649
1650/*
1651 * Scrollbar stuff.
1652 */
1653
1654 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001655gui_mch_set_scrollbar_thumb(
1656 scrollbar_T *sb,
1657 long val,
1658 long size,
1659 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660{
1661 if (sb->id != (Widget)0)
1662 XtVaSetValues(sb->id,
1663 XmNvalue, val,
1664 XmNsliderSize, size,
1665 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001666 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 NULL);
1668}
1669
1670 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001671gui_mch_set_scrollbar_pos(
1672 scrollbar_T *sb,
1673 int x,
1674 int y,
1675 int w,
1676 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677{
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001678 if (sb->id == (Widget)0)
1679 return;
1680
1681 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001683 if (y == 0)
1684 h -= gui.border_offset;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 else
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001686 y -= gui.border_offset;
1687 XtVaSetValues(sb->id,
1688 XmNtopOffset, y,
1689 XmNbottomOffset, -y - h,
1690 XmNwidth, w,
1691 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 }
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001693 else
1694 XtVaSetValues(sb->id,
1695 XmNtopOffset, y,
1696 XmNleftOffset, x,
1697 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
qsmodo094b8472023-02-11 19:12:57 +00001698 ? gui.scrollbar_width : 0,
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001699 XmNheight, h,
1700 NULL);
1701 XtManageChild(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702}
1703
Bram Moolenaar203ec772020-07-17 20:43:43 +02001704 int
1705gui_mch_get_scrollbar_xpadding(void)
1706{
qsmodo28f1a512022-02-07 15:57:50 +00001707 int xpad;
1708 Dimension tw, ww;
1709 Position tx;
1710
1711 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL);
1712 XtVaGetValues(vimShell, XtNwidth, &ww, NULL);
1713 xpad = ww - tw - tx - gui.scrollbar_width;
1714 return (xpad < 0) ? 0 : xpad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001715}
1716
1717 int
1718gui_mch_get_scrollbar_ypadding(void)
1719{
qsmodo28f1a512022-02-07 15:57:50 +00001720 int ypad;
1721 Dimension th, wh;
1722 Position ty;
1723
1724 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL);
1725 XtVaGetValues(vimShell, XtNheight, &wh, NULL);
1726 ypad = wh - th - ty - gui.scrollbar_height;
1727 return (ypad < 0) ? 0 : ypad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001728}
1729
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001731gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732{
1733 Arg args[16];
1734 int n;
1735
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001736 if (sb->id == (Widget)0)
1737 return;
1738
1739 n = 0;
1740 if (flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001742 switch (sb->type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001744 case SBAR_LEFT:
1745 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1746 break;
1747
1748 case SBAR_RIGHT:
1749 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1750 break;
1751
1752 case SBAR_BOTTOM:
1753 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1754 break;
1755 }
1756 XtSetValues(textArea, args, n);
1757 XtManageChild(sb->id);
1758 }
1759 else
1760 {
1761 if (!gui.which_scrollbars[sb->type])
1762 {
1763 // The scrollbars of this type are all disabled, adjust the
1764 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 switch (sb->type)
1766 {
1767 case SBAR_LEFT:
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001768 XtSetArg(args[n], XmNleftOffset, 0); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 break;
1770
1771 case SBAR_RIGHT:
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001772 XtSetArg(args[n], XmNrightOffset, 0); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 break;
1774
1775 case SBAR_BOTTOM:
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001776 XtSetArg(args[n], XmNbottomOffset, 0);n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 break;
1778 }
1779 XtSetValues(textArea, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 }
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001781 XtUnmanageChild(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 }
1783}
1784
1785 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001786gui_mch_create_scrollbar(
1787 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001788 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789{
1790 Arg args[16];
qsmodo094b8472023-02-11 19:12:57 +00001791 int n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 XtSetArg(args[n], XmNminimum, 0); n++;
1794 XtSetArg(args[n], XmNorientation,
1795 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1796
1797 switch (sb->type)
1798 {
1799 case SBAR_LEFT:
1800 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1801 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1802 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
qsmodo094b8472023-02-11 19:12:57 +00001803 XtSetArg(args[n], XmNwidth, gui.scrollbar_width); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 break;
1805
1806 case SBAR_RIGHT:
1807 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1808 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1809 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
qsmodo094b8472023-02-11 19:12:57 +00001810 XtSetArg(args[n], XmNwidth, gui.scrollbar_width); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 break;
1812
1813 case SBAR_BOTTOM:
1814 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1815 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1816 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
qsmodo094b8472023-02-11 19:12:57 +00001817 XtSetArg(args[n], XmNheight, gui.scrollbar_height); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 break;
1819 }
1820
1821 sb->id = XtCreateWidget("scrollBar",
1822 xmScrollBarWidgetClass, textAreaForm, args, n);
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001823 if (sb->id == (Widget)0)
1824 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001826 gui_mch_set_scrollbar_colors(sb);
1827 XtAddCallback(sb->id, XmNvalueChangedCallback,
1828 scroll_cb, (XtPointer)sb->ident);
1829 XtAddCallback(sb->id, XmNdragCallback,
1830 scroll_cb, (XtPointer)sb->ident);
1831 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 (XtPointer)0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833}
1834
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001836gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837{
1838 if (sb->id != (Widget)0)
1839 XtDestroyWidget(sb->id);
1840}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841
1842 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001843gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844{
1845 if (sb->id != (Widget)0)
1846 {
1847 if (gui.scroll_bg_pixel != INVALCOLOR)
1848 {
1849#if (XmVersion>=1002)
Bram Moolenaare8504392022-03-13 14:45:03 +00001850 // This should not only set the through color but also adjust
1851 // related colors, such as shadows.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 XmChangeColor(sb->id, gui.scroll_bg_pixel);
Bram Moolenaare8504392022-03-13 14:45:03 +00001853#endif
1854
1855 // Set the through color directly, in case XmChangeColor() decided
1856 // to change it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 XtVaSetValues(sb->id,
1858 XmNtroughColor, gui.scroll_bg_pixel,
1859 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 }
1861
1862 if (gui.scroll_fg_pixel != INVALCOLOR)
1863 XtVaSetValues(sb->id,
1864 XmNforeground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 XmNbackground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 NULL);
1867 }
1868
Bram Moolenaar734a8672019-12-02 22:49:38 +01001869 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1871 gui_motif_scroll_colors(textAreaForm);
1872}
1873
1874/*
1875 * Miscellaneous stuff:
1876 */
1877
1878 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001879gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880{
1881 return(XtWindow(textArea));
1882}
1883
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001884/*
1885 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1886 * When one is found, simulate a button press on that widget and give it the
1887 * keyboard focus. If the mnemonic is on a label, look in the userData field
1888 * of the label to see if it points to another widget, and give that the focus.
1889 */
1890 static void
1891do_mnemonic(Widget w, unsigned int keycode)
1892{
1893 WidgetList children;
1894 int numChildren, i;
1895 Boolean isMenu;
1896 KeySym mnemonic = '\0';
1897 char mneString[2];
1898 Widget userData;
1899 unsigned char rowColType;
1900
1901 if (XtIsComposite(w))
1902 {
1903 if (XtClass(w) == xmRowColumnWidgetClass)
1904 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001905 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001906 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1907 }
1908 else
1909 isMenu = False;
1910 if (!isMenu)
1911 {
1912 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001913 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001914 for (i = 0; i < numChildren; i++)
1915 do_mnemonic(children[i], keycode);
1916 }
1917 }
1918 else
1919 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001920 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001921 if (mnemonic != '\0')
1922 {
1923 mneString[0] = mnemonic;
1924 mneString[1] = '\0';
1925 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1926 XStringToKeysym(mneString)) == keycode)
1927 {
1928 if (XtClass(w) == xmLabelWidgetClass
1929 || XtClass(w) == xmLabelGadgetClass)
1930 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001931 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001932 if (userData != NULL && XtIsWidget(userData))
1933 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1934 }
1935 else
1936 {
1937 XKeyPressedEvent keyEvent;
1938
1939 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1940
Bram Moolenaara80faa82020-04-12 19:37:17 +02001941 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001942 keyEvent.type = KeyPress;
1943 keyEvent.serial = 1;
1944 keyEvent.send_event = True;
1945 keyEvent.display = XtDisplay(w);
1946 keyEvent.window = XtWindow(w);
1947 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1948 NULL, 0);
1949 }
1950 }
1951 }
1952 }
1953}
1954
1955/*
1956 * Callback routine for dialog mnemonic processing.
1957 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001958 static void
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02001959mnemonic_event(
1960 Widget w,
1961 XtPointer call_data UNUSED,
1962 XKeyEvent *event,
1963 Boolean *b UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001964{
1965 do_mnemonic(w, event->keycode);
1966}
1967
1968
1969/*
1970 * Search the widget tree under w for widgets with mnemonics. When found, add
1971 * a passive grab to the dialog widget for the mnemonic character, thus
1972 * directing mnemonic events to the dialog widget.
1973 */
1974 static void
1975add_mnemonic_grabs(Widget dialog, Widget w)
1976{
1977 char mneString[2];
1978 WidgetList children;
1979 int numChildren, i;
1980 Boolean isMenu;
1981 KeySym mnemonic = '\0';
1982 unsigned char rowColType;
1983
1984 if (XtIsComposite(w))
1985 {
1986 if (XtClass(w) == xmRowColumnWidgetClass)
1987 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001988 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001989 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1990 }
1991 else
1992 isMenu = False;
1993 if (!isMenu)
1994 {
1995 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001996 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001997 for (i = 0; i < numChildren; i++)
1998 add_mnemonic_grabs(dialog, children[i]);
1999 }
2000 }
2001 else
2002 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002003 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002004 if (mnemonic != '\0')
2005 {
2006 mneString[0] = mnemonic;
2007 mneString[1] = '\0';
2008 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2009 XStringToKeysym(mneString)),
2010 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2011 }
2012 }
2013}
2014
2015/*
2016 * Add a handler for mnemonics in a dialog. Motif itself only handles
2017 * mnemonics in menus. Mnemonics added or changed after this call will be
2018 * ignored.
2019 *
2020 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2021 * the appropriate label and set the XmNuserData resource of the label to the
2022 * widget to get the focus when the mnemonic is typed.
2023 */
2024 static void
2025activate_dialog_mnemonics(Widget dialog)
2026{
2027 if (!dialog)
2028 return;
2029
2030 XtAddEventHandler(dialog, KeyPressMask, False,
2031 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2032 add_mnemonic_grabs(dialog, dialog);
2033}
2034
2035/*
2036 * Removes the event handler and key-grabs for dialog mnemonic handling.
2037 */
2038 static void
2039suppress_dialog_mnemonics(Widget dialog)
2040{
2041 if (!dialog)
2042 return;
2043
2044 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2045 XtRemoveEventHandler(dialog, KeyPressMask, False,
2046 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2047}
2048
2049#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002050/*
2051 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2052 */
2053 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002054set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002055{
2056 XmFontList fl;
2057
2058#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002059 if (gui.fontset != NOFONTSET)
2060 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002061 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2062 if (fl != NULL)
2063 {
2064 if (XtIsManaged(id))
2065 {
2066 XtUnmanageChild(id);
2067 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002068 // We should force the widget to recalculate its
2069 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002070 XtManageChild(id);
2071 }
2072 else
2073 XtVaSetValues(id, XmNfontList, fl, NULL);
2074 XmFontListFree(fl);
2075 }
2076 }
2077#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002078 if (gui.norm_font != NOFONT)
2079 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002080 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2081 if (fl != NULL)
2082 {
2083 if (XtIsManaged(id))
2084 {
2085 XtUnmanageChild(id);
2086 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002087 // We should force the widget to recalculate its
2088 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002089 XtManageChild(id);
2090 }
2091 else
2092 XtVaSetValues(id, XmNfontList, fl, NULL);
2093 XmFontListFree(fl);
2094 }
2095 }
2096#endif
2097}
2098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099
2100#if defined(FEAT_BROWSE) || defined(PROTO)
2101
2102/*
2103 * file selector related stuff
2104 */
2105
2106#include <Xm/FileSB.h>
2107#include <Xm/XmStrDefs.h>
2108
2109typedef struct dialog_callback_arg
2110{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002111 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 int id;
2113} dcbarg_T;
2114
2115static Widget dialog_wgt;
2116static char *browse_fname = NULL;
2117static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002118 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002120static void DialogCancelCB(Widget, XtPointer, XtPointer);
2121static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122
2123/*
2124 * This function is used to translate the predefined label text of the
2125 * precomposed dialogs. We do this explicitly to allow:
2126 *
2127 * - usage of gettext for translation, as in all the other places.
2128 *
2129 * - equalize the messages between different GUI implementations as far as
2130 * possible.
2131 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002132 static void
2133set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002135 XmString str;
2136 Widget w;
2137 char_u *p, *next;
2138 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139
2140 w = XtNameToWidget(parent, name);
2141
2142 if (!w)
2143 return;
2144
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002145 p = vim_strsave((char_u *)new_label);
2146 if (p == NULL)
2147 return;
2148 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002150 if (*next == DLG_HOTKEY_CHAR)
2151 {
2152 int len = STRLEN(next);
2153
2154 if (len > 0)
2155 {
2156 mch_memmove(next, next + 1, len);
2157 mnemonic = next[0];
2158 }
2159 }
2160 }
2161
2162 str = XmStringCreate((char *)p, STRING_TAG);
2163 vim_free(p);
2164
2165 if (str != NULL)
2166 {
2167 XtVaSetValues(w,
2168 XmNlabelString, str,
2169 XmNmnemonic, mnemonic,
2170 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 XmStringFree(str);
2172 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002173 gui_motif_menu_fontlist(w);
2174}
2175
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002176 static void
2177set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002178{
2179 Widget w;
2180 w = XtNameToWidget(parent, name);
2181
2182 if (!w)
2183 return;
2184
2185 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186}
2187
2188/*
2189 * Put up a file requester.
2190 * Returns the selected name in allocated memory, or NULL for Cancel.
2191 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002193gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002194 int saving UNUSED, // select file to write
2195 char_u *title, // title for the window
2196 char_u *dflt, // default name
2197 char_u *ext UNUSED, // not used (extension added)
2198 char_u *initdir, // initial directory, NULL for current dir
2199 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200{
2201 char_u dirbuf[MAXPATHL];
2202 char_u dfltbuf[MAXPATHL];
2203 char_u *pattern;
2204 char_u *tofree = NULL;
2205
Bram Moolenaar734a8672019-12-02 22:49:38 +01002206 // There a difference between the resource name and value, Therefore, we
2207 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2208 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002209
2210 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211
2212 if (initdir == NULL || *initdir == NUL)
2213 {
2214 mch_dirname(dirbuf, MAXPATHL);
2215 initdir = dirbuf;
2216 }
2217
2218 if (dflt == NULL)
2219 dflt = (char_u *)"";
2220 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2221 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002222 // The default selection should be the full path, "dflt" is only the
2223 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 STRCPY(dfltbuf, initdir);
2225 add_pathsep(dfltbuf);
2226 STRCAT(dfltbuf, dflt);
2227 dflt = dfltbuf;
2228 }
2229
Bram Moolenaar734a8672019-12-02 22:49:38 +01002230 // Can only use one pattern for a file name. Get the first pattern out of
2231 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 if (filter == NULL)
2233 pattern = (char_u *)"";
2234 else
2235 {
2236 char_u *s, *p;
2237
2238 s = filter;
2239 for (p = filter; *p != NUL; ++p)
2240 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002241 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002243 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 break;
2245 }
2246 pattern = vim_strnsave(s, p - s);
2247 tofree = pattern;
2248 if (pattern == NULL)
2249 pattern = (char_u *)"";
2250 }
2251
2252 XtVaSetValues(dialog_wgt,
2253 XtVaTypedArg,
2254 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2255 XtVaTypedArg,
2256 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2257 XtVaTypedArg,
2258 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2259 XtVaTypedArg,
2260 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2261 NULL);
2262
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002263 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2264 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2266 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002267 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002269 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2271
Bram Moolenaar734a8672019-12-02 22:49:38 +01002272 // This is to save us from silly external settings using not fixed with
2273 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002274 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2275 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2276
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 gui_motif_menu_colors(dialog_wgt);
2278 if (gui.scroll_bg_pixel != INVALCOLOR)
2279 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2280
2281 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2282 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002283 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2285 (unsigned char)XmDIALOG_HELP_BUTTON));
2286
2287 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002288 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289
Bram Moolenaar734a8672019-12-02 22:49:38 +01002290 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 do
2292 {
2293 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2294 (XtInputMask)XtIMAll);
2295 } while (XtIsManaged(dialog_wgt));
2296
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002297 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 XtDestroyWidget(dialog_wgt);
2299 vim_free(tofree);
2300
2301 if (browse_fname == NULL)
2302 return NULL;
2303 return vim_strsave((char_u *)browse_fname);
2304}
2305
2306/*
2307 * The code below was originally taken from
2308 * /usr/examples/motif/xmsamplers/xmeditor.c
2309 * on Digital Unix 4.0d, but heavily modified.
2310 */
2311
2312/*
2313 * Process callback from Dialog cancel actions.
2314 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002316DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002317 Widget w UNUSED, // widget id
2318 XtPointer client_data UNUSED, // data from application
2319 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320{
2321 if (browse_fname != NULL)
2322 {
2323 XtFree(browse_fname);
2324 browse_fname = NULL;
2325 }
2326 XtUnmanageChild(dialog_wgt);
2327}
2328
2329/*
2330 * Process callback from Dialog actions.
2331 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002333DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002334 Widget w UNUSED, // widget id
2335 XtPointer client_data UNUSED, // data from application
2336 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337{
2338 XmFileSelectionBoxCallbackStruct *fcb;
2339
2340 if (browse_fname != NULL)
2341 {
2342 XtFree(browse_fname);
2343 browse_fname = NULL;
2344 }
2345 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2346
Bram Moolenaar734a8672019-12-02 22:49:38 +01002347 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2349
Bram Moolenaar734a8672019-12-02 22:49:38 +01002350 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 XtUnmanageChild(dialog_wgt);
2352}
2353
Bram Moolenaar734a8672019-12-02 22:49:38 +01002354#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355
2356#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2357
2358static int dialogStatus;
2359
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360/*
2361 * Callback function for the textfield. When CR is hit this works like
2362 * hitting the "OK" button, ESC like "Cancel".
2363 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002365keyhit_callback(
2366 Widget w,
2367 XtPointer client_data UNUSED,
2368 XEvent *event,
2369 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370{
2371 char buf[2];
2372 KeySym key_sym;
2373
2374 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2375 {
2376 if (*buf == CAR)
2377 dialogStatus = 1;
2378 else if (*buf == ESC)
2379 dialogStatus = 2;
2380 }
2381 if ((key_sym == XK_Left || key_sym == XK_Right)
2382 && !(event->xkey.state & ShiftMask))
2383 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2384}
2385
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002387butproc(
2388 Widget w UNUSED,
2389 XtPointer client_data,
2390 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391{
2392 dialogStatus = (int)(long)client_data + 1;
2393}
2394
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395#ifdef HAVE_XPM
2396
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002398create_pixmap_label(
2399 Widget parent,
2400 String name,
2401 char **data,
2402 ArgList args,
2403 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404{
2405 Widget label;
2406 Display *dsp;
2407 Screen *scr;
2408 int depth;
2409 Pixmap pixmap = 0;
2410 XpmAttributes attr;
2411 Boolean rs;
2412 XpmColorSymbol color[5] =
2413 {
2414 {"none", NULL, 0},
2415 {"iconColor1", NULL, 0},
2416 {"bottomShadowColor", NULL, 0},
2417 {"topShadowColor", NULL, 0},
2418 {"selectColor", NULL, 0}
2419 };
2420
2421 label = XmCreateLabelGadget(parent, name, args, arg);
2422
2423 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002424 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 * no way to get the background color directly from the widget itself.
2426 * In such cases we get it from The Core part of his parent instead.
2427 */
2428 dsp = XtDisplayOfObject(label);
2429 scr = XtScreenOfObject(label);
2430 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2431 ? label : XtParent(label),
2432 XmNdepth, &depth,
2433 XmNbackground, &color[0].pixel,
2434 XmNforeground, &color[1].pixel,
2435 XmNbottomShadowColor, &color[2].pixel,
2436 XmNtopShadowColor, &color[3].pixel,
2437 XmNhighlight, &color[4].pixel,
2438 NULL);
2439
2440 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2441 attr.colorsymbols = color;
2442 attr.numsymbols = 5;
2443 attr.closeness = 65535;
2444 attr.depth = depth;
2445 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2446 data, &pixmap, NULL, &attr);
2447
2448 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2449 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2450 XtVaSetValues(label,
2451 XmNlabelType, XmPIXMAP,
2452 XmNlabelPixmap, pixmap,
2453 NULL);
2454 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2455
2456 return label;
2457}
2458#endif
2459
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002461gui_mch_dialog(
2462 int type UNUSED,
2463 char_u *title,
2464 char_u *message,
2465 char_u *button_names,
2466 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002467 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002468 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469{
2470 char_u *buts;
2471 char_u *p, *next;
2472 XtAppContext app;
2473 XmString label;
2474 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002475 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 Widget dialogform = NULL;
2477 Widget form = NULL;
2478 Widget dialogtextfield = NULL;
2479 Widget *buttons;
2480 Widget sep_form = NULL;
2481 Boolean vertical;
2482 Widget separator = NULL;
2483 int n;
2484 Arg args[6];
2485#ifdef HAVE_XPM
2486 char **icon_data = NULL;
2487 Widget dialogpixmap = NULL;
2488#endif
2489
2490 if (title == NULL)
2491 title = (char_u *)_("Vim dialog");
2492
Bram Moolenaar734a8672019-12-02 22:49:38 +01002493 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 gui_mch_mousehide(FALSE);
2495
2496 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2497
Bram Moolenaar734a8672019-12-02 22:49:38 +01002498 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2500
Bram Moolenaar734a8672019-12-02 22:49:38 +01002501 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 label = XmStringCreateSimple((char *)title);
2503 if (label == NULL)
2504 return -1;
2505 XtVaSetValues(dialogform,
2506 XmNdialogTitle, label,
2507 XmNhorizontalSpacing, 4,
2508 XmNverticalSpacing, vertical ? 0 : 4,
2509 NULL);
2510 XmStringFree(label);
2511
Bram Moolenaar734a8672019-12-02 22:49:38 +01002512 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 buts = vim_strsave(button_names);
2514 if (buts == NULL)
2515 return -1;
2516
Bram Moolenaar734a8672019-12-02 22:49:38 +01002517 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 butcount = 1;
2519 for (p = buts; *p; ++p)
2520 if (*p == DLG_BUTTON_SEP)
2521 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002522 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 if (buttons == NULL)
2524 {
2525 vim_free(buts);
2526 return -1;
2527 }
2528
2529 /*
2530 * Create the buttons.
2531 */
2532 sep_form = (Widget) 0;
2533 p = buts;
2534 for (butcount = 0; *p; ++butcount)
2535 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002536 KeySym mnemonic = NUL;
2537
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 for (next = p; *next; ++next)
2539 {
2540 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002541 {
2542 int len = STRLEN(next);
2543
2544 if (len > 0)
2545 {
2546 mch_memmove(next, next + 1, len);
2547 mnemonic = next[0];
2548 }
2549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 if (*next == DLG_BUTTON_SEP)
2551 {
2552 *next++ = NUL;
2553 break;
2554 }
2555 }
2556 label = XmStringCreate(_((char *)p), STRING_TAG);
2557 if (label == NULL)
2558 break;
2559
2560 buttons[butcount] = XtVaCreateManagedWidget("button",
2561 xmPushButtonWidgetClass, dialogform,
2562 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002563 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 XmNbottomAttachment, XmATTACH_FORM,
2565 XmNbottomOffset, 4,
2566 XmNshowAsDefault, butcount == dfltbutton - 1,
2567 XmNdefaultButtonShadowThickness, 1,
2568 NULL);
2569 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002570 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571
Bram Moolenaar734a8672019-12-02 22:49:38 +01002572 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573
2574 if (butcount > 0)
2575 {
2576 if (vertical)
2577 XtVaSetValues(buttons[butcount],
2578 XmNtopWidget, buttons[butcount - 1],
2579 NULL);
2580 else
2581 {
2582 if (*next == NUL)
2583 {
2584 XtVaSetValues(buttons[butcount],
2585 XmNrightAttachment, XmATTACH_FORM,
2586 XmNrightOffset, 4,
2587 NULL);
2588
Bram Moolenaar734a8672019-12-02 22:49:38 +01002589 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 sep_form = XtVaCreateWidget("separatorForm",
2591 xmFormWidgetClass, dialogform,
2592 XmNleftAttachment, XmATTACH_WIDGET,
2593 XmNleftWidget, buttons[butcount - 1],
2594 XmNrightAttachment, XmATTACH_WIDGET,
2595 XmNrightWidget, buttons[butcount],
2596 XmNbottomAttachment, XmATTACH_FORM,
2597 XmNbottomOffset, 4,
2598 NULL);
2599 XtManageChild(sep_form);
2600 }
2601 else
2602 {
2603 XtVaSetValues(buttons[butcount],
2604 XmNleftAttachment, XmATTACH_WIDGET,
2605 XmNleftWidget, buttons[butcount - 1],
2606 NULL);
2607 }
2608 }
2609 }
2610 else if (!vertical)
2611 {
2612 if (*next == NUL)
2613 {
2614 XtVaSetValues(buttons[0],
2615 XmNrightAttachment, XmATTACH_FORM,
2616 XmNrightOffset, 4,
2617 NULL);
2618
Bram Moolenaar734a8672019-12-02 22:49:38 +01002619 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 sep_form = XtVaCreateWidget("separatorForm",
2621 xmFormWidgetClass, dialogform,
2622 XmNleftAttachment, XmATTACH_FORM,
2623 XmNleftOffset, 4,
2624 XmNrightAttachment, XmATTACH_WIDGET,
2625 XmNrightWidget, buttons[0],
2626 XmNbottomAttachment, XmATTACH_FORM,
2627 XmNbottomOffset, 4,
2628 NULL);
2629 XtManageChild(sep_form);
2630 }
2631 else
2632 XtVaSetValues(buttons[0],
2633 XmNleftAttachment, XmATTACH_FORM,
2634 XmNleftOffset, 4,
2635 NULL);
2636 }
2637
2638 XtAddCallback(buttons[butcount], XmNactivateCallback,
2639 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2640 p = next;
2641 }
2642 vim_free(buts);
2643
2644 separator = (Widget) 0;
2645 if (butcount > 0)
2646 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002647 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 n = 0;
2649 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2650 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2651 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2652 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2653 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2654 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2655 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2656 XtManageChild(separator);
2657 }
2658
2659 if (textfield != NULL)
2660 {
2661 dialogtextfield = XtVaCreateWidget("textField",
2662 xmTextFieldWidgetClass, dialogform,
2663 XmNleftAttachment, XmATTACH_FORM,
2664 XmNrightAttachment, XmATTACH_FORM,
2665 NULL);
2666 if (butcount > 0)
2667 XtVaSetValues(dialogtextfield,
2668 XmNbottomAttachment, XmATTACH_WIDGET,
2669 XmNbottomWidget, separator,
2670 NULL);
2671 else
2672 XtVaSetValues(dialogtextfield,
2673 XmNbottomAttachment, XmATTACH_FORM,
2674 NULL);
2675
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002676 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2678 XtManageChild(dialogtextfield);
2679 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2680 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2681 }
2682
Bram Moolenaar734a8672019-12-02 22:49:38 +01002683 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 form = XtVaCreateWidget("separatorForm",
2685 xmFormWidgetClass, dialogform,
2686 XmNleftAttachment, XmATTACH_FORM,
2687 XmNrightAttachment, XmATTACH_FORM,
2688 XmNtopAttachment, XmATTACH_FORM,
2689 NULL);
2690 XtManageChild(form);
2691
2692#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002693 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 switch (type)
2695 {
2696 case VIM_GENERIC:
2697 icon_data = generic_xpm;
2698 break;
2699 case VIM_ERROR:
2700 icon_data = error_xpm;
2701 break;
2702 case VIM_WARNING:
2703 icon_data = alert_xpm;
2704 break;
2705 case VIM_INFO:
2706 icon_data = info_xpm;
2707 break;
2708 case VIM_QUESTION:
2709 icon_data = quest_xpm;
2710 break;
2711 default:
2712 icon_data = generic_xpm;
2713 }
2714
2715 n = 0;
2716 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2717 XtSetArg(args[n], XmNtopOffset, 8); n++;
2718 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2719 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2720 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2721 XtSetArg(args[n], XmNleftOffset, 8); n++;
2722
2723 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2724 icon_data, args, n);
2725 XtManageChild(dialogpixmap);
2726#endif
2727
Bram Moolenaar734a8672019-12-02 22:49:38 +01002728 // Create the dialog message.
2729 // Since LessTif is apparently having problems with the creation of
2730 // properly localized string, we use LtoR here. The symptom is that the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002731 // string is not shown properly in multiple lines as it does in native
Bram Moolenaar734a8672019-12-02 22:49:38 +01002732 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002733 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 if (label == NULL)
Christian Brabandt9ccc2972024-03-26 18:44:48 +01002735 {
2736 vim_free(buttons);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 return -1;
Christian Brabandt9ccc2972024-03-26 18:44:48 +01002738 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002739 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 xmLabelGadgetClass, form,
2741 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002742 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 XmNtopAttachment, XmATTACH_FORM,
2744 XmNtopOffset, 8,
2745#ifdef HAVE_XPM
2746 XmNleftAttachment, XmATTACH_WIDGET,
2747 XmNleftWidget, dialogpixmap,
2748#else
2749 XmNleftAttachment, XmATTACH_FORM,
2750#endif
2751 XmNleftOffset, 8,
2752 XmNrightAttachment, XmATTACH_FORM,
2753 XmNrightOffset, 8,
2754 XmNbottomAttachment, XmATTACH_FORM,
2755 XmNbottomOffset, 8,
2756 NULL);
2757 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002758 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759
2760 if (textfield != NULL)
2761 {
2762 XtVaSetValues(form,
2763 XmNbottomAttachment, XmATTACH_WIDGET,
2764 XmNbottomWidget, dialogtextfield,
2765 NULL);
2766 }
2767 else
2768 {
2769 if (butcount > 0)
2770 XtVaSetValues(form,
2771 XmNbottomAttachment, XmATTACH_WIDGET,
2772 XmNbottomWidget, separator,
2773 NULL);
2774 else
2775 XtVaSetValues(form,
2776 XmNbottomAttachment, XmATTACH_FORM,
2777 NULL);
2778 }
2779
2780 if (dfltbutton < 1)
2781 dfltbutton = 1;
2782 if (dfltbutton > butcount)
2783 dfltbutton = butcount;
2784 XtVaSetValues(dialogform,
2785 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2786 if (textfield != NULL)
2787 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2788 else
2789 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2790 NULL);
2791
2792 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002793 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794
2795 if (textfield != NULL && *textfield != NUL)
2796 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002797 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 XmTextFieldSetSelection(dialogtextfield,
2799 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2800 XtLastTimestampProcessed(gui.dpy));
2801 XmTextFieldSetCursorPosition(dialogtextfield,
2802 (XmTextPosition)STRLEN(textfield));
2803 }
2804
2805 app = XtWidgetToApplicationContext(dialogform);
2806
Bram Moolenaar734a8672019-12-02 22:49:38 +01002807 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 dialogStatus = -1;
2809 for (;;)
2810 {
2811 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2812 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2813 break;
2814 }
2815
2816 vim_free(buttons);
2817
2818 if (textfield != NULL)
2819 {
2820 p = (char_u *)XmTextGetString(dialogtextfield);
2821 if (p == NULL || dialogStatus < 0)
2822 *textfield = NUL;
2823 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002824 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002825 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 }
2827
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002828 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 XtDestroyWidget(dialogform);
2830
2831 return dialogStatus;
2832}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002833#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835#if defined(FEAT_TOOLBAR) || defined(PROTO)
2836 void
2837gui_mch_show_toolbar(int showit)
2838{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002839 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840
2841 if (toolBar == (Widget)0)
2842 return;
2843 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2844 if (showit && numChildren > 0)
2845 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002846 // Assume that we want to show the toolbar if p_toolbar contains
2847 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 WidgetList children;
2849
2850 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2851 {
2852 void (*action)(BalloonEval *);
2853 int text = 0;
2854
2855 if (strstr((const char *)p_toolbar, "tooltips"))
2856 action = &gui_mch_enable_beval_area;
2857 else
2858 action = &gui_mch_disable_beval_area;
2859 if (strstr((const char *)p_toolbar, "text"))
2860 text = 1;
2861 else if (strstr((const char *)p_toolbar, "icons"))
2862 text = -1;
2863 if (text != 0)
2864 {
2865 vimmenu_T *toolbar;
2866 vimmenu_T *cur;
2867
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002868 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 if (menu_is_toolbar(toolbar->dname))
2870 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002871 // Assumption: toolbar is NULL if there is no toolbar,
2872 // otherwise it contains the toolbar menu structure.
2873 //
2874 // Assumption: "numChildren" == the number of items in the list
2875 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 if (toolbar)
2877 {
2878 for (cur = toolbar->children; cur; cur = cur->next)
2879 {
2880 Arg args[1];
2881 int n = 0;
2882
Bram Moolenaar734a8672019-12-02 22:49:38 +01002883 // Enable/Disable tooltip (OK to enable while
2884 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 if (cur->tip != NULL)
2886 (*action)(cur->tip);
2887 if (!menu_is_separator(cur->name))
2888 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002889 if (text == 1 || cur->xpm == NULL)
2890 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002892 ++n;
2893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 if (cur->id != NULL)
2895 {
2896 XtUnmanageChild(cur->id);
2897 XtSetValues(cur->id, args, n);
2898 XtManageChild(cur->id);
2899 }
2900 }
2901 }
2902 }
2903 }
2904 }
2905 gui.toolbar_height = gui_mch_compute_toolbar_height();
2906 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002907#ifdef FEAT_GUI_TABLINE
2908 if (showing_tabline)
2909 {
2910 XtVaSetValues(tabLine,
2911 XmNtopAttachment, XmATTACH_WIDGET,
2912 XmNtopWidget, XtParent(toolBar),
2913 NULL);
2914 XtVaSetValues(textAreaForm,
2915 XmNtopAttachment, XmATTACH_WIDGET,
2916 XmNtopWidget, tabLine,
2917 NULL);
2918 }
2919 else
2920#endif
2921 XtVaSetValues(textAreaForm,
2922 XmNtopAttachment, XmATTACH_WIDGET,
2923 XmNtopWidget, XtParent(toolBar),
2924 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 if (XtIsManaged(menuBar))
2926 XtVaSetValues(XtParent(toolBar),
2927 XmNtopAttachment, XmATTACH_WIDGET,
2928 XmNtopWidget, menuBar,
2929 NULL);
2930 else
2931 XtVaSetValues(XtParent(toolBar),
2932 XmNtopAttachment, XmATTACH_FORM,
2933 NULL);
2934 }
2935 else
2936 {
2937 gui.toolbar_height = 0;
2938 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002939 {
2940#ifdef FEAT_GUI_TABLINE
2941 if (showing_tabline)
2942 {
2943 XtVaSetValues(tabLine,
2944 XmNtopAttachment, XmATTACH_WIDGET,
2945 XmNtopWidget, menuBar,
2946 NULL);
2947 XtVaSetValues(textAreaForm,
2948 XmNtopAttachment, XmATTACH_WIDGET,
2949 XmNtopWidget, tabLine,
2950 NULL);
2951 }
2952 else
2953#endif
2954 XtVaSetValues(textAreaForm,
2955 XmNtopAttachment, XmATTACH_WIDGET,
2956 XmNtopWidget, menuBar,
2957 NULL);
2958 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002960 {
2961#ifdef FEAT_GUI_TABLINE
2962 if (showing_tabline)
2963 {
2964 XtVaSetValues(tabLine,
2965 XmNtopAttachment, XmATTACH_FORM,
2966 NULL);
2967 XtVaSetValues(textAreaForm,
2968 XmNtopAttachment, XmATTACH_WIDGET,
2969 XmNtopWidget, tabLine,
2970 NULL);
2971 }
2972 else
2973#endif
2974 XtVaSetValues(textAreaForm,
2975 XmNtopAttachment, XmATTACH_FORM,
2976 NULL);
2977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978
2979 XtUnmanageChild(XtParent(toolBar));
2980 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00002981 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982}
2983
2984/*
2985 * A toolbar button has been pushed; now reset the input focus
2986 * such that the user can type page up/down etc. and have the
2987 * input go to the editor window, not the button
2988 */
2989 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002990reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991{
2992 if (textArea != NULL)
2993 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
2994}
2995
2996 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002997gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002999 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003000 Dimension height; // total Toolbar height
3001 Dimension whgt; // height of each widget
3002 WidgetList children; // list of toolBar's children
3003 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 int i;
3005
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003006 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003009 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003010 Dimension fst;
3011 Dimension fmh;
3012 Dimension tst;
3013 Dimension tmh;
3014
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003016 XmNshadowThickness, &fst,
3017 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003019 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003021 XmNshadowThickness, &tst,
3022 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 XmNchildren, &children,
3024 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003025 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003026 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 {
3028 whgt = 0;
3029 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3030 if (height < whgt)
3031 height = whgt;
3032 }
3033 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003034#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003035 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003036 if (height < 10)
3037 height = 24;
3038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003040 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041}
3042
Bram Moolenaar7c626922005-02-07 22:01:03 +00003043 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003044motif_get_toolbar_colors(
3045 Pixel *bgp,
3046 Pixel *fgp,
3047 Pixel *bsp,
3048 Pixel *tsp,
3049 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003050{
3051 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003052 XmNbackground, bgp,
3053 XmNforeground, fgp,
3054 XmNbottomShadowColor, bsp,
3055 XmNtopShadowColor, tsp,
3056 XmNhighlightColor, hsp,
3057 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003058}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059#endif
3060
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003061#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3062/*
3063 * Show or hide the tabline.
3064 */
3065 void
3066gui_mch_show_tabline(int showit)
3067{
3068 if (tabLine == (Widget)0)
3069 return;
3070
3071 if (!showit != !showing_tabline)
3072 {
3073 if (showit)
3074 {
3075 XtManageChild(tabLine);
3076 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003077 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3078 XtUnmanageChild(XtNameToWidget(tabLine,
3079 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003080#ifdef FEAT_MENU
3081# ifdef FEAT_TOOLBAR
3082 if (XtIsManaged(XtParent(toolBar)))
3083 XtVaSetValues(tabLine,
3084 XmNtopAttachment, XmATTACH_WIDGET,
3085 XmNtopWidget, XtParent(toolBar), NULL);
3086 else
3087# endif
3088 if (XtIsManaged(menuBar))
3089 XtVaSetValues(tabLine,
3090 XmNtopAttachment, XmATTACH_WIDGET,
3091 XmNtopWidget, menuBar, NULL);
3092 else
3093#endif
3094 XtVaSetValues(tabLine,
3095 XmNtopAttachment, XmATTACH_FORM, NULL);
3096 XtVaSetValues(textAreaForm,
3097 XmNtopAttachment, XmATTACH_WIDGET,
3098 XmNtopWidget, tabLine,
3099 NULL);
3100 }
3101 else
3102 {
3103 XtUnmanageChild(tabLine);
3104#ifdef FEAT_MENU
3105# ifdef FEAT_TOOLBAR
3106 if (XtIsManaged(XtParent(toolBar)))
3107 XtVaSetValues(textAreaForm,
3108 XmNtopAttachment, XmATTACH_WIDGET,
3109 XmNtopWidget, XtParent(toolBar), NULL);
3110 else
3111# endif
3112 if (XtIsManaged(menuBar))
3113 XtVaSetValues(textAreaForm,
3114 XmNtopAttachment, XmATTACH_WIDGET,
3115 XmNtopWidget, menuBar, NULL);
3116 else
3117#endif
3118 XtVaSetValues(textAreaForm,
3119 XmNtopAttachment, XmATTACH_FORM, NULL);
3120 }
3121 showing_tabline = showit;
3122 }
3123}
3124
3125/*
3126 * Return TRUE when tabline is displayed.
3127 */
3128 int
3129gui_mch_showing_tabline(void)
3130{
3131 return tabLine != (Widget)0 && showing_tabline;
3132}
3133
3134/*
3135 * Update the labels of the tabline.
3136 */
3137 void
3138gui_mch_update_tabline(void)
3139{
3140 tabpage_T *tp;
3141 int nr = 1, n;
3142 Arg args[10];
3143 int curtabidx = 0, currentpage;
3144 Widget tab;
3145 XmNotebookPageInfo page_info;
3146 XmNotebookPageStatus page_status;
3147 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003148 XmString label_str;
3149 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003150 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003151
3152 if (tabLine == (Widget)0)
3153 return;
3154
Bram Moolenaar734a8672019-12-02 22:49:38 +01003155 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003156 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3157 {
3158 if (tp == curtab)
3159 curtabidx = nr;
3160
3161 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3162 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003163 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003164 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003165 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003166 n = 0;
3167 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3168 XtSetArg(args[n], XmNtraversalOn, False); n++;
3169 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3170 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3171 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3172 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3173 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003174 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3175 NULL);
3176 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003177 }
3178 else
3179 tab = page_info.major_tab_widget;
3180
3181 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003182
3183 /*
3184 * Change the label text only if it is different
3185 */
3186 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3187 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3188 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003189 get_tabline_label(tp, FALSE);
3190 if (STRCMP(label_cstr, NameBuff) != 0)
3191 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003192 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3193 NameBuff, STRLEN(NameBuff) + 1, NULL);
3194 /*
3195 * Force a resize of the tab label button
3196 */
3197 XtUnmanageChild(tab);
3198 XtManageChild(tab);
3199 }
3200 XtFree(label_cstr);
3201 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003202 }
3203
3204 tab_count = nr - 1;
3205
3206 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3207
Bram Moolenaar734a8672019-12-02 22:49:38 +01003208 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003209 while (nr <= last_page)
3210 {
3211 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3212 && page_info.page_number == nr
3213 && page_info.major_tab_widget != (Widget)0)
3214 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003215 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3216 if (beval != NULL)
3217 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003218 XtUnmanageChild(page_info.major_tab_widget);
3219 XtDestroyWidget(page_info.major_tab_widget);
3220 }
3221 nr++;
3222 }
3223
3224 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3225
3226 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3227 if (currentpage != curtabidx)
3228 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3229}
3230
3231/*
3232 * Set the current tab to "nr". First tab is 1.
3233 */
3234 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003235gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003236{
3237 int currentpage;
3238
3239 if (tabLine == (Widget)0)
3240 return;
3241
3242 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3243 if (currentpage != nr)
3244 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3245}
3246#endif
3247
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248/*
3249 * Set the colors of Widget "id" to the menu colors.
3250 */
3251 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003252gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253{
3254 if (gui.menu_bg_pixel != INVALCOLOR)
3255#if (XmVersion >= 1002)
3256 XmChangeColor(id, gui.menu_bg_pixel);
3257#else
3258 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3259#endif
3260 if (gui.menu_fg_pixel != INVALCOLOR)
3261 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3262}
3263
3264/*
3265 * Set the colors of Widget "id" to the scrollbar colors.
3266 */
3267 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003268gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269{
3270 if (gui.scroll_bg_pixel != INVALCOLOR)
3271#if (XmVersion >= 1002)
3272 XmChangeColor(id, gui.scroll_bg_pixel);
3273#else
3274 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3275#endif
3276 if (gui.scroll_fg_pixel != INVALCOLOR)
3277 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3278}
3279
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280/*
3281 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3282 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003283 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003284gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003286#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287#ifdef FONTSET_ALWAYS
3288 if (gui.menu_fontset != NOFONTSET)
3289 {
3290 XmFontList fl;
3291
3292 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3293 if (fl != NULL)
3294 {
3295 if (XtIsManaged(id))
3296 {
3297 XtUnmanageChild(id);
3298 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003299 // We should force the widget to recalculate its
3300 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 XtManageChild(id);
3302 }
3303 else
3304 XtVaSetValues(id, XmNfontList, fl, NULL);
3305 XmFontListFree(fl);
3306 }
3307 }
3308#else
3309 if (gui.menu_font != NOFONT)
3310 {
3311 XmFontList fl;
3312
3313 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3314 if (fl != NULL)
3315 {
3316 if (XtIsManaged(id))
3317 {
3318 XtUnmanageChild(id);
3319 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003320 // We should force the widget to recalculate its
3321 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 XtManageChild(id);
3323 }
3324 else
3325 XtVaSetValues(id, XmNfontList, fl, NULL);
3326 XmFontListFree(fl);
3327 }
3328 }
3329#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331}
3332
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333
3334/*
3335 * We don't create it twice for the sake of speed.
3336 */
3337
3338typedef struct _SharedFindReplace
3339{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003340 Widget dialog; // the main dialog widget
3341 Widget wword; // 'Exact match' check button
3342 Widget mcase; // 'match case' check button
3343 Widget up; // search direction 'Up' radio button
3344 Widget down; // search direction 'Down' radio button
3345 Widget what; // 'Find what' entry text widget
3346 Widget with; // 'Replace with' entry text widget
3347 Widget find; // 'Find Next' action button
3348 Widget replace; // 'Replace With' action button
3349 Widget all; // 'Replace All' action button
3350 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351
3352 Widget cancel;
3353} SharedFindReplace;
3354
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003355static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3356static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003359find_replace_destroy_callback(
3360 Widget w UNUSED,
3361 XtPointer client_data,
3362 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363{
3364 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3365
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003366 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003367 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368 cd->dialog = (Widget)0;
3369}
3370
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003372find_replace_dismiss_callback(
3373 Widget w UNUSED,
3374 XtPointer client_data,
3375 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376{
3377 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3378
3379 if (cd != NULL)
3380 XtUnmanageChild(cd->dialog);
3381}
3382
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003384entry_activate_callback(
3385 Widget w UNUSED,
3386 XtPointer client_data,
3387 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388{
3389 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3390}
3391
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003393find_replace_callback(
3394 Widget w UNUSED,
3395 XtPointer client_data,
3396 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397{
3398 long_u flags = (long_u)client_data;
3399 char *find_text, *repl_text;
3400 Boolean direction_down = TRUE;
3401 Boolean wword;
3402 Boolean mcase;
3403 SharedFindReplace *sfr;
3404
3405 if (flags == FRD_UNDO)
3406 {
3407 char_u *save_cpo = p_cpo;
3408
Bram Moolenaar734a8672019-12-02 22:49:38 +01003409 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003410 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411 u_undo(1);
3412 p_cpo = save_cpo;
3413 gui_update_screen();
3414 return;
3415 }
3416
Bram Moolenaar734a8672019-12-02 22:49:38 +01003417 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 if (flags == FRD_FINDNEXT)
3419 {
3420 repl_text = NULL;
3421 sfr = &find_widgets;
3422 }
3423 else
3424 {
3425 repl_text = XmTextFieldGetString(repl_widgets.with);
3426 sfr = &repl_widgets;
3427 }
3428 find_text = XmTextFieldGetString(sfr->what);
3429 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3430 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3431 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3432 if (wword)
3433 flags |= FRD_WHOLE_WORD;
3434 if (mcase)
3435 flags |= FRD_MATCH_CASE;
3436
3437 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3438 direction_down);
3439
3440 if (find_text != NULL)
3441 XtFree(find_text);
3442 if (repl_text != NULL)
3443 XtFree(repl_text);
3444}
3445
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003447find_replace_keypress(
3448 Widget w UNUSED,
3449 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003450 XKeyEvent *event,
3451 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452{
3453 KeySym keysym;
3454
3455 if (frdp == NULL)
3456 return;
3457
3458 keysym = XLookupKeysym(event, 0);
3459
Bram Moolenaar734a8672019-12-02 22:49:38 +01003460 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 if (keysym == XK_Escape)
3462 XtUnmanageChild(frdp->dialog);
3463}
3464
3465 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003466set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003467{
3468 XmString str;
3469 char_u *p, *next;
3470 KeySym mnemonic = NUL;
3471
3472 if (!w)
3473 return;
3474
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003475 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003476 if (p == NULL)
3477 return;
3478 for (next = p; *next; ++next)
3479 {
3480 if (*next == DLG_HOTKEY_CHAR)
3481 {
3482 int len = STRLEN(next);
3483
3484 if (len > 0)
3485 {
3486 mch_memmove(next, next + 1, len);
3487 mnemonic = next[0];
3488 }
3489 }
3490 }
3491
3492 str = XmStringCreateSimple((char *)p);
3493 vim_free(p);
3494 if (str)
3495 {
3496 XtVaSetValues(w,
3497 XmNlabelString, str,
3498 XmNmnemonic, mnemonic,
3499 NULL);
3500 XmStringFree(str);
3501 }
3502 gui_motif_menu_fontlist(w);
3503}
3504
3505 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003506find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507{
3508 SharedFindReplace *frdp;
3509 Widget separator;
3510 Widget input_form;
3511 Widget button_form;
3512 Widget toggle_form;
3513 Widget frame;
3514 XmString str;
3515 int n;
3516 Arg args[6];
3517 int wword = FALSE;
3518 int mcase = !p_ic;
3519 Dimension width;
3520 Dimension widest;
3521 char_u *entry_text;
3522
3523 frdp = do_replace ? &repl_widgets : &find_widgets;
3524
Bram Moolenaar734a8672019-12-02 22:49:38 +01003525 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3527
Bram Moolenaar734a8672019-12-02 22:49:38 +01003528 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 if (frdp->dialog)
3530 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003531 gui_motif_synch_fonts();
3532
Bram Moolenaar734a8672019-12-02 22:49:38 +01003533 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534 if (XtIsManaged(frdp->dialog))
3535 XMapRaised(XtDisplay(frdp->dialog),
3536 XtWindow(XtParent(frdp->dialog)));
3537 else
3538 XtManageChild(frdp->dialog);
3539 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3540 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3541
3542 if (entry_text != NULL)
3543 XmTextFieldSetString(frdp->what, (char *)entry_text);
3544 vim_free(entry_text);
3545
3546 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3547 return;
3548 }
3549
Bram Moolenaar734a8672019-12-02 22:49:38 +01003550 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003551 if (do_replace)
3552 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3553 else
3554 str = XmStringCreateSimple(_("VIM - Search..."));
3555
3556 n = 0;
3557 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3558 XtSetArg(args[n], XmNnoResize, True); n++;
3559 XtSetArg(args[n], XmNdialogTitle, str); n++;
3560
3561 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3562 XmStringFree(str);
3563 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3564 find_replace_destroy_callback, frdp);
3565
3566 button_form = XtVaCreateWidget("buttonForm",
3567 xmFormWidgetClass, frdp->dialog,
3568 XmNrightAttachment, XmATTACH_FORM,
3569 XmNrightOffset, 4,
3570 XmNtopAttachment, XmATTACH_FORM,
3571 XmNtopOffset, 4,
3572 XmNbottomAttachment, XmATTACH_FORM,
3573 XmNbottomOffset, 4,
3574 NULL);
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 frdp->find = XtVaCreateManagedWidget("findButton",
3577 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 XmNsensitive, True,
3579 XmNtopAttachment, XmATTACH_FORM,
3580 XmNleftAttachment, XmATTACH_FORM,
3581 XmNrightAttachment, XmATTACH_FORM,
3582 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003583 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584
3585 XtAddCallback(frdp->find, XmNactivateCallback,
3586 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003587 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588
3589 if (do_replace)
3590 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003591 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3592 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 XmNtopAttachment, XmATTACH_WIDGET,
3594 XmNtopWidget, frdp->find,
3595 XmNleftAttachment, XmATTACH_FORM,
3596 XmNrightAttachment, XmATTACH_FORM,
3597 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003598 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 XtAddCallback(frdp->replace, XmNactivateCallback,
3600 find_replace_callback, (XtPointer)FRD_REPLACE);
3601
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3603 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 XmNtopAttachment, XmATTACH_WIDGET,
3605 XmNtopWidget, frdp->replace,
3606 XmNleftAttachment, XmATTACH_FORM,
3607 XmNrightAttachment, XmATTACH_FORM,
3608 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003609 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 XtAddCallback(frdp->all, XmNactivateCallback,
3611 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3612
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 frdp->undo = XtVaCreateManagedWidget("undoButton",
3614 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 XmNtopAttachment, XmATTACH_WIDGET,
3616 XmNtopWidget, frdp->all,
3617 XmNleftAttachment, XmATTACH_FORM,
3618 XmNrightAttachment, XmATTACH_FORM,
3619 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003620 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621 XtAddCallback(frdp->undo, XmNactivateCallback,
3622 find_replace_callback, (XtPointer)FRD_UNDO);
3623 }
3624
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3626 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 XmNleftAttachment, XmATTACH_FORM,
3628 XmNrightAttachment, XmATTACH_FORM,
3629 XmNbottomAttachment, XmATTACH_FORM,
3630 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003631 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 XtAddCallback(frdp->cancel, XmNactivateCallback,
3633 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003634 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635
3636 XtManageChild(button_form);
3637
3638 n = 0;
3639 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3640 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3641 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3642 XtSetArg(args[n], XmNrightOffset, 4); n++;
3643 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3644 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3645 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3646 XtManageChild(separator);
3647
3648 input_form = XtVaCreateWidget("inputForm",
3649 xmFormWidgetClass, frdp->dialog,
3650 XmNleftAttachment, XmATTACH_FORM,
3651 XmNleftOffset, 4,
3652 XmNrightAttachment, XmATTACH_WIDGET,
3653 XmNrightWidget, separator,
3654 XmNrightOffset, 4,
3655 XmNtopAttachment, XmATTACH_FORM,
3656 XmNtopOffset, 4,
3657 NULL);
3658
3659 {
3660 Widget label_what;
3661 Widget label_with = (Widget)0;
3662
3663 str = XmStringCreateSimple(_("Find what:"));
3664 label_what = XtVaCreateManagedWidget("whatLabel",
3665 xmLabelGadgetClass, input_form,
3666 XmNlabelString, str,
3667 XmNleftAttachment, XmATTACH_FORM,
3668 XmNtopAttachment, XmATTACH_FORM,
3669 XmNtopOffset, 4,
3670 NULL);
3671 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003672 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673
3674 frdp->what = XtVaCreateManagedWidget("whatText",
3675 xmTextFieldWidgetClass, input_form,
3676 XmNtopAttachment, XmATTACH_FORM,
3677 XmNrightAttachment, XmATTACH_FORM,
3678 XmNleftAttachment, XmATTACH_FORM,
3679 NULL);
3680
3681 if (do_replace)
3682 {
3683 frdp->with = XtVaCreateManagedWidget("withText",
3684 xmTextFieldWidgetClass, input_form,
3685 XmNtopAttachment, XmATTACH_WIDGET,
3686 XmNtopWidget, frdp->what,
3687 XmNtopOffset, 4,
3688 XmNleftAttachment, XmATTACH_FORM,
3689 XmNrightAttachment, XmATTACH_FORM,
3690 XmNbottomAttachment, XmATTACH_FORM,
3691 NULL);
3692
3693 XtAddCallback(frdp->with, XmNactivateCallback,
3694 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3695
3696 str = XmStringCreateSimple(_("Replace with:"));
3697 label_with = XtVaCreateManagedWidget("withLabel",
3698 xmLabelGadgetClass, input_form,
3699 XmNlabelString, str,
3700 XmNleftAttachment, XmATTACH_FORM,
3701 XmNtopAttachment, XmATTACH_WIDGET,
3702 XmNtopWidget, frdp->what,
3703 XmNtopOffset, 4,
3704 XmNbottomAttachment, XmATTACH_FORM,
3705 NULL);
3706 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003707 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708
3709 /*
3710 * Make the entry activation only change the input focus onto the
3711 * with item.
3712 */
3713 XtAddCallback(frdp->what, XmNactivateCallback,
3714 entry_activate_callback, frdp->with);
3715 XtAddEventHandler(frdp->with, KeyPressMask, False,
3716 (XtEventHandler)find_replace_keypress,
3717 (XtPointer) frdp);
3718
3719 }
3720 else
3721 {
3722 /*
3723 * Make the entry activation do the search.
3724 */
3725 XtAddCallback(frdp->what, XmNactivateCallback,
3726 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3727 }
3728 XtAddEventHandler(frdp->what, KeyPressMask, False,
3729 (XtEventHandler)find_replace_keypress,
3730 (XtPointer)frdp);
3731
Bram Moolenaar734a8672019-12-02 22:49:38 +01003732 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 n = 0;
3734 XtSetArg(args[n], XmNwidth, &width); n++;
3735 XtGetValues(label_what, args, n);
3736 widest = width;
3737 if (do_replace)
3738 {
3739 XtGetValues(label_with, args, n);
3740 if (width > widest)
3741 widest = width;
3742 }
3743
3744 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3745 if (do_replace)
3746 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3747
3748 }
3749
3750 XtManageChild(input_form);
3751
3752 {
3753 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003754 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755
3756 frame = XtVaCreateWidget("directionFrame",
3757 xmFrameWidgetClass, frdp->dialog,
3758 XmNtopAttachment, XmATTACH_WIDGET,
3759 XmNtopWidget, input_form,
3760 XmNtopOffset, 4,
3761 XmNbottomAttachment, XmATTACH_FORM,
3762 XmNbottomOffset, 4,
3763 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3764 XmNrightWidget, input_form,
3765 NULL);
3766
3767 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003768 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 xmLabelGadgetClass, frame,
3770 XmNlabelString, str,
3771 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3772 XmNchildType, XmFRAME_TITLE_CHILD,
3773 NULL);
3774 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003775 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776
3777 radio_box = XmCreateRadioBox(frame, "radioBox",
3778 (ArgList)NULL, 0);
3779
3780 str = XmStringCreateSimple( _("Up"));
3781 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3782 xmToggleButtonGadgetClass, radio_box,
3783 XmNlabelString, str,
3784 XmNset, False,
3785 NULL);
3786 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003787 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788
3789 str = XmStringCreateSimple(_("Down"));
3790 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3791 xmToggleButtonGadgetClass, radio_box,
3792 XmNlabelString, str,
3793 XmNset, True,
3794 NULL);
3795 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003796 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797
3798 XtManageChild(radio_box);
3799 XtManageChild(frame);
3800 }
3801
3802 toggle_form = XtVaCreateWidget("toggleForm",
3803 xmFormWidgetClass, frdp->dialog,
3804 XmNleftAttachment, XmATTACH_FORM,
3805 XmNleftOffset, 4,
3806 XmNrightAttachment, XmATTACH_WIDGET,
3807 XmNrightWidget, frame,
3808 XmNrightOffset, 4,
3809 XmNtopAttachment, XmATTACH_WIDGET,
3810 XmNtopWidget, input_form,
3811 XmNtopOffset, 4,
3812 XmNbottomAttachment, XmATTACH_FORM,
3813 XmNbottomOffset, 4,
3814 NULL);
3815
3816 str = XmStringCreateSimple(_("Match whole word only"));
3817 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3818 xmToggleButtonGadgetClass, toggle_form,
3819 XmNlabelString, str,
3820 XmNtopAttachment, XmATTACH_FORM,
3821 XmNtopOffset, 4,
3822 XmNleftAttachment, XmATTACH_FORM,
3823 XmNleftOffset, 4,
3824 XmNset, wword,
3825 NULL);
3826 XmStringFree(str);
3827
3828 str = XmStringCreateSimple(_("Match case"));
3829 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3830 xmToggleButtonGadgetClass, toggle_form,
3831 XmNlabelString, str,
3832 XmNleftAttachment, XmATTACH_FORM,
3833 XmNleftOffset, 4,
3834 XmNtopAttachment, XmATTACH_WIDGET,
3835 XmNtopWidget, frdp->wword,
3836 XmNtopOffset, 4,
3837 XmNset, mcase,
3838 NULL);
3839 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003840 gui_motif_menu_fontlist(frdp->wword);
3841 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842
3843 XtManageChild(toggle_form);
3844
3845 if (entry_text != NULL)
3846 XmTextFieldSetString(frdp->what, (char *)entry_text);
3847 vim_free(entry_text);
3848
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003849 gui_motif_synch_fonts();
3850
3851 manage_centered(frdp->dialog);
3852 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3854}
3855
3856 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003857gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858{
3859 if (!gui.in_use)
3860 return;
3861
3862 find_replace_dialog_create(eap->arg, FALSE);
3863}
3864
3865
3866 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003867gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868{
3869 if (!gui.in_use)
3870 return;
3871
3872 find_replace_dialog_create(eap->arg, TRUE);
3873}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003874
3875/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00003876 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003877 * main text font used. Those are in esp. the find/replace dialogs.
3878 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003879 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003880 */
3881 void
3882gui_motif_synch_fonts(void)
3883{
3884 SharedFindReplace *frdp;
3885 int do_replace;
3886 XFontStruct *font;
3887 XmFontList font_list;
3888
Bram Moolenaar734a8672019-12-02 22:49:38 +01003889 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3890 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003891 font = (XFontStruct *)gui.norm_font;
3892 if (font == NULL)
3893 return;
3894
3895 font_list = gui_motif_create_fontlist(font);
3896
Bram Moolenaar734a8672019-12-02 22:49:38 +01003897 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003898 for (do_replace = 0; do_replace <= 1; ++do_replace)
3899 {
3900 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3901 if (frdp->dialog)
3902 {
3903 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
3904 if (do_replace)
3905 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
3906 }
3907 }
3908
3909 XmFontListFree(font_list);
3910}