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