1 /* vi:set ts=8 sts=4 sw=4 noet:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI/Motif support by Robert Webb
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.
14 #include <Xm/RowColumn.h>
18 #include <Xm/Separator.h>
20 #include <Xm/CascadeB.h>
21 #include <Xm/ScrollBar.h>
22 #include <Xm/MenuShell.h>
23 #include <Xm/DrawingA.h>
24 #if (XmVersion >= 1002)
25 # include <Xm/RepType.h>
28 #include <Xm/LabelG.h>
29 #include <Xm/ToggleBG.h>
30 #include <Xm/SeparatoG.h>
33 #include <X11/keysym.h>
34 #include <X11/Xatom.h>
35 #include <X11/StringDefs.h>
36 #include <X11/Intrinsic.h>
41 # ifdef HAVE_XM_XPMP_H
45 #ifdef HAVE_XM_NOTEBOOK_H
46 # include <Xm/Notebook.h>
49 #include "gui_xmebw.h" /* for our Enhanced Button Widget */
51 #if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
52 # include "../pixmaps/alert.xpm"
53 # include "../pixmaps/error.xpm"
54 # include "../pixmaps/generic.xpm"
55 # include "../pixmaps/info.xpm"
56 # include "../pixmaps/quest.xpm"
61 extern Widget vimShell;
63 static Widget vimForm;
64 static Widget textAreaForm;
67 static Widget toolBarFrame;
68 static Widget toolBar;
70 #ifdef FEAT_GUI_TABLINE
71 static Widget tabLine;
72 static Widget tabLine_menu = 0;
73 static int showing_tabline = 0;
79 # if (XmVersion >= 1002)
80 /* remember the last set value for the tearoff item */
81 static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
83 static Widget menuBar;
86 static void scroll_cb(Widget w, XtPointer client_data, XtPointer call_data);
87 #ifdef FEAT_GUI_TABLINE
88 static void tabline_cb(Widget w, XtPointer client_data, XtPointer call_data);
89 static void tabline_button_cb(Widget w, XtPointer client_data, XtPointer call_data);
90 static void tabline_menu_cb(Widget w, XtPointer closure, XEvent *e, Boolean *continue_dispatch);
91 static void tabline_balloon_cb(BalloonEval *beval, int state);
95 static void toolbarbutton_enter_cb(Widget, XtPointer, XEvent *, Boolean *);
96 static void toolbarbutton_leave_cb(Widget, XtPointer, XEvent *, Boolean *);
98 static void reset_focus(void);
101 static int gui_mch_compute_footer_height(void);
104 static void attachDump(Widget, char *);
107 static void gui_motif_menu_colors(Widget id);
108 static void gui_motif_scroll_colors(Widget id);
110 #if (XmVersion >= 1002)
111 # define STRING_TAG XmFONTLIST_DEFAULT_TAG
113 # define STRING_TAG XmSTRING_DEFAULT_CHARSET
117 * Call-back routines.
121 scroll_cb(Widget w UNUSED, XtPointer client_data, XtPointer call_data)
127 sb = gui_find_scrollbar((long)client_data);
129 value = ((XmScrollBarCallbackStruct *)call_data)->value;
130 dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
132 gui_drag_scrollbar(sb, value, dragging);
135 #ifdef FEAT_GUI_TABLINE
139 XtPointer client_data UNUSED,
142 XmNotebookCallbackStruct *nptr;
144 nptr = (XmNotebookCallbackStruct *)call_data;
145 if (nptr->reason != (int)XmCR_NONE)
146 send_tabline_event(nptr->page_number);
152 XtPointer client_data UNUSED,
153 XtPointer call_data UNUSED)
157 XtVaGetValues(w, XmNuserData, &cmd, NULL);
158 XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);
160 send_tabline_menu_event(tab_idx, cmd);
164 * Tabline single mouse click timeout handler
167 motif_tabline_timer_cb (
169 XtIntervalId *interval_id UNUSED)
171 *((int *)timed_out) = TRUE;
175 * check if the tabline tab scroller is clicked
178 tabline_scroller_clicked(
180 XButtonPressedEvent *event)
183 Position pos_x, pos_y;
184 Dimension width, height;
186 tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
187 if (tab_scroll_w != (Widget)0) {
188 XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
189 &width, XmNheight, &height, NULL);
191 /* Tab scroller (next) is visible */
192 if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
193 (event->y >= pos_y) && (event->y <= pos_y + height)) {
194 /* Clicked on the scroller */
205 XtPointer closure UNUSED,
207 Boolean *continue_dispatch UNUSED)
210 XButtonPressedEvent *event;
213 Cardinal numChildren;
214 static XtIntervalId timer = (XtIntervalId)0;
215 static int timed_out = TRUE;
217 event = (XButtonPressedEvent *)e;
219 if (event->button == Button1)
221 if (tabline_scroller_clicked("MajorTabScrollerNext", event)
222 || tabline_scroller_clicked("MajorTabScrollerPrevious", event))
227 XtRemoveTimeOut(timer);
231 * Double click on the tabline gutter, add a new tab
233 send_tabline_menu_event(0, TABLINE_MENU_NEW);
238 * Single click on the tabline gutter, start a timer to check
241 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
242 motif_tabline_timer_cb, &timed_out);
248 if (event->button != Button3)
251 /* When ignoring events don't show the menu. */
259 if (event->subwindow != None)
261 tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
262 /* LINTED: avoid warning: dubious operation on enum */
263 if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
264 XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
267 XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
268 XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
270 XtManageChildren(children, numChildren);
271 XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
272 XtManageChild(tabLine_menu);
276 tabline_balloon_cb(BalloonEval *beval, int state UNUSED)
281 if (beval->target == (Widget)0)
284 XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
285 tp = find_tabpage(nr);
289 get_tabline_label(tp, TRUE);
290 gui_mch_post_balloon(beval, NameBuff);
296 * End of call-back routines
300 * Implement three dimensional shading of insensitive labels.
305 #include <Xm/LabelP.h>
307 static XtExposeProc old_label_expose = NULL;
309 static void label_expose(Widget _w, XEvent *_event, Region _region);
312 label_expose(Widget _w, XEvent *_event, Region _region)
315 XmLabelWidget lw = (XmLabelWidget)_w;
316 unsigned char label_type = (int)XmSTRING;
318 XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);
320 if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
321 (*old_label_expose)(_w, _event, _region);
329 _XmFontListGetDefaultFont(lw->label.font, &fs);
331 /* FIXME: we should be doing the whole drawing ourself here. */
332 insensitiveGC = lw->label.insensitive_GC;
334 mask = GCForeground | GCBackground | GCGraphicsExposures;
335 dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
336 values.graphics_exposures = False;
341 values.font = fs->fid;
344 if (lw->primitive.top_shadow_pixmap != None
345 && lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
347 mask |= GCFillStyle | GCTile;
348 values.fill_style = FillTiled;
349 values.tile = lw->primitive.top_shadow_pixmap;
352 lw->label.TextRect.x += 1;
353 lw->label.TextRect.y += 1;
354 if (lw->label._acc_text != 0)
356 lw->label.acc_TextRect.x += 1;
357 lw->label.acc_TextRect.y += 1;
360 values.foreground = lw->primitive.top_shadow_color;
361 values.background = lw->core.background_pixel;
363 lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
364 &values, dynamic, (XtGCMask)0);
365 (*old_label_expose)(_w, _event, _region);
366 XtReleaseGC(_w, lw->label.insensitive_GC);
368 lw->label.TextRect.x -= 1;
369 lw->label.TextRect.y -= 1;
370 if (lw->label._acc_text != 0)
372 lw->label.acc_TextRect.x -= 1;
373 lw->label.acc_TextRect.y -= 1;
376 values.foreground = lw->primitive.bottom_shadow_color;
377 values.background = lw->core.background_pixel;
379 lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
380 &values, dynamic, (XtGCMask)0);
381 (*old_label_expose)(_w, _event, _region);
382 XtReleaseGC(_w, lw->label.insensitive_GC);
384 lw->label.insensitive_GC = insensitiveGC;
389 * Create all the motif widgets necessary.
392 gui_x11_create_widgets(void)
394 #ifdef FEAT_GUI_TABLINE
395 Widget button, scroller;
402 * Install the 3D shade effect drawing routines.
404 if (old_label_expose == NULL)
406 old_label_expose = xmLabelWidgetClass->core_class.expose;
407 xmLabelWidgetClass->core_class.expose = label_expose;
411 * Start out by adding the configured border width into the border offset
413 gui.border_offset = gui.border_width;
416 * Install the tearOffModel resource converter.
418 #if (XmVersion >= 1002)
419 XmRepTypeInstallTearOffModelConverter();
422 /* Make sure the "Quit" menu entry of the window manager is ignored */
423 XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);
425 vimForm = XtVaCreateManagedWidget("vimForm",
426 xmFormWidgetClass, vimShell,
428 XmNhighlightThickness, 0,
429 XmNshadowThickness, 0,
432 XmNresizePolicy, XmRESIZE_ANY,
434 gui_motif_menu_colors(vimForm);
438 Arg al[7]; /* Make sure there is enough room for arguments! */
441 # if (XmVersion >= 1002)
442 XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
444 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
445 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
446 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
447 # ifndef FEAT_TOOLBAR
448 /* Always stick to right hand side. */
449 XtSetArg(al[ac], XmNrightOffset, 0); ac++;
451 XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
452 menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
453 XtManageChild(menuBar);
455 /* Remember the default colors, needed for ":hi clear". */
456 XtVaGetValues(menuBar,
457 XmNbackground, &gui.menu_def_bg_pixel,
458 XmNforeground, &gui.menu_def_fg_pixel,
460 gui_motif_menu_colors(menuBar);
466 * Create an empty ToolBar. We should get buttons defined from menu.vim.
468 toolBarFrame = XtVaCreateWidget("toolBarFrame",
469 xmFrameWidgetClass, vimForm,
470 XmNshadowThickness, 0,
473 XmNleftAttachment, XmATTACH_FORM,
474 XmNrightAttachment, XmATTACH_FORM,
476 gui_motif_menu_colors(toolBarFrame);
478 toolBar = XtVaCreateManagedWidget("toolBar",
479 xmRowColumnWidgetClass, toolBarFrame,
480 XmNchildType, XmFRAME_WORKAREA_CHILD,
481 XmNrowColumnType, XmWORK_AREA,
482 XmNorientation, XmHORIZONTAL,
483 XmNtraversalOn, False,
484 XmNisHomogeneous, False,
485 XmNpacking, XmPACK_TIGHT,
487 XmNshadowThickness, 0,
488 XmNhighlightThickness, 0,
493 gui_motif_menu_colors(toolBar);
497 #ifdef FEAT_GUI_TABLINE
498 /* Create the Vim GUI tabline */
500 XtSetArg(args[n], XmNbindingType, XmNONE); n++;
501 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
502 XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
503 XtSetArg(args[n], XmNbackPageNumber, 0); n++;
504 XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
505 XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
506 XtSetArg(args[n], XmNshadowThickness, 0); n++;
507 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
508 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
509 tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);
511 XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
513 XtAddEventHandler(tabLine, ButtonPressMask, False,
514 (XtEventHandler)tabline_menu_cb, NULL);
516 gui.tabline_height = TABLINE_HEIGHT;
519 * Set the size of the minor next/prev scrollers to zero, so
520 * that they are not displayed. Due to a bug in OpenMotif 2.3,
521 * even if these children widget are unmanaged, they are again
522 * managed by the Notebook widget and the notebook widget geometry
523 * is adjusted to account for the minor scroller widgets.
525 scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
526 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
527 XmNtraversalOn, False, NULL);
528 scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
529 XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
530 XmNtraversalOn, False, NULL);
532 /* Create the tabline popup menu */
533 tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);
535 /* Add the buttons to the menu */
536 if (first_tabpage->tp_next != NULL)
539 XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
540 xms = XmStringCreate((char *)"Close tab", STRING_TAG);
541 XtSetArg(args[n], XmNlabelString, xms); n++;
542 button = XmCreatePushButton(tabLine_menu, "Close", args, n);
543 XtAddCallback(button, XmNactivateCallback,
544 (XtCallbackProc)tabline_button_cb, NULL);
549 XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
550 xms = XmStringCreate((char *)"New Tab", STRING_TAG);
551 XtSetArg(args[n], XmNlabelString, xms); n++;
552 button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
553 XtAddCallback(button, XmNactivateCallback,
554 (XtCallbackProc)tabline_button_cb, NULL);
558 XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
559 xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
560 XtSetArg(args[n], XmNlabelString, xms); n++;
561 button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
562 XtAddCallback(button, XmNactivateCallback,
563 (XtCallbackProc)tabline_button_cb, NULL);
567 textAreaForm = XtVaCreateManagedWidget("textAreaForm",
568 xmFormWidgetClass, vimForm,
569 XmNleftAttachment, XmATTACH_FORM,
570 XmNrightAttachment, XmATTACH_FORM,
571 XmNbottomAttachment, XmATTACH_FORM,
572 XmNtopAttachment, XmATTACH_FORM,
575 XmNresizePolicy, XmRESIZE_ANY,
577 gui_motif_scroll_colors(textAreaForm);
579 textArea = XtVaCreateManagedWidget("textArea",
580 xmDrawingAreaWidgetClass, textAreaForm,
581 XmNforeground, gui.norm_pixel,
582 XmNbackground, gui.back_pixel,
583 XmNleftAttachment, XmATTACH_FORM,
584 XmNtopAttachment, XmATTACH_FORM,
585 XmNrightAttachment, XmATTACH_FORM,
586 XmNbottomAttachment, XmATTACH_FORM,
589 * These take some control away from the user, but avoids making them
590 * add resources to get a decent looking setup.
593 XmNhighlightThickness, 0,
594 XmNshadowThickness, 0,
601 footer = XtVaCreateWidget("footer",
602 xmLabelGadgetClass, vimForm,
603 XmNalignment, XmALIGNMENT_BEGINNING,
606 XmNtraversalOn, False,
607 XmNrecomputeSize, False,
608 XmNleftAttachment, XmATTACH_FORM,
610 XmNrightAttachment, XmATTACH_FORM,
611 XmNbottomAttachment, XmATTACH_FORM,
613 gui_mch_set_footer((char_u *) "");
617 * Install the callbacks.
619 gui_x11_callbacks(textArea, vimForm);
621 /* Pretend we don't have input focus, we will get an event if we do. */
622 gui.in_focus = FALSE;
626 * Called when the GUI is not going to start after all.
629 gui_x11_destroy_widgets(void)
638 gui_mch_set_text_area_pos(
645 /* Give keyboard focus to the textArea instead of the toolbar. */
651 gui_x11_set_back_color(void)
653 if (textArea != NULL)
654 #if (XmVersion >= 1002)
655 XmChangeColor(textArea, gui.back_pixel);
657 XtVaSetValues(textArea,
658 XmNbackground, gui.back_pixel,
664 * Manage dialog centered on pointer. This could be used by the Athena code as
668 manage_centered(Widget dialog_child)
670 Widget shell = XtParent(dialog_child);
673 unsigned int width, height, border_width, depth;
674 int x, y, win_x, win_y, maxX, maxY;
675 Boolean mappedWhenManaged;
677 /* Temporarily set value of XmNmappedWhenManaged
678 to stop the dialog from popping up right away */
679 XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
680 XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);
682 XtManageChild(dialog_child);
684 /* Get the pointer position (x, y) */
685 XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
686 &x, &y, &win_x, &win_y, &mask);
688 /* Translate the pointer position (x, y) into a position for the new
689 window that will place the pointer at its center */
690 XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
691 &width, &height, &border_width, &depth);
692 width += 2 * border_width;
693 height += 2 * border_width;
697 /* Ensure that the dialog remains on screen */
698 maxX = XtScreen(shell)->width - width;
699 maxY = XtScreen(shell)->height - height;
709 /* Set desired window position in the DialogShell */
710 XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);
715 /* Restore the value of XmNmappedWhenManaged */
716 XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
719 #if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
720 || defined(FEAT_GUI_DIALOG) || defined(PROTO)
723 * Encapsulate the way an XmFontList is created.
726 gui_motif_create_fontlist(XFontStruct *font)
728 XmFontList font_list;
730 # if (XmVersion <= 1001)
731 /* Motif 1.1 method */
732 font_list = XmFontListCreate(font, STRING_TAG);
734 /* Motif 1.2 method */
735 XmFontListEntry font_list_entry;
737 font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
739 font_list = XmFontListAppendEntry(NULL, font_list_entry);
740 XmFontListEntryFree(&font_list_entry);
745 # if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
747 gui_motif_fontset2fontlist(XFontSet *fontset)
749 XmFontList font_list;
751 /* Motif 1.2 method */
752 XmFontListEntry font_list_entry;
754 font_list_entry = XmFontListEntryCreate(STRING_TAG,
756 (XtPointer)*fontset);
757 font_list = XmFontListAppendEntry(NULL, font_list_entry);
758 XmFontListEntryFree(&font_list_entry);
765 #if defined(FEAT_MENU) || defined(PROTO)
770 static void gui_motif_add_actext(vimmenu_T *menu);
771 #if (XmVersion >= 1002)
772 static void toggle_tearoff(Widget wid);
773 static void gui_mch_recurse_tearoffs(vimmenu_T *menu);
775 static void submenu_change(vimmenu_T *mp, int colors);
777 static void do_set_mnemonics(int enable);
778 static int menu_enabled = TRUE;
781 gui_mch_enable_menu(int flag)
785 XtManageChild(menuBar);
787 if (XtIsManaged(XtParent(toolBar)))
789 /* toolBar is attached to top form */
790 XtVaSetValues(XtParent(toolBar),
791 XmNtopAttachment, XmATTACH_WIDGET,
792 XmNtopWidget, menuBar,
794 #ifdef FEAT_GUI_TABLINE
797 XtVaSetValues(tabLine,
798 XmNtopAttachment, XmATTACH_WIDGET,
799 XmNtopWidget, XtParent(toolBar),
801 XtVaSetValues(textAreaForm,
802 XmNtopAttachment, XmATTACH_WIDGET,
803 XmNtopWidget, tabLine,
808 XtVaSetValues(textAreaForm,
809 XmNtopAttachment, XmATTACH_WIDGET,
810 XmNtopWidget, XtParent(toolBar),
816 #ifdef FEAT_GUI_TABLINE
819 XtVaSetValues(tabLine,
820 XmNtopAttachment, XmATTACH_WIDGET,
821 XmNtopWidget, menuBar,
823 XtVaSetValues(textAreaForm,
824 XmNtopAttachment, XmATTACH_WIDGET,
825 XmNtopWidget, tabLine,
830 XtVaSetValues(textAreaForm,
831 XmNtopAttachment, XmATTACH_WIDGET,
832 XmNtopWidget, menuBar,
838 XtUnmanageChild(menuBar);
840 if (XtIsManaged(XtParent(toolBar)))
842 XtVaSetValues(XtParent(toolBar),
843 XmNtopAttachment, XmATTACH_FORM,
845 #ifdef FEAT_GUI_TABLINE
848 XtVaSetValues(tabLine,
849 XmNtopAttachment, XmATTACH_WIDGET,
850 XmNtopWidget, XtParent(toolBar),
852 XtVaSetValues(textAreaForm,
853 XmNtopAttachment, XmATTACH_WIDGET,
854 XmNtopWidget, tabLine,
859 XtVaSetValues(textAreaForm,
860 XmNtopAttachment, XmATTACH_WIDGET,
861 XmNtopWidget, XtParent(toolBar),
867 #ifdef FEAT_GUI_TABLINE
870 XtVaSetValues(tabLine,
871 XmNtopAttachment, XmATTACH_FORM,
873 XtVaSetValues(textAreaForm,
874 XmNtopAttachment, XmATTACH_WIDGET,
875 XmNtopWidget, tabLine,
880 XtVaSetValues(textAreaForm,
881 XmNtopAttachment, XmATTACH_FORM,
889 * Enable or disable mnemonics for the toplevel menus.
892 gui_motif_set_mnemonics(int enable)
895 * Don't enable menu mnemonics when the menu bar is disabled, LessTif
896 * crashes when using a mnemonic then.
900 do_set_mnemonics(enable);
904 do_set_mnemonics(int enable)
908 for (menu = root_menu; menu != NULL; menu = menu->next)
909 if (menu->id != (Widget)0)
910 XtVaSetValues(menu->id,
911 XmNmnemonic, enable ? menu->mnemonic : NUL,
916 gui_mch_add_menu(vimmenu_T *menu, int idx)
920 vimmenu_T *parent = menu->parent;
923 if (menu_is_popup(menu->name))
928 /* Only create the popup menu when it's actually used, otherwise there
929 * is a delay when using the right mouse button. */
930 # if (XmVersion <= 1002)
931 if (mouse_model_popup())
934 if (gui.menu_bg_pixel != INVALCOLOR)
936 XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
938 if (gui.menu_fg_pixel != INVALCOLOR)
940 XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
942 menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
944 menu->id = (Widget)0;
950 if (!menu_is_menubar(menu->name)
951 || (parent != NULL && parent->submenu_id == (Widget)0))
954 label = XmStringCreate((char *)menu->dname, STRING_TAG);
957 menu->id = XtVaCreateWidget("subMenu",
958 xmCascadeButtonWidgetClass,
959 (parent == NULL) ? menuBar : parent->submenu_id,
960 XmNlabelString, label,
961 XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
962 #if (XmVersion >= 1002)
963 /* submenu: count the tearoff item (needed for LessTif) */
964 XmNpositionIndex, idx + (parent != NULL
965 && tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
968 gui_motif_menu_colors(menu->id);
969 gui_motif_menu_fontlist(menu->id);
972 if (menu->id == (Widget)0) /* failed */
975 /* add accelerator text */
976 gui_motif_add_actext(menu);
978 shell = XtVaCreateWidget("subMenuShell",
979 xmMenuShellWidgetClass, menu->id,
983 gui_motif_menu_colors(shell);
984 menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
985 xmRowColumnWidgetClass, shell,
986 XmNrowColumnType, XmMENU_PULLDOWN,
988 gui_motif_menu_colors(menu->submenu_id);
990 if (menu->submenu_id == (Widget)0) /* failed */
993 #if (XmVersion >= 1002)
994 /* Set the colors for the tear off widget */
995 toggle_tearoff(menu->submenu_id);
998 XtVaSetValues(menu->id,
999 XmNsubMenuId, menu->submenu_id,
1003 * The "Help" menu is a special case, and should be placed at the far
1004 * right hand side of the menu-bar. It's recognized by its high priority.
1006 if (parent == NULL && menu->priority >= 9999)
1007 XtVaSetValues(menuBar,
1008 XmNmenuHelpWidget, menu->id,
1012 * When we add a top-level item to the menu bar, we can figure out how
1013 * high the menu bar should be.
1016 gui_mch_compute_menu_height(menu->id);
1021 * Add mnemonic and accelerator text to a menu button.
1024 gui_motif_add_actext(vimmenu_T *menu)
1028 /* Add accelerator text, if there is one */
1029 if (menu->actext != NULL && menu->id != (Widget)0)
1031 label = XmStringCreate((char *)menu->actext, STRING_TAG);
1034 XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
1035 XmStringFree(label);
1040 gui_mch_toggle_tearoffs(int enable)
1042 #if (XmVersion >= 1002)
1044 tearoff_val = (int)XmTEAR_OFF_ENABLED;
1046 tearoff_val = (int)XmTEAR_OFF_DISABLED;
1047 toggle_tearoff(menuBar);
1048 gui_mch_recurse_tearoffs(root_menu);
1052 #if (XmVersion >= 1002)
1054 * Set the tearoff for one menu widget on or off, and set the color of the
1058 toggle_tearoff(Widget wid)
1062 XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
1063 if (tearoff_val == (int)XmTEAR_OFF_ENABLED
1064 && (w = XmGetTearOffControl(wid)) != (Widget)0)
1065 gui_motif_menu_colors(w);
1069 gui_mch_recurse_tearoffs(vimmenu_T *menu)
1071 while (menu != NULL)
1073 if (!menu_is_popup(menu->name))
1075 if (menu->submenu_id != (Widget)0)
1076 toggle_tearoff(menu->submenu_id);
1077 gui_mch_recurse_tearoffs(menu->children);
1085 gui_mch_text_area_extra_height(void)
1087 Dimension shadowHeight;
1089 XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
1090 return shadowHeight;
1094 * Compute the height of the menu bar.
1095 * We need to check all the items for their position and height, for the case
1096 * there are several rows, and/or some characters extend higher or lower.
1099 gui_mch_compute_menu_height(
1100 Widget id) /* can be NULL when deleting menu */
1103 Dimension margin, shadow;
1105 static Dimension height = 21; /* normal height of a menu item */
1108 * Get the height of the new item, before managing it, because it will
1109 * still reflect the font size. After managing it depends on the menu
1110 * height, which is what we just wanted to get!.
1112 if (id != (Widget)0)
1113 XtVaGetValues(id, XmNheight, &height, NULL);
1115 /* Find any menu Widget, to be able to call XtManageChild() */
1117 for (mp = root_menu; mp != NULL; mp = mp->next)
1118 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1125 * Now manage the menu item, to make them all be positioned (makes an
1126 * extra row when needed, removes it when not needed).
1128 if (id != (Widget)0)
1132 * Now find the menu item that is the furthest down, and get it's position.
1135 for (mp = root_menu; mp != NULL; mp = mp->next)
1137 if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
1139 XtVaGetValues(mp->id, XmNy, &y, NULL);
1145 XtVaGetValues(menuBar,
1146 XmNmarginHeight, &margin,
1147 XmNshadowThickness, &shadow,
1151 * This computation is the result of trial-and-error:
1152 * maxy = The maximum position of an item; required for when there are
1154 * height = height of an item, before managing it; Hopefully this will
1155 * change with the font height. Includes shadow-border.
1156 * shadow = shadow-border; must be subtracted from the height.
1157 * margin = margin around the menu buttons; Must be added.
1158 * Add 4 for the underlining of shortcut keys.
1160 gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;
1162 /* Somehow the menu bar doesn't resize automatically. Set it here,
1163 * even though this is a catch 22. Don't do this when starting up,
1164 * somehow the menu gets very high then. */
1165 if (gui.shell_created)
1166 XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
1172 * Icons used by the toolbar code.
1174 #include "gui_x11_pm.h"
1176 static int check_xpm(char_u *path);
1177 static char **get_toolbar_pixmap(vimmenu_T *menu, char **fname);
1178 static int add_pixmap_args(vimmenu_T *menu, Arg *args, int n);
1181 * Read an Xpm file. Return OK or FAIL.
1184 check_xpm(char_u *path)
1186 XpmAttributes attrs;
1191 attrs.valuemask = 0;
1193 /* Create the "sensitive" pixmap */
1194 status = XpmReadFileToPixmap(gui.dpy,
1195 RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
1196 (char *)path, &map, &mask, &attrs);
1197 XpmFreeAttributes(&attrs);
1199 if (status == XpmSuccess)
1206 * Allocated a pixmap for toolbar menu "menu".
1207 * When it's to be read from a file, "fname" is set to the file name
1208 * (in allocated memory).
1209 * Return a blank pixmap if it fails.
1212 get_toolbar_pixmap(vimmenu_T *menu, char **fname)
1214 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
1215 char **xpm = NULL; /* xpm array */
1219 buf[0] = NUL; /* start with NULL path */
1221 if (menu->iconfile != NULL)
1223 /* Use the "icon=" argument. */
1224 gui_find_iconfile(menu->iconfile, buf, "xpm");
1225 res = check_xpm(buf);
1227 /* If it failed, try using the menu name. */
1228 if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
1229 res = check_xpm(buf);
1232 *fname = (char *)vim_strsave(buf);
1233 return tb_blank_xpm;
1237 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
1239 if (menu->iconidx >= 0 && menu->iconidx
1240 < (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
1241 xpm = built_in_pixmaps[menu->iconidx];
1250 * Add arguments for the toolbar pixmap to a menu item.
1253 add_pixmap_args(vimmenu_T *menu, Arg *args, int n)
1255 vim_free(menu->xpm_fname);
1256 menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
1257 if (menu->xpm == NULL)
1259 XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
1263 if (menu->xpm_fname != NULL)
1265 XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
1267 XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
1268 XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
1272 #endif /* FEAT_TOOLBAR */
1275 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
1278 vimmenu_T *parent = menu->parent;
1284 # if (XmVersion <= 1002)
1285 /* Don't add Popup menu items when the popup menu isn't used. */
1286 if (menu_is_child_of_popup(menu) && !mouse_model_popup())
1290 # ifdef FEAT_TOOLBAR
1291 if (menu_is_toolbar(parent->name))
1294 XmString xms = NULL; /* fallback label if pixmap not found */
1299 if (menu_is_separator(menu->name))
1305 * A separator has the format "-sep%d[:%d]-". The optional :%d is
1306 * a width specifier. If no width is specified then we choose one.
1308 cp = (char *)vim_strchr(menu->name, ':');
1310 wid = (Dimension)atoi(++cp);
1314 type = xmSeparatorWidgetClass;
1315 XtSetArg(args[n], XmNwidth, wid); n++;
1316 XtSetArg(args[n], XmNminWidth, wid); n++;
1317 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
1318 XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
1322 /* Without shadows one can't sense whatever the button has been
1323 * pressed or not! However we want to save a bit of space...
1324 * Need the highlightThickness to see the focus.
1326 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
1327 XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
1328 XtSetArg(args[n], XmNmarginWidth, 0); n++;
1329 XtSetArg(args[n], XmNmarginHeight, 0); n++;
1330 XtSetArg(args[n], XmNtraversalOn, False); n++;
1331 /* Set the label here, so that we can switch between icons/text
1332 * by changing the XmNlabelType resource. */
1333 xms = XmStringCreate((char *)menu->dname, STRING_TAG);
1334 XtSetArg(args[n], XmNlabelString, xms); n++;
1336 n = add_pixmap_args(menu, args, n);
1338 type = xmEnhancedButtonWidgetClass;
1341 XtSetArg(args[n], XmNpositionIndex, idx); n++;
1342 if (menu->id == NULL)
1344 menu->id = XtCreateManagedWidget((char *)menu->dname,
1345 type, toolBar, args, n);
1346 if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
1348 XtAddCallback(menu->id,
1349 XmNactivateCallback, gui_x11_menu_cb, menu);
1351 XtAddEventHandler(menu->id, EnterWindowMask, False,
1352 toolbarbutton_enter_cb, menu);
1353 XtAddEventHandler(menu->id, LeaveWindowMask, False,
1354 toolbarbutton_leave_cb, menu);
1359 XtSetValues(menu->id, args, n);
1364 gui_mch_menu_set_tip(menu);
1367 menu->parent = parent;
1368 menu->submenu_id = NULL;
1369 /* When adding first item to toolbar it might have to be enabled .*/
1370 if (!XtIsManaged(XtParent(toolBar))
1371 && vim_strchr(p_go, GO_TOOLBAR) != NULL)
1372 gui_mch_show_toolbar(TRUE);
1373 gui.toolbar_height = gui_mch_compute_toolbar_height();
1375 } /* toolbar menu item */
1378 /* No parent, must be a non-menubar menu */
1379 if (parent->submenu_id == (Widget)0)
1382 menu->submenu_id = (Widget)0;
1384 /* Add menu separator */
1385 if (menu_is_separator(menu->name))
1387 menu->id = XtVaCreateWidget("subMenu",
1388 xmSeparatorGadgetClass, parent->submenu_id,
1389 #if (XmVersion >= 1002)
1390 /* count the tearoff item (needed for LessTif) */
1391 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1395 gui_motif_menu_colors(menu->id);
1399 label = XmStringCreate((char *)menu->dname, STRING_TAG);
1402 menu->id = XtVaCreateWidget("subMenu",
1403 xmPushButtonWidgetClass, parent->submenu_id,
1404 XmNlabelString, label,
1405 XmNmnemonic, menu->mnemonic,
1406 #if (XmVersion >= 1002)
1407 /* count the tearoff item (needed for LessTif) */
1408 XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
1412 gui_motif_menu_colors(menu->id);
1413 gui_motif_menu_fontlist(menu->id);
1414 XmStringFree(label);
1416 if (menu->id != (Widget)0)
1418 XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
1420 /* add accelerator text */
1421 gui_motif_add_actext(menu);
1425 #if (XmVersion <= 1002) || defined(PROTO)
1427 * This function will destroy/create the popup menus dynamically,
1428 * according to the value of 'mousemodel'.
1429 * This will fix the "right mouse button freeze" that occurs when
1430 * there exists a popup menu but it isn't managed.
1433 gui_motif_update_mousemodel(vimmenu_T *menu)
1437 /* When GUI hasn't started the menus have not been created. */
1443 if (menu->children != NULL)
1445 if (menu_is_popup(menu->name))
1447 if (mouse_model_popup())
1449 /* Popup menu will be used. Create the popup menus. */
1450 gui_mch_add_menu(menu, idx);
1451 gui_motif_update_mousemodel(menu->children);
1455 /* Popup menu will not be used. Destroy the popup menus. */
1456 gui_motif_update_mousemodel(menu->children);
1457 gui_mch_destroy_menu(menu);
1461 else if (menu_is_child_of_popup(menu))
1463 if (mouse_model_popup())
1464 gui_mch_add_menu_item(menu, idx);
1466 gui_mch_destroy_menu(menu);
1475 gui_mch_new_menu_colors(void)
1477 if (menuBar == (Widget)0)
1479 gui_motif_menu_colors(menuBar);
1481 gui_motif_menu_colors(toolBarFrame);
1482 gui_motif_menu_colors(toolBar);
1485 submenu_change(root_menu, TRUE);
1489 gui_mch_new_menu_font(void)
1491 if (menuBar == (Widget)0)
1493 submenu_change(root_menu, FALSE);
1498 XtVaGetValues(menuBar, XmNheight, &height, NULL);
1499 gui.menu_height = height;
1501 XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
1502 gui_resize_shell(w, h
1504 - xim_get_status_area_height()
1508 gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
1512 #if defined(FEAT_BEVAL) || defined(PROTO)
1514 gui_mch_new_tooltip_font(void)
1516 # ifdef FEAT_TOOLBAR
1519 if (toolBar == (Widget)0)
1522 menu = gui_find_menu((char_u *)"ToolBar");
1524 submenu_change(menu, FALSE);
1529 gui_mch_new_tooltip_colors(void)
1531 # ifdef FEAT_TOOLBAR
1534 if (toolBar == (Widget)0)
1537 toolbar = gui_find_menu((char_u *)"ToolBar");
1538 if (toolbar != NULL)
1539 submenu_change(toolbar, TRUE);
1547 int colors) /* TRUE for colors, FALSE for font */
1551 for (mp = menu; mp != NULL; mp = mp->next)
1553 if (mp->id != (Widget)0)
1557 gui_motif_menu_colors(mp->id);
1559 /* For a toolbar item: Free the pixmap and allocate a new one,
1560 * so that the background color is right. */
1561 if (mp->xpm != NULL)
1566 n = add_pixmap_args(mp, args, n);
1567 XtSetValues(mp->id, args, n);
1570 /* If we have a tooltip, then we need to change it's font */
1571 if (mp->tip != NULL)
1575 args[0].name = XmNbackground;
1576 args[0].value = gui.tooltip_bg_pixel;
1577 args[1].name = XmNforeground;
1578 args[1].value = gui.tooltip_fg_pixel;
1579 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1586 gui_motif_menu_fontlist(mp->id);
1588 /* If we have a tooltip, then we need to change it's font */
1589 if (mp->tip != NULL)
1593 args[0].name = XmNfontList;
1594 args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
1595 &gui.tooltip_fontset);
1596 XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
1602 if (mp->children != NULL)
1604 #if (XmVersion >= 1002)
1605 /* Set the colors/font for the tear off widget */
1606 if (mp->submenu_id != (Widget)0)
1609 gui_motif_menu_colors(mp->submenu_id);
1611 gui_motif_menu_fontlist(mp->submenu_id);
1612 toggle_tearoff(mp->submenu_id);
1615 /* Set the colors for the children */
1616 submenu_change(mp->children, colors);
1622 * Destroy the machine specific menu widget.
1625 gui_mch_destroy_menu(vimmenu_T *menu)
1627 /* Please be sure to destroy the parent widget first (i.e. menu->id).
1628 * On the other hand, problems have been reported that the submenu must be
1631 * This code should be basically identical to that in the file gui_athena.c
1632 * because they are both Xt based.
1634 if (menu->submenu_id != (Widget)0)
1636 XtDestroyWidget(menu->submenu_id);
1637 menu->submenu_id = (Widget)0;
1640 if (menu->id != (Widget)0)
1644 parent = XtParent(menu->id);
1645 #if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)
1646 if (parent == toolBar && menu->tip != NULL)
1648 /* We try to destroy this before the actual menu, because there are
1649 * callbacks, etc. that will be unregistered during the tooltip
1652 * If you call "gui_mch_destroy_beval_area()" after destroying
1653 * menu->id, then the tooltip's window will have already been
1654 * deallocated by Xt, and unknown behaviour will ensue (probably
1657 gui_mch_destroy_beval_area(menu->tip);
1661 XtDestroyWidget(menu->id);
1662 menu->id = (Widget)0;
1663 if (parent == menuBar)
1664 gui_mch_compute_menu_height((Widget)0);
1666 else if (parent == toolBar)
1668 Cardinal num_children;
1670 /* When removing last toolbar item, don't display the toolbar. */
1671 XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
1672 if (num_children == 0)
1673 gui_mch_show_toolbar(FALSE);
1675 gui.toolbar_height = gui_mch_compute_toolbar_height();
1682 gui_mch_show_popupmenu(vimmenu_T *menu UNUSED)
1685 XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
1686 XtManageChild(menu->submenu_id);
1690 #endif /* FEAT_MENU */
1693 * Set the menu and scrollbar colors to their default values.
1696 gui_mch_def_colors(void)
1700 /* Use the values saved when starting up. These should come from the
1701 * window manager or a resources file. */
1702 gui.menu_fg_pixel = gui.menu_def_fg_pixel;
1703 gui.menu_bg_pixel = gui.menu_def_bg_pixel;
1704 gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
1705 gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
1707 gui.tooltip_fg_pixel =
1708 gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
1709 gui.tooltip_bg_pixel =
1710 gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
1721 gui_mch_set_scrollbar_thumb(
1727 if (sb->id != (Widget)0)
1728 XtVaSetValues(sb->id,
1730 XmNsliderSize, size,
1731 XmNpageIncrement, (size > 2 ? size - 2 : 1),
1732 XmNmaximum, max + 1, /* Motif has max one past the end */
1737 gui_mch_set_scrollbar_pos(
1744 if (sb->id != (Widget)0)
1746 if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
1749 h -= gui.border_offset;
1751 y -= gui.border_offset;
1752 XtVaSetValues(sb->id,
1754 XmNbottomOffset, -y - h,
1759 XtVaSetValues(sb->id,
1762 XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
1763 ? gui.scrollbar_width : 0,
1766 XtManageChild(sb->id);
1771 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
1776 if (sb->id != (Widget)0)
1784 XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
1788 XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
1792 XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
1795 XtSetValues(textArea, args, n);
1796 XtManageChild(sb->id);
1800 if (!gui.which_scrollbars[sb->type])
1802 /* The scrollbars of this type are all disabled, adjust the
1803 * textArea attachment offset. */
1807 XtSetArg(args[n], XmNleftOffset, 0); n++;
1811 XtSetArg(args[n], XmNrightOffset, 0); n++;
1815 XtSetArg(args[n], XmNbottomOffset, 0);n++;
1818 XtSetValues(textArea, args, n);
1820 XtUnmanageChild(sb->id);
1826 gui_mch_create_scrollbar(
1828 int orient) /* SBAR_VERT or SBAR_HORIZ */
1834 XtSetArg(args[n], XmNminimum, 0); n++;
1835 XtSetArg(args[n], XmNorientation,
1836 (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;
1841 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1842 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1843 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1847 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1848 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
1849 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1853 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1854 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1855 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1859 sb->id = XtCreateWidget("scrollBar",
1860 xmScrollBarWidgetClass, textAreaForm, args, n);
1862 /* Remember the default colors, needed for ":hi clear". */
1863 if (gui.scroll_def_bg_pixel == (guicolor_T)0
1864 && gui.scroll_def_fg_pixel == (guicolor_T)0)
1865 XtVaGetValues(sb->id,
1866 XmNbackground, &gui.scroll_def_bg_pixel,
1867 XmNforeground, &gui.scroll_def_fg_pixel,
1870 if (sb->id != (Widget)0)
1872 gui_mch_set_scrollbar_colors(sb);
1873 XtAddCallback(sb->id, XmNvalueChangedCallback,
1874 scroll_cb, (XtPointer)sb->ident);
1875 XtAddCallback(sb->id, XmNdragCallback,
1876 scroll_cb, (XtPointer)sb->ident);
1877 XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
1882 #if defined(FEAT_WINDOWS) || defined(PROTO)
1884 gui_mch_destroy_scrollbar(scrollbar_T *sb)
1886 if (sb->id != (Widget)0)
1887 XtDestroyWidget(sb->id);
1892 gui_mch_set_scrollbar_colors(scrollbar_T *sb)
1894 if (sb->id != (Widget)0)
1896 if (gui.scroll_bg_pixel != INVALCOLOR)
1898 #if (XmVersion>=1002)
1899 XmChangeColor(sb->id, gui.scroll_bg_pixel);
1901 XtVaSetValues(sb->id,
1902 XmNtroughColor, gui.scroll_bg_pixel,
1907 if (gui.scroll_fg_pixel != INVALCOLOR)
1908 XtVaSetValues(sb->id,
1909 XmNforeground, gui.scroll_fg_pixel,
1910 #if (XmVersion<1002)
1911 XmNbackground, gui.scroll_fg_pixel,
1916 /* This is needed for the rectangle below the vertical scrollbars. */
1917 if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
1918 gui_motif_scroll_colors(textAreaForm);
1922 * Miscellaneous stuff:
1926 gui_x11_get_wid(void)
1928 return(XtWindow(textArea));
1932 * Look for a widget in the widget tree w, with a mnemonic matching keycode.
1933 * When one is found, simulate a button press on that widget and give it the
1934 * keyboard focus. If the mnemonic is on a label, look in the userData field
1935 * of the label to see if it points to another widget, and give that the focus.
1938 do_mnemonic(Widget w, unsigned int keycode)
1940 WidgetList children;
1943 KeySym mnemonic = '\0';
1946 unsigned char rowColType;
1948 if (XtIsComposite(w))
1950 if (XtClass(w) == xmRowColumnWidgetClass)
1952 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
1953 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
1959 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
1960 &numChildren, NULL);
1961 for (i = 0; i < numChildren; i++)
1962 do_mnemonic(children[i], keycode);
1967 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
1968 if (mnemonic != '\0')
1970 mneString[0] = mnemonic;
1971 mneString[1] = '\0';
1972 if (XKeysymToKeycode(XtDisplay(XtParent(w)),
1973 XStringToKeysym(mneString)) == keycode)
1975 if (XtClass(w) == xmLabelWidgetClass
1976 || XtClass(w) == xmLabelGadgetClass)
1978 XtVaGetValues(w, XmNuserData, &userData, NULL);
1979 if (userData != NULL && XtIsWidget(userData))
1980 XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
1984 XKeyPressedEvent keyEvent;
1986 XmProcessTraversal(w, XmTRAVERSE_CURRENT);
1988 vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
1989 keyEvent.type = KeyPress;
1990 keyEvent.serial = 1;
1991 keyEvent.send_event = True;
1992 keyEvent.display = XtDisplay(w);
1993 keyEvent.window = XtWindow(w);
1994 XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
2003 * Callback routine for dialog mnemonic processing.
2006 mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
2008 do_mnemonic(w, event->keycode);
2013 * Search the widget tree under w for widgets with mnemonics. When found, add
2014 * a passive grab to the dialog widget for the mnemonic character, thus
2015 * directing mnemonic events to the dialog widget.
2018 add_mnemonic_grabs(Widget dialog, Widget w)
2021 WidgetList children;
2024 KeySym mnemonic = '\0';
2025 unsigned char rowColType;
2027 if (XtIsComposite(w))
2029 if (XtClass(w) == xmRowColumnWidgetClass)
2031 XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
2032 isMenu = (rowColType != (unsigned char)XmWORK_AREA);
2038 XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
2039 &numChildren, NULL);
2040 for (i = 0; i < numChildren; i++)
2041 add_mnemonic_grabs(dialog, children[i]);
2046 XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
2047 if (mnemonic != '\0')
2049 mneString[0] = mnemonic;
2050 mneString[1] = '\0';
2051 XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
2052 XStringToKeysym(mneString)),
2053 Mod1Mask, True, GrabModeAsync, GrabModeAsync);
2059 * Add a handler for mnemonics in a dialog. Motif itself only handles
2060 * mnemonics in menus. Mnemonics added or changed after this call will be
2063 * To add a mnemonic to a text field or list, set the XmNmnemonic resource on
2064 * the appropriate label and set the XmNuserData resource of the label to the
2065 * widget to get the focus when the mnemonic is typed.
2068 activate_dialog_mnemonics(Widget dialog)
2073 XtAddEventHandler(dialog, KeyPressMask, False,
2074 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2075 add_mnemonic_grabs(dialog, dialog);
2079 * Removes the event handler and key-grabs for dialog mnemonic handling.
2082 suppress_dialog_mnemonics(Widget dialog)
2087 XtUngrabKey(dialog, AnyKey, Mod1Mask);
2088 XtRemoveEventHandler(dialog, KeyPressMask, False,
2089 (XtEventHandler) mnemonic_event, (XtPointer) NULL);
2092 #if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
2093 static void set_fontlist(Widget wg);
2096 * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
2099 set_fontlist(Widget id)
2103 #ifdef FONTSET_ALWAYS
2104 if (gui.fontset != NOFONTSET)
2106 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
2109 if (XtIsManaged(id))
2111 XtUnmanageChild(id);
2112 XtVaSetValues(id, XmNfontList, fl, NULL);
2113 /* We should force the widget to recalculate it's
2118 XtVaSetValues(id, XmNfontList, fl, NULL);
2123 if (gui.norm_font != NOFONT)
2125 fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
2128 if (XtIsManaged(id))
2130 XtUnmanageChild(id);
2131 XtVaSetValues(id, XmNfontList, fl, NULL);
2132 /* We should force the widget to recalculate it's
2137 XtVaSetValues(id, XmNfontList, fl, NULL);
2145 #if defined(FEAT_BROWSE) || defined(PROTO)
2148 * file selector related stuff
2151 #include <Xm/FileSB.h>
2152 #include <Xm/XmStrDefs.h>
2154 typedef struct dialog_callback_arg
2156 char * args; /* not used right now */
2160 static Widget dialog_wgt;
2161 static char *browse_fname = NULL;
2162 static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
2163 /* used to set up XmStrings */
2165 static void DialogCancelCB(Widget, XtPointer, XtPointer);
2166 static void DialogAcceptCB(Widget, XtPointer, XtPointer);
2169 * This function is used to translate the predefined label text of the
2170 * precomposed dialogs. We do this explicitly to allow:
2172 * - usage of gettext for translation, as in all the other places.
2174 * - equalize the messages between different GUI implementations as far as
2177 static void set_predefined_label(Widget parent, String name, char *new_label);
2180 set_predefined_label(Widget parent, String name, char *new_label)
2185 KeySym mnemonic = NUL;
2187 w = XtNameToWidget(parent, name);
2192 p = vim_strsave((char_u *)new_label);
2195 for (next = p; *next; ++next)
2197 if (*next == DLG_HOTKEY_CHAR)
2199 int len = STRLEN(next);
2203 mch_memmove(next, next + 1, len);
2209 str = XmStringCreate((char *)p, STRING_TAG);
2215 XmNlabelString, str,
2216 XmNmnemonic, mnemonic,
2220 gui_motif_menu_fontlist(w);
2224 set_predefined_fontlist(Widget parent, String name)
2227 w = XtNameToWidget(parent, name);
2236 * Put up a file requester.
2237 * Returns the selected name in allocated memory, or NULL for Cancel.
2241 int saving UNUSED, /* select file to write */
2242 char_u *title, /* title for the window */
2243 char_u *dflt, /* default name */
2244 char_u *ext UNUSED, /* not used (extension added) */
2245 char_u *initdir, /* initial directory, NULL for current dir */
2246 char_u *filter) /* file name filter */
2248 char_u dirbuf[MAXPATHL];
2249 char_u dfltbuf[MAXPATHL];
2251 char_u *tofree = NULL;
2253 /* There a difference between the resource name and value, Therefore, we
2254 * avoid to (ab-)use the (maybe internationalized!) dialog title as a
2258 dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);
2260 if (initdir == NULL || *initdir == NUL)
2262 mch_dirname(dirbuf, MAXPATHL);
2267 dflt = (char_u *)"";
2268 else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
2270 /* The default selection should be the full path, "dflt" is only the
2272 STRCPY(dfltbuf, initdir);
2273 add_pathsep(dfltbuf);
2274 STRCAT(dfltbuf, dflt);
2278 /* Can only use one pattern for a file name. Get the first pattern out of
2279 * the filter. An empty pattern means everything matches. */
2281 pattern = (char_u *)"";
2287 for (p = filter; *p != NUL; ++p)
2289 if (*p == '\t') /* end of description, start of pattern */
2291 if (*p == ';' || *p == '\n') /* end of (first) pattern */
2294 pattern = vim_strnsave(s, p - s);
2296 if (pattern == NULL)
2297 pattern = (char_u *)"";
2300 XtVaSetValues(dialog_wgt,
2302 XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
2304 XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
2306 XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
2308 XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
2311 set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
2312 set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
2313 set_predefined_label(dialog_wgt, "Dir", _("Directories"));
2314 set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
2315 set_predefined_label(dialog_wgt, "Help", _("&Help"));
2316 set_predefined_label(dialog_wgt, "Items", _("Files"));
2317 set_predefined_label(dialog_wgt, "OK", _("&OK"));
2318 set_predefined_label(dialog_wgt, "Selection", _("Selection"));
2320 /* This is to save us from silly external settings using not fixed with
2321 * fonts for file selection.
2323 set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
2324 set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");
2326 gui_motif_menu_colors(dialog_wgt);
2327 if (gui.scroll_bg_pixel != INVALCOLOR)
2328 XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);
2330 XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
2331 XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
2332 /* We have no help in this window, so hide help button */
2333 XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
2334 (unsigned char)XmDIALOG_HELP_BUTTON));
2336 manage_centered(dialog_wgt);
2337 activate_dialog_mnemonics(dialog_wgt);
2339 /* sit in a loop until the dialog box has gone away */
2342 XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
2343 (XtInputMask)XtIMAll);
2344 } while (XtIsManaged(dialog_wgt));
2346 suppress_dialog_mnemonics(dialog_wgt);
2347 XtDestroyWidget(dialog_wgt);
2350 if (browse_fname == NULL)
2352 return vim_strsave((char_u *)browse_fname);
2356 * The code below was originally taken from
2357 * /usr/examples/motif/xmsamplers/xmeditor.c
2358 * on Digital Unix 4.0d, but heavily modified.
2362 * Process callback from Dialog cancel actions.
2366 Widget w UNUSED, /* widget id */
2367 XtPointer client_data UNUSED, /* data from application */
2368 XtPointer call_data UNUSED) /* data from widget class */
2370 if (browse_fname != NULL)
2372 XtFree(browse_fname);
2373 browse_fname = NULL;
2375 XtUnmanageChild(dialog_wgt);
2379 * Process callback from Dialog actions.
2383 Widget w UNUSED, /* widget id */
2384 XtPointer client_data UNUSED, /* data from application */
2385 XtPointer call_data) /* data from widget class */
2387 XmFileSelectionBoxCallbackStruct *fcb;
2389 if (browse_fname != NULL)
2391 XtFree(browse_fname);
2392 browse_fname = NULL;
2394 fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
2396 /* get the filename from the file selection box */
2397 XmStringGetLtoR(fcb->value, charset, &browse_fname);
2399 /* popdown the file selection box */
2400 XtUnmanageChild(dialog_wgt);
2403 #endif /* FEAT_BROWSE */
2405 #if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2407 static int dialogStatus;
2409 static void keyhit_callback(Widget w, XtPointer client_data, XEvent *event, Boolean *cont);
2410 static void butproc(Widget w, XtPointer client_data, XtPointer call_data);
2413 * Callback function for the textfield. When CR is hit this works like
2414 * hitting the "OK" button, ESC like "Cancel".
2419 XtPointer client_data UNUSED,
2421 Boolean *cont UNUSED)
2426 if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
2430 else if (*buf == ESC)
2433 if ((key_sym == XK_Left || key_sym == XK_Right)
2434 && !(event->xkey.state & ShiftMask))
2435 XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
2441 XtPointer client_data,
2442 XtPointer call_data UNUSED)
2444 dialogStatus = (int)(long)client_data + 1;
2449 static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg);
2452 create_pixmap_label(
2466 XpmColorSymbol color[5] =
2469 {"iconColor1", NULL, 0},
2470 {"bottomShadowColor", NULL, 0},
2471 {"topShadowColor", NULL, 0},
2472 {"selectColor", NULL, 0}
2475 label = XmCreateLabelGadget(parent, name, args, arg);
2478 * We need to be careful here, since in case of gadgets, there is
2479 * no way to get the background color directly from the widget itself.
2480 * In such cases we get it from The Core part of his parent instead.
2482 dsp = XtDisplayOfObject(label);
2483 scr = XtScreenOfObject(label);
2484 XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
2485 ? label : XtParent(label),
2487 XmNbackground, &color[0].pixel,
2488 XmNforeground, &color[1].pixel,
2489 XmNbottomShadowColor, &color[2].pixel,
2490 XmNtopShadowColor, &color[3].pixel,
2491 XmNhighlight, &color[4].pixel,
2494 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
2495 attr.colorsymbols = color;
2496 attr.numsymbols = 5;
2497 attr.closeness = 65535;
2499 XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
2500 data, &pixmap, NULL, &attr);
2502 XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
2503 XtVaSetValues(label, XmNrecomputeSize, True, NULL);
2504 XtVaSetValues(label,
2505 XmNlabelType, XmPIXMAP,
2506 XmNlabelPixmap, pixmap,
2508 XtVaSetValues(label, XmNrecomputeSize, rs, NULL);
2519 char_u *button_names,
2521 char_u *textfield, /* buffer of size IOSIZE */
2530 Widget dialogform = NULL;
2532 Widget dialogtextfield = NULL;
2534 Widget sep_form = NULL;
2536 Widget separator = NULL;
2540 char **icon_data = NULL;
2541 Widget dialogpixmap = NULL;
2545 title = (char_u *)_("Vim dialog");
2547 /* if our pointer is currently hidden, then we should show it. */
2548 gui_mch_mousehide(FALSE);
2550 dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);
2552 /* Check 'v' flag in 'guioptions': vertical button placement. */
2553 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
2555 /* Set the title of the Dialog window */
2556 label = XmStringCreateSimple((char *)title);
2559 XtVaSetValues(dialogform,
2560 XmNdialogTitle, label,
2561 XmNhorizontalSpacing, 4,
2562 XmNverticalSpacing, vertical ? 0 : 4,
2564 XmStringFree(label);
2566 /* make a copy, so that we can insert NULs */
2567 buts = vim_strsave(button_names);
2571 /* Count the number of buttons and allocate buttons[]. */
2573 for (p = buts; *p; ++p)
2574 if (*p == DLG_BUTTON_SEP)
2576 buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
2577 if (buttons == NULL)
2584 * Create the buttons.
2586 sep_form = (Widget) 0;
2588 for (butcount = 0; *p; ++butcount)
2590 KeySym mnemonic = NUL;
2592 for (next = p; *next; ++next)
2594 if (*next == DLG_HOTKEY_CHAR)
2596 int len = STRLEN(next);
2600 mch_memmove(next, next + 1, len);
2604 if (*next == DLG_BUTTON_SEP)
2610 label = XmStringCreate(_((char *)p), STRING_TAG);
2614 buttons[butcount] = XtVaCreateManagedWidget("button",
2615 xmPushButtonWidgetClass, dialogform,
2616 XmNlabelString, label,
2617 XmNmnemonic, mnemonic,
2618 XmNbottomAttachment, XmATTACH_FORM,
2620 XmNshowAsDefault, butcount == dfltbutton - 1,
2621 XmNdefaultButtonShadowThickness, 1,
2623 XmStringFree(label);
2624 gui_motif_menu_fontlist(buttons[butcount]);
2626 /* Layout properly. */
2631 XtVaSetValues(buttons[butcount],
2632 XmNtopWidget, buttons[butcount - 1],
2638 XtVaSetValues(buttons[butcount],
2639 XmNrightAttachment, XmATTACH_FORM,
2643 /* fill in a form as invisible separator */
2644 sep_form = XtVaCreateWidget("separatorForm",
2645 xmFormWidgetClass, dialogform,
2646 XmNleftAttachment, XmATTACH_WIDGET,
2647 XmNleftWidget, buttons[butcount - 1],
2648 XmNrightAttachment, XmATTACH_WIDGET,
2649 XmNrightWidget, buttons[butcount],
2650 XmNbottomAttachment, XmATTACH_FORM,
2653 XtManageChild(sep_form);
2657 XtVaSetValues(buttons[butcount],
2658 XmNleftAttachment, XmATTACH_WIDGET,
2659 XmNleftWidget, buttons[butcount - 1],
2668 XtVaSetValues(buttons[0],
2669 XmNrightAttachment, XmATTACH_FORM,
2673 /* fill in a form as invisible separator */
2674 sep_form = XtVaCreateWidget("separatorForm",
2675 xmFormWidgetClass, dialogform,
2676 XmNleftAttachment, XmATTACH_FORM,
2678 XmNrightAttachment, XmATTACH_WIDGET,
2679 XmNrightWidget, buttons[0],
2680 XmNbottomAttachment, XmATTACH_FORM,
2683 XtManageChild(sep_form);
2686 XtVaSetValues(buttons[0],
2687 XmNleftAttachment, XmATTACH_FORM,
2692 XtAddCallback(buttons[butcount], XmNactivateCallback,
2693 (XtCallbackProc)butproc, (XtPointer)(long)butcount);
2698 separator = (Widget) 0;
2701 /* Create the separator for beauty. */
2703 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
2704 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
2705 XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
2706 XtSetArg(args[n], XmNbottomOffset, 4); n++;
2707 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2708 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2709 separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
2710 XtManageChild(separator);
2713 if (textfield != NULL)
2715 dialogtextfield = XtVaCreateWidget("textField",
2716 xmTextFieldWidgetClass, dialogform,
2717 XmNleftAttachment, XmATTACH_FORM,
2718 XmNrightAttachment, XmATTACH_FORM,
2721 XtVaSetValues(dialogtextfield,
2722 XmNbottomAttachment, XmATTACH_WIDGET,
2723 XmNbottomWidget, separator,
2726 XtVaSetValues(dialogtextfield,
2727 XmNbottomAttachment, XmATTACH_FORM,
2730 set_fontlist(dialogtextfield);
2731 XmTextFieldSetString(dialogtextfield, (char *)textfield);
2732 XtManageChild(dialogtextfield);
2733 XtAddEventHandler(dialogtextfield, KeyPressMask, False,
2734 (XtEventHandler)keyhit_callback, (XtPointer)NULL);
2737 /* Form holding both message and pixmap labels */
2738 form = XtVaCreateWidget("separatorForm",
2739 xmFormWidgetClass, dialogform,
2740 XmNleftAttachment, XmATTACH_FORM,
2741 XmNrightAttachment, XmATTACH_FORM,
2742 XmNtopAttachment, XmATTACH_FORM,
2744 XtManageChild(form);
2747 /* Add a pixmap, left of the message. */
2751 icon_data = generic_xpm;
2754 icon_data = error_xpm;
2757 icon_data = alert_xpm;
2760 icon_data = info_xpm;
2763 icon_data = quest_xpm;
2766 icon_data = generic_xpm;
2770 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2771 XtSetArg(args[n], XmNtopOffset, 8); n++;
2772 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2773 XtSetArg(args[n], XmNbottomOffset, 8); n++;
2774 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2775 XtSetArg(args[n], XmNleftOffset, 8); n++;
2777 dialogpixmap = create_pixmap_label(form, "dialogPixmap",
2778 icon_data, args, n);
2779 XtManageChild(dialogpixmap);
2782 /* Create the dialog message.
2783 * Since LessTif is apparently having problems with the creation of
2784 * properly localized string, we use LtoR here. The symptom is that the
2785 * string sill not show properly in multiple lines as it does in native
2788 label = XmStringCreateLtoR((char *)message, STRING_TAG);
2791 w = XtVaCreateManagedWidget("dialogMessage",
2792 xmLabelGadgetClass, form,
2793 XmNlabelString, label,
2794 XmNalignment, XmALIGNMENT_BEGINNING,
2795 XmNtopAttachment, XmATTACH_FORM,
2798 XmNleftAttachment, XmATTACH_WIDGET,
2799 XmNleftWidget, dialogpixmap,
2801 XmNleftAttachment, XmATTACH_FORM,
2804 XmNrightAttachment, XmATTACH_FORM,
2806 XmNbottomAttachment, XmATTACH_FORM,
2809 XmStringFree(label);
2812 if (textfield != NULL)
2815 XmNbottomAttachment, XmATTACH_WIDGET,
2816 XmNbottomWidget, dialogtextfield,
2823 XmNbottomAttachment, XmATTACH_WIDGET,
2824 XmNbottomWidget, separator,
2828 XmNbottomAttachment, XmATTACH_FORM,
2834 if (dfltbutton > butcount)
2835 dfltbutton = butcount;
2836 XtVaSetValues(dialogform,
2837 XmNdefaultButton, buttons[dfltbutton - 1], NULL);
2838 if (textfield != NULL)
2839 XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
2841 XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
2844 manage_centered(dialogform);
2845 activate_dialog_mnemonics(dialogform);
2847 if (textfield != NULL && *textfield != NUL)
2849 /* This only works after the textfield has been realised. */
2850 XmTextFieldSetSelection(dialogtextfield,
2851 (XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
2852 XtLastTimestampProcessed(gui.dpy));
2853 XmTextFieldSetCursorPosition(dialogtextfield,
2854 (XmTextPosition)STRLEN(textfield));
2857 app = XtWidgetToApplicationContext(dialogform);
2859 /* Loop until a button is pressed or the dialog is killed somehow. */
2863 XtAppProcessEvent(app, (XtInputMask)XtIMAll);
2864 if (dialogStatus >= 0 || !XtIsManaged(dialogform))
2870 if (textfield != NULL)
2872 p = (char_u *)XmTextGetString(dialogtextfield);
2873 if (p == NULL || dialogStatus < 0)
2876 vim_strncpy(textfield, p, IOSIZE - 1);
2880 suppress_dialog_mnemonics(dialogform);
2881 XtDestroyWidget(dialogform);
2883 return dialogStatus;
2885 #endif /* FEAT_GUI_DIALOG */
2887 #if defined(FEAT_FOOTER) || defined(PROTO)
2890 gui_mch_compute_footer_height(void)
2892 Dimension height; /* total Toolbar height */
2893 Dimension top; /* XmNmarginTop */
2894 Dimension bottom; /* XmNmarginBottom */
2895 Dimension shadow; /* XmNshadowThickness */
2897 XtVaGetValues(footer,
2900 XmNmarginBottom, &bottom,
2901 XmNshadowThickness, &shadow,
2904 return (int) height + top + bottom + (shadow << 1);
2908 gui_mch_enable_footer(int showit)
2912 gui.footer_height = gui_mch_compute_footer_height();
2913 XtManageChild(footer);
2917 gui.footer_height = 0;
2918 XtUnmanageChild(footer);
2920 XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
2924 gui_mch_set_footer(char_u *s)
2928 xms = XmStringCreate((char *)s, STRING_TAG);
2931 XtVaSetValues(footer, XmNlabelString, xms, NULL);
2939 #if defined(FEAT_TOOLBAR) || defined(PROTO)
2941 gui_mch_show_toolbar(int showit)
2943 Cardinal numChildren; /* how many children toolBar has */
2945 if (toolBar == (Widget)0)
2947 XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
2948 if (showit && numChildren > 0)
2950 /* Assume that we want to show the toolbar if p_toolbar contains
2951 * valid option settings, therefore p_toolbar must not be NULL.
2953 WidgetList children;
2955 XtVaGetValues(toolBar, XmNchildren, &children, NULL);
2957 void (*action)(BalloonEval *);
2960 if (strstr((const char *)p_toolbar, "tooltips"))
2961 action = &gui_mch_enable_beval_area;
2963 action = &gui_mch_disable_beval_area;
2964 if (strstr((const char *)p_toolbar, "text"))
2966 else if (strstr((const char *)p_toolbar, "icons"))
2973 for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
2974 if (menu_is_toolbar(toolbar->dname))
2976 /* Assumption: toolbar is NULL if there is no toolbar,
2977 * otherwise it contains the toolbar menu structure.
2979 * Assumption: "numChildren" == the number of items in the list
2980 * of items beginning with toolbar->children.
2984 for (cur = toolbar->children; cur; cur = cur->next)
2989 /* Enable/Disable tooltip (OK to enable while
2990 * currently enabled). */
2991 if (cur->tip != NULL)
2992 (*action)(cur->tip);
2993 if (!menu_is_separator(cur->name))
2995 if (text == 1 || cur->xpm == NULL)
2997 XtSetArg(args[n], XmNlabelType, XmSTRING);
3000 if (cur->id != NULL)
3002 XtUnmanageChild(cur->id);
3003 XtSetValues(cur->id, args, n);
3004 XtManageChild(cur->id);
3011 gui.toolbar_height = gui_mch_compute_toolbar_height();
3012 XtManageChild(XtParent(toolBar));
3013 #ifdef FEAT_GUI_TABLINE
3014 if (showing_tabline)
3016 XtVaSetValues(tabLine,
3017 XmNtopAttachment, XmATTACH_WIDGET,
3018 XmNtopWidget, XtParent(toolBar),
3020 XtVaSetValues(textAreaForm,
3021 XmNtopAttachment, XmATTACH_WIDGET,
3022 XmNtopWidget, tabLine,
3027 XtVaSetValues(textAreaForm,
3028 XmNtopAttachment, XmATTACH_WIDGET,
3029 XmNtopWidget, XtParent(toolBar),
3031 if (XtIsManaged(menuBar))
3032 XtVaSetValues(XtParent(toolBar),
3033 XmNtopAttachment, XmATTACH_WIDGET,
3034 XmNtopWidget, menuBar,
3037 XtVaSetValues(XtParent(toolBar),
3038 XmNtopAttachment, XmATTACH_FORM,
3043 gui.toolbar_height = 0;
3044 if (XtIsManaged(menuBar))
3046 #ifdef FEAT_GUI_TABLINE
3047 if (showing_tabline)
3049 XtVaSetValues(tabLine,
3050 XmNtopAttachment, XmATTACH_WIDGET,
3051 XmNtopWidget, menuBar,
3053 XtVaSetValues(textAreaForm,
3054 XmNtopAttachment, XmATTACH_WIDGET,
3055 XmNtopWidget, tabLine,
3060 XtVaSetValues(textAreaForm,
3061 XmNtopAttachment, XmATTACH_WIDGET,
3062 XmNtopWidget, menuBar,
3067 #ifdef FEAT_GUI_TABLINE
3068 if (showing_tabline)
3070 XtVaSetValues(tabLine,
3071 XmNtopAttachment, XmATTACH_FORM,
3073 XtVaSetValues(textAreaForm,
3074 XmNtopAttachment, XmATTACH_WIDGET,
3075 XmNtopWidget, tabLine,
3080 XtVaSetValues(textAreaForm,
3081 XmNtopAttachment, XmATTACH_FORM,
3085 XtUnmanageChild(XtParent(toolBar));
3087 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
3091 * A toolbar button has been pushed; now reset the input focus
3092 * such that the user can type page up/down etc. and have the
3093 * input go to the editor window, not the button
3098 if (textArea != NULL)
3099 XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
3103 gui_mch_compute_toolbar_height(void)
3106 Dimension height; /* total Toolbar height */
3107 Dimension whgt; /* height of each widget */
3108 WidgetList children; /* list of toolBar's children */
3109 Cardinal numChildren; /* how many children toolBar has */
3114 if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
3115 { /* get height of XmFrame parent */
3121 XtVaGetValues(toolBarFrame,
3122 XmNshadowThickness, &fst,
3123 XmNmarginHeight, &fmh,
3125 borders += fst + fmh;
3126 XtVaGetValues(toolBar,
3127 XmNshadowThickness, &tst,
3128 XmNmarginHeight, &tmh,
3129 XmNchildren, &children,
3130 XmNnumChildren, &numChildren, NULL);
3131 borders += tst + tmh;
3132 for (i = 0; i < (int)numChildren; i++)
3135 XtVaGetValues(children[i], XmNheight, &whgt, NULL);
3140 #ifdef LESSTIF_VERSION
3141 /* Hack: When starting up we get wrong dimensions. */
3146 return (int)(height + (borders << 1));
3150 motif_get_toolbar_colors(
3157 XtVaGetValues(toolBar,
3160 XmNbottomShadowColor, bsp,
3161 XmNtopShadowColor, tsp,
3162 XmNhighlightColor, hsp,
3168 * The next toolbar enter/leave callbacks should really do balloon help. But
3169 * I have to use footer help for backwards compatibility. Hopefully both will
3170 * get implemented and the user will have a choice.
3173 toolbarbutton_enter_cb(
3175 XtPointer client_data,
3176 XEvent *event UNUSED,
3177 Boolean *cont UNUSED)
3179 vimmenu_T *menu = (vimmenu_T *) client_data;
3181 if (menu->strings[MENU_INDEX_TIP] != NULL)
3183 if (vim_strchr(p_go, GO_FOOTER) != NULL)
3184 gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
3189 toolbarbutton_leave_cb(
3191 XtPointer client_data UNUSED,
3192 XEvent *event UNUSED,
3193 Boolean *cont UNUSED)
3195 gui_mch_set_footer((char_u *) "");
3200 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3202 * Show or hide the tabline.
3205 gui_mch_show_tabline(int showit)
3207 if (tabLine == (Widget)0)
3210 if (!showit != !showing_tabline)
3214 XtManageChild(tabLine);
3215 XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
3216 XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
3217 XtUnmanageChild(XtNameToWidget(tabLine,
3218 "MinorTabScrollerPrevious"));
3220 # ifdef FEAT_TOOLBAR
3221 if (XtIsManaged(XtParent(toolBar)))
3222 XtVaSetValues(tabLine,
3223 XmNtopAttachment, XmATTACH_WIDGET,
3224 XmNtopWidget, XtParent(toolBar), NULL);
3227 if (XtIsManaged(menuBar))
3228 XtVaSetValues(tabLine,
3229 XmNtopAttachment, XmATTACH_WIDGET,
3230 XmNtopWidget, menuBar, NULL);
3233 XtVaSetValues(tabLine,
3234 XmNtopAttachment, XmATTACH_FORM, NULL);
3235 XtVaSetValues(textAreaForm,
3236 XmNtopAttachment, XmATTACH_WIDGET,
3237 XmNtopWidget, tabLine,
3242 XtUnmanageChild(tabLine);
3244 # ifdef FEAT_TOOLBAR
3245 if (XtIsManaged(XtParent(toolBar)))
3246 XtVaSetValues(textAreaForm,
3247 XmNtopAttachment, XmATTACH_WIDGET,
3248 XmNtopWidget, XtParent(toolBar), NULL);
3251 if (XtIsManaged(menuBar))
3252 XtVaSetValues(textAreaForm,
3253 XmNtopAttachment, XmATTACH_WIDGET,
3254 XmNtopWidget, menuBar, NULL);
3257 XtVaSetValues(textAreaForm,
3258 XmNtopAttachment, XmATTACH_FORM, NULL);
3260 showing_tabline = showit;
3265 * Return TRUE when tabline is displayed.
3268 gui_mch_showing_tabline(void)
3270 return tabLine != (Widget)0 && showing_tabline;
3274 * Update the labels of the tabline.
3277 gui_mch_update_tabline(void)
3282 int curtabidx = 0, currentpage;
3284 XmNotebookPageInfo page_info;
3285 XmNotebookPageStatus page_status;
3286 int last_page, tab_count;
3291 if (tabLine == (Widget)0)
3294 /* Add a label for each tab page. They all contain the same text area. */
3295 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
3300 page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
3301 if (page_status == XmPAGE_INVALID
3302 || page_info.major_tab_widget == (Widget)0)
3306 XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
3307 XtSetArg(args[n], XmNtraversalOn, False); n++;
3308 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
3309 XtSetArg(args[n], XmNhighlightThickness, 1); n++;
3310 XtSetArg(args[n], XmNshadowThickness , 1); n++;
3311 tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
3313 beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
3315 XtVaSetValues(tab, XmNuserData, beval, NULL);
3318 tab = page_info.major_tab_widget;
3320 XtVaSetValues(tab, XmNpageNumber, nr, NULL);
3323 * Change the label text only if it is different
3325 XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
3326 if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
3328 get_tabline_label(tp, FALSE);
3329 if (STRCMP(label_cstr, NameBuff) != 0)
3331 XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
3332 NameBuff, STRLEN(NameBuff) + 1, NULL);
3334 * Force a resize of the tab label button
3336 XtUnmanageChild(tab);
3345 XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);
3347 /* Remove any old labels. */
3348 while (nr <= last_page)
3350 if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
3351 && page_info.page_number == nr
3352 && page_info.major_tab_widget != (Widget)0)
3354 XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
3356 gui_mch_destroy_beval_area(beval);
3357 XtUnmanageChild(page_info.major_tab_widget);
3358 XtDestroyWidget(page_info.major_tab_widget);
3363 XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);
3365 XtVaGetValues(tabLine, XmNcurrentPageNumber, ¤tpage, NULL);
3366 if (currentpage != curtabidx)
3367 XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
3371 * Set the current tab to "nr". First tab is 1.
3374 gui_mch_set_curtab(int nr)
3378 if (tabLine == (Widget)0)
3381 XtVaGetValues(tabLine, XmNcurrentPageNumber, ¤tpage, NULL);
3382 if (currentpage != nr)
3383 XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
3388 * Set the colors of Widget "id" to the menu colors.
3391 gui_motif_menu_colors(Widget id)
3393 if (gui.menu_bg_pixel != INVALCOLOR)
3394 #if (XmVersion >= 1002)
3395 XmChangeColor(id, gui.menu_bg_pixel);
3397 XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
3399 if (gui.menu_fg_pixel != INVALCOLOR)
3400 XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
3404 * Set the colors of Widget "id" to the scrollbar colors.
3407 gui_motif_scroll_colors(Widget id)
3409 if (gui.scroll_bg_pixel != INVALCOLOR)
3410 #if (XmVersion >= 1002)
3411 XmChangeColor(id, gui.scroll_bg_pixel);
3413 XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
3415 if (gui.scroll_fg_pixel != INVALCOLOR)
3416 XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
3420 * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
3423 gui_motif_menu_fontlist(Widget id UNUSED)
3426 #ifdef FONTSET_ALWAYS
3427 if (gui.menu_fontset != NOFONTSET)
3431 fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
3434 if (XtIsManaged(id))
3436 XtUnmanageChild(id);
3437 XtVaSetValues(id, XmNfontList, fl, NULL);
3438 /* We should force the widget to recalculate it's
3443 XtVaSetValues(id, XmNfontList, fl, NULL);
3448 if (gui.menu_font != NOFONT)
3452 fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
3455 if (XtIsManaged(id))
3457 XtUnmanageChild(id);
3458 XtVaSetValues(id, XmNfontList, fl, NULL);
3459 /* We should force the widget to recalculate it's
3464 XtVaSetValues(id, XmNfontList, fl, NULL);
3474 * We don't create it twice for the sake of speed.
3477 typedef struct _SharedFindReplace
3479 Widget dialog; /* the main dialog widget */
3480 Widget wword; /* 'Exact match' check button */
3481 Widget mcase; /* 'match case' check button */
3482 Widget up; /* search direction 'Up' radio button */
3483 Widget down; /* search direction 'Down' radio button */
3484 Widget what; /* 'Find what' entry text widget */
3485 Widget with; /* 'Replace with' entry text widget */
3486 Widget find; /* 'Find Next' action button */
3487 Widget replace; /* 'Replace With' action button */
3488 Widget all; /* 'Replace All' action button */
3489 Widget undo; /* 'Undo' action button */
3492 } SharedFindReplace;
3494 static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3495 static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3497 static void find_replace_destroy_callback(Widget w, XtPointer client_data, XtPointer call_data);
3498 static void find_replace_dismiss_callback(Widget w, XtPointer client_data, XtPointer call_data);
3499 static void entry_activate_callback(Widget w, XtPointer client_data, XtPointer call_data);
3500 static void find_replace_callback(Widget w, XtPointer client_data, XtPointer call_data);
3501 static void find_replace_keypress(Widget w, SharedFindReplace * frdp, XKeyEvent * event);
3502 static void find_replace_dialog_create(char_u *entry_text, int do_replace);
3505 find_replace_destroy_callback(
3507 XtPointer client_data,
3508 XtPointer call_data UNUSED)
3510 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3513 /* suppress_dialog_mnemonics(cd->dialog); */
3514 cd->dialog = (Widget)0;
3518 find_replace_dismiss_callback(
3520 XtPointer client_data,
3521 XtPointer call_data UNUSED)
3523 SharedFindReplace *cd = (SharedFindReplace *)client_data;
3526 XtUnmanageChild(cd->dialog);
3530 entry_activate_callback(
3532 XtPointer client_data,
3533 XtPointer call_data UNUSED)
3535 XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
3539 find_replace_callback(
3541 XtPointer client_data,
3542 XtPointer call_data UNUSED)
3544 long_u flags = (long_u)client_data;
3545 char *find_text, *repl_text;
3546 Boolean direction_down = TRUE;
3549 SharedFindReplace *sfr;
3551 if (flags == FRD_UNDO)
3553 char_u *save_cpo = p_cpo;
3555 /* No need to be Vi compatible here. */
3556 p_cpo = (char_u *)"";
3559 gui_update_screen();
3563 /* Get the search/replace strings from the dialog */
3564 if (flags == FRD_FINDNEXT)
3567 sfr = &find_widgets;
3571 repl_text = XmTextFieldGetString(repl_widgets.with);
3572 sfr = &repl_widgets;
3574 find_text = XmTextFieldGetString(sfr->what);
3575 XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
3576 XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
3577 XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
3579 flags |= FRD_WHOLE_WORD;
3581 flags |= FRD_MATCH_CASE;
3583 (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
3586 if (find_text != NULL)
3588 if (repl_text != NULL)
3593 find_replace_keypress(
3595 SharedFindReplace *frdp,
3603 keysym = XLookupKeysym(event, 0);
3605 /* the scape key pops the whole dialog down */
3606 if (keysym == XK_Escape)
3607 XtUnmanageChild(frdp->dialog);
3611 set_label(Widget w, char *label)
3615 KeySym mnemonic = NUL;
3620 p = vim_strsave((char_u *)label);
3623 for (next = p; *next; ++next)
3625 if (*next == DLG_HOTKEY_CHAR)
3627 int len = STRLEN(next);
3631 mch_memmove(next, next + 1, len);
3637 str = XmStringCreateSimple((char *)p);
3642 XmNlabelString, str,
3643 XmNmnemonic, mnemonic,
3647 gui_motif_menu_fontlist(w);
3651 find_replace_dialog_create(char_u *arg, int do_replace)
3653 SharedFindReplace *frdp;
3668 frdp = do_replace ? &repl_widgets : &find_widgets;
3670 /* Get the search string to use. */
3671 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3673 /* If the dialog already exists, just raise it. */
3676 gui_motif_synch_fonts();
3678 /* If the window is already up, just pop it to the top */
3679 if (XtIsManaged(frdp->dialog))
3680 XMapRaised(XtDisplay(frdp->dialog),
3681 XtWindow(XtParent(frdp->dialog)));
3683 XtManageChild(frdp->dialog);
3684 XtPopup(XtParent(frdp->dialog), XtGrabNone);
3685 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
3687 if (entry_text != NULL)
3688 XmTextFieldSetString(frdp->what, (char *)entry_text);
3689 vim_free(entry_text);
3691 XtVaSetValues(frdp->wword, XmNset, wword, NULL);
3695 /* Create a fresh new dialog window */
3697 str = XmStringCreateSimple(_("VIM - Search and Replace..."));
3699 str = XmStringCreateSimple(_("VIM - Search..."));
3702 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3703 XtSetArg(args[n], XmNnoResize, True); n++;
3704 XtSetArg(args[n], XmNdialogTitle, str); n++;
3706 frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
3708 XtAddCallback(frdp->dialog, XmNdestroyCallback,
3709 find_replace_destroy_callback, frdp);
3711 button_form = XtVaCreateWidget("buttonForm",
3712 xmFormWidgetClass, frdp->dialog,
3713 XmNrightAttachment, XmATTACH_FORM,
3715 XmNtopAttachment, XmATTACH_FORM,
3717 XmNbottomAttachment, XmATTACH_FORM,
3721 frdp->find = XtVaCreateManagedWidget("findButton",
3722 xmPushButtonWidgetClass, button_form,
3724 XmNtopAttachment, XmATTACH_FORM,
3725 XmNleftAttachment, XmATTACH_FORM,
3726 XmNrightAttachment, XmATTACH_FORM,
3728 set_label(frdp->find, _("Find &Next"));
3730 XtAddCallback(frdp->find, XmNactivateCallback,
3731 find_replace_callback,
3732 (do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));
3736 frdp->replace = XtVaCreateManagedWidget("replaceButton",
3737 xmPushButtonWidgetClass, button_form,
3738 XmNtopAttachment, XmATTACH_WIDGET,
3739 XmNtopWidget, frdp->find,
3740 XmNleftAttachment, XmATTACH_FORM,
3741 XmNrightAttachment, XmATTACH_FORM,
3743 set_label(frdp->replace, _("&Replace"));
3744 XtAddCallback(frdp->replace, XmNactivateCallback,
3745 find_replace_callback, (XtPointer)FRD_REPLACE);
3747 frdp->all = XtVaCreateManagedWidget("replaceAllButton",
3748 xmPushButtonWidgetClass, button_form,
3749 XmNtopAttachment, XmATTACH_WIDGET,
3750 XmNtopWidget, frdp->replace,
3751 XmNleftAttachment, XmATTACH_FORM,
3752 XmNrightAttachment, XmATTACH_FORM,
3754 set_label(frdp->all, _("Replace &All"));
3755 XtAddCallback(frdp->all, XmNactivateCallback,
3756 find_replace_callback, (XtPointer)FRD_REPLACEALL);
3758 frdp->undo = XtVaCreateManagedWidget("undoButton",
3759 xmPushButtonWidgetClass, button_form,
3760 XmNtopAttachment, XmATTACH_WIDGET,
3761 XmNtopWidget, frdp->all,
3762 XmNleftAttachment, XmATTACH_FORM,
3763 XmNrightAttachment, XmATTACH_FORM,
3765 set_label(frdp->undo, _("&Undo"));
3766 XtAddCallback(frdp->undo, XmNactivateCallback,
3767 find_replace_callback, (XtPointer)FRD_UNDO);
3770 frdp->cancel = XtVaCreateManagedWidget("closeButton",
3771 xmPushButtonWidgetClass, button_form,
3772 XmNleftAttachment, XmATTACH_FORM,
3773 XmNrightAttachment, XmATTACH_FORM,
3774 XmNbottomAttachment, XmATTACH_FORM,
3776 set_label(frdp->cancel, _("&Cancel"));
3777 XtAddCallback(frdp->cancel, XmNactivateCallback,
3778 find_replace_dismiss_callback, frdp);
3779 gui_motif_menu_fontlist(frdp->cancel);
3781 XtManageChild(button_form);
3784 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
3785 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
3786 XtSetArg(args[n], XmNrightWidget, button_form); n++;
3787 XtSetArg(args[n], XmNrightOffset, 4); n++;
3788 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
3789 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
3790 separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
3791 XtManageChild(separator);
3793 input_form = XtVaCreateWidget("inputForm",
3794 xmFormWidgetClass, frdp->dialog,
3795 XmNleftAttachment, XmATTACH_FORM,
3797 XmNrightAttachment, XmATTACH_WIDGET,
3798 XmNrightWidget, separator,
3800 XmNtopAttachment, XmATTACH_FORM,
3806 Widget label_with = (Widget)0;
3808 str = XmStringCreateSimple(_("Find what:"));
3809 label_what = XtVaCreateManagedWidget("whatLabel",
3810 xmLabelGadgetClass, input_form,
3811 XmNlabelString, str,
3812 XmNleftAttachment, XmATTACH_FORM,
3813 XmNtopAttachment, XmATTACH_FORM,
3817 gui_motif_menu_fontlist(label_what);
3819 frdp->what = XtVaCreateManagedWidget("whatText",
3820 xmTextFieldWidgetClass, input_form,
3821 XmNtopAttachment, XmATTACH_FORM,
3822 XmNrightAttachment, XmATTACH_FORM,
3823 XmNleftAttachment, XmATTACH_FORM,
3828 frdp->with = XtVaCreateManagedWidget("withText",
3829 xmTextFieldWidgetClass, input_form,
3830 XmNtopAttachment, XmATTACH_WIDGET,
3831 XmNtopWidget, frdp->what,
3833 XmNleftAttachment, XmATTACH_FORM,
3834 XmNrightAttachment, XmATTACH_FORM,
3835 XmNbottomAttachment, XmATTACH_FORM,
3838 XtAddCallback(frdp->with, XmNactivateCallback,
3839 find_replace_callback, (XtPointer) FRD_R_FINDNEXT);
3841 str = XmStringCreateSimple(_("Replace with:"));
3842 label_with = XtVaCreateManagedWidget("withLabel",
3843 xmLabelGadgetClass, input_form,
3844 XmNlabelString, str,
3845 XmNleftAttachment, XmATTACH_FORM,
3846 XmNtopAttachment, XmATTACH_WIDGET,
3847 XmNtopWidget, frdp->what,
3849 XmNbottomAttachment, XmATTACH_FORM,
3852 gui_motif_menu_fontlist(label_with);
3855 * Make the entry activation only change the input focus onto the
3858 XtAddCallback(frdp->what, XmNactivateCallback,
3859 entry_activate_callback, frdp->with);
3860 XtAddEventHandler(frdp->with, KeyPressMask, False,
3861 (XtEventHandler)find_replace_keypress,
3868 * Make the entry activation do the search.
3870 XtAddCallback(frdp->what, XmNactivateCallback,
3871 find_replace_callback, (XtPointer)FRD_FINDNEXT);
3873 XtAddEventHandler(frdp->what, KeyPressMask, False,
3874 (XtEventHandler)find_replace_keypress,
3877 /* Get the maximum width between the label widgets and line them up.
3880 XtSetArg(args[n], XmNwidth, &width); n++;
3881 XtGetValues(label_what, args, n);
3885 XtGetValues(label_with, args, n);
3890 XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
3892 XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);
3896 XtManageChild(input_form);
3902 frame = XtVaCreateWidget("directionFrame",
3903 xmFrameWidgetClass, frdp->dialog,
3904 XmNtopAttachment, XmATTACH_WIDGET,
3905 XmNtopWidget, input_form,
3907 XmNbottomAttachment, XmATTACH_FORM,
3909 XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
3910 XmNrightWidget, input_form,
3913 str = XmStringCreateSimple(_("Direction"));
3914 w = XtVaCreateManagedWidget("directionFrameLabel",
3915 xmLabelGadgetClass, frame,
3916 XmNlabelString, str,
3917 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
3918 XmNchildType, XmFRAME_TITLE_CHILD,
3921 gui_motif_menu_fontlist(w);
3923 radio_box = XmCreateRadioBox(frame, "radioBox",
3926 str = XmStringCreateSimple( _("Up"));
3927 frdp->up = XtVaCreateManagedWidget("upRadioButton",
3928 xmToggleButtonGadgetClass, radio_box,
3929 XmNlabelString, str,
3933 gui_motif_menu_fontlist(frdp->up);
3935 str = XmStringCreateSimple(_("Down"));
3936 frdp->down = XtVaCreateManagedWidget("downRadioButton",
3937 xmToggleButtonGadgetClass, radio_box,
3938 XmNlabelString, str,
3942 gui_motif_menu_fontlist(frdp->down);
3944 XtManageChild(radio_box);
3945 XtManageChild(frame);
3948 toggle_form = XtVaCreateWidget("toggleForm",
3949 xmFormWidgetClass, frdp->dialog,
3950 XmNleftAttachment, XmATTACH_FORM,
3952 XmNrightAttachment, XmATTACH_WIDGET,
3953 XmNrightWidget, frame,
3955 XmNtopAttachment, XmATTACH_WIDGET,
3956 XmNtopWidget, input_form,
3958 XmNbottomAttachment, XmATTACH_FORM,
3962 str = XmStringCreateSimple(_("Match whole word only"));
3963 frdp->wword = XtVaCreateManagedWidget("wordToggle",
3964 xmToggleButtonGadgetClass, toggle_form,
3965 XmNlabelString, str,
3966 XmNtopAttachment, XmATTACH_FORM,
3968 XmNleftAttachment, XmATTACH_FORM,
3974 str = XmStringCreateSimple(_("Match case"));
3975 frdp->mcase = XtVaCreateManagedWidget("caseToggle",
3976 xmToggleButtonGadgetClass, toggle_form,
3977 XmNlabelString, str,
3978 XmNleftAttachment, XmATTACH_FORM,
3980 XmNtopAttachment, XmATTACH_WIDGET,
3981 XmNtopWidget, frdp->wword,
3986 gui_motif_menu_fontlist(frdp->wword);
3987 gui_motif_menu_fontlist(frdp->mcase);
3989 XtManageChild(toggle_form);
3991 if (entry_text != NULL)
3992 XmTextFieldSetString(frdp->what, (char *)entry_text);
3993 vim_free(entry_text);
3995 gui_motif_synch_fonts();
3997 manage_centered(frdp->dialog);
3998 activate_dialog_mnemonics(frdp->dialog);
3999 XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
4003 gui_mch_find_dialog(exarg_T *eap)
4008 find_replace_dialog_create(eap->arg, FALSE);
4013 gui_mch_replace_dialog(exarg_T *eap)
4018 find_replace_dialog_create(eap->arg, TRUE);
4022 * Synchronize all gui elements, which are dependant upon the
4023 * main text font used. Those are in esp. the find/replace dialogs.
4024 * If you don't understand why this should be needed, please try to
4025 * search for "pi\xea\xb6\xe6" in iso8859-2.
4028 gui_motif_synch_fonts(void)
4030 SharedFindReplace *frdp;
4033 XmFontList font_list;
4035 /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
4036 * we just give up here on font synchronization. */
4037 font = (XFontStruct *)gui.norm_font;
4041 font_list = gui_motif_create_fontlist(font);
4043 /* OK this loop is a bit tricky... */
4044 for (do_replace = 0; do_replace <= 1; ++do_replace)
4046 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
4049 XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
4051 XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
4055 XmFontListFree(font_list);