blob: 1a7e03872cd9e2e96443aecc6bd8f71868c81cf6 [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
86static void scroll_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
Bram Moolenaar910f66f2006-04-05 20:41:53 +000087#ifdef FEAT_GUI_TABLINE
88static void tabline_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
89static void tabline_button_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
90static void tabline_menu_cb __ARGS((Widget w, XtPointer closure, XEvent *e, Boolean *continue_dispatch));
Bram Moolenaarf193fff2006-04-27 00:02:13 +000091static void tabline_balloon_cb __ARGS((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
95static void toolbarbutton_enter_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
96static void toolbarbutton_leave_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
97# endif
Bram Moolenaarf9980f12005-01-03 20:58:59 +000098static void reset_focus __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +000099#endif
100#ifdef FEAT_FOOTER
101static int gui_mch_compute_footer_height __ARGS((void));
102#endif
103#ifdef WSDEBUG
104static void attachDump(Widget, char *);
105#endif
106
107static void gui_motif_menu_colors __ARGS((Widget id));
108static void gui_motif_scroll_colors __ARGS((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
121scroll_cb(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000122 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 XtPointer client_data, call_data;
124{
125 scrollbar_T *sb;
126 long value;
127 int dragging;
128
129 sb = gui_find_scrollbar((long)client_data);
130
131 value = ((XmScrollBarCallbackStruct *)call_data)->value;
132 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
133 (int)XmCR_DRAG);
134 gui_drag_scrollbar(sb, value, dragging);
135}
136
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000137#ifdef FEAT_GUI_TABLINE
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000138 static void
139tabline_cb(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000140 Widget w UNUSED;
141 XtPointer client_data UNUSED;
142 XtPointer call_data;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000143{
144 XmNotebookCallbackStruct *nptr;
145
146 nptr = (XmNotebookCallbackStruct *)call_data;
147 if (nptr->reason != (int)XmCR_NONE)
148 send_tabline_event(nptr->page_number);
149}
150
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000151 static void
152tabline_button_cb(w, client_data, call_data)
153 Widget w;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000154 XtPointer client_data UNUSED;
155 XtPointer call_data UNUSED;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000156{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000157 int cmd, tab_idx;
158
159 XtVaGetValues(w, XmNuserData, &cmd, NULL);
160 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
161
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000162 send_tabline_menu_event(tab_idx, cmd);
163}
164
165/*
166 * Tabline single mouse click timeout handler
167 */
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000168 static void
169motif_tabline_timer_cb (timed_out, interval_id)
170 XtPointer timed_out;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000171 XtIntervalId *interval_id UNUSED;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000172{
173 *((int *)timed_out) = TRUE;
174}
175
176/*
177 * check if the tabline tab scroller is clicked
178 */
179 static int
180tabline_scroller_clicked(scroller_name, event)
181 char *scroller_name;
182 XButtonPressedEvent *event;
183{
184 Widget tab_scroll_w;
185 Position pos_x, pos_y;
186 Dimension width, height;
187
188 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
189 if (tab_scroll_w != (Widget)0) {
190 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
191 &width, XmNheight, &height, NULL);
192 if (pos_x >= 0) {
193 /* Tab scroller (next) is visible */
194 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
195 (event->y >= pos_y) && (event->y <= pos_y + height)) {
196 /* Clicked on the scroller */
197 return TRUE;
198 }
199 }
200 }
201 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000202}
203
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000204 static void
205tabline_menu_cb(w, closure, e, continue_dispatch)
206 Widget w;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000207 XtPointer closure UNUSED;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000208 XEvent *e;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000209 Boolean *continue_dispatch UNUSED;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000210{
211 Widget tab_w;
212 XButtonPressedEvent *event;
213 int tab_idx = 0;
214 WidgetList children;
215 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000216 static XtIntervalId timer = (XtIntervalId)0;
217 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000218
219 event = (XButtonPressedEvent *)e;
220
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000221 if (event->button == Button1)
222 {
223 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
224 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
225 return;
226
227 if (!timed_out)
228 {
229 XtRemoveTimeOut(timer);
230 timed_out = TRUE;
231
232 /*
233 * Double click on the tabline gutter, add a new tab
234 */
235 send_tabline_menu_event(0, TABLINE_MENU_NEW);
236 }
237 else
238 {
239 /*
240 * Single click on the tabline gutter, start a timer to check
241 * for double clicks
242 */
243 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
244 motif_tabline_timer_cb, &timed_out);
245 timed_out = FALSE;
246 }
247 return;
248 }
249
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000250 if (event->button != Button3)
251 return;
252
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000253 /* When ignoring events don't show the menu. */
254 if (hold_gui_events
255# ifdef FEAT_CMDWIN
256 || cmdwin_type != 0
257# endif
258 )
259 return;
260
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000261 if (event->subwindow != None)
262 {
263 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000264 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000265 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
266 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
267 }
268
269 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
270 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
271 &numChildren, NULL);
272 XtManageChildren(children, numChildren);
273 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
274 XtManageChild(tabLine_menu);
275}
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000276
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000277 static void
278tabline_balloon_cb(beval, state)
279 BalloonEval *beval;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000280 int state UNUSED;
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000281{
282 int nr;
283 tabpage_T *tp;
284
285 if (beval->target == (Widget)0)
286 return;
287
288 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
289 tp = find_tabpage(nr);
290 if (tp == NULL)
291 return;
292
293 get_tabline_label(tp, TRUE);
294 gui_mch_post_balloon(beval, NameBuff);
295}
296
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000297#endif
298
Bram Moolenaar071d4272004-06-13 20:20:40 +0000299/*
300 * End of call-back routines
301 */
302
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000303/*
304 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000305 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000306 */
307
308#include <Xm/XmP.h>
309#include <Xm/LabelP.h>
310
311static XtExposeProc old_label_expose = NULL;
312
313static void label_expose __ARGS((Widget _w, XEvent *_event, Region _region));
314
315 static void
316label_expose(_w, _event, _region)
317 Widget _w;
318 XEvent *_event;
319 Region _region;
320{
321 GC insensitiveGC;
322 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000323 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000324
325 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
326
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000327 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000328 (*old_label_expose)(_w, _event, _region);
329 else
330 {
331 XGCValues values;
332 XtGCMask mask;
333 XtGCMask dynamic;
334 XFontStruct *fs;
335
336 _XmFontListGetDefaultFont(lw->label.font, &fs);
337
338 /* FIXME: we should be doing the whole drawing ourself here. */
339 insensitiveGC = lw->label.insensitive_GC;
340
341 mask = GCForeground | GCBackground | GCGraphicsExposures;
342 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
343 values.graphics_exposures = False;
344
345 if (fs != 0)
346 {
347 mask |= GCFont;
348 values.font = fs->fid;
349 }
350
351 if (lw->primitive.top_shadow_pixmap != None
352 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
353 {
354 mask |= GCFillStyle | GCTile;
355 values.fill_style = FillTiled;
356 values.tile = lw->primitive.top_shadow_pixmap;
357 }
358
359 lw->label.TextRect.x += 1;
360 lw->label.TextRect.y += 1;
361 if (lw->label._acc_text != 0)
362 {
363 lw->label.acc_TextRect.x += 1;
364 lw->label.acc_TextRect.y += 1;
365 }
366
367 values.foreground = lw->primitive.top_shadow_color;
368 values.background = lw->core.background_pixel;
369
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000370 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
371 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000372 (*old_label_expose)(_w, _event, _region);
373 XtReleaseGC(_w, lw->label.insensitive_GC);
374
375 lw->label.TextRect.x -= 1;
376 lw->label.TextRect.y -= 1;
377 if (lw->label._acc_text != 0)
378 {
379 lw->label.acc_TextRect.x -= 1;
380 lw->label.acc_TextRect.y -= 1;
381 }
382
383 values.foreground = lw->primitive.bottom_shadow_color;
384 values.background = lw->core.background_pixel;
385
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000386 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
387 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000388 (*old_label_expose)(_w, _event, _region);
389 XtReleaseGC(_w, lw->label.insensitive_GC);
390
391 lw->label.insensitive_GC = insensitiveGC;
392 }
393}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000394
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395/*
396 * Create all the motif widgets necessary.
397 */
398 void
399gui_x11_create_widgets()
400{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000401#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000402 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000403 Arg args[10];
404 int n;
405 XmString xms;
406#endif
407
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000408 /*
409 * Install the 3D shade effect drawing routines.
410 */
411 if (old_label_expose == NULL)
412 {
413 old_label_expose = xmLabelWidgetClass->core_class.expose;
414 xmLabelWidgetClass->core_class.expose = label_expose;
415 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000416
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417 /*
418 * Start out by adding the configured border width into the border offset
419 */
420 gui.border_offset = gui.border_width;
421
422 /*
423 * Install the tearOffModel resource converter.
424 */
425#if (XmVersion >= 1002)
426 XmRepTypeInstallTearOffModelConverter();
427#endif
428
429 /* Make sure the "Quit" menu entry of the window manager is ignored */
430 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
431
432 vimForm = XtVaCreateManagedWidget("vimForm",
433 xmFormWidgetClass, vimShell,
434 XmNborderWidth, 0,
435 XmNhighlightThickness, 0,
436 XmNshadowThickness, 0,
437 XmNmarginWidth, 0,
438 XmNmarginHeight, 0,
439 XmNresizePolicy, XmRESIZE_ANY,
440 NULL);
441 gui_motif_menu_colors(vimForm);
442
443#ifdef FEAT_MENU
444 {
445 Arg al[7]; /* Make sure there is enough room for arguments! */
446 int ac = 0;
447
448# if (XmVersion >= 1002)
449 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
450# endif
451 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
452 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
453 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
454# ifndef FEAT_TOOLBAR
455 /* Always stick to right hand side. */
456 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
457# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000458 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
460 XtManageChild(menuBar);
461
462 /* Remember the default colors, needed for ":hi clear". */
463 XtVaGetValues(menuBar,
464 XmNbackground, &gui.menu_def_bg_pixel,
465 XmNforeground, &gui.menu_def_fg_pixel,
466 NULL);
467 gui_motif_menu_colors(menuBar);
468 }
469#endif
470
471#ifdef FEAT_TOOLBAR
472 /*
473 * Create an empty ToolBar. We should get buttons defined from menu.vim.
474 */
475 toolBarFrame = XtVaCreateWidget("toolBarFrame",
476 xmFrameWidgetClass, vimForm,
477 XmNshadowThickness, 0,
478 XmNmarginHeight, 0,
479 XmNmarginWidth, 0,
480 XmNleftAttachment, XmATTACH_FORM,
481 XmNrightAttachment, XmATTACH_FORM,
482 NULL);
483 gui_motif_menu_colors(toolBarFrame);
484
485 toolBar = XtVaCreateManagedWidget("toolBar",
486 xmRowColumnWidgetClass, toolBarFrame,
487 XmNchildType, XmFRAME_WORKAREA_CHILD,
488 XmNrowColumnType, XmWORK_AREA,
489 XmNorientation, XmHORIZONTAL,
490 XmNtraversalOn, False,
491 XmNisHomogeneous, False,
492 XmNpacking, XmPACK_TIGHT,
493 XmNspacing, 0,
494 XmNshadowThickness, 0,
495 XmNhighlightThickness, 0,
496 XmNmarginHeight, 0,
497 XmNmarginWidth, 0,
498 XmNadjustLast, True,
499 NULL);
500 gui_motif_menu_colors(toolBar);
501
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502#endif
503
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000504#ifdef FEAT_GUI_TABLINE
505 /* Create the Vim GUI tabline */
506 n = 0;
507 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
508 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
509 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
510 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
511 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
512 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
513 XtSetArg(args[n], XmNshadowThickness, 0); n++;
514 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
515 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
516 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
517
518 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
519 NULL);
520 XtAddEventHandler(tabLine, ButtonPressMask, False,
521 (XtEventHandler)tabline_menu_cb, NULL);
522
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000523 gui.tabline_height = TABLINE_HEIGHT;
524
Bram Moolenaar18144c82006-04-12 21:52:12 +0000525 /*
526 * Set the size of the minor next/prev scrollers to zero, so
527 * that they are not displayed. Due to a bug in OpenMotif 2.3,
528 * even if these children widget are unmanaged, they are again
529 * managed by the Notebook widget and the notebook widget geometry
530 * is adjusted to account for the minor scroller widgets.
531 */
532 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
533 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
534 XmNtraversalOn, False, NULL);
535 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
536 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
537 XmNtraversalOn, False, NULL);
538
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000539 /* Create the tabline popup menu */
540 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
541
542 /* Add the buttons to the menu */
543 n = 0;
544 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
545 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
546 XtSetArg(args[n], XmNlabelString, xms); n++;
547 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
548 XtAddCallback(button, XmNactivateCallback,
549 (XtCallbackProc)tabline_button_cb, NULL);
550 XmStringFree(xms);
551
552 n = 0;
553 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
554 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
555 XtSetArg(args[n], XmNlabelString, xms); n++;
556 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
557 XtAddCallback(button, XmNactivateCallback,
558 (XtCallbackProc)tabline_button_cb, NULL);
559 XmStringFree(xms);
560
561 n = 0;
562 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
563 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
564 XtSetArg(args[n], XmNlabelString, xms); n++;
565 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
566 XtAddCallback(button, XmNactivateCallback,
567 (XtCallbackProc)tabline_button_cb, NULL);
568 XmStringFree(xms);
569#endif
570
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
572 xmFormWidgetClass, vimForm,
573 XmNleftAttachment, XmATTACH_FORM,
574 XmNrightAttachment, XmATTACH_FORM,
575 XmNbottomAttachment, XmATTACH_FORM,
576 XmNtopAttachment, XmATTACH_FORM,
577 XmNmarginWidth, 0,
578 XmNmarginHeight, 0,
579 XmNresizePolicy, XmRESIZE_ANY,
580 NULL);
581 gui_motif_scroll_colors(textAreaForm);
582
583 textArea = XtVaCreateManagedWidget("textArea",
584 xmDrawingAreaWidgetClass, textAreaForm,
585 XmNforeground, gui.norm_pixel,
586 XmNbackground, gui.back_pixel,
587 XmNleftAttachment, XmATTACH_FORM,
588 XmNtopAttachment, XmATTACH_FORM,
589 XmNrightAttachment, XmATTACH_FORM,
590 XmNbottomAttachment, XmATTACH_FORM,
591
592 /*
593 * These take some control away from the user, but avoids making them
594 * add resources to get a decent looking setup.
595 */
596 XmNborderWidth, 0,
597 XmNhighlightThickness, 0,
598 XmNshadowThickness, 0,
599 NULL);
600
601#ifdef FEAT_FOOTER
602 /*
603 * Create the Footer.
604 */
605 footer = XtVaCreateWidget("footer",
606 xmLabelGadgetClass, vimForm,
607 XmNalignment, XmALIGNMENT_BEGINNING,
608 XmNmarginHeight, 0,
609 XmNmarginWidth, 0,
610 XmNtraversalOn, False,
611 XmNrecomputeSize, False,
612 XmNleftAttachment, XmATTACH_FORM,
613 XmNleftOffset, 5,
614 XmNrightAttachment, XmATTACH_FORM,
615 XmNbottomAttachment, XmATTACH_FORM,
616 NULL);
617 gui_mch_set_footer((char_u *) "");
618#endif
619
620 /*
621 * Install the callbacks.
622 */
623 gui_x11_callbacks(textArea, vimForm);
624
625 /* Pretend we don't have input focus, we will get an event if we do. */
626 gui.in_focus = FALSE;
627}
628
629/*
630 * Called when the GUI is not going to start after all.
631 */
632 void
633gui_x11_destroy_widgets()
634{
635 textArea = NULL;
636#ifdef FEAT_MENU
637 menuBar = NULL;
638#endif
639}
640
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641 void
642gui_mch_set_text_area_pos(x, y, w, h)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000643 int x UNUSED;
644 int y UNUSED;
645 int w UNUSED;
646 int h UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647{
648#ifdef FEAT_TOOLBAR
649 /* Give keyboard focus to the textArea instead of the toolbar. */
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000650 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651#endif
652}
653
654 void
655gui_x11_set_back_color()
656{
657 if (textArea != NULL)
658#if (XmVersion >= 1002)
659 XmChangeColor(textArea, gui.back_pixel);
660#else
661 XtVaSetValues(textArea,
662 XmNbackground, gui.back_pixel,
663 NULL);
664#endif
665}
666
667/*
668 * Manage dialog centered on pointer. This could be used by the Athena code as
669 * well.
670 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000671 void
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672manage_centered(dialog_child)
673 Widget dialog_child;
674{
675 Widget shell = XtParent(dialog_child);
676 Window root, child;
677 unsigned int mask;
678 unsigned int width, height, border_width, depth;
679 int x, y, win_x, win_y, maxX, maxY;
680 Boolean mappedWhenManaged;
681
682 /* Temporarily set value of XmNmappedWhenManaged
683 to stop the dialog from popping up right away */
Bram Moolenaar46784652008-06-20 09:40:11 +0000684 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
685 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000686
687 XtManageChild(dialog_child);
688
689 /* Get the pointer position (x, y) */
690 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
691 &x, &y, &win_x, &win_y, &mask);
692
693 /* Translate the pointer position (x, y) into a position for the new
694 window that will place the pointer at its center */
695 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
696 &width, &height, &border_width, &depth);
697 width += 2 * border_width;
698 height += 2 * border_width;
699 x -= width / 2;
700 y -= height / 2;
701
702 /* Ensure that the dialog remains on screen */
703 maxX = XtScreen(shell)->width - width;
704 maxY = XtScreen(shell)->height - height;
705 if (x < 0)
706 x = 0;
707 if (x > maxX)
708 x = maxX;
709 if (y < 0)
710 y = 0;
711 if (y > maxY)
712 y = maxY;
713
714 /* Set desired window position in the DialogShell */
715 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
716
717 /* Map the widget */
718 XtMapWidget(shell);
719
720 /* Restore the value of XmNmappedWhenManaged */
Bram Moolenaar46784652008-06-20 09:40:11 +0000721 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722}
723
724#if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
725 || defined(FEAT_GUI_DIALOG) || defined(PROTO)
726
727/*
728 * Encapsulate the way an XmFontList is created.
729 */
730 XmFontList
731gui_motif_create_fontlist(font)
732 XFontStruct *font;
733{
734 XmFontList font_list;
735
736# if (XmVersion <= 1001)
737 /* Motif 1.1 method */
738 font_list = XmFontListCreate(font, STRING_TAG);
739# else
740 /* Motif 1.2 method */
741 XmFontListEntry font_list_entry;
742
743 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
744 (XtPointer)font);
745 font_list = XmFontListAppendEntry(NULL, font_list_entry);
746 XmFontListEntryFree(&font_list_entry);
747# endif
748 return font_list;
749}
750
751# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
752 XmFontList
753gui_motif_fontset2fontlist(fontset)
754 XFontSet *fontset;
755{
756 XmFontList font_list;
757
758 /* Motif 1.2 method */
759 XmFontListEntry font_list_entry;
760
761 font_list_entry = XmFontListEntryCreate(STRING_TAG,
762 XmFONT_IS_FONTSET,
763 (XtPointer)*fontset);
764 font_list = XmFontListAppendEntry(NULL, font_list_entry);
765 XmFontListEntryFree(&font_list_entry);
766 return font_list;
767}
768# endif
769
770#endif
771
772#if defined(FEAT_MENU) || defined(PROTO)
773/*
774 * Menu stuff.
775 */
776
777static void gui_motif_add_actext __ARGS((vimmenu_T *menu));
778#if (XmVersion >= 1002)
779static void toggle_tearoff __ARGS((Widget wid));
780static void gui_mch_recurse_tearoffs __ARGS((vimmenu_T *menu));
781#endif
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000782static void submenu_change __ARGS((vimmenu_T *mp, int colors));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783
784static void do_set_mnemonics __ARGS((int enable));
785static int menu_enabled = TRUE;
786
787 void
788gui_mch_enable_menu(flag)
789 int flag;
790{
791 if (flag)
792 {
793 XtManageChild(menuBar);
794#ifdef FEAT_TOOLBAR
795 if (XtIsManaged(XtParent(toolBar)))
796 {
797 /* toolBar is attached to top form */
798 XtVaSetValues(XtParent(toolBar),
799 XmNtopAttachment, XmATTACH_WIDGET,
800 XmNtopWidget, menuBar,
801 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000802#ifdef FEAT_GUI_TABLINE
803 if (showing_tabline)
804 {
805 XtVaSetValues(tabLine,
806 XmNtopAttachment, XmATTACH_WIDGET,
807 XmNtopWidget, XtParent(toolBar),
808 NULL);
809 XtVaSetValues(textAreaForm,
810 XmNtopAttachment, XmATTACH_WIDGET,
811 XmNtopWidget, tabLine,
812 NULL);
813 }
814 else
815#endif
816 XtVaSetValues(textAreaForm,
817 XmNtopAttachment, XmATTACH_WIDGET,
818 XmNtopWidget, XtParent(toolBar),
819 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820 }
821 else
822#endif
823 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000824#ifdef FEAT_GUI_TABLINE
825 if (showing_tabline)
826 {
827 XtVaSetValues(tabLine,
828 XmNtopAttachment, XmATTACH_WIDGET,
829 XmNtopWidget, menuBar,
830 NULL);
831 XtVaSetValues(textAreaForm,
832 XmNtopAttachment, XmATTACH_WIDGET,
833 XmNtopWidget, tabLine,
834 NULL);
835 }
836 else
837#endif
838 XtVaSetValues(textAreaForm,
839 XmNtopAttachment, XmATTACH_WIDGET,
840 XmNtopWidget, menuBar,
841 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842 }
843 }
844 else
845 {
846 XtUnmanageChild(menuBar);
847#ifdef FEAT_TOOLBAR
848 if (XtIsManaged(XtParent(toolBar)))
849 {
850 XtVaSetValues(XtParent(toolBar),
851 XmNtopAttachment, XmATTACH_FORM,
852 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000853#ifdef FEAT_GUI_TABLINE
854 if (showing_tabline)
855 {
856 XtVaSetValues(tabLine,
857 XmNtopAttachment, XmATTACH_WIDGET,
858 XmNtopWidget, XtParent(toolBar),
859 NULL);
860 XtVaSetValues(textAreaForm,
861 XmNtopAttachment, XmATTACH_WIDGET,
862 XmNtopWidget, tabLine,
863 NULL);
864 }
865 else
866#endif
867 XtVaSetValues(textAreaForm,
868 XmNtopAttachment, XmATTACH_WIDGET,
869 XmNtopWidget, XtParent(toolBar),
870 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000871 }
872 else
873#endif
874 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000875#ifdef FEAT_GUI_TABLINE
876 if (showing_tabline)
877 {
878 XtVaSetValues(tabLine,
879 XmNtopAttachment, XmATTACH_FORM,
880 NULL);
881 XtVaSetValues(textAreaForm,
882 XmNtopAttachment, XmATTACH_WIDGET,
883 XmNtopWidget, tabLine,
884 NULL);
885 }
886 else
887#endif
888 XtVaSetValues(textAreaForm,
889 XmNtopAttachment, XmATTACH_FORM,
890 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 }
892 }
893
894}
895
896/*
897 * Enable or disable mnemonics for the toplevel menus.
898 */
899 void
900gui_motif_set_mnemonics(enable)
901 int enable;
902{
903 /*
904 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
905 * crashes when using a mnemonic then.
906 */
907 if (!menu_enabled)
908 enable = FALSE;
909 do_set_mnemonics(enable);
910}
911
912 static void
913do_set_mnemonics(enable)
914 int enable;
915{
916 vimmenu_T *menu;
917
918 for (menu = root_menu; menu != NULL; menu = menu->next)
919 if (menu->id != (Widget)0)
920 XtVaSetValues(menu->id,
921 XmNmnemonic, enable ? menu->mnemonic : NUL,
922 NULL);
923}
924
925 void
926gui_mch_add_menu(menu, idx)
927 vimmenu_T *menu;
928 int idx;
929{
930 XmString label;
931 Widget shell;
932 vimmenu_T *parent = menu->parent;
933
934#ifdef MOTIF_POPUP
935 if (menu_is_popup(menu->name))
936 {
937 Arg arg[2];
938 int n = 0;
939
940 /* Only create the popup menu when it's actually used, otherwise there
941 * is a delay when using the right mouse button. */
942# if (XmVersion <= 1002)
943 if (mouse_model_popup())
944# endif
945 {
946 if (gui.menu_bg_pixel != INVALCOLOR)
947 {
948 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
949 }
950 if (gui.menu_fg_pixel != INVALCOLOR)
951 {
952 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
953 }
954 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
955 arg, n);
956 menu->id = (Widget)0;
957 }
958 return;
959 }
960#endif
961
962 if (!menu_is_menubar(menu->name)
963 || (parent != NULL && parent->submenu_id == (Widget)0))
964 return;
965
966 label = XmStringCreate((char *)menu->dname, STRING_TAG);
967 if (label == NULL)
968 return;
969 menu->id = XtVaCreateWidget("subMenu",
970 xmCascadeButtonWidgetClass,
971 (parent == NULL) ? menuBar : parent->submenu_id,
972 XmNlabelString, label,
973 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
974#if (XmVersion >= 1002)
975 /* submenu: count the tearoff item (needed for LessTif) */
976 XmNpositionIndex, idx + (parent != NULL
977 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
978#endif
979 NULL);
980 gui_motif_menu_colors(menu->id);
981 gui_motif_menu_fontlist(menu->id);
982 XmStringFree(label);
983
984 if (menu->id == (Widget)0) /* failed */
985 return;
986
987 /* add accelerator text */
988 gui_motif_add_actext(menu);
989
990 shell = XtVaCreateWidget("subMenuShell",
991 xmMenuShellWidgetClass, menu->id,
992 XmNwidth, 1,
993 XmNheight, 1,
994 NULL);
995 gui_motif_menu_colors(shell);
996 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
997 xmRowColumnWidgetClass, shell,
998 XmNrowColumnType, XmMENU_PULLDOWN,
999 NULL);
1000 gui_motif_menu_colors(menu->submenu_id);
1001
1002 if (menu->submenu_id == (Widget)0) /* failed */
1003 return;
1004
1005#if (XmVersion >= 1002)
1006 /* Set the colors for the tear off widget */
1007 toggle_tearoff(menu->submenu_id);
1008#endif
1009
1010 XtVaSetValues(menu->id,
1011 XmNsubMenuId, menu->submenu_id,
1012 NULL);
1013
1014 /*
1015 * The "Help" menu is a special case, and should be placed at the far
1016 * right hand side of the menu-bar. It's recognized by its high priority.
1017 */
1018 if (parent == NULL && menu->priority >= 9999)
1019 XtVaSetValues(menuBar,
1020 XmNmenuHelpWidget, menu->id,
1021 NULL);
1022
1023 /*
1024 * When we add a top-level item to the menu bar, we can figure out how
1025 * high the menu bar should be.
1026 */
1027 if (parent == NULL)
1028 gui_mch_compute_menu_height(menu->id);
1029}
1030
1031
1032/*
1033 * Add mnemonic and accelerator text to a menu button.
1034 */
1035 static void
1036gui_motif_add_actext(menu)
1037 vimmenu_T *menu;
1038{
1039 XmString label;
1040
Bram Moolenaar933eb392007-05-10 17:52:45 +00001041 /* Add accelerator text, if there is one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 if (menu->actext != NULL && menu->id != (Widget)0)
1043 {
1044 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1045 if (label == NULL)
1046 return;
1047 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1048 XmStringFree(label);
1049 }
1050}
1051
1052 void
1053gui_mch_toggle_tearoffs(enable)
1054 int enable;
1055{
1056#if (XmVersion >= 1002)
1057 if (enable)
1058 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1059 else
1060 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1061 toggle_tearoff(menuBar);
1062 gui_mch_recurse_tearoffs(root_menu);
1063#endif
1064}
1065
1066#if (XmVersion >= 1002)
1067/*
1068 * Set the tearoff for one menu widget on or off, and set the color of the
1069 * tearoff widget.
1070 */
1071 static void
1072toggle_tearoff(wid)
1073 Widget wid;
1074{
1075 Widget w;
1076
1077 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1078 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1079 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1080 gui_motif_menu_colors(w);
1081}
1082
1083 static void
1084gui_mch_recurse_tearoffs(menu)
1085 vimmenu_T *menu;
1086{
1087 while (menu != NULL)
1088 {
1089 if (!menu_is_popup(menu->name))
1090 {
1091 if (menu->submenu_id != (Widget)0)
1092 toggle_tearoff(menu->submenu_id);
1093 gui_mch_recurse_tearoffs(menu->children);
1094 }
1095 menu = menu->next;
1096 }
1097}
1098#endif
1099
1100 int
1101gui_mch_text_area_extra_height()
1102{
1103 Dimension shadowHeight;
1104
1105 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1106 return shadowHeight;
1107}
1108
1109/*
1110 * Compute the height of the menu bar.
1111 * We need to check all the items for their position and height, for the case
1112 * there are several rows, and/or some characters extend higher or lower.
1113 */
1114 void
1115gui_mch_compute_menu_height(id)
1116 Widget id; /* can be NULL when deleting menu */
1117{
1118 Dimension y, maxy;
1119 Dimension margin, shadow;
1120 vimmenu_T *mp;
1121 static Dimension height = 21; /* normal height of a menu item */
1122
1123 /*
1124 * Get the height of the new item, before managing it, because it will
1125 * still reflect the font size. After managing it depends on the menu
1126 * height, which is what we just wanted to get!.
1127 */
1128 if (id != (Widget)0)
1129 XtVaGetValues(id, XmNheight, &height, NULL);
1130
1131 /* Find any menu Widget, to be able to call XtManageChild() */
1132 else
1133 for (mp = root_menu; mp != NULL; mp = mp->next)
1134 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1135 {
1136 id = mp->id;
1137 break;
1138 }
1139
1140 /*
1141 * Now manage the menu item, to make them all be positioned (makes an
1142 * extra row when needed, removes it when not needed).
1143 */
1144 if (id != (Widget)0)
1145 XtManageChild(id);
1146
1147 /*
1148 * Now find the menu item that is the furthest down, and get it's position.
1149 */
1150 maxy = 0;
1151 for (mp = root_menu; mp != NULL; mp = mp->next)
1152 {
1153 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1154 {
1155 XtVaGetValues(mp->id, XmNy, &y, NULL);
1156 if (y > maxy)
1157 maxy = y;
1158 }
1159 }
1160
1161 XtVaGetValues(menuBar,
1162 XmNmarginHeight, &margin,
1163 XmNshadowThickness, &shadow,
1164 NULL);
1165
1166 /*
1167 * This computation is the result of trial-and-error:
1168 * maxy = The maximum position of an item; required for when there are
1169 * two or more rows
1170 * height = height of an item, before managing it; Hopefully this will
1171 * change with the font height. Includes shadow-border.
1172 * shadow = shadow-border; must be subtracted from the height.
1173 * margin = margin around the menu buttons; Must be added.
1174 * Add 4 for the underlining of shortcut keys.
1175 */
1176 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1177
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 /* Somehow the menu bar doesn't resize automatically. Set it here,
1179 * even though this is a catch 22. Don't do this when starting up,
1180 * somehow the menu gets very high then. */
1181 if (gui.shell_created)
1182 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001183}
1184
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001185#ifdef FEAT_TOOLBAR
1186
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001187/*
1188 * Icons used by the toolbar code.
1189 */
1190#include "gui_x11_pm.h"
1191
1192static int check_xpm __ARGS((char_u *path));
Bram Moolenaar7c626922005-02-07 22:01:03 +00001193static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu, char **fname));
1194static int add_pixmap_args __ARGS((vimmenu_T *menu, Arg *args, int n));
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001195
1196/*
1197 * Read an Xpm file. Return OK or FAIL.
1198 */
1199 static int
1200check_xpm(path)
1201 char_u *path;
1202{
1203 XpmAttributes attrs;
1204 int status;
1205 Pixmap mask;
1206 Pixmap map;
1207
1208 attrs.valuemask = 0;
1209
1210 /* Create the "sensitive" pixmap */
1211 status = XpmReadFileToPixmap(gui.dpy,
1212 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1213 (char *)path, &map, &mask, &attrs);
1214 XpmFreeAttributes(&attrs);
1215
1216 if (status == XpmSuccess)
1217 return OK;
1218 return FAIL;
1219}
1220
1221
1222/*
1223 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001224 * When it's to be read from a file, "fname" is set to the file name
1225 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001226 * Return a blank pixmap if it fails.
1227 */
1228 static char **
Bram Moolenaar7c626922005-02-07 22:01:03 +00001229get_toolbar_pixmap(menu, fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001230 vimmenu_T *menu;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001231 char **fname;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001232{
1233 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1234 char **xpm = NULL; /* xpm array */
1235 int res;
1236
Bram Moolenaar7c626922005-02-07 22:01:03 +00001237 *fname = NULL;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001238 buf[0] = NUL; /* start with NULL path */
1239
1240 if (menu->iconfile != NULL)
1241 {
1242 /* Use the "icon=" argument. */
1243 gui_find_iconfile(menu->iconfile, buf, "xpm");
1244 res = check_xpm(buf);
1245
1246 /* If it failed, try using the menu name. */
1247 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1248 res = check_xpm(buf);
1249 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001250 {
1251 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001252 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001253 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001254 }
1255
1256 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1257 {
1258 if (menu->iconidx >= 0 && menu->iconidx
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001259 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001260 xpm = built_in_pixmaps[menu->iconidx];
1261 else
1262 xpm = tb_blank_xpm;
1263 }
1264
1265 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001267
1268/*
1269 * Add arguments for the toolbar pixmap to a menu item.
1270 */
1271 static int
1272add_pixmap_args(menu, args, n)
1273 vimmenu_T *menu;
1274 Arg *args;
1275 int n;
1276{
1277 vim_free(menu->xpm_fname);
1278 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1279 if (menu->xpm == NULL)
1280 {
1281 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1282 }
1283 else
1284 {
1285 if (menu->xpm_fname != NULL)
1286 {
1287 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
1288 }
1289 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1290 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1291 }
1292 return n;
1293}
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001294#endif /* FEAT_TOOLBAR */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295
1296 void
1297gui_mch_add_menu_item(menu, idx)
1298 vimmenu_T *menu;
1299 int idx;
1300{
1301 XmString label;
1302 vimmenu_T *parent = menu->parent;
1303
1304# ifdef EBCDIC
1305 menu->mnemonic = 0;
1306# endif
1307
1308# if (XmVersion <= 1002)
1309 /* Don't add Popup menu items when the popup menu isn't used. */
1310 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1311 return;
1312# endif
1313
1314# ifdef FEAT_TOOLBAR
1315 if (menu_is_toolbar(parent->name))
1316 {
1317 WidgetClass type;
1318 XmString xms = NULL; /* fallback label if pixmap not found */
1319 int n;
1320 Arg args[18];
1321
1322 n = 0;
1323 if (menu_is_separator(menu->name))
1324 {
1325 char *cp;
1326 Dimension wid;
1327
1328 /*
1329 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1330 * a width specifier. If no width is specified then we choose one.
1331 */
1332 cp = (char *)vim_strchr(menu->name, ':');
1333 if (cp != NULL)
1334 wid = (Dimension)atoi(++cp);
1335 else
1336 wid = 4;
1337
1338#if 0
1339 /* We better use a FormWidget here, since it's far more
1340 * flexible in terms of size. */
1341 type = xmFormWidgetClass;
1342 XtSetArg(args[n], XmNwidth, wid); n++;
1343#else
1344 type = xmSeparatorWidgetClass;
1345 XtSetArg(args[n], XmNwidth, wid); n++;
1346 XtSetArg(args[n], XmNminWidth, wid); n++;
1347 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001348 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349#endif
1350 }
1351 else
1352 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 /* Without shadows one can't sense whatever the button has been
1354 * pressed or not! However we wan't to save a bit of space...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001355 * Need the highlightThickness to see the focus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001357 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1359 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1360 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001361 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001362 /* Set the label here, so that we can switch between icons/text
1363 * by changing the XmNlabelType resource. */
1364 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1365 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001366
Bram Moolenaar7c626922005-02-07 22:01:03 +00001367 n = add_pixmap_args(menu, args, n);
1368
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001369 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 }
1371
1372 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1373 if (menu->id == NULL)
1374 {
1375 menu->id = XtCreateManagedWidget((char *)menu->dname,
1376 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001377 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 {
1379 XtAddCallback(menu->id,
1380 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381# ifdef FEAT_FOOTER
1382 XtAddEventHandler(menu->id, EnterWindowMask, False,
1383 toolbarbutton_enter_cb, menu);
1384 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1385 toolbarbutton_leave_cb, menu);
1386# endif
1387 }
1388 }
1389 else
1390 XtSetValues(menu->id, args, n);
1391 if (xms != NULL)
1392 XmStringFree(xms);
1393
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001394# ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 gui_mch_menu_set_tip(menu);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00001396# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397
1398 menu->parent = parent;
1399 menu->submenu_id = NULL;
1400 /* When adding first item to toolbar it might have to be enabled .*/
1401 if (!XtIsManaged(XtParent(toolBar))
1402 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1403 gui_mch_show_toolbar(TRUE);
1404 gui.toolbar_height = gui_mch_compute_toolbar_height();
1405 return;
1406 } /* toolbar menu item */
1407# endif
1408
1409 /* No parent, must be a non-menubar menu */
1410 if (parent->submenu_id == (Widget)0)
1411 return;
1412
1413 menu->submenu_id = (Widget)0;
1414
1415 /* Add menu separator */
1416 if (menu_is_separator(menu->name))
1417 {
1418 menu->id = XtVaCreateWidget("subMenu",
1419 xmSeparatorGadgetClass, parent->submenu_id,
1420#if (XmVersion >= 1002)
1421 /* count the tearoff item (needed for LessTif) */
1422 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1423 ? 1 : 0),
1424#endif
1425 NULL);
1426 gui_motif_menu_colors(menu->id);
1427 return;
1428 }
1429
1430 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1431 if (label == NULL)
1432 return;
1433 menu->id = XtVaCreateWidget("subMenu",
1434 xmPushButtonWidgetClass, parent->submenu_id,
1435 XmNlabelString, label,
1436 XmNmnemonic, menu->mnemonic,
1437#if (XmVersion >= 1002)
1438 /* count the tearoff item (needed for LessTif) */
1439 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1440 ? 1 : 0),
1441#endif
1442 NULL);
1443 gui_motif_menu_colors(menu->id);
1444 gui_motif_menu_fontlist(menu->id);
1445 XmStringFree(label);
1446
1447 if (menu->id != (Widget)0)
1448 {
1449 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1450 (XtPointer)menu);
1451 /* add accelerator text */
1452 gui_motif_add_actext(menu);
1453 }
1454}
1455
1456#if (XmVersion <= 1002) || defined(PROTO)
1457/*
1458 * This function will destroy/create the popup menus dynamically,
1459 * according to the value of 'mousemodel'.
1460 * This will fix the "right mouse button freeze" that occurs when
1461 * there exists a popup menu but it isn't managed.
1462 */
1463 void
1464gui_motif_update_mousemodel(menu)
1465 vimmenu_T *menu;
1466{
1467 int idx = 0;
1468
1469 /* When GUI hasn't started the menus have not been created. */
1470 if (!gui.in_use)
1471 return;
1472
1473 while (menu)
1474 {
1475 if (menu->children != NULL)
1476 {
1477 if (menu_is_popup(menu->name))
1478 {
1479 if (mouse_model_popup())
1480 {
1481 /* Popup menu will be used. Create the popup menus. */
1482 gui_mch_add_menu(menu, idx);
1483 gui_motif_update_mousemodel(menu->children);
1484 }
1485 else
1486 {
1487 /* Popup menu will not be used. Destroy the popup menus. */
1488 gui_motif_update_mousemodel(menu->children);
1489 gui_mch_destroy_menu(menu);
1490 }
1491 }
1492 }
1493 else if (menu_is_child_of_popup(menu))
1494 {
1495 if (mouse_model_popup())
1496 gui_mch_add_menu_item(menu, idx);
1497 else
1498 gui_mch_destroy_menu(menu);
1499 }
1500 menu = menu->next;
1501 ++idx;
1502 }
1503}
1504#endif
1505
1506 void
1507gui_mch_new_menu_colors()
1508{
1509 if (menuBar == (Widget)0)
1510 return;
1511 gui_motif_menu_colors(menuBar);
1512#ifdef FEAT_TOOLBAR
1513 gui_motif_menu_colors(toolBarFrame);
1514 gui_motif_menu_colors(toolBar);
1515#endif
1516
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001517 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518}
1519
1520 void
1521gui_mch_new_menu_font()
1522{
1523 if (menuBar == (Widget)0)
1524 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001525 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {
1527 Dimension height;
1528 Position w, h;
1529
1530 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1531 gui.menu_height = height;
1532
1533 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1534 gui_resize_shell(w, h
1535#ifdef FEAT_XIM
1536 - xim_get_status_area_height()
1537#endif
1538 );
1539 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001540 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 ui_new_shellsize();
1542}
1543
1544#if defined(FEAT_BEVAL) || defined(PROTO)
1545 void
1546gui_mch_new_tooltip_font()
1547{
1548# ifdef FEAT_TOOLBAR
1549 vimmenu_T *menu;
1550
1551 if (toolBar == (Widget)0)
1552 return;
1553
1554 menu = gui_find_menu((char_u *)"ToolBar");
1555 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001556 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557# endif
1558}
1559
1560 void
1561gui_mch_new_tooltip_colors()
1562{
1563# ifdef FEAT_TOOLBAR
1564 vimmenu_T *toolbar;
1565
1566 if (toolBar == (Widget)0)
1567 return;
1568
1569 toolbar = gui_find_menu((char_u *)"ToolBar");
1570 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001571 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572# endif
1573}
1574#endif
1575
1576 static void
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001577submenu_change(menu, colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 vimmenu_T *menu;
1579 int colors; /* TRUE for colors, FALSE for font */
1580{
1581 vimmenu_T *mp;
1582
1583 for (mp = menu; mp != NULL; mp = mp->next)
1584 {
1585 if (mp->id != (Widget)0)
1586 {
1587 if (colors)
1588 {
1589 gui_motif_menu_colors(mp->id);
1590#ifdef FEAT_TOOLBAR
1591 /* For a toolbar item: Free the pixmap and allocate a new one,
1592 * so that the background color is right. */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001593 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001595 int n = 0;
1596 Arg args[18];
1597
Bram Moolenaar7c626922005-02-07 22:01:03 +00001598 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001599 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 }
1601# ifdef FEAT_BEVAL
1602 /* If we have a tooltip, then we need to change it's font */
1603 if (mp->tip != NULL)
1604 {
1605 Arg args[2];
1606
1607 args[0].name = XmNbackground;
1608 args[0].value = gui.tooltip_bg_pixel;
1609 args[1].name = XmNforeground;
1610 args[1].value = gui.tooltip_fg_pixel;
1611 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1612 }
1613# endif
1614#endif
1615 }
1616 else
1617 {
1618 gui_motif_menu_fontlist(mp->id);
1619#ifdef FEAT_BEVAL
1620 /* If we have a tooltip, then we need to change it's font */
1621 if (mp->tip != NULL)
1622 {
1623 Arg args[1];
1624
1625 args[0].name = XmNfontList;
1626 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1627 &gui.tooltip_fontset);
1628 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1629 }
1630#endif
1631 }
1632 }
1633
1634 if (mp->children != NULL)
1635 {
1636#if (XmVersion >= 1002)
1637 /* Set the colors/font for the tear off widget */
1638 if (mp->submenu_id != (Widget)0)
1639 {
1640 if (colors)
1641 gui_motif_menu_colors(mp->submenu_id);
1642 else
1643 gui_motif_menu_fontlist(mp->submenu_id);
1644 toggle_tearoff(mp->submenu_id);
1645 }
1646#endif
1647 /* Set the colors for the children */
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001648 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 }
1650 }
1651}
1652
1653/*
1654 * Destroy the machine specific menu widget.
1655 */
1656 void
1657gui_mch_destroy_menu(menu)
1658 vimmenu_T *menu;
1659{
1660 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1661 * On the other hand, problems have been reported that the submenu must be
1662 * deleted first...
1663 *
1664 * This code should be basically identical to that in the file gui_athena.c
1665 * because they are both Xt based.
1666 */
1667 if (menu->submenu_id != (Widget)0)
1668 {
1669 XtDestroyWidget(menu->submenu_id);
1670 menu->submenu_id = (Widget)0;
1671 }
1672
1673 if (menu->id != (Widget)0)
1674 {
1675 Widget parent;
1676
1677 parent = XtParent(menu->id);
1678#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001679 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 {
1681 /* We try to destroy this before the actual menu, because there are
1682 * callbacks, etc. that will be unregistered during the tooltip
1683 * destruction.
1684 *
1685 * If you call "gui_mch_destroy_beval_area()" after destroying
1686 * menu->id, then the tooltip's window will have already been
1687 * deallocated by Xt, and unknown behaviour will ensue (probably
1688 * a core dump).
1689 */
1690 gui_mch_destroy_beval_area(menu->tip);
1691 menu->tip = NULL;
1692 }
1693#endif
1694 XtDestroyWidget(menu->id);
1695 menu->id = (Widget)0;
1696 if (parent == menuBar)
1697 gui_mch_compute_menu_height((Widget)0);
1698#ifdef FEAT_TOOLBAR
1699 else if (parent == toolBar)
1700 {
1701 Cardinal num_children;
1702
1703 /* When removing last toolbar item, don't display the toolbar. */
1704 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1705 if (num_children == 0)
1706 gui_mch_show_toolbar(FALSE);
1707 else
1708 gui.toolbar_height = gui_mch_compute_toolbar_height();
1709 }
1710#endif
1711 }
1712}
1713
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 void
1715gui_mch_show_popupmenu(menu)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00001716 vimmenu_T *menu UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717{
1718#ifdef MOTIF_POPUP
1719 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1720 XtManageChild(menu->submenu_id);
1721#endif
1722}
1723
1724#endif /* FEAT_MENU */
1725
1726/*
1727 * Set the menu and scrollbar colors to their default values.
1728 */
1729 void
1730gui_mch_def_colors()
1731{
1732 if (gui.in_use)
1733 {
1734 /* Use the values saved when starting up. These should come from the
1735 * window manager or a resources file. */
1736 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1737 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1738 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1739 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
1740#ifdef FEAT_BEVAL
1741 gui.tooltip_fg_pixel =
1742 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1743 gui.tooltip_bg_pixel =
1744 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1745#endif
1746 }
1747}
1748
1749
1750/*
1751 * Scrollbar stuff.
1752 */
1753
1754 void
1755gui_mch_set_scrollbar_thumb(sb, val, size, max)
1756 scrollbar_T *sb;
1757 long val;
1758 long size;
1759 long max;
1760{
1761 if (sb->id != (Widget)0)
1762 XtVaSetValues(sb->id,
1763 XmNvalue, val,
1764 XmNsliderSize, size,
1765 XmNpageIncrement, (size > 2 ? size - 2 : 1),
1766 XmNmaximum, max + 1, /* Motif has max one past the end */
1767 NULL);
1768}
1769
1770 void
1771gui_mch_set_scrollbar_pos(sb, x, y, w, h)
1772 scrollbar_T *sb;
1773 int x;
1774 int y;
1775 int w;
1776 int h;
1777{
1778 if (sb->id != (Widget)0)
1779 {
1780 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1781 {
1782 if (y == 0)
1783 h -= gui.border_offset;
1784 else
1785 y -= gui.border_offset;
1786 XtVaSetValues(sb->id,
1787 XmNtopOffset, y,
1788 XmNbottomOffset, -y - h,
1789 XmNwidth, w,
1790 NULL);
1791 }
1792 else
1793 XtVaSetValues(sb->id,
1794 XmNtopOffset, y,
1795 XmNleftOffset, x,
1796 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1797 ? gui.scrollbar_width : 0,
1798 XmNheight, h,
1799 NULL);
1800 XtManageChild(sb->id);
1801 }
1802}
1803
1804 void
1805gui_mch_enable_scrollbar(sb, flag)
1806 scrollbar_T *sb;
1807 int flag;
1808{
1809 Arg args[16];
1810 int n;
1811
1812 if (sb->id != (Widget)0)
1813 {
1814 n = 0;
1815 if (flag)
1816 {
1817 switch (sb->type)
1818 {
1819 case SBAR_LEFT:
1820 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1821 break;
1822
1823 case SBAR_RIGHT:
1824 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1825 break;
1826
1827 case SBAR_BOTTOM:
1828 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1829 break;
1830 }
1831 XtSetValues(textArea, args, n);
1832 XtManageChild(sb->id);
1833 }
1834 else
1835 {
1836 if (!gui.which_scrollbars[sb->type])
1837 {
1838 /* The scrollbars of this type are all disabled, adjust the
1839 * textArea attachment offset. */
1840 switch (sb->type)
1841 {
1842 case SBAR_LEFT:
1843 XtSetArg(args[n], XmNleftOffset, 0); n++;
1844 break;
1845
1846 case SBAR_RIGHT:
1847 XtSetArg(args[n], XmNrightOffset, 0); n++;
1848 break;
1849
1850 case SBAR_BOTTOM:
1851 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1852 break;
1853 }
1854 XtSetValues(textArea, args, n);
1855 }
1856 XtUnmanageChild(sb->id);
1857 }
1858 }
1859}
1860
1861 void
1862gui_mch_create_scrollbar(sb, orient)
1863 scrollbar_T *sb;
1864 int orient; /* SBAR_VERT or SBAR_HORIZ */
1865{
1866 Arg args[16];
1867 int n;
1868
1869 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 XtSetArg(args[n], XmNminimum, 0); n++;
1871 XtSetArg(args[n], XmNorientation,
1872 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1873
1874 switch (sb->type)
1875 {
1876 case SBAR_LEFT:
1877 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1878 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1879 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1880 break;
1881
1882 case SBAR_RIGHT:
1883 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1884 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1885 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1886 break;
1887
1888 case SBAR_BOTTOM:
1889 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1890 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1891 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1892 break;
1893 }
1894
1895 sb->id = XtCreateWidget("scrollBar",
1896 xmScrollBarWidgetClass, textAreaForm, args, n);
1897
1898 /* Remember the default colors, needed for ":hi clear". */
1899 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1900 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1901 XtVaGetValues(sb->id,
1902 XmNbackground, &gui.scroll_def_bg_pixel,
1903 XmNforeground, &gui.scroll_def_fg_pixel,
1904 NULL);
1905
1906 if (sb->id != (Widget)0)
1907 {
1908 gui_mch_set_scrollbar_colors(sb);
1909 XtAddCallback(sb->id, XmNvalueChangedCallback,
1910 scroll_cb, (XtPointer)sb->ident);
1911 XtAddCallback(sb->id, XmNdragCallback,
1912 scroll_cb, (XtPointer)sb->ident);
1913 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1914 (XtPointer)0);
1915 }
1916}
1917
1918#if defined(FEAT_WINDOWS) || defined(PROTO)
1919 void
1920gui_mch_destroy_scrollbar(sb)
1921 scrollbar_T *sb;
1922{
1923 if (sb->id != (Widget)0)
1924 XtDestroyWidget(sb->id);
1925}
1926#endif
1927
1928 void
1929gui_mch_set_scrollbar_colors(sb)
1930 scrollbar_T *sb;
1931{
1932 if (sb->id != (Widget)0)
1933 {
1934 if (gui.scroll_bg_pixel != INVALCOLOR)
1935 {
1936#if (XmVersion>=1002)
1937 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1938#else
1939 XtVaSetValues(sb->id,
1940 XmNtroughColor, gui.scroll_bg_pixel,
1941 NULL);
1942#endif
1943 }
1944
1945 if (gui.scroll_fg_pixel != INVALCOLOR)
1946 XtVaSetValues(sb->id,
1947 XmNforeground, gui.scroll_fg_pixel,
1948#if (XmVersion<1002)
1949 XmNbackground, gui.scroll_fg_pixel,
1950#endif
1951 NULL);
1952 }
1953
1954 /* This is needed for the rectangle below the vertical scrollbars. */
1955 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1956 gui_motif_scroll_colors(textAreaForm);
1957}
1958
1959/*
1960 * Miscellaneous stuff:
1961 */
1962
1963 Window
1964gui_x11_get_wid()
1965{
1966 return(XtWindow(textArea));
1967}
1968
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001969/*
1970 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1971 * When one is found, simulate a button press on that widget and give it the
1972 * keyboard focus. If the mnemonic is on a label, look in the userData field
1973 * of the label to see if it points to another widget, and give that the focus.
1974 */
1975 static void
1976do_mnemonic(Widget w, unsigned int keycode)
1977{
1978 WidgetList children;
1979 int numChildren, i;
1980 Boolean isMenu;
1981 KeySym mnemonic = '\0';
1982 char mneString[2];
1983 Widget userData;
1984 unsigned char rowColType;
1985
1986 if (XtIsComposite(w))
1987 {
1988 if (XtClass(w) == xmRowColumnWidgetClass)
1989 {
Bram Moolenaar46784652008-06-20 09:40:11 +00001990 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001991 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1992 }
1993 else
1994 isMenu = False;
1995 if (!isMenu)
1996 {
1997 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00001998 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001999 for (i = 0; i < numChildren; i++)
2000 do_mnemonic(children[i], keycode);
2001 }
2002 }
2003 else
2004 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002005 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002006 if (mnemonic != '\0')
2007 {
2008 mneString[0] = mnemonic;
2009 mneString[1] = '\0';
2010 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
2011 XStringToKeysym(mneString)) == keycode)
2012 {
2013 if (XtClass(w) == xmLabelWidgetClass
2014 || XtClass(w) == xmLabelGadgetClass)
2015 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002016 XtVaGetValues(w, XmNuserData, &userData, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002017 if (userData != NULL && XtIsWidget(userData))
2018 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
2019 }
2020 else
2021 {
2022 XKeyPressedEvent keyEvent;
2023
2024 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
2025
2026 memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
2027 keyEvent.type = KeyPress;
2028 keyEvent.serial = 1;
2029 keyEvent.send_event = True;
2030 keyEvent.display = XtDisplay(w);
2031 keyEvent.window = XtWindow(w);
2032 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
2033 NULL, 0);
2034 }
2035 }
2036 }
2037 }
2038}
2039
2040/*
2041 * Callback routine for dialog mnemonic processing.
2042 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002043 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002044mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002045{
2046 do_mnemonic(w, event->keycode);
2047}
2048
2049
2050/*
2051 * Search the widget tree under w for widgets with mnemonics. When found, add
2052 * a passive grab to the dialog widget for the mnemonic character, thus
2053 * directing mnemonic events to the dialog widget.
2054 */
2055 static void
2056add_mnemonic_grabs(Widget dialog, Widget w)
2057{
2058 char mneString[2];
2059 WidgetList children;
2060 int numChildren, i;
2061 Boolean isMenu;
2062 KeySym mnemonic = '\0';
2063 unsigned char rowColType;
2064
2065 if (XtIsComposite(w))
2066 {
2067 if (XtClass(w) == xmRowColumnWidgetClass)
2068 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002069 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002070 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2071 }
2072 else
2073 isMenu = False;
2074 if (!isMenu)
2075 {
2076 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
Bram Moolenaar46784652008-06-20 09:40:11 +00002077 &numChildren, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002078 for (i = 0; i < numChildren; i++)
2079 add_mnemonic_grabs(dialog, children[i]);
2080 }
2081 }
2082 else
2083 {
Bram Moolenaar46784652008-06-20 09:40:11 +00002084 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002085 if (mnemonic != '\0')
2086 {
2087 mneString[0] = mnemonic;
2088 mneString[1] = '\0';
2089 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2090 XStringToKeysym(mneString)),
2091 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2092 }
2093 }
2094}
2095
2096/*
2097 * Add a handler for mnemonics in a dialog. Motif itself only handles
2098 * mnemonics in menus. Mnemonics added or changed after this call will be
2099 * ignored.
2100 *
2101 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2102 * the appropriate label and set the XmNuserData resource of the label to the
2103 * widget to get the focus when the mnemonic is typed.
2104 */
2105 static void
2106activate_dialog_mnemonics(Widget dialog)
2107{
2108 if (!dialog)
2109 return;
2110
2111 XtAddEventHandler(dialog, KeyPressMask, False,
2112 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2113 add_mnemonic_grabs(dialog, dialog);
2114}
2115
2116/*
2117 * Removes the event handler and key-grabs for dialog mnemonic handling.
2118 */
2119 static void
2120suppress_dialog_mnemonics(Widget dialog)
2121{
2122 if (!dialog)
2123 return;
2124
2125 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2126 XtRemoveEventHandler(dialog, KeyPressMask, False,
2127 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2128}
2129
2130#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
2131static void set_fontlist __ARGS((Widget wg));
2132
2133/*
2134 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2135 */
2136 static void
2137set_fontlist(id)
2138 Widget id;
2139{
2140 XmFontList fl;
2141
2142#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002143 if (gui.fontset != NOFONTSET)
2144 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002145 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2146 if (fl != NULL)
2147 {
2148 if (XtIsManaged(id))
2149 {
2150 XtUnmanageChild(id);
2151 XtVaSetValues(id, XmNfontList, fl, NULL);
2152 /* We should force the widget to recalculate it's
2153 * geometry now. */
2154 XtManageChild(id);
2155 }
2156 else
2157 XtVaSetValues(id, XmNfontList, fl, NULL);
2158 XmFontListFree(fl);
2159 }
2160 }
2161#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002162 if (gui.norm_font != NOFONT)
2163 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002164 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2165 if (fl != NULL)
2166 {
2167 if (XtIsManaged(id))
2168 {
2169 XtUnmanageChild(id);
2170 XtVaSetValues(id, XmNfontList, fl, NULL);
2171 /* We should force the widget to recalculate it's
2172 * geometry now. */
2173 XtManageChild(id);
2174 }
2175 else
2176 XtVaSetValues(id, XmNfontList, fl, NULL);
2177 XmFontListFree(fl);
2178 }
2179 }
2180#endif
2181}
2182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183
2184#if defined(FEAT_BROWSE) || defined(PROTO)
2185
2186/*
2187 * file selector related stuff
2188 */
2189
2190#include <Xm/FileSB.h>
2191#include <Xm/XmStrDefs.h>
2192
2193typedef struct dialog_callback_arg
2194{
2195 char * args; /* not used right now */
2196 int id;
2197} dcbarg_T;
2198
2199static Widget dialog_wgt;
2200static char *browse_fname = NULL;
2201static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2202 /* used to set up XmStrings */
2203
2204static void DialogCancelCB __ARGS((Widget, XtPointer, XtPointer));
2205static void DialogAcceptCB __ARGS((Widget, XtPointer, XtPointer));
2206
2207/*
2208 * This function is used to translate the predefined label text of the
2209 * precomposed dialogs. We do this explicitly to allow:
2210 *
2211 * - usage of gettext for translation, as in all the other places.
2212 *
2213 * - equalize the messages between different GUI implementations as far as
2214 * possible.
2215 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002216static void set_predefined_label __ARGS((Widget parent, String name, char *new_label));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217
2218static void
2219set_predefined_label(parent, name, new_label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002220 Widget parent;
2221 String name;
2222 char *new_label;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002224 XmString str;
2225 Widget w;
2226 char_u *p, *next;
2227 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228
2229 w = XtNameToWidget(parent, name);
2230
2231 if (!w)
2232 return;
2233
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002234 p = vim_strsave((char_u *)new_label);
2235 if (p == NULL)
2236 return;
2237 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002239 if (*next == DLG_HOTKEY_CHAR)
2240 {
2241 int len = STRLEN(next);
2242
2243 if (len > 0)
2244 {
2245 mch_memmove(next, next + 1, len);
2246 mnemonic = next[0];
2247 }
2248 }
2249 }
2250
2251 str = XmStringCreate((char *)p, STRING_TAG);
2252 vim_free(p);
2253
2254 if (str != NULL)
2255 {
2256 XtVaSetValues(w,
2257 XmNlabelString, str,
2258 XmNmnemonic, mnemonic,
2259 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 XmStringFree(str);
2261 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002262 gui_motif_menu_fontlist(w);
2263}
2264
2265static void
2266set_predefined_fontlist(parent, name)
2267 Widget parent;
2268 String name;
2269{
2270 Widget w;
2271 w = XtNameToWidget(parent, name);
2272
2273 if (!w)
2274 return;
2275
2276 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277}
2278
2279/*
2280 * Put up a file requester.
2281 * Returns the selected name in allocated memory, or NULL for Cancel.
2282 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 char_u *
2284gui_mch_browse(saving, title, dflt, ext, initdir, filter)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002285 int saving UNUSED; /* select file to write */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 char_u *title; /* title for the window */
2287 char_u *dflt; /* default name */
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002288 char_u *ext UNUSED; /* not used (extension added) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 char_u *initdir; /* initial directory, NULL for current dir */
2290 char_u *filter; /* file name filter */
2291{
2292 char_u dirbuf[MAXPATHL];
2293 char_u dfltbuf[MAXPATHL];
2294 char_u *pattern;
2295 char_u *tofree = NULL;
2296
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002297 /* There a difference between the resource name and value, Therefore, we
2298 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2299 * dialog name.
2300 */
2301
2302 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303
2304 if (initdir == NULL || *initdir == NUL)
2305 {
2306 mch_dirname(dirbuf, MAXPATHL);
2307 initdir = dirbuf;
2308 }
2309
2310 if (dflt == NULL)
2311 dflt = (char_u *)"";
2312 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2313 {
2314 /* The default selection should be the full path, "dflt" is only the
2315 * file name. */
2316 STRCPY(dfltbuf, initdir);
2317 add_pathsep(dfltbuf);
2318 STRCAT(dfltbuf, dflt);
2319 dflt = dfltbuf;
2320 }
2321
2322 /* Can only use one pattern for a file name. Get the first pattern out of
2323 * the filter. An empty pattern means everything matches. */
2324 if (filter == NULL)
2325 pattern = (char_u *)"";
2326 else
2327 {
2328 char_u *s, *p;
2329
2330 s = filter;
2331 for (p = filter; *p != NUL; ++p)
2332 {
2333 if (*p == '\t') /* end of description, start of pattern */
2334 s = p + 1;
2335 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2336 break;
2337 }
2338 pattern = vim_strnsave(s, p - s);
2339 tofree = pattern;
2340 if (pattern == NULL)
2341 pattern = (char_u *)"";
2342 }
2343
2344 XtVaSetValues(dialog_wgt,
2345 XtVaTypedArg,
2346 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2347 XtVaTypedArg,
2348 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2349 XtVaTypedArg,
2350 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2351 XtVaTypedArg,
2352 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2353 NULL);
2354
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002355 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2356 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2358 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002359 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002361 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2363
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002364 /* This is to save us from silly external settings using not fixed with
2365 * fonts for file selection.
2366 */
2367 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2368 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2369
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 gui_motif_menu_colors(dialog_wgt);
2371 if (gui.scroll_bg_pixel != INVALCOLOR)
2372 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2373
2374 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2375 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2376 /* We have no help in this window, so hide help button */
2377 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2378 (unsigned char)XmDIALOG_HELP_BUTTON));
2379
2380 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002381 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382
2383 /* sit in a loop until the dialog box has gone away */
2384 do
2385 {
2386 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2387 (XtInputMask)XtIMAll);
2388 } while (XtIsManaged(dialog_wgt));
2389
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002390 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 XtDestroyWidget(dialog_wgt);
2392 vim_free(tofree);
2393
2394 if (browse_fname == NULL)
2395 return NULL;
2396 return vim_strsave((char_u *)browse_fname);
2397}
2398
2399/*
2400 * The code below was originally taken from
2401 * /usr/examples/motif/xmsamplers/xmeditor.c
2402 * on Digital Unix 4.0d, but heavily modified.
2403 */
2404
2405/*
2406 * Process callback from Dialog cancel actions.
2407 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 static void
2409DialogCancelCB(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002410 Widget w UNUSED; /* widget id */
2411 XtPointer client_data UNUSED; /* data from application */
2412 XtPointer call_data UNUSED; /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413{
2414 if (browse_fname != NULL)
2415 {
2416 XtFree(browse_fname);
2417 browse_fname = NULL;
2418 }
2419 XtUnmanageChild(dialog_wgt);
2420}
2421
2422/*
2423 * Process callback from Dialog actions.
2424 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 static void
2426DialogAcceptCB(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002427 Widget w UNUSED; /* widget id */
2428 XtPointer client_data UNUSED; /* data from application */
2429 XtPointer call_data; /* data from widget class */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430{
2431 XmFileSelectionBoxCallbackStruct *fcb;
2432
2433 if (browse_fname != NULL)
2434 {
2435 XtFree(browse_fname);
2436 browse_fname = NULL;
2437 }
2438 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2439
2440 /* get the filename from the file selection box */
2441 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2442
2443 /* popdown the file selection box */
2444 XtUnmanageChild(dialog_wgt);
2445}
2446
2447#endif /* FEAT_BROWSE */
2448
2449#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2450
2451static int dialogStatus;
2452
2453static void keyhit_callback __ARGS((Widget w, XtPointer client_data, XEvent *event, Boolean *cont));
2454static void butproc __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
2455
2456/*
2457 * Callback function for the textfield. When CR is hit this works like
2458 * hitting the "OK" button, ESC like "Cancel".
2459 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 static void
2461keyhit_callback(w, client_data, event, cont)
2462 Widget w;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002463 XtPointer client_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 XEvent *event;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002465 Boolean *cont UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466{
2467 char buf[2];
2468 KeySym key_sym;
2469
2470 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2471 {
2472 if (*buf == CAR)
2473 dialogStatus = 1;
2474 else if (*buf == ESC)
2475 dialogStatus = 2;
2476 }
2477 if ((key_sym == XK_Left || key_sym == XK_Right)
2478 && !(event->xkey.state & ShiftMask))
2479 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2480}
2481
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 static void
2483butproc(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002484 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002486 XtPointer call_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487{
2488 dialogStatus = (int)(long)client_data + 1;
2489}
2490
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491#ifdef HAVE_XPM
2492
2493static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg);
2494
2495 static Widget
2496create_pixmap_label(parent, name, data, args, arg)
2497 Widget parent;
2498 String name;
2499 char **data;
2500 ArgList args;
2501 Cardinal arg;
2502{
2503 Widget label;
2504 Display *dsp;
2505 Screen *scr;
2506 int depth;
2507 Pixmap pixmap = 0;
2508 XpmAttributes attr;
2509 Boolean rs;
2510 XpmColorSymbol color[5] =
2511 {
2512 {"none", NULL, 0},
2513 {"iconColor1", NULL, 0},
2514 {"bottomShadowColor", NULL, 0},
2515 {"topShadowColor", NULL, 0},
2516 {"selectColor", NULL, 0}
2517 };
2518
2519 label = XmCreateLabelGadget(parent, name, args, arg);
2520
2521 /*
Bram Moolenaar933eb392007-05-10 17:52:45 +00002522 * We need to be careful here, since in case of gadgets, there is
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 * no way to get the background color directly from the widget itself.
2524 * In such cases we get it from The Core part of his parent instead.
2525 */
2526 dsp = XtDisplayOfObject(label);
2527 scr = XtScreenOfObject(label);
2528 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2529 ? label : XtParent(label),
2530 XmNdepth, &depth,
2531 XmNbackground, &color[0].pixel,
2532 XmNforeground, &color[1].pixel,
2533 XmNbottomShadowColor, &color[2].pixel,
2534 XmNtopShadowColor, &color[3].pixel,
2535 XmNhighlight, &color[4].pixel,
2536 NULL);
2537
2538 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2539 attr.colorsymbols = color;
2540 attr.numsymbols = 5;
2541 attr.closeness = 65535;
2542 attr.depth = depth;
2543 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2544 data, &pixmap, NULL, &attr);
2545
2546 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2547 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2548 XtVaSetValues(label,
2549 XmNlabelType, XmPIXMAP,
2550 XmNlabelPixmap, pixmap,
2551 NULL);
2552 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2553
2554 return label;
2555}
2556#endif
2557
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 int
2559gui_mch_dialog(type, title, message, button_names, dfltbutton, textfield)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00002560 int type UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 char_u *title;
2562 char_u *message;
2563 char_u *button_names;
2564 int dfltbutton;
2565 char_u *textfield; /* buffer of size IOSIZE */
2566{
2567 char_u *buts;
2568 char_u *p, *next;
2569 XtAppContext app;
2570 XmString label;
2571 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002572 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 Widget dialogform = NULL;
2574 Widget form = NULL;
2575 Widget dialogtextfield = NULL;
2576 Widget *buttons;
2577 Widget sep_form = NULL;
2578 Boolean vertical;
2579 Widget separator = NULL;
2580 int n;
2581 Arg args[6];
2582#ifdef HAVE_XPM
2583 char **icon_data = NULL;
2584 Widget dialogpixmap = NULL;
2585#endif
2586
2587 if (title == NULL)
2588 title = (char_u *)_("Vim dialog");
2589
2590 /* if our pointer is currently hidden, then we should show it. */
2591 gui_mch_mousehide(FALSE);
2592
2593 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2594
2595 /* Check 'v' flag in 'guioptions': vertical button placement. */
2596 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2597
2598 /* Set the title of the Dialog window */
2599 label = XmStringCreateSimple((char *)title);
2600 if (label == NULL)
2601 return -1;
2602 XtVaSetValues(dialogform,
2603 XmNdialogTitle, label,
2604 XmNhorizontalSpacing, 4,
2605 XmNverticalSpacing, vertical ? 0 : 4,
2606 NULL);
2607 XmStringFree(label);
2608
2609 /* make a copy, so that we can insert NULs */
2610 buts = vim_strsave(button_names);
2611 if (buts == NULL)
2612 return -1;
2613
2614 /* Count the number of buttons and allocate buttons[]. */
2615 butcount = 1;
2616 for (p = buts; *p; ++p)
2617 if (*p == DLG_BUTTON_SEP)
2618 ++butcount;
2619 buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
2620 if (buttons == NULL)
2621 {
2622 vim_free(buts);
2623 return -1;
2624 }
2625
2626 /*
2627 * Create the buttons.
2628 */
2629 sep_form = (Widget) 0;
2630 p = buts;
2631 for (butcount = 0; *p; ++butcount)
2632 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002633 KeySym mnemonic = NUL;
2634
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 for (next = p; *next; ++next)
2636 {
2637 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002638 {
2639 int len = STRLEN(next);
2640
2641 if (len > 0)
2642 {
2643 mch_memmove(next, next + 1, len);
2644 mnemonic = next[0];
2645 }
2646 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 if (*next == DLG_BUTTON_SEP)
2648 {
2649 *next++ = NUL;
2650 break;
2651 }
2652 }
2653 label = XmStringCreate(_((char *)p), STRING_TAG);
2654 if (label == NULL)
2655 break;
2656
2657 buttons[butcount] = XtVaCreateManagedWidget("button",
2658 xmPushButtonWidgetClass, dialogform,
2659 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002660 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 XmNbottomAttachment, XmATTACH_FORM,
2662 XmNbottomOffset, 4,
2663 XmNshowAsDefault, butcount == dfltbutton - 1,
2664 XmNdefaultButtonShadowThickness, 1,
2665 NULL);
2666 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002667 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668
2669 /* Layout properly. */
2670
2671 if (butcount > 0)
2672 {
2673 if (vertical)
2674 XtVaSetValues(buttons[butcount],
2675 XmNtopWidget, buttons[butcount - 1],
2676 NULL);
2677 else
2678 {
2679 if (*next == NUL)
2680 {
2681 XtVaSetValues(buttons[butcount],
2682 XmNrightAttachment, XmATTACH_FORM,
2683 XmNrightOffset, 4,
2684 NULL);
2685
2686 /* fill in a form as invisible separator */
2687 sep_form = XtVaCreateWidget("separatorForm",
2688 xmFormWidgetClass, dialogform,
2689 XmNleftAttachment, XmATTACH_WIDGET,
2690 XmNleftWidget, buttons[butcount - 1],
2691 XmNrightAttachment, XmATTACH_WIDGET,
2692 XmNrightWidget, buttons[butcount],
2693 XmNbottomAttachment, XmATTACH_FORM,
2694 XmNbottomOffset, 4,
2695 NULL);
2696 XtManageChild(sep_form);
2697 }
2698 else
2699 {
2700 XtVaSetValues(buttons[butcount],
2701 XmNleftAttachment, XmATTACH_WIDGET,
2702 XmNleftWidget, buttons[butcount - 1],
2703 NULL);
2704 }
2705 }
2706 }
2707 else if (!vertical)
2708 {
2709 if (*next == NUL)
2710 {
2711 XtVaSetValues(buttons[0],
2712 XmNrightAttachment, XmATTACH_FORM,
2713 XmNrightOffset, 4,
2714 NULL);
2715
2716 /* fill in a form as invisible separator */
2717 sep_form = XtVaCreateWidget("separatorForm",
2718 xmFormWidgetClass, dialogform,
2719 XmNleftAttachment, XmATTACH_FORM,
2720 XmNleftOffset, 4,
2721 XmNrightAttachment, XmATTACH_WIDGET,
2722 XmNrightWidget, buttons[0],
2723 XmNbottomAttachment, XmATTACH_FORM,
2724 XmNbottomOffset, 4,
2725 NULL);
2726 XtManageChild(sep_form);
2727 }
2728 else
2729 XtVaSetValues(buttons[0],
2730 XmNleftAttachment, XmATTACH_FORM,
2731 XmNleftOffset, 4,
2732 NULL);
2733 }
2734
2735 XtAddCallback(buttons[butcount], XmNactivateCallback,
2736 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2737 p = next;
2738 }
2739 vim_free(buts);
2740
2741 separator = (Widget) 0;
2742 if (butcount > 0)
2743 {
2744 /* Create the separator for beauty. */
2745 n = 0;
2746 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2747 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2748 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2749 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2750 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2751 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2752 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2753 XtManageChild(separator);
2754 }
2755
2756 if (textfield != NULL)
2757 {
2758 dialogtextfield = XtVaCreateWidget("textField",
2759 xmTextFieldWidgetClass, dialogform,
2760 XmNleftAttachment, XmATTACH_FORM,
2761 XmNrightAttachment, XmATTACH_FORM,
2762 NULL);
2763 if (butcount > 0)
2764 XtVaSetValues(dialogtextfield,
2765 XmNbottomAttachment, XmATTACH_WIDGET,
2766 XmNbottomWidget, separator,
2767 NULL);
2768 else
2769 XtVaSetValues(dialogtextfield,
2770 XmNbottomAttachment, XmATTACH_FORM,
2771 NULL);
2772
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002773 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2775 XtManageChild(dialogtextfield);
2776 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2777 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2778 }
2779
2780 /* Form holding both message and pixmap labels */
2781 form = XtVaCreateWidget("separatorForm",
2782 xmFormWidgetClass, dialogform,
2783 XmNleftAttachment, XmATTACH_FORM,
2784 XmNrightAttachment, XmATTACH_FORM,
2785 XmNtopAttachment, XmATTACH_FORM,
2786 NULL);
2787 XtManageChild(form);
2788
2789#ifdef HAVE_XPM
2790 /* Add a pixmap, left of the message. */
2791 switch (type)
2792 {
2793 case VIM_GENERIC:
2794 icon_data = generic_xpm;
2795 break;
2796 case VIM_ERROR:
2797 icon_data = error_xpm;
2798 break;
2799 case VIM_WARNING:
2800 icon_data = alert_xpm;
2801 break;
2802 case VIM_INFO:
2803 icon_data = info_xpm;
2804 break;
2805 case VIM_QUESTION:
2806 icon_data = quest_xpm;
2807 break;
2808 default:
2809 icon_data = generic_xpm;
2810 }
2811
2812 n = 0;
2813 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2814 XtSetArg(args[n], XmNtopOffset, 8); n++;
2815 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2816 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2817 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2818 XtSetArg(args[n], XmNleftOffset, 8); n++;
2819
2820 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2821 icon_data, args, n);
2822 XtManageChild(dialogpixmap);
2823#endif
2824
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002825 /* Create the dialog message.
2826 * Since LessTif is apparently having problems with the creation of
2827 * properly localized string, we use LtoR here. The symptom is that the
2828 * string sill not show properly in multiple lines as it does in native
2829 * Motif.
2830 */
2831 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 if (label == NULL)
2833 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002834 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 xmLabelGadgetClass, form,
2836 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002837 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 XmNtopAttachment, XmATTACH_FORM,
2839 XmNtopOffset, 8,
2840#ifdef HAVE_XPM
2841 XmNleftAttachment, XmATTACH_WIDGET,
2842 XmNleftWidget, dialogpixmap,
2843#else
2844 XmNleftAttachment, XmATTACH_FORM,
2845#endif
2846 XmNleftOffset, 8,
2847 XmNrightAttachment, XmATTACH_FORM,
2848 XmNrightOffset, 8,
2849 XmNbottomAttachment, XmATTACH_FORM,
2850 XmNbottomOffset, 8,
2851 NULL);
2852 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002853 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854
2855 if (textfield != NULL)
2856 {
2857 XtVaSetValues(form,
2858 XmNbottomAttachment, XmATTACH_WIDGET,
2859 XmNbottomWidget, dialogtextfield,
2860 NULL);
2861 }
2862 else
2863 {
2864 if (butcount > 0)
2865 XtVaSetValues(form,
2866 XmNbottomAttachment, XmATTACH_WIDGET,
2867 XmNbottomWidget, separator,
2868 NULL);
2869 else
2870 XtVaSetValues(form,
2871 XmNbottomAttachment, XmATTACH_FORM,
2872 NULL);
2873 }
2874
2875 if (dfltbutton < 1)
2876 dfltbutton = 1;
2877 if (dfltbutton > butcount)
2878 dfltbutton = butcount;
2879 XtVaSetValues(dialogform,
2880 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2881 if (textfield != NULL)
2882 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2883 else
2884 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2885 NULL);
2886
2887 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002888 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889
2890 if (textfield != NULL && *textfield != NUL)
2891 {
2892 /* This only works after the textfield has been realised. */
2893 XmTextFieldSetSelection(dialogtextfield,
2894 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2895 XtLastTimestampProcessed(gui.dpy));
2896 XmTextFieldSetCursorPosition(dialogtextfield,
2897 (XmTextPosition)STRLEN(textfield));
2898 }
2899
2900 app = XtWidgetToApplicationContext(dialogform);
2901
2902 /* Loop until a button is pressed or the dialog is killed somehow. */
2903 dialogStatus = -1;
2904 for (;;)
2905 {
2906 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2907 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2908 break;
2909 }
2910
2911 vim_free(buttons);
2912
2913 if (textfield != NULL)
2914 {
2915 p = (char_u *)XmTextGetString(dialogtextfield);
2916 if (p == NULL || dialogStatus < 0)
2917 *textfield = NUL;
2918 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002919 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar103e6ef2010-05-13 16:31:25 +02002920 XtFree((char *)p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 }
2922
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002923 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 XtDestroyWidget(dialogform);
2925
2926 return dialogStatus;
2927}
2928#endif /* FEAT_GUI_DIALOG */
2929
2930#if defined(FEAT_FOOTER) || defined(PROTO)
2931
2932 static int
2933gui_mch_compute_footer_height()
2934{
2935 Dimension height; /* total Toolbar height */
2936 Dimension top; /* XmNmarginTop */
2937 Dimension bottom; /* XmNmarginBottom */
2938 Dimension shadow; /* XmNshadowThickness */
2939
2940 XtVaGetValues(footer,
2941 XmNheight, &height,
2942 XmNmarginTop, &top,
2943 XmNmarginBottom, &bottom,
2944 XmNshadowThickness, &shadow,
2945 NULL);
2946
2947 return (int) height + top + bottom + (shadow << 1);
2948}
2949
2950#if 0 /* not used */
2951 void
2952gui_mch_set_footer_pos(h)
2953 int h; /* textArea height */
2954{
2955 XtVaSetValues(footer,
2956 XmNtopOffset, h + 7,
2957 NULL);
2958}
2959#endif
2960
2961 void
2962gui_mch_enable_footer(showit)
2963 int showit;
2964{
2965 if (showit)
2966 {
2967 gui.footer_height = gui_mch_compute_footer_height();
2968 XtManageChild(footer);
2969 }
2970 else
2971 {
2972 gui.footer_height = 0;
2973 XtUnmanageChild(footer);
2974 }
2975 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2976}
2977
2978 void
2979gui_mch_set_footer(s)
2980 char_u *s;
2981{
2982 XmString xms;
2983
2984 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002985 if (xms != NULL)
2986 {
2987 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2988 XmStringFree(xms);
2989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990}
2991
2992#endif
2993
2994
2995#if defined(FEAT_TOOLBAR) || defined(PROTO)
2996 void
2997gui_mch_show_toolbar(int showit)
2998{
2999 Cardinal numChildren; /* how many children toolBar has */
3000
3001 if (toolBar == (Widget)0)
3002 return;
3003 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
3004 if (showit && numChildren > 0)
3005 {
3006 /* Assume that we want to show the toolbar if p_toolbar contains
3007 * valid option settings, therefore p_toolbar must not be NULL.
3008 */
3009 WidgetList children;
3010
3011 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
3012 {
3013 void (*action)(BalloonEval *);
3014 int text = 0;
3015
3016 if (strstr((const char *)p_toolbar, "tooltips"))
3017 action = &gui_mch_enable_beval_area;
3018 else
3019 action = &gui_mch_disable_beval_area;
3020 if (strstr((const char *)p_toolbar, "text"))
3021 text = 1;
3022 else if (strstr((const char *)p_toolbar, "icons"))
3023 text = -1;
3024 if (text != 0)
3025 {
3026 vimmenu_T *toolbar;
3027 vimmenu_T *cur;
3028
3029 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
3030 if (menu_is_toolbar(toolbar->dname))
3031 break;
3032 /* Assumption: toolbar is NULL if there is no toolbar,
3033 * otherwise it contains the toolbar menu structure.
3034 *
3035 * Assumption: "numChildren" == the number of items in the list
3036 * of items beginning with toolbar->children.
3037 */
3038 if (toolbar)
3039 {
3040 for (cur = toolbar->children; cur; cur = cur->next)
3041 {
3042 Arg args[1];
3043 int n = 0;
3044
3045 /* Enable/Disable tooltip (OK to enable while
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003046 * currently enabled). */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 if (cur->tip != NULL)
3048 (*action)(cur->tip);
3049 if (!menu_is_separator(cur->name))
3050 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003051 if (text == 1 || cur->xpm == NULL)
3052 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003054 ++n;
3055 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 if (cur->id != NULL)
3057 {
3058 XtUnmanageChild(cur->id);
3059 XtSetValues(cur->id, args, n);
3060 XtManageChild(cur->id);
3061 }
3062 }
3063 }
3064 }
3065 }
3066 }
3067 gui.toolbar_height = gui_mch_compute_toolbar_height();
3068 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003069#ifdef FEAT_GUI_TABLINE
3070 if (showing_tabline)
3071 {
3072 XtVaSetValues(tabLine,
3073 XmNtopAttachment, XmATTACH_WIDGET,
3074 XmNtopWidget, XtParent(toolBar),
3075 NULL);
3076 XtVaSetValues(textAreaForm,
3077 XmNtopAttachment, XmATTACH_WIDGET,
3078 XmNtopWidget, tabLine,
3079 NULL);
3080 }
3081 else
3082#endif
3083 XtVaSetValues(textAreaForm,
3084 XmNtopAttachment, XmATTACH_WIDGET,
3085 XmNtopWidget, XtParent(toolBar),
3086 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 if (XtIsManaged(menuBar))
3088 XtVaSetValues(XtParent(toolBar),
3089 XmNtopAttachment, XmATTACH_WIDGET,
3090 XmNtopWidget, menuBar,
3091 NULL);
3092 else
3093 XtVaSetValues(XtParent(toolBar),
3094 XmNtopAttachment, XmATTACH_FORM,
3095 NULL);
3096 }
3097 else
3098 {
3099 gui.toolbar_height = 0;
3100 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003101 {
3102#ifdef FEAT_GUI_TABLINE
3103 if (showing_tabline)
3104 {
3105 XtVaSetValues(tabLine,
3106 XmNtopAttachment, XmATTACH_WIDGET,
3107 XmNtopWidget, menuBar,
3108 NULL);
3109 XtVaSetValues(textAreaForm,
3110 XmNtopAttachment, XmATTACH_WIDGET,
3111 XmNtopWidget, tabLine,
3112 NULL);
3113 }
3114 else
3115#endif
3116 XtVaSetValues(textAreaForm,
3117 XmNtopAttachment, XmATTACH_WIDGET,
3118 XmNtopWidget, menuBar,
3119 NULL);
3120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003122 {
3123#ifdef FEAT_GUI_TABLINE
3124 if (showing_tabline)
3125 {
3126 XtVaSetValues(tabLine,
3127 XmNtopAttachment, XmATTACH_FORM,
3128 NULL);
3129 XtVaSetValues(textAreaForm,
3130 XmNtopAttachment, XmATTACH_WIDGET,
3131 XmNtopWidget, tabLine,
3132 NULL);
3133 }
3134 else
3135#endif
3136 XtVaSetValues(textAreaForm,
3137 XmNtopAttachment, XmATTACH_FORM,
3138 NULL);
3139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140
3141 XtUnmanageChild(XtParent(toolBar));
3142 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003143 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144}
3145
3146/*
3147 * A toolbar button has been pushed; now reset the input focus
3148 * such that the user can type page up/down etc. and have the
3149 * input go to the editor window, not the button
3150 */
3151 static void
Bram Moolenaarf9980f12005-01-03 20:58:59 +00003152reset_focus()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153{
3154 if (textArea != NULL)
3155 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3156}
3157
3158 int
3159gui_mch_compute_toolbar_height()
3160{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003161 Dimension borders;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 Dimension height; /* total Toolbar height */
3163 Dimension whgt; /* height of each widget */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 WidgetList children; /* list of toolBar's children */
3165 Cardinal numChildren; /* how many children toolBar has */
3166 int i;
3167
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003168 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3171 { /* get height of XmFrame parent */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003172 Dimension fst;
3173 Dimension fmh;
3174 Dimension tst;
3175 Dimension tmh;
3176
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003178 XmNshadowThickness, &fst,
3179 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003181 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003183 XmNshadowThickness, &tst,
3184 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 XmNchildren, &children,
3186 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003187 borders += tst + tmh;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003188 for (i = 0; i < (int)numChildren; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 {
3190 whgt = 0;
3191 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3192 if (height < whgt)
3193 height = whgt;
3194 }
3195 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003196#ifdef LESSTIF_VERSION
3197 /* Hack: When starting up we get wrong dimensions. */
3198 if (height < 10)
3199 height = 24;
3200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003202 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203}
3204
Bram Moolenaar7c626922005-02-07 22:01:03 +00003205 void
3206motif_get_toolbar_colors(bgp, fgp, bsp, tsp, hsp)
3207 Pixel *bgp;
3208 Pixel *fgp;
3209 Pixel *bsp;
3210 Pixel *tsp;
3211 Pixel *hsp;
3212{
3213 XtVaGetValues(toolBar,
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003214 XmNbackground, bgp,
3215 XmNforeground, fgp,
3216 XmNbottomShadowColor, bsp,
3217 XmNtopShadowColor, tsp,
3218 XmNhighlightColor, hsp,
3219 NULL);
Bram Moolenaar7c626922005-02-07 22:01:03 +00003220}
3221
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222# ifdef FEAT_FOOTER
3223/*
3224 * The next toolbar enter/leave callbacks should really do balloon help. But
3225 * I have to use footer help for backwards compatability. Hopefully both will
3226 * get implemented and the user will have a choice.
3227 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 static void
3229toolbarbutton_enter_cb(w, client_data, event, cont)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003230 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003232 XEvent *event UNUSED;
3233 Boolean *cont UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234{
3235 vimmenu_T *menu = (vimmenu_T *) client_data;
3236
3237 if (menu->strings[MENU_INDEX_TIP] != NULL)
3238 {
3239 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3240 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3241 }
3242}
3243
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244 static void
3245toolbarbutton_leave_cb(w, client_data, event, cont)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003246 Widget w UNUSED;
3247 XtPointer client_data UNUSED;
3248 XEvent *event UNUSED;
3249 Boolean *cont UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250{
3251 gui_mch_set_footer((char_u *) "");
3252}
3253# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#endif
3255
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003256#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3257/*
3258 * Show or hide the tabline.
3259 */
3260 void
3261gui_mch_show_tabline(int showit)
3262{
3263 if (tabLine == (Widget)0)
3264 return;
3265
3266 if (!showit != !showing_tabline)
3267 {
3268 if (showit)
3269 {
3270 XtManageChild(tabLine);
3271 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003272 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3273 XtUnmanageChild(XtNameToWidget(tabLine,
3274 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003275#ifdef FEAT_MENU
3276# ifdef FEAT_TOOLBAR
3277 if (XtIsManaged(XtParent(toolBar)))
3278 XtVaSetValues(tabLine,
3279 XmNtopAttachment, XmATTACH_WIDGET,
3280 XmNtopWidget, XtParent(toolBar), NULL);
3281 else
3282# endif
3283 if (XtIsManaged(menuBar))
3284 XtVaSetValues(tabLine,
3285 XmNtopAttachment, XmATTACH_WIDGET,
3286 XmNtopWidget, menuBar, NULL);
3287 else
3288#endif
3289 XtVaSetValues(tabLine,
3290 XmNtopAttachment, XmATTACH_FORM, NULL);
3291 XtVaSetValues(textAreaForm,
3292 XmNtopAttachment, XmATTACH_WIDGET,
3293 XmNtopWidget, tabLine,
3294 NULL);
3295 }
3296 else
3297 {
3298 XtUnmanageChild(tabLine);
3299#ifdef FEAT_MENU
3300# ifdef FEAT_TOOLBAR
3301 if (XtIsManaged(XtParent(toolBar)))
3302 XtVaSetValues(textAreaForm,
3303 XmNtopAttachment, XmATTACH_WIDGET,
3304 XmNtopWidget, XtParent(toolBar), NULL);
3305 else
3306# endif
3307 if (XtIsManaged(menuBar))
3308 XtVaSetValues(textAreaForm,
3309 XmNtopAttachment, XmATTACH_WIDGET,
3310 XmNtopWidget, menuBar, NULL);
3311 else
3312#endif
3313 XtVaSetValues(textAreaForm,
3314 XmNtopAttachment, XmATTACH_FORM, NULL);
3315 }
3316 showing_tabline = showit;
3317 }
3318}
3319
3320/*
3321 * Return TRUE when tabline is displayed.
3322 */
3323 int
3324gui_mch_showing_tabline(void)
3325{
3326 return tabLine != (Widget)0 && showing_tabline;
3327}
3328
3329/*
3330 * Update the labels of the tabline.
3331 */
3332 void
3333gui_mch_update_tabline(void)
3334{
3335 tabpage_T *tp;
3336 int nr = 1, n;
3337 Arg args[10];
3338 int curtabidx = 0, currentpage;
3339 Widget tab;
3340 XmNotebookPageInfo page_info;
3341 XmNotebookPageStatus page_status;
3342 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003343 XmString label_str;
3344 char *label_cstr;
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003345 BalloonEval *beval;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003346
3347 if (tabLine == (Widget)0)
3348 return;
3349
3350 /* Add a label for each tab page. They all contain the same text area. */
3351 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3352 {
3353 if (tp == curtab)
3354 curtabidx = nr;
3355
3356 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3357 if (page_status == XmPAGE_INVALID
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003358 || page_info.major_tab_widget == (Widget)0)
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003359 {
3360 /* Add the tab */
3361 n = 0;
3362 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3363 XtSetArg(args[n], XmNtraversalOn, False); n++;
3364 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3365 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3366 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3367 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3368 XtManageChild(tab);
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003369 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3370 NULL);
3371 XtVaSetValues(tab, XmNuserData, beval, NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003372 }
3373 else
3374 tab = page_info.major_tab_widget;
3375
3376 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003377
3378 /*
3379 * Change the label text only if it is different
3380 */
3381 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3382 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3383 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00003384 get_tabline_label(tp, FALSE);
3385 if (STRCMP(label_cstr, NameBuff) != 0)
3386 {
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003387 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3388 NameBuff, STRLEN(NameBuff) + 1, NULL);
3389 /*
3390 * Force a resize of the tab label button
3391 */
3392 XtUnmanageChild(tab);
3393 XtManageChild(tab);
3394 }
3395 XtFree(label_cstr);
3396 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003397 }
3398
3399 tab_count = nr - 1;
3400
3401 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3402
3403 /* Remove any old labels. */
3404 while (nr <= last_page)
3405 {
3406 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3407 && page_info.page_number == nr
3408 && page_info.major_tab_widget != (Widget)0)
3409 {
Bram Moolenaarf193fff2006-04-27 00:02:13 +00003410 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3411 if (beval != NULL)
3412 gui_mch_destroy_beval_area(beval);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003413 XtUnmanageChild(page_info.major_tab_widget);
3414 XtDestroyWidget(page_info.major_tab_widget);
3415 }
3416 nr++;
3417 }
3418
3419 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3420
3421 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3422 if (currentpage != curtabidx)
3423 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3424}
3425
3426/*
3427 * Set the current tab to "nr". First tab is 1.
3428 */
3429 void
3430gui_mch_set_curtab(nr)
3431 int nr;
3432{
3433 int currentpage;
3434
3435 if (tabLine == (Widget)0)
3436 return;
3437
3438 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3439 if (currentpage != nr)
3440 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3441}
3442#endif
3443
Bram Moolenaar071d4272004-06-13 20:20:40 +00003444/*
3445 * Set the colors of Widget "id" to the menu colors.
3446 */
3447 static void
3448gui_motif_menu_colors(id)
3449 Widget id;
3450{
3451 if (gui.menu_bg_pixel != INVALCOLOR)
3452#if (XmVersion >= 1002)
3453 XmChangeColor(id, gui.menu_bg_pixel);
3454#else
3455 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3456#endif
3457 if (gui.menu_fg_pixel != INVALCOLOR)
3458 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3459}
3460
3461/*
3462 * Set the colors of Widget "id" to the scrollbar colors.
3463 */
3464 static void
3465gui_motif_scroll_colors(id)
3466 Widget id;
3467{
3468 if (gui.scroll_bg_pixel != INVALCOLOR)
3469#if (XmVersion >= 1002)
3470 XmChangeColor(id, gui.scroll_bg_pixel);
3471#else
3472 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3473#endif
3474 if (gui.scroll_fg_pixel != INVALCOLOR)
3475 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3476}
3477
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478/*
3479 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3480 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003481 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482gui_motif_menu_fontlist(id)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003483 Widget id UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003485#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486#ifdef FONTSET_ALWAYS
3487 if (gui.menu_fontset != NOFONTSET)
3488 {
3489 XmFontList fl;
3490
3491 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3492 if (fl != NULL)
3493 {
3494 if (XtIsManaged(id))
3495 {
3496 XtUnmanageChild(id);
3497 XtVaSetValues(id, XmNfontList, fl, NULL);
3498 /* We should force the widget to recalculate it's
3499 * geometry now. */
3500 XtManageChild(id);
3501 }
3502 else
3503 XtVaSetValues(id, XmNfontList, fl, NULL);
3504 XmFontListFree(fl);
3505 }
3506 }
3507#else
3508 if (gui.menu_font != NOFONT)
3509 {
3510 XmFontList fl;
3511
3512 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3513 if (fl != NULL)
3514 {
3515 if (XtIsManaged(id))
3516 {
3517 XtUnmanageChild(id);
3518 XtVaSetValues(id, XmNfontList, fl, NULL);
3519 /* We should force the widget to recalculate it's
3520 * geometry now. */
3521 XtManageChild(id);
3522 }
3523 else
3524 XtVaSetValues(id, XmNfontList, fl, NULL);
3525 XmFontListFree(fl);
3526 }
3527 }
3528#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530}
3531
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532
3533/*
3534 * We don't create it twice for the sake of speed.
3535 */
3536
3537typedef struct _SharedFindReplace
3538{
3539 Widget dialog; /* the main dialog widget */
3540 Widget wword; /* 'Exact match' check button */
3541 Widget mcase; /* 'match case' check button */
3542 Widget up; /* search direction 'Up' radio button */
3543 Widget down; /* search direction 'Down' radio button */
3544 Widget what; /* 'Find what' entry text widget */
3545 Widget with; /* 'Replace with' entry text widget */
3546 Widget find; /* 'Find Next' action button */
3547 Widget replace; /* 'Replace With' action button */
3548 Widget all; /* 'Replace All' action button */
3549 Widget undo; /* 'Undo' action button */
3550
3551 Widget cancel;
3552} SharedFindReplace;
3553
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003554static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3555static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556
3557static void find_replace_destroy_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3558static void find_replace_dismiss_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3559static void entry_activate_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3560static void find_replace_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3561static void find_replace_keypress __ARGS((Widget w, SharedFindReplace * frdp, XKeyEvent * event));
3562static void find_replace_dialog_create __ARGS((char_u *entry_text, int do_replace));
3563
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 static void
3565find_replace_destroy_callback(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003566 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003567 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003568 XtPointer call_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569{
3570 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3571
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003572 if (cd != NULL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003573 /* suppress_dialog_mnemonics(cd->dialog); */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 cd->dialog = (Widget)0;
3575}
3576
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577 static void
3578find_replace_dismiss_callback(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003579 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003581 XtPointer call_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582{
3583 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3584
3585 if (cd != NULL)
3586 XtUnmanageChild(cd->dialog);
3587}
3588
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 static void
3590entry_activate_callback(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003591 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003593 XtPointer call_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594{
3595 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3596}
3597
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 static void
3599find_replace_callback(w, client_data, call_data)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003600 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 XtPointer client_data;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003602 XtPointer call_data UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603{
3604 long_u flags = (long_u)client_data;
3605 char *find_text, *repl_text;
3606 Boolean direction_down = TRUE;
3607 Boolean wword;
3608 Boolean mcase;
3609 SharedFindReplace *sfr;
3610
3611 if (flags == FRD_UNDO)
3612 {
3613 char_u *save_cpo = p_cpo;
3614
3615 /* No need to be Vi compatible here. */
3616 p_cpo = (char_u *)"";
3617 u_undo(1);
3618 p_cpo = save_cpo;
3619 gui_update_screen();
3620 return;
3621 }
3622
3623 /* Get the search/replace strings from the dialog */
3624 if (flags == FRD_FINDNEXT)
3625 {
3626 repl_text = NULL;
3627 sfr = &find_widgets;
3628 }
3629 else
3630 {
3631 repl_text = XmTextFieldGetString(repl_widgets.with);
3632 sfr = &repl_widgets;
3633 }
3634 find_text = XmTextFieldGetString(sfr->what);
3635 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3636 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3637 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3638 if (wword)
3639 flags |= FRD_WHOLE_WORD;
3640 if (mcase)
3641 flags |= FRD_MATCH_CASE;
3642
3643 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3644 direction_down);
3645
3646 if (find_text != NULL)
3647 XtFree(find_text);
3648 if (repl_text != NULL)
3649 XtFree(repl_text);
3650}
3651
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 static void
3653find_replace_keypress(w, frdp, event)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +00003654 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 SharedFindReplace *frdp;
3656 XKeyEvent *event;
3657{
3658 KeySym keysym;
3659
3660 if (frdp == NULL)
3661 return;
3662
3663 keysym = XLookupKeysym(event, 0);
3664
3665 /* the scape key pops the whole dialog down */
3666 if (keysym == XK_Escape)
3667 XtUnmanageChild(frdp->dialog);
3668}
3669
3670 static void
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003671set_label(w, label)
3672 Widget w;
3673 char_u *label;
3674{
3675 XmString str;
3676 char_u *p, *next;
3677 KeySym mnemonic = NUL;
3678
3679 if (!w)
3680 return;
3681
3682 p = vim_strsave(label);
3683 if (p == NULL)
3684 return;
3685 for (next = p; *next; ++next)
3686 {
3687 if (*next == DLG_HOTKEY_CHAR)
3688 {
3689 int len = STRLEN(next);
3690
3691 if (len > 0)
3692 {
3693 mch_memmove(next, next + 1, len);
3694 mnemonic = next[0];
3695 }
3696 }
3697 }
3698
3699 str = XmStringCreateSimple((char *)p);
3700 vim_free(p);
3701 if (str)
3702 {
3703 XtVaSetValues(w,
3704 XmNlabelString, str,
3705 XmNmnemonic, mnemonic,
3706 NULL);
3707 XmStringFree(str);
3708 }
3709 gui_motif_menu_fontlist(w);
3710}
3711
3712 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713find_replace_dialog_create(arg, do_replace)
3714 char_u *arg;
3715 int do_replace;
3716{
3717 SharedFindReplace *frdp;
3718 Widget separator;
3719 Widget input_form;
3720 Widget button_form;
3721 Widget toggle_form;
3722 Widget frame;
3723 XmString str;
3724 int n;
3725 Arg args[6];
3726 int wword = FALSE;
3727 int mcase = !p_ic;
3728 Dimension width;
3729 Dimension widest;
3730 char_u *entry_text;
3731
3732 frdp = do_replace ? &repl_widgets : &find_widgets;
3733
3734 /* Get the search string to use. */
3735 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3736
3737 /* If the dialog already exists, just raise it. */
3738 if (frdp->dialog)
3739 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003740 gui_motif_synch_fonts();
3741
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 /* If the window is already up, just pop it to the top */
3743 if (XtIsManaged(frdp->dialog))
3744 XMapRaised(XtDisplay(frdp->dialog),
3745 XtWindow(XtParent(frdp->dialog)));
3746 else
3747 XtManageChild(frdp->dialog);
3748 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3749 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3750
3751 if (entry_text != NULL)
3752 XmTextFieldSetString(frdp->what, (char *)entry_text);
3753 vim_free(entry_text);
3754
3755 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3756 return;
3757 }
3758
3759 /* Create a fresh new dialog window */
3760 if (do_replace)
3761 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3762 else
3763 str = XmStringCreateSimple(_("VIM - Search..."));
3764
3765 n = 0;
3766 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3767 XtSetArg(args[n], XmNnoResize, True); n++;
3768 XtSetArg(args[n], XmNdialogTitle, str); n++;
3769
3770 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3771 XmStringFree(str);
3772 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3773 find_replace_destroy_callback, frdp);
3774
3775 button_form = XtVaCreateWidget("buttonForm",
3776 xmFormWidgetClass, frdp->dialog,
3777 XmNrightAttachment, XmATTACH_FORM,
3778 XmNrightOffset, 4,
3779 XmNtopAttachment, XmATTACH_FORM,
3780 XmNtopOffset, 4,
3781 XmNbottomAttachment, XmATTACH_FORM,
3782 XmNbottomOffset, 4,
3783 NULL);
3784
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 frdp->find = XtVaCreateManagedWidget("findButton",
3786 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 XmNsensitive, True,
3788 XmNtopAttachment, XmATTACH_FORM,
3789 XmNleftAttachment, XmATTACH_FORM,
3790 XmNrightAttachment, XmATTACH_FORM,
3791 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003792 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793
3794 XtAddCallback(frdp->find, XmNactivateCallback,
3795 find_replace_callback,
Bram Moolenaare9e3b572008-01-22 10:06:48 +00003796 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797
3798 if (do_replace)
3799 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3801 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 XmNtopAttachment, XmATTACH_WIDGET,
3803 XmNtopWidget, frdp->find,
3804 XmNleftAttachment, XmATTACH_FORM,
3805 XmNrightAttachment, XmATTACH_FORM,
3806 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003807 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 XtAddCallback(frdp->replace, XmNactivateCallback,
3809 find_replace_callback, (XtPointer)FRD_REPLACE);
3810
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3812 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 XmNtopAttachment, XmATTACH_WIDGET,
3814 XmNtopWidget, frdp->replace,
3815 XmNleftAttachment, XmATTACH_FORM,
3816 XmNrightAttachment, XmATTACH_FORM,
3817 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003818 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819 XtAddCallback(frdp->all, XmNactivateCallback,
3820 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3821
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 frdp->undo = XtVaCreateManagedWidget("undoButton",
3823 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 XmNtopAttachment, XmATTACH_WIDGET,
3825 XmNtopWidget, frdp->all,
3826 XmNleftAttachment, XmATTACH_FORM,
3827 XmNrightAttachment, XmATTACH_FORM,
3828 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003829 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 XtAddCallback(frdp->undo, XmNactivateCallback,
3831 find_replace_callback, (XtPointer)FRD_UNDO);
3832 }
3833
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3835 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 XmNleftAttachment, XmATTACH_FORM,
3837 XmNrightAttachment, XmATTACH_FORM,
3838 XmNbottomAttachment, XmATTACH_FORM,
3839 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003840 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 XtAddCallback(frdp->cancel, XmNactivateCallback,
3842 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003843 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844
3845 XtManageChild(button_form);
3846
3847 n = 0;
3848 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3849 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3850 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3851 XtSetArg(args[n], XmNrightOffset, 4); n++;
3852 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3853 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3854 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3855 XtManageChild(separator);
3856
3857 input_form = XtVaCreateWidget("inputForm",
3858 xmFormWidgetClass, frdp->dialog,
3859 XmNleftAttachment, XmATTACH_FORM,
3860 XmNleftOffset, 4,
3861 XmNrightAttachment, XmATTACH_WIDGET,
3862 XmNrightWidget, separator,
3863 XmNrightOffset, 4,
3864 XmNtopAttachment, XmATTACH_FORM,
3865 XmNtopOffset, 4,
3866 NULL);
3867
3868 {
3869 Widget label_what;
3870 Widget label_with = (Widget)0;
3871
3872 str = XmStringCreateSimple(_("Find what:"));
3873 label_what = XtVaCreateManagedWidget("whatLabel",
3874 xmLabelGadgetClass, input_form,
3875 XmNlabelString, str,
3876 XmNleftAttachment, XmATTACH_FORM,
3877 XmNtopAttachment, XmATTACH_FORM,
3878 XmNtopOffset, 4,
3879 NULL);
3880 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003881 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882
3883 frdp->what = XtVaCreateManagedWidget("whatText",
3884 xmTextFieldWidgetClass, input_form,
3885 XmNtopAttachment, XmATTACH_FORM,
3886 XmNrightAttachment, XmATTACH_FORM,
3887 XmNleftAttachment, XmATTACH_FORM,
3888 NULL);
3889
3890 if (do_replace)
3891 {
3892 frdp->with = XtVaCreateManagedWidget("withText",
3893 xmTextFieldWidgetClass, input_form,
3894 XmNtopAttachment, XmATTACH_WIDGET,
3895 XmNtopWidget, frdp->what,
3896 XmNtopOffset, 4,
3897 XmNleftAttachment, XmATTACH_FORM,
3898 XmNrightAttachment, XmATTACH_FORM,
3899 XmNbottomAttachment, XmATTACH_FORM,
3900 NULL);
3901
3902 XtAddCallback(frdp->with, XmNactivateCallback,
3903 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3904
3905 str = XmStringCreateSimple(_("Replace with:"));
3906 label_with = XtVaCreateManagedWidget("withLabel",
3907 xmLabelGadgetClass, input_form,
3908 XmNlabelString, str,
3909 XmNleftAttachment, XmATTACH_FORM,
3910 XmNtopAttachment, XmATTACH_WIDGET,
3911 XmNtopWidget, frdp->what,
3912 XmNtopOffset, 4,
3913 XmNbottomAttachment, XmATTACH_FORM,
3914 NULL);
3915 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003916 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917
3918 /*
3919 * Make the entry activation only change the input focus onto the
3920 * with item.
3921 */
3922 XtAddCallback(frdp->what, XmNactivateCallback,
3923 entry_activate_callback, frdp->with);
3924 XtAddEventHandler(frdp->with, KeyPressMask, False,
3925 (XtEventHandler)find_replace_keypress,
3926 (XtPointer) frdp);
3927
3928 }
3929 else
3930 {
3931 /*
3932 * Make the entry activation do the search.
3933 */
3934 XtAddCallback(frdp->what, XmNactivateCallback,
3935 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3936 }
3937 XtAddEventHandler(frdp->what, KeyPressMask, False,
3938 (XtEventHandler)find_replace_keypress,
3939 (XtPointer)frdp);
3940
3941 /* Get the maximum width between the label widgets and line them up.
3942 */
3943 n = 0;
3944 XtSetArg(args[n], XmNwidth, &width); n++;
3945 XtGetValues(label_what, args, n);
3946 widest = width;
3947 if (do_replace)
3948 {
3949 XtGetValues(label_with, args, n);
3950 if (width > widest)
3951 widest = width;
3952 }
3953
3954 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3955 if (do_replace)
3956 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3957
3958 }
3959
3960 XtManageChild(input_form);
3961
3962 {
3963 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003964 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965
3966 frame = XtVaCreateWidget("directionFrame",
3967 xmFrameWidgetClass, frdp->dialog,
3968 XmNtopAttachment, XmATTACH_WIDGET,
3969 XmNtopWidget, input_form,
3970 XmNtopOffset, 4,
3971 XmNbottomAttachment, XmATTACH_FORM,
3972 XmNbottomOffset, 4,
3973 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3974 XmNrightWidget, input_form,
3975 NULL);
3976
3977 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003978 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 xmLabelGadgetClass, frame,
3980 XmNlabelString, str,
3981 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3982 XmNchildType, XmFRAME_TITLE_CHILD,
3983 NULL);
3984 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003985 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986
3987 radio_box = XmCreateRadioBox(frame, "radioBox",
3988 (ArgList)NULL, 0);
3989
3990 str = XmStringCreateSimple( _("Up"));
3991 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3992 xmToggleButtonGadgetClass, radio_box,
3993 XmNlabelString, str,
3994 XmNset, False,
3995 NULL);
3996 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003997 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998
3999 str = XmStringCreateSimple(_("Down"));
4000 frdp->down = XtVaCreateManagedWidget("downRadioButton",
4001 xmToggleButtonGadgetClass, radio_box,
4002 XmNlabelString, str,
4003 XmNset, True,
4004 NULL);
4005 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004006 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007
4008 XtManageChild(radio_box);
4009 XtManageChild(frame);
4010 }
4011
4012 toggle_form = XtVaCreateWidget("toggleForm",
4013 xmFormWidgetClass, frdp->dialog,
4014 XmNleftAttachment, XmATTACH_FORM,
4015 XmNleftOffset, 4,
4016 XmNrightAttachment, XmATTACH_WIDGET,
4017 XmNrightWidget, frame,
4018 XmNrightOffset, 4,
4019 XmNtopAttachment, XmATTACH_WIDGET,
4020 XmNtopWidget, input_form,
4021 XmNtopOffset, 4,
4022 XmNbottomAttachment, XmATTACH_FORM,
4023 XmNbottomOffset, 4,
4024 NULL);
4025
4026 str = XmStringCreateSimple(_("Match whole word only"));
4027 frdp->wword = XtVaCreateManagedWidget("wordToggle",
4028 xmToggleButtonGadgetClass, toggle_form,
4029 XmNlabelString, str,
4030 XmNtopAttachment, XmATTACH_FORM,
4031 XmNtopOffset, 4,
4032 XmNleftAttachment, XmATTACH_FORM,
4033 XmNleftOffset, 4,
4034 XmNset, wword,
4035 NULL);
4036 XmStringFree(str);
4037
4038 str = XmStringCreateSimple(_("Match case"));
4039 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
4040 xmToggleButtonGadgetClass, toggle_form,
4041 XmNlabelString, str,
4042 XmNleftAttachment, XmATTACH_FORM,
4043 XmNleftOffset, 4,
4044 XmNtopAttachment, XmATTACH_WIDGET,
4045 XmNtopWidget, frdp->wword,
4046 XmNtopOffset, 4,
4047 XmNset, mcase,
4048 NULL);
4049 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004050 gui_motif_menu_fontlist(frdp->wword);
4051 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052
4053 XtManageChild(toggle_form);
4054
4055 if (entry_text != NULL)
4056 XmTextFieldSetString(frdp->what, (char *)entry_text);
4057 vim_free(entry_text);
4058
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004059 gui_motif_synch_fonts();
4060
4061 manage_centered(frdp->dialog);
4062 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
4064}
4065
4066 void
4067gui_mch_find_dialog(eap)
4068 exarg_T *eap;
4069{
4070 if (!gui.in_use)
4071 return;
4072
4073 find_replace_dialog_create(eap->arg, FALSE);
4074}
4075
4076
4077 void
4078gui_mch_replace_dialog(eap)
4079 exarg_T *eap;
4080{
4081 if (!gui.in_use)
4082 return;
4083
4084 find_replace_dialog_create(eap->arg, TRUE);
4085}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004086
4087/*
4088 * Synchronize all gui elements, which are dependant upon the
4089 * main text font used. Those are in esp. the find/replace dialogs.
4090 * If you don't understand why this should be needed, please try to
4091 * search for "piê¶æ" in iso8859-2.
4092 */
4093 void
4094gui_motif_synch_fonts(void)
4095{
4096 SharedFindReplace *frdp;
4097 int do_replace;
4098 XFontStruct *font;
4099 XmFontList font_list;
4100
4101 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4102 * we just give up here on font synchronization. */
4103 font = (XFontStruct *)gui.norm_font;
4104 if (font == NULL)
4105 return;
4106
4107 font_list = gui_motif_create_fontlist(font);
4108
4109 /* OK this loop is a bit tricky... */
4110 for (do_replace = 0; do_replace <= 1; ++do_replace)
4111 {
4112 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4113 if (frdp->dialog)
4114 {
4115 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4116 if (do_replace)
4117 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4118 }
4119 }
4120
4121 XmFontListFree(font_list);
4122}