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