blob: d5a627609a50948dd84bced3e170efe5b9a48f33 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI/Motif support by Robert Webb
5 *
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
9 */
10
Bram Moolenaarf7506ca2017-02-25 16:01:49 +010011#include "vim.h"
12
Bram Moolenaar071d4272004-06-13 20:20:40 +000013#include <Xm/Form.h>
14#include <Xm/RowColumn.h>
15#include <Xm/PushB.h>
16#include <Xm/Text.h>
17#include <Xm/TextF.h>
18#include <Xm/Separator.h>
19#include <Xm/Label.h>
20#include <Xm/CascadeB.h>
21#include <Xm/ScrollBar.h>
22#include <Xm/MenuShell.h>
23#include <Xm/DrawingA.h>
24#if (XmVersion >= 1002)
25# include <Xm/RepType.h>
26#endif
27#include <Xm/Frame.h>
28#include <Xm/LabelG.h>
29#include <Xm/ToggleBG.h>
30#include <Xm/SeparatoG.h>
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000031#include <Xm/XmP.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33#include <X11/keysym.h>
34#include <X11/Xatom.h>
35#include <X11/StringDefs.h>
36#include <X11/Intrinsic.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#ifdef HAVE_X11_XPM_H
Bram Moolenaar88c86eb2019-01-17 17:13:30 +010038# if defined(VMS)
39# include <xpm.h>
40# else
41# include <X11/xpm.h>
42# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#else
44# ifdef HAVE_XM_XPMP_H
45# include <Xm/XpmP.h>
46# endif
47#endif
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000048#ifdef HAVE_XM_NOTEBOOK_H
49# include <Xm/Notebook.h>
50#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaar734a8672019-12-02 22:49:38 +010052#include "gui_xmebw.h" // for our Enhanced Button Widget
Bram Moolenaarb7fcef52005-01-02 11:31:05 +000053
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
55# include "../pixmaps/alert.xpm"
56# include "../pixmaps/error.xpm"
57# include "../pixmaps/generic.xpm"
58# include "../pixmaps/info.xpm"
59# include "../pixmaps/quest.xpm"
60#endif
61
62#define MOTIF_POPUP
63
64extern Widget vimShell;
65
66static Widget vimForm;
67static Widget textAreaForm;
68Widget textArea;
69#ifdef FEAT_TOOLBAR
70static Widget toolBarFrame;
71static Widget toolBar;
72#endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +000073#ifdef FEAT_GUI_TABLINE
74static Widget tabLine;
75static Widget tabLine_menu = 0;
76static int showing_tabline = 0;
77#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000078#ifdef FEAT_FOOTER
79static Widget footer;
80#endif
81#ifdef FEAT_MENU
82# if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +010083// remember the last set value for the tearoff item
Bram Moolenaar071d4272004-06-13 20:20:40 +000084static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
85# endif
86static Widget menuBar;
87#endif
88
Bram Moolenaar071d4272004-06-13 20:20:40 +000089#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000090# ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +010091static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
92static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000093# endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +010094static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
Bram Moolenaard25c16e2016-01-29 22:13:30 +010097static void gui_motif_menu_colors(Widget id);
98static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100#if (XmVersion >= 1002)
101# define STRING_TAG XmFONTLIST_DEFAULT_TAG
102#else
103# define STRING_TAG XmSTRING_DEFAULT_CHARSET
104#endif
105
106/*
107 * Call-back routines.
108 */
109
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110 static void
Bram Moolenaarc1ab6762016-01-30 19:45:49 +0100111scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112{
113 scrollbar_T *sb;
114 long value;
115 int dragging;
116
117 sb = gui_find_scrollbar((long)client_data);
118
119 value = ((XmScrollBarCallbackStruct *)call_data)->value;
120 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
121 (int)XmCR_DRAG);
122 gui_drag_scrollbar(sb, value, dragging);
123}
124
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000125#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000126 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100127tabline_cb(
128 Widget w UNUSED,
129 XtPointer client_data UNUSED,
130 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000131{
132 XmNotebookCallbackStruct *nptr;
133
134 nptr = (XmNotebookCallbackStruct *)call_data;
135 if (nptr->reason != (int)XmCR_NONE)
136 send_tabline_event(nptr->page_number);
137}
138
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000139 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100140tabline_button_cb(
141 Widget w,
142 XtPointer client_data UNUSED,
143 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000144{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000145 int cmd, tab_idx;
146
147 XtVaGetValues(w, XmNuserData, &cmd, NULL);
148 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
149
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000150 send_tabline_menu_event(tab_idx, cmd);
151}
152
153/*
154 * Tabline single mouse click timeout handler
155 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000156 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100157motif_tabline_timer_cb (
158 XtPointer timed_out,
159 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000160{
161 *((int *)timed_out) = TRUE;
162}
163
164/*
165 * check if the tabline tab scroller is clicked
166 */
167 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100168tabline_scroller_clicked(
169 char *scroller_name,
170 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000171{
172 Widget tab_scroll_w;
173 Position pos_x, pos_y;
174 Dimension width, height;
175
176 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
177 if (tab_scroll_w != (Widget)0) {
178 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
179 &width, XmNheight, &height, NULL);
180 if (pos_x >= 0) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100181 // Tab scroller (next) is visible
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000182 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
183 (event->y >= pos_y) && (event->y <= pos_y + height)) {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100184 // Clicked on the scroller
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000185 return TRUE;
186 }
187 }
188 }
189 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000190}
191
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000192 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100193tabline_menu_cb(
194 Widget w,
195 XtPointer closure UNUSED,
196 XEvent *e,
197 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000198{
199 Widget tab_w;
200 XButtonPressedEvent *event;
201 int tab_idx = 0;
202 WidgetList children;
203 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000204 static XtIntervalId timer = (XtIntervalId)0;
205 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000206
207 event = (XButtonPressedEvent *)e;
208
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000209 if (event->button == Button1)
210 {
211 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
212 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
213 return;
214
215 if (!timed_out)
216 {
217 XtRemoveTimeOut(timer);
218 timed_out = TRUE;
219
220 /*
221 * Double click on the tabline gutter, add a new tab
222 */
223 send_tabline_menu_event(0, TABLINE_MENU_NEW);
224 }
225 else
226 {
227 /*
228 * Single click on the tabline gutter, start a timer to check
229 * for double clicks
230 */
231 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
232 motif_tabline_timer_cb, &timed_out);
233 timed_out = FALSE;
234 }
235 return;
236 }
237
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000238 if (event->button != Button3)
239 return;
240
Bram Moolenaar734a8672019-12-02 22:49:38 +0100241 // When ignoring events don't show the menu.
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000242 if (hold_gui_events
243# ifdef FEAT_CMDWIN
244 || cmdwin_type != 0
245# endif
246 )
247 return;
248
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000249 if (event->subwindow != None)
250 {
251 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaar734a8672019-12-02 22:49:38 +0100252 // LINTED: avoid warning: dubious operation on enum
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000253 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
254 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
255 }
256
257 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
258 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
259 &numChildren, NULL);
260 XtManageChildren(children, numChildren);
261 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
262 XtManageChild(tabLine_menu);
263}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000264
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000265 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100266tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000267{
268 int nr;
269 tabpage_T *tp;
270
271 if (beval->target == (Widget)0)
272 return;
273
274 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
275 tp = find_tabpage(nr);
276 if (tp == NULL)
277 return;
278
279 get_tabline_label(tp, TRUE);
280 gui_mch_post_balloon(beval, NameBuff);
281}
282
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000283#endif
284
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285/*
286 * End of call-back routines
287 */
288
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289/*
290 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000291 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000292 */
293
294#include <Xm/XmP.h>
295#include <Xm/LabelP.h>
296
297static XtExposeProc old_label_expose = NULL;
298
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000299 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100300label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000301{
302 GC insensitiveGC;
303 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000304 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000305
306 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
307
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000308 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000309 (*old_label_expose)(_w, _event, _region);
310 else
311 {
312 XGCValues values;
313 XtGCMask mask;
314 XtGCMask dynamic;
315 XFontStruct *fs;
316
317 _XmFontListGetDefaultFont(lw->label.font, &fs);
318
Bram Moolenaar734a8672019-12-02 22:49:38 +0100319 // FIXME: we should be doing the whole drawing ourself here.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000320 insensitiveGC = lw->label.insensitive_GC;
321
322 mask = GCForeground | GCBackground | GCGraphicsExposures;
323 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
324 values.graphics_exposures = False;
325
326 if (fs != 0)
327 {
328 mask |= GCFont;
329 values.font = fs->fid;
330 }
331
332 if (lw->primitive.top_shadow_pixmap != None
333 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
334 {
335 mask |= GCFillStyle | GCTile;
336 values.fill_style = FillTiled;
337 values.tile = lw->primitive.top_shadow_pixmap;
338 }
339
340 lw->label.TextRect.x += 1;
341 lw->label.TextRect.y += 1;
342 if (lw->label._acc_text != 0)
343 {
344 lw->label.acc_TextRect.x += 1;
345 lw->label.acc_TextRect.y += 1;
346 }
347
348 values.foreground = lw->primitive.top_shadow_color;
349 values.background = lw->core.background_pixel;
350
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000351 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
352 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000353 (*old_label_expose)(_w, _event, _region);
354 XtReleaseGC(_w, lw->label.insensitive_GC);
355
356 lw->label.TextRect.x -= 1;
357 lw->label.TextRect.y -= 1;
358 if (lw->label._acc_text != 0)
359 {
360 lw->label.acc_TextRect.x -= 1;
361 lw->label.acc_TextRect.y -= 1;
362 }
363
364 values.foreground = lw->primitive.bottom_shadow_color;
365 values.background = lw->core.background_pixel;
366
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000367 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
368 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000369 (*old_label_expose)(_w, _event, _region);
370 XtReleaseGC(_w, lw->label.insensitive_GC);
371
372 lw->label.insensitive_GC = insensitiveGC;
373 }
374}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000375
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376/*
377 * Create all the motif widgets necessary.
378 */
379 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100380gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000382#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000383 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000384 Arg args[10];
385 int n;
386 XmString xms;
387#endif
388
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000389 /*
390 * Install the 3D shade effect drawing routines.
391 */
392 if (old_label_expose == NULL)
393 {
394 old_label_expose = xmLabelWidgetClass->core_class.expose;
395 xmLabelWidgetClass->core_class.expose = label_expose;
396 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000397
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 /*
399 * Start out by adding the configured border width into the border offset
400 */
401 gui.border_offset = gui.border_width;
402
403 /*
404 * Install the tearOffModel resource converter.
405 */
406#if (XmVersion >= 1002)
407 XmRepTypeInstallTearOffModelConverter();
408#endif
409
Bram Moolenaar734a8672019-12-02 22:49:38 +0100410 // Make sure the "Quit" menu entry of the window manager is ignored
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
412
413 vimForm = XtVaCreateManagedWidget("vimForm",
414 xmFormWidgetClass, vimShell,
415 XmNborderWidth, 0,
416 XmNhighlightThickness, 0,
417 XmNshadowThickness, 0,
418 XmNmarginWidth, 0,
419 XmNmarginHeight, 0,
420 XmNresizePolicy, XmRESIZE_ANY,
421 NULL);
422 gui_motif_menu_colors(vimForm);
423
424#ifdef FEAT_MENU
425 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100426 Arg al[7]; // Make sure there is enough room for arguments!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427 int ac = 0;
428
429# if (XmVersion >= 1002)
430 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
431# endif
432 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
433 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
434 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
435# ifndef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100436 // Always stick to right hand side.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
438# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000439 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
441 XtManageChild(menuBar);
442
Bram Moolenaar734a8672019-12-02 22:49:38 +0100443 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 XtVaGetValues(menuBar,
445 XmNbackground, &gui.menu_def_bg_pixel,
446 XmNforeground, &gui.menu_def_fg_pixel,
447 NULL);
448 gui_motif_menu_colors(menuBar);
449 }
450#endif
451
452#ifdef FEAT_TOOLBAR
453 /*
454 * Create an empty ToolBar. We should get buttons defined from menu.vim.
455 */
456 toolBarFrame = XtVaCreateWidget("toolBarFrame",
457 xmFrameWidgetClass, vimForm,
458 XmNshadowThickness, 0,
459 XmNmarginHeight, 0,
460 XmNmarginWidth, 0,
461 XmNleftAttachment, XmATTACH_FORM,
462 XmNrightAttachment, XmATTACH_FORM,
463 NULL);
464 gui_motif_menu_colors(toolBarFrame);
465
466 toolBar = XtVaCreateManagedWidget("toolBar",
467 xmRowColumnWidgetClass, toolBarFrame,
468 XmNchildType, XmFRAME_WORKAREA_CHILD,
469 XmNrowColumnType, XmWORK_AREA,
470 XmNorientation, XmHORIZONTAL,
471 XmNtraversalOn, False,
472 XmNisHomogeneous, False,
473 XmNpacking, XmPACK_TIGHT,
474 XmNspacing, 0,
475 XmNshadowThickness, 0,
476 XmNhighlightThickness, 0,
477 XmNmarginHeight, 0,
478 XmNmarginWidth, 0,
479 XmNadjustLast, True,
480 NULL);
481 gui_motif_menu_colors(toolBar);
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483#endif
484
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000485#ifdef FEAT_GUI_TABLINE
Bram Moolenaar734a8672019-12-02 22:49:38 +0100486 // Create the Vim GUI tabline
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000487 n = 0;
488 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
489 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
490 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
491 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
492 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
493 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
494 XtSetArg(args[n], XmNshadowThickness, 0); n++;
495 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
496 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
497 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
498
499 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
500 NULL);
501 XtAddEventHandler(tabLine, ButtonPressMask, False,
502 (XtEventHandler)tabline_menu_cb, NULL);
503
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000504 gui.tabline_height = TABLINE_HEIGHT;
505
Bram Moolenaar18144c82006-04-12 21:52:12 +0000506 /*
507 * Set the size of the minor next/prev scrollers to zero, so
508 * that they are not displayed. Due to a bug in OpenMotif 2.3,
509 * even if these children widget are unmanaged, they are again
510 * managed by the Notebook widget and the notebook widget geometry
511 * is adjusted to account for the minor scroller widgets.
512 */
513 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
514 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
515 XmNtraversalOn, False, NULL);
516 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
517 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
518 XmNtraversalOn, False, NULL);
519
Bram Moolenaar29547192018-12-11 20:39:19 +0100520 // Create the tabline popup menu
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000521 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
522
Bram Moolenaar29547192018-12-11 20:39:19 +0100523 // Add the buttons to the tabline popup menu
524 n = 0;
525 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
526 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
527 XtSetArg(args[n], XmNlabelString, xms); n++;
528 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
529 XtAddCallback(button, XmNactivateCallback,
530 (XtCallbackProc)tabline_button_cb, NULL);
531 XmStringFree(xms);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000532
533 n = 0;
534 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
535 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
536 XtSetArg(args[n], XmNlabelString, xms); n++;
537 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
538 XtAddCallback(button, XmNactivateCallback,
539 (XtCallbackProc)tabline_button_cb, NULL);
540 XmStringFree(xms);
541
542 n = 0;
543 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
544 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
545 XtSetArg(args[n], XmNlabelString, xms); n++;
546 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
547 XtAddCallback(button, XmNactivateCallback,
548 (XtCallbackProc)tabline_button_cb, NULL);
549 XmStringFree(xms);
550#endif
551
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
553 xmFormWidgetClass, vimForm,
554 XmNleftAttachment, XmATTACH_FORM,
555 XmNrightAttachment, XmATTACH_FORM,
556 XmNbottomAttachment, XmATTACH_FORM,
557 XmNtopAttachment, XmATTACH_FORM,
558 XmNmarginWidth, 0,
559 XmNmarginHeight, 0,
560 XmNresizePolicy, XmRESIZE_ANY,
561 NULL);
562 gui_motif_scroll_colors(textAreaForm);
563
564 textArea = XtVaCreateManagedWidget("textArea",
565 xmDrawingAreaWidgetClass, textAreaForm,
566 XmNforeground, gui.norm_pixel,
567 XmNbackground, gui.back_pixel,
568 XmNleftAttachment, XmATTACH_FORM,
569 XmNtopAttachment, XmATTACH_FORM,
570 XmNrightAttachment, XmATTACH_FORM,
571 XmNbottomAttachment, XmATTACH_FORM,
572
573 /*
574 * These take some control away from the user, but avoids making them
575 * add resources to get a decent looking setup.
576 */
577 XmNborderWidth, 0,
578 XmNhighlightThickness, 0,
579 XmNshadowThickness, 0,
580 NULL);
581
582#ifdef FEAT_FOOTER
583 /*
584 * Create the Footer.
585 */
586 footer = XtVaCreateWidget("footer",
587 xmLabelGadgetClass, vimForm,
588 XmNalignment, XmALIGNMENT_BEGINNING,
589 XmNmarginHeight, 0,
590 XmNmarginWidth, 0,
591 XmNtraversalOn, False,
592 XmNrecomputeSize, False,
593 XmNleftAttachment, XmATTACH_FORM,
594 XmNleftOffset, 5,
595 XmNrightAttachment, XmATTACH_FORM,
596 XmNbottomAttachment, XmATTACH_FORM,
597 NULL);
598 gui_mch_set_footer((char_u *) "");
599#endif
600
601 /*
602 * Install the callbacks.
603 */
604 gui_x11_callbacks(textArea, vimForm);
605
Bram Moolenaar734a8672019-12-02 22:49:38 +0100606 // Pretend we don't have input focus, we will get an event if we do.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 gui.in_focus = FALSE;
608}
609
610/*
611 * Called when the GUI is not going to start after all.
612 */
613 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100614gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615{
616 textArea = NULL;
617#ifdef FEAT_MENU
618 menuBar = NULL;
619#endif
620}
621
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100623gui_mch_set_text_area_pos(
624 int x UNUSED,
625 int y UNUSED,
626 int w UNUSED,
627 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628{
629#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +0100630 // Give keyboard focus to the textArea instead of the toolbar.
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000631 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
633}
634
635 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100636gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637{
638 if (textArea != NULL)
639#if (XmVersion >= 1002)
640 XmChangeColor(textArea, gui.back_pixel);
641#else
642 XtVaSetValues(textArea,
643 XmNbackground, gui.back_pixel,
644 NULL);
645#endif
646}
647
648/*
649 * Manage dialog centered on pointer. This could be used by the Athena code as
650 * well.
651 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000652 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100653manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654{
655 Widget shell = XtParent(dialog_child);
656 Window root, child;
657 unsigned int mask;
658 unsigned int width, height, border_width, depth;
659 int x, y, win_x, win_y, maxX, maxY;
660 Boolean mappedWhenManaged;
661
Bram Moolenaar734a8672019-12-02 22:49:38 +0100662 // Temporarily set value of XmNmappedWhenManaged
663 // to stop the dialog from popping up right away
Bram Moolenaar46784652008-06-20 09:40:11 +0000664 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
665 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666
667 XtManageChild(dialog_child);
668
Bram Moolenaar734a8672019-12-02 22:49:38 +0100669 // Get the pointer position (x, y)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
671 &x, &y, &win_x, &win_y, &mask);
672
Bram Moolenaar734a8672019-12-02 22:49:38 +0100673 // Translate the pointer position (x, y) into a position for the new
674 // window that will place the pointer at its center
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
676 &width, &height, &border_width, &depth);
677 width += 2 * border_width;
678 height += 2 * border_width;
679 x -= width / 2;
680 y -= height / 2;
681
Bram Moolenaar734a8672019-12-02 22:49:38 +0100682 // Ensure that the dialog remains on screen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 maxX = XtScreen(shell)->width - width;
684 maxY = XtScreen(shell)->height - height;
685 if (x < 0)
686 x = 0;
687 if (x > maxX)
688 x = maxX;
689 if (y < 0)
690 y = 0;
691 if (y > maxY)
692 y = maxY;
693
Bram Moolenaar734a8672019-12-02 22:49:38 +0100694 // Set desired window position in the DialogShell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
696
Bram Moolenaar734a8672019-12-02 22:49:38 +0100697 // Map the widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 XtMapWidget(shell);
699
Bram Moolenaar734a8672019-12-02 22:49:38 +0100700 // Restore the value of XmNmappedWhenManaged
Bram Moolenaar46784652008-06-20 09:40:11 +0000701 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702}
703
Bram Moolenaarbb1969b2019-01-17 15:45:25 +0100704#if defined(FEAT_MENU) || defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705
706/*
707 * Encapsulate the way an XmFontList is created.
708 */
709 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100710gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711{
712 XmFontList font_list;
713
714# if (XmVersion <= 1001)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100715 // Motif 1.1 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 font_list = XmFontListCreate(font, STRING_TAG);
717# else
Bram Moolenaar734a8672019-12-02 22:49:38 +0100718 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 XmFontListEntry font_list_entry;
720
721 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
722 (XtPointer)font);
723 font_list = XmFontListAppendEntry(NULL, font_list_entry);
724 XmFontListEntryFree(&font_list_entry);
725# endif
726 return font_list;
727}
728
729# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
730 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100731gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732{
733 XmFontList font_list;
734
Bram Moolenaar734a8672019-12-02 22:49:38 +0100735 // Motif 1.2 method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 XmFontListEntry font_list_entry;
737
738 font_list_entry = XmFontListEntryCreate(STRING_TAG,
739 XmFONT_IS_FONTSET,
740 (XtPointer)*fontset);
741 font_list = XmFontListAppendEntry(NULL, font_list_entry);
742 XmFontListEntryFree(&font_list_entry);
743 return font_list;
744}
745# endif
746
747#endif
748
749#if defined(FEAT_MENU) || defined(PROTO)
750/*
751 * Menu stuff.
752 */
753
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100754static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100756static void toggle_tearoff(Widget wid);
757static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100759static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100761static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762static int menu_enabled = TRUE;
763
764 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100765gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766{
767 if (flag)
768 {
769 XtManageChild(menuBar);
770#ifdef FEAT_TOOLBAR
771 if (XtIsManaged(XtParent(toolBar)))
772 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100773 // toolBar is attached to top form
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 XtVaSetValues(XtParent(toolBar),
775 XmNtopAttachment, XmATTACH_WIDGET,
776 XmNtopWidget, menuBar,
777 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000778#ifdef FEAT_GUI_TABLINE
779 if (showing_tabline)
780 {
781 XtVaSetValues(tabLine,
782 XmNtopAttachment, XmATTACH_WIDGET,
783 XmNtopWidget, XtParent(toolBar),
784 NULL);
785 XtVaSetValues(textAreaForm,
786 XmNtopAttachment, XmATTACH_WIDGET,
787 XmNtopWidget, tabLine,
788 NULL);
789 }
790 else
791#endif
792 XtVaSetValues(textAreaForm,
793 XmNtopAttachment, XmATTACH_WIDGET,
794 XmNtopWidget, XtParent(toolBar),
795 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 }
797 else
798#endif
799 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000800#ifdef FEAT_GUI_TABLINE
801 if (showing_tabline)
802 {
803 XtVaSetValues(tabLine,
804 XmNtopAttachment, XmATTACH_WIDGET,
805 XmNtopWidget, menuBar,
806 NULL);
807 XtVaSetValues(textAreaForm,
808 XmNtopAttachment, XmATTACH_WIDGET,
809 XmNtopWidget, tabLine,
810 NULL);
811 }
812 else
813#endif
814 XtVaSetValues(textAreaForm,
815 XmNtopAttachment, XmATTACH_WIDGET,
816 XmNtopWidget, menuBar,
817 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 }
819 }
820 else
821 {
822 XtUnmanageChild(menuBar);
823#ifdef FEAT_TOOLBAR
824 if (XtIsManaged(XtParent(toolBar)))
825 {
826 XtVaSetValues(XtParent(toolBar),
827 XmNtopAttachment, XmATTACH_FORM,
828 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000829#ifdef FEAT_GUI_TABLINE
830 if (showing_tabline)
831 {
832 XtVaSetValues(tabLine,
833 XmNtopAttachment, XmATTACH_WIDGET,
834 XmNtopWidget, XtParent(toolBar),
835 NULL);
836 XtVaSetValues(textAreaForm,
837 XmNtopAttachment, XmATTACH_WIDGET,
838 XmNtopWidget, tabLine,
839 NULL);
840 }
841 else
842#endif
843 XtVaSetValues(textAreaForm,
844 XmNtopAttachment, XmATTACH_WIDGET,
845 XmNtopWidget, XtParent(toolBar),
846 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 }
848 else
849#endif
850 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000851#ifdef FEAT_GUI_TABLINE
852 if (showing_tabline)
853 {
854 XtVaSetValues(tabLine,
855 XmNtopAttachment, XmATTACH_FORM,
856 NULL);
857 XtVaSetValues(textAreaForm,
858 XmNtopAttachment, XmATTACH_WIDGET,
859 XmNtopWidget, tabLine,
860 NULL);
861 }
862 else
863#endif
864 XtVaSetValues(textAreaForm,
865 XmNtopAttachment, XmATTACH_FORM,
866 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 }
868 }
869
870}
871
872/*
873 * Enable or disable mnemonics for the toplevel menus.
874 */
875 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100876gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000877{
878 /*
879 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
880 * crashes when using a mnemonic then.
881 */
882 if (!menu_enabled)
883 enable = FALSE;
884 do_set_mnemonics(enable);
885}
886
887 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100888do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889{
890 vimmenu_T *menu;
891
892 for (menu = root_menu; menu != NULL; menu = menu->next)
893 if (menu->id != (Widget)0)
894 XtVaSetValues(menu->id,
895 XmNmnemonic, enable ? menu->mnemonic : NUL,
896 NULL);
897}
898
899 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100900gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901{
902 XmString label;
903 Widget shell;
904 vimmenu_T *parent = menu->parent;
905
906#ifdef MOTIF_POPUP
907 if (menu_is_popup(menu->name))
908 {
909 Arg arg[2];
910 int n = 0;
911
Bram Moolenaar734a8672019-12-02 22:49:38 +0100912 // Only create the popup menu when it's actually used, otherwise there
913 // is a delay when using the right mouse button.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914# if (XmVersion <= 1002)
915 if (mouse_model_popup())
916# endif
917 {
918 if (gui.menu_bg_pixel != INVALCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 if (gui.menu_fg_pixel != INVALCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
923 arg, n);
924 menu->id = (Widget)0;
925 }
926 return;
927 }
928#endif
929
930 if (!menu_is_menubar(menu->name)
931 || (parent != NULL && parent->submenu_id == (Widget)0))
932 return;
933
934 label = XmStringCreate((char *)menu->dname, STRING_TAG);
935 if (label == NULL)
936 return;
937 menu->id = XtVaCreateWidget("subMenu",
938 xmCascadeButtonWidgetClass,
939 (parent == NULL) ? menuBar : parent->submenu_id,
940 XmNlabelString, label,
941 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
942#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100943 // submenu: count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 XmNpositionIndex, idx + (parent != NULL
945 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
946#endif
947 NULL);
948 gui_motif_menu_colors(menu->id);
949 gui_motif_menu_fontlist(menu->id);
950 XmStringFree(label);
951
Bram Moolenaar734a8672019-12-02 22:49:38 +0100952 if (menu->id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 return;
954
Bram Moolenaar734a8672019-12-02 22:49:38 +0100955 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 gui_motif_add_actext(menu);
957
958 shell = XtVaCreateWidget("subMenuShell",
959 xmMenuShellWidgetClass, menu->id,
960 XmNwidth, 1,
961 XmNheight, 1,
962 NULL);
963 gui_motif_menu_colors(shell);
964 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
965 xmRowColumnWidgetClass, shell,
966 XmNrowColumnType, XmMENU_PULLDOWN,
967 NULL);
968 gui_motif_menu_colors(menu->submenu_id);
969
Bram Moolenaar734a8672019-12-02 22:49:38 +0100970 if (menu->submenu_id == (Widget)0) // failed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 return;
972
973#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +0100974 // Set the colors for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 toggle_tearoff(menu->submenu_id);
976#endif
977
978 XtVaSetValues(menu->id,
979 XmNsubMenuId, menu->submenu_id,
980 NULL);
981
982 /*
983 * The "Help" menu is a special case, and should be placed at the far
984 * right hand side of the menu-bar. It's recognized by its high priority.
985 */
986 if (parent == NULL && menu->priority >= 9999)
987 XtVaSetValues(menuBar,
988 XmNmenuHelpWidget, menu->id,
989 NULL);
990
991 /*
992 * When we add a top-level item to the menu bar, we can figure out how
993 * high the menu bar should be.
994 */
995 if (parent == NULL)
996 gui_mch_compute_menu_height(menu->id);
997}
998
999
1000/*
1001 * Add mnemonic and accelerator text to a menu button.
1002 */
1003 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001004gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005{
1006 XmString label;
1007
Bram Moolenaar734a8672019-12-02 22:49:38 +01001008 // Add accelerator text, if there is one
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009 if (menu->actext != NULL && menu->id != (Widget)0)
1010 {
1011 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1012 if (label == NULL)
1013 return;
1014 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1015 XmStringFree(label);
1016 }
1017}
1018
1019 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001020gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021{
1022#if (XmVersion >= 1002)
1023 if (enable)
1024 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1025 else
1026 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1027 toggle_tearoff(menuBar);
1028 gui_mch_recurse_tearoffs(root_menu);
1029#endif
1030}
1031
1032#if (XmVersion >= 1002)
1033/*
1034 * Set the tearoff for one menu widget on or off, and set the color of the
1035 * tearoff widget.
1036 */
1037 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001038toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039{
1040 Widget w;
1041
1042 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1043 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1044 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1045 gui_motif_menu_colors(w);
1046}
1047
1048 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001049gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050{
1051 while (menu != NULL)
1052 {
1053 if (!menu_is_popup(menu->name))
1054 {
1055 if (menu->submenu_id != (Widget)0)
1056 toggle_tearoff(menu->submenu_id);
1057 gui_mch_recurse_tearoffs(menu->children);
1058 }
1059 menu = menu->next;
1060 }
1061}
1062#endif
1063
1064 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001065gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066{
1067 Dimension shadowHeight;
1068
1069 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1070 return shadowHeight;
1071}
1072
1073/*
1074 * Compute the height of the menu bar.
1075 * We need to check all the items for their position and height, for the case
1076 * there are several rows, and/or some characters extend higher or lower.
1077 */
1078 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001079gui_mch_compute_menu_height(
Bram Moolenaar734a8672019-12-02 22:49:38 +01001080 Widget id) // can be NULL when deleting menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081{
1082 Dimension y, maxy;
1083 Dimension margin, shadow;
1084 vimmenu_T *mp;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001085 static Dimension height = 21; // normal height of a menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086
1087 /*
1088 * Get the height of the new item, before managing it, because it will
1089 * still reflect the font size. After managing it depends on the menu
1090 * height, which is what we just wanted to get!.
1091 */
1092 if (id != (Widget)0)
1093 XtVaGetValues(id, XmNheight, &height, NULL);
1094
Bram Moolenaar734a8672019-12-02 22:49:38 +01001095 // Find any menu Widget, to be able to call XtManageChild()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 else
1097 for (mp = root_menu; mp != NULL; mp = mp->next)
1098 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1099 {
1100 id = mp->id;
1101 break;
1102 }
1103
1104 /*
1105 * Now manage the menu item, to make them all be positioned (makes an
1106 * extra row when needed, removes it when not needed).
1107 */
1108 if (id != (Widget)0)
1109 XtManageChild(id);
1110
1111 /*
Bram Moolenaarc4568ab2018-11-16 16:21:05 +01001112 * Now find the menu item that is the furthest down, and get its position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 */
1114 maxy = 0;
1115 for (mp = root_menu; mp != NULL; mp = mp->next)
1116 {
1117 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1118 {
1119 XtVaGetValues(mp->id, XmNy, &y, NULL);
1120 if (y > maxy)
1121 maxy = y;
1122 }
1123 }
1124
1125 XtVaGetValues(menuBar,
1126 XmNmarginHeight, &margin,
1127 XmNshadowThickness, &shadow,
1128 NULL);
1129
1130 /*
1131 * This computation is the result of trial-and-error:
1132 * maxy = The maximum position of an item; required for when there are
1133 * two or more rows
1134 * height = height of an item, before managing it; Hopefully this will
1135 * change with the font height. Includes shadow-border.
1136 * shadow = shadow-border; must be subtracted from the height.
1137 * margin = margin around the menu buttons; Must be added.
1138 * Add 4 for the underlining of shortcut keys.
1139 */
1140 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1141
Bram Moolenaar734a8672019-12-02 22:49:38 +01001142 // Somehow the menu bar doesn't resize automatically. Set it here,
1143 // even though this is a catch 22. Don't do this when starting up,
1144 // somehow the menu gets very high then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 if (gui.shell_created)
1146 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001147}
1148
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001149#ifdef FEAT_TOOLBAR
1150
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001151/*
1152 * Icons used by the toolbar code.
1153 */
1154#include "gui_x11_pm.h"
1155
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001156static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001157
1158/*
1159 * Read an Xpm file. Return OK or FAIL.
1160 */
1161 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001162check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001163{
1164 XpmAttributes attrs;
1165 int status;
1166 Pixmap mask;
1167 Pixmap map;
1168
1169 attrs.valuemask = 0;
1170
Bram Moolenaar734a8672019-12-02 22:49:38 +01001171 // Create the "sensitive" pixmap
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001172 status = XpmReadFileToPixmap(gui.dpy,
1173 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1174 (char *)path, &map, &mask, &attrs);
1175 XpmFreeAttributes(&attrs);
1176
1177 if (status == XpmSuccess)
1178 return OK;
1179 return FAIL;
1180}
1181
1182
1183/*
1184 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001185 * When it's to be read from a file, "fname" is set to the file name
1186 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001187 * Return a blank pixmap if it fails.
1188 */
1189 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001190get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001191{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001192 char_u buf[MAXPATHL]; // buffer storing expanded pathname
1193 char **xpm = NULL; // xpm array
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001194 int res;
1195
Bram Moolenaar7c626922005-02-07 22:01:03 +00001196 *fname = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001197 buf[0] = NUL; // start with NULL path
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001198
1199 if (menu->iconfile != NULL)
1200 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001201 // Use the "icon=" argument.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001202 gui_find_iconfile(menu->iconfile, buf, "xpm");
1203 res = check_xpm(buf);
1204
Bram Moolenaar734a8672019-12-02 22:49:38 +01001205 // If it failed, try using the menu name.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001206 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1207 res = check_xpm(buf);
1208 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001209 {
1210 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001211 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001212 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001213 }
1214
1215 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1216 {
1217 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001218 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001219 xpm = built_in_pixmaps[menu->iconidx];
1220 else
1221 xpm = tb_blank_xpm;
1222 }
1223
1224 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001226
1227/*
1228 * Add arguments for the toolbar pixmap to a menu item.
1229 */
1230 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001231add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001232{
1233 vim_free(menu->xpm_fname);
1234 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1235 if (menu->xpm == NULL)
1236 {
1237 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1238 }
1239 else
1240 {
1241 if (menu->xpm_fname != NULL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001242 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001243 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1244 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1245 }
1246 return n;
1247}
Bram Moolenaar734a8672019-12-02 22:49:38 +01001248#endif // FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249
1250 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001251gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252{
1253 XmString label;
1254 vimmenu_T *parent = menu->parent;
1255
1256# ifdef EBCDIC
1257 menu->mnemonic = 0;
1258# endif
1259
1260# if (XmVersion <= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001261 // Don't add Popup menu items when the popup menu isn't used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1263 return;
1264# endif
1265
1266# ifdef FEAT_TOOLBAR
1267 if (menu_is_toolbar(parent->name))
1268 {
1269 WidgetClass type;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001270 XmString xms = NULL; // fallback label if pixmap not found
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271 int n;
1272 Arg args[18];
1273
1274 n = 0;
1275 if (menu_is_separator(menu->name))
1276 {
1277 char *cp;
1278 Dimension wid;
1279
1280 /*
1281 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1282 * a width specifier. If no width is specified then we choose one.
1283 */
1284 cp = (char *)vim_strchr(menu->name, ':');
1285 if (cp != NULL)
1286 wid = (Dimension)atoi(++cp);
1287 else
1288 wid = 4;
1289
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 type = xmSeparatorWidgetClass;
1291 XtSetArg(args[n], XmNwidth, wid); n++;
1292 XtSetArg(args[n], XmNminWidth, wid); n++;
1293 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001294 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 }
1296 else
1297 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001298 // Without shadows one can't sense whatever the button has been
1299 // pressed or not! However we want to save a bit of space...
1300 // Need the highlightThickness to see the focus.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001301 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1303 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1304 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001305 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001306 // Set the label here, so that we can switch between icons/text
1307 // by changing the XmNlabelType resource.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001308 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1309 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001310
Bram Moolenaar7c626922005-02-07 22:01:03 +00001311 n = add_pixmap_args(menu, args, n);
1312
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001313 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 }
1315
1316 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1317 if (menu->id == NULL)
1318 {
1319 menu->id = XtCreateManagedWidget((char *)menu->dname,
1320 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001321 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 {
1323 XtAddCallback(menu->id,
1324 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325# ifdef FEAT_FOOTER
1326 XtAddEventHandler(menu->id, EnterWindowMask, False,
1327 toolbarbutton_enter_cb, menu);
1328 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1329 toolbarbutton_leave_cb, menu);
1330# endif
1331 }
1332 }
1333 else
1334 XtSetValues(menu->id, args, n);
1335 if (xms != NULL)
1336 XmStringFree(xms);
1337
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001338# ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001340# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341
1342 menu->parent = parent;
1343 menu->submenu_id = NULL;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001344 // When adding first item to toolbar it might have to be enabled .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345 if (!XtIsManaged(XtParent(toolBar))
1346 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1347 gui_mch_show_toolbar(TRUE);
1348 gui.toolbar_height = gui_mch_compute_toolbar_height();
1349 return;
Bram Moolenaar734a8672019-12-02 22:49:38 +01001350 } // toolbar menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351# endif
1352
Bram Moolenaar734a8672019-12-02 22:49:38 +01001353 // No parent, must be a non-menubar menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354 if (parent->submenu_id == (Widget)0)
1355 return;
1356
1357 menu->submenu_id = (Widget)0;
1358
Bram Moolenaar734a8672019-12-02 22:49:38 +01001359 // Add menu separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 if (menu_is_separator(menu->name))
1361 {
1362 menu->id = XtVaCreateWidget("subMenu",
1363 xmSeparatorGadgetClass, parent->submenu_id,
1364#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001365 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1367 ? 1 : 0),
1368#endif
1369 NULL);
1370 gui_motif_menu_colors(menu->id);
1371 return;
1372 }
1373
1374 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1375 if (label == NULL)
1376 return;
1377 menu->id = XtVaCreateWidget("subMenu",
1378 xmPushButtonWidgetClass, parent->submenu_id,
1379 XmNlabelString, label,
1380 XmNmnemonic, menu->mnemonic,
1381#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001382 // count the tearoff item (needed for LessTif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1384 ? 1 : 0),
1385#endif
1386 NULL);
1387 gui_motif_menu_colors(menu->id);
1388 gui_motif_menu_fontlist(menu->id);
1389 XmStringFree(label);
1390
1391 if (menu->id != (Widget)0)
1392 {
1393 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1394 (XtPointer)menu);
Bram Moolenaar734a8672019-12-02 22:49:38 +01001395 // add accelerator text
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 gui_motif_add_actext(menu);
1397 }
1398}
1399
1400#if (XmVersion <= 1002) || defined(PROTO)
1401/*
1402 * This function will destroy/create the popup menus dynamically,
1403 * according to the value of 'mousemodel'.
1404 * This will fix the "right mouse button freeze" that occurs when
1405 * there exists a popup menu but it isn't managed.
1406 */
1407 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001408gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409{
1410 int idx = 0;
1411
Bram Moolenaar734a8672019-12-02 22:49:38 +01001412 // When GUI hasn't started the menus have not been created.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 if (!gui.in_use)
1414 return;
1415
1416 while (menu)
1417 {
1418 if (menu->children != NULL)
1419 {
1420 if (menu_is_popup(menu->name))
1421 {
1422 if (mouse_model_popup())
1423 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001424 // Popup menu will be used. Create the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 gui_mch_add_menu(menu, idx);
1426 gui_motif_update_mousemodel(menu->children);
1427 }
1428 else
1429 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001430 // Popup menu will not be used. Destroy the popup menus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 gui_motif_update_mousemodel(menu->children);
1432 gui_mch_destroy_menu(menu);
1433 }
1434 }
1435 }
1436 else if (menu_is_child_of_popup(menu))
1437 {
1438 if (mouse_model_popup())
1439 gui_mch_add_menu_item(menu, idx);
1440 else
1441 gui_mch_destroy_menu(menu);
1442 }
1443 menu = menu->next;
1444 ++idx;
1445 }
1446}
1447#endif
1448
1449 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001450gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451{
1452 if (menuBar == (Widget)0)
1453 return;
1454 gui_motif_menu_colors(menuBar);
1455#ifdef FEAT_TOOLBAR
1456 gui_motif_menu_colors(toolBarFrame);
1457 gui_motif_menu_colors(toolBar);
1458#endif
1459
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001460 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461}
1462
1463 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001464gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465{
1466 if (menuBar == (Widget)0)
1467 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001468 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {
1470 Dimension height;
1471 Position w, h;
1472
1473 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1474 gui.menu_height = height;
1475
1476 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1477 gui_resize_shell(w, h
1478#ifdef FEAT_XIM
1479 - xim_get_status_area_height()
1480#endif
1481 );
1482 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001483 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 ui_new_shellsize();
1485}
1486
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001487#if defined(FEAT_BEVAL_GUI) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001489gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490{
1491# ifdef FEAT_TOOLBAR
1492 vimmenu_T *menu;
1493
1494 if (toolBar == (Widget)0)
1495 return;
1496
1497 menu = gui_find_menu((char_u *)"ToolBar");
1498 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001499 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500# endif
1501}
1502
1503 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001504gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505{
1506# ifdef FEAT_TOOLBAR
1507 vimmenu_T *toolbar;
1508
1509 if (toolBar == (Widget)0)
1510 return;
1511
1512 toolbar = gui_find_menu((char_u *)"ToolBar");
1513 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001514 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515# endif
1516}
1517#endif
1518
1519 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001520submenu_change(
1521 vimmenu_T *menu,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001522 int colors) // TRUE for colors, FALSE for font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523{
1524 vimmenu_T *mp;
1525
1526 for (mp = menu; mp != NULL; mp = mp->next)
1527 {
1528 if (mp->id != (Widget)0)
1529 {
1530 if (colors)
1531 {
1532 gui_motif_menu_colors(mp->id);
1533#ifdef FEAT_TOOLBAR
Bram Moolenaar734a8672019-12-02 22:49:38 +01001534 // For a toolbar item: Free the pixmap and allocate a new one,
1535 // so that the background color is right.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001536 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001538 int n = 0;
1539 Arg args[18];
1540
Bram Moolenaar7c626922005-02-07 22:01:03 +00001541 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001542 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001544# ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001545 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 if (mp->tip != NULL)
1547 {
1548 Arg args[2];
1549
1550 args[0].name = XmNbackground;
1551 args[0].value = gui.tooltip_bg_pixel;
1552 args[1].name = XmNforeground;
1553 args[1].value = gui.tooltip_fg_pixel;
1554 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1555 }
1556# endif
1557#endif
1558 }
1559 else
1560 {
1561 gui_motif_menu_fontlist(mp->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001562#ifdef FEAT_BEVAL_GUI
Bram Moolenaar734a8672019-12-02 22:49:38 +01001563 // If we have a tooltip, then we need to change its font
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 if (mp->tip != NULL)
1565 {
1566 Arg args[1];
1567
1568 args[0].name = XmNfontList;
1569 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1570 &gui.tooltip_fontset);
1571 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1572 }
1573#endif
1574 }
1575 }
1576
1577 if (mp->children != NULL)
1578 {
1579#if (XmVersion >= 1002)
Bram Moolenaar734a8672019-12-02 22:49:38 +01001580 // Set the colors/font for the tear off widget
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 if (mp->submenu_id != (Widget)0)
1582 {
1583 if (colors)
1584 gui_motif_menu_colors(mp->submenu_id);
1585 else
1586 gui_motif_menu_fontlist(mp->submenu_id);
1587 toggle_tearoff(mp->submenu_id);
1588 }
1589#endif
Bram Moolenaar734a8672019-12-02 22:49:38 +01001590 // Set the colors for the children
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001591 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 }
1593 }
1594}
1595
1596/*
1597 * Destroy the machine specific menu widget.
1598 */
1599 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001600gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001601{
Bram Moolenaar734a8672019-12-02 22:49:38 +01001602 // Please be sure to destroy the parent widget first (i.e. menu->id).
1603 // On the other hand, problems have been reported that the submenu must be
1604 // deleted first...
1605 //
1606 // This code should be basically identical to that in the file gui_athena.c
1607 // because they are both Xt based.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001608 if (menu->submenu_id != (Widget)0)
1609 {
1610 XtDestroyWidget(menu->submenu_id);
1611 menu->submenu_id = (Widget)0;
1612 }
1613
1614 if (menu->id != (Widget)0)
1615 {
1616 Widget parent;
1617
1618 parent = XtParent(menu->id);
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001619#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL_GUI)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001620 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001622 // We try to destroy this before the actual menu, because there are
1623 // callbacks, etc. that will be unregistered during the tooltip
1624 // destruction.
1625 //
1626 // If you call "gui_mch_destroy_beval_area()" after destroying
1627 // menu->id, then the tooltip's window will have already been
1628 // deallocated by Xt, and unknown behaviour will ensue (probably
1629 // a core dump).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 gui_mch_destroy_beval_area(menu->tip);
1631 menu->tip = NULL;
1632 }
1633#endif
1634 XtDestroyWidget(menu->id);
1635 menu->id = (Widget)0;
1636 if (parent == menuBar)
1637 gui_mch_compute_menu_height((Widget)0);
1638#ifdef FEAT_TOOLBAR
1639 else if (parent == toolBar)
1640 {
1641 Cardinal num_children;
1642
Bram Moolenaar734a8672019-12-02 22:49:38 +01001643 // When removing last toolbar item, don't display the toolbar.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1645 if (num_children == 0)
1646 gui_mch_show_toolbar(FALSE);
1647 else
1648 gui.toolbar_height = gui_mch_compute_toolbar_height();
1649 }
1650#endif
1651 }
1652}
1653
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001655gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656{
1657#ifdef MOTIF_POPUP
1658 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1659 XtManageChild(menu->submenu_id);
1660#endif
1661}
1662
Bram Moolenaar734a8672019-12-02 22:49:38 +01001663#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664
1665/*
1666 * Set the menu and scrollbar colors to their default values.
1667 */
1668 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001669gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670{
1671 if (gui.in_use)
1672 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001673 // Use the values saved when starting up. These should come from the
1674 // window manager or a resources file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1676 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1677 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1678 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01001679#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 gui.tooltip_fg_pixel =
1681 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1682 gui.tooltip_bg_pixel =
1683 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1684#endif
1685 }
1686}
1687
1688
1689/*
1690 * Scrollbar stuff.
1691 */
1692
1693 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001694gui_mch_set_scrollbar_thumb(
1695 scrollbar_T *sb,
1696 long val,
1697 long size,
1698 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699{
1700 if (sb->id != (Widget)0)
1701 XtVaSetValues(sb->id,
1702 XmNvalue, val,
1703 XmNsliderSize, size,
1704 XmNpageIncrement, (size > 2 ? size - 2 : 1),
Bram Moolenaar734a8672019-12-02 22:49:38 +01001705 XmNmaximum, max + 1, // Motif has max one past the end
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 NULL);
1707}
1708
1709 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001710gui_mch_set_scrollbar_pos(
1711 scrollbar_T *sb,
1712 int x,
1713 int y,
1714 int w,
1715 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716{
1717 if (sb->id != (Widget)0)
1718 {
1719 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1720 {
1721 if (y == 0)
1722 h -= gui.border_offset;
1723 else
1724 y -= gui.border_offset;
1725 XtVaSetValues(sb->id,
1726 XmNtopOffset, y,
1727 XmNbottomOffset, -y - h,
1728 XmNwidth, w,
1729 NULL);
1730 }
1731 else
1732 XtVaSetValues(sb->id,
1733 XmNtopOffset, y,
1734 XmNleftOffset, x,
1735 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1736 ? gui.scrollbar_width : 0,
1737 XmNheight, h,
1738 NULL);
1739 XtManageChild(sb->id);
1740 }
1741}
1742
1743 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001744gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745{
1746 Arg args[16];
1747 int n;
1748
1749 if (sb->id != (Widget)0)
1750 {
1751 n = 0;
1752 if (flag)
1753 {
1754 switch (sb->type)
1755 {
1756 case SBAR_LEFT:
1757 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1758 break;
1759
1760 case SBAR_RIGHT:
1761 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1762 break;
1763
1764 case SBAR_BOTTOM:
1765 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1766 break;
1767 }
1768 XtSetValues(textArea, args, n);
1769 XtManageChild(sb->id);
1770 }
1771 else
1772 {
1773 if (!gui.which_scrollbars[sb->type])
1774 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001775 // The scrollbars of this type are all disabled, adjust the
1776 // textArea attachment offset.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 switch (sb->type)
1778 {
1779 case SBAR_LEFT:
1780 XtSetArg(args[n], XmNleftOffset, 0); n++;
1781 break;
1782
1783 case SBAR_RIGHT:
1784 XtSetArg(args[n], XmNrightOffset, 0); n++;
1785 break;
1786
1787 case SBAR_BOTTOM:
1788 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1789 break;
1790 }
1791 XtSetValues(textArea, args, n);
1792 }
1793 XtUnmanageChild(sb->id);
1794 }
1795 }
1796}
1797
1798 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001799gui_mch_create_scrollbar(
1800 scrollbar_T *sb,
Bram Moolenaar734a8672019-12-02 22:49:38 +01001801 int orient) // SBAR_VERT or SBAR_HORIZ
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802{
1803 Arg args[16];
1804 int n;
1805
1806 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 XtSetArg(args[n], XmNminimum, 0); n++;
1808 XtSetArg(args[n], XmNorientation,
1809 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1810
1811 switch (sb->type)
1812 {
1813 case SBAR_LEFT:
1814 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1815 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1816 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1817 break;
1818
1819 case SBAR_RIGHT:
1820 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1821 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1822 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1823 break;
1824
1825 case SBAR_BOTTOM:
1826 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1827 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1828 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1829 break;
1830 }
1831
1832 sb->id = XtCreateWidget("scrollBar",
1833 xmScrollBarWidgetClass, textAreaForm, args, n);
1834
Bram Moolenaar734a8672019-12-02 22:49:38 +01001835 // Remember the default colors, needed for ":hi clear".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1837 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1838 XtVaGetValues(sb->id,
1839 XmNbackground, &gui.scroll_def_bg_pixel,
1840 XmNforeground, &gui.scroll_def_fg_pixel,
1841 NULL);
1842
1843 if (sb->id != (Widget)0)
1844 {
1845 gui_mch_set_scrollbar_colors(sb);
1846 XtAddCallback(sb->id, XmNvalueChangedCallback,
1847 scroll_cb, (XtPointer)sb->ident);
1848 XtAddCallback(sb->id, XmNdragCallback,
1849 scroll_cb, (XtPointer)sb->ident);
1850 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1851 (XtPointer)0);
1852 }
1853}
1854
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001856gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857{
1858 if (sb->id != (Widget)0)
1859 XtDestroyWidget(sb->id);
1860}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861
1862 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001863gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864{
1865 if (sb->id != (Widget)0)
1866 {
1867 if (gui.scroll_bg_pixel != INVALCOLOR)
1868 {
1869#if (XmVersion>=1002)
1870 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1871#else
1872 XtVaSetValues(sb->id,
1873 XmNtroughColor, gui.scroll_bg_pixel,
1874 NULL);
1875#endif
1876 }
1877
1878 if (gui.scroll_fg_pixel != INVALCOLOR)
1879 XtVaSetValues(sb->id,
1880 XmNforeground, gui.scroll_fg_pixel,
1881#if (XmVersion<1002)
1882 XmNbackground, gui.scroll_fg_pixel,
1883#endif
1884 NULL);
1885 }
1886
Bram Moolenaar734a8672019-12-02 22:49:38 +01001887 // This is needed for the rectangle below the vertical scrollbars.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1889 gui_motif_scroll_colors(textAreaForm);
1890}
1891
1892/*
1893 * Miscellaneous stuff:
1894 */
1895
1896 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001897gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898{
1899 return(XtWindow(textArea));
1900}
1901
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001902/*
1903 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1904 * When one is found, simulate a button press on that widget and give it the
1905 * keyboard focus. If the mnemonic is on a label, look in the userData field
1906 * of the label to see if it points to another widget, and give that the focus.
1907 */
1908 static void
1909do_mnemonic(Widget w, unsigned int keycode)
1910{
1911 WidgetList children;
1912 int numChildren, i;
1913 Boolean isMenu;
1914 KeySym mnemonic = '\0';
1915 char mneString[2];
1916 Widget userData;
1917 unsigned char rowColType;
1918
1919 if (XtIsComposite(w))
1920 {
1921 if (XtClass(w) == xmRowColumnWidgetClass)
1922 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001923 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001924 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1925 }
1926 else
1927 isMenu = False;
1928 if (!isMenu)
1929 {
1930 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001931 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001932 for (i = 0; i < numChildren; i++)
1933 do_mnemonic(children[i], keycode);
1934 }
1935 }
1936 else
1937 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001938 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001939 if (mnemonic != '\0')
1940 {
1941 mneString[0] = mnemonic;
1942 mneString[1] = '\0';
1943 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1944 XStringToKeysym(mneString)) == keycode)
1945 {
1946 if (XtClass(w) == xmLabelWidgetClass
1947 || XtClass(w) == xmLabelGadgetClass)
1948 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001949 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001950 if (userData != NULL && XtIsWidget(userData))
1951 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1952 }
1953 else
1954 {
1955 XKeyPressedEvent keyEvent;
1956
1957 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1958
Bram Moolenaar7db5fc82010-05-24 11:59:29 +02001959 vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001960 keyEvent.type = KeyPress;
1961 keyEvent.serial = 1;
1962 keyEvent.send_event = True;
1963 keyEvent.display = XtDisplay(w);
1964 keyEvent.window = XtWindow(w);
1965 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1966 NULL, 0);
1967 }
1968 }
1969 }
1970 }
1971}
1972
1973/*
1974 * Callback routine for dialog mnemonic processing.
1975 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001976 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001977mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001978{
1979 do_mnemonic(w, event->keycode);
1980}
1981
1982
1983/*
1984 * Search the widget tree under w for widgets with mnemonics. When found, add
1985 * a passive grab to the dialog widget for the mnemonic character, thus
1986 * directing mnemonic events to the dialog widget.
1987 */
1988 static void
1989add_mnemonic_grabs(Widget dialog, Widget w)
1990{
1991 char mneString[2];
1992 WidgetList children;
1993 int numChildren, i;
1994 Boolean isMenu;
1995 KeySym mnemonic = '\0';
1996 unsigned char rowColType;
1997
1998 if (XtIsComposite(w))
1999 {
2000 if (XtClass(w) == xmRowColumnWidgetClass)
2001 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002002 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002003 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2004 }
2005 else
2006 isMenu = False;
2007 if (!isMenu)
2008 {
2009 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002010 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002011 for (i = 0; i < numChildren; i++)
2012 add_mnemonic_grabs(dialog, children[i]);
2013 }
2014 }
2015 else
2016 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002017 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002018 if (mnemonic != '\0')
2019 {
2020 mneString[0] = mnemonic;
2021 mneString[1] = '\0';
2022 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2023 XStringToKeysym(mneString)),
2024 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2025 }
2026 }
2027}
2028
2029/*
2030 * Add a handler for mnemonics in a dialog. Motif itself only handles
2031 * mnemonics in menus. Mnemonics added or changed after this call will be
2032 * ignored.
2033 *
2034 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2035 * the appropriate label and set the XmNuserData resource of the label to the
2036 * widget to get the focus when the mnemonic is typed.
2037 */
2038 static void
2039activate_dialog_mnemonics(Widget dialog)
2040{
2041 if (!dialog)
2042 return;
2043
2044 XtAddEventHandler(dialog, KeyPressMask, False,
2045 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2046 add_mnemonic_grabs(dialog, dialog);
2047}
2048
2049/*
2050 * Removes the event handler and key-grabs for dialog mnemonic handling.
2051 */
2052 static void
2053suppress_dialog_mnemonics(Widget dialog)
2054{
2055 if (!dialog)
2056 return;
2057
2058 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2059 XtRemoveEventHandler(dialog, KeyPressMask, False,
2060 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2061}
2062
2063#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002064/*
2065 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2066 */
2067 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002068set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002069{
2070 XmFontList fl;
2071
2072#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002073 if (gui.fontset != NOFONTSET)
2074 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002075 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2076 if (fl != NULL)
2077 {
2078 if (XtIsManaged(id))
2079 {
2080 XtUnmanageChild(id);
2081 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002082 // We should force the widget to recalculate its
2083 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002084 XtManageChild(id);
2085 }
2086 else
2087 XtVaSetValues(id, XmNfontList, fl, NULL);
2088 XmFontListFree(fl);
2089 }
2090 }
2091#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002092 if (gui.norm_font != NOFONT)
2093 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002094 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2095 if (fl != NULL)
2096 {
2097 if (XtIsManaged(id))
2098 {
2099 XtUnmanageChild(id);
2100 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002101 // We should force the widget to recalculate its
2102 // geometry now.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002103 XtManageChild(id);
2104 }
2105 else
2106 XtVaSetValues(id, XmNfontList, fl, NULL);
2107 XmFontListFree(fl);
2108 }
2109 }
2110#endif
2111}
2112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113
2114#if defined(FEAT_BROWSE) || defined(PROTO)
2115
2116/*
2117 * file selector related stuff
2118 */
2119
2120#include <Xm/FileSB.h>
2121#include <Xm/XmStrDefs.h>
2122
2123typedef struct dialog_callback_arg
2124{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002125 char * args; // not used right now
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 int id;
2127} dcbarg_T;
2128
2129static Widget dialog_wgt;
2130static char *browse_fname = NULL;
2131static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002132 // used to set up XmStrings
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002134static void DialogCancelCB(Widget, XtPointer, XtPointer);
2135static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136
2137/*
2138 * This function is used to translate the predefined label text of the
2139 * precomposed dialogs. We do this explicitly to allow:
2140 *
2141 * - usage of gettext for translation, as in all the other places.
2142 *
2143 * - equalize the messages between different GUI implementations as far as
2144 * possible.
2145 */
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002146 static void
2147set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002149 XmString str;
2150 Widget w;
2151 char_u *p, *next;
2152 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153
2154 w = XtNameToWidget(parent, name);
2155
2156 if (!w)
2157 return;
2158
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002159 p = vim_strsave((char_u *)new_label);
2160 if (p == NULL)
2161 return;
2162 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002164 if (*next == DLG_HOTKEY_CHAR)
2165 {
2166 int len = STRLEN(next);
2167
2168 if (len > 0)
2169 {
2170 mch_memmove(next, next + 1, len);
2171 mnemonic = next[0];
2172 }
2173 }
2174 }
2175
2176 str = XmStringCreate((char *)p, STRING_TAG);
2177 vim_free(p);
2178
2179 if (str != NULL)
2180 {
2181 XtVaSetValues(w,
2182 XmNlabelString, str,
2183 XmNmnemonic, mnemonic,
2184 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 XmStringFree(str);
2186 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002187 gui_motif_menu_fontlist(w);
2188}
2189
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002190 static void
2191set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002192{
2193 Widget w;
2194 w = XtNameToWidget(parent, name);
2195
2196 if (!w)
2197 return;
2198
2199 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200}
2201
2202/*
2203 * Put up a file requester.
2204 * Returns the selected name in allocated memory, or NULL for Cancel.
2205 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002206 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002207gui_mch_browse(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002208 int saving UNUSED, // select file to write
2209 char_u *title, // title for the window
2210 char_u *dflt, // default name
2211 char_u *ext UNUSED, // not used (extension added)
2212 char_u *initdir, // initial directory, NULL for current dir
2213 char_u *filter) // file name filter
Bram Moolenaar071d4272004-06-13 20:20:40 +00002214{
2215 char_u dirbuf[MAXPATHL];
2216 char_u dfltbuf[MAXPATHL];
2217 char_u *pattern;
2218 char_u *tofree = NULL;
2219
Bram Moolenaar734a8672019-12-02 22:49:38 +01002220 // There a difference between the resource name and value, Therefore, we
2221 // avoid to (ab-)use the (maybe internationalized!) dialog title as a
2222 // dialog name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002223
2224 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225
2226 if (initdir == NULL || *initdir == NUL)
2227 {
2228 mch_dirname(dirbuf, MAXPATHL);
2229 initdir = dirbuf;
2230 }
2231
2232 if (dflt == NULL)
2233 dflt = (char_u *)"";
2234 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2235 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002236 // The default selection should be the full path, "dflt" is only the
2237 // file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 STRCPY(dfltbuf, initdir);
2239 add_pathsep(dfltbuf);
2240 STRCAT(dfltbuf, dflt);
2241 dflt = dfltbuf;
2242 }
2243
Bram Moolenaar734a8672019-12-02 22:49:38 +01002244 // Can only use one pattern for a file name. Get the first pattern out of
2245 // the filter. An empty pattern means everything matches.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 if (filter == NULL)
2247 pattern = (char_u *)"";
2248 else
2249 {
2250 char_u *s, *p;
2251
2252 s = filter;
2253 for (p = filter; *p != NUL; ++p)
2254 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002255 if (*p == '\t') // end of description, start of pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 s = p + 1;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002257 if (*p == ';' || *p == '\n') // end of (first) pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 break;
2259 }
2260 pattern = vim_strnsave(s, p - s);
2261 tofree = pattern;
2262 if (pattern == NULL)
2263 pattern = (char_u *)"";
2264 }
2265
2266 XtVaSetValues(dialog_wgt,
2267 XtVaTypedArg,
2268 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2269 XtVaTypedArg,
2270 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2271 XtVaTypedArg,
2272 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2273 XtVaTypedArg,
2274 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2275 NULL);
2276
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002277 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2278 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2280 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002281 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002283 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2285
Bram Moolenaar734a8672019-12-02 22:49:38 +01002286 // This is to save us from silly external settings using not fixed with
2287 // fonts for file selection.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002288 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2289 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2290
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 gui_motif_menu_colors(dialog_wgt);
2292 if (gui.scroll_bg_pixel != INVALCOLOR)
2293 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2294
2295 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2296 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
Bram Moolenaar734a8672019-12-02 22:49:38 +01002297 // We have no help in this window, so hide help button
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2299 (unsigned char)XmDIALOG_HELP_BUTTON));
2300
2301 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002302 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303
Bram Moolenaar734a8672019-12-02 22:49:38 +01002304 // sit in a loop until the dialog box has gone away
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 do
2306 {
2307 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2308 (XtInputMask)XtIMAll);
2309 } while (XtIsManaged(dialog_wgt));
2310
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002311 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 XtDestroyWidget(dialog_wgt);
2313 vim_free(tofree);
2314
2315 if (browse_fname == NULL)
2316 return NULL;
2317 return vim_strsave((char_u *)browse_fname);
2318}
2319
2320/*
2321 * The code below was originally taken from
2322 * /usr/examples/motif/xmsamplers/xmeditor.c
2323 * on Digital Unix 4.0d, but heavily modified.
2324 */
2325
2326/*
2327 * Process callback from Dialog cancel actions.
2328 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002330DialogCancelCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002331 Widget w UNUSED, // widget id
2332 XtPointer client_data UNUSED, // data from application
2333 XtPointer call_data UNUSED) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334{
2335 if (browse_fname != NULL)
2336 {
2337 XtFree(browse_fname);
2338 browse_fname = NULL;
2339 }
2340 XtUnmanageChild(dialog_wgt);
2341}
2342
2343/*
2344 * Process callback from Dialog actions.
2345 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002347DialogAcceptCB(
Bram Moolenaar734a8672019-12-02 22:49:38 +01002348 Widget w UNUSED, // widget id
2349 XtPointer client_data UNUSED, // data from application
2350 XtPointer call_data) // data from widget class
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351{
2352 XmFileSelectionBoxCallbackStruct *fcb;
2353
2354 if (browse_fname != NULL)
2355 {
2356 XtFree(browse_fname);
2357 browse_fname = NULL;
2358 }
2359 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2360
Bram Moolenaar734a8672019-12-02 22:49:38 +01002361 // get the filename from the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2363
Bram Moolenaar734a8672019-12-02 22:49:38 +01002364 // popdown the file selection box
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 XtUnmanageChild(dialog_wgt);
2366}
2367
Bram Moolenaar734a8672019-12-02 22:49:38 +01002368#endif // FEAT_BROWSE
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369
2370#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2371
2372static int dialogStatus;
2373
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374/*
2375 * Callback function for the textfield. When CR is hit this works like
2376 * hitting the "OK" button, ESC like "Cancel".
2377 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002379keyhit_callback(
2380 Widget w,
2381 XtPointer client_data UNUSED,
2382 XEvent *event,
2383 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384{
2385 char buf[2];
2386 KeySym key_sym;
2387
2388 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2389 {
2390 if (*buf == CAR)
2391 dialogStatus = 1;
2392 else if (*buf == ESC)
2393 dialogStatus = 2;
2394 }
2395 if ((key_sym == XK_Left || key_sym == XK_Right)
2396 && !(event->xkey.state & ShiftMask))
2397 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2398}
2399
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002401butproc(
2402 Widget w UNUSED,
2403 XtPointer client_data,
2404 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405{
2406 dialogStatus = (int)(long)client_data + 1;
2407}
2408
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409#ifdef HAVE_XPM
2410
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002412create_pixmap_label(
2413 Widget parent,
2414 String name,
2415 char **data,
2416 ArgList args,
2417 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418{
2419 Widget label;
2420 Display *dsp;
2421 Screen *scr;
2422 int depth;
2423 Pixmap pixmap = 0;
2424 XpmAttributes attr;
2425 Boolean rs;
2426 XpmColorSymbol color[5] =
2427 {
2428 {"none", NULL, 0},
2429 {"iconColor1", NULL, 0},
2430 {"bottomShadowColor", NULL, 0},
2431 {"topShadowColor", NULL, 0},
2432 {"selectColor", NULL, 0}
2433 };
2434
2435 label = XmCreateLabelGadget(parent, name, args, arg);
2436
2437 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002438 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 * no way to get the background color directly from the widget itself.
2440 * In such cases we get it from The Core part of his parent instead.
2441 */
2442 dsp = XtDisplayOfObject(label);
2443 scr = XtScreenOfObject(label);
2444 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2445 ? label : XtParent(label),
2446 XmNdepth, &depth,
2447 XmNbackground, &color[0].pixel,
2448 XmNforeground, &color[1].pixel,
2449 XmNbottomShadowColor, &color[2].pixel,
2450 XmNtopShadowColor, &color[3].pixel,
2451 XmNhighlight, &color[4].pixel,
2452 NULL);
2453
2454 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2455 attr.colorsymbols = color;
2456 attr.numsymbols = 5;
2457 attr.closeness = 65535;
2458 attr.depth = depth;
2459 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2460 data, &pixmap, NULL, &attr);
2461
2462 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2463 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2464 XtVaSetValues(label,
2465 XmNlabelType, XmPIXMAP,
2466 XmNlabelPixmap, pixmap,
2467 NULL);
2468 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2469
2470 return label;
2471}
2472#endif
2473
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002475gui_mch_dialog(
2476 int type UNUSED,
2477 char_u *title,
2478 char_u *message,
2479 char_u *button_names,
2480 int dfltbutton,
Bram Moolenaar734a8672019-12-02 22:49:38 +01002481 char_u *textfield, // buffer of size IOSIZE
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002482 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483{
2484 char_u *buts;
2485 char_u *p, *next;
2486 XtAppContext app;
2487 XmString label;
2488 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002489 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 Widget dialogform = NULL;
2491 Widget form = NULL;
2492 Widget dialogtextfield = NULL;
2493 Widget *buttons;
2494 Widget sep_form = NULL;
2495 Boolean vertical;
2496 Widget separator = NULL;
2497 int n;
2498 Arg args[6];
2499#ifdef HAVE_XPM
2500 char **icon_data = NULL;
2501 Widget dialogpixmap = NULL;
2502#endif
2503
2504 if (title == NULL)
2505 title = (char_u *)_("Vim dialog");
2506
Bram Moolenaar734a8672019-12-02 22:49:38 +01002507 // if our pointer is currently hidden, then we should show it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 gui_mch_mousehide(FALSE);
2509
2510 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2511
Bram Moolenaar734a8672019-12-02 22:49:38 +01002512 // Check 'v' flag in 'guioptions': vertical button placement.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2514
Bram Moolenaar734a8672019-12-02 22:49:38 +01002515 // Set the title of the Dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 label = XmStringCreateSimple((char *)title);
2517 if (label == NULL)
2518 return -1;
2519 XtVaSetValues(dialogform,
2520 XmNdialogTitle, label,
2521 XmNhorizontalSpacing, 4,
2522 XmNverticalSpacing, vertical ? 0 : 4,
2523 NULL);
2524 XmStringFree(label);
2525
Bram Moolenaar734a8672019-12-02 22:49:38 +01002526 // make a copy, so that we can insert NULs
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 buts = vim_strsave(button_names);
2528 if (buts == NULL)
2529 return -1;
2530
Bram Moolenaar734a8672019-12-02 22:49:38 +01002531 // Count the number of buttons and allocate buttons[].
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 butcount = 1;
2533 for (p = buts; *p; ++p)
2534 if (*p == DLG_BUTTON_SEP)
2535 ++butcount;
Bram Moolenaarc799fe22019-05-28 23:08:19 +02002536 buttons = ALLOC_MULT(Widget, butcount);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537 if (buttons == NULL)
2538 {
2539 vim_free(buts);
2540 return -1;
2541 }
2542
2543 /*
2544 * Create the buttons.
2545 */
2546 sep_form = (Widget) 0;
2547 p = buts;
2548 for (butcount = 0; *p; ++butcount)
2549 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002550 KeySym mnemonic = NUL;
2551
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 for (next = p; *next; ++next)
2553 {
2554 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002555 {
2556 int len = STRLEN(next);
2557
2558 if (len > 0)
2559 {
2560 mch_memmove(next, next + 1, len);
2561 mnemonic = next[0];
2562 }
2563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 if (*next == DLG_BUTTON_SEP)
2565 {
2566 *next++ = NUL;
2567 break;
2568 }
2569 }
2570 label = XmStringCreate(_((char *)p), STRING_TAG);
2571 if (label == NULL)
2572 break;
2573
2574 buttons[butcount] = XtVaCreateManagedWidget("button",
2575 xmPushButtonWidgetClass, dialogform,
2576 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002577 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 XmNbottomAttachment, XmATTACH_FORM,
2579 XmNbottomOffset, 4,
2580 XmNshowAsDefault, butcount == dfltbutton - 1,
2581 XmNdefaultButtonShadowThickness, 1,
2582 NULL);
2583 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002584 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585
Bram Moolenaar734a8672019-12-02 22:49:38 +01002586 // Layout properly.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587
2588 if (butcount > 0)
2589 {
2590 if (vertical)
2591 XtVaSetValues(buttons[butcount],
2592 XmNtopWidget, buttons[butcount - 1],
2593 NULL);
2594 else
2595 {
2596 if (*next == NUL)
2597 {
2598 XtVaSetValues(buttons[butcount],
2599 XmNrightAttachment, XmATTACH_FORM,
2600 XmNrightOffset, 4,
2601 NULL);
2602
Bram Moolenaar734a8672019-12-02 22:49:38 +01002603 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 sep_form = XtVaCreateWidget("separatorForm",
2605 xmFormWidgetClass, dialogform,
2606 XmNleftAttachment, XmATTACH_WIDGET,
2607 XmNleftWidget, buttons[butcount - 1],
2608 XmNrightAttachment, XmATTACH_WIDGET,
2609 XmNrightWidget, buttons[butcount],
2610 XmNbottomAttachment, XmATTACH_FORM,
2611 XmNbottomOffset, 4,
2612 NULL);
2613 XtManageChild(sep_form);
2614 }
2615 else
2616 {
2617 XtVaSetValues(buttons[butcount],
2618 XmNleftAttachment, XmATTACH_WIDGET,
2619 XmNleftWidget, buttons[butcount - 1],
2620 NULL);
2621 }
2622 }
2623 }
2624 else if (!vertical)
2625 {
2626 if (*next == NUL)
2627 {
2628 XtVaSetValues(buttons[0],
2629 XmNrightAttachment, XmATTACH_FORM,
2630 XmNrightOffset, 4,
2631 NULL);
2632
Bram Moolenaar734a8672019-12-02 22:49:38 +01002633 // fill in a form as invisible separator
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 sep_form = XtVaCreateWidget("separatorForm",
2635 xmFormWidgetClass, dialogform,
2636 XmNleftAttachment, XmATTACH_FORM,
2637 XmNleftOffset, 4,
2638 XmNrightAttachment, XmATTACH_WIDGET,
2639 XmNrightWidget, buttons[0],
2640 XmNbottomAttachment, XmATTACH_FORM,
2641 XmNbottomOffset, 4,
2642 NULL);
2643 XtManageChild(sep_form);
2644 }
2645 else
2646 XtVaSetValues(buttons[0],
2647 XmNleftAttachment, XmATTACH_FORM,
2648 XmNleftOffset, 4,
2649 NULL);
2650 }
2651
2652 XtAddCallback(buttons[butcount], XmNactivateCallback,
2653 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2654 p = next;
2655 }
2656 vim_free(buts);
2657
2658 separator = (Widget) 0;
2659 if (butcount > 0)
2660 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002661 // Create the separator for beauty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 n = 0;
2663 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2664 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2665 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2666 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2667 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2668 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2669 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2670 XtManageChild(separator);
2671 }
2672
2673 if (textfield != NULL)
2674 {
2675 dialogtextfield = XtVaCreateWidget("textField",
2676 xmTextFieldWidgetClass, dialogform,
2677 XmNleftAttachment, XmATTACH_FORM,
2678 XmNrightAttachment, XmATTACH_FORM,
2679 NULL);
2680 if (butcount > 0)
2681 XtVaSetValues(dialogtextfield,
2682 XmNbottomAttachment, XmATTACH_WIDGET,
2683 XmNbottomWidget, separator,
2684 NULL);
2685 else
2686 XtVaSetValues(dialogtextfield,
2687 XmNbottomAttachment, XmATTACH_FORM,
2688 NULL);
2689
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002690 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2692 XtManageChild(dialogtextfield);
2693 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2694 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2695 }
2696
Bram Moolenaar734a8672019-12-02 22:49:38 +01002697 // Form holding both message and pixmap labels
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 form = XtVaCreateWidget("separatorForm",
2699 xmFormWidgetClass, dialogform,
2700 XmNleftAttachment, XmATTACH_FORM,
2701 XmNrightAttachment, XmATTACH_FORM,
2702 XmNtopAttachment, XmATTACH_FORM,
2703 NULL);
2704 XtManageChild(form);
2705
2706#ifdef HAVE_XPM
Bram Moolenaar734a8672019-12-02 22:49:38 +01002707 // Add a pixmap, left of the message.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 switch (type)
2709 {
2710 case VIM_GENERIC:
2711 icon_data = generic_xpm;
2712 break;
2713 case VIM_ERROR:
2714 icon_data = error_xpm;
2715 break;
2716 case VIM_WARNING:
2717 icon_data = alert_xpm;
2718 break;
2719 case VIM_INFO:
2720 icon_data = info_xpm;
2721 break;
2722 case VIM_QUESTION:
2723 icon_data = quest_xpm;
2724 break;
2725 default:
2726 icon_data = generic_xpm;
2727 }
2728
2729 n = 0;
2730 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2731 XtSetArg(args[n], XmNtopOffset, 8); n++;
2732 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2733 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2734 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2735 XtSetArg(args[n], XmNleftOffset, 8); n++;
2736
2737 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2738 icon_data, args, n);
2739 XtManageChild(dialogpixmap);
2740#endif
2741
Bram Moolenaar734a8672019-12-02 22:49:38 +01002742 // Create the dialog message.
2743 // Since LessTif is apparently having problems with the creation of
2744 // properly localized string, we use LtoR here. The symptom is that the
2745 // string sill not show properly in multiple lines as it does in native
2746 // Motif.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002747 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 if (label == NULL)
2749 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002750 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 xmLabelGadgetClass, form,
2752 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002753 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 XmNtopAttachment, XmATTACH_FORM,
2755 XmNtopOffset, 8,
2756#ifdef HAVE_XPM
2757 XmNleftAttachment, XmATTACH_WIDGET,
2758 XmNleftWidget, dialogpixmap,
2759#else
2760 XmNleftAttachment, XmATTACH_FORM,
2761#endif
2762 XmNleftOffset, 8,
2763 XmNrightAttachment, XmATTACH_FORM,
2764 XmNrightOffset, 8,
2765 XmNbottomAttachment, XmATTACH_FORM,
2766 XmNbottomOffset, 8,
2767 NULL);
2768 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002769 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770
2771 if (textfield != NULL)
2772 {
2773 XtVaSetValues(form,
2774 XmNbottomAttachment, XmATTACH_WIDGET,
2775 XmNbottomWidget, dialogtextfield,
2776 NULL);
2777 }
2778 else
2779 {
2780 if (butcount > 0)
2781 XtVaSetValues(form,
2782 XmNbottomAttachment, XmATTACH_WIDGET,
2783 XmNbottomWidget, separator,
2784 NULL);
2785 else
2786 XtVaSetValues(form,
2787 XmNbottomAttachment, XmATTACH_FORM,
2788 NULL);
2789 }
2790
2791 if (dfltbutton < 1)
2792 dfltbutton = 1;
2793 if (dfltbutton > butcount)
2794 dfltbutton = butcount;
2795 XtVaSetValues(dialogform,
2796 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2797 if (textfield != NULL)
2798 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2799 else
2800 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2801 NULL);
2802
2803 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002804 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805
2806 if (textfield != NULL && *textfield != NUL)
2807 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002808 // This only works after the textfield has been realised.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 XmTextFieldSetSelection(dialogtextfield,
2810 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2811 XtLastTimestampProcessed(gui.dpy));
2812 XmTextFieldSetCursorPosition(dialogtextfield,
2813 (XmTextPosition)STRLEN(textfield));
2814 }
2815
2816 app = XtWidgetToApplicationContext(dialogform);
2817
Bram Moolenaar734a8672019-12-02 22:49:38 +01002818 // Loop until a button is pressed or the dialog is killed somehow.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 dialogStatus = -1;
2820 for (;;)
2821 {
2822 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2823 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2824 break;
2825 }
2826
2827 vim_free(buttons);
2828
2829 if (textfield != NULL)
2830 {
2831 p = (char_u *)XmTextGetString(dialogtextfield);
2832 if (p == NULL || dialogStatus < 0)
2833 *textfield = NUL;
2834 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002835 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002836 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 }
2838
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002839 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 XtDestroyWidget(dialogform);
2841
2842 return dialogStatus;
2843}
Bram Moolenaar734a8672019-12-02 22:49:38 +01002844#endif // FEAT_GUI_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845
2846#if defined(FEAT_FOOTER) || defined(PROTO)
2847
2848 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002849gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002851 Dimension height; // total Toolbar height
2852 Dimension top; // XmNmarginTop
2853 Dimension bottom; // XmNmarginBottom
2854 Dimension shadow; // XmNshadowThickness
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855
2856 XtVaGetValues(footer,
2857 XmNheight, &height,
2858 XmNmarginTop, &top,
2859 XmNmarginBottom, &bottom,
2860 XmNshadowThickness, &shadow,
2861 NULL);
2862
2863 return (int) height + top + bottom + (shadow << 1);
2864}
2865
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002867gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868{
2869 if (showit)
2870 {
2871 gui.footer_height = gui_mch_compute_footer_height();
2872 XtManageChild(footer);
2873 }
2874 else
2875 {
2876 gui.footer_height = 0;
2877 XtUnmanageChild(footer);
2878 }
2879 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2880}
2881
2882 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002883gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884{
2885 XmString xms;
2886
2887 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002888 if (xms != NULL)
2889 {
2890 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2891 XmStringFree(xms);
2892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893}
2894
2895#endif
2896
2897
2898#if defined(FEAT_TOOLBAR) || defined(PROTO)
2899 void
2900gui_mch_show_toolbar(int showit)
2901{
Bram Moolenaar734a8672019-12-02 22:49:38 +01002902 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903
2904 if (toolBar == (Widget)0)
2905 return;
2906 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2907 if (showit && numChildren > 0)
2908 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01002909 // Assume that we want to show the toolbar if p_toolbar contains
2910 // valid option settings, therefore p_toolbar must not be NULL.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 WidgetList children;
2912
2913 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2914 {
2915 void (*action)(BalloonEval *);
2916 int text = 0;
2917
2918 if (strstr((const char *)p_toolbar, "tooltips"))
2919 action = &gui_mch_enable_beval_area;
2920 else
2921 action = &gui_mch_disable_beval_area;
2922 if (strstr((const char *)p_toolbar, "text"))
2923 text = 1;
2924 else if (strstr((const char *)p_toolbar, "icons"))
2925 text = -1;
2926 if (text != 0)
2927 {
2928 vimmenu_T *toolbar;
2929 vimmenu_T *cur;
2930
2931 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
2932 if (menu_is_toolbar(toolbar->dname))
2933 break;
Bram Moolenaar734a8672019-12-02 22:49:38 +01002934 // Assumption: toolbar is NULL if there is no toolbar,
2935 // otherwise it contains the toolbar menu structure.
2936 //
2937 // Assumption: "numChildren" == the number of items in the list
2938 // of items beginning with toolbar->children.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 if (toolbar)
2940 {
2941 for (cur = toolbar->children; cur; cur = cur->next)
2942 {
2943 Arg args[1];
2944 int n = 0;
2945
Bram Moolenaar734a8672019-12-02 22:49:38 +01002946 // Enable/Disable tooltip (OK to enable while
2947 // currently enabled).
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 if (cur->tip != NULL)
2949 (*action)(cur->tip);
2950 if (!menu_is_separator(cur->name))
2951 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002952 if (text == 1 || cur->xpm == NULL)
2953 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002955 ++n;
2956 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 if (cur->id != NULL)
2958 {
2959 XtUnmanageChild(cur->id);
2960 XtSetValues(cur->id, args, n);
2961 XtManageChild(cur->id);
2962 }
2963 }
2964 }
2965 }
2966 }
2967 }
2968 gui.toolbar_height = gui_mch_compute_toolbar_height();
2969 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002970#ifdef FEAT_GUI_TABLINE
2971 if (showing_tabline)
2972 {
2973 XtVaSetValues(tabLine,
2974 XmNtopAttachment, XmATTACH_WIDGET,
2975 XmNtopWidget, XtParent(toolBar),
2976 NULL);
2977 XtVaSetValues(textAreaForm,
2978 XmNtopAttachment, XmATTACH_WIDGET,
2979 XmNtopWidget, tabLine,
2980 NULL);
2981 }
2982 else
2983#endif
2984 XtVaSetValues(textAreaForm,
2985 XmNtopAttachment, XmATTACH_WIDGET,
2986 XmNtopWidget, XtParent(toolBar),
2987 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 if (XtIsManaged(menuBar))
2989 XtVaSetValues(XtParent(toolBar),
2990 XmNtopAttachment, XmATTACH_WIDGET,
2991 XmNtopWidget, menuBar,
2992 NULL);
2993 else
2994 XtVaSetValues(XtParent(toolBar),
2995 XmNtopAttachment, XmATTACH_FORM,
2996 NULL);
2997 }
2998 else
2999 {
3000 gui.toolbar_height = 0;
3001 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003002 {
3003#ifdef FEAT_GUI_TABLINE
3004 if (showing_tabline)
3005 {
3006 XtVaSetValues(tabLine,
3007 XmNtopAttachment, XmATTACH_WIDGET,
3008 XmNtopWidget, menuBar,
3009 NULL);
3010 XtVaSetValues(textAreaForm,
3011 XmNtopAttachment, XmATTACH_WIDGET,
3012 XmNtopWidget, tabLine,
3013 NULL);
3014 }
3015 else
3016#endif
3017 XtVaSetValues(textAreaForm,
3018 XmNtopAttachment, XmATTACH_WIDGET,
3019 XmNtopWidget, menuBar,
3020 NULL);
3021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003023 {
3024#ifdef FEAT_GUI_TABLINE
3025 if (showing_tabline)
3026 {
3027 XtVaSetValues(tabLine,
3028 XmNtopAttachment, XmATTACH_FORM,
3029 NULL);
3030 XtVaSetValues(textAreaForm,
3031 XmNtopAttachment, XmATTACH_WIDGET,
3032 XmNtopWidget, tabLine,
3033 NULL);
3034 }
3035 else
3036#endif
3037 XtVaSetValues(textAreaForm,
3038 XmNtopAttachment, XmATTACH_FORM,
3039 NULL);
3040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041
3042 XtUnmanageChild(XtParent(toolBar));
3043 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003044 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045}
3046
3047/*
3048 * A toolbar button has been pushed; now reset the input focus
3049 * such that the user can type page up/down etc. and have the
3050 * input go to the editor window, not the button
3051 */
3052 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003053reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054{
3055 if (textArea != NULL)
3056 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3057}
3058
3059 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003060gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003062 Dimension borders;
Bram Moolenaar734a8672019-12-02 22:49:38 +01003063 Dimension height; // total Toolbar height
3064 Dimension whgt; // height of each widget
3065 WidgetList children; // list of toolBar's children
3066 Cardinal numChildren; // how many children toolBar has
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 int i;
3068
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003069 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003072 { // get height of XmFrame parent
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003073 Dimension fst;
3074 Dimension fmh;
3075 Dimension tst;
3076 Dimension tmh;
3077
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003079 XmNshadowThickness, &fst,
3080 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003082 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003084 XmNshadowThickness, &tst,
3085 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 XmNchildren, &children,
3087 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003088 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003089 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {
3091 whgt = 0;
3092 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3093 if (height < whgt)
3094 height = whgt;
3095 }
3096 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003097#ifdef LESSTIF_VERSION
Bram Moolenaar734a8672019-12-02 22:49:38 +01003098 // Hack: When starting up we get wrong dimensions.
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003099 if (height < 10)
3100 height = 24;
3101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003103 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104}
3105
Bram Moolenaar7c626922005-02-07 22:01:03 +00003106 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003107motif_get_toolbar_colors(
3108 Pixel *bgp,
3109 Pixel *fgp,
3110 Pixel *bsp,
3111 Pixel *tsp,
3112 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003113{
3114 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003115 XmNbackground, bgp,
3116 XmNforeground, fgp,
3117 XmNbottomShadowColor, bsp,
3118 XmNtopShadowColor, tsp,
3119 XmNhighlightColor, hsp,
3120 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003121}
3122
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123# ifdef FEAT_FOOTER
3124/*
3125 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003126 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 * get implemented and the user will have a choice.
3128 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003130toolbarbutton_enter_cb(
3131 Widget w UNUSED,
3132 XtPointer client_data,
3133 XEvent *event UNUSED,
3134 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135{
3136 vimmenu_T *menu = (vimmenu_T *) client_data;
3137
3138 if (menu->strings[MENU_INDEX_TIP] != NULL)
3139 {
3140 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3141 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3142 }
3143}
3144
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003146toolbarbutton_leave_cb(
3147 Widget w UNUSED,
3148 XtPointer client_data UNUSED,
3149 XEvent *event UNUSED,
3150 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151{
3152 gui_mch_set_footer((char_u *) "");
3153}
3154# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155#endif
3156
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003157#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3158/*
3159 * Show or hide the tabline.
3160 */
3161 void
3162gui_mch_show_tabline(int showit)
3163{
3164 if (tabLine == (Widget)0)
3165 return;
3166
3167 if (!showit != !showing_tabline)
3168 {
3169 if (showit)
3170 {
3171 XtManageChild(tabLine);
3172 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003173 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3174 XtUnmanageChild(XtNameToWidget(tabLine,
3175 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003176#ifdef FEAT_MENU
3177# ifdef FEAT_TOOLBAR
3178 if (XtIsManaged(XtParent(toolBar)))
3179 XtVaSetValues(tabLine,
3180 XmNtopAttachment, XmATTACH_WIDGET,
3181 XmNtopWidget, XtParent(toolBar), NULL);
3182 else
3183# endif
3184 if (XtIsManaged(menuBar))
3185 XtVaSetValues(tabLine,
3186 XmNtopAttachment, XmATTACH_WIDGET,
3187 XmNtopWidget, menuBar, NULL);
3188 else
3189#endif
3190 XtVaSetValues(tabLine,
3191 XmNtopAttachment, XmATTACH_FORM, NULL);
3192 XtVaSetValues(textAreaForm,
3193 XmNtopAttachment, XmATTACH_WIDGET,
3194 XmNtopWidget, tabLine,
3195 NULL);
3196 }
3197 else
3198 {
3199 XtUnmanageChild(tabLine);
3200#ifdef FEAT_MENU
3201# ifdef FEAT_TOOLBAR
3202 if (XtIsManaged(XtParent(toolBar)))
3203 XtVaSetValues(textAreaForm,
3204 XmNtopAttachment, XmATTACH_WIDGET,
3205 XmNtopWidget, XtParent(toolBar), NULL);
3206 else
3207# endif
3208 if (XtIsManaged(menuBar))
3209 XtVaSetValues(textAreaForm,
3210 XmNtopAttachment, XmATTACH_WIDGET,
3211 XmNtopWidget, menuBar, NULL);
3212 else
3213#endif
3214 XtVaSetValues(textAreaForm,
3215 XmNtopAttachment, XmATTACH_FORM, NULL);
3216 }
3217 showing_tabline = showit;
3218 }
3219}
3220
3221/*
3222 * Return TRUE when tabline is displayed.
3223 */
3224 int
3225gui_mch_showing_tabline(void)
3226{
3227 return tabLine != (Widget)0 && showing_tabline;
3228}
3229
3230/*
3231 * Update the labels of the tabline.
3232 */
3233 void
3234gui_mch_update_tabline(void)
3235{
3236 tabpage_T *tp;
3237 int nr = 1, n;
3238 Arg args[10];
3239 int curtabidx = 0, currentpage;
3240 Widget tab;
3241 XmNotebookPageInfo page_info;
3242 XmNotebookPageStatus page_status;
3243 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003244 XmString label_str;
3245 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003246 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003247
3248 if (tabLine == (Widget)0)
3249 return;
3250
Bram Moolenaar734a8672019-12-02 22:49:38 +01003251 // Add a label for each tab page. They all contain the same text area.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003252 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3253 {
3254 if (tp == curtab)
3255 curtabidx = nr;
3256
3257 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3258 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003259 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003260 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01003261 // Add the tab
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003262 n = 0;
3263 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3264 XtSetArg(args[n], XmNtraversalOn, False); n++;
3265 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3266 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3267 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3268 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3269 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003270 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3271 NULL);
3272 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003273 }
3274 else
3275 tab = page_info.major_tab_widget;
3276
3277 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003278
3279 /*
3280 * Change the label text only if it is different
3281 */
3282 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3283 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3284 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003285 get_tabline_label(tp, FALSE);
3286 if (STRCMP(label_cstr, NameBuff) != 0)
3287 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003288 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3289 NameBuff, STRLEN(NameBuff) + 1, NULL);
3290 /*
3291 * Force a resize of the tab label button
3292 */
3293 XtUnmanageChild(tab);
3294 XtManageChild(tab);
3295 }
3296 XtFree(label_cstr);
3297 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003298 }
3299
3300 tab_count = nr - 1;
3301
3302 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3303
Bram Moolenaar734a8672019-12-02 22:49:38 +01003304 // Remove any old labels.
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003305 while (nr <= last_page)
3306 {
3307 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3308 && page_info.page_number == nr
3309 && page_info.major_tab_widget != (Widget)0)
3310 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003311 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3312 if (beval != NULL)
3313 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003314 XtUnmanageChild(page_info.major_tab_widget);
3315 XtDestroyWidget(page_info.major_tab_widget);
3316 }
3317 nr++;
3318 }
3319
3320 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3321
3322 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3323 if (currentpage != curtabidx)
3324 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3325}
3326
3327/*
3328 * Set the current tab to "nr". First tab is 1.
3329 */
3330 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003331gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003332{
3333 int currentpage;
3334
3335 if (tabLine == (Widget)0)
3336 return;
3337
3338 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3339 if (currentpage != nr)
3340 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3341}
3342#endif
3343
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344/*
3345 * Set the colors of Widget "id" to the menu colors.
3346 */
3347 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003348gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349{
3350 if (gui.menu_bg_pixel != INVALCOLOR)
3351#if (XmVersion >= 1002)
3352 XmChangeColor(id, gui.menu_bg_pixel);
3353#else
3354 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3355#endif
3356 if (gui.menu_fg_pixel != INVALCOLOR)
3357 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3358}
3359
3360/*
3361 * Set the colors of Widget "id" to the scrollbar colors.
3362 */
3363 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003364gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365{
3366 if (gui.scroll_bg_pixel != INVALCOLOR)
3367#if (XmVersion >= 1002)
3368 XmChangeColor(id, gui.scroll_bg_pixel);
3369#else
3370 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3371#endif
3372 if (gui.scroll_fg_pixel != INVALCOLOR)
3373 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3374}
3375
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376/*
3377 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3378 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003379 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003380gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003382#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383#ifdef FONTSET_ALWAYS
3384 if (gui.menu_fontset != NOFONTSET)
3385 {
3386 XmFontList fl;
3387
3388 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3389 if (fl != NULL)
3390 {
3391 if (XtIsManaged(id))
3392 {
3393 XtUnmanageChild(id);
3394 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003395 // We should force the widget to recalculate its
3396 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 XtManageChild(id);
3398 }
3399 else
3400 XtVaSetValues(id, XmNfontList, fl, NULL);
3401 XmFontListFree(fl);
3402 }
3403 }
3404#else
3405 if (gui.menu_font != NOFONT)
3406 {
3407 XmFontList fl;
3408
3409 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3410 if (fl != NULL)
3411 {
3412 if (XtIsManaged(id))
3413 {
3414 XtUnmanageChild(id);
3415 XtVaSetValues(id, XmNfontList, fl, NULL);
Bram Moolenaar734a8672019-12-02 22:49:38 +01003416 // We should force the widget to recalculate its
3417 // geometry now.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 XtManageChild(id);
3419 }
3420 else
3421 XtVaSetValues(id, XmNfontList, fl, NULL);
3422 XmFontListFree(fl);
3423 }
3424 }
3425#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427}
3428
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429
3430/*
3431 * We don't create it twice for the sake of speed.
3432 */
3433
3434typedef struct _SharedFindReplace
3435{
Bram Moolenaar734a8672019-12-02 22:49:38 +01003436 Widget dialog; // the main dialog widget
3437 Widget wword; // 'Exact match' check button
3438 Widget mcase; // 'match case' check button
3439 Widget up; // search direction 'Up' radio button
3440 Widget down; // search direction 'Down' radio button
3441 Widget what; // 'Find what' entry text widget
3442 Widget with; // 'Replace with' entry text widget
3443 Widget find; // 'Find Next' action button
3444 Widget replace; // 'Replace With' action button
3445 Widget all; // 'Replace All' action button
3446 Widget undo; // 'Undo' action button
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447
3448 Widget cancel;
3449} SharedFindReplace;
3450
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003451static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3452static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003455find_replace_destroy_callback(
3456 Widget w UNUSED,
3457 XtPointer client_data,
3458 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459{
3460 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3461
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003462 if (cd != NULL)
Bram Moolenaar734a8672019-12-02 22:49:38 +01003463 // suppress_dialog_mnemonics(cd->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 cd->dialog = (Widget)0;
3465}
3466
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003468find_replace_dismiss_callback(
3469 Widget w UNUSED,
3470 XtPointer client_data,
3471 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472{
3473 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3474
3475 if (cd != NULL)
3476 XtUnmanageChild(cd->dialog);
3477}
3478
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003480entry_activate_callback(
3481 Widget w UNUSED,
3482 XtPointer client_data,
3483 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484{
3485 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3486}
3487
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003489find_replace_callback(
3490 Widget w UNUSED,
3491 XtPointer client_data,
3492 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493{
3494 long_u flags = (long_u)client_data;
3495 char *find_text, *repl_text;
3496 Boolean direction_down = TRUE;
3497 Boolean wword;
3498 Boolean mcase;
3499 SharedFindReplace *sfr;
3500
3501 if (flags == FRD_UNDO)
3502 {
3503 char_u *save_cpo = p_cpo;
3504
Bram Moolenaar734a8672019-12-02 22:49:38 +01003505 // No need to be Vi compatible here.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 p_cpo = (char_u *)"";
3507 u_undo(1);
3508 p_cpo = save_cpo;
3509 gui_update_screen();
3510 return;
3511 }
3512
Bram Moolenaar734a8672019-12-02 22:49:38 +01003513 // Get the search/replace strings from the dialog
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 if (flags == FRD_FINDNEXT)
3515 {
3516 repl_text = NULL;
3517 sfr = &find_widgets;
3518 }
3519 else
3520 {
3521 repl_text = XmTextFieldGetString(repl_widgets.with);
3522 sfr = &repl_widgets;
3523 }
3524 find_text = XmTextFieldGetString(sfr->what);
3525 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3526 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3527 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3528 if (wword)
3529 flags |= FRD_WHOLE_WORD;
3530 if (mcase)
3531 flags |= FRD_MATCH_CASE;
3532
3533 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3534 direction_down);
3535
3536 if (find_text != NULL)
3537 XtFree(find_text);
3538 if (repl_text != NULL)
3539 XtFree(repl_text);
3540}
3541
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003543find_replace_keypress(
3544 Widget w UNUSED,
3545 SharedFindReplace *frdp,
3546 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547{
3548 KeySym keysym;
3549
3550 if (frdp == NULL)
3551 return;
3552
3553 keysym = XLookupKeysym(event, 0);
3554
Bram Moolenaar734a8672019-12-02 22:49:38 +01003555 // the scape key pops the whole dialog down
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556 if (keysym == XK_Escape)
3557 XtUnmanageChild(frdp->dialog);
3558}
3559
3560 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003561set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003562{
3563 XmString str;
3564 char_u *p, *next;
3565 KeySym mnemonic = NUL;
3566
3567 if (!w)
3568 return;
3569
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003570 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003571 if (p == NULL)
3572 return;
3573 for (next = p; *next; ++next)
3574 {
3575 if (*next == DLG_HOTKEY_CHAR)
3576 {
3577 int len = STRLEN(next);
3578
3579 if (len > 0)
3580 {
3581 mch_memmove(next, next + 1, len);
3582 mnemonic = next[0];
3583 }
3584 }
3585 }
3586
3587 str = XmStringCreateSimple((char *)p);
3588 vim_free(p);
3589 if (str)
3590 {
3591 XtVaSetValues(w,
3592 XmNlabelString, str,
3593 XmNmnemonic, mnemonic,
3594 NULL);
3595 XmStringFree(str);
3596 }
3597 gui_motif_menu_fontlist(w);
3598}
3599
3600 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003601find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602{
3603 SharedFindReplace *frdp;
3604 Widget separator;
3605 Widget input_form;
3606 Widget button_form;
3607 Widget toggle_form;
3608 Widget frame;
3609 XmString str;
3610 int n;
3611 Arg args[6];
3612 int wword = FALSE;
3613 int mcase = !p_ic;
3614 Dimension width;
3615 Dimension widest;
3616 char_u *entry_text;
3617
3618 frdp = do_replace ? &repl_widgets : &find_widgets;
3619
Bram Moolenaar734a8672019-12-02 22:49:38 +01003620 // Get the search string to use.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3622
Bram Moolenaar734a8672019-12-02 22:49:38 +01003623 // If the dialog already exists, just raise it.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624 if (frdp->dialog)
3625 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003626 gui_motif_synch_fonts();
3627
Bram Moolenaar734a8672019-12-02 22:49:38 +01003628 // If the window is already up, just pop it to the top
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 if (XtIsManaged(frdp->dialog))
3630 XMapRaised(XtDisplay(frdp->dialog),
3631 XtWindow(XtParent(frdp->dialog)));
3632 else
3633 XtManageChild(frdp->dialog);
3634 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3635 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3636
3637 if (entry_text != NULL)
3638 XmTextFieldSetString(frdp->what, (char *)entry_text);
3639 vim_free(entry_text);
3640
3641 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3642 return;
3643 }
3644
Bram Moolenaar734a8672019-12-02 22:49:38 +01003645 // Create a fresh new dialog window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 if (do_replace)
3647 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3648 else
3649 str = XmStringCreateSimple(_("VIM - Search..."));
3650
3651 n = 0;
3652 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3653 XtSetArg(args[n], XmNnoResize, True); n++;
3654 XtSetArg(args[n], XmNdialogTitle, str); n++;
3655
3656 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3657 XmStringFree(str);
3658 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3659 find_replace_destroy_callback, frdp);
3660
3661 button_form = XtVaCreateWidget("buttonForm",
3662 xmFormWidgetClass, frdp->dialog,
3663 XmNrightAttachment, XmATTACH_FORM,
3664 XmNrightOffset, 4,
3665 XmNtopAttachment, XmATTACH_FORM,
3666 XmNtopOffset, 4,
3667 XmNbottomAttachment, XmATTACH_FORM,
3668 XmNbottomOffset, 4,
3669 NULL);
3670
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 frdp->find = XtVaCreateManagedWidget("findButton",
3672 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 XmNsensitive, True,
3674 XmNtopAttachment, XmATTACH_FORM,
3675 XmNleftAttachment, XmATTACH_FORM,
3676 XmNrightAttachment, XmATTACH_FORM,
3677 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003678 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679
3680 XtAddCallback(frdp->find, XmNactivateCallback,
3681 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003682 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683
3684 if (do_replace)
3685 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3687 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 XmNtopAttachment, XmATTACH_WIDGET,
3689 XmNtopWidget, frdp->find,
3690 XmNleftAttachment, XmATTACH_FORM,
3691 XmNrightAttachment, XmATTACH_FORM,
3692 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003693 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 XtAddCallback(frdp->replace, XmNactivateCallback,
3695 find_replace_callback, (XtPointer)FRD_REPLACE);
3696
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3698 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003699 XmNtopAttachment, XmATTACH_WIDGET,
3700 XmNtopWidget, frdp->replace,
3701 XmNleftAttachment, XmATTACH_FORM,
3702 XmNrightAttachment, XmATTACH_FORM,
3703 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003704 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 XtAddCallback(frdp->all, XmNactivateCallback,
3706 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3707
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708 frdp->undo = XtVaCreateManagedWidget("undoButton",
3709 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 XmNtopAttachment, XmATTACH_WIDGET,
3711 XmNtopWidget, frdp->all,
3712 XmNleftAttachment, XmATTACH_FORM,
3713 XmNrightAttachment, XmATTACH_FORM,
3714 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003715 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 XtAddCallback(frdp->undo, XmNactivateCallback,
3717 find_replace_callback, (XtPointer)FRD_UNDO);
3718 }
3719
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3721 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 XmNleftAttachment, XmATTACH_FORM,
3723 XmNrightAttachment, XmATTACH_FORM,
3724 XmNbottomAttachment, XmATTACH_FORM,
3725 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003726 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 XtAddCallback(frdp->cancel, XmNactivateCallback,
3728 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003729 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730
3731 XtManageChild(button_form);
3732
3733 n = 0;
3734 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3735 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3736 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3737 XtSetArg(args[n], XmNrightOffset, 4); n++;
3738 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3739 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3740 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3741 XtManageChild(separator);
3742
3743 input_form = XtVaCreateWidget("inputForm",
3744 xmFormWidgetClass, frdp->dialog,
3745 XmNleftAttachment, XmATTACH_FORM,
3746 XmNleftOffset, 4,
3747 XmNrightAttachment, XmATTACH_WIDGET,
3748 XmNrightWidget, separator,
3749 XmNrightOffset, 4,
3750 XmNtopAttachment, XmATTACH_FORM,
3751 XmNtopOffset, 4,
3752 NULL);
3753
3754 {
3755 Widget label_what;
3756 Widget label_with = (Widget)0;
3757
3758 str = XmStringCreateSimple(_("Find what:"));
3759 label_what = XtVaCreateManagedWidget("whatLabel",
3760 xmLabelGadgetClass, input_form,
3761 XmNlabelString, str,
3762 XmNleftAttachment, XmATTACH_FORM,
3763 XmNtopAttachment, XmATTACH_FORM,
3764 XmNtopOffset, 4,
3765 NULL);
3766 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003767 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768
3769 frdp->what = XtVaCreateManagedWidget("whatText",
3770 xmTextFieldWidgetClass, input_form,
3771 XmNtopAttachment, XmATTACH_FORM,
3772 XmNrightAttachment, XmATTACH_FORM,
3773 XmNleftAttachment, XmATTACH_FORM,
3774 NULL);
3775
3776 if (do_replace)
3777 {
3778 frdp->with = XtVaCreateManagedWidget("withText",
3779 xmTextFieldWidgetClass, input_form,
3780 XmNtopAttachment, XmATTACH_WIDGET,
3781 XmNtopWidget, frdp->what,
3782 XmNtopOffset, 4,
3783 XmNleftAttachment, XmATTACH_FORM,
3784 XmNrightAttachment, XmATTACH_FORM,
3785 XmNbottomAttachment, XmATTACH_FORM,
3786 NULL);
3787
3788 XtAddCallback(frdp->with, XmNactivateCallback,
3789 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3790
3791 str = XmStringCreateSimple(_("Replace with:"));
3792 label_with = XtVaCreateManagedWidget("withLabel",
3793 xmLabelGadgetClass, input_form,
3794 XmNlabelString, str,
3795 XmNleftAttachment, XmATTACH_FORM,
3796 XmNtopAttachment, XmATTACH_WIDGET,
3797 XmNtopWidget, frdp->what,
3798 XmNtopOffset, 4,
3799 XmNbottomAttachment, XmATTACH_FORM,
3800 NULL);
3801 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003802 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803
3804 /*
3805 * Make the entry activation only change the input focus onto the
3806 * with item.
3807 */
3808 XtAddCallback(frdp->what, XmNactivateCallback,
3809 entry_activate_callback, frdp->with);
3810 XtAddEventHandler(frdp->with, KeyPressMask, False,
3811 (XtEventHandler)find_replace_keypress,
3812 (XtPointer) frdp);
3813
3814 }
3815 else
3816 {
3817 /*
3818 * Make the entry activation do the search.
3819 */
3820 XtAddCallback(frdp->what, XmNactivateCallback,
3821 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3822 }
3823 XtAddEventHandler(frdp->what, KeyPressMask, False,
3824 (XtEventHandler)find_replace_keypress,
3825 (XtPointer)frdp);
3826
Bram Moolenaar734a8672019-12-02 22:49:38 +01003827 // Get the maximum width between the label widgets and line them up.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828 n = 0;
3829 XtSetArg(args[n], XmNwidth, &width); n++;
3830 XtGetValues(label_what, args, n);
3831 widest = width;
3832 if (do_replace)
3833 {
3834 XtGetValues(label_with, args, n);
3835 if (width > widest)
3836 widest = width;
3837 }
3838
3839 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3840 if (do_replace)
3841 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3842
3843 }
3844
3845 XtManageChild(input_form);
3846
3847 {
3848 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003849 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850
3851 frame = XtVaCreateWidget("directionFrame",
3852 xmFrameWidgetClass, frdp->dialog,
3853 XmNtopAttachment, XmATTACH_WIDGET,
3854 XmNtopWidget, input_form,
3855 XmNtopOffset, 4,
3856 XmNbottomAttachment, XmATTACH_FORM,
3857 XmNbottomOffset, 4,
3858 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3859 XmNrightWidget, input_form,
3860 NULL);
3861
3862 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003863 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 xmLabelGadgetClass, frame,
3865 XmNlabelString, str,
3866 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3867 XmNchildType, XmFRAME_TITLE_CHILD,
3868 NULL);
3869 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003870 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871
3872 radio_box = XmCreateRadioBox(frame, "radioBox",
3873 (ArgList)NULL, 0);
3874
3875 str = XmStringCreateSimple( _("Up"));
3876 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3877 xmToggleButtonGadgetClass, radio_box,
3878 XmNlabelString, str,
3879 XmNset, False,
3880 NULL);
3881 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003882 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883
3884 str = XmStringCreateSimple(_("Down"));
3885 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3886 xmToggleButtonGadgetClass, radio_box,
3887 XmNlabelString, str,
3888 XmNset, True,
3889 NULL);
3890 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003891 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892
3893 XtManageChild(radio_box);
3894 XtManageChild(frame);
3895 }
3896
3897 toggle_form = XtVaCreateWidget("toggleForm",
3898 xmFormWidgetClass, frdp->dialog,
3899 XmNleftAttachment, XmATTACH_FORM,
3900 XmNleftOffset, 4,
3901 XmNrightAttachment, XmATTACH_WIDGET,
3902 XmNrightWidget, frame,
3903 XmNrightOffset, 4,
3904 XmNtopAttachment, XmATTACH_WIDGET,
3905 XmNtopWidget, input_form,
3906 XmNtopOffset, 4,
3907 XmNbottomAttachment, XmATTACH_FORM,
3908 XmNbottomOffset, 4,
3909 NULL);
3910
3911 str = XmStringCreateSimple(_("Match whole word only"));
3912 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3913 xmToggleButtonGadgetClass, toggle_form,
3914 XmNlabelString, str,
3915 XmNtopAttachment, XmATTACH_FORM,
3916 XmNtopOffset, 4,
3917 XmNleftAttachment, XmATTACH_FORM,
3918 XmNleftOffset, 4,
3919 XmNset, wword,
3920 NULL);
3921 XmStringFree(str);
3922
3923 str = XmStringCreateSimple(_("Match case"));
3924 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3925 xmToggleButtonGadgetClass, toggle_form,
3926 XmNlabelString, str,
3927 XmNleftAttachment, XmATTACH_FORM,
3928 XmNleftOffset, 4,
3929 XmNtopAttachment, XmATTACH_WIDGET,
3930 XmNtopWidget, frdp->wword,
3931 XmNtopOffset, 4,
3932 XmNset, mcase,
3933 NULL);
3934 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003935 gui_motif_menu_fontlist(frdp->wword);
3936 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937
3938 XtManageChild(toggle_form);
3939
3940 if (entry_text != NULL)
3941 XmTextFieldSetString(frdp->what, (char *)entry_text);
3942 vim_free(entry_text);
3943
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003944 gui_motif_synch_fonts();
3945
3946 manage_centered(frdp->dialog);
3947 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3949}
3950
3951 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003952gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953{
3954 if (!gui.in_use)
3955 return;
3956
3957 find_replace_dialog_create(eap->arg, FALSE);
3958}
3959
3960
3961 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003962gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963{
3964 if (!gui.in_use)
3965 return;
3966
3967 find_replace_dialog_create(eap->arg, TRUE);
3968}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003969
3970/*
3971 * Synchronize all gui elements, which are dependant upon the
3972 * main text font used. Those are in esp. the find/replace dialogs.
3973 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01003974 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003975 */
3976 void
3977gui_motif_synch_fonts(void)
3978{
3979 SharedFindReplace *frdp;
3980 int do_replace;
3981 XFontStruct *font;
3982 XmFontList font_list;
3983
Bram Moolenaar734a8672019-12-02 22:49:38 +01003984 // FIXME: Unless we find out how to create a XmFontList from a XFontSet,
3985 // we just give up here on font synchronization.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003986 font = (XFontStruct *)gui.norm_font;
3987 if (font == NULL)
3988 return;
3989
3990 font_list = gui_motif_create_fontlist(font);
3991
Bram Moolenaar734a8672019-12-02 22:49:38 +01003992 // OK this loop is a bit tricky...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003993 for (do_replace = 0; do_replace <= 1; ++do_replace)
3994 {
3995 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3996 if (frdp->dialog)
3997 {
3998 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
3999 if (do_replace)
4000 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4001 }
4002 }
4003
4004 XmFontListFree(font_list);
4005}