blob: 9e28be2b05e65a5d9ebcf3977aa99a1d2a3b4a48 [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));
91#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000092#ifdef FEAT_TOOLBAR
Bram Moolenaar071d4272004-06-13 20:20:40 +000093# ifdef FEAT_FOOTER
94static void toolbarbutton_enter_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
95static void toolbarbutton_leave_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
96# endif
Bram Moolenaarf9980f12005-01-03 20:58:59 +000097static void reset_focus __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +000098#endif
99#ifdef FEAT_FOOTER
100static int gui_mch_compute_footer_height __ARGS((void));
101#endif
102#ifdef WSDEBUG
103static void attachDump(Widget, char *);
104#endif
105
106static void gui_motif_menu_colors __ARGS((Widget id));
107static void gui_motif_scroll_colors __ARGS((Widget id));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
109#if (XmVersion >= 1002)
110# define STRING_TAG XmFONTLIST_DEFAULT_TAG
111#else
112# define STRING_TAG XmSTRING_DEFAULT_CHARSET
113#endif
114
115/*
116 * Call-back routines.
117 */
118
119/* ARGSUSED */
120 static void
121scroll_cb(w, client_data, call_data)
122 Widget w;
123 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
138/*ARGSUSED*/
139 static void
140tabline_cb(w, client_data, call_data)
141 Widget w;
142 XtPointer client_data, call_data;
143{
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
151/*ARGSUSED*/
152 static void
153tabline_button_cb(w, client_data, call_data)
154 Widget w;
155 XtPointer client_data, call_data;
156{
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 */
168/*ARGSUSED*/
169 static void
170motif_tabline_timer_cb (timed_out, interval_id)
171 XtPointer timed_out;
172 XtIntervalId *interval_id;
173{
174 *((int *)timed_out) = TRUE;
175}
176
177/*
178 * check if the tabline tab scroller is clicked
179 */
180 static int
181tabline_scroller_clicked(scroller_name, event)
182 char *scroller_name;
183 XButtonPressedEvent *event;
184{
185 Widget tab_scroll_w;
186 Position pos_x, pos_y;
187 Dimension width, height;
188
189 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
190 if (tab_scroll_w != (Widget)0) {
191 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
192 &width, XmNheight, &height, NULL);
193 if (pos_x >= 0) {
194 /* Tab scroller (next) is visible */
195 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
196 (event->y >= pos_y) && (event->y <= pos_y + height)) {
197 /* Clicked on the scroller */
198 return TRUE;
199 }
200 }
201 }
202 return FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000203}
204
205/*ARGSUSED*/
206 static void
207tabline_menu_cb(w, closure, e, continue_dispatch)
208 Widget w;
209 XtPointer closure;
210 XEvent *e;
211 Boolean *continue_dispatch;
212{
213 Widget tab_w;
214 XButtonPressedEvent *event;
215 int tab_idx = 0;
216 WidgetList children;
217 Cardinal numChildren;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000218 static XtIntervalId timer = (XtIntervalId)0;
219 static int timed_out = TRUE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000220
221 event = (XButtonPressedEvent *)e;
222
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000223 if (event->button == Button1)
224 {
225 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
226 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
227 return;
228
229 if (!timed_out)
230 {
231 XtRemoveTimeOut(timer);
232 timed_out = TRUE;
233
234 /*
235 * Double click on the tabline gutter, add a new tab
236 */
237 send_tabline_menu_event(0, TABLINE_MENU_NEW);
238 }
239 else
240 {
241 /*
242 * Single click on the tabline gutter, start a timer to check
243 * for double clicks
244 */
245 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
246 motif_tabline_timer_cb, &timed_out);
247 timed_out = FALSE;
248 }
249 return;
250 }
251
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000252 if (event->button != Button3)
253 return;
254
255 if (event->subwindow != None)
256 {
257 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000258 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000259 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
260 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
261 }
262
263 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
264 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
265 &numChildren, NULL);
266 XtManageChildren(children, numChildren);
267 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
268 XtManageChild(tabLine_menu);
269}
270#endif
271
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272/*
273 * End of call-back routines
274 */
275
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000276/*
277 * Implement three dimensional shading of insensitive labels.
Bram Moolenaara0a83be2005-01-04 21:26:43 +0000278 * By Marcin Dalecki.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000279 */
280
281#include <Xm/XmP.h>
282#include <Xm/LabelP.h>
283
284static XtExposeProc old_label_expose = NULL;
285
286static void label_expose __ARGS((Widget _w, XEvent *_event, Region _region));
287
288 static void
289label_expose(_w, _event, _region)
290 Widget _w;
291 XEvent *_event;
292 Region _region;
293{
294 GC insensitiveGC;
295 XmLabelWidget lw = (XmLabelWidget)_w;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000296 unsigned char label_type = (int)XmSTRING;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000297
298 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
299
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000300 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000301 (*old_label_expose)(_w, _event, _region);
302 else
303 {
304 XGCValues values;
305 XtGCMask mask;
306 XtGCMask dynamic;
307 XFontStruct *fs;
308
309 _XmFontListGetDefaultFont(lw->label.font, &fs);
310
311 /* FIXME: we should be doing the whole drawing ourself here. */
312 insensitiveGC = lw->label.insensitive_GC;
313
314 mask = GCForeground | GCBackground | GCGraphicsExposures;
315 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
316 values.graphics_exposures = False;
317
318 if (fs != 0)
319 {
320 mask |= GCFont;
321 values.font = fs->fid;
322 }
323
324 if (lw->primitive.top_shadow_pixmap != None
325 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
326 {
327 mask |= GCFillStyle | GCTile;
328 values.fill_style = FillTiled;
329 values.tile = lw->primitive.top_shadow_pixmap;
330 }
331
332 lw->label.TextRect.x += 1;
333 lw->label.TextRect.y += 1;
334 if (lw->label._acc_text != 0)
335 {
336 lw->label.acc_TextRect.x += 1;
337 lw->label.acc_TextRect.y += 1;
338 }
339
340 values.foreground = lw->primitive.top_shadow_color;
341 values.background = lw->core.background_pixel;
342
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000343 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
344 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000345 (*old_label_expose)(_w, _event, _region);
346 XtReleaseGC(_w, lw->label.insensitive_GC);
347
348 lw->label.TextRect.x -= 1;
349 lw->label.TextRect.y -= 1;
350 if (lw->label._acc_text != 0)
351 {
352 lw->label.acc_TextRect.x -= 1;
353 lw->label.acc_TextRect.y -= 1;
354 }
355
356 values.foreground = lw->primitive.bottom_shadow_color;
357 values.background = lw->core.background_pixel;
358
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000359 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
360 &values, dynamic, (XtGCMask)0);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000361 (*old_label_expose)(_w, _event, _region);
362 XtReleaseGC(_w, lw->label.insensitive_GC);
363
364 lw->label.insensitive_GC = insensitiveGC;
365 }
366}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000367
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368/*
369 * Create all the motif widgets necessary.
370 */
371 void
372gui_x11_create_widgets()
373{
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000374#ifdef FEAT_GUI_TABLINE
Bram Moolenaar18144c82006-04-12 21:52:12 +0000375 Widget button, scroller;
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000376 Arg args[10];
377 int n;
378 XmString xms;
379#endif
380
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000381 /*
382 * Install the 3D shade effect drawing routines.
383 */
384 if (old_label_expose == NULL)
385 {
386 old_label_expose = xmLabelWidgetClass->core_class.expose;
387 xmLabelWidgetClass->core_class.expose = label_expose;
388 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000389
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390 /*
391 * Start out by adding the configured border width into the border offset
392 */
393 gui.border_offset = gui.border_width;
394
395 /*
396 * Install the tearOffModel resource converter.
397 */
398#if (XmVersion >= 1002)
399 XmRepTypeInstallTearOffModelConverter();
400#endif
401
402 /* Make sure the "Quit" menu entry of the window manager is ignored */
403 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
404
405 vimForm = XtVaCreateManagedWidget("vimForm",
406 xmFormWidgetClass, vimShell,
407 XmNborderWidth, 0,
408 XmNhighlightThickness, 0,
409 XmNshadowThickness, 0,
410 XmNmarginWidth, 0,
411 XmNmarginHeight, 0,
412 XmNresizePolicy, XmRESIZE_ANY,
413 NULL);
414 gui_motif_menu_colors(vimForm);
415
416#ifdef FEAT_MENU
417 {
418 Arg al[7]; /* Make sure there is enough room for arguments! */
419 int ac = 0;
420
421# if (XmVersion >= 1002)
422 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
423# endif
424 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
425 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
426 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
427# ifndef FEAT_TOOLBAR
428 /* Always stick to right hand side. */
429 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
430# endif
Bram Moolenaarb7fcef52005-01-02 11:31:05 +0000431 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
433 XtManageChild(menuBar);
434
435 /* Remember the default colors, needed for ":hi clear". */
436 XtVaGetValues(menuBar,
437 XmNbackground, &gui.menu_def_bg_pixel,
438 XmNforeground, &gui.menu_def_fg_pixel,
439 NULL);
440 gui_motif_menu_colors(menuBar);
441 }
442#endif
443
444#ifdef FEAT_TOOLBAR
445 /*
446 * Create an empty ToolBar. We should get buttons defined from menu.vim.
447 */
448 toolBarFrame = XtVaCreateWidget("toolBarFrame",
449 xmFrameWidgetClass, vimForm,
450 XmNshadowThickness, 0,
451 XmNmarginHeight, 0,
452 XmNmarginWidth, 0,
453 XmNleftAttachment, XmATTACH_FORM,
454 XmNrightAttachment, XmATTACH_FORM,
455 NULL);
456 gui_motif_menu_colors(toolBarFrame);
457
458 toolBar = XtVaCreateManagedWidget("toolBar",
459 xmRowColumnWidgetClass, toolBarFrame,
460 XmNchildType, XmFRAME_WORKAREA_CHILD,
461 XmNrowColumnType, XmWORK_AREA,
462 XmNorientation, XmHORIZONTAL,
463 XmNtraversalOn, False,
464 XmNisHomogeneous, False,
465 XmNpacking, XmPACK_TIGHT,
466 XmNspacing, 0,
467 XmNshadowThickness, 0,
468 XmNhighlightThickness, 0,
469 XmNmarginHeight, 0,
470 XmNmarginWidth, 0,
471 XmNadjustLast, True,
472 NULL);
473 gui_motif_menu_colors(toolBar);
474
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475#endif
476
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000477#ifdef FEAT_GUI_TABLINE
478 /* Create the Vim GUI tabline */
479 n = 0;
480 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
481 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
482 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
483 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
484 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
485 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
486 XtSetArg(args[n], XmNshadowThickness, 0); n++;
487 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
488 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
489 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
490
491 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
492 NULL);
493 XtAddEventHandler(tabLine, ButtonPressMask, False,
494 (XtEventHandler)tabline_menu_cb, NULL);
495
Bram Moolenaar18144c82006-04-12 21:52:12 +0000496 /*
497 * Set the size of the minor next/prev scrollers to zero, so
498 * that they are not displayed. Due to a bug in OpenMotif 2.3,
499 * even if these children widget are unmanaged, they are again
500 * managed by the Notebook widget and the notebook widget geometry
501 * is adjusted to account for the minor scroller widgets.
502 */
503 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
504 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
505 XmNtraversalOn, False, NULL);
506 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
507 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
508 XmNtraversalOn, False, NULL);
509
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000510 /* Create the tabline popup menu */
511 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
512
513 /* Add the buttons to the menu */
514 n = 0;
515 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
516 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
517 XtSetArg(args[n], XmNlabelString, xms); n++;
518 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
519 XtAddCallback(button, XmNactivateCallback,
520 (XtCallbackProc)tabline_button_cb, NULL);
521 XmStringFree(xms);
522
523 n = 0;
524 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
525 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
526 XtSetArg(args[n], XmNlabelString, xms); n++;
527 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
528 XtAddCallback(button, XmNactivateCallback,
529 (XtCallbackProc)tabline_button_cb, NULL);
530 XmStringFree(xms);
531
532 n = 0;
533 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
534 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
535 XtSetArg(args[n], XmNlabelString, xms); n++;
536 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
537 XtAddCallback(button, XmNactivateCallback,
538 (XtCallbackProc)tabline_button_cb, NULL);
539 XmStringFree(xms);
540#endif
541
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
543 xmFormWidgetClass, vimForm,
544 XmNleftAttachment, XmATTACH_FORM,
545 XmNrightAttachment, XmATTACH_FORM,
546 XmNbottomAttachment, XmATTACH_FORM,
547 XmNtopAttachment, XmATTACH_FORM,
548 XmNmarginWidth, 0,
549 XmNmarginHeight, 0,
550 XmNresizePolicy, XmRESIZE_ANY,
551 NULL);
552 gui_motif_scroll_colors(textAreaForm);
553
554 textArea = XtVaCreateManagedWidget("textArea",
555 xmDrawingAreaWidgetClass, textAreaForm,
556 XmNforeground, gui.norm_pixel,
557 XmNbackground, gui.back_pixel,
558 XmNleftAttachment, XmATTACH_FORM,
559 XmNtopAttachment, XmATTACH_FORM,
560 XmNrightAttachment, XmATTACH_FORM,
561 XmNbottomAttachment, XmATTACH_FORM,
562
563 /*
564 * These take some control away from the user, but avoids making them
565 * add resources to get a decent looking setup.
566 */
567 XmNborderWidth, 0,
568 XmNhighlightThickness, 0,
569 XmNshadowThickness, 0,
570 NULL);
571
572#ifdef FEAT_FOOTER
573 /*
574 * Create the Footer.
575 */
576 footer = XtVaCreateWidget("footer",
577 xmLabelGadgetClass, vimForm,
578 XmNalignment, XmALIGNMENT_BEGINNING,
579 XmNmarginHeight, 0,
580 XmNmarginWidth, 0,
581 XmNtraversalOn, False,
582 XmNrecomputeSize, False,
583 XmNleftAttachment, XmATTACH_FORM,
584 XmNleftOffset, 5,
585 XmNrightAttachment, XmATTACH_FORM,
586 XmNbottomAttachment, XmATTACH_FORM,
587 NULL);
588 gui_mch_set_footer((char_u *) "");
589#endif
590
591 /*
592 * Install the callbacks.
593 */
594 gui_x11_callbacks(textArea, vimForm);
595
596 /* Pretend we don't have input focus, we will get an event if we do. */
597 gui.in_focus = FALSE;
598}
599
600/*
601 * Called when the GUI is not going to start after all.
602 */
603 void
604gui_x11_destroy_widgets()
605{
606 textArea = NULL;
607#ifdef FEAT_MENU
608 menuBar = NULL;
609#endif
610}
611
612/*ARGSUSED*/
613 void
614gui_mch_set_text_area_pos(x, y, w, h)
615 int x;
616 int y;
617 int w;
618 int h;
619{
620#ifdef FEAT_TOOLBAR
621 /* Give keyboard focus to the textArea instead of the toolbar. */
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000622 reset_focus();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623#endif
624}
625
626 void
627gui_x11_set_back_color()
628{
629 if (textArea != NULL)
630#if (XmVersion >= 1002)
631 XmChangeColor(textArea, gui.back_pixel);
632#else
633 XtVaSetValues(textArea,
634 XmNbackground, gui.back_pixel,
635 NULL);
636#endif
637}
638
639/*
640 * Manage dialog centered on pointer. This could be used by the Athena code as
641 * well.
642 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000643 void
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644manage_centered(dialog_child)
645 Widget dialog_child;
646{
647 Widget shell = XtParent(dialog_child);
648 Window root, child;
649 unsigned int mask;
650 unsigned int width, height, border_width, depth;
651 int x, y, win_x, win_y, maxX, maxY;
652 Boolean mappedWhenManaged;
653
654 /* Temporarily set value of XmNmappedWhenManaged
655 to stop the dialog from popping up right away */
656 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, 0);
657 XtVaSetValues(shell, XmNmappedWhenManaged, False, 0);
658
659 XtManageChild(dialog_child);
660
661 /* Get the pointer position (x, y) */
662 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
663 &x, &y, &win_x, &win_y, &mask);
664
665 /* Translate the pointer position (x, y) into a position for the new
666 window that will place the pointer at its center */
667 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
668 &width, &height, &border_width, &depth);
669 width += 2 * border_width;
670 height += 2 * border_width;
671 x -= width / 2;
672 y -= height / 2;
673
674 /* Ensure that the dialog remains on screen */
675 maxX = XtScreen(shell)->width - width;
676 maxY = XtScreen(shell)->height - height;
677 if (x < 0)
678 x = 0;
679 if (x > maxX)
680 x = maxX;
681 if (y < 0)
682 y = 0;
683 if (y > maxY)
684 y = maxY;
685
686 /* Set desired window position in the DialogShell */
687 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
688
689 /* Map the widget */
690 XtMapWidget(shell);
691
692 /* Restore the value of XmNmappedWhenManaged */
693 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, 0);
694}
695
696#if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
697 || defined(FEAT_GUI_DIALOG) || defined(PROTO)
698
699/*
700 * Encapsulate the way an XmFontList is created.
701 */
702 XmFontList
703gui_motif_create_fontlist(font)
704 XFontStruct *font;
705{
706 XmFontList font_list;
707
708# if (XmVersion <= 1001)
709 /* Motif 1.1 method */
710 font_list = XmFontListCreate(font, STRING_TAG);
711# else
712 /* Motif 1.2 method */
713 XmFontListEntry font_list_entry;
714
715 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
716 (XtPointer)font);
717 font_list = XmFontListAppendEntry(NULL, font_list_entry);
718 XmFontListEntryFree(&font_list_entry);
719# endif
720 return font_list;
721}
722
723# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
724 XmFontList
725gui_motif_fontset2fontlist(fontset)
726 XFontSet *fontset;
727{
728 XmFontList font_list;
729
730 /* Motif 1.2 method */
731 XmFontListEntry font_list_entry;
732
733 font_list_entry = XmFontListEntryCreate(STRING_TAG,
734 XmFONT_IS_FONTSET,
735 (XtPointer)*fontset);
736 font_list = XmFontListAppendEntry(NULL, font_list_entry);
737 XmFontListEntryFree(&font_list_entry);
738 return font_list;
739}
740# endif
741
742#endif
743
744#if defined(FEAT_MENU) || defined(PROTO)
745/*
746 * Menu stuff.
747 */
748
749static void gui_motif_add_actext __ARGS((vimmenu_T *menu));
750#if (XmVersion >= 1002)
751static void toggle_tearoff __ARGS((Widget wid));
752static void gui_mch_recurse_tearoffs __ARGS((vimmenu_T *menu));
753#endif
Bram Moolenaarf9980f12005-01-03 20:58:59 +0000754static void submenu_change __ARGS((vimmenu_T *mp, int colors));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755
756static void do_set_mnemonics __ARGS((int enable));
757static int menu_enabled = TRUE;
758
759 void
760gui_mch_enable_menu(flag)
761 int flag;
762{
763 if (flag)
764 {
765 XtManageChild(menuBar);
766#ifdef FEAT_TOOLBAR
767 if (XtIsManaged(XtParent(toolBar)))
768 {
769 /* toolBar is attached to top form */
770 XtVaSetValues(XtParent(toolBar),
771 XmNtopAttachment, XmATTACH_WIDGET,
772 XmNtopWidget, menuBar,
773 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000774#ifdef FEAT_GUI_TABLINE
775 if (showing_tabline)
776 {
777 XtVaSetValues(tabLine,
778 XmNtopAttachment, XmATTACH_WIDGET,
779 XmNtopWidget, XtParent(toolBar),
780 NULL);
781 XtVaSetValues(textAreaForm,
782 XmNtopAttachment, XmATTACH_WIDGET,
783 XmNtopWidget, tabLine,
784 NULL);
785 }
786 else
787#endif
788 XtVaSetValues(textAreaForm,
789 XmNtopAttachment, XmATTACH_WIDGET,
790 XmNtopWidget, XtParent(toolBar),
791 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792 }
793 else
794#endif
795 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000796#ifdef FEAT_GUI_TABLINE
797 if (showing_tabline)
798 {
799 XtVaSetValues(tabLine,
800 XmNtopAttachment, XmATTACH_WIDGET,
801 XmNtopWidget, menuBar,
802 NULL);
803 XtVaSetValues(textAreaForm,
804 XmNtopAttachment, XmATTACH_WIDGET,
805 XmNtopWidget, tabLine,
806 NULL);
807 }
808 else
809#endif
810 XtVaSetValues(textAreaForm,
811 XmNtopAttachment, XmATTACH_WIDGET,
812 XmNtopWidget, menuBar,
813 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 }
815 }
816 else
817 {
818 XtUnmanageChild(menuBar);
819#ifdef FEAT_TOOLBAR
820 if (XtIsManaged(XtParent(toolBar)))
821 {
822 XtVaSetValues(XtParent(toolBar),
823 XmNtopAttachment, XmATTACH_FORM,
824 NULL);
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000825#ifdef FEAT_GUI_TABLINE
826 if (showing_tabline)
827 {
828 XtVaSetValues(tabLine,
829 XmNtopAttachment, XmATTACH_WIDGET,
830 XmNtopWidget, XtParent(toolBar),
831 NULL);
832 XtVaSetValues(textAreaForm,
833 XmNtopAttachment, XmATTACH_WIDGET,
834 XmNtopWidget, tabLine,
835 NULL);
836 }
837 else
838#endif
839 XtVaSetValues(textAreaForm,
840 XmNtopAttachment, XmATTACH_WIDGET,
841 XmNtopWidget, XtParent(toolBar),
842 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843 }
844 else
845#endif
846 {
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000847#ifdef FEAT_GUI_TABLINE
848 if (showing_tabline)
849 {
850 XtVaSetValues(tabLine,
851 XmNtopAttachment, XmATTACH_FORM,
852 NULL);
853 XtVaSetValues(textAreaForm,
854 XmNtopAttachment, XmATTACH_WIDGET,
855 XmNtopWidget, tabLine,
856 NULL);
857 }
858 else
859#endif
860 XtVaSetValues(textAreaForm,
861 XmNtopAttachment, XmATTACH_FORM,
862 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 }
864 }
865
866}
867
868/*
869 * Enable or disable mnemonics for the toplevel menus.
870 */
871 void
872gui_motif_set_mnemonics(enable)
873 int enable;
874{
875 /*
876 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
877 * crashes when using a mnemonic then.
878 */
879 if (!menu_enabled)
880 enable = FALSE;
881 do_set_mnemonics(enable);
882}
883
884 static void
885do_set_mnemonics(enable)
886 int enable;
887{
888 vimmenu_T *menu;
889
890 for (menu = root_menu; menu != NULL; menu = menu->next)
891 if (menu->id != (Widget)0)
892 XtVaSetValues(menu->id,
893 XmNmnemonic, enable ? menu->mnemonic : NUL,
894 NULL);
895}
896
897 void
898gui_mch_add_menu(menu, idx)
899 vimmenu_T *menu;
900 int idx;
901{
902 XmString label;
903 Widget shell;
904 vimmenu_T *parent = menu->parent;
905
906#ifdef MOTIF_POPUP
907 if (menu_is_popup(menu->name))
908 {
909 Arg arg[2];
910 int n = 0;
911
912 /* Only create the popup menu when it's actually used, otherwise there
913 * is a delay when using the right mouse button. */
914# if (XmVersion <= 1002)
915 if (mouse_model_popup())
916# endif
917 {
918 if (gui.menu_bg_pixel != INVALCOLOR)
919 {
920 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
921 }
922 if (gui.menu_fg_pixel != INVALCOLOR)
923 {
924 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
925 }
926 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
927 arg, n);
928 menu->id = (Widget)0;
929 }
930 return;
931 }
932#endif
933
934 if (!menu_is_menubar(menu->name)
935 || (parent != NULL && parent->submenu_id == (Widget)0))
936 return;
937
938 label = XmStringCreate((char *)menu->dname, STRING_TAG);
939 if (label == NULL)
940 return;
941 menu->id = XtVaCreateWidget("subMenu",
942 xmCascadeButtonWidgetClass,
943 (parent == NULL) ? menuBar : parent->submenu_id,
944 XmNlabelString, label,
945 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
946#if (XmVersion >= 1002)
947 /* submenu: count the tearoff item (needed for LessTif) */
948 XmNpositionIndex, idx + (parent != NULL
949 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
950#endif
951 NULL);
952 gui_motif_menu_colors(menu->id);
953 gui_motif_menu_fontlist(menu->id);
954 XmStringFree(label);
955
956 if (menu->id == (Widget)0) /* failed */
957 return;
958
959 /* add accelerator text */
960 gui_motif_add_actext(menu);
961
962 shell = XtVaCreateWidget("subMenuShell",
963 xmMenuShellWidgetClass, menu->id,
964 XmNwidth, 1,
965 XmNheight, 1,
966 NULL);
967 gui_motif_menu_colors(shell);
968 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
969 xmRowColumnWidgetClass, shell,
970 XmNrowColumnType, XmMENU_PULLDOWN,
971 NULL);
972 gui_motif_menu_colors(menu->submenu_id);
973
974 if (menu->submenu_id == (Widget)0) /* failed */
975 return;
976
977#if (XmVersion >= 1002)
978 /* Set the colors for the tear off widget */
979 toggle_tearoff(menu->submenu_id);
980#endif
981
982 XtVaSetValues(menu->id,
983 XmNsubMenuId, menu->submenu_id,
984 NULL);
985
986 /*
987 * The "Help" menu is a special case, and should be placed at the far
988 * right hand side of the menu-bar. It's recognized by its high priority.
989 */
990 if (parent == NULL && menu->priority >= 9999)
991 XtVaSetValues(menuBar,
992 XmNmenuHelpWidget, menu->id,
993 NULL);
994
995 /*
996 * When we add a top-level item to the menu bar, we can figure out how
997 * high the menu bar should be.
998 */
999 if (parent == NULL)
1000 gui_mch_compute_menu_height(menu->id);
1001}
1002
1003
1004/*
1005 * Add mnemonic and accelerator text to a menu button.
1006 */
1007 static void
1008gui_motif_add_actext(menu)
1009 vimmenu_T *menu;
1010{
1011 XmString label;
1012
1013 /* Add accelrator text, if there is one */
1014 if (menu->actext != NULL && menu->id != (Widget)0)
1015 {
1016 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1017 if (label == NULL)
1018 return;
1019 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1020 XmStringFree(label);
1021 }
1022}
1023
1024 void
1025gui_mch_toggle_tearoffs(enable)
1026 int enable;
1027{
1028#if (XmVersion >= 1002)
1029 if (enable)
1030 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1031 else
1032 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1033 toggle_tearoff(menuBar);
1034 gui_mch_recurse_tearoffs(root_menu);
1035#endif
1036}
1037
1038#if (XmVersion >= 1002)
1039/*
1040 * Set the tearoff for one menu widget on or off, and set the color of the
1041 * tearoff widget.
1042 */
1043 static void
1044toggle_tearoff(wid)
1045 Widget wid;
1046{
1047 Widget w;
1048
1049 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1050 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1051 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1052 gui_motif_menu_colors(w);
1053}
1054
1055 static void
1056gui_mch_recurse_tearoffs(menu)
1057 vimmenu_T *menu;
1058{
1059 while (menu != NULL)
1060 {
1061 if (!menu_is_popup(menu->name))
1062 {
1063 if (menu->submenu_id != (Widget)0)
1064 toggle_tearoff(menu->submenu_id);
1065 gui_mch_recurse_tearoffs(menu->children);
1066 }
1067 menu = menu->next;
1068 }
1069}
1070#endif
1071
1072 int
1073gui_mch_text_area_extra_height()
1074{
1075 Dimension shadowHeight;
1076
1077 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1078 return shadowHeight;
1079}
1080
1081/*
1082 * Compute the height of the menu bar.
1083 * We need to check all the items for their position and height, for the case
1084 * there are several rows, and/or some characters extend higher or lower.
1085 */
1086 void
1087gui_mch_compute_menu_height(id)
1088 Widget id; /* can be NULL when deleting menu */
1089{
1090 Dimension y, maxy;
1091 Dimension margin, shadow;
1092 vimmenu_T *mp;
1093 static Dimension height = 21; /* normal height of a menu item */
1094
1095 /*
1096 * Get the height of the new item, before managing it, because it will
1097 * still reflect the font size. After managing it depends on the menu
1098 * height, which is what we just wanted to get!.
1099 */
1100 if (id != (Widget)0)
1101 XtVaGetValues(id, XmNheight, &height, NULL);
1102
1103 /* Find any menu Widget, to be able to call XtManageChild() */
1104 else
1105 for (mp = root_menu; mp != NULL; mp = mp->next)
1106 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1107 {
1108 id = mp->id;
1109 break;
1110 }
1111
1112 /*
1113 * Now manage the menu item, to make them all be positioned (makes an
1114 * extra row when needed, removes it when not needed).
1115 */
1116 if (id != (Widget)0)
1117 XtManageChild(id);
1118
1119 /*
1120 * Now find the menu item that is the furthest down, and get it's position.
1121 */
1122 maxy = 0;
1123 for (mp = root_menu; mp != NULL; mp = mp->next)
1124 {
1125 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1126 {
1127 XtVaGetValues(mp->id, XmNy, &y, NULL);
1128 if (y > maxy)
1129 maxy = y;
1130 }
1131 }
1132
1133 XtVaGetValues(menuBar,
1134 XmNmarginHeight, &margin,
1135 XmNshadowThickness, &shadow,
1136 NULL);
1137
1138 /*
1139 * This computation is the result of trial-and-error:
1140 * maxy = The maximum position of an item; required for when there are
1141 * two or more rows
1142 * height = height of an item, before managing it; Hopefully this will
1143 * change with the font height. Includes shadow-border.
1144 * shadow = shadow-border; must be subtracted from the height.
1145 * margin = margin around the menu buttons; Must be added.
1146 * Add 4 for the underlining of shortcut keys.
1147 */
1148 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1149
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 /* Somehow the menu bar doesn't resize automatically. Set it here,
1151 * even though this is a catch 22. Don't do this when starting up,
1152 * somehow the menu gets very high then. */
1153 if (gui.shell_created)
1154 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001155}
1156
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001157#ifdef FEAT_TOOLBAR
1158
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001159/*
1160 * Icons used by the toolbar code.
1161 */
1162#include "gui_x11_pm.h"
1163
1164static int check_xpm __ARGS((char_u *path));
Bram Moolenaar7c626922005-02-07 22:01:03 +00001165static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu, char **fname));
1166static int add_pixmap_args __ARGS((vimmenu_T *menu, Arg *args, int n));
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001167
1168/*
1169 * Read an Xpm file. Return OK or FAIL.
1170 */
1171 static int
1172check_xpm(path)
1173 char_u *path;
1174{
1175 XpmAttributes attrs;
1176 int status;
1177 Pixmap mask;
1178 Pixmap map;
1179
1180 attrs.valuemask = 0;
1181
1182 /* Create the "sensitive" pixmap */
1183 status = XpmReadFileToPixmap(gui.dpy,
1184 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1185 (char *)path, &map, &mask, &attrs);
1186 XpmFreeAttributes(&attrs);
1187
1188 if (status == XpmSuccess)
1189 return OK;
1190 return FAIL;
1191}
1192
1193
1194/*
1195 * Allocated a pixmap for toolbar menu "menu".
Bram Moolenaar7c626922005-02-07 22:01:03 +00001196 * When it's to be read from a file, "fname" is set to the file name
1197 * (in allocated memory).
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001198 * Return a blank pixmap if it fails.
1199 */
1200 static char **
Bram Moolenaar7c626922005-02-07 22:01:03 +00001201get_toolbar_pixmap(menu, fname)
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001202 vimmenu_T *menu;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001203 char **fname;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001204{
1205 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1206 char **xpm = NULL; /* xpm array */
1207 int res;
1208
Bram Moolenaar7c626922005-02-07 22:01:03 +00001209 *fname = NULL;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001210 buf[0] = NUL; /* start with NULL path */
1211
1212 if (menu->iconfile != NULL)
1213 {
1214 /* Use the "icon=" argument. */
1215 gui_find_iconfile(menu->iconfile, buf, "xpm");
1216 res = check_xpm(buf);
1217
1218 /* If it failed, try using the menu name. */
1219 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1220 res = check_xpm(buf);
1221 if (res == OK)
Bram Moolenaar7c626922005-02-07 22:01:03 +00001222 {
1223 *fname = (char *)vim_strsave(buf);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001224 return tb_blank_xpm;
Bram Moolenaar7c626922005-02-07 22:01:03 +00001225 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001226 }
1227
1228 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1229 {
1230 if (menu->iconidx >= 0 && menu->iconidx
1231 < (sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
1232 xpm = built_in_pixmaps[menu->iconidx];
1233 else
1234 xpm = tb_blank_xpm;
1235 }
1236
1237 return xpm;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238}
Bram Moolenaar7c626922005-02-07 22:01:03 +00001239
1240/*
1241 * Add arguments for the toolbar pixmap to a menu item.
1242 */
1243 static int
1244add_pixmap_args(menu, args, n)
1245 vimmenu_T *menu;
1246 Arg *args;
1247 int n;
1248{
1249 vim_free(menu->xpm_fname);
1250 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1251 if (menu->xpm == NULL)
1252 {
1253 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1254 }
1255 else
1256 {
1257 if (menu->xpm_fname != NULL)
1258 {
1259 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
1260 }
1261 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1262 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1263 }
1264 return n;
1265}
Bram Moolenaarb23c3382005-01-31 19:09:12 +00001266#endif /* FEAT_TOOLBAR */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267
1268 void
1269gui_mch_add_menu_item(menu, idx)
1270 vimmenu_T *menu;
1271 int idx;
1272{
1273 XmString label;
1274 vimmenu_T *parent = menu->parent;
1275
1276# ifdef EBCDIC
1277 menu->mnemonic = 0;
1278# endif
1279
1280# if (XmVersion <= 1002)
1281 /* Don't add Popup menu items when the popup menu isn't used. */
1282 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1283 return;
1284# endif
1285
1286# ifdef FEAT_TOOLBAR
1287 if (menu_is_toolbar(parent->name))
1288 {
1289 WidgetClass type;
1290 XmString xms = NULL; /* fallback label if pixmap not found */
1291 int n;
1292 Arg args[18];
1293
1294 n = 0;
1295 if (menu_is_separator(menu->name))
1296 {
1297 char *cp;
1298 Dimension wid;
1299
1300 /*
1301 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1302 * a width specifier. If no width is specified then we choose one.
1303 */
1304 cp = (char *)vim_strchr(menu->name, ':');
1305 if (cp != NULL)
1306 wid = (Dimension)atoi(++cp);
1307 else
1308 wid = 4;
1309
1310#if 0
1311 /* We better use a FormWidget here, since it's far more
1312 * flexible in terms of size. */
1313 type = xmFormWidgetClass;
1314 XtSetArg(args[n], XmNwidth, wid); n++;
1315#else
1316 type = xmSeparatorWidgetClass;
1317 XtSetArg(args[n], XmNwidth, wid); n++;
1318 XtSetArg(args[n], XmNminWidth, wid); n++;
1319 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001320 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321#endif
1322 }
1323 else
1324 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 /* Without shadows one can't sense whatever the button has been
1326 * pressed or not! However we wan't to save a bit of space...
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001327 * Need the highlightThickness to see the focus.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001329 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1331 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1332 XtSetArg(args[n], XmNmarginHeight, 0); n++;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001333 XtSetArg(args[n], XmNtraversalOn, False); n++;
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001334 /* Set the label here, so that we can switch between icons/text
1335 * by changing the XmNlabelType resource. */
1336 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1337 XtSetArg(args[n], XmNlabelString, xms); n++;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001338
Bram Moolenaar7c626922005-02-07 22:01:03 +00001339 n = add_pixmap_args(menu, args, n);
1340
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001341 type = xmEnhancedButtonWidgetClass;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 }
1343
1344 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1345 if (menu->id == NULL)
1346 {
1347 menu->id = XtCreateManagedWidget((char *)menu->dname,
1348 type, toolBar, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001349 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {
1351 XtAddCallback(menu->id,
1352 XmNactivateCallback, gui_x11_menu_cb, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353# ifdef FEAT_FOOTER
1354 XtAddEventHandler(menu->id, EnterWindowMask, False,
1355 toolbarbutton_enter_cb, menu);
1356 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1357 toolbarbutton_leave_cb, menu);
1358# endif
1359 }
1360 }
1361 else
1362 XtSetValues(menu->id, args, n);
1363 if (xms != NULL)
1364 XmStringFree(xms);
1365
1366#ifdef FEAT_BEVAL
1367 gui_mch_menu_set_tip(menu);
1368#endif
1369
1370 menu->parent = parent;
1371 menu->submenu_id = NULL;
1372 /* When adding first item to toolbar it might have to be enabled .*/
1373 if (!XtIsManaged(XtParent(toolBar))
1374 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1375 gui_mch_show_toolbar(TRUE);
1376 gui.toolbar_height = gui_mch_compute_toolbar_height();
1377 return;
1378 } /* toolbar menu item */
1379# endif
1380
1381 /* No parent, must be a non-menubar menu */
1382 if (parent->submenu_id == (Widget)0)
1383 return;
1384
1385 menu->submenu_id = (Widget)0;
1386
1387 /* Add menu separator */
1388 if (menu_is_separator(menu->name))
1389 {
1390 menu->id = XtVaCreateWidget("subMenu",
1391 xmSeparatorGadgetClass, parent->submenu_id,
1392#if (XmVersion >= 1002)
1393 /* count the tearoff item (needed for LessTif) */
1394 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1395 ? 1 : 0),
1396#endif
1397 NULL);
1398 gui_motif_menu_colors(menu->id);
1399 return;
1400 }
1401
1402 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1403 if (label == NULL)
1404 return;
1405 menu->id = XtVaCreateWidget("subMenu",
1406 xmPushButtonWidgetClass, parent->submenu_id,
1407 XmNlabelString, label,
1408 XmNmnemonic, menu->mnemonic,
1409#if (XmVersion >= 1002)
1410 /* count the tearoff item (needed for LessTif) */
1411 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1412 ? 1 : 0),
1413#endif
1414 NULL);
1415 gui_motif_menu_colors(menu->id);
1416 gui_motif_menu_fontlist(menu->id);
1417 XmStringFree(label);
1418
1419 if (menu->id != (Widget)0)
1420 {
1421 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1422 (XtPointer)menu);
1423 /* add accelerator text */
1424 gui_motif_add_actext(menu);
1425 }
1426}
1427
1428#if (XmVersion <= 1002) || defined(PROTO)
1429/*
1430 * This function will destroy/create the popup menus dynamically,
1431 * according to the value of 'mousemodel'.
1432 * This will fix the "right mouse button freeze" that occurs when
1433 * there exists a popup menu but it isn't managed.
1434 */
1435 void
1436gui_motif_update_mousemodel(menu)
1437 vimmenu_T *menu;
1438{
1439 int idx = 0;
1440
1441 /* When GUI hasn't started the menus have not been created. */
1442 if (!gui.in_use)
1443 return;
1444
1445 while (menu)
1446 {
1447 if (menu->children != NULL)
1448 {
1449 if (menu_is_popup(menu->name))
1450 {
1451 if (mouse_model_popup())
1452 {
1453 /* Popup menu will be used. Create the popup menus. */
1454 gui_mch_add_menu(menu, idx);
1455 gui_motif_update_mousemodel(menu->children);
1456 }
1457 else
1458 {
1459 /* Popup menu will not be used. Destroy the popup menus. */
1460 gui_motif_update_mousemodel(menu->children);
1461 gui_mch_destroy_menu(menu);
1462 }
1463 }
1464 }
1465 else if (menu_is_child_of_popup(menu))
1466 {
1467 if (mouse_model_popup())
1468 gui_mch_add_menu_item(menu, idx);
1469 else
1470 gui_mch_destroy_menu(menu);
1471 }
1472 menu = menu->next;
1473 ++idx;
1474 }
1475}
1476#endif
1477
1478 void
1479gui_mch_new_menu_colors()
1480{
1481 if (menuBar == (Widget)0)
1482 return;
1483 gui_motif_menu_colors(menuBar);
1484#ifdef FEAT_TOOLBAR
1485 gui_motif_menu_colors(toolBarFrame);
1486 gui_motif_menu_colors(toolBar);
1487#endif
1488
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001489 submenu_change(root_menu, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490}
1491
1492 void
1493gui_mch_new_menu_font()
1494{
1495 if (menuBar == (Widget)0)
1496 return;
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001497 submenu_change(root_menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {
1499 Dimension height;
1500 Position w, h;
1501
1502 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1503 gui.menu_height = height;
1504
1505 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1506 gui_resize_shell(w, h
1507#ifdef FEAT_XIM
1508 - xim_get_status_area_height()
1509#endif
1510 );
1511 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00001512 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 ui_new_shellsize();
1514}
1515
1516#if defined(FEAT_BEVAL) || defined(PROTO)
1517 void
1518gui_mch_new_tooltip_font()
1519{
1520# ifdef FEAT_TOOLBAR
1521 vimmenu_T *menu;
1522
1523 if (toolBar == (Widget)0)
1524 return;
1525
1526 menu = gui_find_menu((char_u *)"ToolBar");
1527 if (menu != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001528 submenu_change(menu, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529# endif
1530}
1531
1532 void
1533gui_mch_new_tooltip_colors()
1534{
1535# ifdef FEAT_TOOLBAR
1536 vimmenu_T *toolbar;
1537
1538 if (toolBar == (Widget)0)
1539 return;
1540
1541 toolbar = gui_find_menu((char_u *)"ToolBar");
1542 if (toolbar != NULL)
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001543 submenu_change(toolbar, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544# endif
1545}
1546#endif
1547
1548 static void
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001549submenu_change(menu, colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 vimmenu_T *menu;
1551 int colors; /* TRUE for colors, FALSE for font */
1552{
1553 vimmenu_T *mp;
1554
1555 for (mp = menu; mp != NULL; mp = mp->next)
1556 {
1557 if (mp->id != (Widget)0)
1558 {
1559 if (colors)
1560 {
1561 gui_motif_menu_colors(mp->id);
1562#ifdef FEAT_TOOLBAR
1563 /* For a toolbar item: Free the pixmap and allocate a new one,
1564 * so that the background color is right. */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001565 if (mp->xpm != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001567 int n = 0;
1568 Arg args[18];
1569
Bram Moolenaar7c626922005-02-07 22:01:03 +00001570 n = add_pixmap_args(mp, args, n);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00001571 XtSetValues(mp->id, args, n);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 }
1573# ifdef FEAT_BEVAL
1574 /* If we have a tooltip, then we need to change it's font */
1575 if (mp->tip != NULL)
1576 {
1577 Arg args[2];
1578
1579 args[0].name = XmNbackground;
1580 args[0].value = gui.tooltip_bg_pixel;
1581 args[1].name = XmNforeground;
1582 args[1].value = gui.tooltip_fg_pixel;
1583 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1584 }
1585# endif
1586#endif
1587 }
1588 else
1589 {
1590 gui_motif_menu_fontlist(mp->id);
1591#ifdef FEAT_BEVAL
1592 /* If we have a tooltip, then we need to change it's font */
1593 if (mp->tip != NULL)
1594 {
1595 Arg args[1];
1596
1597 args[0].name = XmNfontList;
1598 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1599 &gui.tooltip_fontset);
1600 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1601 }
1602#endif
1603 }
1604 }
1605
1606 if (mp->children != NULL)
1607 {
1608#if (XmVersion >= 1002)
1609 /* Set the colors/font for the tear off widget */
1610 if (mp->submenu_id != (Widget)0)
1611 {
1612 if (colors)
1613 gui_motif_menu_colors(mp->submenu_id);
1614 else
1615 gui_motif_menu_fontlist(mp->submenu_id);
1616 toggle_tearoff(mp->submenu_id);
1617 }
1618#endif
1619 /* Set the colors for the children */
Bram Moolenaarf9980f12005-01-03 20:58:59 +00001620 submenu_change(mp->children, colors);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 }
1622 }
1623}
1624
1625/*
1626 * Destroy the machine specific menu widget.
1627 */
1628 void
1629gui_mch_destroy_menu(menu)
1630 vimmenu_T *menu;
1631{
1632 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1633 * On the other hand, problems have been reported that the submenu must be
1634 * deleted first...
1635 *
1636 * This code should be basically identical to that in the file gui_athena.c
1637 * because they are both Xt based.
1638 */
1639 if (menu->submenu_id != (Widget)0)
1640 {
1641 XtDestroyWidget(menu->submenu_id);
1642 menu->submenu_id = (Widget)0;
1643 }
1644
1645 if (menu->id != (Widget)0)
1646 {
1647 Widget parent;
1648
1649 parent = XtParent(menu->id);
1650#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)
Bram Moolenaar4317d9b2005-03-18 20:25:31 +00001651 if (parent == toolBar && menu->tip != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 {
1653 /* We try to destroy this before the actual menu, because there are
1654 * callbacks, etc. that will be unregistered during the tooltip
1655 * destruction.
1656 *
1657 * If you call "gui_mch_destroy_beval_area()" after destroying
1658 * menu->id, then the tooltip's window will have already been
1659 * deallocated by Xt, and unknown behaviour will ensue (probably
1660 * a core dump).
1661 */
1662 gui_mch_destroy_beval_area(menu->tip);
1663 menu->tip = NULL;
1664 }
1665#endif
1666 XtDestroyWidget(menu->id);
1667 menu->id = (Widget)0;
1668 if (parent == menuBar)
1669 gui_mch_compute_menu_height((Widget)0);
1670#ifdef FEAT_TOOLBAR
1671 else if (parent == toolBar)
1672 {
1673 Cardinal num_children;
1674
1675 /* When removing last toolbar item, don't display the toolbar. */
1676 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1677 if (num_children == 0)
1678 gui_mch_show_toolbar(FALSE);
1679 else
1680 gui.toolbar_height = gui_mch_compute_toolbar_height();
1681 }
1682#endif
1683 }
1684}
1685
1686/* ARGSUSED */
1687 void
1688gui_mch_show_popupmenu(menu)
1689 vimmenu_T *menu;
1690{
1691#ifdef MOTIF_POPUP
1692 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1693 XtManageChild(menu->submenu_id);
1694#endif
1695}
1696
1697#endif /* FEAT_MENU */
1698
1699/*
1700 * Set the menu and scrollbar colors to their default values.
1701 */
1702 void
1703gui_mch_def_colors()
1704{
1705 if (gui.in_use)
1706 {
1707 /* Use the values saved when starting up. These should come from the
1708 * window manager or a resources file. */
1709 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1710 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1711 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1712 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
1713#ifdef FEAT_BEVAL
1714 gui.tooltip_fg_pixel =
1715 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1716 gui.tooltip_bg_pixel =
1717 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1718#endif
1719 }
1720}
1721
1722
1723/*
1724 * Scrollbar stuff.
1725 */
1726
1727 void
1728gui_mch_set_scrollbar_thumb(sb, val, size, max)
1729 scrollbar_T *sb;
1730 long val;
1731 long size;
1732 long max;
1733{
1734 if (sb->id != (Widget)0)
1735 XtVaSetValues(sb->id,
1736 XmNvalue, val,
1737 XmNsliderSize, size,
1738 XmNpageIncrement, (size > 2 ? size - 2 : 1),
1739 XmNmaximum, max + 1, /* Motif has max one past the end */
1740 NULL);
1741}
1742
1743 void
1744gui_mch_set_scrollbar_pos(sb, x, y, w, h)
1745 scrollbar_T *sb;
1746 int x;
1747 int y;
1748 int w;
1749 int h;
1750{
1751 if (sb->id != (Widget)0)
1752 {
1753 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1754 {
1755 if (y == 0)
1756 h -= gui.border_offset;
1757 else
1758 y -= gui.border_offset;
1759 XtVaSetValues(sb->id,
1760 XmNtopOffset, y,
1761 XmNbottomOffset, -y - h,
1762 XmNwidth, w,
1763 NULL);
1764 }
1765 else
1766 XtVaSetValues(sb->id,
1767 XmNtopOffset, y,
1768 XmNleftOffset, x,
1769 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1770 ? gui.scrollbar_width : 0,
1771 XmNheight, h,
1772 NULL);
1773 XtManageChild(sb->id);
1774 }
1775}
1776
1777 void
1778gui_mch_enable_scrollbar(sb, flag)
1779 scrollbar_T *sb;
1780 int flag;
1781{
1782 Arg args[16];
1783 int n;
1784
1785 if (sb->id != (Widget)0)
1786 {
1787 n = 0;
1788 if (flag)
1789 {
1790 switch (sb->type)
1791 {
1792 case SBAR_LEFT:
1793 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1794 break;
1795
1796 case SBAR_RIGHT:
1797 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1798 break;
1799
1800 case SBAR_BOTTOM:
1801 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1802 break;
1803 }
1804 XtSetValues(textArea, args, n);
1805 XtManageChild(sb->id);
1806 }
1807 else
1808 {
1809 if (!gui.which_scrollbars[sb->type])
1810 {
1811 /* The scrollbars of this type are all disabled, adjust the
1812 * textArea attachment offset. */
1813 switch (sb->type)
1814 {
1815 case SBAR_LEFT:
1816 XtSetArg(args[n], XmNleftOffset, 0); n++;
1817 break;
1818
1819 case SBAR_RIGHT:
1820 XtSetArg(args[n], XmNrightOffset, 0); n++;
1821 break;
1822
1823 case SBAR_BOTTOM:
1824 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1825 break;
1826 }
1827 XtSetValues(textArea, args, n);
1828 }
1829 XtUnmanageChild(sb->id);
1830 }
1831 }
1832}
1833
1834 void
1835gui_mch_create_scrollbar(sb, orient)
1836 scrollbar_T *sb;
1837 int orient; /* SBAR_VERT or SBAR_HORIZ */
1838{
1839 Arg args[16];
1840 int n;
1841
1842 n = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 XtSetArg(args[n], XmNminimum, 0); n++;
1844 XtSetArg(args[n], XmNorientation,
1845 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1846
1847 switch (sb->type)
1848 {
1849 case SBAR_LEFT:
1850 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1851 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1852 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1853 break;
1854
1855 case SBAR_RIGHT:
1856 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1857 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1858 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1859 break;
1860
1861 case SBAR_BOTTOM:
1862 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1863 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1864 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1865 break;
1866 }
1867
1868 sb->id = XtCreateWidget("scrollBar",
1869 xmScrollBarWidgetClass, textAreaForm, args, n);
1870
1871 /* Remember the default colors, needed for ":hi clear". */
1872 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1873 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1874 XtVaGetValues(sb->id,
1875 XmNbackground, &gui.scroll_def_bg_pixel,
1876 XmNforeground, &gui.scroll_def_fg_pixel,
1877 NULL);
1878
1879 if (sb->id != (Widget)0)
1880 {
1881 gui_mch_set_scrollbar_colors(sb);
1882 XtAddCallback(sb->id, XmNvalueChangedCallback,
1883 scroll_cb, (XtPointer)sb->ident);
1884 XtAddCallback(sb->id, XmNdragCallback,
1885 scroll_cb, (XtPointer)sb->ident);
1886 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1887 (XtPointer)0);
1888 }
1889}
1890
1891#if defined(FEAT_WINDOWS) || defined(PROTO)
1892 void
1893gui_mch_destroy_scrollbar(sb)
1894 scrollbar_T *sb;
1895{
1896 if (sb->id != (Widget)0)
1897 XtDestroyWidget(sb->id);
1898}
1899#endif
1900
1901 void
1902gui_mch_set_scrollbar_colors(sb)
1903 scrollbar_T *sb;
1904{
1905 if (sb->id != (Widget)0)
1906 {
1907 if (gui.scroll_bg_pixel != INVALCOLOR)
1908 {
1909#if (XmVersion>=1002)
1910 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1911#else
1912 XtVaSetValues(sb->id,
1913 XmNtroughColor, gui.scroll_bg_pixel,
1914 NULL);
1915#endif
1916 }
1917
1918 if (gui.scroll_fg_pixel != INVALCOLOR)
1919 XtVaSetValues(sb->id,
1920 XmNforeground, gui.scroll_fg_pixel,
1921#if (XmVersion<1002)
1922 XmNbackground, gui.scroll_fg_pixel,
1923#endif
1924 NULL);
1925 }
1926
1927 /* This is needed for the rectangle below the vertical scrollbars. */
1928 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1929 gui_motif_scroll_colors(textAreaForm);
1930}
1931
1932/*
1933 * Miscellaneous stuff:
1934 */
1935
1936 Window
1937gui_x11_get_wid()
1938{
1939 return(XtWindow(textArea));
1940}
1941
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001942/*
1943 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1944 * When one is found, simulate a button press on that widget and give it the
1945 * keyboard focus. If the mnemonic is on a label, look in the userData field
1946 * of the label to see if it points to another widget, and give that the focus.
1947 */
1948 static void
1949do_mnemonic(Widget w, unsigned int keycode)
1950{
1951 WidgetList children;
1952 int numChildren, i;
1953 Boolean isMenu;
1954 KeySym mnemonic = '\0';
1955 char mneString[2];
1956 Widget userData;
1957 unsigned char rowColType;
1958
1959 if (XtIsComposite(w))
1960 {
1961 if (XtClass(w) == xmRowColumnWidgetClass)
1962 {
1963 XtVaGetValues(w, XmNrowColumnType, &rowColType, 0);
1964 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1965 }
1966 else
1967 isMenu = False;
1968 if (!isMenu)
1969 {
1970 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
1971 &numChildren, 0);
1972 for (i = 0; i < numChildren; i++)
1973 do_mnemonic(children[i], keycode);
1974 }
1975 }
1976 else
1977 {
1978 XtVaGetValues(w, XmNmnemonic, &mnemonic, 0);
1979 if (mnemonic != '\0')
1980 {
1981 mneString[0] = mnemonic;
1982 mneString[1] = '\0';
1983 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1984 XStringToKeysym(mneString)) == keycode)
1985 {
1986 if (XtClass(w) == xmLabelWidgetClass
1987 || XtClass(w) == xmLabelGadgetClass)
1988 {
1989 XtVaGetValues(w, XmNuserData, &userData, 0);
1990 if (userData != NULL && XtIsWidget(userData))
1991 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1992 }
1993 else
1994 {
1995 XKeyPressedEvent keyEvent;
1996
1997 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1998
1999 memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
2000 keyEvent.type = KeyPress;
2001 keyEvent.serial = 1;
2002 keyEvent.send_event = True;
2003 keyEvent.display = XtDisplay(w);
2004 keyEvent.window = XtWindow(w);
2005 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
2006 NULL, 0);
2007 }
2008 }
2009 }
2010 }
2011}
2012
2013/*
2014 * Callback routine for dialog mnemonic processing.
2015 */
2016/*ARGSUSED*/
2017 static void
2018mnemonic_event(Widget w, XtPointer call_data, XKeyEvent *event)
2019{
2020 do_mnemonic(w, event->keycode);
2021}
2022
2023
2024/*
2025 * Search the widget tree under w for widgets with mnemonics. When found, add
2026 * a passive grab to the dialog widget for the mnemonic character, thus
2027 * directing mnemonic events to the dialog widget.
2028 */
2029 static void
2030add_mnemonic_grabs(Widget dialog, Widget w)
2031{
2032 char mneString[2];
2033 WidgetList children;
2034 int numChildren, i;
2035 Boolean isMenu;
2036 KeySym mnemonic = '\0';
2037 unsigned char rowColType;
2038
2039 if (XtIsComposite(w))
2040 {
2041 if (XtClass(w) == xmRowColumnWidgetClass)
2042 {
2043 XtVaGetValues(w, XmNrowColumnType, &rowColType, 0);
2044 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2045 }
2046 else
2047 isMenu = False;
2048 if (!isMenu)
2049 {
2050 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
2051 &numChildren, 0);
2052 for (i = 0; i < numChildren; i++)
2053 add_mnemonic_grabs(dialog, children[i]);
2054 }
2055 }
2056 else
2057 {
2058 XtVaGetValues(w, XmNmnemonic, &mnemonic, 0);
2059 if (mnemonic != '\0')
2060 {
2061 mneString[0] = mnemonic;
2062 mneString[1] = '\0';
2063 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2064 XStringToKeysym(mneString)),
2065 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2066 }
2067 }
2068}
2069
2070/*
2071 * Add a handler for mnemonics in a dialog. Motif itself only handles
2072 * mnemonics in menus. Mnemonics added or changed after this call will be
2073 * ignored.
2074 *
2075 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2076 * the appropriate label and set the XmNuserData resource of the label to the
2077 * widget to get the focus when the mnemonic is typed.
2078 */
2079 static void
2080activate_dialog_mnemonics(Widget dialog)
2081{
2082 if (!dialog)
2083 return;
2084
2085 XtAddEventHandler(dialog, KeyPressMask, False,
2086 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2087 add_mnemonic_grabs(dialog, dialog);
2088}
2089
2090/*
2091 * Removes the event handler and key-grabs for dialog mnemonic handling.
2092 */
2093 static void
2094suppress_dialog_mnemonics(Widget dialog)
2095{
2096 if (!dialog)
2097 return;
2098
2099 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2100 XtRemoveEventHandler(dialog, KeyPressMask, False,
2101 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2102}
2103
2104#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
2105static void set_fontlist __ARGS((Widget wg));
2106
2107/*
2108 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2109 */
2110 static void
2111set_fontlist(id)
2112 Widget id;
2113{
2114 XmFontList fl;
2115
2116#ifdef FONTSET_ALWAYS
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002117 if (gui.fontset != NOFONTSET)
2118 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002119 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2120 if (fl != NULL)
2121 {
2122 if (XtIsManaged(id))
2123 {
2124 XtUnmanageChild(id);
2125 XtVaSetValues(id, XmNfontList, fl, NULL);
2126 /* We should force the widget to recalculate it's
2127 * geometry now. */
2128 XtManageChild(id);
2129 }
2130 else
2131 XtVaSetValues(id, XmNfontList, fl, NULL);
2132 XmFontListFree(fl);
2133 }
2134 }
2135#else
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00002136 if (gui.norm_font != NOFONT)
2137 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002138 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2139 if (fl != NULL)
2140 {
2141 if (XtIsManaged(id))
2142 {
2143 XtUnmanageChild(id);
2144 XtVaSetValues(id, XmNfontList, fl, NULL);
2145 /* We should force the widget to recalculate it's
2146 * geometry now. */
2147 XtManageChild(id);
2148 }
2149 else
2150 XtVaSetValues(id, XmNfontList, fl, NULL);
2151 XmFontListFree(fl);
2152 }
2153 }
2154#endif
2155}
2156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002157
2158#if defined(FEAT_BROWSE) || defined(PROTO)
2159
2160/*
2161 * file selector related stuff
2162 */
2163
2164#include <Xm/FileSB.h>
2165#include <Xm/XmStrDefs.h>
2166
2167typedef struct dialog_callback_arg
2168{
2169 char * args; /* not used right now */
2170 int id;
2171} dcbarg_T;
2172
2173static Widget dialog_wgt;
2174static char *browse_fname = NULL;
2175static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2176 /* used to set up XmStrings */
2177
2178static void DialogCancelCB __ARGS((Widget, XtPointer, XtPointer));
2179static void DialogAcceptCB __ARGS((Widget, XtPointer, XtPointer));
2180
2181/*
2182 * This function is used to translate the predefined label text of the
2183 * precomposed dialogs. We do this explicitly to allow:
2184 *
2185 * - usage of gettext for translation, as in all the other places.
2186 *
2187 * - equalize the messages between different GUI implementations as far as
2188 * possible.
2189 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002190static void set_predefined_label __ARGS((Widget parent, String name, char *new_label));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191
2192static void
2193set_predefined_label(parent, name, new_label)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002194 Widget parent;
2195 String name;
2196 char *new_label;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002198 XmString str;
2199 Widget w;
2200 char_u *p, *next;
2201 KeySym mnemonic = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202
2203 w = XtNameToWidget(parent, name);
2204
2205 if (!w)
2206 return;
2207
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002208 p = vim_strsave((char_u *)new_label);
2209 if (p == NULL)
2210 return;
2211 for (next = p; *next; ++next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002213 if (*next == DLG_HOTKEY_CHAR)
2214 {
2215 int len = STRLEN(next);
2216
2217 if (len > 0)
2218 {
2219 mch_memmove(next, next + 1, len);
2220 mnemonic = next[0];
2221 }
2222 }
2223 }
2224
2225 str = XmStringCreate((char *)p, STRING_TAG);
2226 vim_free(p);
2227
2228 if (str != NULL)
2229 {
2230 XtVaSetValues(w,
2231 XmNlabelString, str,
2232 XmNmnemonic, mnemonic,
2233 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 XmStringFree(str);
2235 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002236 gui_motif_menu_fontlist(w);
2237}
2238
2239static void
2240set_predefined_fontlist(parent, name)
2241 Widget parent;
2242 String name;
2243{
2244 Widget w;
2245 w = XtNameToWidget(parent, name);
2246
2247 if (!w)
2248 return;
2249
2250 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251}
2252
2253/*
2254 * Put up a file requester.
2255 * Returns the selected name in allocated memory, or NULL for Cancel.
2256 */
2257/* ARGSUSED */
2258 char_u *
2259gui_mch_browse(saving, title, dflt, ext, initdir, filter)
2260 int saving; /* select file to write */
2261 char_u *title; /* title for the window */
2262 char_u *dflt; /* default name */
2263 char_u *ext; /* not used (extension added) */
2264 char_u *initdir; /* initial directory, NULL for current dir */
2265 char_u *filter; /* file name filter */
2266{
2267 char_u dirbuf[MAXPATHL];
2268 char_u dfltbuf[MAXPATHL];
2269 char_u *pattern;
2270 char_u *tofree = NULL;
2271
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002272 /* There a difference between the resource name and value, Therefore, we
2273 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2274 * dialog name.
2275 */
2276
2277 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278
2279 if (initdir == NULL || *initdir == NUL)
2280 {
2281 mch_dirname(dirbuf, MAXPATHL);
2282 initdir = dirbuf;
2283 }
2284
2285 if (dflt == NULL)
2286 dflt = (char_u *)"";
2287 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2288 {
2289 /* The default selection should be the full path, "dflt" is only the
2290 * file name. */
2291 STRCPY(dfltbuf, initdir);
2292 add_pathsep(dfltbuf);
2293 STRCAT(dfltbuf, dflt);
2294 dflt = dfltbuf;
2295 }
2296
2297 /* Can only use one pattern for a file name. Get the first pattern out of
2298 * the filter. An empty pattern means everything matches. */
2299 if (filter == NULL)
2300 pattern = (char_u *)"";
2301 else
2302 {
2303 char_u *s, *p;
2304
2305 s = filter;
2306 for (p = filter; *p != NUL; ++p)
2307 {
2308 if (*p == '\t') /* end of description, start of pattern */
2309 s = p + 1;
2310 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2311 break;
2312 }
2313 pattern = vim_strnsave(s, p - s);
2314 tofree = pattern;
2315 if (pattern == NULL)
2316 pattern = (char_u *)"";
2317 }
2318
2319 XtVaSetValues(dialog_wgt,
2320 XtVaTypedArg,
2321 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2322 XtVaTypedArg,
2323 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2324 XtVaTypedArg,
2325 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2326 XtVaTypedArg,
2327 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2328 NULL);
2329
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002330 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2331 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2333 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002334 set_predefined_label(dialog_wgt, "Help", _("&Help"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 set_predefined_label(dialog_wgt, "Items", _("Files"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002336 set_predefined_label(dialog_wgt, "OK", _("&OK"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2338
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002339 /* This is to save us from silly external settings using not fixed with
2340 * fonts for file selection.
2341 */
2342 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2343 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2344
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 gui_motif_menu_colors(dialog_wgt);
2346 if (gui.scroll_bg_pixel != INVALCOLOR)
2347 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2348
2349 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2350 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2351 /* We have no help in this window, so hide help button */
2352 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2353 (unsigned char)XmDIALOG_HELP_BUTTON));
2354
2355 manage_centered(dialog_wgt);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002356 activate_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357
2358 /* sit in a loop until the dialog box has gone away */
2359 do
2360 {
2361 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2362 (XtInputMask)XtIMAll);
2363 } while (XtIsManaged(dialog_wgt));
2364
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002365 suppress_dialog_mnemonics(dialog_wgt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 XtDestroyWidget(dialog_wgt);
2367 vim_free(tofree);
2368
2369 if (browse_fname == NULL)
2370 return NULL;
2371 return vim_strsave((char_u *)browse_fname);
2372}
2373
2374/*
2375 * The code below was originally taken from
2376 * /usr/examples/motif/xmsamplers/xmeditor.c
2377 * on Digital Unix 4.0d, but heavily modified.
2378 */
2379
2380/*
2381 * Process callback from Dialog cancel actions.
2382 */
2383/* ARGSUSED */
2384 static void
2385DialogCancelCB(w, client_data, call_data)
2386 Widget w; /* widget id */
2387 XtPointer client_data; /* data from application */
2388 XtPointer call_data; /* data from widget class */
2389{
2390 if (browse_fname != NULL)
2391 {
2392 XtFree(browse_fname);
2393 browse_fname = NULL;
2394 }
2395 XtUnmanageChild(dialog_wgt);
2396}
2397
2398/*
2399 * Process callback from Dialog actions.
2400 */
2401/* ARGSUSED */
2402 static void
2403DialogAcceptCB(w, client_data, call_data)
2404 Widget w; /* widget id */
2405 XtPointer client_data; /* data from application */
2406 XtPointer call_data; /* data from widget class */
2407{
2408 XmFileSelectionBoxCallbackStruct *fcb;
2409
2410 if (browse_fname != NULL)
2411 {
2412 XtFree(browse_fname);
2413 browse_fname = NULL;
2414 }
2415 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2416
2417 /* get the filename from the file selection box */
2418 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2419
2420 /* popdown the file selection box */
2421 XtUnmanageChild(dialog_wgt);
2422}
2423
2424#endif /* FEAT_BROWSE */
2425
2426#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2427
2428static int dialogStatus;
2429
2430static void keyhit_callback __ARGS((Widget w, XtPointer client_data, XEvent *event, Boolean *cont));
2431static void butproc __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
2432
2433/*
2434 * Callback function for the textfield. When CR is hit this works like
2435 * hitting the "OK" button, ESC like "Cancel".
2436 */
2437/* ARGSUSED */
2438 static void
2439keyhit_callback(w, client_data, event, cont)
2440 Widget w;
2441 XtPointer client_data;
2442 XEvent *event;
2443 Boolean *cont;
2444{
2445 char buf[2];
2446 KeySym key_sym;
2447
2448 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2449 {
2450 if (*buf == CAR)
2451 dialogStatus = 1;
2452 else if (*buf == ESC)
2453 dialogStatus = 2;
2454 }
2455 if ((key_sym == XK_Left || key_sym == XK_Right)
2456 && !(event->xkey.state & ShiftMask))
2457 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2458}
2459
2460/* ARGSUSED */
2461 static void
2462butproc(w, client_data, call_data)
2463 Widget w;
2464 XtPointer client_data;
2465 XtPointer call_data;
2466{
2467 dialogStatus = (int)(long)client_data + 1;
2468}
2469
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470#ifdef HAVE_XPM
2471
2472static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg);
2473
2474 static Widget
2475create_pixmap_label(parent, name, data, args, arg)
2476 Widget parent;
2477 String name;
2478 char **data;
2479 ArgList args;
2480 Cardinal arg;
2481{
2482 Widget label;
2483 Display *dsp;
2484 Screen *scr;
2485 int depth;
2486 Pixmap pixmap = 0;
2487 XpmAttributes attr;
2488 Boolean rs;
2489 XpmColorSymbol color[5] =
2490 {
2491 {"none", NULL, 0},
2492 {"iconColor1", NULL, 0},
2493 {"bottomShadowColor", NULL, 0},
2494 {"topShadowColor", NULL, 0},
2495 {"selectColor", NULL, 0}
2496 };
2497
2498 label = XmCreateLabelGadget(parent, name, args, arg);
2499
2500 /*
2501 * We need to be carefull here, since in case of gadgets, there is
2502 * no way to get the background color directly from the widget itself.
2503 * In such cases we get it from The Core part of his parent instead.
2504 */
2505 dsp = XtDisplayOfObject(label);
2506 scr = XtScreenOfObject(label);
2507 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2508 ? label : XtParent(label),
2509 XmNdepth, &depth,
2510 XmNbackground, &color[0].pixel,
2511 XmNforeground, &color[1].pixel,
2512 XmNbottomShadowColor, &color[2].pixel,
2513 XmNtopShadowColor, &color[3].pixel,
2514 XmNhighlight, &color[4].pixel,
2515 NULL);
2516
2517 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2518 attr.colorsymbols = color;
2519 attr.numsymbols = 5;
2520 attr.closeness = 65535;
2521 attr.depth = depth;
2522 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2523 data, &pixmap, NULL, &attr);
2524
2525 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2526 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2527 XtVaSetValues(label,
2528 XmNlabelType, XmPIXMAP,
2529 XmNlabelPixmap, pixmap,
2530 NULL);
2531 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2532
2533 return label;
2534}
2535#endif
2536
2537/* ARGSUSED */
2538 int
2539gui_mch_dialog(type, title, message, button_names, dfltbutton, textfield)
2540 int type;
2541 char_u *title;
2542 char_u *message;
2543 char_u *button_names;
2544 int dfltbutton;
2545 char_u *textfield; /* buffer of size IOSIZE */
2546{
2547 char_u *buts;
2548 char_u *p, *next;
2549 XtAppContext app;
2550 XmString label;
2551 int butcount;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002552 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 Widget dialogform = NULL;
2554 Widget form = NULL;
2555 Widget dialogtextfield = NULL;
2556 Widget *buttons;
2557 Widget sep_form = NULL;
2558 Boolean vertical;
2559 Widget separator = NULL;
2560 int n;
2561 Arg args[6];
2562#ifdef HAVE_XPM
2563 char **icon_data = NULL;
2564 Widget dialogpixmap = NULL;
2565#endif
2566
2567 if (title == NULL)
2568 title = (char_u *)_("Vim dialog");
2569
2570 /* if our pointer is currently hidden, then we should show it. */
2571 gui_mch_mousehide(FALSE);
2572
2573 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2574
2575 /* Check 'v' flag in 'guioptions': vertical button placement. */
2576 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2577
2578 /* Set the title of the Dialog window */
2579 label = XmStringCreateSimple((char *)title);
2580 if (label == NULL)
2581 return -1;
2582 XtVaSetValues(dialogform,
2583 XmNdialogTitle, label,
2584 XmNhorizontalSpacing, 4,
2585 XmNverticalSpacing, vertical ? 0 : 4,
2586 NULL);
2587 XmStringFree(label);
2588
2589 /* make a copy, so that we can insert NULs */
2590 buts = vim_strsave(button_names);
2591 if (buts == NULL)
2592 return -1;
2593
2594 /* Count the number of buttons and allocate buttons[]. */
2595 butcount = 1;
2596 for (p = buts; *p; ++p)
2597 if (*p == DLG_BUTTON_SEP)
2598 ++butcount;
2599 buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
2600 if (buttons == NULL)
2601 {
2602 vim_free(buts);
2603 return -1;
2604 }
2605
2606 /*
2607 * Create the buttons.
2608 */
2609 sep_form = (Widget) 0;
2610 p = buts;
2611 for (butcount = 0; *p; ++butcount)
2612 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002613 KeySym mnemonic = NUL;
2614
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 for (next = p; *next; ++next)
2616 {
2617 if (*next == DLG_HOTKEY_CHAR)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002618 {
2619 int len = STRLEN(next);
2620
2621 if (len > 0)
2622 {
2623 mch_memmove(next, next + 1, len);
2624 mnemonic = next[0];
2625 }
2626 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 if (*next == DLG_BUTTON_SEP)
2628 {
2629 *next++ = NUL;
2630 break;
2631 }
2632 }
2633 label = XmStringCreate(_((char *)p), STRING_TAG);
2634 if (label == NULL)
2635 break;
2636
2637 buttons[butcount] = XtVaCreateManagedWidget("button",
2638 xmPushButtonWidgetClass, dialogform,
2639 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002640 XmNmnemonic, mnemonic,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 XmNbottomAttachment, XmATTACH_FORM,
2642 XmNbottomOffset, 4,
2643 XmNshowAsDefault, butcount == dfltbutton - 1,
2644 XmNdefaultButtonShadowThickness, 1,
2645 NULL);
2646 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002647 gui_motif_menu_fontlist(buttons[butcount]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648
2649 /* Layout properly. */
2650
2651 if (butcount > 0)
2652 {
2653 if (vertical)
2654 XtVaSetValues(buttons[butcount],
2655 XmNtopWidget, buttons[butcount - 1],
2656 NULL);
2657 else
2658 {
2659 if (*next == NUL)
2660 {
2661 XtVaSetValues(buttons[butcount],
2662 XmNrightAttachment, XmATTACH_FORM,
2663 XmNrightOffset, 4,
2664 NULL);
2665
2666 /* fill in a form as invisible separator */
2667 sep_form = XtVaCreateWidget("separatorForm",
2668 xmFormWidgetClass, dialogform,
2669 XmNleftAttachment, XmATTACH_WIDGET,
2670 XmNleftWidget, buttons[butcount - 1],
2671 XmNrightAttachment, XmATTACH_WIDGET,
2672 XmNrightWidget, buttons[butcount],
2673 XmNbottomAttachment, XmATTACH_FORM,
2674 XmNbottomOffset, 4,
2675 NULL);
2676 XtManageChild(sep_form);
2677 }
2678 else
2679 {
2680 XtVaSetValues(buttons[butcount],
2681 XmNleftAttachment, XmATTACH_WIDGET,
2682 XmNleftWidget, buttons[butcount - 1],
2683 NULL);
2684 }
2685 }
2686 }
2687 else if (!vertical)
2688 {
2689 if (*next == NUL)
2690 {
2691 XtVaSetValues(buttons[0],
2692 XmNrightAttachment, XmATTACH_FORM,
2693 XmNrightOffset, 4,
2694 NULL);
2695
2696 /* fill in a form as invisible separator */
2697 sep_form = XtVaCreateWidget("separatorForm",
2698 xmFormWidgetClass, dialogform,
2699 XmNleftAttachment, XmATTACH_FORM,
2700 XmNleftOffset, 4,
2701 XmNrightAttachment, XmATTACH_WIDGET,
2702 XmNrightWidget, buttons[0],
2703 XmNbottomAttachment, XmATTACH_FORM,
2704 XmNbottomOffset, 4,
2705 NULL);
2706 XtManageChild(sep_form);
2707 }
2708 else
2709 XtVaSetValues(buttons[0],
2710 XmNleftAttachment, XmATTACH_FORM,
2711 XmNleftOffset, 4,
2712 NULL);
2713 }
2714
2715 XtAddCallback(buttons[butcount], XmNactivateCallback,
2716 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2717 p = next;
2718 }
2719 vim_free(buts);
2720
2721 separator = (Widget) 0;
2722 if (butcount > 0)
2723 {
2724 /* Create the separator for beauty. */
2725 n = 0;
2726 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2727 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2728 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2729 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2730 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2731 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2732 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2733 XtManageChild(separator);
2734 }
2735
2736 if (textfield != NULL)
2737 {
2738 dialogtextfield = XtVaCreateWidget("textField",
2739 xmTextFieldWidgetClass, dialogform,
2740 XmNleftAttachment, XmATTACH_FORM,
2741 XmNrightAttachment, XmATTACH_FORM,
2742 NULL);
2743 if (butcount > 0)
2744 XtVaSetValues(dialogtextfield,
2745 XmNbottomAttachment, XmATTACH_WIDGET,
2746 XmNbottomWidget, separator,
2747 NULL);
2748 else
2749 XtVaSetValues(dialogtextfield,
2750 XmNbottomAttachment, XmATTACH_FORM,
2751 NULL);
2752
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002753 set_fontlist(dialogtextfield);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2755 XtManageChild(dialogtextfield);
2756 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2757 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2758 }
2759
2760 /* Form holding both message and pixmap labels */
2761 form = XtVaCreateWidget("separatorForm",
2762 xmFormWidgetClass, dialogform,
2763 XmNleftAttachment, XmATTACH_FORM,
2764 XmNrightAttachment, XmATTACH_FORM,
2765 XmNtopAttachment, XmATTACH_FORM,
2766 NULL);
2767 XtManageChild(form);
2768
2769#ifdef HAVE_XPM
2770 /* Add a pixmap, left of the message. */
2771 switch (type)
2772 {
2773 case VIM_GENERIC:
2774 icon_data = generic_xpm;
2775 break;
2776 case VIM_ERROR:
2777 icon_data = error_xpm;
2778 break;
2779 case VIM_WARNING:
2780 icon_data = alert_xpm;
2781 break;
2782 case VIM_INFO:
2783 icon_data = info_xpm;
2784 break;
2785 case VIM_QUESTION:
2786 icon_data = quest_xpm;
2787 break;
2788 default:
2789 icon_data = generic_xpm;
2790 }
2791
2792 n = 0;
2793 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2794 XtSetArg(args[n], XmNtopOffset, 8); n++;
2795 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2796 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2797 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2798 XtSetArg(args[n], XmNleftOffset, 8); n++;
2799
2800 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2801 icon_data, args, n);
2802 XtManageChild(dialogpixmap);
2803#endif
2804
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002805 /* Create the dialog message.
2806 * Since LessTif is apparently having problems with the creation of
2807 * properly localized string, we use LtoR here. The symptom is that the
2808 * string sill not show properly in multiple lines as it does in native
2809 * Motif.
2810 */
2811 label = XmStringCreateLtoR((char *)message, STRING_TAG);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 if (label == NULL)
2813 return -1;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002814 w = XtVaCreateManagedWidget("dialogMessage",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 xmLabelGadgetClass, form,
2816 XmNlabelString, label,
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002817 XmNalignment, XmALIGNMENT_BEGINNING,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 XmNtopAttachment, XmATTACH_FORM,
2819 XmNtopOffset, 8,
2820#ifdef HAVE_XPM
2821 XmNleftAttachment, XmATTACH_WIDGET,
2822 XmNleftWidget, dialogpixmap,
2823#else
2824 XmNleftAttachment, XmATTACH_FORM,
2825#endif
2826 XmNleftOffset, 8,
2827 XmNrightAttachment, XmATTACH_FORM,
2828 XmNrightOffset, 8,
2829 XmNbottomAttachment, XmATTACH_FORM,
2830 XmNbottomOffset, 8,
2831 NULL);
2832 XmStringFree(label);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002833 set_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834
2835 if (textfield != NULL)
2836 {
2837 XtVaSetValues(form,
2838 XmNbottomAttachment, XmATTACH_WIDGET,
2839 XmNbottomWidget, dialogtextfield,
2840 NULL);
2841 }
2842 else
2843 {
2844 if (butcount > 0)
2845 XtVaSetValues(form,
2846 XmNbottomAttachment, XmATTACH_WIDGET,
2847 XmNbottomWidget, separator,
2848 NULL);
2849 else
2850 XtVaSetValues(form,
2851 XmNbottomAttachment, XmATTACH_FORM,
2852 NULL);
2853 }
2854
2855 if (dfltbutton < 1)
2856 dfltbutton = 1;
2857 if (dfltbutton > butcount)
2858 dfltbutton = butcount;
2859 XtVaSetValues(dialogform,
2860 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2861 if (textfield != NULL)
2862 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2863 else
2864 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2865 NULL);
2866
2867 manage_centered(dialogform);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002868 activate_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869
2870 if (textfield != NULL && *textfield != NUL)
2871 {
2872 /* This only works after the textfield has been realised. */
2873 XmTextFieldSetSelection(dialogtextfield,
2874 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2875 XtLastTimestampProcessed(gui.dpy));
2876 XmTextFieldSetCursorPosition(dialogtextfield,
2877 (XmTextPosition)STRLEN(textfield));
2878 }
2879
2880 app = XtWidgetToApplicationContext(dialogform);
2881
2882 /* Loop until a button is pressed or the dialog is killed somehow. */
2883 dialogStatus = -1;
2884 for (;;)
2885 {
2886 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2887 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2888 break;
2889 }
2890
2891 vim_free(buttons);
2892
2893 if (textfield != NULL)
2894 {
2895 p = (char_u *)XmTextGetString(dialogtextfield);
2896 if (p == NULL || dialogStatus < 0)
2897 *textfield = NUL;
2898 else
Bram Moolenaarbbebc852005-07-18 21:47:53 +00002899 vim_strncpy(textfield, p, IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 }
2901
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002902 suppress_dialog_mnemonics(dialogform);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 XtDestroyWidget(dialogform);
2904
2905 return dialogStatus;
2906}
2907#endif /* FEAT_GUI_DIALOG */
2908
2909#if defined(FEAT_FOOTER) || defined(PROTO)
2910
2911 static int
2912gui_mch_compute_footer_height()
2913{
2914 Dimension height; /* total Toolbar height */
2915 Dimension top; /* XmNmarginTop */
2916 Dimension bottom; /* XmNmarginBottom */
2917 Dimension shadow; /* XmNshadowThickness */
2918
2919 XtVaGetValues(footer,
2920 XmNheight, &height,
2921 XmNmarginTop, &top,
2922 XmNmarginBottom, &bottom,
2923 XmNshadowThickness, &shadow,
2924 NULL);
2925
2926 return (int) height + top + bottom + (shadow << 1);
2927}
2928
2929#if 0 /* not used */
2930 void
2931gui_mch_set_footer_pos(h)
2932 int h; /* textArea height */
2933{
2934 XtVaSetValues(footer,
2935 XmNtopOffset, h + 7,
2936 NULL);
2937}
2938#endif
2939
2940 void
2941gui_mch_enable_footer(showit)
2942 int showit;
2943{
2944 if (showit)
2945 {
2946 gui.footer_height = gui_mch_compute_footer_height();
2947 XtManageChild(footer);
2948 }
2949 else
2950 {
2951 gui.footer_height = 0;
2952 XtUnmanageChild(footer);
2953 }
2954 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2955}
2956
2957 void
2958gui_mch_set_footer(s)
2959 char_u *s;
2960{
2961 XmString xms;
2962
2963 xms = XmStringCreate((char *)s, STRING_TAG);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002964 if (xms != NULL)
2965 {
2966 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2967 XmStringFree(xms);
2968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969}
2970
2971#endif
2972
2973
2974#if defined(FEAT_TOOLBAR) || defined(PROTO)
2975 void
2976gui_mch_show_toolbar(int showit)
2977{
2978 Cardinal numChildren; /* how many children toolBar has */
2979
2980 if (toolBar == (Widget)0)
2981 return;
2982 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2983 if (showit && numChildren > 0)
2984 {
2985 /* Assume that we want to show the toolbar if p_toolbar contains
2986 * valid option settings, therefore p_toolbar must not be NULL.
2987 */
2988 WidgetList children;
2989
2990 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2991 {
2992 void (*action)(BalloonEval *);
2993 int text = 0;
2994
2995 if (strstr((const char *)p_toolbar, "tooltips"))
2996 action = &gui_mch_enable_beval_area;
2997 else
2998 action = &gui_mch_disable_beval_area;
2999 if (strstr((const char *)p_toolbar, "text"))
3000 text = 1;
3001 else if (strstr((const char *)p_toolbar, "icons"))
3002 text = -1;
3003 if (text != 0)
3004 {
3005 vimmenu_T *toolbar;
3006 vimmenu_T *cur;
3007
3008 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
3009 if (menu_is_toolbar(toolbar->dname))
3010 break;
3011 /* Assumption: toolbar is NULL if there is no toolbar,
3012 * otherwise it contains the toolbar menu structure.
3013 *
3014 * Assumption: "numChildren" == the number of items in the list
3015 * of items beginning with toolbar->children.
3016 */
3017 if (toolbar)
3018 {
3019 for (cur = toolbar->children; cur; cur = cur->next)
3020 {
3021 Arg args[1];
3022 int n = 0;
3023
3024 /* Enable/Disable tooltip (OK to enable while
3025 * currently enabled)
3026 */
3027 if (cur->tip != NULL)
3028 (*action)(cur->tip);
3029 if (!menu_is_separator(cur->name))
3030 {
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003031 if (text == 1 || cur->xpm == NULL)
3032 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 XtSetArg(args[n], XmNlabelType, XmSTRING);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003034 ++n;
3035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 if (cur->id != NULL)
3037 {
3038 XtUnmanageChild(cur->id);
3039 XtSetValues(cur->id, args, n);
3040 XtManageChild(cur->id);
3041 }
3042 }
3043 }
3044 }
3045 }
3046 }
3047 gui.toolbar_height = gui_mch_compute_toolbar_height();
3048 XtManageChild(XtParent(toolBar));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003049#ifdef FEAT_GUI_TABLINE
3050 if (showing_tabline)
3051 {
3052 XtVaSetValues(tabLine,
3053 XmNtopAttachment, XmATTACH_WIDGET,
3054 XmNtopWidget, XtParent(toolBar),
3055 NULL);
3056 XtVaSetValues(textAreaForm,
3057 XmNtopAttachment, XmATTACH_WIDGET,
3058 XmNtopWidget, tabLine,
3059 NULL);
3060 }
3061 else
3062#endif
3063 XtVaSetValues(textAreaForm,
3064 XmNtopAttachment, XmATTACH_WIDGET,
3065 XmNtopWidget, XtParent(toolBar),
3066 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 if (XtIsManaged(menuBar))
3068 XtVaSetValues(XtParent(toolBar),
3069 XmNtopAttachment, XmATTACH_WIDGET,
3070 XmNtopWidget, menuBar,
3071 NULL);
3072 else
3073 XtVaSetValues(XtParent(toolBar),
3074 XmNtopAttachment, XmATTACH_FORM,
3075 NULL);
3076 }
3077 else
3078 {
3079 gui.toolbar_height = 0;
3080 if (XtIsManaged(menuBar))
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003081 {
3082#ifdef FEAT_GUI_TABLINE
3083 if (showing_tabline)
3084 {
3085 XtVaSetValues(tabLine,
3086 XmNtopAttachment, XmATTACH_WIDGET,
3087 XmNtopWidget, menuBar,
3088 NULL);
3089 XtVaSetValues(textAreaForm,
3090 XmNtopAttachment, XmATTACH_WIDGET,
3091 XmNtopWidget, tabLine,
3092 NULL);
3093 }
3094 else
3095#endif
3096 XtVaSetValues(textAreaForm,
3097 XmNtopAttachment, XmATTACH_WIDGET,
3098 XmNtopWidget, menuBar,
3099 NULL);
3100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 else
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003102 {
3103#ifdef FEAT_GUI_TABLINE
3104 if (showing_tabline)
3105 {
3106 XtVaSetValues(tabLine,
3107 XmNtopAttachment, XmATTACH_FORM,
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_FORM,
3118 NULL);
3119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120
3121 XtUnmanageChild(XtParent(toolBar));
3122 }
Bram Moolenaar2e2a2812006-03-27 20:55:21 +00003123 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124}
3125
3126/*
3127 * A toolbar button has been pushed; now reset the input focus
3128 * such that the user can type page up/down etc. and have the
3129 * input go to the editor window, not the button
3130 */
3131 static void
Bram Moolenaarf9980f12005-01-03 20:58:59 +00003132reset_focus()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133{
3134 if (textArea != NULL)
3135 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3136}
3137
3138 int
3139gui_mch_compute_toolbar_height()
3140{
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003141 Dimension borders;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 Dimension height; /* total Toolbar height */
3143 Dimension whgt; /* height of each widget */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 WidgetList children; /* list of toolBar's children */
3145 Cardinal numChildren; /* how many children toolBar has */
3146 int i;
3147
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003148 borders = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 height = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3151 { /* get height of XmFrame parent */
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003152 Dimension fst;
3153 Dimension fmh;
3154 Dimension tst;
3155 Dimension tmh;
3156
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 XtVaGetValues(toolBarFrame,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003158 XmNshadowThickness, &fst,
3159 XmNmarginHeight, &fmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003161 borders += fst + fmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 XtVaGetValues(toolBar,
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003163 XmNshadowThickness, &tst,
3164 XmNmarginHeight, &tmh,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 XmNchildren, &children,
3166 XmNnumChildren, &numChildren, NULL);
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003167 borders += tst + tmh;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 for (i = 0; i < numChildren; i++)
3169 {
3170 whgt = 0;
3171 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3172 if (height < whgt)
3173 height = whgt;
3174 }
3175 }
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003176#ifdef LESSTIF_VERSION
3177 /* Hack: When starting up we get wrong dimensions. */
3178 if (height < 10)
3179 height = 24;
3180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003182 return (int)(height + (borders << 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183}
3184
Bram Moolenaar7c626922005-02-07 22:01:03 +00003185 void
3186motif_get_toolbar_colors(bgp, fgp, bsp, tsp, hsp)
3187 Pixel *bgp;
3188 Pixel *fgp;
3189 Pixel *bsp;
3190 Pixel *tsp;
3191 Pixel *hsp;
3192{
3193 XtVaGetValues(toolBar,
3194 XmNbackground, bgp,
3195 XmNforeground, fgp,
3196 XmNbottomShadowColor, bsp,
3197 XmNtopShadowColor, tsp,
3198 XmNhighlightColor, hsp,
3199 NULL);
3200}
3201
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202# ifdef FEAT_FOOTER
3203/*
3204 * The next toolbar enter/leave callbacks should really do balloon help. But
3205 * I have to use footer help for backwards compatability. Hopefully both will
3206 * get implemented and the user will have a choice.
3207 */
3208/*ARGSUSED*/
3209 static void
3210toolbarbutton_enter_cb(w, client_data, event, cont)
3211 Widget w;
3212 XtPointer client_data;
3213 XEvent *event;
3214 Boolean *cont;
3215{
3216 vimmenu_T *menu = (vimmenu_T *) client_data;
3217
3218 if (menu->strings[MENU_INDEX_TIP] != NULL)
3219 {
3220 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3221 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3222 }
3223}
3224
3225/*ARGSUSED*/
3226 static void
3227toolbarbutton_leave_cb(w, client_data, event, cont)
3228 Widget w;
3229 XtPointer client_data;
3230 XEvent *event;
3231 Boolean *cont;
3232{
3233 gui_mch_set_footer((char_u *) "");
3234}
3235# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236#endif
3237
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003238#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3239/*
3240 * Show or hide the tabline.
3241 */
3242 void
3243gui_mch_show_tabline(int showit)
3244{
3245 if (tabLine == (Widget)0)
3246 return;
3247
3248 if (!showit != !showing_tabline)
3249 {
3250 if (showit)
3251 {
3252 XtManageChild(tabLine);
3253 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003254 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3255 XtUnmanageChild(XtNameToWidget(tabLine,
3256 "MinorTabScrollerPrevious"));
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003257#ifdef FEAT_MENU
3258# ifdef FEAT_TOOLBAR
3259 if (XtIsManaged(XtParent(toolBar)))
3260 XtVaSetValues(tabLine,
3261 XmNtopAttachment, XmATTACH_WIDGET,
3262 XmNtopWidget, XtParent(toolBar), NULL);
3263 else
3264# endif
3265 if (XtIsManaged(menuBar))
3266 XtVaSetValues(tabLine,
3267 XmNtopAttachment, XmATTACH_WIDGET,
3268 XmNtopWidget, menuBar, NULL);
3269 else
3270#endif
3271 XtVaSetValues(tabLine,
3272 XmNtopAttachment, XmATTACH_FORM, NULL);
3273 XtVaSetValues(textAreaForm,
3274 XmNtopAttachment, XmATTACH_WIDGET,
3275 XmNtopWidget, tabLine,
3276 NULL);
3277 }
3278 else
3279 {
3280 XtUnmanageChild(tabLine);
3281#ifdef FEAT_MENU
3282# ifdef FEAT_TOOLBAR
3283 if (XtIsManaged(XtParent(toolBar)))
3284 XtVaSetValues(textAreaForm,
3285 XmNtopAttachment, XmATTACH_WIDGET,
3286 XmNtopWidget, XtParent(toolBar), NULL);
3287 else
3288# endif
3289 if (XtIsManaged(menuBar))
3290 XtVaSetValues(textAreaForm,
3291 XmNtopAttachment, XmATTACH_WIDGET,
3292 XmNtopWidget, menuBar, NULL);
3293 else
3294#endif
3295 XtVaSetValues(textAreaForm,
3296 XmNtopAttachment, XmATTACH_FORM, NULL);
3297 }
3298 showing_tabline = showit;
3299 }
3300}
3301
3302/*
3303 * Return TRUE when tabline is displayed.
3304 */
3305 int
3306gui_mch_showing_tabline(void)
3307{
3308 return tabLine != (Widget)0 && showing_tabline;
3309}
3310
3311/*
3312 * Update the labels of the tabline.
3313 */
3314 void
3315gui_mch_update_tabline(void)
3316{
3317 tabpage_T *tp;
3318 int nr = 1, n;
3319 Arg args[10];
3320 int curtabidx = 0, currentpage;
3321 Widget tab;
3322 XmNotebookPageInfo page_info;
3323 XmNotebookPageStatus page_status;
3324 int last_page, tab_count;
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003325 XmString label_str;
3326 char *label_cstr;
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003327
3328 if (tabLine == (Widget)0)
3329 return;
3330
3331 /* Add a label for each tab page. They all contain the same text area. */
3332 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3333 {
3334 if (tp == curtab)
3335 curtabidx = nr;
3336
3337 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3338 if (page_status == XmPAGE_INVALID
3339 || page_info.major_tab_widget == (Widget)0)
3340 {
3341 /* Add the tab */
3342 n = 0;
3343 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3344 XtSetArg(args[n], XmNtraversalOn, False); n++;
3345 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3346 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3347 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3348 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3349 XtManageChild(tab);
3350 }
3351 else
3352 tab = page_info.major_tab_widget;
3353
3354 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00003355
3356 /*
3357 * Change the label text only if it is different
3358 */
3359 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3360 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3361 {
3362 get_tabline_label(tp);
3363 if (STRCMP(label_cstr, NameBuff) != 0) {
3364 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3365 NameBuff, STRLEN(NameBuff) + 1, NULL);
3366 /*
3367 * Force a resize of the tab label button
3368 */
3369 XtUnmanageChild(tab);
3370 XtManageChild(tab);
3371 }
3372 XtFree(label_cstr);
3373 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003374 }
3375
3376 tab_count = nr - 1;
3377
3378 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3379
3380 /* Remove any old labels. */
3381 while (nr <= last_page)
3382 {
3383 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3384 && page_info.page_number == nr
3385 && page_info.major_tab_widget != (Widget)0)
3386 {
3387 XtUnmanageChild(page_info.major_tab_widget);
3388 XtDestroyWidget(page_info.major_tab_widget);
3389 }
3390 nr++;
3391 }
3392
3393 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3394
3395 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3396 if (currentpage != curtabidx)
3397 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3398}
3399
3400/*
3401 * Set the current tab to "nr". First tab is 1.
3402 */
3403 void
3404gui_mch_set_curtab(nr)
3405 int nr;
3406{
3407 int currentpage;
3408
3409 if (tabLine == (Widget)0)
3410 return;
3411
3412 XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
3413 if (currentpage != nr)
3414 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3415}
3416#endif
3417
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418/*
3419 * Set the colors of Widget "id" to the menu colors.
3420 */
3421 static void
3422gui_motif_menu_colors(id)
3423 Widget id;
3424{
3425 if (gui.menu_bg_pixel != INVALCOLOR)
3426#if (XmVersion >= 1002)
3427 XmChangeColor(id, gui.menu_bg_pixel);
3428#else
3429 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3430#endif
3431 if (gui.menu_fg_pixel != INVALCOLOR)
3432 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3433}
3434
3435/*
3436 * Set the colors of Widget "id" to the scrollbar colors.
3437 */
3438 static void
3439gui_motif_scroll_colors(id)
3440 Widget id;
3441{
3442 if (gui.scroll_bg_pixel != INVALCOLOR)
3443#if (XmVersion >= 1002)
3444 XmChangeColor(id, gui.scroll_bg_pixel);
3445#else
3446 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3447#endif
3448 if (gui.scroll_fg_pixel != INVALCOLOR)
3449 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3450}
3451
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452/*
3453 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3454 */
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003455/*ARGSUSED*/
3456 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457gui_motif_menu_fontlist(id)
3458 Widget id;
3459{
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003460#ifdef FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461#ifdef FONTSET_ALWAYS
3462 if (gui.menu_fontset != NOFONTSET)
3463 {
3464 XmFontList fl;
3465
3466 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3467 if (fl != NULL)
3468 {
3469 if (XtIsManaged(id))
3470 {
3471 XtUnmanageChild(id);
3472 XtVaSetValues(id, XmNfontList, fl, NULL);
3473 /* We should force the widget to recalculate it's
3474 * geometry now. */
3475 XtManageChild(id);
3476 }
3477 else
3478 XtVaSetValues(id, XmNfontList, fl, NULL);
3479 XmFontListFree(fl);
3480 }
3481 }
3482#else
3483 if (gui.menu_font != NOFONT)
3484 {
3485 XmFontList fl;
3486
3487 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3488 if (fl != NULL)
3489 {
3490 if (XtIsManaged(id))
3491 {
3492 XtUnmanageChild(id);
3493 XtVaSetValues(id, XmNfontList, fl, NULL);
3494 /* We should force the widget to recalculate it's
3495 * geometry now. */
3496 XtManageChild(id);
3497 }
3498 else
3499 XtVaSetValues(id, XmNfontList, fl, NULL);
3500 XmFontListFree(fl);
3501 }
3502 }
3503#endif
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505}
3506
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507
3508/*
3509 * We don't create it twice for the sake of speed.
3510 */
3511
3512typedef struct _SharedFindReplace
3513{
3514 Widget dialog; /* the main dialog widget */
3515 Widget wword; /* 'Exact match' check button */
3516 Widget mcase; /* 'match case' check button */
3517 Widget up; /* search direction 'Up' radio button */
3518 Widget down; /* search direction 'Down' radio button */
3519 Widget what; /* 'Find what' entry text widget */
3520 Widget with; /* 'Replace with' entry text widget */
3521 Widget find; /* 'Find Next' action button */
3522 Widget replace; /* 'Replace With' action button */
3523 Widget all; /* 'Replace All' action button */
3524 Widget undo; /* 'Undo' action button */
3525
3526 Widget cancel;
3527} SharedFindReplace;
3528
3529static SharedFindReplace find_widgets = { NULL };
3530static SharedFindReplace repl_widgets = { NULL };
3531
3532static void find_replace_destroy_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3533static void find_replace_dismiss_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3534static void entry_activate_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3535static void find_replace_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
3536static void find_replace_keypress __ARGS((Widget w, SharedFindReplace * frdp, XKeyEvent * event));
3537static void find_replace_dialog_create __ARGS((char_u *entry_text, int do_replace));
3538
3539/*ARGSUSED*/
3540 static void
3541find_replace_destroy_callback(w, client_data, call_data)
3542 Widget w;
3543 XtPointer client_data;
3544 XtPointer call_data;
3545{
3546 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3547
Bram Moolenaarb7fcef52005-01-02 11:31:05 +00003548 if (cd != NULL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003549 /* suppress_dialog_mnemonics(cd->dialog); */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 cd->dialog = (Widget)0;
3551}
3552
3553/*ARGSUSED*/
3554 static void
3555find_replace_dismiss_callback(w, client_data, call_data)
3556 Widget w;
3557 XtPointer client_data;
3558 XtPointer call_data;
3559{
3560 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3561
3562 if (cd != NULL)
3563 XtUnmanageChild(cd->dialog);
3564}
3565
3566/*ARGSUSED*/
3567 static void
3568entry_activate_callback(w, client_data, call_data)
3569 Widget w;
3570 XtPointer client_data;
3571 XtPointer call_data;
3572{
3573 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3574}
3575
3576/*ARGSUSED*/
3577 static void
3578find_replace_callback(w, client_data, call_data)
3579 Widget w;
3580 XtPointer client_data;
3581 XtPointer call_data;
3582{
3583 long_u flags = (long_u)client_data;
3584 char *find_text, *repl_text;
3585 Boolean direction_down = TRUE;
3586 Boolean wword;
3587 Boolean mcase;
3588 SharedFindReplace *sfr;
3589
3590 if (flags == FRD_UNDO)
3591 {
3592 char_u *save_cpo = p_cpo;
3593
3594 /* No need to be Vi compatible here. */
3595 p_cpo = (char_u *)"";
3596 u_undo(1);
3597 p_cpo = save_cpo;
3598 gui_update_screen();
3599 return;
3600 }
3601
3602 /* Get the search/replace strings from the dialog */
3603 if (flags == FRD_FINDNEXT)
3604 {
3605 repl_text = NULL;
3606 sfr = &find_widgets;
3607 }
3608 else
3609 {
3610 repl_text = XmTextFieldGetString(repl_widgets.with);
3611 sfr = &repl_widgets;
3612 }
3613 find_text = XmTextFieldGetString(sfr->what);
3614 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3615 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3616 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3617 if (wword)
3618 flags |= FRD_WHOLE_WORD;
3619 if (mcase)
3620 flags |= FRD_MATCH_CASE;
3621
3622 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3623 direction_down);
3624
3625 if (find_text != NULL)
3626 XtFree(find_text);
3627 if (repl_text != NULL)
3628 XtFree(repl_text);
3629}
3630
3631/*ARGSUSED*/
3632 static void
3633find_replace_keypress(w, frdp, event)
3634 Widget w;
3635 SharedFindReplace *frdp;
3636 XKeyEvent *event;
3637{
3638 KeySym keysym;
3639
3640 if (frdp == NULL)
3641 return;
3642
3643 keysym = XLookupKeysym(event, 0);
3644
3645 /* the scape key pops the whole dialog down */
3646 if (keysym == XK_Escape)
3647 XtUnmanageChild(frdp->dialog);
3648}
3649
3650 static void
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003651set_label(w, label)
3652 Widget w;
3653 char_u *label;
3654{
3655 XmString str;
3656 char_u *p, *next;
3657 KeySym mnemonic = NUL;
3658
3659 if (!w)
3660 return;
3661
3662 p = vim_strsave(label);
3663 if (p == NULL)
3664 return;
3665 for (next = p; *next; ++next)
3666 {
3667 if (*next == DLG_HOTKEY_CHAR)
3668 {
3669 int len = STRLEN(next);
3670
3671 if (len > 0)
3672 {
3673 mch_memmove(next, next + 1, len);
3674 mnemonic = next[0];
3675 }
3676 }
3677 }
3678
3679 str = XmStringCreateSimple((char *)p);
3680 vim_free(p);
3681 if (str)
3682 {
3683 XtVaSetValues(w,
3684 XmNlabelString, str,
3685 XmNmnemonic, mnemonic,
3686 NULL);
3687 XmStringFree(str);
3688 }
3689 gui_motif_menu_fontlist(w);
3690}
3691
3692 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693find_replace_dialog_create(arg, do_replace)
3694 char_u *arg;
3695 int do_replace;
3696{
3697 SharedFindReplace *frdp;
3698 Widget separator;
3699 Widget input_form;
3700 Widget button_form;
3701 Widget toggle_form;
3702 Widget frame;
3703 XmString str;
3704 int n;
3705 Arg args[6];
3706 int wword = FALSE;
3707 int mcase = !p_ic;
3708 Dimension width;
3709 Dimension widest;
3710 char_u *entry_text;
3711
3712 frdp = do_replace ? &repl_widgets : &find_widgets;
3713
3714 /* Get the search string to use. */
3715 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3716
3717 /* If the dialog already exists, just raise it. */
3718 if (frdp->dialog)
3719 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003720 gui_motif_synch_fonts();
3721
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 /* If the window is already up, just pop it to the top */
3723 if (XtIsManaged(frdp->dialog))
3724 XMapRaised(XtDisplay(frdp->dialog),
3725 XtWindow(XtParent(frdp->dialog)));
3726 else
3727 XtManageChild(frdp->dialog);
3728 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3729 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3730
3731 if (entry_text != NULL)
3732 XmTextFieldSetString(frdp->what, (char *)entry_text);
3733 vim_free(entry_text);
3734
3735 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3736 return;
3737 }
3738
3739 /* Create a fresh new dialog window */
3740 if (do_replace)
3741 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3742 else
3743 str = XmStringCreateSimple(_("VIM - Search..."));
3744
3745 n = 0;
3746 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3747 XtSetArg(args[n], XmNnoResize, True); n++;
3748 XtSetArg(args[n], XmNdialogTitle, str); n++;
3749
3750 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3751 XmStringFree(str);
3752 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3753 find_replace_destroy_callback, frdp);
3754
3755 button_form = XtVaCreateWidget("buttonForm",
3756 xmFormWidgetClass, frdp->dialog,
3757 XmNrightAttachment, XmATTACH_FORM,
3758 XmNrightOffset, 4,
3759 XmNtopAttachment, XmATTACH_FORM,
3760 XmNtopOffset, 4,
3761 XmNbottomAttachment, XmATTACH_FORM,
3762 XmNbottomOffset, 4,
3763 NULL);
3764
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 frdp->find = XtVaCreateManagedWidget("findButton",
3766 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 XmNsensitive, True,
3768 XmNtopAttachment, XmATTACH_FORM,
3769 XmNleftAttachment, XmATTACH_FORM,
3770 XmNrightAttachment, XmATTACH_FORM,
3771 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003772 set_label(frdp->find, _("Find &Next"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773
3774 XtAddCallback(frdp->find, XmNactivateCallback,
3775 find_replace_callback,
3776 (XtPointer) (do_replace ? FRD_R_FINDNEXT : FRD_FINDNEXT));
3777
3778 if (do_replace)
3779 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3781 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782 XmNtopAttachment, XmATTACH_WIDGET,
3783 XmNtopWidget, frdp->find,
3784 XmNleftAttachment, XmATTACH_FORM,
3785 XmNrightAttachment, XmATTACH_FORM,
3786 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003787 set_label(frdp->replace, _("&Replace"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 XtAddCallback(frdp->replace, XmNactivateCallback,
3789 find_replace_callback, (XtPointer)FRD_REPLACE);
3790
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3792 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 XmNtopAttachment, XmATTACH_WIDGET,
3794 XmNtopWidget, frdp->replace,
3795 XmNleftAttachment, XmATTACH_FORM,
3796 XmNrightAttachment, XmATTACH_FORM,
3797 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003798 set_label(frdp->all, _("Replace &All"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 XtAddCallback(frdp->all, XmNactivateCallback,
3800 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3801
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 frdp->undo = XtVaCreateManagedWidget("undoButton",
3803 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 XmNtopAttachment, XmATTACH_WIDGET,
3805 XmNtopWidget, frdp->all,
3806 XmNleftAttachment, XmATTACH_FORM,
3807 XmNrightAttachment, XmATTACH_FORM,
3808 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003809 set_label(frdp->undo, _("&Undo"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 XtAddCallback(frdp->undo, XmNactivateCallback,
3811 find_replace_callback, (XtPointer)FRD_UNDO);
3812 }
3813
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3815 xmPushButtonWidgetClass, button_form,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 XmNleftAttachment, XmATTACH_FORM,
3817 XmNrightAttachment, XmATTACH_FORM,
3818 XmNbottomAttachment, XmATTACH_FORM,
3819 NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003820 set_label(frdp->cancel, _("&Cancel"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 XtAddCallback(frdp->cancel, XmNactivateCallback,
3822 find_replace_dismiss_callback, frdp);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003823 gui_motif_menu_fontlist(frdp->cancel);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824
3825 XtManageChild(button_form);
3826
3827 n = 0;
3828 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3829 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3830 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3831 XtSetArg(args[n], XmNrightOffset, 4); n++;
3832 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3833 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3834 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3835 XtManageChild(separator);
3836
3837 input_form = XtVaCreateWidget("inputForm",
3838 xmFormWidgetClass, frdp->dialog,
3839 XmNleftAttachment, XmATTACH_FORM,
3840 XmNleftOffset, 4,
3841 XmNrightAttachment, XmATTACH_WIDGET,
3842 XmNrightWidget, separator,
3843 XmNrightOffset, 4,
3844 XmNtopAttachment, XmATTACH_FORM,
3845 XmNtopOffset, 4,
3846 NULL);
3847
3848 {
3849 Widget label_what;
3850 Widget label_with = (Widget)0;
3851
3852 str = XmStringCreateSimple(_("Find what:"));
3853 label_what = XtVaCreateManagedWidget("whatLabel",
3854 xmLabelGadgetClass, input_form,
3855 XmNlabelString, str,
3856 XmNleftAttachment, XmATTACH_FORM,
3857 XmNtopAttachment, XmATTACH_FORM,
3858 XmNtopOffset, 4,
3859 NULL);
3860 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003861 gui_motif_menu_fontlist(label_what);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862
3863 frdp->what = XtVaCreateManagedWidget("whatText",
3864 xmTextFieldWidgetClass, input_form,
3865 XmNtopAttachment, XmATTACH_FORM,
3866 XmNrightAttachment, XmATTACH_FORM,
3867 XmNleftAttachment, XmATTACH_FORM,
3868 NULL);
3869
3870 if (do_replace)
3871 {
3872 frdp->with = XtVaCreateManagedWidget("withText",
3873 xmTextFieldWidgetClass, input_form,
3874 XmNtopAttachment, XmATTACH_WIDGET,
3875 XmNtopWidget, frdp->what,
3876 XmNtopOffset, 4,
3877 XmNleftAttachment, XmATTACH_FORM,
3878 XmNrightAttachment, XmATTACH_FORM,
3879 XmNbottomAttachment, XmATTACH_FORM,
3880 NULL);
3881
3882 XtAddCallback(frdp->with, XmNactivateCallback,
3883 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3884
3885 str = XmStringCreateSimple(_("Replace with:"));
3886 label_with = XtVaCreateManagedWidget("withLabel",
3887 xmLabelGadgetClass, input_form,
3888 XmNlabelString, str,
3889 XmNleftAttachment, XmATTACH_FORM,
3890 XmNtopAttachment, XmATTACH_WIDGET,
3891 XmNtopWidget, frdp->what,
3892 XmNtopOffset, 4,
3893 XmNbottomAttachment, XmATTACH_FORM,
3894 NULL);
3895 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003896 gui_motif_menu_fontlist(label_with);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897
3898 /*
3899 * Make the entry activation only change the input focus onto the
3900 * with item.
3901 */
3902 XtAddCallback(frdp->what, XmNactivateCallback,
3903 entry_activate_callback, frdp->with);
3904 XtAddEventHandler(frdp->with, KeyPressMask, False,
3905 (XtEventHandler)find_replace_keypress,
3906 (XtPointer) frdp);
3907
3908 }
3909 else
3910 {
3911 /*
3912 * Make the entry activation do the search.
3913 */
3914 XtAddCallback(frdp->what, XmNactivateCallback,
3915 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3916 }
3917 XtAddEventHandler(frdp->what, KeyPressMask, False,
3918 (XtEventHandler)find_replace_keypress,
3919 (XtPointer)frdp);
3920
3921 /* Get the maximum width between the label widgets and line them up.
3922 */
3923 n = 0;
3924 XtSetArg(args[n], XmNwidth, &width); n++;
3925 XtGetValues(label_what, args, n);
3926 widest = width;
3927 if (do_replace)
3928 {
3929 XtGetValues(label_with, args, n);
3930 if (width > widest)
3931 widest = width;
3932 }
3933
3934 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3935 if (do_replace)
3936 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3937
3938 }
3939
3940 XtManageChild(input_form);
3941
3942 {
3943 Widget radio_box;
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003944 Widget w;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945
3946 frame = XtVaCreateWidget("directionFrame",
3947 xmFrameWidgetClass, frdp->dialog,
3948 XmNtopAttachment, XmATTACH_WIDGET,
3949 XmNtopWidget, input_form,
3950 XmNtopOffset, 4,
3951 XmNbottomAttachment, XmATTACH_FORM,
3952 XmNbottomOffset, 4,
3953 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3954 XmNrightWidget, input_form,
3955 NULL);
3956
3957 str = XmStringCreateSimple(_("Direction"));
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003958 w = XtVaCreateManagedWidget("directionFrameLabel",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 xmLabelGadgetClass, frame,
3960 XmNlabelString, str,
3961 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3962 XmNchildType, XmFRAME_TITLE_CHILD,
3963 NULL);
3964 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003965 gui_motif_menu_fontlist(w);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966
3967 radio_box = XmCreateRadioBox(frame, "radioBox",
3968 (ArgList)NULL, 0);
3969
3970 str = XmStringCreateSimple( _("Up"));
3971 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3972 xmToggleButtonGadgetClass, radio_box,
3973 XmNlabelString, str,
3974 XmNset, False,
3975 NULL);
3976 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003977 gui_motif_menu_fontlist(frdp->up);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978
3979 str = XmStringCreateSimple(_("Down"));
3980 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3981 xmToggleButtonGadgetClass, radio_box,
3982 XmNlabelString, str,
3983 XmNset, True,
3984 NULL);
3985 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00003986 gui_motif_menu_fontlist(frdp->down);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987
3988 XtManageChild(radio_box);
3989 XtManageChild(frame);
3990 }
3991
3992 toggle_form = XtVaCreateWidget("toggleForm",
3993 xmFormWidgetClass, frdp->dialog,
3994 XmNleftAttachment, XmATTACH_FORM,
3995 XmNleftOffset, 4,
3996 XmNrightAttachment, XmATTACH_WIDGET,
3997 XmNrightWidget, frame,
3998 XmNrightOffset, 4,
3999 XmNtopAttachment, XmATTACH_WIDGET,
4000 XmNtopWidget, input_form,
4001 XmNtopOffset, 4,
4002 XmNbottomAttachment, XmATTACH_FORM,
4003 XmNbottomOffset, 4,
4004 NULL);
4005
4006 str = XmStringCreateSimple(_("Match whole word only"));
4007 frdp->wword = XtVaCreateManagedWidget("wordToggle",
4008 xmToggleButtonGadgetClass, toggle_form,
4009 XmNlabelString, str,
4010 XmNtopAttachment, XmATTACH_FORM,
4011 XmNtopOffset, 4,
4012 XmNleftAttachment, XmATTACH_FORM,
4013 XmNleftOffset, 4,
4014 XmNset, wword,
4015 NULL);
4016 XmStringFree(str);
4017
4018 str = XmStringCreateSimple(_("Match case"));
4019 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
4020 xmToggleButtonGadgetClass, toggle_form,
4021 XmNlabelString, str,
4022 XmNleftAttachment, XmATTACH_FORM,
4023 XmNleftOffset, 4,
4024 XmNtopAttachment, XmATTACH_WIDGET,
4025 XmNtopWidget, frdp->wword,
4026 XmNtopOffset, 4,
4027 XmNset, mcase,
4028 NULL);
4029 XmStringFree(str);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004030 gui_motif_menu_fontlist(frdp->wword);
4031 gui_motif_menu_fontlist(frdp->mcase);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032
4033 XtManageChild(toggle_form);
4034
4035 if (entry_text != NULL)
4036 XmTextFieldSetString(frdp->what, (char *)entry_text);
4037 vim_free(entry_text);
4038
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004039 gui_motif_synch_fonts();
4040
4041 manage_centered(frdp->dialog);
4042 activate_dialog_mnemonics(frdp->dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
4044}
4045
4046 void
4047gui_mch_find_dialog(eap)
4048 exarg_T *eap;
4049{
4050 if (!gui.in_use)
4051 return;
4052
4053 find_replace_dialog_create(eap->arg, FALSE);
4054}
4055
4056
4057 void
4058gui_mch_replace_dialog(eap)
4059 exarg_T *eap;
4060{
4061 if (!gui.in_use)
4062 return;
4063
4064 find_replace_dialog_create(eap->arg, TRUE);
4065}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004066
4067/*
4068 * Synchronize all gui elements, which are dependant upon the
4069 * main text font used. Those are in esp. the find/replace dialogs.
4070 * If you don't understand why this should be needed, please try to
4071 * search for "piê¶æ" in iso8859-2.
4072 */
4073 void
4074gui_motif_synch_fonts(void)
4075{
4076 SharedFindReplace *frdp;
4077 int do_replace;
4078 XFontStruct *font;
4079 XmFontList font_list;
4080
4081 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4082 * we just give up here on font synchronization. */
4083 font = (XFontStruct *)gui.norm_font;
4084 if (font == NULL)
4085 return;
4086
4087 font_list = gui_motif_create_fontlist(font);
4088
4089 /* OK this loop is a bit tricky... */
4090 for (do_replace = 0; do_replace <= 1; ++do_replace)
4091 {
4092 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4093 if (frdp->dialog)
4094 {
4095 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4096 if (do_replace)
4097 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4098 }
4099 }
4100
4101 XmFontListFree(font_list);
4102}