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