blob: b25b99186d25d02fb88c79f93e902ecdae64b799 [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]
1698 ? gui.scrollbar_width : 0,
1699 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];
1791 int n;
1792
1793 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 XtSetArg(args[n], XmNminimum, 0); n++;
1795 XtSetArg(args[n], XmNorientation,
1796 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1797
1798 switch (sb->type)
1799 {
1800 case SBAR_LEFT:
1801 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1802 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1803 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1804 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++;
1810 break;
1811
1812 case SBAR_BOTTOM:
1813 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1814 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1815 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1816 break;
1817 }
1818
1819 sb->id = XtCreateWidget("scrollBar",
1820 xmScrollBarWidgetClass, textAreaForm, args, n);
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001821 if (sb->id == (Widget)0)
1822 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823
Yegappan Lakshmanan7f8b2552023-01-08 13:44:24 +00001824 gui_mch_set_scrollbar_colors(sb);
1825 XtAddCallback(sb->id, XmNvalueChangedCallback,
1826 scroll_cb, (XtPointer)sb->ident);
1827 XtAddCallback(sb->id, XmNdragCallback,
1828 scroll_cb, (XtPointer)sb->ident);
1829 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 (XtPointer)0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831}
1832
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001834gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835{
1836 if (sb->id != (Widget)0)
1837 XtDestroyWidget(sb->id);
1838}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839
1840 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001841gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842{
1843 if (sb->id != (Widget)0)
1844 {
1845 if (gui.scroll_bg_pixel != INVALCOLOR)
1846 {
1847#if (XmVersion>=1002)
Bram Moolenaare8504392022-03-13 14:45:03 +00001848 // This should not only set the through color but also adjust
1849 // related colors, such as shadows.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 XmChangeColor(sb->id, gui.scroll_bg_pixel);
Bram Moolenaare8504392022-03-13 14:45:03 +00001851#endif
1852
1853 // Set the through color directly, in case XmChangeColor() decided
1854 // to change it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 XtVaSetValues(sb->id,
1856 XmNtroughColor, gui.scroll_bg_pixel,
1857 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 }
1859
1860 if (gui.scroll_fg_pixel != INVALCOLOR)
1861 XtVaSetValues(sb->id,
1862 XmNforeground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 XmNbackground, gui.scroll_fg_pixel,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 NULL);
1865 }
1866
Bram Moolenaar734a8672019-12-02 22:49:38 +01001867 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1869 gui_motif_scroll_colors(textAreaForm);
1870}
1871
1872/*
1873 * Miscellaneous stuff:
1874 */
1875
1876 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001877gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878{
1879 return(XtWindow(textArea));
1880}
1881
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001882/*
1883 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1884 * When one is found, simulate a button press on that widget and give it the
1885 * keyboard focus. If the mnemonic is on a label, look in the userData field
1886 * of the label to see if it points to another widget, and give that the focus.
1887 */
1888 static void
1889do_mnemonic(Widget w, unsigned int keycode)
1890{
1891 WidgetList children;
1892 int numChildren, i;
1893 Boolean isMenu;
1894 KeySym mnemonic = '\0';
1895 char mneString[2];
1896 Widget userData;
1897 unsigned char rowColType;
1898
1899 if (XtIsComposite(w))
1900 {
1901 if (XtClass(w) == xmRowColumnWidgetClass)
1902 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001903 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001904 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1905 }
1906 else
1907 isMenu = False;
1908 if (!isMenu)
1909 {
1910 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001911 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001912 for (i = 0; i < numChildren; i++)
1913 do_mnemonic(children[i], keycode);
1914 }
1915 }
1916 else
1917 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001918 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001919 if (mnemonic != '\0')
1920 {
1921 mneString[0] = mnemonic;
1922 mneString[1] = '\0';
1923 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1924 XStringToKeysym(mneString)) == keycode)
1925 {
1926 if (XtClass(w) == xmLabelWidgetClass
1927 || XtClass(w) == xmLabelGadgetClass)
1928 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001929 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001930 if (userData != NULL && XtIsWidget(userData))
1931 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1932 }
1933 else
1934 {
1935 XKeyPressedEvent keyEvent;
1936
1937 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1938
Bram Moolenaara80faa82020-04-12 19:37:17 +02001939 CLEAR_FIELD(keyEvent);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001940 keyEvent.type = KeyPress;
1941 keyEvent.serial = 1;
1942 keyEvent.send_event = True;
1943 keyEvent.display = XtDisplay(w);
1944 keyEvent.window = XtWindow(w);
1945 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1946 NULL, 0);
1947 }
1948 }
1949 }
1950 }
1951}
1952
1953/*
1954 * Callback routine for dialog mnemonic processing.
1955 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001956 static void
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02001957mnemonic_event(
1958 Widget w,
1959 XtPointer call_data UNUSED,
1960 XKeyEvent *event,
1961 Boolean *b UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001962{
1963 do_mnemonic(w, event->keycode);
1964}
1965
1966
1967/*
1968 * Search the widget tree under w for widgets with mnemonics. When found, add
1969 * a passive grab to the dialog widget for the mnemonic character, thus
1970 * directing mnemonic events to the dialog widget.
1971 */
1972 static void
1973add_mnemonic_grabs(Widget dialog, Widget w)
1974{
1975 char mneString[2];
1976 WidgetList children;
1977 int numChildren, i;
1978 Boolean isMenu;
1979 KeySym mnemonic = '\0';
1980 unsigned char rowColType;
1981
1982 if (XtIsComposite(w))
1983 {
1984 if (XtClass(w) == xmRowColumnWidgetClass)
1985 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001986 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001987 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1988 }
1989 else
1990 isMenu = False;
1991 if (!isMenu)
1992 {
1993 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001994 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001995 for (i = 0; i < numChildren; i++)
1996 add_mnemonic_grabs(dialog, children[i]);
1997 }
1998 }
1999 else
2000 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002001 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002002 if (mnemonic != '\0')
2003 {
2004 mneString[0] = mnemonic;
2005 mneString[1] = '\0';
2006 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2007 XStringToKeysym(mneString)),
2008 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2009 }
2010 }
2011}
2012
2013/*
2014 * Add a handler for mnemonics in a dialog. Motif itself only handles
2015 * mnemonics in menus. Mnemonics added or changed after this call will be
2016 * ignored.
2017 *
2018 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2019 * the appropriate label and set the XmNuserData resource of the label to the
2020 * widget to get the focus when the mnemonic is typed.
2021 */
2022 static void
2023activate_dialog_mnemonics(Widget dialog)
2024{
2025 if (!dialog)
2026 return;
2027
2028 XtAddEventHandler(dialog, KeyPressMask, False,
2029 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2030 add_mnemonic_grabs(dialog, dialog);
2031}
2032
2033/*
2034 * Removes the event handler and key-grabs for dialog mnemonic handling.
2035 */
2036 static void
2037suppress_dialog_mnemonics(Widget dialog)
2038{
2039 if (!dialog)
2040 return;
2041
2042 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2043 XtRemoveEventHandler(dialog, KeyPressMask, False,
2044 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2045}
2046
2047#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002048/*
2049 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2050 */
2051 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002052set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002053{
2054 XmFontList fl;
2055
2056#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002057 if (gui.fontset != NOFONTSET)
2058 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002059 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2060 if (fl != NULL)
2061 {
2062 if (XtIsManaged(id))
2063 {
2064 XtUnmanageChild(id);
2065 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002066 // We should force the widget to recalculate its
2067 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002068 XtManageChild(id);
2069 }
2070 else
2071 XtVaSetValues(id, XmNfontList, fl, NULL);
2072 XmFontListFree(fl);
2073 }
2074 }
2075#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002076 if (gui.norm_font != NOFONT)
2077 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002078 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2079 if (fl != NULL)
2080 {
2081 if (XtIsManaged(id))
2082 {
2083 XtUnmanageChild(id);
2084 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002085 // We should force the widget to recalculate its
2086 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002087 XtManageChild(id);
2088 }
2089 else
2090 XtVaSetValues(id, XmNfontList, fl, NULL);
2091 XmFontListFree(fl);
2092 }
2093 }
2094#endif
2095}
2096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097
2098#if defined(FEAT_BROWSE) || defined(PROTO)
2099
2100/*
2101 * file selector related stuff
2102 */
2103
2104#include <Xm/FileSB.h>
2105#include <Xm/XmStrDefs.h>
2106
2107typedef struct dialog_callback_arg
2108{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002109 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 int id;
2111} dcbarg_T;
2112
2113static Widget dialog_wgt;
2114static char *browse_fname = NULL;
2115static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002116 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002118static void DialogCancelCB(Widget, XtPointer, XtPointer);
2119static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120
2121/*
2122 * This function is used to translate the predefined label text of the
2123 * precomposed dialogs. We do this explicitly to allow:
2124 *
2125 * - usage of gettext for translation, as in all the other places.
2126 *
2127 * - equalize the messages between different GUI implementations as far as
2128 * possible.
2129 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002130 static void
2131set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002133 XmString str;
2134 Widget w;
2135 char_u *p, *next;
2136 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137
2138 w = XtNameToWidget(parent, name);
2139
2140 if (!w)
2141 return;
2142
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002143 p = vim_strsave((char_u *)new_label);
2144 if (p == NULL)
2145 return;
2146 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002148 if (*next == DLG_HOTKEY_CHAR)
2149 {
2150 int len = STRLEN(next);
2151
2152 if (len > 0)
2153 {
2154 mch_memmove(next, next + 1, len);
2155 mnemonic = next[0];
2156 }
2157 }
2158 }
2159
2160 str = XmStringCreate((char *)p, STRING_TAG);
2161 vim_free(p);
2162
2163 if (str != NULL)
2164 {
2165 XtVaSetValues(w,
2166 XmNlabelString, str,
2167 XmNmnemonic, mnemonic,
2168 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 XmStringFree(str);
2170 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002171 gui_motif_menu_fontlist(w);
2172}
2173
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002174 static void
2175set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002176{
2177 Widget w;
2178 w = XtNameToWidget(parent, name);
2179
2180 if (!w)
2181 return;
2182
2183 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184}
2185
2186/*
2187 * Put up a file requester.
2188 * Returns the selected name in allocated memory, or NULL for Cancel.
2189 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002191gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002192 int saving UNUSED, // select file to write
2193 char_u *title, // title for the window
2194 char_u *dflt, // default name
2195 char_u *ext UNUSED, // not used (extension added)
2196 char_u *initdir, // initial directory, NULL for current dir
2197 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198{
2199 char_u dirbuf[MAXPATHL];
2200 char_u dfltbuf[MAXPATHL];
2201 char_u *pattern;
2202 char_u *tofree = NULL;
2203
Bram Moolenaar734a8672019-12-02 22:49:38 +01002204 // There a difference between the resource name and value, Therefore, we
2205 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2206 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002207
2208 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002209
2210 if (initdir == NULL || *initdir == NUL)
2211 {
2212 mch_dirname(dirbuf, MAXPATHL);
2213 initdir = dirbuf;
2214 }
2215
2216 if (dflt == NULL)
2217 dflt = (char_u *)"";
2218 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2219 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002220 // The default selection should be the full path, "dflt" is only the
2221 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 STRCPY(dfltbuf, initdir);
2223 add_pathsep(dfltbuf);
2224 STRCAT(dfltbuf, dflt);
2225 dflt = dfltbuf;
2226 }
2227
Bram Moolenaar734a8672019-12-02 22:49:38 +01002228 // Can only use one pattern for a file name. Get the first pattern out of
2229 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 if (filter == NULL)
2231 pattern = (char_u *)"";
2232 else
2233 {
2234 char_u *s, *p;
2235
2236 s = filter;
2237 for (p = filter; *p != NUL; ++p)
2238 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002239 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002241 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 break;
2243 }
2244 pattern = vim_strnsave(s, p - s);
2245 tofree = pattern;
2246 if (pattern == NULL)
2247 pattern = (char_u *)"";
2248 }
2249
2250 XtVaSetValues(dialog_wgt,
2251 XtVaTypedArg,
2252 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2253 XtVaTypedArg,
2254 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2255 XtVaTypedArg,
2256 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2257 XtVaTypedArg,
2258 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2259 NULL);
2260
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002261 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2262 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2264 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002265 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002267 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2269
Bram Moolenaar734a8672019-12-02 22:49:38 +01002270 // This is to save us from silly external settings using not fixed with
2271 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002272 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2273 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2274
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 gui_motif_menu_colors(dialog_wgt);
2276 if (gui.scroll_bg_pixel != INVALCOLOR)
2277 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2278
2279 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2280 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002281 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2283 (unsigned char)XmDIALOG_HELP_BUTTON));
2284
2285 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002286 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287
Bram Moolenaar734a8672019-12-02 22:49:38 +01002288 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 do
2290 {
2291 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2292 (XtInputMask)XtIMAll);
2293 } while (XtIsManaged(dialog_wgt));
2294
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002295 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 XtDestroyWidget(dialog_wgt);
2297 vim_free(tofree);
2298
2299 if (browse_fname == NULL)
2300 return NULL;
2301 return vim_strsave((char_u *)browse_fname);
2302}
2303
2304/*
2305 * The code below was originally taken from
2306 * /usr/examples/motif/xmsamplers/xmeditor.c
2307 * on Digital Unix 4.0d, but heavily modified.
2308 */
2309
2310/*
2311 * Process callback from Dialog cancel actions.
2312 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002314DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002315 Widget w UNUSED, // widget id
2316 XtPointer client_data UNUSED, // data from application
2317 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318{
2319 if (browse_fname != NULL)
2320 {
2321 XtFree(browse_fname);
2322 browse_fname = NULL;
2323 }
2324 XtUnmanageChild(dialog_wgt);
2325}
2326
2327/*
2328 * Process callback from Dialog actions.
2329 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002331DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002332 Widget w UNUSED, // widget id
2333 XtPointer client_data UNUSED, // data from application
2334 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335{
2336 XmFileSelectionBoxCallbackStruct *fcb;
2337
2338 if (browse_fname != NULL)
2339 {
2340 XtFree(browse_fname);
2341 browse_fname = NULL;
2342 }
2343 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2344
Bram Moolenaar734a8672019-12-02 22:49:38 +01002345 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2347
Bram Moolenaar734a8672019-12-02 22:49:38 +01002348 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 XtUnmanageChild(dialog_wgt);
2350}
2351
Bram Moolenaar734a8672019-12-02 22:49:38 +01002352#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353
2354#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2355
2356static int dialogStatus;
2357
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358/*
2359 * Callback function for the textfield. When CR is hit this works like
2360 * hitting the "OK" button, ESC like "Cancel".
2361 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002363keyhit_callback(
2364 Widget w,
2365 XtPointer client_data UNUSED,
2366 XEvent *event,
2367 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368{
2369 char buf[2];
2370 KeySym key_sym;
2371
2372 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2373 {
2374 if (*buf == CAR)
2375 dialogStatus = 1;
2376 else if (*buf == ESC)
2377 dialogStatus = 2;
2378 }
2379 if ((key_sym == XK_Left || key_sym == XK_Right)
2380 && !(event->xkey.state & ShiftMask))
2381 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2382}
2383
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002385butproc(
2386 Widget w UNUSED,
2387 XtPointer client_data,
2388 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389{
2390 dialogStatus = (int)(long)client_data + 1;
2391}
2392
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393#ifdef HAVE_XPM
2394
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002396create_pixmap_label(
2397 Widget parent,
2398 String name,
2399 char **data,
2400 ArgList args,
2401 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402{
2403 Widget label;
2404 Display *dsp;
2405 Screen *scr;
2406 int depth;
2407 Pixmap pixmap = 0;
2408 XpmAttributes attr;
2409 Boolean rs;
2410 XpmColorSymbol color[5] =
2411 {
2412 {"none", NULL, 0},
2413 {"iconColor1", NULL, 0},
2414 {"bottomShadowColor", NULL, 0},
2415 {"topShadowColor", NULL, 0},
2416 {"selectColor", NULL, 0}
2417 };
2418
2419 label = XmCreateLabelGadget(parent, name, args, arg);
2420
2421 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002422 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 * no way to get the background color directly from the widget itself.
2424 * In such cases we get it from The Core part of his parent instead.
2425 */
2426 dsp = XtDisplayOfObject(label);
2427 scr = XtScreenOfObject(label);
2428 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2429 ? label : XtParent(label),
2430 XmNdepth, &depth,
2431 XmNbackground, &color[0].pixel,
2432 XmNforeground, &color[1].pixel,
2433 XmNbottomShadowColor, &color[2].pixel,
2434 XmNtopShadowColor, &color[3].pixel,
2435 XmNhighlight, &color[4].pixel,
2436 NULL);
2437
2438 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2439 attr.colorsymbols = color;
2440 attr.numsymbols = 5;
2441 attr.closeness = 65535;
2442 attr.depth = depth;
2443 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2444 data, &pixmap, NULL, &attr);
2445
2446 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2447 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2448 XtVaSetValues(label,
2449 XmNlabelType, XmPIXMAP,
2450 XmNlabelPixmap, pixmap,
2451 NULL);
2452 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2453
2454 return label;
2455}
2456#endif
2457
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002459gui_mch_dialog(
2460 int type UNUSED,
2461 char_u *title,
2462 char_u *message,
2463 char_u *button_names,
2464 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002465 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002466 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467{
2468 char_u *buts;
2469 char_u *p, *next;
2470 XtAppContext app;
2471 XmString label;
2472 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002473 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 Widget dialogform = NULL;
2475 Widget form = NULL;
2476 Widget dialogtextfield = NULL;
2477 Widget *buttons;
2478 Widget sep_form = NULL;
2479 Boolean vertical;
2480 Widget separator = NULL;
2481 int n;
2482 Arg args[6];
2483#ifdef HAVE_XPM
2484 char **icon_data = NULL;
2485 Widget dialogpixmap = NULL;
2486#endif
2487
2488 if (title == NULL)
2489 title = (char_u *)_("Vim dialog");
2490
Bram Moolenaar734a8672019-12-02 22:49:38 +01002491 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 gui_mch_mousehide(FALSE);
2493
2494 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2495
Bram Moolenaar734a8672019-12-02 22:49:38 +01002496 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2498
Bram Moolenaar734a8672019-12-02 22:49:38 +01002499 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 label = XmStringCreateSimple((char *)title);
2501 if (label == NULL)
2502 return -1;
2503 XtVaSetValues(dialogform,
2504 XmNdialogTitle, label,
2505 XmNhorizontalSpacing, 4,
2506 XmNverticalSpacing, vertical ? 0 : 4,
2507 NULL);
2508 XmStringFree(label);
2509
Bram Moolenaar734a8672019-12-02 22:49:38 +01002510 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 buts = vim_strsave(button_names);
2512 if (buts == NULL)
2513 return -1;
2514
Bram Moolenaar734a8672019-12-02 22:49:38 +01002515 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 butcount = 1;
2517 for (p = buts; *p; ++p)
2518 if (*p == DLG_BUTTON_SEP)
2519 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002520 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 if (buttons == NULL)
2522 {
2523 vim_free(buts);
2524 return -1;
2525 }
2526
2527 /*
2528 * Create the buttons.
2529 */
2530 sep_form = (Widget) 0;
2531 p = buts;
2532 for (butcount = 0; *p; ++butcount)
2533 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002534 KeySym mnemonic = NUL;
2535
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 for (next = p; *next; ++next)
2537 {
2538 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002539 {
2540 int len = STRLEN(next);
2541
2542 if (len > 0)
2543 {
2544 mch_memmove(next, next + 1, len);
2545 mnemonic = next[0];
2546 }
2547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 if (*next == DLG_BUTTON_SEP)
2549 {
2550 *next++ = NUL;
2551 break;
2552 }
2553 }
2554 label = XmStringCreate(_((char *)p), STRING_TAG);
2555 if (label == NULL)
2556 break;
2557
2558 buttons[butcount] = XtVaCreateManagedWidget("button",
2559 xmPushButtonWidgetClass, dialogform,
2560 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002561 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 XmNbottomAttachment, XmATTACH_FORM,
2563 XmNbottomOffset, 4,
2564 XmNshowAsDefault, butcount == dfltbutton - 1,
2565 XmNdefaultButtonShadowThickness, 1,
2566 NULL);
2567 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002568 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569
Bram Moolenaar734a8672019-12-02 22:49:38 +01002570 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571
2572 if (butcount > 0)
2573 {
2574 if (vertical)
2575 XtVaSetValues(buttons[butcount],
2576 XmNtopWidget, buttons[butcount - 1],
2577 NULL);
2578 else
2579 {
2580 if (*next == NUL)
2581 {
2582 XtVaSetValues(buttons[butcount],
2583 XmNrightAttachment, XmATTACH_FORM,
2584 XmNrightOffset, 4,
2585 NULL);
2586
Bram Moolenaar734a8672019-12-02 22:49:38 +01002587 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 sep_form = XtVaCreateWidget("separatorForm",
2589 xmFormWidgetClass, dialogform,
2590 XmNleftAttachment, XmATTACH_WIDGET,
2591 XmNleftWidget, buttons[butcount - 1],
2592 XmNrightAttachment, XmATTACH_WIDGET,
2593 XmNrightWidget, buttons[butcount],
2594 XmNbottomAttachment, XmATTACH_FORM,
2595 XmNbottomOffset, 4,
2596 NULL);
2597 XtManageChild(sep_form);
2598 }
2599 else
2600 {
2601 XtVaSetValues(buttons[butcount],
2602 XmNleftAttachment, XmATTACH_WIDGET,
2603 XmNleftWidget, buttons[butcount - 1],
2604 NULL);
2605 }
2606 }
2607 }
2608 else if (!vertical)
2609 {
2610 if (*next == NUL)
2611 {
2612 XtVaSetValues(buttons[0],
2613 XmNrightAttachment, XmATTACH_FORM,
2614 XmNrightOffset, 4,
2615 NULL);
2616
Bram Moolenaar734a8672019-12-02 22:49:38 +01002617 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 sep_form = XtVaCreateWidget("separatorForm",
2619 xmFormWidgetClass, dialogform,
2620 XmNleftAttachment, XmATTACH_FORM,
2621 XmNleftOffset, 4,
2622 XmNrightAttachment, XmATTACH_WIDGET,
2623 XmNrightWidget, buttons[0],
2624 XmNbottomAttachment, XmATTACH_FORM,
2625 XmNbottomOffset, 4,
2626 NULL);
2627 XtManageChild(sep_form);
2628 }
2629 else
2630 XtVaSetValues(buttons[0],
2631 XmNleftAttachment, XmATTACH_FORM,
2632 XmNleftOffset, 4,
2633 NULL);
2634 }
2635
2636 XtAddCallback(buttons[butcount], XmNactivateCallback,
2637 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2638 p = next;
2639 }
2640 vim_free(buts);
2641
2642 separator = (Widget) 0;
2643 if (butcount > 0)
2644 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002645 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 n = 0;
2647 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2648 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2649 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2650 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2651 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2652 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2653 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2654 XtManageChild(separator);
2655 }
2656
2657 if (textfield != NULL)
2658 {
2659 dialogtextfield = XtVaCreateWidget("textField",
2660 xmTextFieldWidgetClass, dialogform,
2661 XmNleftAttachment, XmATTACH_FORM,
2662 XmNrightAttachment, XmATTACH_FORM,
2663 NULL);
2664 if (butcount > 0)
2665 XtVaSetValues(dialogtextfield,
2666 XmNbottomAttachment, XmATTACH_WIDGET,
2667 XmNbottomWidget, separator,
2668 NULL);
2669 else
2670 XtVaSetValues(dialogtextfield,
2671 XmNbottomAttachment, XmATTACH_FORM,
2672 NULL);
2673
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002674 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2676 XtManageChild(dialogtextfield);
2677 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2678 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2679 }
2680
Bram Moolenaar734a8672019-12-02 22:49:38 +01002681 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 form = XtVaCreateWidget("separatorForm",
2683 xmFormWidgetClass, dialogform,
2684 XmNleftAttachment, XmATTACH_FORM,
2685 XmNrightAttachment, XmATTACH_FORM,
2686 XmNtopAttachment, XmATTACH_FORM,
2687 NULL);
2688 XtManageChild(form);
2689
2690#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002691 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 switch (type)
2693 {
2694 case VIM_GENERIC:
2695 icon_data = generic_xpm;
2696 break;
2697 case VIM_ERROR:
2698 icon_data = error_xpm;
2699 break;
2700 case VIM_WARNING:
2701 icon_data = alert_xpm;
2702 break;
2703 case VIM_INFO:
2704 icon_data = info_xpm;
2705 break;
2706 case VIM_QUESTION:
2707 icon_data = quest_xpm;
2708 break;
2709 default:
2710 icon_data = generic_xpm;
2711 }
2712
2713 n = 0;
2714 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2715 XtSetArg(args[n], XmNtopOffset, 8); n++;
2716 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2717 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2718 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2719 XtSetArg(args[n], XmNleftOffset, 8); n++;
2720
2721 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2722 icon_data, args, n);
2723 XtManageChild(dialogpixmap);
2724#endif
2725
Bram Moolenaar734a8672019-12-02 22:49:38 +01002726 // Create the dialog message.
2727 // Since LessTif is apparently having problems with the creation of
2728 // properly localized string, we use LtoR here. The symptom is that the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002729 // string is not shown properly in multiple lines as it does in native
Bram Moolenaar734a8672019-12-02 22:49:38 +01002730 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002731 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 if (label == NULL)
2733 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002734 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 xmLabelGadgetClass, form,
2736 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002737 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 XmNtopAttachment, XmATTACH_FORM,
2739 XmNtopOffset, 8,
2740#ifdef HAVE_XPM
2741 XmNleftAttachment, XmATTACH_WIDGET,
2742 XmNleftWidget, dialogpixmap,
2743#else
2744 XmNleftAttachment, XmATTACH_FORM,
2745#endif
2746 XmNleftOffset, 8,
2747 XmNrightAttachment, XmATTACH_FORM,
2748 XmNrightOffset, 8,
2749 XmNbottomAttachment, XmATTACH_FORM,
2750 XmNbottomOffset, 8,
2751 NULL);
2752 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002753 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754
2755 if (textfield != NULL)
2756 {
2757 XtVaSetValues(form,
2758 XmNbottomAttachment, XmATTACH_WIDGET,
2759 XmNbottomWidget, dialogtextfield,
2760 NULL);
2761 }
2762 else
2763 {
2764 if (butcount > 0)
2765 XtVaSetValues(form,
2766 XmNbottomAttachment, XmATTACH_WIDGET,
2767 XmNbottomWidget, separator,
2768 NULL);
2769 else
2770 XtVaSetValues(form,
2771 XmNbottomAttachment, XmATTACH_FORM,
2772 NULL);
2773 }
2774
2775 if (dfltbutton < 1)
2776 dfltbutton = 1;
2777 if (dfltbutton > butcount)
2778 dfltbutton = butcount;
2779 XtVaSetValues(dialogform,
2780 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2781 if (textfield != NULL)
2782 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2783 else
2784 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2785 NULL);
2786
2787 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002788 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789
2790 if (textfield != NULL && *textfield != NUL)
2791 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002792 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 XmTextFieldSetSelection(dialogtextfield,
2794 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2795 XtLastTimestampProcessed(gui.dpy));
2796 XmTextFieldSetCursorPosition(dialogtextfield,
2797 (XmTextPosition)STRLEN(textfield));
2798 }
2799
2800 app = XtWidgetToApplicationContext(dialogform);
2801
Bram Moolenaar734a8672019-12-02 22:49:38 +01002802 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 dialogStatus = -1;
2804 for (;;)
2805 {
2806 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2807 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2808 break;
2809 }
2810
2811 vim_free(buttons);
2812
2813 if (textfield != NULL)
2814 {
2815 p = (char_u *)XmTextGetString(dialogtextfield);
2816 if (p == NULL || dialogStatus < 0)
2817 *textfield = NUL;
2818 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002819 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002820 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 }
2822
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002823 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 XtDestroyWidget(dialogform);
2825
2826 return dialogStatus;
2827}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002828#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#if defined(FEAT_TOOLBAR) || defined(PROTO)
2831 void
2832gui_mch_show_toolbar(int showit)
2833{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002834 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835
2836 if (toolBar == (Widget)0)
2837 return;
2838 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2839 if (showit && numChildren > 0)
2840 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002841 // Assume that we want to show the toolbar if p_toolbar contains
2842 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 WidgetList children;
2844
2845 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2846 {
2847 void (*action)(BalloonEval *);
2848 int text = 0;
2849
2850 if (strstr((const char *)p_toolbar, "tooltips"))
2851 action = &gui_mch_enable_beval_area;
2852 else
2853 action = &gui_mch_disable_beval_area;
2854 if (strstr((const char *)p_toolbar, "text"))
2855 text = 1;
2856 else if (strstr((const char *)p_toolbar, "icons"))
2857 text = -1;
2858 if (text != 0)
2859 {
2860 vimmenu_T *toolbar;
2861 vimmenu_T *cur;
2862
Bram Moolenaar00d253e2020-04-06 22:13:01 +02002863 FOR_ALL_MENUS(toolbar)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 if (menu_is_toolbar(toolbar->dname))
2865 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002866 // Assumption: toolbar is NULL if there is no toolbar,
2867 // otherwise it contains the toolbar menu structure.
2868 //
2869 // Assumption: "numChildren" == the number of items in the list
2870 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 if (toolbar)
2872 {
2873 for (cur = toolbar->children; cur; cur = cur->next)
2874 {
2875 Arg args[1];
2876 int n = 0;
2877
Bram Moolenaar734a8672019-12-02 22:49:38 +01002878 // Enable/Disable tooltip (OK to enable while
2879 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 if (cur->tip != NULL)
2881 (*action)(cur->tip);
2882 if (!menu_is_separator(cur->name))
2883 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002884 if (text == 1 || cur->xpm == NULL)
2885 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002887 ++n;
2888 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 if (cur->id != NULL)
2890 {
2891 XtUnmanageChild(cur->id);
2892 XtSetValues(cur->id, args, n);
2893 XtManageChild(cur->id);
2894 }
2895 }
2896 }
2897 }
2898 }
2899 }
2900 gui.toolbar_height = gui_mch_compute_toolbar_height();
2901 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002902#ifdef FEAT_GUI_TABLINE
2903 if (showing_tabline)
2904 {
2905 XtVaSetValues(tabLine,
2906 XmNtopAttachment, XmATTACH_WIDGET,
2907 XmNtopWidget, XtParent(toolBar),
2908 NULL);
2909 XtVaSetValues(textAreaForm,
2910 XmNtopAttachment, XmATTACH_WIDGET,
2911 XmNtopWidget, tabLine,
2912 NULL);
2913 }
2914 else
2915#endif
2916 XtVaSetValues(textAreaForm,
2917 XmNtopAttachment, XmATTACH_WIDGET,
2918 XmNtopWidget, XtParent(toolBar),
2919 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 if (XtIsManaged(menuBar))
2921 XtVaSetValues(XtParent(toolBar),
2922 XmNtopAttachment, XmATTACH_WIDGET,
2923 XmNtopWidget, menuBar,
2924 NULL);
2925 else
2926 XtVaSetValues(XtParent(toolBar),
2927 XmNtopAttachment, XmATTACH_FORM,
2928 NULL);
2929 }
2930 else
2931 {
2932 gui.toolbar_height = 0;
2933 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002934 {
2935#ifdef FEAT_GUI_TABLINE
2936 if (showing_tabline)
2937 {
2938 XtVaSetValues(tabLine,
2939 XmNtopAttachment, XmATTACH_WIDGET,
2940 XmNtopWidget, menuBar,
2941 NULL);
2942 XtVaSetValues(textAreaForm,
2943 XmNtopAttachment, XmATTACH_WIDGET,
2944 XmNtopWidget, tabLine,
2945 NULL);
2946 }
2947 else
2948#endif
2949 XtVaSetValues(textAreaForm,
2950 XmNtopAttachment, XmATTACH_WIDGET,
2951 XmNtopWidget, menuBar,
2952 NULL);
2953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002955 {
2956#ifdef FEAT_GUI_TABLINE
2957 if (showing_tabline)
2958 {
2959 XtVaSetValues(tabLine,
2960 XmNtopAttachment, XmATTACH_FORM,
2961 NULL);
2962 XtVaSetValues(textAreaForm,
2963 XmNtopAttachment, XmATTACH_WIDGET,
2964 XmNtopWidget, tabLine,
2965 NULL);
2966 }
2967 else
2968#endif
2969 XtVaSetValues(textAreaForm,
2970 XmNtopAttachment, XmATTACH_FORM,
2971 NULL);
2972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973
2974 XtUnmanageChild(XtParent(toolBar));
2975 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00002976 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977}
2978
2979/*
2980 * A toolbar button has been pushed; now reset the input focus
2981 * such that the user can type page up/down etc. and have the
2982 * input go to the editor window, not the button
2983 */
2984 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002985reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986{
2987 if (textArea != NULL)
2988 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
2989}
2990
2991 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002992gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002994 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002995 Dimension height; // total Toolbar height
2996 Dimension whgt; // height of each widget
2997 WidgetList children; // list of toolBar's children
2998 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 int i;
3000
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003001 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003004 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003005 Dimension fst;
3006 Dimension fmh;
3007 Dimension tst;
3008 Dimension tmh;
3009
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003011 XmNshadowThickness, &fst,
3012 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003014 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003016 XmNshadowThickness, &tst,
3017 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 XmNchildren, &children,
3019 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003020 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003021 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 {
3023 whgt = 0;
3024 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3025 if (height < whgt)
3026 height = whgt;
3027 }
3028 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003029#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003030 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003031 if (height < 10)
3032 height = 24;
3033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003035 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036}
3037
Bram Moolenaar7c626922005-02-07 22:01:03 +00003038 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003039motif_get_toolbar_colors(
3040 Pixel *bgp,
3041 Pixel *fgp,
3042 Pixel *bsp,
3043 Pixel *tsp,
3044 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003045{
3046 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003047 XmNbackground, bgp,
3048 XmNforeground, fgp,
3049 XmNbottomShadowColor, bsp,
3050 XmNtopShadowColor, tsp,
3051 XmNhighlightColor, hsp,
3052 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003053}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054#endif
3055
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003056#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3057/*
3058 * Show or hide the tabline.
3059 */
3060 void
3061gui_mch_show_tabline(int showit)
3062{
3063 if (tabLine == (Widget)0)
3064 return;
3065
3066 if (!showit != !showing_tabline)
3067 {
3068 if (showit)
3069 {
3070 XtManageChild(tabLine);
3071 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003072 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3073 XtUnmanageChild(XtNameToWidget(tabLine,
3074 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003075#ifdef FEAT_MENU
3076# ifdef FEAT_TOOLBAR
3077 if (XtIsManaged(XtParent(toolBar)))
3078 XtVaSetValues(tabLine,
3079 XmNtopAttachment, XmATTACH_WIDGET,
3080 XmNtopWidget, XtParent(toolBar), NULL);
3081 else
3082# endif
3083 if (XtIsManaged(menuBar))
3084 XtVaSetValues(tabLine,
3085 XmNtopAttachment, XmATTACH_WIDGET,
3086 XmNtopWidget, menuBar, NULL);
3087 else
3088#endif
3089 XtVaSetValues(tabLine,
3090 XmNtopAttachment, XmATTACH_FORM, NULL);
3091 XtVaSetValues(textAreaForm,
3092 XmNtopAttachment, XmATTACH_WIDGET,
3093 XmNtopWidget, tabLine,
3094 NULL);
3095 }
3096 else
3097 {
3098 XtUnmanageChild(tabLine);
3099#ifdef FEAT_MENU
3100# ifdef FEAT_TOOLBAR
3101 if (XtIsManaged(XtParent(toolBar)))
3102 XtVaSetValues(textAreaForm,
3103 XmNtopAttachment, XmATTACH_WIDGET,
3104 XmNtopWidget, XtParent(toolBar), NULL);
3105 else
3106# endif
3107 if (XtIsManaged(menuBar))
3108 XtVaSetValues(textAreaForm,
3109 XmNtopAttachment, XmATTACH_WIDGET,
3110 XmNtopWidget, menuBar, NULL);
3111 else
3112#endif
3113 XtVaSetValues(textAreaForm,
3114 XmNtopAttachment, XmATTACH_FORM, NULL);
3115 }
3116 showing_tabline = showit;
3117 }
3118}
3119
3120/*
3121 * Return TRUE when tabline is displayed.
3122 */
3123 int
3124gui_mch_showing_tabline(void)
3125{
3126 return tabLine != (Widget)0 && showing_tabline;
3127}
3128
3129/*
3130 * Update the labels of the tabline.
3131 */
3132 void
3133gui_mch_update_tabline(void)
3134{
3135 tabpage_T *tp;
3136 int nr = 1, n;
3137 Arg args[10];
3138 int curtabidx = 0, currentpage;
3139 Widget tab;
3140 XmNotebookPageInfo page_info;
3141 XmNotebookPageStatus page_status;
3142 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003143 XmString label_str;
3144 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003145 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003146
3147 if (tabLine == (Widget)0)
3148 return;
3149
Bram Moolenaar734a8672019-12-02 22:49:38 +01003150 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003151 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3152 {
3153 if (tp == curtab)
3154 curtabidx = nr;
3155
3156 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3157 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003158 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003159 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003160 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003161 n = 0;
3162 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3163 XtSetArg(args[n], XmNtraversalOn, False); n++;
3164 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3165 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3166 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3167 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3168 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003169 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3170 NULL);
3171 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003172 }
3173 else
3174 tab = page_info.major_tab_widget;
3175
3176 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003177
3178 /*
3179 * Change the label text only if it is different
3180 */
3181 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3182 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3183 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003184 get_tabline_label(tp, FALSE);
3185 if (STRCMP(label_cstr, NameBuff) != 0)
3186 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003187 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3188 NameBuff, STRLEN(NameBuff) + 1, NULL);
3189 /*
3190 * Force a resize of the tab label button
3191 */
3192 XtUnmanageChild(tab);
3193 XtManageChild(tab);
3194 }
3195 XtFree(label_cstr);
3196 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003197 }
3198
3199 tab_count = nr - 1;
3200
3201 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3202
Bram Moolenaar734a8672019-12-02 22:49:38 +01003203 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003204 while (nr <= last_page)
3205 {
3206 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3207 && page_info.page_number == nr
3208 && page_info.major_tab_widget != (Widget)0)
3209 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003210 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3211 if (beval != NULL)
3212 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003213 XtUnmanageChild(page_info.major_tab_widget);
3214 XtDestroyWidget(page_info.major_tab_widget);
3215 }
3216 nr++;
3217 }
3218
3219 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3220
3221 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3222 if (currentpage != curtabidx)
3223 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3224}
3225
3226/*
3227 * Set the current tab to "nr". First tab is 1.
3228 */
3229 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003230gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003231{
3232 int currentpage;
3233
3234 if (tabLine == (Widget)0)
3235 return;
3236
3237 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3238 if (currentpage != nr)
3239 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3240}
3241#endif
3242
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243/*
3244 * Set the colors of Widget "id" to the menu colors.
3245 */
3246 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003247gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248{
3249 if (gui.menu_bg_pixel != INVALCOLOR)
3250#if (XmVersion >= 1002)
3251 XmChangeColor(id, gui.menu_bg_pixel);
3252#else
3253 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3254#endif
3255 if (gui.menu_fg_pixel != INVALCOLOR)
3256 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3257}
3258
3259/*
3260 * Set the colors of Widget "id" to the scrollbar colors.
3261 */
3262 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003263gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264{
3265 if (gui.scroll_bg_pixel != INVALCOLOR)
3266#if (XmVersion >= 1002)
3267 XmChangeColor(id, gui.scroll_bg_pixel);
3268#else
3269 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3270#endif
3271 if (gui.scroll_fg_pixel != INVALCOLOR)
3272 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3273}
3274
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275/*
3276 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3277 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003278 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003279gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003281#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#ifdef FONTSET_ALWAYS
3283 if (gui.menu_fontset != NOFONTSET)
3284 {
3285 XmFontList fl;
3286
3287 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3288 if (fl != NULL)
3289 {
3290 if (XtIsManaged(id))
3291 {
3292 XtUnmanageChild(id);
3293 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003294 // We should force the widget to recalculate its
3295 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296 XtManageChild(id);
3297 }
3298 else
3299 XtVaSetValues(id, XmNfontList, fl, NULL);
3300 XmFontListFree(fl);
3301 }
3302 }
3303#else
3304 if (gui.menu_font != NOFONT)
3305 {
3306 XmFontList fl;
3307
3308 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3309 if (fl != NULL)
3310 {
3311 if (XtIsManaged(id))
3312 {
3313 XtUnmanageChild(id);
3314 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003315 // We should force the widget to recalculate its
3316 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 XtManageChild(id);
3318 }
3319 else
3320 XtVaSetValues(id, XmNfontList, fl, NULL);
3321 XmFontListFree(fl);
3322 }
3323 }
3324#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326}
3327
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328
3329/*
3330 * We don't create it twice for the sake of speed.
3331 */
3332
3333typedef struct _SharedFindReplace
3334{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003335 Widget dialog; // the main dialog widget
3336 Widget wword; // 'Exact match' check button
3337 Widget mcase; // 'match case' check button
3338 Widget up; // search direction 'Up' radio button
3339 Widget down; // search direction 'Down' radio button
3340 Widget what; // 'Find what' entry text widget
3341 Widget with; // 'Replace with' entry text widget
3342 Widget find; // 'Find Next' action button
3343 Widget replace; // 'Replace With' action button
3344 Widget all; // 'Replace All' action button
3345 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346
3347 Widget cancel;
3348} SharedFindReplace;
3349
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003350static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3351static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003354find_replace_destroy_callback(
3355 Widget w UNUSED,
3356 XtPointer client_data,
3357 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358{
3359 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3360
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003361 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003362 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363 cd->dialog = (Widget)0;
3364}
3365
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003367find_replace_dismiss_callback(
3368 Widget w UNUSED,
3369 XtPointer client_data,
3370 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371{
3372 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3373
3374 if (cd != NULL)
3375 XtUnmanageChild(cd->dialog);
3376}
3377
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003379entry_activate_callback(
3380 Widget w UNUSED,
3381 XtPointer client_data,
3382 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383{
3384 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3385}
3386
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003388find_replace_callback(
3389 Widget w UNUSED,
3390 XtPointer client_data,
3391 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392{
3393 long_u flags = (long_u)client_data;
3394 char *find_text, *repl_text;
3395 Boolean direction_down = TRUE;
3396 Boolean wword;
3397 Boolean mcase;
3398 SharedFindReplace *sfr;
3399
3400 if (flags == FRD_UNDO)
3401 {
3402 char_u *save_cpo = p_cpo;
3403
Bram Moolenaar734a8672019-12-02 22:49:38 +01003404 // No need to be Vi compatible here.
Bram Moolenaarbb0956f2021-01-03 22:12:15 +01003405 p_cpo = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 u_undo(1);
3407 p_cpo = save_cpo;
3408 gui_update_screen();
3409 return;
3410 }
3411
Bram Moolenaar734a8672019-12-02 22:49:38 +01003412 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413 if (flags == FRD_FINDNEXT)
3414 {
3415 repl_text = NULL;
3416 sfr = &find_widgets;
3417 }
3418 else
3419 {
3420 repl_text = XmTextFieldGetString(repl_widgets.with);
3421 sfr = &repl_widgets;
3422 }
3423 find_text = XmTextFieldGetString(sfr->what);
3424 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3425 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3426 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3427 if (wword)
3428 flags |= FRD_WHOLE_WORD;
3429 if (mcase)
3430 flags |= FRD_MATCH_CASE;
3431
3432 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3433 direction_down);
3434
3435 if (find_text != NULL)
3436 XtFree(find_text);
3437 if (repl_text != NULL)
3438 XtFree(repl_text);
3439}
3440
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003442find_replace_keypress(
3443 Widget w UNUSED,
3444 SharedFindReplace *frdp,
Bram Moolenaar9dbe7012021-03-29 20:10:26 +02003445 XKeyEvent *event,
3446 Boolean *b UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447{
3448 KeySym keysym;
3449
3450 if (frdp == NULL)
3451 return;
3452
3453 keysym = XLookupKeysym(event, 0);
3454
Bram Moolenaar734a8672019-12-02 22:49:38 +01003455 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456 if (keysym == XK_Escape)
3457 XtUnmanageChild(frdp->dialog);
3458}
3459
3460 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003461set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003462{
3463 XmString str;
3464 char_u *p, *next;
3465 KeySym mnemonic = NUL;
3466
3467 if (!w)
3468 return;
3469
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003470 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003471 if (p == NULL)
3472 return;
3473 for (next = p; *next; ++next)
3474 {
3475 if (*next == DLG_HOTKEY_CHAR)
3476 {
3477 int len = STRLEN(next);
3478
3479 if (len > 0)
3480 {
3481 mch_memmove(next, next + 1, len);
3482 mnemonic = next[0];
3483 }
3484 }
3485 }
3486
3487 str = XmStringCreateSimple((char *)p);
3488 vim_free(p);
3489 if (str)
3490 {
3491 XtVaSetValues(w,
3492 XmNlabelString, str,
3493 XmNmnemonic, mnemonic,
3494 NULL);
3495 XmStringFree(str);
3496 }
3497 gui_motif_menu_fontlist(w);
3498}
3499
3500 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003501find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502{
3503 SharedFindReplace *frdp;
3504 Widget separator;
3505 Widget input_form;
3506 Widget button_form;
3507 Widget toggle_form;
3508 Widget frame;
3509 XmString str;
3510 int n;
3511 Arg args[6];
3512 int wword = FALSE;
3513 int mcase = !p_ic;
3514 Dimension width;
3515 Dimension widest;
3516 char_u *entry_text;
3517
3518 frdp = do_replace ? &repl_widgets : &find_widgets;
3519
Bram Moolenaar734a8672019-12-02 22:49:38 +01003520 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3522
Bram Moolenaar734a8672019-12-02 22:49:38 +01003523 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 if (frdp->dialog)
3525 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003526 gui_motif_synch_fonts();
3527
Bram Moolenaar734a8672019-12-02 22:49:38 +01003528 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 if (XtIsManaged(frdp->dialog))
3530 XMapRaised(XtDisplay(frdp->dialog),
3531 XtWindow(XtParent(frdp->dialog)));
3532 else
3533 XtManageChild(frdp->dialog);
3534 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3535 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3536
3537 if (entry_text != NULL)
3538 XmTextFieldSetString(frdp->what, (char *)entry_text);
3539 vim_free(entry_text);
3540
3541 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3542 return;
3543 }
3544
Bram Moolenaar734a8672019-12-02 22:49:38 +01003545 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 if (do_replace)
3547 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3548 else
3549 str = XmStringCreateSimple(_("VIM - Search..."));
3550
3551 n = 0;
3552 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3553 XtSetArg(args[n], XmNnoResize, True); n++;
3554 XtSetArg(args[n], XmNdialogTitle, str); n++;
3555
3556 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3557 XmStringFree(str);
3558 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3559 find_replace_destroy_callback, frdp);
3560
3561 button_form = XtVaCreateWidget("buttonForm",
3562 xmFormWidgetClass, frdp->dialog,
3563 XmNrightAttachment, XmATTACH_FORM,
3564 XmNrightOffset, 4,
3565 XmNtopAttachment, XmATTACH_FORM,
3566 XmNtopOffset, 4,
3567 XmNbottomAttachment, XmATTACH_FORM,
3568 XmNbottomOffset, 4,
3569 NULL);
3570
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 frdp->find = XtVaCreateManagedWidget("findButton",
3572 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 XmNsensitive, True,
3574 XmNtopAttachment, XmATTACH_FORM,
3575 XmNleftAttachment, XmATTACH_FORM,
3576 XmNrightAttachment, XmATTACH_FORM,
3577 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003578 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579
3580 XtAddCallback(frdp->find, XmNactivateCallback,
3581 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003582 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583
3584 if (do_replace)
3585 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3587 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588 XmNtopAttachment, XmATTACH_WIDGET,
3589 XmNtopWidget, frdp->find,
3590 XmNleftAttachment, XmATTACH_FORM,
3591 XmNrightAttachment, XmATTACH_FORM,
3592 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003593 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594 XtAddCallback(frdp->replace, XmNactivateCallback,
3595 find_replace_callback, (XtPointer)FRD_REPLACE);
3596
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3598 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 XmNtopAttachment, XmATTACH_WIDGET,
3600 XmNtopWidget, frdp->replace,
3601 XmNleftAttachment, XmATTACH_FORM,
3602 XmNrightAttachment, XmATTACH_FORM,
3603 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003604 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 XtAddCallback(frdp->all, XmNactivateCallback,
3606 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3607
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 frdp->undo = XtVaCreateManagedWidget("undoButton",
3609 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 XmNtopAttachment, XmATTACH_WIDGET,
3611 XmNtopWidget, frdp->all,
3612 XmNleftAttachment, XmATTACH_FORM,
3613 XmNrightAttachment, XmATTACH_FORM,
3614 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003615 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 XtAddCallback(frdp->undo, XmNactivateCallback,
3617 find_replace_callback, (XtPointer)FRD_UNDO);
3618 }
3619
Bram Moolenaar071d4272004-06-13 20:20:40 +00003620 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3621 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 XmNleftAttachment, XmATTACH_FORM,
3623 XmNrightAttachment, XmATTACH_FORM,
3624 XmNbottomAttachment, XmATTACH_FORM,
3625 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003626 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 XtAddCallback(frdp->cancel, XmNactivateCallback,
3628 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003629 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630
3631 XtManageChild(button_form);
3632
3633 n = 0;
3634 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3635 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3636 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3637 XtSetArg(args[n], XmNrightOffset, 4); n++;
3638 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3639 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3640 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3641 XtManageChild(separator);
3642
3643 input_form = XtVaCreateWidget("inputForm",
3644 xmFormWidgetClass, frdp->dialog,
3645 XmNleftAttachment, XmATTACH_FORM,
3646 XmNleftOffset, 4,
3647 XmNrightAttachment, XmATTACH_WIDGET,
3648 XmNrightWidget, separator,
3649 XmNrightOffset, 4,
3650 XmNtopAttachment, XmATTACH_FORM,
3651 XmNtopOffset, 4,
3652 NULL);
3653
3654 {
3655 Widget label_what;
3656 Widget label_with = (Widget)0;
3657
3658 str = XmStringCreateSimple(_("Find what:"));
3659 label_what = XtVaCreateManagedWidget("whatLabel",
3660 xmLabelGadgetClass, input_form,
3661 XmNlabelString, str,
3662 XmNleftAttachment, XmATTACH_FORM,
3663 XmNtopAttachment, XmATTACH_FORM,
3664 XmNtopOffset, 4,
3665 NULL);
3666 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003667 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668
3669 frdp->what = XtVaCreateManagedWidget("whatText",
3670 xmTextFieldWidgetClass, input_form,
3671 XmNtopAttachment, XmATTACH_FORM,
3672 XmNrightAttachment, XmATTACH_FORM,
3673 XmNleftAttachment, XmATTACH_FORM,
3674 NULL);
3675
3676 if (do_replace)
3677 {
3678 frdp->with = XtVaCreateManagedWidget("withText",
3679 xmTextFieldWidgetClass, input_form,
3680 XmNtopAttachment, XmATTACH_WIDGET,
3681 XmNtopWidget, frdp->what,
3682 XmNtopOffset, 4,
3683 XmNleftAttachment, XmATTACH_FORM,
3684 XmNrightAttachment, XmATTACH_FORM,
3685 XmNbottomAttachment, XmATTACH_FORM,
3686 NULL);
3687
3688 XtAddCallback(frdp->with, XmNactivateCallback,
3689 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3690
3691 str = XmStringCreateSimple(_("Replace with:"));
3692 label_with = XtVaCreateManagedWidget("withLabel",
3693 xmLabelGadgetClass, input_form,
3694 XmNlabelString, str,
3695 XmNleftAttachment, XmATTACH_FORM,
3696 XmNtopAttachment, XmATTACH_WIDGET,
3697 XmNtopWidget, frdp->what,
3698 XmNtopOffset, 4,
3699 XmNbottomAttachment, XmATTACH_FORM,
3700 NULL);
3701 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003702 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703
3704 /*
3705 * Make the entry activation only change the input focus onto the
3706 * with item.
3707 */
3708 XtAddCallback(frdp->what, XmNactivateCallback,
3709 entry_activate_callback, frdp->with);
3710 XtAddEventHandler(frdp->with, KeyPressMask, False,
3711 (XtEventHandler)find_replace_keypress,
3712 (XtPointer) frdp);
3713
3714 }
3715 else
3716 {
3717 /*
3718 * Make the entry activation do the search.
3719 */
3720 XtAddCallback(frdp->what, XmNactivateCallback,
3721 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3722 }
3723 XtAddEventHandler(frdp->what, KeyPressMask, False,
3724 (XtEventHandler)find_replace_keypress,
3725 (XtPointer)frdp);
3726
Bram Moolenaar734a8672019-12-02 22:49:38 +01003727 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 n = 0;
3729 XtSetArg(args[n], XmNwidth, &width); n++;
3730 XtGetValues(label_what, args, n);
3731 widest = width;
3732 if (do_replace)
3733 {
3734 XtGetValues(label_with, args, n);
3735 if (width > widest)
3736 widest = width;
3737 }
3738
3739 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3740 if (do_replace)
3741 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3742
3743 }
3744
3745 XtManageChild(input_form);
3746
3747 {
3748 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003749 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750
3751 frame = XtVaCreateWidget("directionFrame",
3752 xmFrameWidgetClass, frdp->dialog,
3753 XmNtopAttachment, XmATTACH_WIDGET,
3754 XmNtopWidget, input_form,
3755 XmNtopOffset, 4,
3756 XmNbottomAttachment, XmATTACH_FORM,
3757 XmNbottomOffset, 4,
3758 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3759 XmNrightWidget, input_form,
3760 NULL);
3761
3762 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003763 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764 xmLabelGadgetClass, frame,
3765 XmNlabelString, str,
3766 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3767 XmNchildType, XmFRAME_TITLE_CHILD,
3768 NULL);
3769 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003770 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771
3772 radio_box = XmCreateRadioBox(frame, "radioBox",
3773 (ArgList)NULL, 0);
3774
3775 str = XmStringCreateSimple( _("Up"));
3776 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3777 xmToggleButtonGadgetClass, radio_box,
3778 XmNlabelString, str,
3779 XmNset, False,
3780 NULL);
3781 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003782 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783
3784 str = XmStringCreateSimple(_("Down"));
3785 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3786 xmToggleButtonGadgetClass, radio_box,
3787 XmNlabelString, str,
3788 XmNset, True,
3789 NULL);
3790 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003791 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792
3793 XtManageChild(radio_box);
3794 XtManageChild(frame);
3795 }
3796
3797 toggle_form = XtVaCreateWidget("toggleForm",
3798 xmFormWidgetClass, frdp->dialog,
3799 XmNleftAttachment, XmATTACH_FORM,
3800 XmNleftOffset, 4,
3801 XmNrightAttachment, XmATTACH_WIDGET,
3802 XmNrightWidget, frame,
3803 XmNrightOffset, 4,
3804 XmNtopAttachment, XmATTACH_WIDGET,
3805 XmNtopWidget, input_form,
3806 XmNtopOffset, 4,
3807 XmNbottomAttachment, XmATTACH_FORM,
3808 XmNbottomOffset, 4,
3809 NULL);
3810
3811 str = XmStringCreateSimple(_("Match whole word only"));
3812 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3813 xmToggleButtonGadgetClass, toggle_form,
3814 XmNlabelString, str,
3815 XmNtopAttachment, XmATTACH_FORM,
3816 XmNtopOffset, 4,
3817 XmNleftAttachment, XmATTACH_FORM,
3818 XmNleftOffset, 4,
3819 XmNset, wword,
3820 NULL);
3821 XmStringFree(str);
3822
3823 str = XmStringCreateSimple(_("Match case"));
3824 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3825 xmToggleButtonGadgetClass, toggle_form,
3826 XmNlabelString, str,
3827 XmNleftAttachment, XmATTACH_FORM,
3828 XmNleftOffset, 4,
3829 XmNtopAttachment, XmATTACH_WIDGET,
3830 XmNtopWidget, frdp->wword,
3831 XmNtopOffset, 4,
3832 XmNset, mcase,
3833 NULL);
3834 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003835 gui_motif_menu_fontlist(frdp->wword);
3836 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837
3838 XtManageChild(toggle_form);
3839
3840 if (entry_text != NULL)
3841 XmTextFieldSetString(frdp->what, (char *)entry_text);
3842 vim_free(entry_text);
3843
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003844 gui_motif_synch_fonts();
3845
3846 manage_centered(frdp->dialog);
3847 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3849}
3850
3851 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003852gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853{
3854 if (!gui.in_use)
3855 return;
3856
3857 find_replace_dialog_create(eap->arg, FALSE);
3858}
3859
3860
3861 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003862gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863{
3864 if (!gui.in_use)
3865 return;
3866
3867 find_replace_dialog_create(eap->arg, TRUE);
3868}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003869
3870/*
Bram Moolenaar52797ba2021-12-16 14:45:13 +00003871 * Synchronize all gui elements, which are dependent upon the
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003872 * main text font used. Those are in esp. the find/replace dialogs.
3873 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003874 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003875 */
3876 void
3877gui_motif_synch_fonts(void)
3878{
3879 SharedFindReplace *frdp;
3880 int do_replace;
3881 XFontStruct *font;
3882 XmFontList font_list;
3883
Bram Moolenaar734a8672019-12-02 22:49:38 +01003884 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3885 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003886 font = (XFontStruct *)gui.norm_font;
3887 if (font == NULL)
3888 return;
3889
3890 font_list = gui_motif_create_fontlist(font);
3891
Bram Moolenaar734a8672019-12-02 22:49:38 +01003892 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003893 for (do_replace = 0; do_replace <= 1; ++do_replace)
3894 {
3895 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3896 if (frdp->dialog)
3897 {
3898 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
3899 if (do_replace)
3900 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
3901 }
3902 }
3903
3904 XmFontListFree(font_list);
3905}