blob: 72a2915290809748a0c7374bda6aab080a13881e [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
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
11#include <Xm/Form.h>
12#include <Xm/RowColumn.h>
13#include <Xm/PushB.h>
14#include <Xm/Text.h>
15#include <Xm/TextF.h>
16#include <Xm/Separator.h>
17#include <Xm/Label.h>
18#include <Xm/CascadeB.h>
19#include <Xm/ScrollBar.h>
20#include <Xm/MenuShell.h>
21#include <Xm/DrawingA.h>
22#if (XmVersion >= 1002)
23# include <Xm/RepType.h>
24#endif
25#include <Xm/Frame.h>
26#include <Xm/LabelG.h>
27#include <Xm/ToggleBG.h>
28#include <Xm/SeparatoG.h>
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000029#include <Xm/XmP.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
31#include <X11/keysym.h>
32#include <X11/Xatom.h>
33#include <X11/StringDefs.h>
34#include <X11/Intrinsic.h>
35
36#include "vim.h"
37
38#ifdef HAVE_X11_XPM_H
39# include <X11/xpm.h>
40#else
41# ifdef HAVE_XM_XPMP_H
42# include <Xm/XpmP.h>
43# endif
44#endif
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000045#ifdef HAVE_XM_NOTEBOOK_H
46# include <Xm/Notebook.h>
47#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaarb7fcef52005-01-02 11:31:05 +000049#include "gui_xmebw.h" /* for our Enhanced Button Widget */
50
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
52# include "../pixmaps/alert.xpm"
53# include "../pixmaps/error.xpm"
54# include "../pixmaps/generic.xpm"
55# include "../pixmaps/info.xpm"
56# include "../pixmaps/quest.xpm"
57#endif
58
59#define MOTIF_POPUP
60
61extern Widget vimShell;
62
63static Widget vimForm;
64static Widget textAreaForm;
65Widget textArea;
66#ifdef FEAT_TOOLBAR
67static Widget toolBarFrame;
68static Widget toolBar;
69#endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +000070#ifdef FEAT_GUI_TABLINE
71static Widget tabLine;
72static Widget tabLine_menu = 0;
73static int showing_tabline = 0;
74#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000075#ifdef FEAT_FOOTER
76static Widget footer;
77#endif
78#ifdef FEAT_MENU
79# if (XmVersion >= 1002)
80/* remember the last set value for the tearoff item */
81static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
82# endif
83static Widget menuBar;
84#endif
85
Bram Moolenaard25c16e2016-01-29 22:13:30 +010086static void scroll_cb(Widget w, XtPointer client_data, XtPointer call_data);
Bram Moolenaar910f66f2006-04-05 20:41:53 +000087#ifdef FEAT_GUI_TABLINE
Bram Moolenaard25c16e2016-01-29 22:13:30 +010088static void tabline_cb(Widget w, XtPointer client_data, XtPointer call_data);
89static void tabline_button_cb(Widget w, XtPointer client_data, XtPointer call_data);
90static void tabline_menu_cb(Widget w, XtPointer closure, XEvent *e, Boolean *continue_dispatch);
91static void tabline_balloon_cb(BalloonEval *beval, int state);
Bram Moolenaar910f66f2006-04-05 20:41:53 +000092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000093#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000094# ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +010095static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
96static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000097# endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +010098static void reset_focus(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000099#endif
100#ifdef FEAT_FOOTER
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100101static int gui_mch_compute_footer_height(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102#endif
103#ifdef WSDEBUG
104static void attachDump(Widget, char *);
105#endif
106
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100107static void gui_motif_menu_colors(Widget id);
108static void gui_motif_scroll_colors(Widget id);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
110#if (XmVersion >= 1002)
111# define STRING_TAG XmFONTLIST_DEFAULT_TAG
112#else
113# define STRING_TAG XmSTRING_DEFAULT_CHARSET
114#endif
115
116/*
117 * Call-back routines.
118 */
119
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100121scroll_cb(Widget w UNUSED, XtPointer client_data, call_data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122{
123 scrollbar_T *sb;
124 long value;
125 int dragging;
126
127 sb = gui_find_scrollbar((long)client_data);
128
129 value = ((XmScrollBarCallbackStruct *)call_data)->value;
130 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
131 (int)XmCR_DRAG);
132 gui_drag_scrollbar(sb, value, dragging);
133}
134
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000135#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000136 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100137tabline_cb(
138 Widget w UNUSED,
139 XtPointer client_data UNUSED,
140 XtPointer call_data)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000141{
142 XmNotebookCallbackStruct *nptr;
143
144 nptr = (XmNotebookCallbackStruct *)call_data;
145 if (nptr->reason != (int)XmCR_NONE)
146 send_tabline_event(nptr->page_number);
147}
148
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000149 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100150tabline_button_cb(
151 Widget w,
152 XtPointer client_data UNUSED,
153 XtPointer call_data UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000154{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000155 int cmd, tab_idx;
156
157 XtVaGetValues(w, XmNuserData, &cmd, NULL);
158 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
159
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000160 send_tabline_menu_event(tab_idx, cmd);
161}
162
163/*
164 * Tabline single mouse click timeout handler
165 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000166 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100167motif_tabline_timer_cb (
168 XtPointer timed_out,
169 XtIntervalId *interval_id UNUSED)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000170{
171 *((int *)timed_out) = TRUE;
172}
173
174/*
175 * check if the tabline tab scroller is clicked
176 */
177 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100178tabline_scroller_clicked(
179 char *scroller_name,
180 XButtonPressedEvent *event)
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000181{
182 Widget tab_scroll_w;
183 Position pos_x, pos_y;
184 Dimension width, height;
185
186 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
187 if (tab_scroll_w != (Widget)0) {
188 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
189 &width, XmNheight, &height, NULL);
190 if (pos_x >= 0) {
191 /* Tab scroller (next) is visible */
192 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
193 (event->y >= pos_y) && (event->y <= pos_y + height)) {
194 /* Clicked on the scroller */
195 return TRUE;
196 }
197 }
198 }
199 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000200}
201
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000202 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100203tabline_menu_cb(
204 Widget w,
205 XtPointer closure UNUSED,
206 XEvent *e,
207 Boolean *continue_dispatch UNUSED)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000208{
209 Widget tab_w;
210 XButtonPressedEvent *event;
211 int tab_idx = 0;
212 WidgetList children;
213 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000214 static XtIntervalId timer = (XtIntervalId)0;
215 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000216
217 event = (XButtonPressedEvent *)e;
218
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000219 if (event->button == Button1)
220 {
221 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
222 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
223 return;
224
225 if (!timed_out)
226 {
227 XtRemoveTimeOut(timer);
228 timed_out = TRUE;
229
230 /*
231 * Double click on the tabline gutter, add a new tab
232 */
233 send_tabline_menu_event(0, TABLINE_MENU_NEW);
234 }
235 else
236 {
237 /*
238 * Single click on the tabline gutter, start a timer to check
239 * for double clicks
240 */
241 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
242 motif_tabline_timer_cb, &timed_out);
243 timed_out = FALSE;
244 }
245 return;
246 }
247
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000248 if (event->button != Button3)
249 return;
250
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000251 /* When ignoring events don't show the menu. */
252 if (hold_gui_events
253# ifdef FEAT_CMDWIN
254 || cmdwin_type != 0
255# endif
256 )
257 return;
258
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000259 if (event->subwindow != None)
260 {
261 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000262 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000263 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
264 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
265 }
266
267 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
268 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
269 &numChildren, NULL);
270 XtManageChildren(children, numChildren);
271 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
272 XtManageChild(tabLine_menu);
273}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000274
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000275 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100276tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000277{
278 int nr;
279 tabpage_T *tp;
280
281 if (beval->target == (Widget)0)
282 return;
283
284 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
285 tp = find_tabpage(nr);
286 if (tp == NULL)
287 return;
288
289 get_tabline_label(tp, TRUE);
290 gui_mch_post_balloon(beval, NameBuff);
291}
292
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000293#endif
294
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295/*
296 * End of call-back routines
297 */
298
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000299/*
300 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000301 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000302 */
303
304#include <Xm/XmP.h>
305#include <Xm/LabelP.h>
306
307static XtExposeProc old_label_expose = NULL;
308
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100309static void label_expose(Widget _w, XEvent *_event, Region _region);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000310
311 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100312label_expose(Widget _w, XEvent *_event, Region _region)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000313{
314 GC insensitiveGC;
315 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000316 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000317
318 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
319
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000320 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000321 (*old_label_expose)(_w, _event, _region);
322 else
323 {
324 XGCValues values;
325 XtGCMask mask;
326 XtGCMask dynamic;
327 XFontStruct *fs;
328
329 _XmFontListGetDefaultFont(lw->label.font, &fs);
330
331 /* FIXME: we should be doing the whole drawing ourself here. */
332 insensitiveGC = lw->label.insensitive_GC;
333
334 mask = GCForeground | GCBackground | GCGraphicsExposures;
335 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
336 values.graphics_exposures = False;
337
338 if (fs != 0)
339 {
340 mask |= GCFont;
341 values.font = fs->fid;
342 }
343
344 if (lw->primitive.top_shadow_pixmap != None
345 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
346 {
347 mask |= GCFillStyle | GCTile;
348 values.fill_style = FillTiled;
349 values.tile = lw->primitive.top_shadow_pixmap;
350 }
351
352 lw->label.TextRect.x += 1;
353 lw->label.TextRect.y += 1;
354 if (lw->label._acc_text != 0)
355 {
356 lw->label.acc_TextRect.x += 1;
357 lw->label.acc_TextRect.y += 1;
358 }
359
360 values.foreground = lw->primitive.top_shadow_color;
361 values.background = lw->core.background_pixel;
362
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000363 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
364 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000365 (*old_label_expose)(_w, _event, _region);
366 XtReleaseGC(_w, lw->label.insensitive_GC);
367
368 lw->label.TextRect.x -= 1;
369 lw->label.TextRect.y -= 1;
370 if (lw->label._acc_text != 0)
371 {
372 lw->label.acc_TextRect.x -= 1;
373 lw->label.acc_TextRect.y -= 1;
374 }
375
376 values.foreground = lw->primitive.bottom_shadow_color;
377 values.background = lw->core.background_pixel;
378
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000379 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
380 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000381 (*old_label_expose)(_w, _event, _region);
382 XtReleaseGC(_w, lw->label.insensitive_GC);
383
384 lw->label.insensitive_GC = insensitiveGC;
385 }
386}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000387
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388/*
389 * Create all the motif widgets necessary.
390 */
391 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100392gui_x11_create_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000394#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000395 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000396 Arg args[10];
397 int n;
398 XmString xms;
399#endif
400
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000401 /*
402 * Install the 3D shade effect drawing routines.
403 */
404 if (old_label_expose == NULL)
405 {
406 old_label_expose = xmLabelWidgetClass->core_class.expose;
407 xmLabelWidgetClass->core_class.expose = label_expose;
408 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000409
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410 /*
411 * Start out by adding the configured border width into the border offset
412 */
413 gui.border_offset = gui.border_width;
414
415 /*
416 * Install the tearOffModel resource converter.
417 */
418#if (XmVersion >= 1002)
419 XmRepTypeInstallTearOffModelConverter();
420#endif
421
422 /* Make sure the "Quit" menu entry of the window manager is ignored */
423 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
424
425 vimForm = XtVaCreateManagedWidget("vimForm",
426 xmFormWidgetClass, vimShell,
427 XmNborderWidth, 0,
428 XmNhighlightThickness, 0,
429 XmNshadowThickness, 0,
430 XmNmarginWidth, 0,
431 XmNmarginHeight, 0,
432 XmNresizePolicy, XmRESIZE_ANY,
433 NULL);
434 gui_motif_menu_colors(vimForm);
435
436#ifdef FEAT_MENU
437 {
438 Arg al[7]; /* Make sure there is enough room for arguments! */
439 int ac = 0;
440
441# if (XmVersion >= 1002)
442 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
443# endif
444 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
445 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
446 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
447# ifndef FEAT_TOOLBAR
448 /* Always stick to right hand side. */
449 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
450# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000451 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
453 XtManageChild(menuBar);
454
455 /* Remember the default colors, needed for ":hi clear". */
456 XtVaGetValues(menuBar,
457 XmNbackground, &gui.menu_def_bg_pixel,
458 XmNforeground, &gui.menu_def_fg_pixel,
459 NULL);
460 gui_motif_menu_colors(menuBar);
461 }
462#endif
463
464#ifdef FEAT_TOOLBAR
465 /*
466 * Create an empty ToolBar. We should get buttons defined from menu.vim.
467 */
468 toolBarFrame = XtVaCreateWidget("toolBarFrame",
469 xmFrameWidgetClass, vimForm,
470 XmNshadowThickness, 0,
471 XmNmarginHeight, 0,
472 XmNmarginWidth, 0,
473 XmNleftAttachment, XmATTACH_FORM,
474 XmNrightAttachment, XmATTACH_FORM,
475 NULL);
476 gui_motif_menu_colors(toolBarFrame);
477
478 toolBar = XtVaCreateManagedWidget("toolBar",
479 xmRowColumnWidgetClass, toolBarFrame,
480 XmNchildType, XmFRAME_WORKAREA_CHILD,
481 XmNrowColumnType, XmWORK_AREA,
482 XmNorientation, XmHORIZONTAL,
483 XmNtraversalOn, False,
484 XmNisHomogeneous, False,
485 XmNpacking, XmPACK_TIGHT,
486 XmNspacing, 0,
487 XmNshadowThickness, 0,
488 XmNhighlightThickness, 0,
489 XmNmarginHeight, 0,
490 XmNmarginWidth, 0,
491 XmNadjustLast, True,
492 NULL);
493 gui_motif_menu_colors(toolBar);
494
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495#endif
496
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000497#ifdef FEAT_GUI_TABLINE
498 /* Create the Vim GUI tabline */
499 n = 0;
500 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
501 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
502 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
503 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
504 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
505 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
506 XtSetArg(args[n], XmNshadowThickness, 0); n++;
507 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
508 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
509 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
510
511 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
512 NULL);
513 XtAddEventHandler(tabLine, ButtonPressMask, False,
514 (XtEventHandler)tabline_menu_cb, NULL);
515
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000516 gui.tabline_height = TABLINE_HEIGHT;
517
Bram Moolenaar18144c82006-04-12 21:52:12 +0000518 /*
519 * Set the size of the minor next/prev scrollers to zero, so
520 * that they are not displayed. Due to a bug in OpenMotif 2.3,
521 * even if these children widget are unmanaged, they are again
522 * managed by the Notebook widget and the notebook widget geometry
523 * is adjusted to account for the minor scroller widgets.
524 */
525 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
526 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
527 XmNtraversalOn, False, NULL);
528 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
529 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
530 XmNtraversalOn, False, NULL);
531
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000532 /* Create the tabline popup menu */
533 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
534
535 /* Add the buttons to the menu */
Bram Moolenaar7098ee52015-06-09 19:14:24 +0200536 if (first_tabpage->tp_next != NULL)
537 {
538 n = 0;
539 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
540 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
541 XtSetArg(args[n], XmNlabelString, xms); n++;
542 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
543 XtAddCallback(button, XmNactivateCallback,
544 (XtCallbackProc)tabline_button_cb, NULL);
545 XmStringFree(xms);
546 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000547
548 n = 0;
549 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
550 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
551 XtSetArg(args[n], XmNlabelString, xms); n++;
552 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
553 XtAddCallback(button, XmNactivateCallback,
554 (XtCallbackProc)tabline_button_cb, NULL);
555 XmStringFree(xms);
556
557 n = 0;
558 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
559 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
560 XtSetArg(args[n], XmNlabelString, xms); n++;
561 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
562 XtAddCallback(button, XmNactivateCallback,
563 (XtCallbackProc)tabline_button_cb, NULL);
564 XmStringFree(xms);
565#endif
566
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
568 xmFormWidgetClass, vimForm,
569 XmNleftAttachment, XmATTACH_FORM,
570 XmNrightAttachment, XmATTACH_FORM,
571 XmNbottomAttachment, XmATTACH_FORM,
572 XmNtopAttachment, XmATTACH_FORM,
573 XmNmarginWidth, 0,
574 XmNmarginHeight, 0,
575 XmNresizePolicy, XmRESIZE_ANY,
576 NULL);
577 gui_motif_scroll_colors(textAreaForm);
578
579 textArea = XtVaCreateManagedWidget("textArea",
580 xmDrawingAreaWidgetClass, textAreaForm,
581 XmNforeground, gui.norm_pixel,
582 XmNbackground, gui.back_pixel,
583 XmNleftAttachment, XmATTACH_FORM,
584 XmNtopAttachment, XmATTACH_FORM,
585 XmNrightAttachment, XmATTACH_FORM,
586 XmNbottomAttachment, XmATTACH_FORM,
587
588 /*
589 * These take some control away from the user, but avoids making them
590 * add resources to get a decent looking setup.
591 */
592 XmNborderWidth, 0,
593 XmNhighlightThickness, 0,
594 XmNshadowThickness, 0,
595 NULL);
596
597#ifdef FEAT_FOOTER
598 /*
599 * Create the Footer.
600 */
601 footer = XtVaCreateWidget("footer",
602 xmLabelGadgetClass, vimForm,
603 XmNalignment, XmALIGNMENT_BEGINNING,
604 XmNmarginHeight, 0,
605 XmNmarginWidth, 0,
606 XmNtraversalOn, False,
607 XmNrecomputeSize, False,
608 XmNleftAttachment, XmATTACH_FORM,
609 XmNleftOffset, 5,
610 XmNrightAttachment, XmATTACH_FORM,
611 XmNbottomAttachment, XmATTACH_FORM,
612 NULL);
613 gui_mch_set_footer((char_u *) "");
614#endif
615
616 /*
617 * Install the callbacks.
618 */
619 gui_x11_callbacks(textArea, vimForm);
620
621 /* Pretend we don't have input focus, we will get an event if we do. */
622 gui.in_focus = FALSE;
623}
624
625/*
626 * Called when the GUI is not going to start after all.
627 */
628 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100629gui_x11_destroy_widgets(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630{
631 textArea = NULL;
632#ifdef FEAT_MENU
633 menuBar = NULL;
634#endif
635}
636
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100638gui_mch_set_text_area_pos(
639 int x UNUSED,
640 int y UNUSED,
641 int w UNUSED,
642 int h UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643{
644#ifdef FEAT_TOOLBAR
645 /* Give keyboard focus to the textArea instead of the toolbar. */
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000646 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647#endif
648}
649
650 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100651gui_x11_set_back_color(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652{
653 if (textArea != NULL)
654#if (XmVersion >= 1002)
655 XmChangeColor(textArea, gui.back_pixel);
656#else
657 XtVaSetValues(textArea,
658 XmNbackground, gui.back_pixel,
659 NULL);
660#endif
661}
662
663/*
664 * Manage dialog centered on pointer. This could be used by the Athena code as
665 * well.
666 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000667 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100668manage_centered(Widget dialog_child)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669{
670 Widget shell = XtParent(dialog_child);
671 Window root, child;
672 unsigned int mask;
673 unsigned int width, height, border_width, depth;
674 int x, y, win_x, win_y, maxX, maxY;
675 Boolean mappedWhenManaged;
676
677 /* Temporarily set value of XmNmappedWhenManaged
678 to stop the dialog from popping up right away */
Bram Moolenaar46784652008-06-20 09:40:11 +0000679 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
680 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681
682 XtManageChild(dialog_child);
683
684 /* Get the pointer position (x, y) */
685 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
686 &x, &y, &win_x, &win_y, &mask);
687
688 /* Translate the pointer position (x, y) into a position for the new
689 window that will place the pointer at its center */
690 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
691 &width, &height, &border_width, &depth);
692 width += 2 * border_width;
693 height += 2 * border_width;
694 x -= width / 2;
695 y -= height / 2;
696
697 /* Ensure that the dialog remains on screen */
698 maxX = XtScreen(shell)->width - width;
699 maxY = XtScreen(shell)->height - height;
700 if (x < 0)
701 x = 0;
702 if (x > maxX)
703 x = maxX;
704 if (y < 0)
705 y = 0;
706 if (y > maxY)
707 y = maxY;
708
709 /* Set desired window position in the DialogShell */
710 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
711
712 /* Map the widget */
713 XtMapWidget(shell);
714
715 /* Restore the value of XmNmappedWhenManaged */
Bram Moolenaar46784652008-06-20 09:40:11 +0000716 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717}
718
719#if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
720 || defined(FEAT_GUI_DIALOG) || defined(PROTO)
721
722/*
723 * Encapsulate the way an XmFontList is created.
724 */
725 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100726gui_motif_create_fontlist(XFontStruct *font)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727{
728 XmFontList font_list;
729
730# if (XmVersion <= 1001)
731 /* Motif 1.1 method */
732 font_list = XmFontListCreate(font, STRING_TAG);
733# else
734 /* Motif 1.2 method */
735 XmFontListEntry font_list_entry;
736
737 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
738 (XtPointer)font);
739 font_list = XmFontListAppendEntry(NULL, font_list_entry);
740 XmFontListEntryFree(&font_list_entry);
741# endif
742 return font_list;
743}
744
745# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
746 XmFontList
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100747gui_motif_fontset2fontlist(XFontSet *fontset)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748{
749 XmFontList font_list;
750
751 /* Motif 1.2 method */
752 XmFontListEntry font_list_entry;
753
754 font_list_entry = XmFontListEntryCreate(STRING_TAG,
755 XmFONT_IS_FONTSET,
756 (XtPointer)*fontset);
757 font_list = XmFontListAppendEntry(NULL, font_list_entry);
758 XmFontListEntryFree(&font_list_entry);
759 return font_list;
760}
761# endif
762
763#endif
764
765#if defined(FEAT_MENU) || defined(PROTO)
766/*
767 * Menu stuff.
768 */
769
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100770static void gui_motif_add_actext(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#if (XmVersion >= 1002)
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100772static void toggle_tearoff(Widget wid);
773static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#endif
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100775static void submenu_change(vimmenu_T *mp, int colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
Bram Moolenaard25c16e2016-01-29 22:13:30 +0100777static void do_set_mnemonics(int enable);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778static int menu_enabled = TRUE;
779
780 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100781gui_mch_enable_menu(int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782{
783 if (flag)
784 {
785 XtManageChild(menuBar);
786#ifdef FEAT_TOOLBAR
787 if (XtIsManaged(XtParent(toolBar)))
788 {
789 /* toolBar is attached to top form */
790 XtVaSetValues(XtParent(toolBar),
791 XmNtopAttachment, XmATTACH_WIDGET,
792 XmNtopWidget, menuBar,
793 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000794#ifdef FEAT_GUI_TABLINE
795 if (showing_tabline)
796 {
797 XtVaSetValues(tabLine,
798 XmNtopAttachment, XmATTACH_WIDGET,
799 XmNtopWidget, XtParent(toolBar),
800 NULL);
801 XtVaSetValues(textAreaForm,
802 XmNtopAttachment, XmATTACH_WIDGET,
803 XmNtopWidget, tabLine,
804 NULL);
805 }
806 else
807#endif
808 XtVaSetValues(textAreaForm,
809 XmNtopAttachment, XmATTACH_WIDGET,
810 XmNtopWidget, XtParent(toolBar),
811 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 }
813 else
814#endif
815 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000816#ifdef FEAT_GUI_TABLINE
817 if (showing_tabline)
818 {
819 XtVaSetValues(tabLine,
820 XmNtopAttachment, XmATTACH_WIDGET,
821 XmNtopWidget, menuBar,
822 NULL);
823 XtVaSetValues(textAreaForm,
824 XmNtopAttachment, XmATTACH_WIDGET,
825 XmNtopWidget, tabLine,
826 NULL);
827 }
828 else
829#endif
830 XtVaSetValues(textAreaForm,
831 XmNtopAttachment, XmATTACH_WIDGET,
832 XmNtopWidget, menuBar,
833 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834 }
835 }
836 else
837 {
838 XtUnmanageChild(menuBar);
839#ifdef FEAT_TOOLBAR
840 if (XtIsManaged(XtParent(toolBar)))
841 {
842 XtVaSetValues(XtParent(toolBar),
843 XmNtopAttachment, XmATTACH_FORM,
844 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000845#ifdef FEAT_GUI_TABLINE
846 if (showing_tabline)
847 {
848 XtVaSetValues(tabLine,
849 XmNtopAttachment, XmATTACH_WIDGET,
850 XmNtopWidget, XtParent(toolBar),
851 NULL);
852 XtVaSetValues(textAreaForm,
853 XmNtopAttachment, XmATTACH_WIDGET,
854 XmNtopWidget, tabLine,
855 NULL);
856 }
857 else
858#endif
859 XtVaSetValues(textAreaForm,
860 XmNtopAttachment, XmATTACH_WIDGET,
861 XmNtopWidget, XtParent(toolBar),
862 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 }
864 else
865#endif
866 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000867#ifdef FEAT_GUI_TABLINE
868 if (showing_tabline)
869 {
870 XtVaSetValues(tabLine,
871 XmNtopAttachment, XmATTACH_FORM,
872 NULL);
873 XtVaSetValues(textAreaForm,
874 XmNtopAttachment, XmATTACH_WIDGET,
875 XmNtopWidget, tabLine,
876 NULL);
877 }
878 else
879#endif
880 XtVaSetValues(textAreaForm,
881 XmNtopAttachment, XmATTACH_FORM,
882 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 }
884 }
885
886}
887
888/*
889 * Enable or disable mnemonics for the toplevel menus.
890 */
891 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100892gui_motif_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893{
894 /*
895 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
896 * crashes when using a mnemonic then.
897 */
898 if (!menu_enabled)
899 enable = FALSE;
900 do_set_mnemonics(enable);
901}
902
903 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100904do_set_mnemonics(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905{
906 vimmenu_T *menu;
907
908 for (menu = root_menu; menu != NULL; menu = menu->next)
909 if (menu->id != (Widget)0)
910 XtVaSetValues(menu->id,
911 XmNmnemonic, enable ? menu->mnemonic : NUL,
912 NULL);
913}
914
915 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +0100916gui_mch_add_menu(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917{
918 XmString label;
919 Widget shell;
920 vimmenu_T *parent = menu->parent;
921
922#ifdef MOTIF_POPUP
923 if (menu_is_popup(menu->name))
924 {
925 Arg arg[2];
926 int n = 0;
927
928 /* Only create the popup menu when it's actually used, otherwise there
929 * is a delay when using the right mouse button. */
930# if (XmVersion <= 1002)
931 if (mouse_model_popup())
932# endif
933 {
934 if (gui.menu_bg_pixel != INVALCOLOR)
935 {
936 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
937 }
938 if (gui.menu_fg_pixel != INVALCOLOR)
939 {
940 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
941 }
942 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
943 arg, n);
944 menu->id = (Widget)0;
945 }
946 return;
947 }
948#endif
949
950 if (!menu_is_menubar(menu->name)
951 || (parent != NULL && parent->submenu_id == (Widget)0))
952 return;
953
954 label = XmStringCreate((char *)menu->dname, STRING_TAG);
955 if (label == NULL)
956 return;
957 menu->id = XtVaCreateWidget("subMenu",
958 xmCascadeButtonWidgetClass,
959 (parent == NULL) ? menuBar : parent->submenu_id,
960 XmNlabelString, label,
961 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
962#if (XmVersion >= 1002)
963 /* submenu: count the tearoff item (needed for LessTif) */
964 XmNpositionIndex, idx + (parent != NULL
965 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
966#endif
967 NULL);
968 gui_motif_menu_colors(menu->id);
969 gui_motif_menu_fontlist(menu->id);
970 XmStringFree(label);
971
972 if (menu->id == (Widget)0) /* failed */
973 return;
974
975 /* add accelerator text */
976 gui_motif_add_actext(menu);
977
978 shell = XtVaCreateWidget("subMenuShell",
979 xmMenuShellWidgetClass, menu->id,
980 XmNwidth, 1,
981 XmNheight, 1,
982 NULL);
983 gui_motif_menu_colors(shell);
984 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
985 xmRowColumnWidgetClass, shell,
986 XmNrowColumnType, XmMENU_PULLDOWN,
987 NULL);
988 gui_motif_menu_colors(menu->submenu_id);
989
990 if (menu->submenu_id == (Widget)0) /* failed */
991 return;
992
993#if (XmVersion >= 1002)
994 /* Set the colors for the tear off widget */
995 toggle_tearoff(menu->submenu_id);
996#endif
997
998 XtVaSetValues(menu->id,
999 XmNsubMenuId, menu->submenu_id,
1000 NULL);
1001
1002 /*
1003 * The "Help" menu is a special case, and should be placed at the far
1004 * right hand side of the menu-bar. It's recognized by its high priority.
1005 */
1006 if (parent == NULL && menu->priority >= 9999)
1007 XtVaSetValues(menuBar,
1008 XmNmenuHelpWidget, menu->id,
1009 NULL);
1010
1011 /*
1012 * When we add a top-level item to the menu bar, we can figure out how
1013 * high the menu bar should be.
1014 */
1015 if (parent == NULL)
1016 gui_mch_compute_menu_height(menu->id);
1017}
1018
1019
1020/*
1021 * Add mnemonic and accelerator text to a menu button.
1022 */
1023 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001024gui_motif_add_actext(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025{
1026 XmString label;
1027
Bram Moolenaar933eb392007-05-10 17:52:45 +00001028 /* Add accelerator text, if there is one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 if (menu->actext != NULL && menu->id != (Widget)0)
1030 {
1031 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1032 if (label == NULL)
1033 return;
1034 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1035 XmStringFree(label);
1036 }
1037}
1038
1039 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001040gui_mch_toggle_tearoffs(int enable)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041{
1042#if (XmVersion >= 1002)
1043 if (enable)
1044 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1045 else
1046 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1047 toggle_tearoff(menuBar);
1048 gui_mch_recurse_tearoffs(root_menu);
1049#endif
1050}
1051
1052#if (XmVersion >= 1002)
1053/*
1054 * Set the tearoff for one menu widget on or off, and set the color of the
1055 * tearoff widget.
1056 */
1057 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001058toggle_tearoff(Widget wid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059{
1060 Widget w;
1061
1062 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1063 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1064 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1065 gui_motif_menu_colors(w);
1066}
1067
1068 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001069gui_mch_recurse_tearoffs(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070{
1071 while (menu != NULL)
1072 {
1073 if (!menu_is_popup(menu->name))
1074 {
1075 if (menu->submenu_id != (Widget)0)
1076 toggle_tearoff(menu->submenu_id);
1077 gui_mch_recurse_tearoffs(menu->children);
1078 }
1079 menu = menu->next;
1080 }
1081}
1082#endif
1083
1084 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001085gui_mch_text_area_extra_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086{
1087 Dimension shadowHeight;
1088
1089 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1090 return shadowHeight;
1091}
1092
1093/*
1094 * Compute the height of the menu bar.
1095 * We need to check all the items for their position and height, for the case
1096 * there are several rows, and/or some characters extend higher or lower.
1097 */
1098 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001099gui_mch_compute_menu_height(
1100 Widget id) /* can be NULL when deleting menu */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101{
1102 Dimension y, maxy;
1103 Dimension margin, shadow;
1104 vimmenu_T *mp;
1105 static Dimension height = 21; /* normal height of a menu item */
1106
1107 /*
1108 * Get the height of the new item, before managing it, because it will
1109 * still reflect the font size. After managing it depends on the menu
1110 * height, which is what we just wanted to get!.
1111 */
1112 if (id != (Widget)0)
1113 XtVaGetValues(id, XmNheight, &height, NULL);
1114
1115 /* Find any menu Widget, to be able to call XtManageChild() */
1116 else
1117 for (mp = root_menu; mp != NULL; mp = mp->next)
1118 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1119 {
1120 id = mp->id;
1121 break;
1122 }
1123
1124 /*
1125 * Now manage the menu item, to make them all be positioned (makes an
1126 * extra row when needed, removes it when not needed).
1127 */
1128 if (id != (Widget)0)
1129 XtManageChild(id);
1130
1131 /*
1132 * Now find the menu item that is the furthest down, and get it's position.
1133 */
1134 maxy = 0;
1135 for (mp = root_menu; mp != NULL; mp = mp->next)
1136 {
1137 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1138 {
1139 XtVaGetValues(mp->id, XmNy, &y, NULL);
1140 if (y > maxy)
1141 maxy = y;
1142 }
1143 }
1144
1145 XtVaGetValues(menuBar,
1146 XmNmarginHeight, &margin,
1147 XmNshadowThickness, &shadow,
1148 NULL);
1149
1150 /*
1151 * This computation is the result of trial-and-error:
1152 * maxy = The maximum position of an item; required for when there are
1153 * two or more rows
1154 * height = height of an item, before managing it; Hopefully this will
1155 * change with the font height. Includes shadow-border.
1156 * shadow = shadow-border; must be subtracted from the height.
1157 * margin = margin around the menu buttons; Must be added.
1158 * Add 4 for the underlining of shortcut keys.
1159 */
1160 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1161
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 /* Somehow the menu bar doesn't resize automatically. Set it here,
1163 * even though this is a catch 22. Don't do this when starting up,
1164 * somehow the menu gets very high then. */
1165 if (gui.shell_created)
1166 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001167}
1168
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001169#ifdef FEAT_TOOLBAR
1170
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001171/*
1172 * Icons used by the toolbar code.
1173 */
1174#include "gui_x11_pm.h"
1175
Bram Moolenaard25c16e2016-01-29 22:13:30 +01001176static int check_xpm(char_u *path);
1177static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
1178static int add_pixmap_args(vimmenu_T *menu, Arg *args, int n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001179
1180/*
1181 * Read an Xpm file. Return OK or FAIL.
1182 */
1183 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001184check_xpm(char_u *path)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001185{
1186 XpmAttributes attrs;
1187 int status;
1188 Pixmap mask;
1189 Pixmap map;
1190
1191 attrs.valuemask = 0;
1192
1193 /* Create the "sensitive" pixmap */
1194 status = XpmReadFileToPixmap(gui.dpy,
1195 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1196 (char *)path, &map, &mask, &attrs);
1197 XpmFreeAttributes(&attrs);
1198
1199 if (status == XpmSuccess)
1200 return OK;
1201 return FAIL;
1202}
1203
1204
1205/*
1206 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001207 * When it's to be read from a file, "fname" is set to the file name
1208 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001209 * Return a blank pixmap if it fails.
1210 */
1211 static char **
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001212get_toolbar_pixmap(vimmenu_T *menu, char **fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001213{
1214 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1215 char **xpm = NULL; /* xpm array */
1216 int res;
1217
Bram Moolenaar7c626922005-02-07 22:01:03 +00001218 *fname = NULL;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001219 buf[0] = NUL; /* start with NULL path */
1220
1221 if (menu->iconfile != NULL)
1222 {
1223 /* Use the "icon=" argument. */
1224 gui_find_iconfile(menu->iconfile, buf, "xpm");
1225 res = check_xpm(buf);
1226
1227 /* If it failed, try using the menu name. */
1228 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1229 res = check_xpm(buf);
1230 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001231 {
1232 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001233 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001234 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001235 }
1236
1237 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1238 {
1239 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001240 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001241 xpm = built_in_pixmaps[menu->iconidx];
1242 else
1243 xpm = tb_blank_xpm;
1244 }
1245
1246 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001248
1249/*
1250 * Add arguments for the toolbar pixmap to a menu item.
1251 */
1252 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001253add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001254{
1255 vim_free(menu->xpm_fname);
1256 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1257 if (menu->xpm == NULL)
1258 {
1259 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1260 }
1261 else
1262 {
1263 if (menu->xpm_fname != NULL)
1264 {
1265 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
1266 }
1267 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1268 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1269 }
1270 return n;
1271}
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001272#endif /* FEAT_TOOLBAR */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273
1274 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001275gui_mch_add_menu_item(vimmenu_T *menu, int idx)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276{
1277 XmString label;
1278 vimmenu_T *parent = menu->parent;
1279
1280# ifdef EBCDIC
1281 menu->mnemonic = 0;
1282# endif
1283
1284# if (XmVersion <= 1002)
1285 /* Don't add Popup menu items when the popup menu isn't used. */
1286 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1287 return;
1288# endif
1289
1290# ifdef FEAT_TOOLBAR
1291 if (menu_is_toolbar(parent->name))
1292 {
1293 WidgetClass type;
1294 XmString xms = NULL; /* fallback label if pixmap not found */
1295 int n;
1296 Arg args[18];
1297
1298 n = 0;
1299 if (menu_is_separator(menu->name))
1300 {
1301 char *cp;
1302 Dimension wid;
1303
1304 /*
1305 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1306 * a width specifier. If no width is specified then we choose one.
1307 */
1308 cp = (char *)vim_strchr(menu->name, ':');
1309 if (cp != NULL)
1310 wid = (Dimension)atoi(++cp);
1311 else
1312 wid = 4;
1313
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 type = xmSeparatorWidgetClass;
1315 XtSetArg(args[n], XmNwidth, wid); n++;
1316 XtSetArg(args[n], XmNminWidth, wid); n++;
1317 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001318 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 }
1320 else
1321 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 /* Without shadows one can't sense whatever the button has been
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001323 * pressed or not! However we want to save a bit of space...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001324 * Need the highlightThickness to see the focus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001326 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1328 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1329 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001330 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001331 /* Set the label here, so that we can switch between icons/text
1332 * by changing the XmNlabelType resource. */
1333 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1334 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001335
Bram Moolenaar7c626922005-02-07 22:01:03 +00001336 n = add_pixmap_args(menu, args, n);
1337
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001338 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339 }
1340
1341 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1342 if (menu->id == NULL)
1343 {
1344 menu->id = XtCreateManagedWidget((char *)menu->dname,
1345 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001346 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {
1348 XtAddCallback(menu->id,
1349 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350# ifdef FEAT_FOOTER
1351 XtAddEventHandler(menu->id, EnterWindowMask, False,
1352 toolbarbutton_enter_cb, menu);
1353 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1354 toolbarbutton_leave_cb, menu);
1355# endif
1356 }
1357 }
1358 else
1359 XtSetValues(menu->id, args, n);
1360 if (xms != NULL)
1361 XmStringFree(xms);
1362
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001363# ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001365# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366
1367 menu->parent = parent;
1368 menu->submenu_id = NULL;
1369 /* When adding first item to toolbar it might have to be enabled .*/
1370 if (!XtIsManaged(XtParent(toolBar))
1371 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1372 gui_mch_show_toolbar(TRUE);
1373 gui.toolbar_height = gui_mch_compute_toolbar_height();
1374 return;
1375 } /* toolbar menu item */
1376# endif
1377
1378 /* No parent, must be a non-menubar menu */
1379 if (parent->submenu_id == (Widget)0)
1380 return;
1381
1382 menu->submenu_id = (Widget)0;
1383
1384 /* Add menu separator */
1385 if (menu_is_separator(menu->name))
1386 {
1387 menu->id = XtVaCreateWidget("subMenu",
1388 xmSeparatorGadgetClass, parent->submenu_id,
1389#if (XmVersion >= 1002)
1390 /* count the tearoff item (needed for LessTif) */
1391 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1392 ? 1 : 0),
1393#endif
1394 NULL);
1395 gui_motif_menu_colors(menu->id);
1396 return;
1397 }
1398
1399 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1400 if (label == NULL)
1401 return;
1402 menu->id = XtVaCreateWidget("subMenu",
1403 xmPushButtonWidgetClass, parent->submenu_id,
1404 XmNlabelString, label,
1405 XmNmnemonic, menu->mnemonic,
1406#if (XmVersion >= 1002)
1407 /* count the tearoff item (needed for LessTif) */
1408 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1409 ? 1 : 0),
1410#endif
1411 NULL);
1412 gui_motif_menu_colors(menu->id);
1413 gui_motif_menu_fontlist(menu->id);
1414 XmStringFree(label);
1415
1416 if (menu->id != (Widget)0)
1417 {
1418 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1419 (XtPointer)menu);
1420 /* add accelerator text */
1421 gui_motif_add_actext(menu);
1422 }
1423}
1424
1425#if (XmVersion <= 1002) || defined(PROTO)
1426/*
1427 * This function will destroy/create the popup menus dynamically,
1428 * according to the value of 'mousemodel'.
1429 * This will fix the "right mouse button freeze" that occurs when
1430 * there exists a popup menu but it isn't managed.
1431 */
1432 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001433gui_motif_update_mousemodel(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434{
1435 int idx = 0;
1436
1437 /* When GUI hasn't started the menus have not been created. */
1438 if (!gui.in_use)
1439 return;
1440
1441 while (menu)
1442 {
1443 if (menu->children != NULL)
1444 {
1445 if (menu_is_popup(menu->name))
1446 {
1447 if (mouse_model_popup())
1448 {
1449 /* Popup menu will be used. Create the popup menus. */
1450 gui_mch_add_menu(menu, idx);
1451 gui_motif_update_mousemodel(menu->children);
1452 }
1453 else
1454 {
1455 /* Popup menu will not be used. Destroy the popup menus. */
1456 gui_motif_update_mousemodel(menu->children);
1457 gui_mch_destroy_menu(menu);
1458 }
1459 }
1460 }
1461 else if (menu_is_child_of_popup(menu))
1462 {
1463 if (mouse_model_popup())
1464 gui_mch_add_menu_item(menu, idx);
1465 else
1466 gui_mch_destroy_menu(menu);
1467 }
1468 menu = menu->next;
1469 ++idx;
1470 }
1471}
1472#endif
1473
1474 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001475gui_mch_new_menu_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476{
1477 if (menuBar == (Widget)0)
1478 return;
1479 gui_motif_menu_colors(menuBar);
1480#ifdef FEAT_TOOLBAR
1481 gui_motif_menu_colors(toolBarFrame);
1482 gui_motif_menu_colors(toolBar);
1483#endif
1484
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001485 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486}
1487
1488 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001489gui_mch_new_menu_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490{
1491 if (menuBar == (Widget)0)
1492 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001493 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 {
1495 Dimension height;
1496 Position w, h;
1497
1498 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1499 gui.menu_height = height;
1500
1501 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1502 gui_resize_shell(w, h
1503#ifdef FEAT_XIM
1504 - xim_get_status_area_height()
1505#endif
1506 );
1507 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001508 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 ui_new_shellsize();
1510}
1511
1512#if defined(FEAT_BEVAL) || defined(PROTO)
1513 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001514gui_mch_new_tooltip_font(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515{
1516# ifdef FEAT_TOOLBAR
1517 vimmenu_T *menu;
1518
1519 if (toolBar == (Widget)0)
1520 return;
1521
1522 menu = gui_find_menu((char_u *)"ToolBar");
1523 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001524 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525# endif
1526}
1527
1528 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001529gui_mch_new_tooltip_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530{
1531# ifdef FEAT_TOOLBAR
1532 vimmenu_T *toolbar;
1533
1534 if (toolBar == (Widget)0)
1535 return;
1536
1537 toolbar = gui_find_menu((char_u *)"ToolBar");
1538 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001539 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540# endif
1541}
1542#endif
1543
1544 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001545submenu_change(
1546 vimmenu_T *menu,
1547 int colors) /* TRUE for colors, FALSE for font */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548{
1549 vimmenu_T *mp;
1550
1551 for (mp = menu; mp != NULL; mp = mp->next)
1552 {
1553 if (mp->id != (Widget)0)
1554 {
1555 if (colors)
1556 {
1557 gui_motif_menu_colors(mp->id);
1558#ifdef FEAT_TOOLBAR
1559 /* For a toolbar item: Free the pixmap and allocate a new one,
1560 * so that the background color is right. */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001561 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001563 int n = 0;
1564 Arg args[18];
1565
Bram Moolenaar7c626922005-02-07 22:01:03 +00001566 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001567 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 }
1569# ifdef FEAT_BEVAL
1570 /* If we have a tooltip, then we need to change it's font */
1571 if (mp->tip != NULL)
1572 {
1573 Arg args[2];
1574
1575 args[0].name = XmNbackground;
1576 args[0].value = gui.tooltip_bg_pixel;
1577 args[1].name = XmNforeground;
1578 args[1].value = gui.tooltip_fg_pixel;
1579 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1580 }
1581# endif
1582#endif
1583 }
1584 else
1585 {
1586 gui_motif_menu_fontlist(mp->id);
1587#ifdef FEAT_BEVAL
1588 /* If we have a tooltip, then we need to change it's font */
1589 if (mp->tip != NULL)
1590 {
1591 Arg args[1];
1592
1593 args[0].name = XmNfontList;
1594 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1595 &gui.tooltip_fontset);
1596 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1597 }
1598#endif
1599 }
1600 }
1601
1602 if (mp->children != NULL)
1603 {
1604#if (XmVersion >= 1002)
1605 /* Set the colors/font for the tear off widget */
1606 if (mp->submenu_id != (Widget)0)
1607 {
1608 if (colors)
1609 gui_motif_menu_colors(mp->submenu_id);
1610 else
1611 gui_motif_menu_fontlist(mp->submenu_id);
1612 toggle_tearoff(mp->submenu_id);
1613 }
1614#endif
1615 /* Set the colors for the children */
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001616 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 }
1618 }
1619}
1620
1621/*
1622 * Destroy the machine specific menu widget.
1623 */
1624 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001625gui_mch_destroy_menu(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626{
1627 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1628 * On the other hand, problems have been reported that the submenu must be
1629 * deleted first...
1630 *
1631 * This code should be basically identical to that in the file gui_athena.c
1632 * because they are both Xt based.
1633 */
1634 if (menu->submenu_id != (Widget)0)
1635 {
1636 XtDestroyWidget(menu->submenu_id);
1637 menu->submenu_id = (Widget)0;
1638 }
1639
1640 if (menu->id != (Widget)0)
1641 {
1642 Widget parent;
1643
1644 parent = XtParent(menu->id);
1645#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001646 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {
1648 /* We try to destroy this before the actual menu, because there are
1649 * callbacks, etc. that will be unregistered during the tooltip
1650 * destruction.
1651 *
1652 * If you call "gui_mch_destroy_beval_area()" after destroying
1653 * menu->id, then the tooltip's window will have already been
1654 * deallocated by Xt, and unknown behaviour will ensue (probably
1655 * a core dump).
1656 */
1657 gui_mch_destroy_beval_area(menu->tip);
1658 menu->tip = NULL;
1659 }
1660#endif
1661 XtDestroyWidget(menu->id);
1662 menu->id = (Widget)0;
1663 if (parent == menuBar)
1664 gui_mch_compute_menu_height((Widget)0);
1665#ifdef FEAT_TOOLBAR
1666 else if (parent == toolBar)
1667 {
1668 Cardinal num_children;
1669
1670 /* When removing last toolbar item, don't display the toolbar. */
1671 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1672 if (num_children == 0)
1673 gui_mch_show_toolbar(FALSE);
1674 else
1675 gui.toolbar_height = gui_mch_compute_toolbar_height();
1676 }
1677#endif
1678 }
1679}
1680
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001682gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683{
1684#ifdef MOTIF_POPUP
1685 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1686 XtManageChild(menu->submenu_id);
1687#endif
1688}
1689
1690#endif /* FEAT_MENU */
1691
1692/*
1693 * Set the menu and scrollbar colors to their default values.
1694 */
1695 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001696gui_mch_def_colors(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697{
1698 if (gui.in_use)
1699 {
1700 /* Use the values saved when starting up. These should come from the
1701 * window manager or a resources file. */
1702 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1703 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1704 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1705 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
1706#ifdef FEAT_BEVAL
1707 gui.tooltip_fg_pixel =
1708 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1709 gui.tooltip_bg_pixel =
1710 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1711#endif
1712 }
1713}
1714
1715
1716/*
1717 * Scrollbar stuff.
1718 */
1719
1720 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001721gui_mch_set_scrollbar_thumb(
1722 scrollbar_T *sb,
1723 long val,
1724 long size,
1725 long max)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726{
1727 if (sb->id != (Widget)0)
1728 XtVaSetValues(sb->id,
1729 XmNvalue, val,
1730 XmNsliderSize, size,
1731 XmNpageIncrement, (size > 2 ? size - 2 : 1),
1732 XmNmaximum, max + 1, /* Motif has max one past the end */
1733 NULL);
1734}
1735
1736 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001737gui_mch_set_scrollbar_pos(
1738 scrollbar_T *sb,
1739 int x,
1740 int y,
1741 int w,
1742 int h)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743{
1744 if (sb->id != (Widget)0)
1745 {
1746 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1747 {
1748 if (y == 0)
1749 h -= gui.border_offset;
1750 else
1751 y -= gui.border_offset;
1752 XtVaSetValues(sb->id,
1753 XmNtopOffset, y,
1754 XmNbottomOffset, -y - h,
1755 XmNwidth, w,
1756 NULL);
1757 }
1758 else
1759 XtVaSetValues(sb->id,
1760 XmNtopOffset, y,
1761 XmNleftOffset, x,
1762 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1763 ? gui.scrollbar_width : 0,
1764 XmNheight, h,
1765 NULL);
1766 XtManageChild(sb->id);
1767 }
1768}
1769
1770 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001771gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772{
1773 Arg args[16];
1774 int n;
1775
1776 if (sb->id != (Widget)0)
1777 {
1778 n = 0;
1779 if (flag)
1780 {
1781 switch (sb->type)
1782 {
1783 case SBAR_LEFT:
1784 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1785 break;
1786
1787 case SBAR_RIGHT:
1788 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1789 break;
1790
1791 case SBAR_BOTTOM:
1792 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1793 break;
1794 }
1795 XtSetValues(textArea, args, n);
1796 XtManageChild(sb->id);
1797 }
1798 else
1799 {
1800 if (!gui.which_scrollbars[sb->type])
1801 {
1802 /* The scrollbars of this type are all disabled, adjust the
1803 * textArea attachment offset. */
1804 switch (sb->type)
1805 {
1806 case SBAR_LEFT:
1807 XtSetArg(args[n], XmNleftOffset, 0); n++;
1808 break;
1809
1810 case SBAR_RIGHT:
1811 XtSetArg(args[n], XmNrightOffset, 0); n++;
1812 break;
1813
1814 case SBAR_BOTTOM:
1815 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1816 break;
1817 }
1818 XtSetValues(textArea, args, n);
1819 }
1820 XtUnmanageChild(sb->id);
1821 }
1822 }
1823}
1824
1825 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001826gui_mch_create_scrollbar(
1827 scrollbar_T *sb,
1828 int orient) /* SBAR_VERT or SBAR_HORIZ */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829{
1830 Arg args[16];
1831 int n;
1832
1833 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 XtSetArg(args[n], XmNminimum, 0); n++;
1835 XtSetArg(args[n], XmNorientation,
1836 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1837
1838 switch (sb->type)
1839 {
1840 case SBAR_LEFT:
1841 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1842 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1843 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1844 break;
1845
1846 case SBAR_RIGHT:
1847 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1848 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1849 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1850 break;
1851
1852 case SBAR_BOTTOM:
1853 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1854 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1855 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1856 break;
1857 }
1858
1859 sb->id = XtCreateWidget("scrollBar",
1860 xmScrollBarWidgetClass, textAreaForm, args, n);
1861
1862 /* Remember the default colors, needed for ":hi clear". */
1863 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1864 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1865 XtVaGetValues(sb->id,
1866 XmNbackground, &gui.scroll_def_bg_pixel,
1867 XmNforeground, &gui.scroll_def_fg_pixel,
1868 NULL);
1869
1870 if (sb->id != (Widget)0)
1871 {
1872 gui_mch_set_scrollbar_colors(sb);
1873 XtAddCallback(sb->id, XmNvalueChangedCallback,
1874 scroll_cb, (XtPointer)sb->ident);
1875 XtAddCallback(sb->id, XmNdragCallback,
1876 scroll_cb, (XtPointer)sb->ident);
1877 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1878 (XtPointer)0);
1879 }
1880}
1881
1882#if defined(FEAT_WINDOWS) || defined(PROTO)
1883 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001884gui_mch_destroy_scrollbar(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885{
1886 if (sb->id != (Widget)0)
1887 XtDestroyWidget(sb->id);
1888}
1889#endif
1890
1891 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001892gui_mch_set_scrollbar_colors(scrollbar_T *sb)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893{
1894 if (sb->id != (Widget)0)
1895 {
1896 if (gui.scroll_bg_pixel != INVALCOLOR)
1897 {
1898#if (XmVersion>=1002)
1899 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1900#else
1901 XtVaSetValues(sb->id,
1902 XmNtroughColor, gui.scroll_bg_pixel,
1903 NULL);
1904#endif
1905 }
1906
1907 if (gui.scroll_fg_pixel != INVALCOLOR)
1908 XtVaSetValues(sb->id,
1909 XmNforeground, gui.scroll_fg_pixel,
1910#if (XmVersion<1002)
1911 XmNbackground, gui.scroll_fg_pixel,
1912#endif
1913 NULL);
1914 }
1915
1916 /* This is needed for the rectangle below the vertical scrollbars. */
1917 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1918 gui_motif_scroll_colors(textAreaForm);
1919}
1920
1921/*
1922 * Miscellaneous stuff:
1923 */
1924
1925 Window
Bram Moolenaar66f948e2016-01-30 16:39:25 +01001926gui_x11_get_wid(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927{
1928 return(XtWindow(textArea));
1929}
1930
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001931/*
1932 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1933 * When one is found, simulate a button press on that widget and give it the
1934 * keyboard focus. If the mnemonic is on a label, look in the userData field
1935 * of the label to see if it points to another widget, and give that the focus.
1936 */
1937 static void
1938do_mnemonic(Widget w, unsigned int keycode)
1939{
1940 WidgetList children;
1941 int numChildren, i;
1942 Boolean isMenu;
1943 KeySym mnemonic = '\0';
1944 char mneString[2];
1945 Widget userData;
1946 unsigned char rowColType;
1947
1948 if (XtIsComposite(w))
1949 {
1950 if (XtClass(w) == xmRowColumnWidgetClass)
1951 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001952 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001953 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1954 }
1955 else
1956 isMenu = False;
1957 if (!isMenu)
1958 {
1959 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001960 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001961 for (i = 0; i < numChildren; i++)
1962 do_mnemonic(children[i], keycode);
1963 }
1964 }
1965 else
1966 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001967 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001968 if (mnemonic != '\0')
1969 {
1970 mneString[0] = mnemonic;
1971 mneString[1] = '\0';
1972 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1973 XStringToKeysym(mneString)) == keycode)
1974 {
1975 if (XtClass(w) == xmLabelWidgetClass
1976 || XtClass(w) == xmLabelGadgetClass)
1977 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001978 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001979 if (userData != NULL && XtIsWidget(userData))
1980 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1981 }
1982 else
1983 {
1984 XKeyPressedEvent keyEvent;
1985
1986 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1987
Bram Moolenaar7db5fc82010-05-24 11:59:29 +02001988 vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001989 keyEvent.type = KeyPress;
1990 keyEvent.serial = 1;
1991 keyEvent.send_event = True;
1992 keyEvent.display = XtDisplay(w);
1993 keyEvent.window = XtWindow(w);
1994 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
1995 NULL, 0);
1996 }
1997 }
1998 }
1999 }
2000}
2001
2002/*
2003 * Callback routine for dialog mnemonic processing.
2004 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002005 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002006mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002007{
2008 do_mnemonic(w, event->keycode);
2009}
2010
2011
2012/*
2013 * Search the widget tree under w for widgets with mnemonics. When found, add
2014 * a passive grab to the dialog widget for the mnemonic character, thus
2015 * directing mnemonic events to the dialog widget.
2016 */
2017 static void
2018add_mnemonic_grabs(Widget dialog, Widget w)
2019{
2020 char mneString[2];
2021 WidgetList children;
2022 int numChildren, i;
2023 Boolean isMenu;
2024 KeySym mnemonic = '\0';
2025 unsigned char rowColType;
2026
2027 if (XtIsComposite(w))
2028 {
2029 if (XtClass(w) == xmRowColumnWidgetClass)
2030 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002031 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002032 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2033 }
2034 else
2035 isMenu = False;
2036 if (!isMenu)
2037 {
2038 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002039 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002040 for (i = 0; i < numChildren; i++)
2041 add_mnemonic_grabs(dialog, children[i]);
2042 }
2043 }
2044 else
2045 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002046 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002047 if (mnemonic != '\0')
2048 {
2049 mneString[0] = mnemonic;
2050 mneString[1] = '\0';
2051 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2052 XStringToKeysym(mneString)),
2053 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2054 }
2055 }
2056}
2057
2058/*
2059 * Add a handler for mnemonics in a dialog. Motif itself only handles
2060 * mnemonics in menus. Mnemonics added or changed after this call will be
2061 * ignored.
2062 *
2063 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2064 * the appropriate label and set the XmNuserData resource of the label to the
2065 * widget to get the focus when the mnemonic is typed.
2066 */
2067 static void
2068activate_dialog_mnemonics(Widget dialog)
2069{
2070 if (!dialog)
2071 return;
2072
2073 XtAddEventHandler(dialog, KeyPressMask, False,
2074 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2075 add_mnemonic_grabs(dialog, dialog);
2076}
2077
2078/*
2079 * Removes the event handler and key-grabs for dialog mnemonic handling.
2080 */
2081 static void
2082suppress_dialog_mnemonics(Widget dialog)
2083{
2084 if (!dialog)
2085 return;
2086
2087 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2088 XtRemoveEventHandler(dialog, KeyPressMask, False,
2089 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2090}
2091
2092#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002093static void set_fontlist(Widget wg);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002094
2095/*
2096 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2097 */
2098 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002099set_fontlist(Widget id)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002100{
2101 XmFontList fl;
2102
2103#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002104 if (gui.fontset != NOFONTSET)
2105 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002106 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2107 if (fl != NULL)
2108 {
2109 if (XtIsManaged(id))
2110 {
2111 XtUnmanageChild(id);
2112 XtVaSetValues(id, XmNfontList, fl, NULL);
2113 /* We should force the widget to recalculate it's
2114 * geometry now. */
2115 XtManageChild(id);
2116 }
2117 else
2118 XtVaSetValues(id, XmNfontList, fl, NULL);
2119 XmFontListFree(fl);
2120 }
2121 }
2122#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002123 if (gui.norm_font != NOFONT)
2124 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002125 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2126 if (fl != NULL)
2127 {
2128 if (XtIsManaged(id))
2129 {
2130 XtUnmanageChild(id);
2131 XtVaSetValues(id, XmNfontList, fl, NULL);
2132 /* We should force the widget to recalculate it's
2133 * geometry now. */
2134 XtManageChild(id);
2135 }
2136 else
2137 XtVaSetValues(id, XmNfontList, fl, NULL);
2138 XmFontListFree(fl);
2139 }
2140 }
2141#endif
2142}
2143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144
2145#if defined(FEAT_BROWSE) || defined(PROTO)
2146
2147/*
2148 * file selector related stuff
2149 */
2150
2151#include <Xm/FileSB.h>
2152#include <Xm/XmStrDefs.h>
2153
2154typedef struct dialog_callback_arg
2155{
2156 char * args; /* not used right now */
2157 int id;
2158} dcbarg_T;
2159
2160static Widget dialog_wgt;
2161static char *browse_fname = NULL;
2162static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2163 /* used to set up XmStrings */
2164
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002165static void DialogCancelCB(Widget, XtPointer, XtPointer);
2166static void DialogAcceptCB(Widget, XtPointer, XtPointer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167
2168/*
2169 * This function is used to translate the predefined label text of the
2170 * precomposed dialogs. We do this explicitly to allow:
2171 *
2172 * - usage of gettext for translation, as in all the other places.
2173 *
2174 * - equalize the messages between different GUI implementations as far as
2175 * possible.
2176 */
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002177static void set_predefined_label(Widget parent, String name, char *new_label);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002179 static void
2180set_predefined_label(Widget parent, String name, char *new_label)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002182 XmString str;
2183 Widget w;
2184 char_u *p, *next;
2185 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186
2187 w = XtNameToWidget(parent, name);
2188
2189 if (!w)
2190 return;
2191
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002192 p = vim_strsave((char_u *)new_label);
2193 if (p == NULL)
2194 return;
2195 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002196 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002197 if (*next == DLG_HOTKEY_CHAR)
2198 {
2199 int len = STRLEN(next);
2200
2201 if (len > 0)
2202 {
2203 mch_memmove(next, next + 1, len);
2204 mnemonic = next[0];
2205 }
2206 }
2207 }
2208
2209 str = XmStringCreate((char *)p, STRING_TAG);
2210 vim_free(p);
2211
2212 if (str != NULL)
2213 {
2214 XtVaSetValues(w,
2215 XmNlabelString, str,
2216 XmNmnemonic, mnemonic,
2217 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 XmStringFree(str);
2219 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002220 gui_motif_menu_fontlist(w);
2221}
2222
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002223 static void
2224set_predefined_fontlist(Widget parent, String name)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002225{
2226 Widget w;
2227 w = XtNameToWidget(parent, name);
2228
2229 if (!w)
2230 return;
2231
2232 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002233}
2234
2235/*
2236 * Put up a file requester.
2237 * Returns the selected name in allocated memory, or NULL for Cancel.
2238 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 char_u *
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002240gui_mch_browse(
2241 int saving UNUSED, /* select file to write */
2242 char_u *title, /* title for the window */
2243 char_u *dflt, /* default name */
2244 char_u *ext UNUSED, /* not used (extension added) */
2245 char_u *initdir, /* initial directory, NULL for current dir */
2246 char_u *filter) /* file name filter */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247{
2248 char_u dirbuf[MAXPATHL];
2249 char_u dfltbuf[MAXPATHL];
2250 char_u *pattern;
2251 char_u *tofree = NULL;
2252
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002253 /* There a difference between the resource name and value, Therefore, we
2254 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2255 * dialog name.
2256 */
2257
2258 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259
2260 if (initdir == NULL || *initdir == NUL)
2261 {
2262 mch_dirname(dirbuf, MAXPATHL);
2263 initdir = dirbuf;
2264 }
2265
2266 if (dflt == NULL)
2267 dflt = (char_u *)"";
2268 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2269 {
2270 /* The default selection should be the full path, "dflt" is only the
2271 * file name. */
2272 STRCPY(dfltbuf, initdir);
2273 add_pathsep(dfltbuf);
2274 STRCAT(dfltbuf, dflt);
2275 dflt = dfltbuf;
2276 }
2277
2278 /* Can only use one pattern for a file name. Get the first pattern out of
2279 * the filter. An empty pattern means everything matches. */
2280 if (filter == NULL)
2281 pattern = (char_u *)"";
2282 else
2283 {
2284 char_u *s, *p;
2285
2286 s = filter;
2287 for (p = filter; *p != NUL; ++p)
2288 {
2289 if (*p == '\t') /* end of description, start of pattern */
2290 s = p + 1;
2291 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2292 break;
2293 }
2294 pattern = vim_strnsave(s, p - s);
2295 tofree = pattern;
2296 if (pattern == NULL)
2297 pattern = (char_u *)"";
2298 }
2299
2300 XtVaSetValues(dialog_wgt,
2301 XtVaTypedArg,
2302 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2303 XtVaTypedArg,
2304 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2305 XtVaTypedArg,
2306 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2307 XtVaTypedArg,
2308 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2309 NULL);
2310
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002311 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2312 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2314 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002315 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002317 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2319
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002320 /* This is to save us from silly external settings using not fixed with
2321 * fonts for file selection.
2322 */
2323 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2324 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2325
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 gui_motif_menu_colors(dialog_wgt);
2327 if (gui.scroll_bg_pixel != INVALCOLOR)
2328 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2329
2330 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2331 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2332 /* We have no help in this window, so hide help button */
2333 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2334 (unsigned char)XmDIALOG_HELP_BUTTON));
2335
2336 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002337 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338
2339 /* sit in a loop until the dialog box has gone away */
2340 do
2341 {
2342 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2343 (XtInputMask)XtIMAll);
2344 } while (XtIsManaged(dialog_wgt));
2345
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002346 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 XtDestroyWidget(dialog_wgt);
2348 vim_free(tofree);
2349
2350 if (browse_fname == NULL)
2351 return NULL;
2352 return vim_strsave((char_u *)browse_fname);
2353}
2354
2355/*
2356 * The code below was originally taken from
2357 * /usr/examples/motif/xmsamplers/xmeditor.c
2358 * on Digital Unix 4.0d, but heavily modified.
2359 */
2360
2361/*
2362 * Process callback from Dialog cancel actions.
2363 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002365DialogCancelCB(
2366 Widget w UNUSED, /* widget id */
2367 XtPointer client_data UNUSED, /* data from application */
2368 XtPointer call_data UNUSED) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369{
2370 if (browse_fname != NULL)
2371 {
2372 XtFree(browse_fname);
2373 browse_fname = NULL;
2374 }
2375 XtUnmanageChild(dialog_wgt);
2376}
2377
2378/*
2379 * Process callback from Dialog actions.
2380 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002382DialogAcceptCB(
2383 Widget w UNUSED, /* widget id */
2384 XtPointer client_data UNUSED, /* data from application */
2385 XtPointer call_data) /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386{
2387 XmFileSelectionBoxCallbackStruct *fcb;
2388
2389 if (browse_fname != NULL)
2390 {
2391 XtFree(browse_fname);
2392 browse_fname = NULL;
2393 }
2394 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2395
2396 /* get the filename from the file selection box */
2397 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2398
2399 /* popdown the file selection box */
2400 XtUnmanageChild(dialog_wgt);
2401}
2402
2403#endif /* FEAT_BROWSE */
2404
2405#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2406
2407static int dialogStatus;
2408
Bram Moolenaard25c16e2016-01-29 22:13:30 +01002409static void keyhit_callback(Widget w, XtPointer client_data, XEvent *event, Boolean *cont);
2410static void butproc(Widget w, XtPointer client_data, XtPointer call_data);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411
2412/*
2413 * Callback function for the textfield. When CR is hit this works like
2414 * hitting the "OK" button, ESC like "Cancel".
2415 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002417keyhit_callback(
2418 Widget w,
2419 XtPointer client_data UNUSED,
2420 XEvent *event,
2421 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422{
2423 char buf[2];
2424 KeySym key_sym;
2425
2426 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2427 {
2428 if (*buf == CAR)
2429 dialogStatus = 1;
2430 else if (*buf == ESC)
2431 dialogStatus = 2;
2432 }
2433 if ((key_sym == XK_Left || key_sym == XK_Right)
2434 && !(event->xkey.state & ShiftMask))
2435 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2436}
2437
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002439butproc(
2440 Widget w UNUSED,
2441 XtPointer client_data,
2442 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443{
2444 dialogStatus = (int)(long)client_data + 1;
2445}
2446
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447#ifdef HAVE_XPM
2448
2449static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg);
2450
2451 static Widget
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002452create_pixmap_label(
2453 Widget parent,
2454 String name,
2455 char **data,
2456 ArgList args,
2457 Cardinal arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458{
2459 Widget label;
2460 Display *dsp;
2461 Screen *scr;
2462 int depth;
2463 Pixmap pixmap = 0;
2464 XpmAttributes attr;
2465 Boolean rs;
2466 XpmColorSymbol color[5] =
2467 {
2468 {"none", NULL, 0},
2469 {"iconColor1", NULL, 0},
2470 {"bottomShadowColor", NULL, 0},
2471 {"topShadowColor", NULL, 0},
2472 {"selectColor", NULL, 0}
2473 };
2474
2475 label = XmCreateLabelGadget(parent, name, args, arg);
2476
2477 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002478 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 * no way to get the background color directly from the widget itself.
2480 * In such cases we get it from The Core part of his parent instead.
2481 */
2482 dsp = XtDisplayOfObject(label);
2483 scr = XtScreenOfObject(label);
2484 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2485 ? label : XtParent(label),
2486 XmNdepth, &depth,
2487 XmNbackground, &color[0].pixel,
2488 XmNforeground, &color[1].pixel,
2489 XmNbottomShadowColor, &color[2].pixel,
2490 XmNtopShadowColor, &color[3].pixel,
2491 XmNhighlight, &color[4].pixel,
2492 NULL);
2493
2494 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2495 attr.colorsymbols = color;
2496 attr.numsymbols = 5;
2497 attr.closeness = 65535;
2498 attr.depth = depth;
2499 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2500 data, &pixmap, NULL, &attr);
2501
2502 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2503 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2504 XtVaSetValues(label,
2505 XmNlabelType, XmPIXMAP,
2506 XmNlabelPixmap, pixmap,
2507 NULL);
2508 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2509
2510 return label;
2511}
2512#endif
2513
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002515gui_mch_dialog(
2516 int type UNUSED,
2517 char_u *title,
2518 char_u *message,
2519 char_u *button_names,
2520 int dfltbutton,
2521 char_u *textfield, /* buffer of size IOSIZE */
2522 int ex_cmd UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523{
2524 char_u *buts;
2525 char_u *p, *next;
2526 XtAppContext app;
2527 XmString label;
2528 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002529 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 Widget dialogform = NULL;
2531 Widget form = NULL;
2532 Widget dialogtextfield = NULL;
2533 Widget *buttons;
2534 Widget sep_form = NULL;
2535 Boolean vertical;
2536 Widget separator = NULL;
2537 int n;
2538 Arg args[6];
2539#ifdef HAVE_XPM
2540 char **icon_data = NULL;
2541 Widget dialogpixmap = NULL;
2542#endif
2543
2544 if (title == NULL)
2545 title = (char_u *)_("Vim dialog");
2546
2547 /* if our pointer is currently hidden, then we should show it. */
2548 gui_mch_mousehide(FALSE);
2549
2550 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2551
2552 /* Check 'v' flag in 'guioptions': vertical button placement. */
2553 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2554
2555 /* Set the title of the Dialog window */
2556 label = XmStringCreateSimple((char *)title);
2557 if (label == NULL)
2558 return -1;
2559 XtVaSetValues(dialogform,
2560 XmNdialogTitle, label,
2561 XmNhorizontalSpacing, 4,
2562 XmNverticalSpacing, vertical ? 0 : 4,
2563 NULL);
2564 XmStringFree(label);
2565
2566 /* make a copy, so that we can insert NULs */
2567 buts = vim_strsave(button_names);
2568 if (buts == NULL)
2569 return -1;
2570
2571 /* Count the number of buttons and allocate buttons[]. */
2572 butcount = 1;
2573 for (p = buts; *p; ++p)
2574 if (*p == DLG_BUTTON_SEP)
2575 ++butcount;
2576 buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
2577 if (buttons == NULL)
2578 {
2579 vim_free(buts);
2580 return -1;
2581 }
2582
2583 /*
2584 * Create the buttons.
2585 */
2586 sep_form = (Widget) 0;
2587 p = buts;
2588 for (butcount = 0; *p; ++butcount)
2589 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002590 KeySym mnemonic = NUL;
2591
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 for (next = p; *next; ++next)
2593 {
2594 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002595 {
2596 int len = STRLEN(next);
2597
2598 if (len > 0)
2599 {
2600 mch_memmove(next, next + 1, len);
2601 mnemonic = next[0];
2602 }
2603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 if (*next == DLG_BUTTON_SEP)
2605 {
2606 *next++ = NUL;
2607 break;
2608 }
2609 }
2610 label = XmStringCreate(_((char *)p), STRING_TAG);
2611 if (label == NULL)
2612 break;
2613
2614 buttons[butcount] = XtVaCreateManagedWidget("button",
2615 xmPushButtonWidgetClass, dialogform,
2616 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002617 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 XmNbottomAttachment, XmATTACH_FORM,
2619 XmNbottomOffset, 4,
2620 XmNshowAsDefault, butcount == dfltbutton - 1,
2621 XmNdefaultButtonShadowThickness, 1,
2622 NULL);
2623 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002624 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625
2626 /* Layout properly. */
2627
2628 if (butcount > 0)
2629 {
2630 if (vertical)
2631 XtVaSetValues(buttons[butcount],
2632 XmNtopWidget, buttons[butcount - 1],
2633 NULL);
2634 else
2635 {
2636 if (*next == NUL)
2637 {
2638 XtVaSetValues(buttons[butcount],
2639 XmNrightAttachment, XmATTACH_FORM,
2640 XmNrightOffset, 4,
2641 NULL);
2642
2643 /* fill in a form as invisible separator */
2644 sep_form = XtVaCreateWidget("separatorForm",
2645 xmFormWidgetClass, dialogform,
2646 XmNleftAttachment, XmATTACH_WIDGET,
2647 XmNleftWidget, buttons[butcount - 1],
2648 XmNrightAttachment, XmATTACH_WIDGET,
2649 XmNrightWidget, buttons[butcount],
2650 XmNbottomAttachment, XmATTACH_FORM,
2651 XmNbottomOffset, 4,
2652 NULL);
2653 XtManageChild(sep_form);
2654 }
2655 else
2656 {
2657 XtVaSetValues(buttons[butcount],
2658 XmNleftAttachment, XmATTACH_WIDGET,
2659 XmNleftWidget, buttons[butcount - 1],
2660 NULL);
2661 }
2662 }
2663 }
2664 else if (!vertical)
2665 {
2666 if (*next == NUL)
2667 {
2668 XtVaSetValues(buttons[0],
2669 XmNrightAttachment, XmATTACH_FORM,
2670 XmNrightOffset, 4,
2671 NULL);
2672
2673 /* fill in a form as invisible separator */
2674 sep_form = XtVaCreateWidget("separatorForm",
2675 xmFormWidgetClass, dialogform,
2676 XmNleftAttachment, XmATTACH_FORM,
2677 XmNleftOffset, 4,
2678 XmNrightAttachment, XmATTACH_WIDGET,
2679 XmNrightWidget, buttons[0],
2680 XmNbottomAttachment, XmATTACH_FORM,
2681 XmNbottomOffset, 4,
2682 NULL);
2683 XtManageChild(sep_form);
2684 }
2685 else
2686 XtVaSetValues(buttons[0],
2687 XmNleftAttachment, XmATTACH_FORM,
2688 XmNleftOffset, 4,
2689 NULL);
2690 }
2691
2692 XtAddCallback(buttons[butcount], XmNactivateCallback,
2693 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2694 p = next;
2695 }
2696 vim_free(buts);
2697
2698 separator = (Widget) 0;
2699 if (butcount > 0)
2700 {
2701 /* Create the separator for beauty. */
2702 n = 0;
2703 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2704 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2705 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2706 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2707 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2708 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2709 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2710 XtManageChild(separator);
2711 }
2712
2713 if (textfield != NULL)
2714 {
2715 dialogtextfield = XtVaCreateWidget("textField",
2716 xmTextFieldWidgetClass, dialogform,
2717 XmNleftAttachment, XmATTACH_FORM,
2718 XmNrightAttachment, XmATTACH_FORM,
2719 NULL);
2720 if (butcount > 0)
2721 XtVaSetValues(dialogtextfield,
2722 XmNbottomAttachment, XmATTACH_WIDGET,
2723 XmNbottomWidget, separator,
2724 NULL);
2725 else
2726 XtVaSetValues(dialogtextfield,
2727 XmNbottomAttachment, XmATTACH_FORM,
2728 NULL);
2729
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002730 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2732 XtManageChild(dialogtextfield);
2733 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2734 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2735 }
2736
2737 /* Form holding both message and pixmap labels */
2738 form = XtVaCreateWidget("separatorForm",
2739 xmFormWidgetClass, dialogform,
2740 XmNleftAttachment, XmATTACH_FORM,
2741 XmNrightAttachment, XmATTACH_FORM,
2742 XmNtopAttachment, XmATTACH_FORM,
2743 NULL);
2744 XtManageChild(form);
2745
2746#ifdef HAVE_XPM
2747 /* Add a pixmap, left of the message. */
2748 switch (type)
2749 {
2750 case VIM_GENERIC:
2751 icon_data = generic_xpm;
2752 break;
2753 case VIM_ERROR:
2754 icon_data = error_xpm;
2755 break;
2756 case VIM_WARNING:
2757 icon_data = alert_xpm;
2758 break;
2759 case VIM_INFO:
2760 icon_data = info_xpm;
2761 break;
2762 case VIM_QUESTION:
2763 icon_data = quest_xpm;
2764 break;
2765 default:
2766 icon_data = generic_xpm;
2767 }
2768
2769 n = 0;
2770 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2771 XtSetArg(args[n], XmNtopOffset, 8); n++;
2772 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2773 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2774 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2775 XtSetArg(args[n], XmNleftOffset, 8); n++;
2776
2777 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2778 icon_data, args, n);
2779 XtManageChild(dialogpixmap);
2780#endif
2781
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002782 /* Create the dialog message.
2783 * Since LessTif is apparently having problems with the creation of
2784 * properly localized string, we use LtoR here. The symptom is that the
2785 * string sill not show properly in multiple lines as it does in native
2786 * Motif.
2787 */
2788 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 if (label == NULL)
2790 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002791 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 xmLabelGadgetClass, form,
2793 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002794 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 XmNtopAttachment, XmATTACH_FORM,
2796 XmNtopOffset, 8,
2797#ifdef HAVE_XPM
2798 XmNleftAttachment, XmATTACH_WIDGET,
2799 XmNleftWidget, dialogpixmap,
2800#else
2801 XmNleftAttachment, XmATTACH_FORM,
2802#endif
2803 XmNleftOffset, 8,
2804 XmNrightAttachment, XmATTACH_FORM,
2805 XmNrightOffset, 8,
2806 XmNbottomAttachment, XmATTACH_FORM,
2807 XmNbottomOffset, 8,
2808 NULL);
2809 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002810 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811
2812 if (textfield != NULL)
2813 {
2814 XtVaSetValues(form,
2815 XmNbottomAttachment, XmATTACH_WIDGET,
2816 XmNbottomWidget, dialogtextfield,
2817 NULL);
2818 }
2819 else
2820 {
2821 if (butcount > 0)
2822 XtVaSetValues(form,
2823 XmNbottomAttachment, XmATTACH_WIDGET,
2824 XmNbottomWidget, separator,
2825 NULL);
2826 else
2827 XtVaSetValues(form,
2828 XmNbottomAttachment, XmATTACH_FORM,
2829 NULL);
2830 }
2831
2832 if (dfltbutton < 1)
2833 dfltbutton = 1;
2834 if (dfltbutton > butcount)
2835 dfltbutton = butcount;
2836 XtVaSetValues(dialogform,
2837 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2838 if (textfield != NULL)
2839 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2840 else
2841 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2842 NULL);
2843
2844 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002845 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846
2847 if (textfield != NULL && *textfield != NUL)
2848 {
2849 /* This only works after the textfield has been realised. */
2850 XmTextFieldSetSelection(dialogtextfield,
2851 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2852 XtLastTimestampProcessed(gui.dpy));
2853 XmTextFieldSetCursorPosition(dialogtextfield,
2854 (XmTextPosition)STRLEN(textfield));
2855 }
2856
2857 app = XtWidgetToApplicationContext(dialogform);
2858
2859 /* Loop until a button is pressed or the dialog is killed somehow. */
2860 dialogStatus = -1;
2861 for (;;)
2862 {
2863 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2864 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2865 break;
2866 }
2867
2868 vim_free(buttons);
2869
2870 if (textfield != NULL)
2871 {
2872 p = (char_u *)XmTextGetString(dialogtextfield);
2873 if (p == NULL || dialogStatus < 0)
2874 *textfield = NUL;
2875 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002876 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002877 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 }
2879
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002880 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 XtDestroyWidget(dialogform);
2882
2883 return dialogStatus;
2884}
2885#endif /* FEAT_GUI_DIALOG */
2886
2887#if defined(FEAT_FOOTER) || defined(PROTO)
2888
2889 static int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002890gui_mch_compute_footer_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891{
2892 Dimension height; /* total Toolbar height */
2893 Dimension top; /* XmNmarginTop */
2894 Dimension bottom; /* XmNmarginBottom */
2895 Dimension shadow; /* XmNshadowThickness */
2896
2897 XtVaGetValues(footer,
2898 XmNheight, &height,
2899 XmNmarginTop, &top,
2900 XmNmarginBottom, &bottom,
2901 XmNshadowThickness, &shadow,
2902 NULL);
2903
2904 return (int) height + top + bottom + (shadow << 1);
2905}
2906
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002908gui_mch_enable_footer(int showit)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909{
2910 if (showit)
2911 {
2912 gui.footer_height = gui_mch_compute_footer_height();
2913 XtManageChild(footer);
2914 }
2915 else
2916 {
2917 gui.footer_height = 0;
2918 XtUnmanageChild(footer);
2919 }
2920 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2921}
2922
2923 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01002924gui_mch_set_footer(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925{
2926 XmString xms;
2927
2928 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002929 if (xms != NULL)
2930 {
2931 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2932 XmStringFree(xms);
2933 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934}
2935
2936#endif
2937
2938
2939#if defined(FEAT_TOOLBAR) || defined(PROTO)
2940 void
2941gui_mch_show_toolbar(int showit)
2942{
2943 Cardinal numChildren; /* how many children toolBar has */
2944
2945 if (toolBar == (Widget)0)
2946 return;
2947 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2948 if (showit && numChildren > 0)
2949 {
2950 /* Assume that we want to show the toolbar if p_toolbar contains
2951 * valid option settings, therefore p_toolbar must not be NULL.
2952 */
2953 WidgetList children;
2954
2955 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2956 {
2957 void (*action)(BalloonEval *);
2958 int text = 0;
2959
2960 if (strstr((const char *)p_toolbar, "tooltips"))
2961 action = &gui_mch_enable_beval_area;
2962 else
2963 action = &gui_mch_disable_beval_area;
2964 if (strstr((const char *)p_toolbar, "text"))
2965 text = 1;
2966 else if (strstr((const char *)p_toolbar, "icons"))
2967 text = -1;
2968 if (text != 0)
2969 {
2970 vimmenu_T *toolbar;
2971 vimmenu_T *cur;
2972
2973 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
2974 if (menu_is_toolbar(toolbar->dname))
2975 break;
2976 /* Assumption: toolbar is NULL if there is no toolbar,
2977 * otherwise it contains the toolbar menu structure.
2978 *
2979 * Assumption: "numChildren" == the number of items in the list
2980 * of items beginning with toolbar->children.
2981 */
2982 if (toolbar)
2983 {
2984 for (cur = toolbar->children; cur; cur = cur->next)
2985 {
2986 Arg args[1];
2987 int n = 0;
2988
2989 /* Enable/Disable tooltip (OK to enable while
Bram Moolenaarf193fff2006-04-27 00:02:13 +00002990 * currently enabled). */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 if (cur->tip != NULL)
2992 (*action)(cur->tip);
2993 if (!menu_is_separator(cur->name))
2994 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002995 if (text == 1 || cur->xpm == NULL)
2996 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002998 ++n;
2999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 if (cur->id != NULL)
3001 {
3002 XtUnmanageChild(cur->id);
3003 XtSetValues(cur->id, args, n);
3004 XtManageChild(cur->id);
3005 }
3006 }
3007 }
3008 }
3009 }
3010 }
3011 gui.toolbar_height = gui_mch_compute_toolbar_height();
3012 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003013#ifdef FEAT_GUI_TABLINE
3014 if (showing_tabline)
3015 {
3016 XtVaSetValues(tabLine,
3017 XmNtopAttachment, XmATTACH_WIDGET,
3018 XmNtopWidget, XtParent(toolBar),
3019 NULL);
3020 XtVaSetValues(textAreaForm,
3021 XmNtopAttachment, XmATTACH_WIDGET,
3022 XmNtopWidget, tabLine,
3023 NULL);
3024 }
3025 else
3026#endif
3027 XtVaSetValues(textAreaForm,
3028 XmNtopAttachment, XmATTACH_WIDGET,
3029 XmNtopWidget, XtParent(toolBar),
3030 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 if (XtIsManaged(menuBar))
3032 XtVaSetValues(XtParent(toolBar),
3033 XmNtopAttachment, XmATTACH_WIDGET,
3034 XmNtopWidget, menuBar,
3035 NULL);
3036 else
3037 XtVaSetValues(XtParent(toolBar),
3038 XmNtopAttachment, XmATTACH_FORM,
3039 NULL);
3040 }
3041 else
3042 {
3043 gui.toolbar_height = 0;
3044 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003045 {
3046#ifdef FEAT_GUI_TABLINE
3047 if (showing_tabline)
3048 {
3049 XtVaSetValues(tabLine,
3050 XmNtopAttachment, XmATTACH_WIDGET,
3051 XmNtopWidget, menuBar,
3052 NULL);
3053 XtVaSetValues(textAreaForm,
3054 XmNtopAttachment, XmATTACH_WIDGET,
3055 XmNtopWidget, tabLine,
3056 NULL);
3057 }
3058 else
3059#endif
3060 XtVaSetValues(textAreaForm,
3061 XmNtopAttachment, XmATTACH_WIDGET,
3062 XmNtopWidget, menuBar,
3063 NULL);
3064 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003066 {
3067#ifdef FEAT_GUI_TABLINE
3068 if (showing_tabline)
3069 {
3070 XtVaSetValues(tabLine,
3071 XmNtopAttachment, XmATTACH_FORM,
3072 NULL);
3073 XtVaSetValues(textAreaForm,
3074 XmNtopAttachment, XmATTACH_WIDGET,
3075 XmNtopWidget, tabLine,
3076 NULL);
3077 }
3078 else
3079#endif
3080 XtVaSetValues(textAreaForm,
3081 XmNtopAttachment, XmATTACH_FORM,
3082 NULL);
3083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084
3085 XtUnmanageChild(XtParent(toolBar));
3086 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003087 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088}
3089
3090/*
3091 * A toolbar button has been pushed; now reset the input focus
3092 * such that the user can type page up/down etc. and have the
3093 * input go to the editor window, not the button
3094 */
3095 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003096reset_focus(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097{
3098 if (textArea != NULL)
3099 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3100}
3101
3102 int
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003103gui_mch_compute_toolbar_height(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003105 Dimension borders;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106 Dimension height; /* total Toolbar height */
3107 Dimension whgt; /* height of each widget */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108 WidgetList children; /* list of toolBar's children */
3109 Cardinal numChildren; /* how many children toolBar has */
3110 int i;
3111
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003112 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3115 { /* get height of XmFrame parent */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003116 Dimension fst;
3117 Dimension fmh;
3118 Dimension tst;
3119 Dimension tmh;
3120
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003122 XmNshadowThickness, &fst,
3123 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003125 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003127 XmNshadowThickness, &tst,
3128 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 XmNchildren, &children,
3130 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003131 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003132 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {
3134 whgt = 0;
3135 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3136 if (height < whgt)
3137 height = whgt;
3138 }
3139 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003140#ifdef LESSTIF_VERSION
3141 /* Hack: When starting up we get wrong dimensions. */
3142 if (height < 10)
3143 height = 24;
3144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003146 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147}
3148
Bram Moolenaar7c626922005-02-07 22:01:03 +00003149 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003150motif_get_toolbar_colors(
3151 Pixel *bgp,
3152 Pixel *fgp,
3153 Pixel *bsp,
3154 Pixel *tsp,
3155 Pixel *hsp)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003156{
3157 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003158 XmNbackground, bgp,
3159 XmNforeground, fgp,
3160 XmNbottomShadowColor, bsp,
3161 XmNtopShadowColor, tsp,
3162 XmNhighlightColor, hsp,
3163 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003164}
3165
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166# ifdef FEAT_FOOTER
3167/*
3168 * The next toolbar enter/leave callbacks should really do balloon help. But
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02003169 * I have to use footer help for backwards compatibility. Hopefully both will
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 * get implemented and the user will have a choice.
3171 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003173toolbarbutton_enter_cb(
3174 Widget w UNUSED,
3175 XtPointer client_data,
3176 XEvent *event UNUSED,
3177 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178{
3179 vimmenu_T *menu = (vimmenu_T *) client_data;
3180
3181 if (menu->strings[MENU_INDEX_TIP] != NULL)
3182 {
3183 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3184 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3185 }
3186}
3187
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003189toolbarbutton_leave_cb(
3190 Widget w UNUSED,
3191 XtPointer client_data UNUSED,
3192 XEvent *event UNUSED,
3193 Boolean *cont UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194{
3195 gui_mch_set_footer((char_u *) "");
3196}
3197# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198#endif
3199
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003200#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3201/*
3202 * Show or hide the tabline.
3203 */
3204 void
3205gui_mch_show_tabline(int showit)
3206{
3207 if (tabLine == (Widget)0)
3208 return;
3209
3210 if (!showit != !showing_tabline)
3211 {
3212 if (showit)
3213 {
3214 XtManageChild(tabLine);
3215 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003216 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3217 XtUnmanageChild(XtNameToWidget(tabLine,
3218 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003219#ifdef FEAT_MENU
3220# ifdef FEAT_TOOLBAR
3221 if (XtIsManaged(XtParent(toolBar)))
3222 XtVaSetValues(tabLine,
3223 XmNtopAttachment, XmATTACH_WIDGET,
3224 XmNtopWidget, XtParent(toolBar), NULL);
3225 else
3226# endif
3227 if (XtIsManaged(menuBar))
3228 XtVaSetValues(tabLine,
3229 XmNtopAttachment, XmATTACH_WIDGET,
3230 XmNtopWidget, menuBar, NULL);
3231 else
3232#endif
3233 XtVaSetValues(tabLine,
3234 XmNtopAttachment, XmATTACH_FORM, NULL);
3235 XtVaSetValues(textAreaForm,
3236 XmNtopAttachment, XmATTACH_WIDGET,
3237 XmNtopWidget, tabLine,
3238 NULL);
3239 }
3240 else
3241 {
3242 XtUnmanageChild(tabLine);
3243#ifdef FEAT_MENU
3244# ifdef FEAT_TOOLBAR
3245 if (XtIsManaged(XtParent(toolBar)))
3246 XtVaSetValues(textAreaForm,
3247 XmNtopAttachment, XmATTACH_WIDGET,
3248 XmNtopWidget, XtParent(toolBar), NULL);
3249 else
3250# endif
3251 if (XtIsManaged(menuBar))
3252 XtVaSetValues(textAreaForm,
3253 XmNtopAttachment, XmATTACH_WIDGET,
3254 XmNtopWidget, menuBar, NULL);
3255 else
3256#endif
3257 XtVaSetValues(textAreaForm,
3258 XmNtopAttachment, XmATTACH_FORM, NULL);
3259 }
3260 showing_tabline = showit;
3261 }
3262}
3263
3264/*
3265 * Return TRUE when tabline is displayed.
3266 */
3267 int
3268gui_mch_showing_tabline(void)
3269{
3270 return tabLine != (Widget)0 && showing_tabline;
3271}
3272
3273/*
3274 * Update the labels of the tabline.
3275 */
3276 void
3277gui_mch_update_tabline(void)
3278{
3279 tabpage_T *tp;
3280 int nr = 1, n;
3281 Arg args[10];
3282 int curtabidx = 0, currentpage;
3283 Widget tab;
3284 XmNotebookPageInfo page_info;
3285 XmNotebookPageStatus page_status;
3286 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003287 XmString label_str;
3288 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003289 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003290
3291 if (tabLine == (Widget)0)
3292 return;
3293
3294 /* Add a label for each tab page. They all contain the same text area. */
3295 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3296 {
3297 if (tp == curtab)
3298 curtabidx = nr;
3299
3300 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3301 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003302 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003303 {
3304 /* Add the tab */
3305 n = 0;
3306 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3307 XtSetArg(args[n], XmNtraversalOn, False); n++;
3308 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3309 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3310 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3311 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3312 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003313 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3314 NULL);
3315 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003316 }
3317 else
3318 tab = page_info.major_tab_widget;
3319
3320 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003321
3322 /*
3323 * Change the label text only if it is different
3324 */
3325 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3326 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3327 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003328 get_tabline_label(tp, FALSE);
3329 if (STRCMP(label_cstr, NameBuff) != 0)
3330 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003331 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3332 NameBuff, STRLEN(NameBuff) + 1, NULL);
3333 /*
3334 * Force a resize of the tab label button
3335 */
3336 XtUnmanageChild(tab);
3337 XtManageChild(tab);
3338 }
3339 XtFree(label_cstr);
3340 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003341 }
3342
3343 tab_count = nr - 1;
3344
3345 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3346
3347 /* Remove any old labels. */
3348 while (nr <= last_page)
3349 {
3350 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3351 && page_info.page_number == nr
3352 && page_info.major_tab_widget != (Widget)0)
3353 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003354 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3355 if (beval != NULL)
3356 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003357 XtUnmanageChild(page_info.major_tab_widget);
3358 XtDestroyWidget(page_info.major_tab_widget);
3359 }
3360 nr++;
3361 }
3362
3363 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3364
3365 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3366 if (currentpage != curtabidx)
3367 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3368}
3369
3370/*
3371 * Set the current tab to "nr". First tab is 1.
3372 */
3373 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003374gui_mch_set_curtab(int nr)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003375{
3376 int currentpage;
3377
3378 if (tabLine == (Widget)0)
3379 return;
3380
3381 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3382 if (currentpage != nr)
3383 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3384}
3385#endif
3386
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387/*
3388 * Set the colors of Widget "id" to the menu colors.
3389 */
3390 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003391gui_motif_menu_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392{
3393 if (gui.menu_bg_pixel != INVALCOLOR)
3394#if (XmVersion >= 1002)
3395 XmChangeColor(id, gui.menu_bg_pixel);
3396#else
3397 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3398#endif
3399 if (gui.menu_fg_pixel != INVALCOLOR)
3400 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3401}
3402
3403/*
3404 * Set the colors of Widget "id" to the scrollbar colors.
3405 */
3406 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003407gui_motif_scroll_colors(Widget id)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408{
3409 if (gui.scroll_bg_pixel != INVALCOLOR)
3410#if (XmVersion >= 1002)
3411 XmChangeColor(id, gui.scroll_bg_pixel);
3412#else
3413 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3414#endif
3415 if (gui.scroll_fg_pixel != INVALCOLOR)
3416 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3417}
3418
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419/*
3420 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3421 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003422 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003423gui_motif_menu_fontlist(Widget id UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003425#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426#ifdef FONTSET_ALWAYS
3427 if (gui.menu_fontset != NOFONTSET)
3428 {
3429 XmFontList fl;
3430
3431 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3432 if (fl != NULL)
3433 {
3434 if (XtIsManaged(id))
3435 {
3436 XtUnmanageChild(id);
3437 XtVaSetValues(id, XmNfontList, fl, NULL);
3438 /* We should force the widget to recalculate it's
3439 * geometry now. */
3440 XtManageChild(id);
3441 }
3442 else
3443 XtVaSetValues(id, XmNfontList, fl, NULL);
3444 XmFontListFree(fl);
3445 }
3446 }
3447#else
3448 if (gui.menu_font != NOFONT)
3449 {
3450 XmFontList fl;
3451
3452 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3453 if (fl != NULL)
3454 {
3455 if (XtIsManaged(id))
3456 {
3457 XtUnmanageChild(id);
3458 XtVaSetValues(id, XmNfontList, fl, NULL);
3459 /* We should force the widget to recalculate it's
3460 * geometry now. */
3461 XtManageChild(id);
3462 }
3463 else
3464 XtVaSetValues(id, XmNfontList, fl, NULL);
3465 XmFontListFree(fl);
3466 }
3467 }
3468#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470}
3471
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472
3473/*
3474 * We don't create it twice for the sake of speed.
3475 */
3476
3477typedef struct _SharedFindReplace
3478{
3479 Widget dialog; /* the main dialog widget */
3480 Widget wword; /* 'Exact match' check button */
3481 Widget mcase; /* 'match case' check button */
3482 Widget up; /* search direction 'Up' radio button */
3483 Widget down; /* search direction 'Down' radio button */
3484 Widget what; /* 'Find what' entry text widget */
3485 Widget with; /* 'Replace with' entry text widget */
3486 Widget find; /* 'Find Next' action button */
3487 Widget replace; /* 'Replace With' action button */
3488 Widget all; /* 'Replace All' action button */
3489 Widget undo; /* 'Undo' action button */
3490
3491 Widget cancel;
3492} SharedFindReplace;
3493
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003494static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3495static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496
Bram Moolenaard25c16e2016-01-29 22:13:30 +01003497static void find_replace_destroy_callback(Widget w, XtPointer client_data, XtPointer call_data);
3498static void find_replace_dismiss_callback(Widget w, XtPointer client_data, XtPointer call_data);
3499static void entry_activate_callback(Widget w, XtPointer client_data, XtPointer call_data);
3500static void find_replace_callback(Widget w, XtPointer client_data, XtPointer call_data);
3501static void find_replace_keypress(Widget w, SharedFindReplace * frdp, XKeyEvent * event);
3502static void find_replace_dialog_create(char_u *entry_text, int do_replace);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003505find_replace_destroy_callback(
3506 Widget w UNUSED,
3507 XtPointer client_data,
3508 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509{
3510 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3511
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003512 if (cd != NULL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003513 /* suppress_dialog_mnemonics(cd->dialog); */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514 cd->dialog = (Widget)0;
3515}
3516
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003518find_replace_dismiss_callback(
3519 Widget w UNUSED,
3520 XtPointer client_data,
3521 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522{
3523 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3524
3525 if (cd != NULL)
3526 XtUnmanageChild(cd->dialog);
3527}
3528
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003530entry_activate_callback(
3531 Widget w UNUSED,
3532 XtPointer client_data,
3533 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534{
3535 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3536}
3537
Bram Moolenaar071d4272004-06-13 20:20:40 +00003538 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003539find_replace_callback(
3540 Widget w UNUSED,
3541 XtPointer client_data,
3542 XtPointer call_data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543{
3544 long_u flags = (long_u)client_data;
3545 char *find_text, *repl_text;
3546 Boolean direction_down = TRUE;
3547 Boolean wword;
3548 Boolean mcase;
3549 SharedFindReplace *sfr;
3550
3551 if (flags == FRD_UNDO)
3552 {
3553 char_u *save_cpo = p_cpo;
3554
3555 /* No need to be Vi compatible here. */
3556 p_cpo = (char_u *)"";
3557 u_undo(1);
3558 p_cpo = save_cpo;
3559 gui_update_screen();
3560 return;
3561 }
3562
3563 /* Get the search/replace strings from the dialog */
3564 if (flags == FRD_FINDNEXT)
3565 {
3566 repl_text = NULL;
3567 sfr = &find_widgets;
3568 }
3569 else
3570 {
3571 repl_text = XmTextFieldGetString(repl_widgets.with);
3572 sfr = &repl_widgets;
3573 }
3574 find_text = XmTextFieldGetString(sfr->what);
3575 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3576 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3577 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3578 if (wword)
3579 flags |= FRD_WHOLE_WORD;
3580 if (mcase)
3581 flags |= FRD_MATCH_CASE;
3582
3583 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3584 direction_down);
3585
3586 if (find_text != NULL)
3587 XtFree(find_text);
3588 if (repl_text != NULL)
3589 XtFree(repl_text);
3590}
3591
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003593find_replace_keypress(
3594 Widget w UNUSED,
3595 SharedFindReplace *frdp,
3596 XKeyEvent *event)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597{
3598 KeySym keysym;
3599
3600 if (frdp == NULL)
3601 return;
3602
3603 keysym = XLookupKeysym(event, 0);
3604
3605 /* the scape key pops the whole dialog down */
3606 if (keysym == XK_Escape)
3607 XtUnmanageChild(frdp->dialog);
3608}
3609
3610 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003611set_label(Widget w, char *label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003612{
3613 XmString str;
3614 char_u *p, *next;
3615 KeySym mnemonic = NUL;
3616
3617 if (!w)
3618 return;
3619
Bram Moolenaar3dbcd0c2013-06-22 13:00:16 +02003620 p = vim_strsave((char_u *)label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003621 if (p == NULL)
3622 return;
3623 for (next = p; *next; ++next)
3624 {
3625 if (*next == DLG_HOTKEY_CHAR)
3626 {
3627 int len = STRLEN(next);
3628
3629 if (len > 0)
3630 {
3631 mch_memmove(next, next + 1, len);
3632 mnemonic = next[0];
3633 }
3634 }
3635 }
3636
3637 str = XmStringCreateSimple((char *)p);
3638 vim_free(p);
3639 if (str)
3640 {
3641 XtVaSetValues(w,
3642 XmNlabelString, str,
3643 XmNmnemonic, mnemonic,
3644 NULL);
3645 XmStringFree(str);
3646 }
3647 gui_motif_menu_fontlist(w);
3648}
3649
3650 static void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01003651find_replace_dialog_create(char_u *arg, int do_replace)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652{
3653 SharedFindReplace *frdp;
3654 Widget separator;
3655 Widget input_form;
3656 Widget button_form;
3657 Widget toggle_form;
3658 Widget frame;
3659 XmString str;
3660 int n;
3661 Arg args[6];
3662 int wword = FALSE;
3663 int mcase = !p_ic;
3664 Dimension width;
3665 Dimension widest;
3666 char_u *entry_text;
3667
3668 frdp = do_replace ? &repl_widgets : &find_widgets;
3669
3670 /* Get the search string to use. */
3671 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3672
3673 /* If the dialog already exists, just raise it. */
3674 if (frdp->dialog)
3675 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003676 gui_motif_synch_fonts();
3677
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 /* If the window is already up, just pop it to the top */
3679 if (XtIsManaged(frdp->dialog))
3680 XMapRaised(XtDisplay(frdp->dialog),
3681 XtWindow(XtParent(frdp->dialog)));
3682 else
3683 XtManageChild(frdp->dialog);
3684 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3685 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3686
3687 if (entry_text != NULL)
3688 XmTextFieldSetString(frdp->what, (char *)entry_text);
3689 vim_free(entry_text);
3690
3691 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3692 return;
3693 }
3694
3695 /* Create a fresh new dialog window */
3696 if (do_replace)
3697 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3698 else
3699 str = XmStringCreateSimple(_("VIM - Search..."));
3700
3701 n = 0;
3702 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3703 XtSetArg(args[n], XmNnoResize, True); n++;
3704 XtSetArg(args[n], XmNdialogTitle, str); n++;
3705
3706 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3707 XmStringFree(str);
3708 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3709 find_replace_destroy_callback, frdp);
3710
3711 button_form = XtVaCreateWidget("buttonForm",
3712 xmFormWidgetClass, frdp->dialog,
3713 XmNrightAttachment, XmATTACH_FORM,
3714 XmNrightOffset, 4,
3715 XmNtopAttachment, XmATTACH_FORM,
3716 XmNtopOffset, 4,
3717 XmNbottomAttachment, XmATTACH_FORM,
3718 XmNbottomOffset, 4,
3719 NULL);
3720
Bram Moolenaar071d4272004-06-13 20:20:40 +00003721 frdp->find = XtVaCreateManagedWidget("findButton",
3722 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 XmNsensitive, True,
3724 XmNtopAttachment, XmATTACH_FORM,
3725 XmNleftAttachment, XmATTACH_FORM,
3726 XmNrightAttachment, XmATTACH_FORM,
3727 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003728 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729
3730 XtAddCallback(frdp->find, XmNactivateCallback,
3731 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003732 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733
3734 if (do_replace)
3735 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3737 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 XmNtopAttachment, XmATTACH_WIDGET,
3739 XmNtopWidget, frdp->find,
3740 XmNleftAttachment, XmATTACH_FORM,
3741 XmNrightAttachment, XmATTACH_FORM,
3742 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003743 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 XtAddCallback(frdp->replace, XmNactivateCallback,
3745 find_replace_callback, (XtPointer)FRD_REPLACE);
3746
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3748 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 XmNtopAttachment, XmATTACH_WIDGET,
3750 XmNtopWidget, frdp->replace,
3751 XmNleftAttachment, XmATTACH_FORM,
3752 XmNrightAttachment, XmATTACH_FORM,
3753 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003754 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 XtAddCallback(frdp->all, XmNactivateCallback,
3756 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3757
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 frdp->undo = XtVaCreateManagedWidget("undoButton",
3759 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 XmNtopAttachment, XmATTACH_WIDGET,
3761 XmNtopWidget, frdp->all,
3762 XmNleftAttachment, XmATTACH_FORM,
3763 XmNrightAttachment, XmATTACH_FORM,
3764 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003765 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 XtAddCallback(frdp->undo, XmNactivateCallback,
3767 find_replace_callback, (XtPointer)FRD_UNDO);
3768 }
3769
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3771 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 XmNleftAttachment, XmATTACH_FORM,
3773 XmNrightAttachment, XmATTACH_FORM,
3774 XmNbottomAttachment, XmATTACH_FORM,
3775 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003776 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 XtAddCallback(frdp->cancel, XmNactivateCallback,
3778 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003779 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780
3781 XtManageChild(button_form);
3782
3783 n = 0;
3784 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3785 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3786 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3787 XtSetArg(args[n], XmNrightOffset, 4); n++;
3788 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3789 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3790 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3791 XtManageChild(separator);
3792
3793 input_form = XtVaCreateWidget("inputForm",
3794 xmFormWidgetClass, frdp->dialog,
3795 XmNleftAttachment, XmATTACH_FORM,
3796 XmNleftOffset, 4,
3797 XmNrightAttachment, XmATTACH_WIDGET,
3798 XmNrightWidget, separator,
3799 XmNrightOffset, 4,
3800 XmNtopAttachment, XmATTACH_FORM,
3801 XmNtopOffset, 4,
3802 NULL);
3803
3804 {
3805 Widget label_what;
3806 Widget label_with = (Widget)0;
3807
3808 str = XmStringCreateSimple(_("Find what:"));
3809 label_what = XtVaCreateManagedWidget("whatLabel",
3810 xmLabelGadgetClass, input_form,
3811 XmNlabelString, str,
3812 XmNleftAttachment, XmATTACH_FORM,
3813 XmNtopAttachment, XmATTACH_FORM,
3814 XmNtopOffset, 4,
3815 NULL);
3816 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003817 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003818
3819 frdp->what = XtVaCreateManagedWidget("whatText",
3820 xmTextFieldWidgetClass, input_form,
3821 XmNtopAttachment, XmATTACH_FORM,
3822 XmNrightAttachment, XmATTACH_FORM,
3823 XmNleftAttachment, XmATTACH_FORM,
3824 NULL);
3825
3826 if (do_replace)
3827 {
3828 frdp->with = XtVaCreateManagedWidget("withText",
3829 xmTextFieldWidgetClass, input_form,
3830 XmNtopAttachment, XmATTACH_WIDGET,
3831 XmNtopWidget, frdp->what,
3832 XmNtopOffset, 4,
3833 XmNleftAttachment, XmATTACH_FORM,
3834 XmNrightAttachment, XmATTACH_FORM,
3835 XmNbottomAttachment, XmATTACH_FORM,
3836 NULL);
3837
3838 XtAddCallback(frdp->with, XmNactivateCallback,
3839 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3840
3841 str = XmStringCreateSimple(_("Replace with:"));
3842 label_with = XtVaCreateManagedWidget("withLabel",
3843 xmLabelGadgetClass, input_form,
3844 XmNlabelString, str,
3845 XmNleftAttachment, XmATTACH_FORM,
3846 XmNtopAttachment, XmATTACH_WIDGET,
3847 XmNtopWidget, frdp->what,
3848 XmNtopOffset, 4,
3849 XmNbottomAttachment, XmATTACH_FORM,
3850 NULL);
3851 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003852 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853
3854 /*
3855 * Make the entry activation only change the input focus onto the
3856 * with item.
3857 */
3858 XtAddCallback(frdp->what, XmNactivateCallback,
3859 entry_activate_callback, frdp->with);
3860 XtAddEventHandler(frdp->with, KeyPressMask, False,
3861 (XtEventHandler)find_replace_keypress,
3862 (XtPointer) frdp);
3863
3864 }
3865 else
3866 {
3867 /*
3868 * Make the entry activation do the search.
3869 */
3870 XtAddCallback(frdp->what, XmNactivateCallback,
3871 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3872 }
3873 XtAddEventHandler(frdp->what, KeyPressMask, False,
3874 (XtEventHandler)find_replace_keypress,
3875 (XtPointer)frdp);
3876
3877 /* Get the maximum width between the label widgets and line them up.
3878 */
3879 n = 0;
3880 XtSetArg(args[n], XmNwidth, &width); n++;
3881 XtGetValues(label_what, args, n);
3882 widest = width;
3883 if (do_replace)
3884 {
3885 XtGetValues(label_with, args, n);
3886 if (width > widest)
3887 widest = width;
3888 }
3889
3890 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3891 if (do_replace)
3892 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3893
3894 }
3895
3896 XtManageChild(input_form);
3897
3898 {
3899 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003900 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901
3902 frame = XtVaCreateWidget("directionFrame",
3903 xmFrameWidgetClass, frdp->dialog,
3904 XmNtopAttachment, XmATTACH_WIDGET,
3905 XmNtopWidget, input_form,
3906 XmNtopOffset, 4,
3907 XmNbottomAttachment, XmATTACH_FORM,
3908 XmNbottomOffset, 4,
3909 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3910 XmNrightWidget, input_form,
3911 NULL);
3912
3913 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003914 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 xmLabelGadgetClass, frame,
3916 XmNlabelString, str,
3917 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3918 XmNchildType, XmFRAME_TITLE_CHILD,
3919 NULL);
3920 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003921 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922
3923 radio_box = XmCreateRadioBox(frame, "radioBox",
3924 (ArgList)NULL, 0);
3925
3926 str = XmStringCreateSimple( _("Up"));
3927 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3928 xmToggleButtonGadgetClass, radio_box,
3929 XmNlabelString, str,
3930 XmNset, False,
3931 NULL);
3932 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003933 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934
3935 str = XmStringCreateSimple(_("Down"));
3936 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3937 xmToggleButtonGadgetClass, radio_box,
3938 XmNlabelString, str,
3939 XmNset, True,
3940 NULL);
3941 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003942 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943
3944 XtManageChild(radio_box);
3945 XtManageChild(frame);
3946 }
3947
3948 toggle_form = XtVaCreateWidget("toggleForm",
3949 xmFormWidgetClass, frdp->dialog,
3950 XmNleftAttachment, XmATTACH_FORM,
3951 XmNleftOffset, 4,
3952 XmNrightAttachment, XmATTACH_WIDGET,
3953 XmNrightWidget, frame,
3954 XmNrightOffset, 4,
3955 XmNtopAttachment, XmATTACH_WIDGET,
3956 XmNtopWidget, input_form,
3957 XmNtopOffset, 4,
3958 XmNbottomAttachment, XmATTACH_FORM,
3959 XmNbottomOffset, 4,
3960 NULL);
3961
3962 str = XmStringCreateSimple(_("Match whole word only"));
3963 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3964 xmToggleButtonGadgetClass, toggle_form,
3965 XmNlabelString, str,
3966 XmNtopAttachment, XmATTACH_FORM,
3967 XmNtopOffset, 4,
3968 XmNleftAttachment, XmATTACH_FORM,
3969 XmNleftOffset, 4,
3970 XmNset, wword,
3971 NULL);
3972 XmStringFree(str);
3973
3974 str = XmStringCreateSimple(_("Match case"));
3975 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3976 xmToggleButtonGadgetClass, toggle_form,
3977 XmNlabelString, str,
3978 XmNleftAttachment, XmATTACH_FORM,
3979 XmNleftOffset, 4,
3980 XmNtopAttachment, XmATTACH_WIDGET,
3981 XmNtopWidget, frdp->wword,
3982 XmNtopOffset, 4,
3983 XmNset, mcase,
3984 NULL);
3985 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003986 gui_motif_menu_fontlist(frdp->wword);
3987 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988
3989 XtManageChild(toggle_form);
3990
3991 if (entry_text != NULL)
3992 XmTextFieldSetString(frdp->what, (char *)entry_text);
3993 vim_free(entry_text);
3994
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003995 gui_motif_synch_fonts();
3996
3997 manage_centered(frdp->dialog);
3998 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
4000}
4001
4002 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01004003gui_mch_find_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004{
4005 if (!gui.in_use)
4006 return;
4007
4008 find_replace_dialog_create(eap->arg, FALSE);
4009}
4010
4011
4012 void
Bram Moolenaar66f948e2016-01-30 16:39:25 +01004013gui_mch_replace_dialog(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014{
4015 if (!gui.in_use)
4016 return;
4017
4018 find_replace_dialog_create(eap->arg, TRUE);
4019}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004020
4021/*
4022 * Synchronize all gui elements, which are dependant upon the
4023 * main text font used. Those are in esp. the find/replace dialogs.
4024 * If you don't understand why this should be needed, please try to
Bram Moolenaar305598b2016-01-30 13:53:36 +01004025 * search for "pi\xea\xb6\xe6" in iso8859-2.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004026 */
4027 void
4028gui_motif_synch_fonts(void)
4029{
4030 SharedFindReplace *frdp;
4031 int do_replace;
4032 XFontStruct *font;
4033 XmFontList font_list;
4034
4035 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4036 * we just give up here on font synchronization. */
4037 font = (XFontStruct *)gui.norm_font;
4038 if (font == NULL)
4039 return;
4040
4041 font_list = gui_motif_create_fontlist(font);
4042
4043 /* OK this loop is a bit tricky... */
4044 for (do_replace = 0; do_replace <= 1; ++do_replace)
4045 {
4046 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4047 if (frdp->dialog)
4048 {
4049 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4050 if (do_replace)
4051 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4052 }
4053 }
4054
4055 XmFontListFree(font_list);
4056}