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