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