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