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