blob: 55c026eb48b9a91be2b457d6f36479590cc9ba4f [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);
170 if (tab_scroll_w != (Widget)0) {
171 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
172 &width, XmNheight, &height, NULL);
173 if (pos_x >= 0) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100174 // Tab scroller (next) is visible
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000175 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
176 (event->y >= pos_y) && (event->y <= pos_y + height)) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100177 // Clicked on the scroller
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000178 return TRUE;
179 }
180 }
181 }
182 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000183}
184
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000185 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100186tabline_menu_cb(
187 Widget w,
188 XtPointer closure UNUSED,
189 XEvent *e,
190 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000191{
192 Widget tab_w;
193 XButtonPressedEvent *event;
194 int tab_idx = 0;
195 WidgetList children;
196 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000197 static XtIntervalId timer = (XtIntervalId)0;
198 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000199
200 event = (XButtonPressedEvent *)e;
201
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000202 if (event->button == Button1)
203 {
204 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
205 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
206 return;
207
208 if (!timed_out)
209 {
210 XtRemoveTimeOut(timer);
211 timed_out = TRUE;
212
213 /*
214 * Double click on the tabline gutter, add a new tab
215 */
216 send_tabline_menu_event(0, TABLINE_MENU_NEW);
217 }
218 else
219 {
220 /*
221 * Single click on the tabline gutter, start a timer to check
222 * for double clicks
223 */
224 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
225 motif_tabline_timer_cb, &timed_out);
226 timed_out = FALSE;
227 }
228 return;
229 }
230
Martin Tournoij7904fa42022-10-04 16:28:45 +0100231 if (event->button == Button2)
232 {
233 // Middle mouse click on tabpage label closes that tab.
234 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
235 send_tabline_menu_event(tab_idx, (int)TABLINE_MENU_CLOSE);
236 return;
237 }
238
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000239 if (event->button != Button3)
240 return;
241
Bram Moolenaar734a8672019-12-02 22:49:38 +0100242 // When ignoring events don't show the menu.
Martin Tournoij7904fa42022-10-04 16:28:45 +0100243 if (hold_gui_events || cmdwin_type != 0)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000244 return;
245
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000246 if (event->subwindow != None)
247 {
248 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaar734a8672019-12-02 22:49:38 +0100249 // LINTED: avoid warning: dubious operation on enum
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000250 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
251 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
252 }
253
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000254 XtVaSetValues(tabLine_menu, XmNuserData, (XtPointer)(long)tab_idx, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000255 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
256 &numChildren, NULL);
257 XtManageChildren(children, numChildren);
258 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
259 XtManageChild(tabLine_menu);
260}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000261
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000262 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100263tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000264{
265 int nr;
266 tabpage_T *tp;
267
268 if (beval->target == (Widget)0)
269 return;
270
271 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
272 tp = find_tabpage(nr);
273 if (tp == NULL)
274 return;
275
276 get_tabline_label(tp, TRUE);
277 gui_mch_post_balloon(beval, NameBuff);
278}
279
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000280#endif
281
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282/*
283 * End of call-back routines
284 */
285
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000286/*
287 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000288 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289 */
290
291#include <Xm/XmP.h>
292#include <Xm/LabelP.h>
293
294static XtExposeProc old_label_expose = NULL;
295
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000296 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100297label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000298{
299 GC insensitiveGC;
300 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000301 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000302
303 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
304
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000305 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000306 (*old_label_expose)(_w, _event, _region);
307 else
308 {
309 XGCValues values;
310 XtGCMask mask;
311 XtGCMask dynamic;
312 XFontStruct *fs;
313
314 _XmFontListGetDefaultFont(lw->label.font, &fs);
315
Bram Moolenaar734a8672019-12-02 22:49:38 +0100316 // FIXME: we should be doing the whole drawing ourself here.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000317 insensitiveGC = lw->label.insensitive_GC;
318
319 mask = GCForeground | GCBackground | GCGraphicsExposures;
320 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
321 values.graphics_exposures = False;
322
323 if (fs != 0)
324 {
325 mask |= GCFont;
326 values.font = fs->fid;
327 }
328
329 if (lw->primitive.top_shadow_pixmap != None
330 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
331 {
332 mask |= GCFillStyle | GCTile;
333 values.fill_style = FillTiled;
334 values.tile = lw->primitive.top_shadow_pixmap;
335 }
336
337 lw->label.TextRect.x += 1;
338 lw->label.TextRect.y += 1;
339 if (lw->label._acc_text != 0)
340 {
341 lw->label.acc_TextRect.x += 1;
342 lw->label.acc_TextRect.y += 1;
343 }
344
345 values.foreground = lw->primitive.top_shadow_color;
346 values.background = lw->core.background_pixel;
347
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000348 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
349 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000350 (*old_label_expose)(_w, _event, _region);
351 XtReleaseGC(_w, lw->label.insensitive_GC);
352
353 lw->label.TextRect.x -= 1;
354 lw->label.TextRect.y -= 1;
355 if (lw->label._acc_text != 0)
356 {
357 lw->label.acc_TextRect.x -= 1;
358 lw->label.acc_TextRect.y -= 1;
359 }
360
361 values.foreground = lw->primitive.bottom_shadow_color;
362 values.background = lw->core.background_pixel;
363
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000364 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
365 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000366 (*old_label_expose)(_w, _event, _region);
367 XtReleaseGC(_w, lw->label.insensitive_GC);
368
369 lw->label.insensitive_GC = insensitiveGC;
370 }
371}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000372
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373/*
374 * Create all the motif widgets necessary.
375 */
376 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100377gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000379#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000380 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000381 Arg args[10];
382 int n;
383 XmString xms;
384#endif
385
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000386 /*
387 * Install the 3D shade effect drawing routines.
388 */
389 if (old_label_expose == NULL)
390 {
391 old_label_expose = xmLabelWidgetClass->core_class.expose;
392 xmLabelWidgetClass->core_class.expose = label_expose;
393 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000394
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395 /*
396 * Start out by adding the configured border width into the border offset
397 */
398 gui.border_offset = gui.border_width;
399
400 /*
401 * Install the tearOffModel resource converter.
402 */
403#if (XmVersion >= 1002)
404 XmRepTypeInstallTearOffModelConverter();
405#endif
406
Bram Moolenaar734a8672019-12-02 22:49:38 +0100407 // Make sure the "Quit" menu entry of the window manager is ignored
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
409
410 vimForm = XtVaCreateManagedWidget("vimForm",
411 xmFormWidgetClass, vimShell,
412 XmNborderWidth, 0,
413 XmNhighlightThickness, 0,
414 XmNshadowThickness, 0,
415 XmNmarginWidth, 0,
416 XmNmarginHeight, 0,
417 XmNresizePolicy, XmRESIZE_ANY,
418 NULL);
419 gui_motif_menu_colors(vimForm);
420
421#ifdef FEAT_MENU
422 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100423 Arg al[7]; // Make sure there is enough room for arguments!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424 int ac = 0;
425
426# if (XmVersion >= 1002)
427 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
428# endif
429 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
430 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
431 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
432# ifndef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100433 // Always stick to right hand side.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
435# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000436 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
438 XtManageChild(menuBar);
439
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 gui_motif_menu_colors(menuBar);
441 }
442#endif
443
444#ifdef FEAT_TOOLBAR
445 /*
446 * Create an empty ToolBar. We should get buttons defined from menu.vim.
447 */
448 toolBarFrame = XtVaCreateWidget("toolBarFrame",
449 xmFrameWidgetClass, vimForm,
450 XmNshadowThickness, 0,
451 XmNmarginHeight, 0,
452 XmNmarginWidth, 0,
453 XmNleftAttachment, XmATTACH_FORM,
454 XmNrightAttachment, XmATTACH_FORM,
455 NULL);
456 gui_motif_menu_colors(toolBarFrame);
457
458 toolBar = XtVaCreateManagedWidget("toolBar",
459 xmRowColumnWidgetClass, toolBarFrame,
460 XmNchildType, XmFRAME_WORKAREA_CHILD,
461 XmNrowColumnType, XmWORK_AREA,
462 XmNorientation, XmHORIZONTAL,
463 XmNtraversalOn, False,
464 XmNisHomogeneous, False,
465 XmNpacking, XmPACK_TIGHT,
466 XmNspacing, 0,
467 XmNshadowThickness, 0,
468 XmNhighlightThickness, 0,
469 XmNmarginHeight, 0,
470 XmNmarginWidth, 0,
471 XmNadjustLast, True,
472 NULL);
473 gui_motif_menu_colors(toolBar);
474
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475#endif
476
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000477#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100478 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000479 n = 0;
480 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
481 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
482 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
483 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
484 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
485 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
486 XtSetArg(args[n], XmNshadowThickness, 0); n++;
487 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
488 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
489 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
490
491 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
492 NULL);
493 XtAddEventHandler(tabLine, ButtonPressMask, False,
494 (XtEventHandler)tabline_menu_cb, NULL);
495
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000496 gui.tabline_height = TABLINE_HEIGHT;
497
Bram Moolenaar18144c82006-04-12 21:52:12 +0000498 /*
499 * Set the size of the minor next/prev scrollers to zero, so
500 * that they are not displayed. Due to a bug in OpenMotif 2.3,
501 * even if these children widget are unmanaged, they are again
502 * managed by the Notebook widget and the notebook widget geometry
503 * is adjusted to account for the minor scroller widgets.
504 */
505 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
506 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
507 XmNtraversalOn, False, NULL);
508 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
509 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
510 XmNtraversalOn, False, NULL);
511
Bram Moolenaar29547192018-12-11 20:39:19 +0100512 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000513 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
514
Bram Moolenaar29547192018-12-11 20:39:19 +0100515 // Add the buttons to the tabline popup menu
516 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000517 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_CLOSE); n++;
Bram Moolenaar29547192018-12-11 20:39:19 +0100518 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
519 XtSetArg(args[n], XmNlabelString, xms); n++;
520 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
521 XtAddCallback(button, XmNactivateCallback,
522 (XtCallbackProc)tabline_button_cb, NULL);
523 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000524
525 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000526 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_NEW); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000527 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
528 XtSetArg(args[n], XmNlabelString, xms); n++;
529 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
530 XtAddCallback(button, XmNactivateCallback,
531 (XtCallbackProc)tabline_button_cb, NULL);
532 XmStringFree(xms);
533
534 n = 0;
Bram Moolenaar9dd42a62022-03-24 18:04:49 +0000535 XtSetArg(args[n], XmNuserData, (XtPointer)TABLINE_MENU_OPEN); n++;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000536 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
537 XtSetArg(args[n], XmNlabelString, xms); n++;
538 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
539 XtAddCallback(button, XmNactivateCallback,
540 (XtCallbackProc)tabline_button_cb, NULL);
541 XmStringFree(xms);
542#endif
543
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
545 xmFormWidgetClass, vimForm,
546 XmNleftAttachment, XmATTACH_FORM,
547 XmNrightAttachment, XmATTACH_FORM,
548 XmNbottomAttachment, XmATTACH_FORM,
549 XmNtopAttachment, XmATTACH_FORM,
550 XmNmarginWidth, 0,
551 XmNmarginHeight, 0,
552 XmNresizePolicy, XmRESIZE_ANY,
553 NULL);
554 gui_motif_scroll_colors(textAreaForm);
555
556 textArea = XtVaCreateManagedWidget("textArea",
557 xmDrawingAreaWidgetClass, textAreaForm,
558 XmNforeground, gui.norm_pixel,
559 XmNbackground, gui.back_pixel,
560 XmNleftAttachment, XmATTACH_FORM,
561 XmNtopAttachment, XmATTACH_FORM,
562 XmNrightAttachment, XmATTACH_FORM,
563 XmNbottomAttachment, XmATTACH_FORM,
564
565 /*
566 * These take some control away from the user, but avoids making them
567 * add resources to get a decent looking setup.
568 */
569 XmNborderWidth, 0,
570 XmNhighlightThickness, 0,
571 XmNshadowThickness, 0,
572 NULL);
573
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 /*
575 * Install the callbacks.
576 */
577 gui_x11_callbacks(textArea, vimForm);
578
Bram Moolenaar734a8672019-12-02 22:49:38 +0100579 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 gui.in_focus = FALSE;
581}
582
583/*
584 * Called when the GUI is not going to start after all.
585 */
586 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100587gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588{
589 textArea = NULL;
590#ifdef FEAT_MENU
591 menuBar = NULL;
592#endif
593}
594
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100596gui_mch_set_text_area_pos(
597 int x UNUSED,
598 int y UNUSED,
599 int w UNUSED,
600 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601{
602#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100603 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000604 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605#endif
606}
607
608 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100609gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610{
611 if (textArea != NULL)
612#if (XmVersion >= 1002)
613 XmChangeColor(textArea, gui.back_pixel);
614#else
615 XtVaSetValues(textArea,
616 XmNbackground, gui.back_pixel,
617 NULL);
618#endif
619}
620
621/*
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100622 * Manage dialog centered on pointer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000624 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100625manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626{
627 Widget shell = XtParent(dialog_child);
628 Window root, child;
629 unsigned int mask;
630 unsigned int width, height, border_width, depth;
631 int x, y, win_x, win_y, maxX, maxY;
632 Boolean mappedWhenManaged;
633
Bram Moolenaar734a8672019-12-02 22:49:38 +0100634 // Temporarily set value of XmNmappedWhenManaged
635 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000636 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
637 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638
639 XtManageChild(dialog_child);
640
Bram Moolenaar734a8672019-12-02 22:49:38 +0100641 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
643 &x, &y, &win_x, &win_y, &mask);
644
Bram Moolenaar734a8672019-12-02 22:49:38 +0100645 // Translate the pointer position (x, y) into a position for the new
646 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
648 &width, &height, &border_width, &depth);
649 width += 2 * border_width;
650 height += 2 * border_width;
651 x -= width / 2;
652 y -= height / 2;
653
Bram Moolenaar734a8672019-12-02 22:49:38 +0100654 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 maxX = XtScreen(shell)->width - width;
656 maxY = XtScreen(shell)->height - height;
657 if (x < 0)
658 x = 0;
659 if (x > maxX)
660 x = maxX;
661 if (y < 0)
662 y = 0;
663 if (y > maxY)
664 y = maxY;
665
Bram Moolenaar734a8672019-12-02 22:49:38 +0100666 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
668
Bram Moolenaar734a8672019-12-02 22:49:38 +0100669 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 XtMapWidget(shell);
671
Bram Moolenaar734a8672019-12-02 22:49:38 +0100672 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000673 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674}
675
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100676#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677
678/*
679 * Encapsulate the way an XmFontList is created.
680 */
681 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100682gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683{
684 XmFontList font_list;
685
686# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100687 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 font_list = XmFontListCreate(font, STRING_TAG);
689# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100690 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 XmFontListEntry font_list_entry;
692
693 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
694 (XtPointer)font);
695 font_list = XmFontListAppendEntry(NULL, font_list_entry);
696 XmFontListEntryFree(&font_list_entry);
697# endif
698 return font_list;
699}
700
701# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
702 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100703gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704{
705 XmFontList font_list;
706
Bram Moolenaar734a8672019-12-02 22:49:38 +0100707 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 XmFontListEntry font_list_entry;
709
710 font_list_entry = XmFontListEntryCreate(STRING_TAG,
711 XmFONT_IS_FONTSET,
712 (XtPointer)*fontset);
713 font_list = XmFontListAppendEntry(NULL, font_list_entry);
714 XmFontListEntryFree(&font_list_entry);
715 return font_list;
716}
717# endif
718
719#endif
720
721#if defined(FEAT_MENU) || defined(PROTO)
722/*
723 * Menu stuff.
724 */
725
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100726static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100728static void toggle_tearoff(Widget wid);
729static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100731static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100733static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734static int menu_enabled = TRUE;
735
736 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100737gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738{
739 if (flag)
740 {
741 XtManageChild(menuBar);
742#ifdef FEAT_TOOLBAR
743 if (XtIsManaged(XtParent(toolBar)))
744 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100745 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746 XtVaSetValues(XtParent(toolBar),
747 XmNtopAttachment, XmATTACH_WIDGET,
748 XmNtopWidget, menuBar,
749 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000750#ifdef FEAT_GUI_TABLINE
751 if (showing_tabline)
752 {
753 XtVaSetValues(tabLine,
754 XmNtopAttachment, XmATTACH_WIDGET,
755 XmNtopWidget, XtParent(toolBar),
756 NULL);
757 XtVaSetValues(textAreaForm,
758 XmNtopAttachment, XmATTACH_WIDGET,
759 XmNtopWidget, tabLine,
760 NULL);
761 }
762 else
763#endif
764 XtVaSetValues(textAreaForm,
765 XmNtopAttachment, XmATTACH_WIDGET,
766 XmNtopWidget, XtParent(toolBar),
767 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 }
769 else
770#endif
771 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000772#ifdef FEAT_GUI_TABLINE
773 if (showing_tabline)
774 {
775 XtVaSetValues(tabLine,
776 XmNtopAttachment, XmATTACH_WIDGET,
777 XmNtopWidget, menuBar,
778 NULL);
779 XtVaSetValues(textAreaForm,
780 XmNtopAttachment, XmATTACH_WIDGET,
781 XmNtopWidget, tabLine,
782 NULL);
783 }
784 else
785#endif
786 XtVaSetValues(textAreaForm,
787 XmNtopAttachment, XmATTACH_WIDGET,
788 XmNtopWidget, menuBar,
789 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 }
791 }
792 else
793 {
794 XtUnmanageChild(menuBar);
795#ifdef FEAT_TOOLBAR
796 if (XtIsManaged(XtParent(toolBar)))
797 {
798 XtVaSetValues(XtParent(toolBar),
799 XmNtopAttachment, XmATTACH_FORM,
800 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000801#ifdef FEAT_GUI_TABLINE
802 if (showing_tabline)
803 {
804 XtVaSetValues(tabLine,
805 XmNtopAttachment, XmATTACH_WIDGET,
806 XmNtopWidget, XtParent(toolBar),
807 NULL);
808 XtVaSetValues(textAreaForm,
809 XmNtopAttachment, XmATTACH_WIDGET,
810 XmNtopWidget, tabLine,
811 NULL);
812 }
813 else
814#endif
815 XtVaSetValues(textAreaForm,
816 XmNtopAttachment, XmATTACH_WIDGET,
817 XmNtopWidget, XtParent(toolBar),
818 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 }
820 else
821#endif
822 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000823#ifdef FEAT_GUI_TABLINE
824 if (showing_tabline)
825 {
826 XtVaSetValues(tabLine,
827 XmNtopAttachment, XmATTACH_FORM,
828 NULL);
829 XtVaSetValues(textAreaForm,
830 XmNtopAttachment, XmATTACH_WIDGET,
831 XmNtopWidget, tabLine,
832 NULL);
833 }
834 else
835#endif
836 XtVaSetValues(textAreaForm,
837 XmNtopAttachment, XmATTACH_FORM,
838 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 }
840 }
841
842}
843
844/*
845 * Enable or disable mnemonics for the toplevel menus.
846 */
847 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100848gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849{
850 /*
851 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
852 * crashes when using a mnemonic then.
853 */
854 if (!menu_enabled)
855 enable = FALSE;
856 do_set_mnemonics(enable);
857}
858
859 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100860do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861{
862 vimmenu_T *menu;
863
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200864 FOR_ALL_MENUS(menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865 if (menu->id != (Widget)0)
866 XtVaSetValues(menu->id,
867 XmNmnemonic, enable ? menu->mnemonic : NUL,
868 NULL);
869}
870
871 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100872gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873{
874 XmString label;
875 Widget shell;
876 vimmenu_T *parent = menu->parent;
877
878#ifdef MOTIF_POPUP
879 if (menu_is_popup(menu->name))
880 {
881 Arg arg[2];
882 int n = 0;
883
Bram Moolenaar734a8672019-12-02 22:49:38 +0100884 // Only create the popup menu when it's actually used, otherwise there
885 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886# if (XmVersion <= 1002)
887 if (mouse_model_popup())
888# endif
889 {
890 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200891 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200895 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar7795bfe2020-09-20 19:57:15 +0200897 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
899 arg, n);
900 menu->id = (Widget)0;
901 }
902 return;
903 }
904#endif
905
906 if (!menu_is_menubar(menu->name)
907 || (parent != NULL && parent->submenu_id == (Widget)0))
908 return;
909
910 label = XmStringCreate((char *)menu->dname, STRING_TAG);
911 if (label == NULL)
912 return;
913 menu->id = XtVaCreateWidget("subMenu",
914 xmCascadeButtonWidgetClass,
915 (parent == NULL) ? menuBar : parent->submenu_id,
916 XmNlabelString, label,
917 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
918#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100919 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 XmNpositionIndex, idx + (parent != NULL
921 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
922#endif
923 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 XmStringFree(label);
925
Bram Moolenaar734a8672019-12-02 22:49:38 +0100926 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 return;
928
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100929 // The "Help" menu is a special case, and should be placed at the far
930 // right hand side of the menu-bar. It's recognized by its high priority.
931 if (parent == NULL && menu->priority >= 9999)
932 XtVaSetValues(menuBar,
933 XmNmenuHelpWidget, menu->id,
934 NULL);
935
936 gui_motif_menu_colors(menu->id);
937 gui_motif_menu_fontlist(menu->id);
938
Bram Moolenaar734a8672019-12-02 22:49:38 +0100939 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940 gui_motif_add_actext(menu);
941
942 shell = XtVaCreateWidget("subMenuShell",
943 xmMenuShellWidgetClass, menu->id,
944 XmNwidth, 1,
945 XmNheight, 1,
946 NULL);
947 gui_motif_menu_colors(shell);
948 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
949 xmRowColumnWidgetClass, shell,
950 XmNrowColumnType, XmMENU_PULLDOWN,
951 NULL);
952 gui_motif_menu_colors(menu->submenu_id);
953
Bram Moolenaar734a8672019-12-02 22:49:38 +0100954 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 return;
956
957#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100958 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 toggle_tearoff(menu->submenu_id);
960#endif
961
962 XtVaSetValues(menu->id,
963 XmNsubMenuId, menu->submenu_id,
964 NULL);
965
Bram Moolenaarb4ad3b02022-03-30 10:57:45 +0100966 // When we add a top-level item to the menu bar, we can figure out how
967 // high the menu bar should be.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000968 if (parent == NULL)
969 gui_mch_compute_menu_height(menu->id);
970}
971
972
973/*
974 * Add mnemonic and accelerator text to a menu button.
975 */
976 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100977gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978{
979 XmString label;
980
Bram Moolenaar734a8672019-12-02 22:49:38 +0100981 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 if (menu->actext != NULL && menu->id != (Widget)0)
983 {
984 label = XmStringCreate((char *)menu->actext, STRING_TAG);
985 if (label == NULL)
986 return;
987 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
988 XmStringFree(label);
989 }
990}
991
992 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100993gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994{
995#if (XmVersion >= 1002)
996 if (enable)
997 tearoff_val = (int)XmTEAR_OFF_ENABLED;
998 else
999 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1000 toggle_tearoff(menuBar);
1001 gui_mch_recurse_tearoffs(root_menu);
1002#endif
1003}
1004
1005#if (XmVersion >= 1002)
1006/*
1007 * Set the tearoff for one menu widget on or off, and set the color of the
1008 * tearoff widget.
1009 */
1010 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001011toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012{
1013 Widget w;
1014
1015 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1016 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1017 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1018 gui_motif_menu_colors(w);
1019}
1020
1021 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001022gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023{
1024 while (menu != NULL)
1025 {
1026 if (!menu_is_popup(menu->name))
1027 {
1028 if (menu->submenu_id != (Widget)0)
1029 toggle_tearoff(menu->submenu_id);
1030 gui_mch_recurse_tearoffs(menu->children);
1031 }
1032 menu = menu->next;
1033 }
1034}
1035#endif
1036
1037 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001038gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039{
1040 Dimension shadowHeight;
1041
1042 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1043 return shadowHeight;
1044}
1045
1046/*
1047 * Compute the height of the menu bar.
1048 * We need to check all the items for their position and height, for the case
1049 * there are several rows, and/or some characters extend higher or lower.
1050 */
1051 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001052gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001053 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054{
1055 Dimension y, maxy;
1056 Dimension margin, shadow;
1057 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001058 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059
1060 /*
1061 * Get the height of the new item, before managing it, because it will
1062 * still reflect the font size. After managing it depends on the menu
1063 * height, which is what we just wanted to get!.
1064 */
1065 if (id != (Widget)0)
1066 XtVaGetValues(id, XmNheight, &height, NULL);
1067
Bram Moolenaar734a8672019-12-02 22:49:38 +01001068 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 else
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001070 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1072 {
1073 id = mp->id;
1074 break;
1075 }
1076
1077 /*
1078 * Now manage the menu item, to make them all be positioned (makes an
1079 * extra row when needed, removes it when not needed).
1080 */
1081 if (id != (Widget)0)
1082 XtManageChild(id);
1083
1084 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001085 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 */
1087 maxy = 0;
Bram Moolenaar00d253e2020-04-06 22:13:01 +02001088 FOR_ALL_MENUS(mp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {
1090 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1091 {
1092 XtVaGetValues(mp->id, XmNy, &y, NULL);
1093 if (y > maxy)
1094 maxy = y;
1095 }
1096 }
1097
1098 XtVaGetValues(menuBar,
1099 XmNmarginHeight, &margin,
1100 XmNshadowThickness, &shadow,
1101 NULL);
1102
1103 /*
1104 * This computation is the result of trial-and-error:
1105 * maxy = The maximum position of an item; required for when there are
1106 * two or more rows
1107 * height = height of an item, before managing it; Hopefully this will
1108 * change with the font height. Includes shadow-border.
1109 * shadow = shadow-border; must be subtracted from the height.
1110 * margin = margin around the menu buttons; Must be added.
1111 * Add 4 for the underlining of shortcut keys.
1112 */
1113 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1114
Bram Moolenaar734a8672019-12-02 22:49:38 +01001115 // Somehow the menu bar doesn't resize automatically. Set it here,
1116 // even though this is a catch 22. Don't do this when starting up,
1117 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 if (gui.shell_created)
1119 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001120}
1121
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001122#ifdef FEAT_TOOLBAR
1123
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001124/*
1125 * Icons used by the toolbar code.
1126 */
1127#include "gui_x11_pm.h"
1128
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001129static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001130
1131/*
1132 * Read an Xpm file. Return OK or FAIL.
1133 */
1134 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001135check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001136{
1137 XpmAttributes attrs;
1138 int status;
1139 Pixmap mask;
1140 Pixmap map;
1141
1142 attrs.valuemask = 0;
1143
Bram Moolenaar734a8672019-12-02 22:49:38 +01001144 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001145 status = XpmReadFileToPixmap(gui.dpy,
1146 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1147 (char *)path, &map, &mask, &attrs);
1148 XpmFreeAttributes(&attrs);
1149
1150 if (status == XpmSuccess)
1151 return OK;
1152 return FAIL;
1153}
1154
1155
1156/*
1157 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001158 * When it's to be read from a file, "fname" is set to the file name
1159 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001160 * Return a blank pixmap if it fails.
1161 */
1162 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001163get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001164{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001165 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1166 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001167 int res;
1168
Bram Moolenaar7c626922005-02-07 22:01:03 +00001169 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001170 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001171
1172 if (menu->iconfile != NULL)
1173 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001174 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001175 gui_find_iconfile(menu->iconfile, buf, "xpm");
1176 res = check_xpm(buf);
1177
Bram Moolenaar734a8672019-12-02 22:49:38 +01001178 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001179 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1180 res = check_xpm(buf);
1181 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001182 {
1183 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001184 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001185 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001186 }
1187
1188 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1189 {
1190 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001191 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001192 xpm = built_in_pixmaps[menu->iconidx];
1193 else
1194 xpm = tb_blank_xpm;
1195 }
1196
1197 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001199
1200/*
1201 * Add arguments for the toolbar pixmap to a menu item.
1202 */
1203 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001204add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001205{
1206 vim_free(menu->xpm_fname);
1207 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1208 if (menu->xpm == NULL)
1209 {
1210 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1211 }
1212 else
1213 {
1214 if (menu->xpm_fname != NULL)
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001215 {
Bram Moolenaar7c626922005-02-07 22:01:03 +00001216 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar26cd3062020-09-20 21:13:27 +02001217 }
Bram Moolenaar7c626922005-02-07 22:01:03 +00001218 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1219 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1220 }
1221 return n;
1222}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001223#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224
1225 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001226gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227{
1228 XmString label;
1229 vimmenu_T *parent = menu->parent;
1230
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001232 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1234 return;
1235# endif
1236
1237# ifdef FEAT_TOOLBAR
1238 if (menu_is_toolbar(parent->name))
1239 {
1240 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001241 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 int n;
1243 Arg args[18];
1244
1245 n = 0;
1246 if (menu_is_separator(menu->name))
1247 {
1248 char *cp;
1249 Dimension wid;
1250
1251 /*
1252 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1253 * a width specifier. If no width is specified then we choose one.
1254 */
1255 cp = (char *)vim_strchr(menu->name, ':');
1256 if (cp != NULL)
1257 wid = (Dimension)atoi(++cp);
1258 else
1259 wid = 4;
1260
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 type = xmSeparatorWidgetClass;
1262 XtSetArg(args[n], XmNwidth, wid); n++;
1263 XtSetArg(args[n], XmNminWidth, wid); n++;
1264 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001265 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266 }
1267 else
1268 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001269 // Without shadows one can't sense whatever the button has been
1270 // pressed or not! However we want to save a bit of space...
1271 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001272 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1274 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1275 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001276 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001277 // Set the label here, so that we can switch between icons/text
1278 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001279 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1280 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001281
Bram Moolenaar7c626922005-02-07 22:01:03 +00001282 n = add_pixmap_args(menu, args, n);
1283
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001284 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 }
1286
1287 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1288 if (menu->id == NULL)
1289 {
1290 menu->id = XtCreateManagedWidget((char *)menu->dname,
1291 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001292 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293 {
1294 XtAddCallback(menu->id,
1295 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 }
1297 }
1298 else
1299 XtSetValues(menu->id, args, n);
1300 if (xms != NULL)
1301 XmStringFree(xms);
1302
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001303# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001305# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306
1307 menu->parent = parent;
1308 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001309 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310 if (!XtIsManaged(XtParent(toolBar))
1311 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1312 gui_mch_show_toolbar(TRUE);
1313 gui.toolbar_height = gui_mch_compute_toolbar_height();
1314 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001315 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316# endif
1317
Bram Moolenaar734a8672019-12-02 22:49:38 +01001318 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 if (parent->submenu_id == (Widget)0)
1320 return;
1321
1322 menu->submenu_id = (Widget)0;
1323
Bram Moolenaar734a8672019-12-02 22:49:38 +01001324 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 if (menu_is_separator(menu->name))
1326 {
1327 menu->id = XtVaCreateWidget("subMenu",
1328 xmSeparatorGadgetClass, parent->submenu_id,
1329#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001330 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1332 ? 1 : 0),
1333#endif
1334 NULL);
1335 gui_motif_menu_colors(menu->id);
1336 return;
1337 }
1338
1339 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1340 if (label == NULL)
1341 return;
1342 menu->id = XtVaCreateWidget("subMenu",
1343 xmPushButtonWidgetClass, parent->submenu_id,
1344 XmNlabelString, label,
1345 XmNmnemonic, menu->mnemonic,
1346#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001347 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1349 ? 1 : 0),
1350#endif
1351 NULL);
1352 gui_motif_menu_colors(menu->id);
1353 gui_motif_menu_fontlist(menu->id);
1354 XmStringFree(label);
1355
1356 if (menu->id != (Widget)0)
1357 {
1358 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1359 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001360 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 gui_motif_add_actext(menu);
1362 }
1363}
1364
1365#if (XmVersion <= 1002) || defined(PROTO)
1366/*
1367 * This function will destroy/create the popup menus dynamically,
1368 * according to the value of 'mousemodel'.
1369 * This will fix the "right mouse button freeze" that occurs when
1370 * there exists a popup menu but it isn't managed.
1371 */
1372 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001373gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374{
1375 int idx = 0;
1376
Bram Moolenaar734a8672019-12-02 22:49:38 +01001377 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 if (!gui.in_use)
1379 return;
1380
1381 while (menu)
1382 {
1383 if (menu->children != NULL)
1384 {
1385 if (menu_is_popup(menu->name))
1386 {
1387 if (mouse_model_popup())
1388 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001389 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 gui_mch_add_menu(menu, idx);
1391 gui_motif_update_mousemodel(menu->children);
1392 }
1393 else
1394 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001395 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 gui_motif_update_mousemodel(menu->children);
1397 gui_mch_destroy_menu(menu);
1398 }
1399 }
1400 }
1401 else if (menu_is_child_of_popup(menu))
1402 {
1403 if (mouse_model_popup())
1404 gui_mch_add_menu_item(menu, idx);
1405 else
1406 gui_mch_destroy_menu(menu);
1407 }
1408 menu = menu->next;
1409 ++idx;
1410 }
1411}
1412#endif
1413
1414 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001415gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416{
1417 if (menuBar == (Widget)0)
1418 return;
1419 gui_motif_menu_colors(menuBar);
1420#ifdef FEAT_TOOLBAR
1421 gui_motif_menu_colors(toolBarFrame);
1422 gui_motif_menu_colors(toolBar);
1423#endif
1424
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001425 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426}
1427
1428 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001429gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430{
1431 if (menuBar == (Widget)0)
1432 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001433 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {
1435 Dimension height;
1436 Position w, h;
1437
1438 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1439 gui.menu_height = height;
1440
1441 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1442 gui_resize_shell(w, h
1443#ifdef FEAT_XIM
1444 - xim_get_status_area_height()
1445#endif
1446 );
1447 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001448 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 ui_new_shellsize();
1450}
1451
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001452#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001454gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455{
1456# ifdef FEAT_TOOLBAR
1457 vimmenu_T *menu;
1458
1459 if (toolBar == (Widget)0)
1460 return;
1461
1462 menu = gui_find_menu((char_u *)"ToolBar");
1463 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001464 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465# endif
1466}
1467
1468 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001469gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470{
1471# ifdef FEAT_TOOLBAR
1472 vimmenu_T *toolbar;
1473
1474 if (toolBar == (Widget)0)
1475 return;
1476
1477 toolbar = gui_find_menu((char_u *)"ToolBar");
1478 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001479 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480# endif
1481}
1482#endif
1483
1484 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001485submenu_change(
1486 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001487 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488{
1489 vimmenu_T *mp;
1490
1491 for (mp = menu; mp != NULL; mp = mp->next)
1492 {
1493 if (mp->id != (Widget)0)
1494 {
1495 if (colors)
1496 {
1497 gui_motif_menu_colors(mp->id);
1498#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001499 // For a toolbar item: Free the pixmap and allocate a new one,
1500 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001501 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001503 int n = 0;
1504 Arg args[18];
1505
Bram Moolenaar7c626922005-02-07 22:01:03 +00001506 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001507 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001509# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001510 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 if (mp->tip != NULL)
1512 {
1513 Arg args[2];
1514
1515 args[0].name = XmNbackground;
1516 args[0].value = gui.tooltip_bg_pixel;
1517 args[1].name = XmNforeground;
1518 args[1].value = gui.tooltip_fg_pixel;
1519 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1520 }
1521# endif
1522#endif
1523 }
1524 else
1525 {
1526 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001527#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001528 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 if (mp->tip != NULL)
1530 {
1531 Arg args[1];
1532
1533 args[0].name = XmNfontList;
1534 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1535 &gui.tooltip_fontset);
1536 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1537 }
1538#endif
1539 }
1540 }
1541
1542 if (mp->children != NULL)
1543 {
1544#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001545 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 if (mp->submenu_id != (Widget)0)
1547 {
1548 if (colors)
1549 gui_motif_menu_colors(mp->submenu_id);
1550 else
1551 gui_motif_menu_fontlist(mp->submenu_id);
1552 toggle_tearoff(mp->submenu_id);
1553 }
1554#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001555 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001556 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 }
1558 }
1559}
1560
1561/*
1562 * Destroy the machine specific menu widget.
1563 */
1564 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001565gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001567 // Please be sure to destroy the parent widget first (i.e. menu->id).
1568 // On the other hand, problems have been reported that the submenu must be
1569 // deleted first...
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 if (menu->submenu_id != (Widget)0)
1571 {
1572 XtDestroyWidget(menu->submenu_id);
1573 menu->submenu_id = (Widget)0;
1574 }
1575
1576 if (menu->id != (Widget)0)
1577 {
1578 Widget parent;
1579
1580 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001581#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001582 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001584 // We try to destroy this before the actual menu, because there are
1585 // callbacks, etc. that will be unregistered during the tooltip
1586 // destruction.
1587 //
1588 // If you call "gui_mch_destroy_beval_area()" after destroying
1589 // menu->id, then the tooltip's window will have already been
1590 // deallocated by Xt, and unknown behaviour will ensue (probably
1591 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 gui_mch_destroy_beval_area(menu->tip);
1593 menu->tip = NULL;
1594 }
1595#endif
1596 XtDestroyWidget(menu->id);
1597 menu->id = (Widget)0;
1598 if (parent == menuBar)
1599 gui_mch_compute_menu_height((Widget)0);
1600#ifdef FEAT_TOOLBAR
1601 else if (parent == toolBar)
1602 {
1603 Cardinal num_children;
1604
Bram Moolenaar734a8672019-12-02 22:49:38 +01001605 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1607 if (num_children == 0)
1608 gui_mch_show_toolbar(FALSE);
1609 else
1610 gui.toolbar_height = gui_mch_compute_toolbar_height();
1611 }
1612#endif
1613 }
1614}
1615
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001617gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618{
1619#ifdef MOTIF_POPUP
1620 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1621 XtManageChild(menu->submenu_id);
1622#endif
1623}
1624
Bram Moolenaar734a8672019-12-02 22:49:38 +01001625#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626
1627/*
1628 * Set the menu and scrollbar colors to their default values.
1629 */
1630 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001631gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632{
1633 if (gui.in_use)
1634 {
Bram Moolenaare8504392022-03-13 14:45:03 +00001635 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
1636 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
1637 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
1638 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001639#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 gui.tooltip_fg_pixel =
1641 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1642 gui.tooltip_bg_pixel =
1643 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1644#endif
1645 }
1646}
1647
1648
1649/*
1650 * Scrollbar stuff.
1651 */
1652
1653 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001654gui_mch_set_scrollbar_thumb(
1655 scrollbar_T *sb,
1656 long val,
1657 long size,
1658 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659{
1660 if (sb->id != (Widget)0)
1661 XtVaSetValues(sb->id,
1662 XmNvalue, val,
1663 XmNsliderSize, size,
1664 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001665 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 NULL);
1667}
1668
1669 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001670gui_mch_set_scrollbar_pos(
1671 scrollbar_T *sb,
1672 int x,
1673 int y,
1674 int w,
1675 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676{
1677 if (sb->id != (Widget)0)
1678 {
1679 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1680 {
1681 if (y == 0)
1682 h -= gui.border_offset;
1683 else
1684 y -= gui.border_offset;
1685 XtVaSetValues(sb->id,
1686 XmNtopOffset, y,
1687 XmNbottomOffset, -y - h,
1688 XmNwidth, w,
1689 NULL);
1690 }
1691 else
1692 XtVaSetValues(sb->id,
1693 XmNtopOffset, y,
1694 XmNleftOffset, x,
1695 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1696 ? gui.scrollbar_width : 0,
1697 XmNheight, h,
1698 NULL);
1699 XtManageChild(sb->id);
1700 }
1701}
1702
Bram Moolenaar203ec772020-07-17 20:43:43 +02001703 int
1704gui_mch_get_scrollbar_xpadding(void)
1705{
qsmodo28f1a512022-02-07 15:57:50 +00001706 int xpad;
1707 Dimension tw, ww;
1708 Position tx;
1709
1710 XtVaGetValues(textArea, XtNwidth, &tw, XtNx, &tx, NULL);
1711 XtVaGetValues(vimShell, XtNwidth, &ww, NULL);
1712 xpad = ww - tw - tx - gui.scrollbar_width;
1713 return (xpad < 0) ? 0 : xpad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001714}
1715
1716 int
1717gui_mch_get_scrollbar_ypadding(void)
1718{
qsmodo28f1a512022-02-07 15:57:50 +00001719 int ypad;
1720 Dimension th, wh;
1721 Position ty;
1722
1723 XtVaGetValues(textArea, XtNheight, &th, XtNy, &ty, NULL);
1724 XtVaGetValues(vimShell, XtNheight, &wh, NULL);
1725 ypad = wh - th - ty - gui.scrollbar_height;
1726 return (ypad < 0) ? 0 : ypad;
Bram Moolenaar203ec772020-07-17 20:43:43 +02001727}
1728
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001730gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731{
1732 Arg args[16];
1733 int n;
1734
1735 if (sb->id != (Widget)0)
1736 {
1737 n = 0;
1738 if (flag)
1739 {
1740 switch (sb->type)
1741 {
1742 case SBAR_LEFT:
1743 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1744 break;
1745
1746 case SBAR_RIGHT:
1747 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1748 break;
1749
1750 case SBAR_BOTTOM:
1751 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1752 break;
1753 }
1754 XtSetValues(textArea, args, n);
1755 XtManageChild(sb->id);
1756 }
1757 else
1758 {
1759 if (!gui.which_scrollbars[sb->type])
1760 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001761 // The scrollbars of this type are all disabled, adjust the
1762 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 switch (sb->type)
1764 {
1765 case SBAR_LEFT:
1766 XtSetArg(args[n], XmNleftOffset, 0); n++;
1767 break;
1768
1769 case SBAR_RIGHT:
1770 XtSetArg(args[n], XmNrightOffset, 0); n++;
1771 break;
1772
1773 case SBAR_BOTTOM:
1774 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1775 break;
1776 }
1777 XtSetValues(textArea, args, n);
1778 }
1779 XtUnmanageChild(sb->id);
1780 }
1781 }
1782}
1783
1784 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001785gui_mch_create_scrollbar(
1786 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001787 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788{
1789 Arg args[16];
1790 int n;
1791
1792 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 XtSetArg(args[n], XmNminimum, 0); n++;
1794 XtSetArg(args[n], XmNorientation,
1795 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1796
1797 switch (sb->type)
1798 {
1799 case SBAR_LEFT:
1800 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1801 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1802 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1803 break;
1804
1805 case SBAR_RIGHT:
1806 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1807 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1808 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1809 break;
1810
1811 case SBAR_BOTTOM:
1812 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1813 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1814 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1815 break;
1816 }
1817
1818 sb->id = XtCreateWidget("scrollBar",
1819 xmScrollBarWidgetClass, textAreaForm, args, n);
1820
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 if (sb->id != (Widget)0)
1822 {
1823 gui_mch_set_scrollbar_colors(sb);
1824 XtAddCallback(sb->id, XmNvalueChangedCallback,
1825 scroll_cb, (XtPointer)sb->ident);
1826 XtAddCallback(sb->id, XmNdragCallback,
1827 scroll_cb, (XtPointer)sb->ident);
1828 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1829 (XtPointer)0);
1830 }
1831}
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}