blob: 630082e981308fde6bbf77860d69dead57de9cf7 [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)
1380 return;
1381
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)
2735 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002736 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 xmLabelGadgetClass, form,
2738 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002739 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 XmNtopAttachment, XmATTACH_FORM,
2741 XmNtopOffset, 8,
2742#ifdef HAVE_XPM
2743 XmNleftAttachment, XmATTACH_WIDGET,
2744 XmNleftWidget, dialogpixmap,
2745#else
2746 XmNleftAttachment, XmATTACH_FORM,
2747#endif
2748 XmNleftOffset, 8,
2749 XmNrightAttachment, XmATTACH_FORM,
2750 XmNrightOffset, 8,
2751 XmNbottomAttachment, XmATTACH_FORM,
2752 XmNbottomOffset, 8,
2753 NULL);
2754 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002755 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756
2757 if (textfield != NULL)
2758 {
2759 XtVaSetValues(form,
2760 XmNbottomAttachment, XmATTACH_WIDGET,
2761 XmNbottomWidget, dialogtextfield,
2762 NULL);
2763 }
2764 else
2765 {
2766 if (butcount > 0)
2767 XtVaSetValues(form,
2768 XmNbottomAttachment, XmATTACH_WIDGET,
2769 XmNbottomWidget, separator,
2770 NULL);
2771 else
2772 XtVaSetValues(form,
2773 XmNbottomAttachment, XmATTACH_FORM,
2774 NULL);
2775 }
2776
2777 if (dfltbutton < 1)
2778 dfltbutton = 1;
2779 if (dfltbutton > butcount)
2780 dfltbutton = butcount;
2781 XtVaSetValues(dialogform,
2782 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2783 if (textfield != NULL)
2784 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2785 else
2786 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2787 NULL);
2788
2789 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002790 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791
2792 if (textfield != NULL && *textfield != NUL)
2793 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002794 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 XmTextFieldSetSelection(dialogtextfield,
2796 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2797 XtLastTimestampProcessed(gui.dpy));
2798 XmTextFieldSetCursorPosition(dialogtextfield,
2799 (XmTextPosition)STRLEN(textfield));
2800 }
2801
2802 app = XtWidgetToApplicationContext(dialogform);
2803
Bram Moolenaar734a8672019-12-02 22:49:38 +01002804 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 dialogStatus = -1;
2806 for (;;)
2807 {
2808 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2809 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2810 break;
2811 }
2812
2813 vim_free(buttons);
2814
2815 if (textfield != NULL)
2816 {
2817 p = (char_u *)XmTextGetString(dialogtextfield);
2818 if (p == NULL || dialogStatus < 0)
2819 *textfield = NUL;
2820 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002821 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002822 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 }
2824
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002825 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 XtDestroyWidget(dialogform);
2827
2828 return dialogStatus;
2829}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002830#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832#if defined(FEAT_TOOLBAR) || defined(PROTO)
2833 void
2834gui_mch_show_toolbar(int showit)
2835{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002836 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837
2838 if (toolBar == (Widget)0)
2839 return;
2840 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2841 if (showit && numChildren > 0)
2842 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002843 // Assume that we want to show the toolbar if p_toolbar contains
2844 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 WidgetList children;
2846
2847 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2848 {
2849 void (*action)(BalloonEval *);
2850 int text = 0;
2851
2852 if (strstr((const char *)p_toolbar, "tooltips"))
2853 action = &gui_mch_enable_beval_area;
2854 else
2855 action = &gui_mch_disable_beval_area;
2856 if (strstr((const char *)p_toolbar, "text"))
2857 text = 1;
2858 else if (strstr((const char *)p_toolbar, "icons"))
2859 text = -1;
2860 if (text != 0)
2861 {
2862 vimmenu_T *toolbar;
2863 vimmenu_T *cur;
2864
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002865 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 if (menu_is_toolbar(toolbar->dname))
2867 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002868 // Assumption: toolbar is NULL if there is no toolbar,
2869 // otherwise it contains the toolbar menu structure.
2870 //
2871 // Assumption: "numChildren" == the number of items in the list
2872 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 if (toolbar)
2874 {
2875 for (cur = toolbar->children; cur; cur = cur->next)
2876 {
2877 Arg args[1];
2878 int n = 0;
2879
Bram Moolenaar734a8672019-12-02 22:49:38 +01002880 // Enable/Disable tooltip (OK to enable while
2881 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 if (cur->tip != NULL)
2883 (*action)(cur->tip);
2884 if (!menu_is_separator(cur->name))
2885 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002886 if (text == 1 || cur->xpm == NULL)
2887 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002889 ++n;
2890 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 if (cur->id != NULL)
2892 {
2893 XtUnmanageChild(cur->id);
2894 XtSetValues(cur->id, args, n);
2895 XtManageChild(cur->id);
2896 }
2897 }
2898 }
2899 }
2900 }
2901 }
2902 gui.toolbar_height = gui_mch_compute_toolbar_height();
2903 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002904#ifdef FEAT_GUI_TABLINE
2905 if (showing_tabline)
2906 {
2907 XtVaSetValues(tabLine,
2908 XmNtopAttachment, XmATTACH_WIDGET,
2909 XmNtopWidget, XtParent(toolBar),
2910 NULL);
2911 XtVaSetValues(textAreaForm,
2912 XmNtopAttachment, XmATTACH_WIDGET,
2913 XmNtopWidget, tabLine,
2914 NULL);
2915 }
2916 else
2917#endif
2918 XtVaSetValues(textAreaForm,
2919 XmNtopAttachment, XmATTACH_WIDGET,
2920 XmNtopWidget, XtParent(toolBar),
2921 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 if (XtIsManaged(menuBar))
2923 XtVaSetValues(XtParent(toolBar),
2924 XmNtopAttachment, XmATTACH_WIDGET,
2925 XmNtopWidget, menuBar,
2926 NULL);
2927 else
2928 XtVaSetValues(XtParent(toolBar),
2929 XmNtopAttachment, XmATTACH_FORM,
2930 NULL);
2931 }
2932 else
2933 {
2934 gui.toolbar_height = 0;
2935 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002936 {
2937#ifdef FEAT_GUI_TABLINE
2938 if (showing_tabline)
2939 {
2940 XtVaSetValues(tabLine,
2941 XmNtopAttachment, XmATTACH_WIDGET,
2942 XmNtopWidget, menuBar,
2943 NULL);
2944 XtVaSetValues(textAreaForm,
2945 XmNtopAttachment, XmATTACH_WIDGET,
2946 XmNtopWidget, tabLine,
2947 NULL);
2948 }
2949 else
2950#endif
2951 XtVaSetValues(textAreaForm,
2952 XmNtopAttachment, XmATTACH_WIDGET,
2953 XmNtopWidget, menuBar,
2954 NULL);
2955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002957 {
2958#ifdef FEAT_GUI_TABLINE
2959 if (showing_tabline)
2960 {
2961 XtVaSetValues(tabLine,
2962 XmNtopAttachment, XmATTACH_FORM,
2963 NULL);
2964 XtVaSetValues(textAreaForm,
2965 XmNtopAttachment, XmATTACH_WIDGET,
2966 XmNtopWidget, tabLine,
2967 NULL);
2968 }
2969 else
2970#endif
2971 XtVaSetValues(textAreaForm,
2972 XmNtopAttachment, XmATTACH_FORM,
2973 NULL);
2974 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975
2976 XtUnmanageChild(XtParent(toolBar));
2977 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00002978 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979}
2980
2981/*
2982 * A toolbar button has been pushed; now reset the input focus
2983 * such that the user can type page up/down etc. and have the
2984 * input go to the editor window, not the button
2985 */
2986 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002987reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988{
2989 if (textArea != NULL)
2990 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
2991}
2992
2993 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002994gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002996 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002997 Dimension height; // total Toolbar height
2998 Dimension whgt; // height of each widget
2999 WidgetList children; // list of toolBar's children
3000 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 int i;
3002
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003003 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003006 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003007 Dimension fst;
3008 Dimension fmh;
3009 Dimension tst;
3010 Dimension tmh;
3011
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003013 XmNshadowThickness, &fst,
3014 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003016 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003018 XmNshadowThickness, &tst,
3019 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 XmNchildren, &children,
3021 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003022 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003023 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 {
3025 whgt = 0;
3026 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3027 if (height < whgt)
3028 height = whgt;
3029 }
3030 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003031#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003032 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003033 if (height < 10)
3034 height = 24;
3035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003037 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038}
3039
Bram Moolenaar7c626922005-02-07 22:01:03 +00003040 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003041motif_get_toolbar_colors(
3042 Pixel *bgp,
3043 Pixel *fgp,
3044 Pixel *bsp,
3045 Pixel *tsp,
3046 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003047{
3048 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003049 XmNbackground, bgp,
3050 XmNforeground, fgp,
3051 XmNbottomShadowColor, bsp,
3052 XmNtopShadowColor, tsp,
3053 XmNhighlightColor, hsp,
3054 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003055}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056#endif
3057
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003058#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3059/*
3060 * Show or hide the tabline.
3061 */
3062 void
3063gui_mch_show_tabline(int showit)
3064{
3065 if (tabLine == (Widget)0)
3066 return;
3067
3068 if (!showit != !showing_tabline)
3069 {
3070 if (showit)
3071 {
3072 XtManageChild(tabLine);
3073 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003074 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3075 XtUnmanageChild(XtNameToWidget(tabLine,
3076 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003077#ifdef FEAT_MENU
3078# ifdef FEAT_TOOLBAR
3079 if (XtIsManaged(XtParent(toolBar)))
3080 XtVaSetValues(tabLine,
3081 XmNtopAttachment, XmATTACH_WIDGET,
3082 XmNtopWidget, XtParent(toolBar), NULL);
3083 else
3084# endif
3085 if (XtIsManaged(menuBar))
3086 XtVaSetValues(tabLine,
3087 XmNtopAttachment, XmATTACH_WIDGET,
3088 XmNtopWidget, menuBar, NULL);
3089 else
3090#endif
3091 XtVaSetValues(tabLine,
3092 XmNtopAttachment, XmATTACH_FORM, NULL);
3093 XtVaSetValues(textAreaForm,
3094 XmNtopAttachment, XmATTACH_WIDGET,
3095 XmNtopWidget, tabLine,
3096 NULL);
3097 }
3098 else
3099 {
3100 XtUnmanageChild(tabLine);
3101#ifdef FEAT_MENU
3102# ifdef FEAT_TOOLBAR
3103 if (XtIsManaged(XtParent(toolBar)))
3104 XtVaSetValues(textAreaForm,
3105 XmNtopAttachment, XmATTACH_WIDGET,
3106 XmNtopWidget, XtParent(toolBar), NULL);
3107 else
3108# endif
3109 if (XtIsManaged(menuBar))
3110 XtVaSetValues(textAreaForm,
3111 XmNtopAttachment, XmATTACH_WIDGET,
3112 XmNtopWidget, menuBar, NULL);
3113 else
3114#endif
3115 XtVaSetValues(textAreaForm,
3116 XmNtopAttachment, XmATTACH_FORM, NULL);
3117 }
3118 showing_tabline = showit;
3119 }
3120}
3121
3122/*
3123 * Return TRUE when tabline is displayed.
3124 */
3125 int
3126gui_mch_showing_tabline(void)
3127{
3128 return tabLine != (Widget)0 && showing_tabline;
3129}
3130
3131/*
3132 * Update the labels of the tabline.
3133 */
3134 void
3135gui_mch_update_tabline(void)
3136{
3137 tabpage_T *tp;
3138 int nr = 1, n;
3139 Arg args[10];
3140 int curtabidx = 0, currentpage;
3141 Widget tab;
3142 XmNotebookPageInfo page_info;
3143 XmNotebookPageStatus page_status;
3144 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003145 XmString label_str;
3146 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003147 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003148
3149 if (tabLine == (Widget)0)
3150 return;
3151
Bram Moolenaar734a8672019-12-02 22:49:38 +01003152 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003153 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3154 {
3155 if (tp == curtab)
3156 curtabidx = nr;
3157
3158 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3159 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003160 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003161 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003162 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003163 n = 0;
3164 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3165 XtSetArg(args[n], XmNtraversalOn, False); n++;
3166 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3167 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3168 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3169 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3170 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003171 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3172 NULL);
3173 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003174 }
3175 else
3176 tab = page_info.major_tab_widget;
3177
3178 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003179
3180 /*
3181 * Change the label text only if it is different
3182 */
3183 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3184 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3185 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003186 get_tabline_label(tp, FALSE);
3187 if (STRCMP(label_cstr, NameBuff) != 0)
3188 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003189 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3190 NameBuff, STRLEN(NameBuff) + 1, NULL);
3191 /*
3192 * Force a resize of the tab label button
3193 */
3194 XtUnmanageChild(tab);
3195 XtManageChild(tab);
3196 }
3197 XtFree(label_cstr);
3198 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003199 }
3200
3201 tab_count = nr - 1;
3202
3203 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3204
Bram Moolenaar734a8672019-12-02 22:49:38 +01003205 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003206 while (nr <= last_page)
3207 {
3208 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3209 && page_info.page_number == nr
3210 && page_info.major_tab_widget != (Widget)0)
3211 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003212 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3213 if (beval != NULL)
3214 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003215 XtUnmanageChild(page_info.major_tab_widget);
3216 XtDestroyWidget(page_info.major_tab_widget);
3217 }
3218 nr++;
3219 }
3220
3221 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3222
3223 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3224 if (currentpage != curtabidx)
3225 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3226}
3227
3228/*
3229 * Set the current tab to "nr". First tab is 1.
3230 */
3231 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003232gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003233{
3234 int currentpage;
3235
3236 if (tabLine == (Widget)0)
3237 return;
3238
3239 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3240 if (currentpage != nr)
3241 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3242}
3243#endif
3244
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245/*
3246 * Set the colors of Widget "id" to the menu colors.
3247 */
3248 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003249gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250{
3251 if (gui.menu_bg_pixel != INVALCOLOR)
3252#if (XmVersion >= 1002)
3253 XmChangeColor(id, gui.menu_bg_pixel);
3254#else
3255 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3256#endif
3257 if (gui.menu_fg_pixel != INVALCOLOR)
3258 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3259}
3260
3261/*
3262 * Set the colors of Widget "id" to the scrollbar colors.
3263 */
3264 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003265gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266{
3267 if (gui.scroll_bg_pixel != INVALCOLOR)
3268#if (XmVersion >= 1002)
3269 XmChangeColor(id, gui.scroll_bg_pixel);
3270#else
3271 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3272#endif
3273 if (gui.scroll_fg_pixel != INVALCOLOR)
3274 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3275}
3276
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277/*
3278 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3279 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003280 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003281gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003283#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284#ifdef FONTSET_ALWAYS
3285 if (gui.menu_fontset != NOFONTSET)
3286 {
3287 XmFontList fl;
3288
3289 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3290 if (fl != NULL)
3291 {
3292 if (XtIsManaged(id))
3293 {
3294 XtUnmanageChild(id);
3295 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003296 // We should force the widget to recalculate its
3297 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 XtManageChild(id);
3299 }
3300 else
3301 XtVaSetValues(id, XmNfontList, fl, NULL);
3302 XmFontListFree(fl);
3303 }
3304 }
3305#else
3306 if (gui.menu_font != NOFONT)
3307 {
3308 XmFontList fl;
3309
3310 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3311 if (fl != NULL)
3312 {
3313 if (XtIsManaged(id))
3314 {
3315 XtUnmanageChild(id);
3316 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003317 // We should force the widget to recalculate its
3318 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 XtManageChild(id);
3320 }
3321 else
3322 XtVaSetValues(id, XmNfontList, fl, NULL);
3323 XmFontListFree(fl);
3324 }
3325 }
3326#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328}
3329
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331/*
3332 * We don't create it twice for the sake of speed.
3333 */
3334
3335typedef struct _SharedFindReplace
3336{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003337 Widget dialog; // the main dialog widget
3338 Widget wword; // 'Exact match' check button
3339 Widget mcase; // 'match case' check button
3340 Widget up; // search direction 'Up' radio button
3341 Widget down; // search direction 'Down' radio button
3342 Widget what; // 'Find what' entry text widget
3343 Widget with; // 'Replace with' entry text widget
3344 Widget find; // 'Find Next' action button
3345 Widget replace; // 'Replace With' action button
3346 Widget all; // 'Replace All' action button
3347 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349 Widget cancel;
3350} SharedFindReplace;
3351
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003352static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3353static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003356find_replace_destroy_callback(
3357 Widget w UNUSED,
3358 XtPointer client_data,
3359 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360{
3361 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3362
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003363 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003364 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 cd->dialog = (Widget)0;
3366}
3367
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003369find_replace_dismiss_callback(
3370 Widget w UNUSED,
3371 XtPointer client_data,
3372 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373{
3374 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3375
3376 if (cd != NULL)
3377 XtUnmanageChild(cd->dialog);
3378}
3379
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003381entry_activate_callback(
3382 Widget w UNUSED,
3383 XtPointer client_data,
3384 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385{
3386 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3387}
3388
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003390find_replace_callback(
3391 Widget w UNUSED,
3392 XtPointer client_data,
3393 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003394{
3395 long_u flags = (long_u)client_data;
3396 char *find_text, *repl_text;
3397 Boolean direction_down = TRUE;
3398 Boolean wword;
3399 Boolean mcase;
3400 SharedFindReplace *sfr;
3401
3402 if (flags == FRD_UNDO)
3403 {
3404 char_u *save_cpo = p_cpo;
3405
Bram Moolenaar734a8672019-12-02 22:49:38 +01003406 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003407 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 u_undo(1);
3409 p_cpo = save_cpo;
3410 gui_update_screen();
3411 return;
3412 }
3413
Bram Moolenaar734a8672019-12-02 22:49:38 +01003414 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415 if (flags == FRD_FINDNEXT)
3416 {
3417 repl_text = NULL;
3418 sfr = &find_widgets;
3419 }
3420 else
3421 {
3422 repl_text = XmTextFieldGetString(repl_widgets.with);
3423 sfr = &repl_widgets;
3424 }
3425 find_text = XmTextFieldGetString(sfr->what);
3426 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3427 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3428 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3429 if (wword)
3430 flags |= FRD_WHOLE_WORD;
3431 if (mcase)
3432 flags |= FRD_MATCH_CASE;
3433
3434 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3435 direction_down);
3436
3437 if (find_text != NULL)
3438 XtFree(find_text);
3439 if (repl_text != NULL)
3440 XtFree(repl_text);
3441}
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003444find_replace_keypress(
3445 Widget w UNUSED,
3446 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003447 XKeyEvent *event,
3448 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449{
3450 KeySym keysym;
3451
3452 if (frdp == NULL)
3453 return;
3454
3455 keysym = XLookupKeysym(event, 0);
3456
Bram Moolenaar734a8672019-12-02 22:49:38 +01003457 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 if (keysym == XK_Escape)
3459 XtUnmanageChild(frdp->dialog);
3460}
3461
3462 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003463set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003464{
3465 XmString str;
3466 char_u *p, *next;
3467 KeySym mnemonic = NUL;
3468
3469 if (!w)
3470 return;
3471
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003472 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003473 if (p == NULL)
3474 return;
3475 for (next = p; *next; ++next)
3476 {
3477 if (*next == DLG_HOTKEY_CHAR)
3478 {
3479 int len = STRLEN(next);
3480
3481 if (len > 0)
3482 {
3483 mch_memmove(next, next + 1, len);
3484 mnemonic = next[0];
3485 }
3486 }
3487 }
3488
3489 str = XmStringCreateSimple((char *)p);
3490 vim_free(p);
3491 if (str)
3492 {
3493 XtVaSetValues(w,
3494 XmNlabelString, str,
3495 XmNmnemonic, mnemonic,
3496 NULL);
3497 XmStringFree(str);
3498 }
3499 gui_motif_menu_fontlist(w);
3500}
3501
3502 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003503find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504{
3505 SharedFindReplace *frdp;
3506 Widget separator;
3507 Widget input_form;
3508 Widget button_form;
3509 Widget toggle_form;
3510 Widget frame;
3511 XmString str;
3512 int n;
3513 Arg args[6];
3514 int wword = FALSE;
3515 int mcase = !p_ic;
3516 Dimension width;
3517 Dimension widest;
3518 char_u *entry_text;
3519
3520 frdp = do_replace ? &repl_widgets : &find_widgets;
3521
Bram Moolenaar734a8672019-12-02 22:49:38 +01003522 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3524
Bram Moolenaar734a8672019-12-02 22:49:38 +01003525 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526 if (frdp->dialog)
3527 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003528 gui_motif_synch_fonts();
3529
Bram Moolenaar734a8672019-12-02 22:49:38 +01003530 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531 if (XtIsManaged(frdp->dialog))
3532 XMapRaised(XtDisplay(frdp->dialog),
3533 XtWindow(XtParent(frdp->dialog)));
3534 else
3535 XtManageChild(frdp->dialog);
3536 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3537 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3538
3539 if (entry_text != NULL)
3540 XmTextFieldSetString(frdp->what, (char *)entry_text);
3541 vim_free(entry_text);
3542
3543 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3544 return;
3545 }
3546
Bram Moolenaar734a8672019-12-02 22:49:38 +01003547 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548 if (do_replace)
3549 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3550 else
3551 str = XmStringCreateSimple(_("VIM - Search..."));
3552
3553 n = 0;
3554 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3555 XtSetArg(args[n], XmNnoResize, True); n++;
3556 XtSetArg(args[n], XmNdialogTitle, str); n++;
3557
3558 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3559 XmStringFree(str);
3560 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3561 find_replace_destroy_callback, frdp);
3562
3563 button_form = XtVaCreateWidget("buttonForm",
3564 xmFormWidgetClass, frdp->dialog,
3565 XmNrightAttachment, XmATTACH_FORM,
3566 XmNrightOffset, 4,
3567 XmNtopAttachment, XmATTACH_FORM,
3568 XmNtopOffset, 4,
3569 XmNbottomAttachment, XmATTACH_FORM,
3570 XmNbottomOffset, 4,
3571 NULL);
3572
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 frdp->find = XtVaCreateManagedWidget("findButton",
3574 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575 XmNsensitive, True,
3576 XmNtopAttachment, XmATTACH_FORM,
3577 XmNleftAttachment, XmATTACH_FORM,
3578 XmNrightAttachment, XmATTACH_FORM,
3579 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003580 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581
3582 XtAddCallback(frdp->find, XmNactivateCallback,
3583 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003584 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585
3586 if (do_replace)
3587 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3589 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 XmNtopAttachment, XmATTACH_WIDGET,
3591 XmNtopWidget, frdp->find,
3592 XmNleftAttachment, XmATTACH_FORM,
3593 XmNrightAttachment, XmATTACH_FORM,
3594 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003595 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 XtAddCallback(frdp->replace, XmNactivateCallback,
3597 find_replace_callback, (XtPointer)FRD_REPLACE);
3598
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3600 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 XmNtopAttachment, XmATTACH_WIDGET,
3602 XmNtopWidget, frdp->replace,
3603 XmNleftAttachment, XmATTACH_FORM,
3604 XmNrightAttachment, XmATTACH_FORM,
3605 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003606 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 XtAddCallback(frdp->all, XmNactivateCallback,
3608 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3609
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 frdp->undo = XtVaCreateManagedWidget("undoButton",
3611 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003612 XmNtopAttachment, XmATTACH_WIDGET,
3613 XmNtopWidget, frdp->all,
3614 XmNleftAttachment, XmATTACH_FORM,
3615 XmNrightAttachment, XmATTACH_FORM,
3616 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003617 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 XtAddCallback(frdp->undo, XmNactivateCallback,
3619 find_replace_callback, (XtPointer)FRD_UNDO);
3620 }
3621
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3623 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624 XmNleftAttachment, XmATTACH_FORM,
3625 XmNrightAttachment, XmATTACH_FORM,
3626 XmNbottomAttachment, XmATTACH_FORM,
3627 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003628 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 XtAddCallback(frdp->cancel, XmNactivateCallback,
3630 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003631 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632
3633 XtManageChild(button_form);
3634
3635 n = 0;
3636 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3637 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3638 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3639 XtSetArg(args[n], XmNrightOffset, 4); n++;
3640 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3641 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3642 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3643 XtManageChild(separator);
3644
3645 input_form = XtVaCreateWidget("inputForm",
3646 xmFormWidgetClass, frdp->dialog,
3647 XmNleftAttachment, XmATTACH_FORM,
3648 XmNleftOffset, 4,
3649 XmNrightAttachment, XmATTACH_WIDGET,
3650 XmNrightWidget, separator,
3651 XmNrightOffset, 4,
3652 XmNtopAttachment, XmATTACH_FORM,
3653 XmNtopOffset, 4,
3654 NULL);
3655
3656 {
3657 Widget label_what;
3658 Widget label_with = (Widget)0;
3659
3660 str = XmStringCreateSimple(_("Find what:"));
3661 label_what = XtVaCreateManagedWidget("whatLabel",
3662 xmLabelGadgetClass, input_form,
3663 XmNlabelString, str,
3664 XmNleftAttachment, XmATTACH_FORM,
3665 XmNtopAttachment, XmATTACH_FORM,
3666 XmNtopOffset, 4,
3667 NULL);
3668 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003669 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670
3671 frdp->what = XtVaCreateManagedWidget("whatText",
3672 xmTextFieldWidgetClass, input_form,
3673 XmNtopAttachment, XmATTACH_FORM,
3674 XmNrightAttachment, XmATTACH_FORM,
3675 XmNleftAttachment, XmATTACH_FORM,
3676 NULL);
3677
3678 if (do_replace)
3679 {
3680 frdp->with = XtVaCreateManagedWidget("withText",
3681 xmTextFieldWidgetClass, input_form,
3682 XmNtopAttachment, XmATTACH_WIDGET,
3683 XmNtopWidget, frdp->what,
3684 XmNtopOffset, 4,
3685 XmNleftAttachment, XmATTACH_FORM,
3686 XmNrightAttachment, XmATTACH_FORM,
3687 XmNbottomAttachment, XmATTACH_FORM,
3688 NULL);
3689
3690 XtAddCallback(frdp->with, XmNactivateCallback,
3691 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3692
3693 str = XmStringCreateSimple(_("Replace with:"));
3694 label_with = XtVaCreateManagedWidget("withLabel",
3695 xmLabelGadgetClass, input_form,
3696 XmNlabelString, str,
3697 XmNleftAttachment, XmATTACH_FORM,
3698 XmNtopAttachment, XmATTACH_WIDGET,
3699 XmNtopWidget, frdp->what,
3700 XmNtopOffset, 4,
3701 XmNbottomAttachment, XmATTACH_FORM,
3702 NULL);
3703 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003704 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705
3706 /*
3707 * Make the entry activation only change the input focus onto the
3708 * with item.
3709 */
3710 XtAddCallback(frdp->what, XmNactivateCallback,
3711 entry_activate_callback, frdp->with);
3712 XtAddEventHandler(frdp->with, KeyPressMask, False,
3713 (XtEventHandler)find_replace_keypress,
3714 (XtPointer) frdp);
3715
3716 }
3717 else
3718 {
3719 /*
3720 * Make the entry activation do the search.
3721 */
3722 XtAddCallback(frdp->what, XmNactivateCallback,
3723 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3724 }
3725 XtAddEventHandler(frdp->what, KeyPressMask, False,
3726 (XtEventHandler)find_replace_keypress,
3727 (XtPointer)frdp);
3728
Bram Moolenaar734a8672019-12-02 22:49:38 +01003729 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730 n = 0;
3731 XtSetArg(args[n], XmNwidth, &width); n++;
3732 XtGetValues(label_what, args, n);
3733 widest = width;
3734 if (do_replace)
3735 {
3736 XtGetValues(label_with, args, n);
3737 if (width > widest)
3738 widest = width;
3739 }
3740
3741 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3742 if (do_replace)
3743 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3744
3745 }
3746
3747 XtManageChild(input_form);
3748
3749 {
3750 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003751 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752
3753 frame = XtVaCreateWidget("directionFrame",
3754 xmFrameWidgetClass, frdp->dialog,
3755 XmNtopAttachment, XmATTACH_WIDGET,
3756 XmNtopWidget, input_form,
3757 XmNtopOffset, 4,
3758 XmNbottomAttachment, XmATTACH_FORM,
3759 XmNbottomOffset, 4,
3760 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3761 XmNrightWidget, input_form,
3762 NULL);
3763
3764 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003765 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 xmLabelGadgetClass, frame,
3767 XmNlabelString, str,
3768 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3769 XmNchildType, XmFRAME_TITLE_CHILD,
3770 NULL);
3771 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003772 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773
3774 radio_box = XmCreateRadioBox(frame, "radioBox",
3775 (ArgList)NULL, 0);
3776
3777 str = XmStringCreateSimple( _("Up"));
3778 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3779 xmToggleButtonGadgetClass, radio_box,
3780 XmNlabelString, str,
3781 XmNset, False,
3782 NULL);
3783 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003784 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785
3786 str = XmStringCreateSimple(_("Down"));
3787 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3788 xmToggleButtonGadgetClass, radio_box,
3789 XmNlabelString, str,
3790 XmNset, True,
3791 NULL);
3792 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003793 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794
3795 XtManageChild(radio_box);
3796 XtManageChild(frame);
3797 }
3798
3799 toggle_form = XtVaCreateWidget("toggleForm",
3800 xmFormWidgetClass, frdp->dialog,
3801 XmNleftAttachment, XmATTACH_FORM,
3802 XmNleftOffset, 4,
3803 XmNrightAttachment, XmATTACH_WIDGET,
3804 XmNrightWidget, frame,
3805 XmNrightOffset, 4,
3806 XmNtopAttachment, XmATTACH_WIDGET,
3807 XmNtopWidget, input_form,
3808 XmNtopOffset, 4,
3809 XmNbottomAttachment, XmATTACH_FORM,
3810 XmNbottomOffset, 4,
3811 NULL);
3812
3813 str = XmStringCreateSimple(_("Match whole word only"));
3814 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3815 xmToggleButtonGadgetClass, toggle_form,
3816 XmNlabelString, str,
3817 XmNtopAttachment, XmATTACH_FORM,
3818 XmNtopOffset, 4,
3819 XmNleftAttachment, XmATTACH_FORM,
3820 XmNleftOffset, 4,
3821 XmNset, wword,
3822 NULL);
3823 XmStringFree(str);
3824
3825 str = XmStringCreateSimple(_("Match case"));
3826 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3827 xmToggleButtonGadgetClass, toggle_form,
3828 XmNlabelString, str,
3829 XmNleftAttachment, XmATTACH_FORM,
3830 XmNleftOffset, 4,
3831 XmNtopAttachment, XmATTACH_WIDGET,
3832 XmNtopWidget, frdp->wword,
3833 XmNtopOffset, 4,
3834 XmNset, mcase,
3835 NULL);
3836 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003837 gui_motif_menu_fontlist(frdp->wword);
3838 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839
3840 XtManageChild(toggle_form);
3841
3842 if (entry_text != NULL)
3843 XmTextFieldSetString(frdp->what, (char *)entry_text);
3844 vim_free(entry_text);
3845
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003846 gui_motif_synch_fonts();
3847
3848 manage_centered(frdp->dialog);
3849 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3851}
3852
3853 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003854gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855{
3856 if (!gui.in_use)
3857 return;
3858
3859 find_replace_dialog_create(eap->arg, FALSE);
3860}
3861
3862
3863 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003864gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865{
3866 if (!gui.in_use)
3867 return;
3868
3869 find_replace_dialog_create(eap->arg, TRUE);
3870}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003871
3872/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00003873 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003874 * main text font used. Those are in esp. the find/replace dialogs.
3875 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003876 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003877 */
3878 void
3879gui_motif_synch_fonts(void)
3880{
3881 SharedFindReplace *frdp;
3882 int do_replace;
3883 XFontStruct *font;
3884 XmFontList font_list;
3885
Bram Moolenaar734a8672019-12-02 22:49:38 +01003886 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3887 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003888 font = (XFontStruct *)gui.norm_font;
3889 if (font == NULL)
3890 return;
3891
3892 font_list = gui_motif_create_fontlist(font);
3893
Bram Moolenaar734a8672019-12-02 22:49:38 +01003894 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003895 for (do_replace = 0; do_replace <= 1; ++do_replace)
3896 {
3897 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3898 if (frdp->dialog)
3899 {
3900 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
3901 if (do_replace)
3902 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
3903 }
3904 }
3905
3906 XmFontListFree(font_list);
3907}