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 | |
| 881 | /* |
| 882 | * Icons used by the toolbar code. |
| 883 | */ |
| 884 | #include "gui_x11_pm.h" |
| 885 | |
| 886 | static int check_xpm __ARGS((char_u *path)); |
| 887 | static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu)); |
| 888 | |
| 889 | /* |
| 890 | * Read an Xpm file. Return OK or FAIL. |
| 891 | */ |
| 892 | static int |
| 893 | check_xpm(path) |
| 894 | char_u *path; |
| 895 | { |
| 896 | XpmAttributes attrs; |
| 897 | int status; |
| 898 | Pixmap mask; |
| 899 | Pixmap map; |
| 900 | |
| 901 | attrs.valuemask = 0; |
| 902 | |
| 903 | /* Create the "sensitive" pixmap */ |
| 904 | status = XpmReadFileToPixmap(gui.dpy, |
| 905 | RootWindow(gui.dpy, DefaultScreen(gui.dpy)), |
| 906 | (char *)path, &map, &mask, &attrs); |
| 907 | XpmFreeAttributes(&attrs); |
| 908 | |
| 909 | if (status == XpmSuccess) |
| 910 | return OK; |
| 911 | return FAIL; |
| 912 | } |
| 913 | |
| 914 | |
| 915 | /* |
| 916 | * Allocated a pixmap for toolbar menu "menu". |
| 917 | * Return a blank pixmap if it fails. |
| 918 | */ |
| 919 | static char ** |
| 920 | get_toolbar_pixmap(menu) |
| 921 | vimmenu_T *menu; |
| 922 | { |
| 923 | char_u buf[MAXPATHL]; /* buffer storing expanded pathname */ |
| 924 | char **xpm = NULL; /* xpm array */ |
| 925 | int res; |
| 926 | |
| 927 | buf[0] = NUL; /* start with NULL path */ |
| 928 | |
| 929 | if (menu->iconfile != NULL) |
| 930 | { |
| 931 | /* Use the "icon=" argument. */ |
| 932 | gui_find_iconfile(menu->iconfile, buf, "xpm"); |
| 933 | res = check_xpm(buf); |
| 934 | |
| 935 | /* If it failed, try using the menu name. */ |
| 936 | if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK) |
| 937 | res = check_xpm(buf); |
| 938 | if (res == OK) |
| 939 | return tb_blank_xpm; |
| 940 | } |
| 941 | |
| 942 | if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL) |
| 943 | { |
| 944 | if (menu->iconidx >= 0 && menu->iconidx |
| 945 | < (sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0]))) |
| 946 | xpm = built_in_pixmaps[menu->iconidx]; |
| 947 | else |
| 948 | xpm = tb_blank_xpm; |
| 949 | } |
| 950 | |
| 951 | return xpm; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void |
| 955 | gui_mch_add_menu_item(menu, idx) |
| 956 | vimmenu_T *menu; |
| 957 | int idx; |
| 958 | { |
| 959 | XmString label; |
| 960 | vimmenu_T *parent = menu->parent; |
| 961 | |
| 962 | # ifdef EBCDIC |
| 963 | menu->mnemonic = 0; |
| 964 | # endif |
| 965 | |
| 966 | # if (XmVersion <= 1002) |
| 967 | /* Don't add Popup menu items when the popup menu isn't used. */ |
| 968 | if (menu_is_child_of_popup(menu) && !mouse_model_popup()) |
| 969 | return; |
| 970 | # endif |
| 971 | |
| 972 | # ifdef FEAT_TOOLBAR |
| 973 | if (menu_is_toolbar(parent->name)) |
| 974 | { |
| 975 | WidgetClass type; |
| 976 | XmString xms = NULL; /* fallback label if pixmap not found */ |
| 977 | int n; |
| 978 | Arg args[18]; |
| 979 | |
| 980 | n = 0; |
| 981 | if (menu_is_separator(menu->name)) |
| 982 | { |
| 983 | char *cp; |
| 984 | Dimension wid; |
| 985 | |
| 986 | /* |
| 987 | * A separator has the format "-sep%d[:%d]-". The optional :%d is |
| 988 | * a width specifier. If no width is specified then we choose one. |
| 989 | */ |
| 990 | cp = (char *)vim_strchr(menu->name, ':'); |
| 991 | if (cp != NULL) |
| 992 | wid = (Dimension)atoi(++cp); |
| 993 | else |
| 994 | wid = 4; |
| 995 | |
| 996 | #if 0 |
| 997 | /* We better use a FormWidget here, since it's far more |
| 998 | * flexible in terms of size. */ |
| 999 | type = xmFormWidgetClass; |
| 1000 | XtSetArg(args[n], XmNwidth, wid); n++; |
| 1001 | #else |
| 1002 | type = xmSeparatorWidgetClass; |
| 1003 | XtSetArg(args[n], XmNwidth, wid); n++; |
| 1004 | XtSetArg(args[n], XmNminWidth, wid); n++; |
| 1005 | XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1006 | XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1007 | #endif |
| 1008 | } |
| 1009 | else |
| 1010 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1011 | /* Without shadows one can't sense whatever the button has been |
| 1012 | * 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] | 1013 | * Need the highlightThickness to see the focus. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1014 | */ |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1015 | XtSetArg(args[n], XmNhighlightThickness, 1); n++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1016 | XtSetArg(args[n], XmNhighlightOnEnter, True); n++; |
| 1017 | XtSetArg(args[n], XmNmarginWidth, 0); n++; |
| 1018 | XtSetArg(args[n], XmNmarginHeight, 0); n++; |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1019 | XtSetArg(args[n], XmNtraversalOn, False); n++; |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1020 | /* Set the label here, so that we can switch between icons/text |
| 1021 | * by changing the XmNlabelType resource. */ |
| 1022 | xms = XmStringCreate((char *)menu->dname, STRING_TAG); |
| 1023 | XtSetArg(args[n], XmNlabelString, xms); n++; |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1024 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1025 | menu->xpm = get_toolbar_pixmap(menu); |
| 1026 | if (menu->xpm == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1027 | { |
| 1028 | XtSetArg(args[n], XmNlabelType, XmSTRING); n++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1029 | } |
| 1030 | else |
| 1031 | { |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1032 | XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; |
| 1033 | XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1034 | } |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1035 | type = xmEnhancedButtonWidgetClass; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | XtSetArg(args[n], XmNpositionIndex, idx); n++; |
| 1039 | if (menu->id == NULL) |
| 1040 | { |
| 1041 | menu->id = XtCreateManagedWidget((char *)menu->dname, |
| 1042 | type, toolBar, args, n); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1043 | if (menu->id != NULL && type == xmEnhancedButtonWidgetClass) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1044 | { |
| 1045 | XtAddCallback(menu->id, |
| 1046 | XmNactivateCallback, gui_x11_menu_cb, menu); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1047 | # ifdef FEAT_FOOTER |
| 1048 | XtAddEventHandler(menu->id, EnterWindowMask, False, |
| 1049 | toolbarbutton_enter_cb, menu); |
| 1050 | XtAddEventHandler(menu->id, LeaveWindowMask, False, |
| 1051 | toolbarbutton_leave_cb, menu); |
| 1052 | # endif |
| 1053 | } |
| 1054 | } |
| 1055 | else |
| 1056 | XtSetValues(menu->id, args, n); |
| 1057 | if (xms != NULL) |
| 1058 | XmStringFree(xms); |
| 1059 | |
| 1060 | #ifdef FEAT_BEVAL |
| 1061 | gui_mch_menu_set_tip(menu); |
| 1062 | #endif |
| 1063 | |
| 1064 | menu->parent = parent; |
| 1065 | menu->submenu_id = NULL; |
| 1066 | /* When adding first item to toolbar it might have to be enabled .*/ |
| 1067 | if (!XtIsManaged(XtParent(toolBar)) |
| 1068 | && vim_strchr(p_go, GO_TOOLBAR) != NULL) |
| 1069 | gui_mch_show_toolbar(TRUE); |
| 1070 | gui.toolbar_height = gui_mch_compute_toolbar_height(); |
| 1071 | return; |
| 1072 | } /* toolbar menu item */ |
| 1073 | # endif |
| 1074 | |
| 1075 | /* No parent, must be a non-menubar menu */ |
| 1076 | if (parent->submenu_id == (Widget)0) |
| 1077 | return; |
| 1078 | |
| 1079 | menu->submenu_id = (Widget)0; |
| 1080 | |
| 1081 | /* Add menu separator */ |
| 1082 | if (menu_is_separator(menu->name)) |
| 1083 | { |
| 1084 | menu->id = XtVaCreateWidget("subMenu", |
| 1085 | xmSeparatorGadgetClass, parent->submenu_id, |
| 1086 | #if (XmVersion >= 1002) |
| 1087 | /* count the tearoff item (needed for LessTif) */ |
| 1088 | XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED |
| 1089 | ? 1 : 0), |
| 1090 | #endif |
| 1091 | NULL); |
| 1092 | gui_motif_menu_colors(menu->id); |
| 1093 | return; |
| 1094 | } |
| 1095 | |
| 1096 | label = XmStringCreate((char *)menu->dname, STRING_TAG); |
| 1097 | if (label == NULL) |
| 1098 | return; |
| 1099 | menu->id = XtVaCreateWidget("subMenu", |
| 1100 | xmPushButtonWidgetClass, parent->submenu_id, |
| 1101 | XmNlabelString, label, |
| 1102 | XmNmnemonic, menu->mnemonic, |
| 1103 | #if (XmVersion >= 1002) |
| 1104 | /* count the tearoff item (needed for LessTif) */ |
| 1105 | XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED |
| 1106 | ? 1 : 0), |
| 1107 | #endif |
| 1108 | NULL); |
| 1109 | gui_motif_menu_colors(menu->id); |
| 1110 | gui_motif_menu_fontlist(menu->id); |
| 1111 | XmStringFree(label); |
| 1112 | |
| 1113 | if (menu->id != (Widget)0) |
| 1114 | { |
| 1115 | XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb, |
| 1116 | (XtPointer)menu); |
| 1117 | /* add accelerator text */ |
| 1118 | gui_motif_add_actext(menu); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | #if (XmVersion <= 1002) || defined(PROTO) |
| 1123 | /* |
| 1124 | * This function will destroy/create the popup menus dynamically, |
| 1125 | * according to the value of 'mousemodel'. |
| 1126 | * This will fix the "right mouse button freeze" that occurs when |
| 1127 | * there exists a popup menu but it isn't managed. |
| 1128 | */ |
| 1129 | void |
| 1130 | gui_motif_update_mousemodel(menu) |
| 1131 | vimmenu_T *menu; |
| 1132 | { |
| 1133 | int idx = 0; |
| 1134 | |
| 1135 | /* When GUI hasn't started the menus have not been created. */ |
| 1136 | if (!gui.in_use) |
| 1137 | return; |
| 1138 | |
| 1139 | while (menu) |
| 1140 | { |
| 1141 | if (menu->children != NULL) |
| 1142 | { |
| 1143 | if (menu_is_popup(menu->name)) |
| 1144 | { |
| 1145 | if (mouse_model_popup()) |
| 1146 | { |
| 1147 | /* Popup menu will be used. Create the popup menus. */ |
| 1148 | gui_mch_add_menu(menu, idx); |
| 1149 | gui_motif_update_mousemodel(menu->children); |
| 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | /* Popup menu will not be used. Destroy the popup menus. */ |
| 1154 | gui_motif_update_mousemodel(menu->children); |
| 1155 | gui_mch_destroy_menu(menu); |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | else if (menu_is_child_of_popup(menu)) |
| 1160 | { |
| 1161 | if (mouse_model_popup()) |
| 1162 | gui_mch_add_menu_item(menu, idx); |
| 1163 | else |
| 1164 | gui_mch_destroy_menu(menu); |
| 1165 | } |
| 1166 | menu = menu->next; |
| 1167 | ++idx; |
| 1168 | } |
| 1169 | } |
| 1170 | #endif |
| 1171 | |
| 1172 | void |
| 1173 | gui_mch_new_menu_colors() |
| 1174 | { |
| 1175 | if (menuBar == (Widget)0) |
| 1176 | return; |
| 1177 | gui_motif_menu_colors(menuBar); |
| 1178 | #ifdef FEAT_TOOLBAR |
| 1179 | gui_motif_menu_colors(toolBarFrame); |
| 1180 | gui_motif_menu_colors(toolBar); |
| 1181 | #endif |
| 1182 | |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1183 | submenu_change(root_menu, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void |
| 1187 | gui_mch_new_menu_font() |
| 1188 | { |
| 1189 | if (menuBar == (Widget)0) |
| 1190 | return; |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1191 | submenu_change(root_menu, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1192 | { |
| 1193 | Dimension height; |
| 1194 | Position w, h; |
| 1195 | |
| 1196 | XtVaGetValues(menuBar, XmNheight, &height, NULL); |
| 1197 | gui.menu_height = height; |
| 1198 | |
| 1199 | XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL); |
| 1200 | gui_resize_shell(w, h |
| 1201 | #ifdef FEAT_XIM |
| 1202 | - xim_get_status_area_height() |
| 1203 | #endif |
| 1204 | ); |
| 1205 | } |
| 1206 | gui_set_shellsize(FALSE, TRUE); |
| 1207 | ui_new_shellsize(); |
| 1208 | } |
| 1209 | |
| 1210 | #if defined(FEAT_BEVAL) || defined(PROTO) |
| 1211 | void |
| 1212 | gui_mch_new_tooltip_font() |
| 1213 | { |
| 1214 | # ifdef FEAT_TOOLBAR |
| 1215 | vimmenu_T *menu; |
| 1216 | |
| 1217 | if (toolBar == (Widget)0) |
| 1218 | return; |
| 1219 | |
| 1220 | menu = gui_find_menu((char_u *)"ToolBar"); |
| 1221 | if (menu != NULL) |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1222 | submenu_change(menu, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1223 | # endif |
| 1224 | } |
| 1225 | |
| 1226 | void |
| 1227 | gui_mch_new_tooltip_colors() |
| 1228 | { |
| 1229 | # ifdef FEAT_TOOLBAR |
| 1230 | vimmenu_T *toolbar; |
| 1231 | |
| 1232 | if (toolBar == (Widget)0) |
| 1233 | return; |
| 1234 | |
| 1235 | toolbar = gui_find_menu((char_u *)"ToolBar"); |
| 1236 | if (toolbar != NULL) |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1237 | submenu_change(toolbar, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1238 | # endif |
| 1239 | } |
| 1240 | #endif |
| 1241 | |
| 1242 | static void |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1243 | submenu_change(menu, colors) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1244 | vimmenu_T *menu; |
| 1245 | int colors; /* TRUE for colors, FALSE for font */ |
| 1246 | { |
| 1247 | vimmenu_T *mp; |
| 1248 | |
| 1249 | for (mp = menu; mp != NULL; mp = mp->next) |
| 1250 | { |
| 1251 | if (mp->id != (Widget)0) |
| 1252 | { |
| 1253 | if (colors) |
| 1254 | { |
| 1255 | gui_motif_menu_colors(mp->id); |
| 1256 | #ifdef FEAT_TOOLBAR |
| 1257 | /* For a toolbar item: Free the pixmap and allocate a new one, |
| 1258 | * so that the background color is right. */ |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1259 | if (mp->xpm != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1260 | { |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1261 | int n = 0; |
| 1262 | Arg args[18]; |
| 1263 | |
| 1264 | mp->xpm = get_toolbar_pixmap(mp); |
| 1265 | if (menu->xpm == NULL) |
| 1266 | { |
| 1267 | XtSetArg(args[n], XmNlabelType, XmSTRING); n++; |
| 1268 | } |
| 1269 | else |
| 1270 | { |
| 1271 | XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; |
| 1272 | XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; |
| 1273 | } |
| 1274 | XtSetValues(mp->id, args, n); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | } |
| 1276 | # ifdef FEAT_BEVAL |
| 1277 | /* If we have a tooltip, then we need to change it's font */ |
| 1278 | if (mp->tip != NULL) |
| 1279 | { |
| 1280 | Arg args[2]; |
| 1281 | |
| 1282 | args[0].name = XmNbackground; |
| 1283 | args[0].value = gui.tooltip_bg_pixel; |
| 1284 | args[1].name = XmNforeground; |
| 1285 | args[1].value = gui.tooltip_fg_pixel; |
| 1286 | XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args)); |
| 1287 | } |
| 1288 | # endif |
| 1289 | #endif |
| 1290 | } |
| 1291 | else |
| 1292 | { |
| 1293 | gui_motif_menu_fontlist(mp->id); |
| 1294 | #ifdef FEAT_BEVAL |
| 1295 | /* If we have a tooltip, then we need to change it's font */ |
| 1296 | if (mp->tip != NULL) |
| 1297 | { |
| 1298 | Arg args[1]; |
| 1299 | |
| 1300 | args[0].name = XmNfontList; |
| 1301 | args[0].value = (XtArgVal)gui_motif_fontset2fontlist( |
| 1302 | &gui.tooltip_fontset); |
| 1303 | XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args)); |
| 1304 | } |
| 1305 | #endif |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | if (mp->children != NULL) |
| 1310 | { |
| 1311 | #if (XmVersion >= 1002) |
| 1312 | /* Set the colors/font for the tear off widget */ |
| 1313 | if (mp->submenu_id != (Widget)0) |
| 1314 | { |
| 1315 | if (colors) |
| 1316 | gui_motif_menu_colors(mp->submenu_id); |
| 1317 | else |
| 1318 | gui_motif_menu_fontlist(mp->submenu_id); |
| 1319 | toggle_tearoff(mp->submenu_id); |
| 1320 | } |
| 1321 | #endif |
| 1322 | /* Set the colors for the children */ |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 1323 | submenu_change(mp->children, colors); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * Destroy the machine specific menu widget. |
| 1330 | */ |
| 1331 | void |
| 1332 | gui_mch_destroy_menu(menu) |
| 1333 | vimmenu_T *menu; |
| 1334 | { |
| 1335 | /* Please be sure to destroy the parent widget first (i.e. menu->id). |
| 1336 | * On the other hand, problems have been reported that the submenu must be |
| 1337 | * deleted first... |
| 1338 | * |
| 1339 | * This code should be basically identical to that in the file gui_athena.c |
| 1340 | * because they are both Xt based. |
| 1341 | */ |
| 1342 | if (menu->submenu_id != (Widget)0) |
| 1343 | { |
| 1344 | XtDestroyWidget(menu->submenu_id); |
| 1345 | menu->submenu_id = (Widget)0; |
| 1346 | } |
| 1347 | |
| 1348 | if (menu->id != (Widget)0) |
| 1349 | { |
| 1350 | Widget parent; |
| 1351 | |
| 1352 | parent = XtParent(menu->id); |
| 1353 | #if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL) |
| 1354 | if ((parent == toolBar) && (menu->tip != NULL)) |
| 1355 | { |
| 1356 | /* We try to destroy this before the actual menu, because there are |
| 1357 | * callbacks, etc. that will be unregistered during the tooltip |
| 1358 | * destruction. |
| 1359 | * |
| 1360 | * If you call "gui_mch_destroy_beval_area()" after destroying |
| 1361 | * menu->id, then the tooltip's window will have already been |
| 1362 | * deallocated by Xt, and unknown behaviour will ensue (probably |
| 1363 | * a core dump). |
| 1364 | */ |
| 1365 | gui_mch_destroy_beval_area(menu->tip); |
| 1366 | menu->tip = NULL; |
| 1367 | } |
| 1368 | #endif |
| 1369 | XtDestroyWidget(menu->id); |
| 1370 | menu->id = (Widget)0; |
| 1371 | if (parent == menuBar) |
| 1372 | gui_mch_compute_menu_height((Widget)0); |
| 1373 | #ifdef FEAT_TOOLBAR |
| 1374 | else if (parent == toolBar) |
| 1375 | { |
| 1376 | Cardinal num_children; |
| 1377 | |
| 1378 | /* When removing last toolbar item, don't display the toolbar. */ |
| 1379 | XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL); |
| 1380 | if (num_children == 0) |
| 1381 | gui_mch_show_toolbar(FALSE); |
| 1382 | else |
| 1383 | gui.toolbar_height = gui_mch_compute_toolbar_height(); |
| 1384 | } |
| 1385 | #endif |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /* ARGSUSED */ |
| 1390 | void |
| 1391 | gui_mch_show_popupmenu(menu) |
| 1392 | vimmenu_T *menu; |
| 1393 | { |
| 1394 | #ifdef MOTIF_POPUP |
| 1395 | XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event()); |
| 1396 | XtManageChild(menu->submenu_id); |
| 1397 | #endif |
| 1398 | } |
| 1399 | |
| 1400 | #endif /* FEAT_MENU */ |
| 1401 | |
| 1402 | /* |
| 1403 | * Set the menu and scrollbar colors to their default values. |
| 1404 | */ |
| 1405 | void |
| 1406 | gui_mch_def_colors() |
| 1407 | { |
| 1408 | if (gui.in_use) |
| 1409 | { |
| 1410 | /* Use the values saved when starting up. These should come from the |
| 1411 | * window manager or a resources file. */ |
| 1412 | gui.menu_fg_pixel = gui.menu_def_fg_pixel; |
| 1413 | gui.menu_bg_pixel = gui.menu_def_bg_pixel; |
| 1414 | gui.scroll_fg_pixel = gui.scroll_def_fg_pixel; |
| 1415 | gui.scroll_bg_pixel = gui.scroll_def_bg_pixel; |
| 1416 | #ifdef FEAT_BEVAL |
| 1417 | gui.tooltip_fg_pixel = |
| 1418 | gui_get_color((char_u *)gui.rsrc_tooltip_fg_name); |
| 1419 | gui.tooltip_bg_pixel = |
| 1420 | gui_get_color((char_u *)gui.rsrc_tooltip_bg_name); |
| 1421 | #endif |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | |
| 1426 | /* |
| 1427 | * Scrollbar stuff. |
| 1428 | */ |
| 1429 | |
| 1430 | void |
| 1431 | gui_mch_set_scrollbar_thumb(sb, val, size, max) |
| 1432 | scrollbar_T *sb; |
| 1433 | long val; |
| 1434 | long size; |
| 1435 | long max; |
| 1436 | { |
| 1437 | if (sb->id != (Widget)0) |
| 1438 | XtVaSetValues(sb->id, |
| 1439 | XmNvalue, val, |
| 1440 | XmNsliderSize, size, |
| 1441 | XmNpageIncrement, (size > 2 ? size - 2 : 1), |
| 1442 | XmNmaximum, max + 1, /* Motif has max one past the end */ |
| 1443 | NULL); |
| 1444 | } |
| 1445 | |
| 1446 | void |
| 1447 | gui_mch_set_scrollbar_pos(sb, x, y, w, h) |
| 1448 | scrollbar_T *sb; |
| 1449 | int x; |
| 1450 | int y; |
| 1451 | int w; |
| 1452 | int h; |
| 1453 | { |
| 1454 | if (sb->id != (Widget)0) |
| 1455 | { |
| 1456 | if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT) |
| 1457 | { |
| 1458 | if (y == 0) |
| 1459 | h -= gui.border_offset; |
| 1460 | else |
| 1461 | y -= gui.border_offset; |
| 1462 | XtVaSetValues(sb->id, |
| 1463 | XmNtopOffset, y, |
| 1464 | XmNbottomOffset, -y - h, |
| 1465 | XmNwidth, w, |
| 1466 | NULL); |
| 1467 | } |
| 1468 | else |
| 1469 | XtVaSetValues(sb->id, |
| 1470 | XmNtopOffset, y, |
| 1471 | XmNleftOffset, x, |
| 1472 | XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT] |
| 1473 | ? gui.scrollbar_width : 0, |
| 1474 | XmNheight, h, |
| 1475 | NULL); |
| 1476 | XtManageChild(sb->id); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | void |
| 1481 | gui_mch_enable_scrollbar(sb, flag) |
| 1482 | scrollbar_T *sb; |
| 1483 | int flag; |
| 1484 | { |
| 1485 | Arg args[16]; |
| 1486 | int n; |
| 1487 | |
| 1488 | if (sb->id != (Widget)0) |
| 1489 | { |
| 1490 | n = 0; |
| 1491 | if (flag) |
| 1492 | { |
| 1493 | switch (sb->type) |
| 1494 | { |
| 1495 | case SBAR_LEFT: |
| 1496 | XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++; |
| 1497 | break; |
| 1498 | |
| 1499 | case SBAR_RIGHT: |
| 1500 | XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++; |
| 1501 | break; |
| 1502 | |
| 1503 | case SBAR_BOTTOM: |
| 1504 | XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++; |
| 1505 | break; |
| 1506 | } |
| 1507 | XtSetValues(textArea, args, n); |
| 1508 | XtManageChild(sb->id); |
| 1509 | } |
| 1510 | else |
| 1511 | { |
| 1512 | if (!gui.which_scrollbars[sb->type]) |
| 1513 | { |
| 1514 | /* The scrollbars of this type are all disabled, adjust the |
| 1515 | * textArea attachment offset. */ |
| 1516 | switch (sb->type) |
| 1517 | { |
| 1518 | case SBAR_LEFT: |
| 1519 | XtSetArg(args[n], XmNleftOffset, 0); n++; |
| 1520 | break; |
| 1521 | |
| 1522 | case SBAR_RIGHT: |
| 1523 | XtSetArg(args[n], XmNrightOffset, 0); n++; |
| 1524 | break; |
| 1525 | |
| 1526 | case SBAR_BOTTOM: |
| 1527 | XtSetArg(args[n], XmNbottomOffset, 0);n++; |
| 1528 | break; |
| 1529 | } |
| 1530 | XtSetValues(textArea, args, n); |
| 1531 | } |
| 1532 | XtUnmanageChild(sb->id); |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | void |
| 1538 | gui_mch_create_scrollbar(sb, orient) |
| 1539 | scrollbar_T *sb; |
| 1540 | int orient; /* SBAR_VERT or SBAR_HORIZ */ |
| 1541 | { |
| 1542 | Arg args[16]; |
| 1543 | int n; |
| 1544 | |
| 1545 | n = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1546 | XtSetArg(args[n], XmNminimum, 0); n++; |
| 1547 | XtSetArg(args[n], XmNorientation, |
| 1548 | (orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++; |
| 1549 | |
| 1550 | switch (sb->type) |
| 1551 | { |
| 1552 | case SBAR_LEFT: |
| 1553 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 1554 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++; |
| 1555 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 1556 | break; |
| 1557 | |
| 1558 | case SBAR_RIGHT: |
| 1559 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 1560 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++; |
| 1561 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 1562 | break; |
| 1563 | |
| 1564 | case SBAR_BOTTOM: |
| 1565 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 1566 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 1567 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 1568 | break; |
| 1569 | } |
| 1570 | |
| 1571 | sb->id = XtCreateWidget("scrollBar", |
| 1572 | xmScrollBarWidgetClass, textAreaForm, args, n); |
| 1573 | |
| 1574 | /* Remember the default colors, needed for ":hi clear". */ |
| 1575 | if (gui.scroll_def_bg_pixel == (guicolor_T)0 |
| 1576 | && gui.scroll_def_fg_pixel == (guicolor_T)0) |
| 1577 | XtVaGetValues(sb->id, |
| 1578 | XmNbackground, &gui.scroll_def_bg_pixel, |
| 1579 | XmNforeground, &gui.scroll_def_fg_pixel, |
| 1580 | NULL); |
| 1581 | |
| 1582 | if (sb->id != (Widget)0) |
| 1583 | { |
| 1584 | gui_mch_set_scrollbar_colors(sb); |
| 1585 | XtAddCallback(sb->id, XmNvalueChangedCallback, |
| 1586 | scroll_cb, (XtPointer)sb->ident); |
| 1587 | XtAddCallback(sb->id, XmNdragCallback, |
| 1588 | scroll_cb, (XtPointer)sb->ident); |
| 1589 | XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb, |
| 1590 | (XtPointer)0); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 1595 | void |
| 1596 | gui_mch_destroy_scrollbar(sb) |
| 1597 | scrollbar_T *sb; |
| 1598 | { |
| 1599 | if (sb->id != (Widget)0) |
| 1600 | XtDestroyWidget(sb->id); |
| 1601 | } |
| 1602 | #endif |
| 1603 | |
| 1604 | void |
| 1605 | gui_mch_set_scrollbar_colors(sb) |
| 1606 | scrollbar_T *sb; |
| 1607 | { |
| 1608 | if (sb->id != (Widget)0) |
| 1609 | { |
| 1610 | if (gui.scroll_bg_pixel != INVALCOLOR) |
| 1611 | { |
| 1612 | #if (XmVersion>=1002) |
| 1613 | XmChangeColor(sb->id, gui.scroll_bg_pixel); |
| 1614 | #else |
| 1615 | XtVaSetValues(sb->id, |
| 1616 | XmNtroughColor, gui.scroll_bg_pixel, |
| 1617 | NULL); |
| 1618 | #endif |
| 1619 | } |
| 1620 | |
| 1621 | if (gui.scroll_fg_pixel != INVALCOLOR) |
| 1622 | XtVaSetValues(sb->id, |
| 1623 | XmNforeground, gui.scroll_fg_pixel, |
| 1624 | #if (XmVersion<1002) |
| 1625 | XmNbackground, gui.scroll_fg_pixel, |
| 1626 | #endif |
| 1627 | NULL); |
| 1628 | } |
| 1629 | |
| 1630 | /* This is needed for the rectangle below the vertical scrollbars. */ |
| 1631 | if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0) |
| 1632 | gui_motif_scroll_colors(textAreaForm); |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * Miscellaneous stuff: |
| 1637 | */ |
| 1638 | |
| 1639 | Window |
| 1640 | gui_x11_get_wid() |
| 1641 | { |
| 1642 | return(XtWindow(textArea)); |
| 1643 | } |
| 1644 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1645 | /* |
| 1646 | * Look for a widget in the widget tree w, with a mnemonic matching keycode. |
| 1647 | * When one is found, simulate a button press on that widget and give it the |
| 1648 | * keyboard focus. If the mnemonic is on a label, look in the userData field |
| 1649 | * of the label to see if it points to another widget, and give that the focus. |
| 1650 | */ |
| 1651 | static void |
| 1652 | do_mnemonic(Widget w, unsigned int keycode) |
| 1653 | { |
| 1654 | WidgetList children; |
| 1655 | int numChildren, i; |
| 1656 | Boolean isMenu; |
| 1657 | KeySym mnemonic = '\0'; |
| 1658 | char mneString[2]; |
| 1659 | Widget userData; |
| 1660 | unsigned char rowColType; |
| 1661 | |
| 1662 | if (XtIsComposite(w)) |
| 1663 | { |
| 1664 | if (XtClass(w) == xmRowColumnWidgetClass) |
| 1665 | { |
| 1666 | XtVaGetValues(w, XmNrowColumnType, &rowColType, 0); |
| 1667 | isMenu = (rowColType != (unsigned char)XmWORK_AREA); |
| 1668 | } |
| 1669 | else |
| 1670 | isMenu = False; |
| 1671 | if (!isMenu) |
| 1672 | { |
| 1673 | XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, |
| 1674 | &numChildren, 0); |
| 1675 | for (i = 0; i < numChildren; i++) |
| 1676 | do_mnemonic(children[i], keycode); |
| 1677 | } |
| 1678 | } |
| 1679 | else |
| 1680 | { |
| 1681 | XtVaGetValues(w, XmNmnemonic, &mnemonic, 0); |
| 1682 | if (mnemonic != '\0') |
| 1683 | { |
| 1684 | mneString[0] = mnemonic; |
| 1685 | mneString[1] = '\0'; |
| 1686 | if (XKeysymToKeycode(XtDisplay(XtParent(w)), |
| 1687 | XStringToKeysym(mneString)) == keycode) |
| 1688 | { |
| 1689 | if (XtClass(w) == xmLabelWidgetClass |
| 1690 | || XtClass(w) == xmLabelGadgetClass) |
| 1691 | { |
| 1692 | XtVaGetValues(w, XmNuserData, &userData, 0); |
| 1693 | if (userData != NULL && XtIsWidget(userData)) |
| 1694 | XmProcessTraversal(userData, XmTRAVERSE_CURRENT); |
| 1695 | } |
| 1696 | else |
| 1697 | { |
| 1698 | XKeyPressedEvent keyEvent; |
| 1699 | |
| 1700 | XmProcessTraversal(w, XmTRAVERSE_CURRENT); |
| 1701 | |
| 1702 | memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent)); |
| 1703 | keyEvent.type = KeyPress; |
| 1704 | keyEvent.serial = 1; |
| 1705 | keyEvent.send_event = True; |
| 1706 | keyEvent.display = XtDisplay(w); |
| 1707 | keyEvent.window = XtWindow(w); |
| 1708 | XtCallActionProc(w, "Activate", (XEvent *) & keyEvent, |
| 1709 | NULL, 0); |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | /* |
| 1717 | * Callback routine for dialog mnemonic processing. |
| 1718 | */ |
| 1719 | /*ARGSUSED*/ |
| 1720 | static void |
| 1721 | mnemonic_event(Widget w, XtPointer call_data, XKeyEvent *event) |
| 1722 | { |
| 1723 | do_mnemonic(w, event->keycode); |
| 1724 | } |
| 1725 | |
| 1726 | |
| 1727 | /* |
| 1728 | * Search the widget tree under w for widgets with mnemonics. When found, add |
| 1729 | * a passive grab to the dialog widget for the mnemonic character, thus |
| 1730 | * directing mnemonic events to the dialog widget. |
| 1731 | */ |
| 1732 | static void |
| 1733 | add_mnemonic_grabs(Widget dialog, Widget w) |
| 1734 | { |
| 1735 | char mneString[2]; |
| 1736 | WidgetList children; |
| 1737 | int numChildren, i; |
| 1738 | Boolean isMenu; |
| 1739 | KeySym mnemonic = '\0'; |
| 1740 | unsigned char rowColType; |
| 1741 | |
| 1742 | if (XtIsComposite(w)) |
| 1743 | { |
| 1744 | if (XtClass(w) == xmRowColumnWidgetClass) |
| 1745 | { |
| 1746 | XtVaGetValues(w, XmNrowColumnType, &rowColType, 0); |
| 1747 | isMenu = (rowColType != (unsigned char)XmWORK_AREA); |
| 1748 | } |
| 1749 | else |
| 1750 | isMenu = False; |
| 1751 | if (!isMenu) |
| 1752 | { |
| 1753 | XtVaGetValues(w, XmNchildren, &children, XmNnumChildren, |
| 1754 | &numChildren, 0); |
| 1755 | for (i = 0; i < numChildren; i++) |
| 1756 | add_mnemonic_grabs(dialog, children[i]); |
| 1757 | } |
| 1758 | } |
| 1759 | else |
| 1760 | { |
| 1761 | XtVaGetValues(w, XmNmnemonic, &mnemonic, 0); |
| 1762 | if (mnemonic != '\0') |
| 1763 | { |
| 1764 | mneString[0] = mnemonic; |
| 1765 | mneString[1] = '\0'; |
| 1766 | XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog), |
| 1767 | XStringToKeysym(mneString)), |
| 1768 | Mod1Mask, True, GrabModeAsync, GrabModeAsync); |
| 1769 | } |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | /* |
| 1774 | * Add a handler for mnemonics in a dialog. Motif itself only handles |
| 1775 | * mnemonics in menus. Mnemonics added or changed after this call will be |
| 1776 | * ignored. |
| 1777 | * |
| 1778 | * To add a mnemonic to a text field or list, set the XmNmnemonic resource on |
| 1779 | * the appropriate label and set the XmNuserData resource of the label to the |
| 1780 | * widget to get the focus when the mnemonic is typed. |
| 1781 | */ |
| 1782 | static void |
| 1783 | activate_dialog_mnemonics(Widget dialog) |
| 1784 | { |
| 1785 | if (!dialog) |
| 1786 | return; |
| 1787 | |
| 1788 | XtAddEventHandler(dialog, KeyPressMask, False, |
| 1789 | (XtEventHandler) mnemonic_event, (XtPointer) NULL); |
| 1790 | add_mnemonic_grabs(dialog, dialog); |
| 1791 | } |
| 1792 | |
| 1793 | /* |
| 1794 | * Removes the event handler and key-grabs for dialog mnemonic handling. |
| 1795 | */ |
| 1796 | static void |
| 1797 | suppress_dialog_mnemonics(Widget dialog) |
| 1798 | { |
| 1799 | if (!dialog) |
| 1800 | return; |
| 1801 | |
| 1802 | XtUngrabKey(dialog, AnyKey, Mod1Mask); |
| 1803 | XtRemoveEventHandler(dialog, KeyPressMask, False, |
| 1804 | (XtEventHandler) mnemonic_event, (XtPointer) NULL); |
| 1805 | } |
| 1806 | |
| 1807 | #if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG) |
| 1808 | static void set_fontlist __ARGS((Widget wg)); |
| 1809 | |
| 1810 | /* |
| 1811 | * Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget. |
| 1812 | */ |
| 1813 | static void |
| 1814 | set_fontlist(id) |
| 1815 | Widget id; |
| 1816 | { |
| 1817 | XmFontList fl; |
| 1818 | |
| 1819 | #ifdef FONTSET_ALWAYS |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1820 | if (gui.fontset != NOFONTSET) |
| 1821 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1822 | fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset); |
| 1823 | if (fl != NULL) |
| 1824 | { |
| 1825 | if (XtIsManaged(id)) |
| 1826 | { |
| 1827 | XtUnmanageChild(id); |
| 1828 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 1829 | /* We should force the widget to recalculate it's |
| 1830 | * geometry now. */ |
| 1831 | XtManageChild(id); |
| 1832 | } |
| 1833 | else |
| 1834 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 1835 | XmFontListFree(fl); |
| 1836 | } |
| 1837 | } |
| 1838 | #else |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 1839 | if (gui.norm_font != NOFONT) |
| 1840 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1841 | fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); |
| 1842 | if (fl != NULL) |
| 1843 | { |
| 1844 | if (XtIsManaged(id)) |
| 1845 | { |
| 1846 | XtUnmanageChild(id); |
| 1847 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 1848 | /* We should force the widget to recalculate it's |
| 1849 | * geometry now. */ |
| 1850 | XtManageChild(id); |
| 1851 | } |
| 1852 | else |
| 1853 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 1854 | XmFontListFree(fl); |
| 1855 | } |
| 1856 | } |
| 1857 | #endif |
| 1858 | } |
| 1859 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1860 | |
| 1861 | #if defined(FEAT_BROWSE) || defined(PROTO) |
| 1862 | |
| 1863 | /* |
| 1864 | * file selector related stuff |
| 1865 | */ |
| 1866 | |
| 1867 | #include <Xm/FileSB.h> |
| 1868 | #include <Xm/XmStrDefs.h> |
| 1869 | |
| 1870 | typedef struct dialog_callback_arg |
| 1871 | { |
| 1872 | char * args; /* not used right now */ |
| 1873 | int id; |
| 1874 | } dcbarg_T; |
| 1875 | |
| 1876 | static Widget dialog_wgt; |
| 1877 | static char *browse_fname = NULL; |
| 1878 | static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET; |
| 1879 | /* used to set up XmStrings */ |
| 1880 | |
| 1881 | static void DialogCancelCB __ARGS((Widget, XtPointer, XtPointer)); |
| 1882 | static void DialogAcceptCB __ARGS((Widget, XtPointer, XtPointer)); |
| 1883 | |
| 1884 | /* |
| 1885 | * This function is used to translate the predefined label text of the |
| 1886 | * precomposed dialogs. We do this explicitly to allow: |
| 1887 | * |
| 1888 | * - usage of gettext for translation, as in all the other places. |
| 1889 | * |
| 1890 | * - equalize the messages between different GUI implementations as far as |
| 1891 | * possible. |
| 1892 | */ |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1893 | 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] | 1894 | |
| 1895 | static void |
| 1896 | set_predefined_label(parent, name, new_label) |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1897 | Widget parent; |
| 1898 | String name; |
| 1899 | char *new_label; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1900 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1901 | XmString str; |
| 1902 | Widget w; |
| 1903 | char_u *p, *next; |
| 1904 | KeySym mnemonic = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1905 | |
| 1906 | w = XtNameToWidget(parent, name); |
| 1907 | |
| 1908 | if (!w) |
| 1909 | return; |
| 1910 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1911 | p = vim_strsave((char_u *)new_label); |
| 1912 | if (p == NULL) |
| 1913 | return; |
| 1914 | for (next = p; *next; ++next) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1915 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1916 | if (*next == DLG_HOTKEY_CHAR) |
| 1917 | { |
| 1918 | int len = STRLEN(next); |
| 1919 | |
| 1920 | if (len > 0) |
| 1921 | { |
| 1922 | mch_memmove(next, next + 1, len); |
| 1923 | mnemonic = next[0]; |
| 1924 | } |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | str = XmStringCreate((char *)p, STRING_TAG); |
| 1929 | vim_free(p); |
| 1930 | |
| 1931 | if (str != NULL) |
| 1932 | { |
| 1933 | XtVaSetValues(w, |
| 1934 | XmNlabelString, str, |
| 1935 | XmNmnemonic, mnemonic, |
| 1936 | NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1937 | XmStringFree(str); |
| 1938 | } |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1939 | gui_motif_menu_fontlist(w); |
| 1940 | } |
| 1941 | |
| 1942 | static void |
| 1943 | set_predefined_fontlist(parent, name) |
| 1944 | Widget parent; |
| 1945 | String name; |
| 1946 | { |
| 1947 | Widget w; |
| 1948 | w = XtNameToWidget(parent, name); |
| 1949 | |
| 1950 | if (!w) |
| 1951 | return; |
| 1952 | |
| 1953 | set_fontlist(w); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * Put up a file requester. |
| 1958 | * Returns the selected name in allocated memory, or NULL for Cancel. |
| 1959 | */ |
| 1960 | /* ARGSUSED */ |
| 1961 | char_u * |
| 1962 | gui_mch_browse(saving, title, dflt, ext, initdir, filter) |
| 1963 | int saving; /* select file to write */ |
| 1964 | char_u *title; /* title for the window */ |
| 1965 | char_u *dflt; /* default name */ |
| 1966 | char_u *ext; /* not used (extension added) */ |
| 1967 | char_u *initdir; /* initial directory, NULL for current dir */ |
| 1968 | char_u *filter; /* file name filter */ |
| 1969 | { |
| 1970 | char_u dirbuf[MAXPATHL]; |
| 1971 | char_u dfltbuf[MAXPATHL]; |
| 1972 | char_u *pattern; |
| 1973 | char_u *tofree = NULL; |
| 1974 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1975 | /* There a difference between the resource name and value, Therefore, we |
| 1976 | * avoid to (ab-)use the (maybe internationalized!) dialog title as a |
| 1977 | * dialog name. |
| 1978 | */ |
| 1979 | |
| 1980 | dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1981 | |
| 1982 | if (initdir == NULL || *initdir == NUL) |
| 1983 | { |
| 1984 | mch_dirname(dirbuf, MAXPATHL); |
| 1985 | initdir = dirbuf; |
| 1986 | } |
| 1987 | |
| 1988 | if (dflt == NULL) |
| 1989 | dflt = (char_u *)""; |
| 1990 | else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL) |
| 1991 | { |
| 1992 | /* The default selection should be the full path, "dflt" is only the |
| 1993 | * file name. */ |
| 1994 | STRCPY(dfltbuf, initdir); |
| 1995 | add_pathsep(dfltbuf); |
| 1996 | STRCAT(dfltbuf, dflt); |
| 1997 | dflt = dfltbuf; |
| 1998 | } |
| 1999 | |
| 2000 | /* Can only use one pattern for a file name. Get the first pattern out of |
| 2001 | * the filter. An empty pattern means everything matches. */ |
| 2002 | if (filter == NULL) |
| 2003 | pattern = (char_u *)""; |
| 2004 | else |
| 2005 | { |
| 2006 | char_u *s, *p; |
| 2007 | |
| 2008 | s = filter; |
| 2009 | for (p = filter; *p != NUL; ++p) |
| 2010 | { |
| 2011 | if (*p == '\t') /* end of description, start of pattern */ |
| 2012 | s = p + 1; |
| 2013 | if (*p == ';' || *p == '\n') /* end of (first) pattern */ |
| 2014 | break; |
| 2015 | } |
| 2016 | pattern = vim_strnsave(s, p - s); |
| 2017 | tofree = pattern; |
| 2018 | if (pattern == NULL) |
| 2019 | pattern = (char_u *)""; |
| 2020 | } |
| 2021 | |
| 2022 | XtVaSetValues(dialog_wgt, |
| 2023 | XtVaTypedArg, |
| 2024 | XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1, |
| 2025 | XtVaTypedArg, |
| 2026 | XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1, |
| 2027 | XtVaTypedArg, |
| 2028 | XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1, |
| 2029 | XtVaTypedArg, |
| 2030 | XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1, |
| 2031 | NULL); |
| 2032 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2033 | set_predefined_label(dialog_wgt, "Apply", _("&Filter")); |
| 2034 | set_predefined_label(dialog_wgt, "Cancel", _("&Cancel")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2035 | set_predefined_label(dialog_wgt, "Dir", _("Directories")); |
| 2036 | set_predefined_label(dialog_wgt, "FilterLabel", _("Filter")); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2037 | set_predefined_label(dialog_wgt, "Help", _("&Help")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2038 | set_predefined_label(dialog_wgt, "Items", _("Files")); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2039 | set_predefined_label(dialog_wgt, "OK", _("&OK")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2040 | set_predefined_label(dialog_wgt, "Selection", _("Selection")); |
| 2041 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2042 | /* This is to save us from silly external settings using not fixed with |
| 2043 | * fonts for file selection. |
| 2044 | */ |
| 2045 | set_predefined_fontlist(dialog_wgt, "DirListSW.DirList"); |
| 2046 | set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList"); |
| 2047 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2048 | gui_motif_menu_colors(dialog_wgt); |
| 2049 | if (gui.scroll_bg_pixel != INVALCOLOR) |
| 2050 | XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL); |
| 2051 | |
| 2052 | XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0); |
| 2053 | XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0); |
| 2054 | /* We have no help in this window, so hide help button */ |
| 2055 | XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt, |
| 2056 | (unsigned char)XmDIALOG_HELP_BUTTON)); |
| 2057 | |
| 2058 | manage_centered(dialog_wgt); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2059 | activate_dialog_mnemonics(dialog_wgt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2060 | |
| 2061 | /* sit in a loop until the dialog box has gone away */ |
| 2062 | do |
| 2063 | { |
| 2064 | XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt), |
| 2065 | (XtInputMask)XtIMAll); |
| 2066 | } while (XtIsManaged(dialog_wgt)); |
| 2067 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2068 | suppress_dialog_mnemonics(dialog_wgt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2069 | XtDestroyWidget(dialog_wgt); |
| 2070 | vim_free(tofree); |
| 2071 | |
| 2072 | if (browse_fname == NULL) |
| 2073 | return NULL; |
| 2074 | return vim_strsave((char_u *)browse_fname); |
| 2075 | } |
| 2076 | |
| 2077 | /* |
| 2078 | * The code below was originally taken from |
| 2079 | * /usr/examples/motif/xmsamplers/xmeditor.c |
| 2080 | * on Digital Unix 4.0d, but heavily modified. |
| 2081 | */ |
| 2082 | |
| 2083 | /* |
| 2084 | * Process callback from Dialog cancel actions. |
| 2085 | */ |
| 2086 | /* ARGSUSED */ |
| 2087 | static void |
| 2088 | DialogCancelCB(w, client_data, call_data) |
| 2089 | Widget w; /* widget id */ |
| 2090 | XtPointer client_data; /* data from application */ |
| 2091 | XtPointer call_data; /* data from widget class */ |
| 2092 | { |
| 2093 | if (browse_fname != NULL) |
| 2094 | { |
| 2095 | XtFree(browse_fname); |
| 2096 | browse_fname = NULL; |
| 2097 | } |
| 2098 | XtUnmanageChild(dialog_wgt); |
| 2099 | } |
| 2100 | |
| 2101 | /* |
| 2102 | * Process callback from Dialog actions. |
| 2103 | */ |
| 2104 | /* ARGSUSED */ |
| 2105 | static void |
| 2106 | DialogAcceptCB(w, client_data, call_data) |
| 2107 | Widget w; /* widget id */ |
| 2108 | XtPointer client_data; /* data from application */ |
| 2109 | XtPointer call_data; /* data from widget class */ |
| 2110 | { |
| 2111 | XmFileSelectionBoxCallbackStruct *fcb; |
| 2112 | |
| 2113 | if (browse_fname != NULL) |
| 2114 | { |
| 2115 | XtFree(browse_fname); |
| 2116 | browse_fname = NULL; |
| 2117 | } |
| 2118 | fcb = (XmFileSelectionBoxCallbackStruct *)call_data; |
| 2119 | |
| 2120 | /* get the filename from the file selection box */ |
| 2121 | XmStringGetLtoR(fcb->value, charset, &browse_fname); |
| 2122 | |
| 2123 | /* popdown the file selection box */ |
| 2124 | XtUnmanageChild(dialog_wgt); |
| 2125 | } |
| 2126 | |
| 2127 | #endif /* FEAT_BROWSE */ |
| 2128 | |
| 2129 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 2130 | |
| 2131 | static int dialogStatus; |
| 2132 | |
| 2133 | static void keyhit_callback __ARGS((Widget w, XtPointer client_data, XEvent *event, Boolean *cont)); |
| 2134 | static void butproc __ARGS((Widget w, XtPointer client_data, XtPointer call_data)); |
| 2135 | |
| 2136 | /* |
| 2137 | * Callback function for the textfield. When CR is hit this works like |
| 2138 | * hitting the "OK" button, ESC like "Cancel". |
| 2139 | */ |
| 2140 | /* ARGSUSED */ |
| 2141 | static void |
| 2142 | keyhit_callback(w, client_data, event, cont) |
| 2143 | Widget w; |
| 2144 | XtPointer client_data; |
| 2145 | XEvent *event; |
| 2146 | Boolean *cont; |
| 2147 | { |
| 2148 | char buf[2]; |
| 2149 | KeySym key_sym; |
| 2150 | |
| 2151 | if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1) |
| 2152 | { |
| 2153 | if (*buf == CAR) |
| 2154 | dialogStatus = 1; |
| 2155 | else if (*buf == ESC) |
| 2156 | dialogStatus = 2; |
| 2157 | } |
| 2158 | if ((key_sym == XK_Left || key_sym == XK_Right) |
| 2159 | && !(event->xkey.state & ShiftMask)) |
| 2160 | XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy)); |
| 2161 | } |
| 2162 | |
| 2163 | /* ARGSUSED */ |
| 2164 | static void |
| 2165 | butproc(w, client_data, call_data) |
| 2166 | Widget w; |
| 2167 | XtPointer client_data; |
| 2168 | XtPointer call_data; |
| 2169 | { |
| 2170 | dialogStatus = (int)(long)client_data + 1; |
| 2171 | } |
| 2172 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2173 | #ifdef HAVE_XPM |
| 2174 | |
| 2175 | static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg); |
| 2176 | |
| 2177 | static Widget |
| 2178 | create_pixmap_label(parent, name, data, args, arg) |
| 2179 | Widget parent; |
| 2180 | String name; |
| 2181 | char **data; |
| 2182 | ArgList args; |
| 2183 | Cardinal arg; |
| 2184 | { |
| 2185 | Widget label; |
| 2186 | Display *dsp; |
| 2187 | Screen *scr; |
| 2188 | int depth; |
| 2189 | Pixmap pixmap = 0; |
| 2190 | XpmAttributes attr; |
| 2191 | Boolean rs; |
| 2192 | XpmColorSymbol color[5] = |
| 2193 | { |
| 2194 | {"none", NULL, 0}, |
| 2195 | {"iconColor1", NULL, 0}, |
| 2196 | {"bottomShadowColor", NULL, 0}, |
| 2197 | {"topShadowColor", NULL, 0}, |
| 2198 | {"selectColor", NULL, 0} |
| 2199 | }; |
| 2200 | |
| 2201 | label = XmCreateLabelGadget(parent, name, args, arg); |
| 2202 | |
| 2203 | /* |
| 2204 | * We need to be carefull here, since in case of gadgets, there is |
| 2205 | * no way to get the background color directly from the widget itself. |
| 2206 | * In such cases we get it from The Core part of his parent instead. |
| 2207 | */ |
| 2208 | dsp = XtDisplayOfObject(label); |
| 2209 | scr = XtScreenOfObject(label); |
| 2210 | XtVaGetValues(XtIsSubclass(label, coreWidgetClass) |
| 2211 | ? label : XtParent(label), |
| 2212 | XmNdepth, &depth, |
| 2213 | XmNbackground, &color[0].pixel, |
| 2214 | XmNforeground, &color[1].pixel, |
| 2215 | XmNbottomShadowColor, &color[2].pixel, |
| 2216 | XmNtopShadowColor, &color[3].pixel, |
| 2217 | XmNhighlight, &color[4].pixel, |
| 2218 | NULL); |
| 2219 | |
| 2220 | attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth; |
| 2221 | attr.colorsymbols = color; |
| 2222 | attr.numsymbols = 5; |
| 2223 | attr.closeness = 65535; |
| 2224 | attr.depth = depth; |
| 2225 | XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr), |
| 2226 | data, &pixmap, NULL, &attr); |
| 2227 | |
| 2228 | XtVaGetValues(label, XmNrecomputeSize, &rs, NULL); |
| 2229 | XtVaSetValues(label, XmNrecomputeSize, True, NULL); |
| 2230 | XtVaSetValues(label, |
| 2231 | XmNlabelType, XmPIXMAP, |
| 2232 | XmNlabelPixmap, pixmap, |
| 2233 | NULL); |
| 2234 | XtVaSetValues(label, XmNrecomputeSize, rs, NULL); |
| 2235 | |
| 2236 | return label; |
| 2237 | } |
| 2238 | #endif |
| 2239 | |
| 2240 | /* ARGSUSED */ |
| 2241 | int |
| 2242 | gui_mch_dialog(type, title, message, button_names, dfltbutton, textfield) |
| 2243 | int type; |
| 2244 | char_u *title; |
| 2245 | char_u *message; |
| 2246 | char_u *button_names; |
| 2247 | int dfltbutton; |
| 2248 | char_u *textfield; /* buffer of size IOSIZE */ |
| 2249 | { |
| 2250 | char_u *buts; |
| 2251 | char_u *p, *next; |
| 2252 | XtAppContext app; |
| 2253 | XmString label; |
| 2254 | int butcount; |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2255 | Widget w; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2256 | Widget dialogform = NULL; |
| 2257 | Widget form = NULL; |
| 2258 | Widget dialogtextfield = NULL; |
| 2259 | Widget *buttons; |
| 2260 | Widget sep_form = NULL; |
| 2261 | Boolean vertical; |
| 2262 | Widget separator = NULL; |
| 2263 | int n; |
| 2264 | Arg args[6]; |
| 2265 | #ifdef HAVE_XPM |
| 2266 | char **icon_data = NULL; |
| 2267 | Widget dialogpixmap = NULL; |
| 2268 | #endif |
| 2269 | |
| 2270 | if (title == NULL) |
| 2271 | title = (char_u *)_("Vim dialog"); |
| 2272 | |
| 2273 | /* if our pointer is currently hidden, then we should show it. */ |
| 2274 | gui_mch_mousehide(FALSE); |
| 2275 | |
| 2276 | dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0); |
| 2277 | |
| 2278 | /* Check 'v' flag in 'guioptions': vertical button placement. */ |
| 2279 | vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); |
| 2280 | |
| 2281 | /* Set the title of the Dialog window */ |
| 2282 | label = XmStringCreateSimple((char *)title); |
| 2283 | if (label == NULL) |
| 2284 | return -1; |
| 2285 | XtVaSetValues(dialogform, |
| 2286 | XmNdialogTitle, label, |
| 2287 | XmNhorizontalSpacing, 4, |
| 2288 | XmNverticalSpacing, vertical ? 0 : 4, |
| 2289 | NULL); |
| 2290 | XmStringFree(label); |
| 2291 | |
| 2292 | /* make a copy, so that we can insert NULs */ |
| 2293 | buts = vim_strsave(button_names); |
| 2294 | if (buts == NULL) |
| 2295 | return -1; |
| 2296 | |
| 2297 | /* Count the number of buttons and allocate buttons[]. */ |
| 2298 | butcount = 1; |
| 2299 | for (p = buts; *p; ++p) |
| 2300 | if (*p == DLG_BUTTON_SEP) |
| 2301 | ++butcount; |
| 2302 | buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget))); |
| 2303 | if (buttons == NULL) |
| 2304 | { |
| 2305 | vim_free(buts); |
| 2306 | return -1; |
| 2307 | } |
| 2308 | |
| 2309 | /* |
| 2310 | * Create the buttons. |
| 2311 | */ |
| 2312 | sep_form = (Widget) 0; |
| 2313 | p = buts; |
| 2314 | for (butcount = 0; *p; ++butcount) |
| 2315 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2316 | KeySym mnemonic = NUL; |
| 2317 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2318 | for (next = p; *next; ++next) |
| 2319 | { |
| 2320 | if (*next == DLG_HOTKEY_CHAR) |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2321 | { |
| 2322 | int len = STRLEN(next); |
| 2323 | |
| 2324 | if (len > 0) |
| 2325 | { |
| 2326 | mch_memmove(next, next + 1, len); |
| 2327 | mnemonic = next[0]; |
| 2328 | } |
| 2329 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2330 | if (*next == DLG_BUTTON_SEP) |
| 2331 | { |
| 2332 | *next++ = NUL; |
| 2333 | break; |
| 2334 | } |
| 2335 | } |
| 2336 | label = XmStringCreate(_((char *)p), STRING_TAG); |
| 2337 | if (label == NULL) |
| 2338 | break; |
| 2339 | |
| 2340 | buttons[butcount] = XtVaCreateManagedWidget("button", |
| 2341 | xmPushButtonWidgetClass, dialogform, |
| 2342 | XmNlabelString, label, |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2343 | XmNmnemonic, mnemonic, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2344 | XmNbottomAttachment, XmATTACH_FORM, |
| 2345 | XmNbottomOffset, 4, |
| 2346 | XmNshowAsDefault, butcount == dfltbutton - 1, |
| 2347 | XmNdefaultButtonShadowThickness, 1, |
| 2348 | NULL); |
| 2349 | XmStringFree(label); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2350 | gui_motif_menu_fontlist(buttons[butcount]); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2351 | |
| 2352 | /* Layout properly. */ |
| 2353 | |
| 2354 | if (butcount > 0) |
| 2355 | { |
| 2356 | if (vertical) |
| 2357 | XtVaSetValues(buttons[butcount], |
| 2358 | XmNtopWidget, buttons[butcount - 1], |
| 2359 | NULL); |
| 2360 | else |
| 2361 | { |
| 2362 | if (*next == NUL) |
| 2363 | { |
| 2364 | XtVaSetValues(buttons[butcount], |
| 2365 | XmNrightAttachment, XmATTACH_FORM, |
| 2366 | XmNrightOffset, 4, |
| 2367 | NULL); |
| 2368 | |
| 2369 | /* fill in a form as invisible separator */ |
| 2370 | sep_form = XtVaCreateWidget("separatorForm", |
| 2371 | xmFormWidgetClass, dialogform, |
| 2372 | XmNleftAttachment, XmATTACH_WIDGET, |
| 2373 | XmNleftWidget, buttons[butcount - 1], |
| 2374 | XmNrightAttachment, XmATTACH_WIDGET, |
| 2375 | XmNrightWidget, buttons[butcount], |
| 2376 | XmNbottomAttachment, XmATTACH_FORM, |
| 2377 | XmNbottomOffset, 4, |
| 2378 | NULL); |
| 2379 | XtManageChild(sep_form); |
| 2380 | } |
| 2381 | else |
| 2382 | { |
| 2383 | XtVaSetValues(buttons[butcount], |
| 2384 | XmNleftAttachment, XmATTACH_WIDGET, |
| 2385 | XmNleftWidget, buttons[butcount - 1], |
| 2386 | NULL); |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | else if (!vertical) |
| 2391 | { |
| 2392 | if (*next == NUL) |
| 2393 | { |
| 2394 | XtVaSetValues(buttons[0], |
| 2395 | XmNrightAttachment, XmATTACH_FORM, |
| 2396 | XmNrightOffset, 4, |
| 2397 | NULL); |
| 2398 | |
| 2399 | /* fill in a form as invisible separator */ |
| 2400 | sep_form = XtVaCreateWidget("separatorForm", |
| 2401 | xmFormWidgetClass, dialogform, |
| 2402 | XmNleftAttachment, XmATTACH_FORM, |
| 2403 | XmNleftOffset, 4, |
| 2404 | XmNrightAttachment, XmATTACH_WIDGET, |
| 2405 | XmNrightWidget, buttons[0], |
| 2406 | XmNbottomAttachment, XmATTACH_FORM, |
| 2407 | XmNbottomOffset, 4, |
| 2408 | NULL); |
| 2409 | XtManageChild(sep_form); |
| 2410 | } |
| 2411 | else |
| 2412 | XtVaSetValues(buttons[0], |
| 2413 | XmNleftAttachment, XmATTACH_FORM, |
| 2414 | XmNleftOffset, 4, |
| 2415 | NULL); |
| 2416 | } |
| 2417 | |
| 2418 | XtAddCallback(buttons[butcount], XmNactivateCallback, |
| 2419 | (XtCallbackProc)butproc, (XtPointer)(long)butcount); |
| 2420 | p = next; |
| 2421 | } |
| 2422 | vim_free(buts); |
| 2423 | |
| 2424 | separator = (Widget) 0; |
| 2425 | if (butcount > 0) |
| 2426 | { |
| 2427 | /* Create the separator for beauty. */ |
| 2428 | n = 0; |
| 2429 | XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++; |
| 2430 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++; |
| 2431 | XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++; |
| 2432 | XtSetArg(args[n], XmNbottomOffset, 4); n++; |
| 2433 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 2434 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; |
| 2435 | separator = XmCreateSeparatorGadget(dialogform, "separator", args, n); |
| 2436 | XtManageChild(separator); |
| 2437 | } |
| 2438 | |
| 2439 | if (textfield != NULL) |
| 2440 | { |
| 2441 | dialogtextfield = XtVaCreateWidget("textField", |
| 2442 | xmTextFieldWidgetClass, dialogform, |
| 2443 | XmNleftAttachment, XmATTACH_FORM, |
| 2444 | XmNrightAttachment, XmATTACH_FORM, |
| 2445 | NULL); |
| 2446 | if (butcount > 0) |
| 2447 | XtVaSetValues(dialogtextfield, |
| 2448 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 2449 | XmNbottomWidget, separator, |
| 2450 | NULL); |
| 2451 | else |
| 2452 | XtVaSetValues(dialogtextfield, |
| 2453 | XmNbottomAttachment, XmATTACH_FORM, |
| 2454 | NULL); |
| 2455 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2456 | set_fontlist(dialogtextfield); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2457 | XmTextFieldSetString(dialogtextfield, (char *)textfield); |
| 2458 | XtManageChild(dialogtextfield); |
| 2459 | XtAddEventHandler(dialogtextfield, KeyPressMask, False, |
| 2460 | (XtEventHandler)keyhit_callback, (XtPointer)NULL); |
| 2461 | } |
| 2462 | |
| 2463 | /* Form holding both message and pixmap labels */ |
| 2464 | form = XtVaCreateWidget("separatorForm", |
| 2465 | xmFormWidgetClass, dialogform, |
| 2466 | XmNleftAttachment, XmATTACH_FORM, |
| 2467 | XmNrightAttachment, XmATTACH_FORM, |
| 2468 | XmNtopAttachment, XmATTACH_FORM, |
| 2469 | NULL); |
| 2470 | XtManageChild(form); |
| 2471 | |
| 2472 | #ifdef HAVE_XPM |
| 2473 | /* Add a pixmap, left of the message. */ |
| 2474 | switch (type) |
| 2475 | { |
| 2476 | case VIM_GENERIC: |
| 2477 | icon_data = generic_xpm; |
| 2478 | break; |
| 2479 | case VIM_ERROR: |
| 2480 | icon_data = error_xpm; |
| 2481 | break; |
| 2482 | case VIM_WARNING: |
| 2483 | icon_data = alert_xpm; |
| 2484 | break; |
| 2485 | case VIM_INFO: |
| 2486 | icon_data = info_xpm; |
| 2487 | break; |
| 2488 | case VIM_QUESTION: |
| 2489 | icon_data = quest_xpm; |
| 2490 | break; |
| 2491 | default: |
| 2492 | icon_data = generic_xpm; |
| 2493 | } |
| 2494 | |
| 2495 | n = 0; |
| 2496 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 2497 | XtSetArg(args[n], XmNtopOffset, 8); n++; |
| 2498 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 2499 | XtSetArg(args[n], XmNbottomOffset, 8); n++; |
| 2500 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 2501 | XtSetArg(args[n], XmNleftOffset, 8); n++; |
| 2502 | |
| 2503 | dialogpixmap = create_pixmap_label(form, "dialogPixmap", |
| 2504 | icon_data, args, n); |
| 2505 | XtManageChild(dialogpixmap); |
| 2506 | #endif |
| 2507 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2508 | /* Create the dialog message. |
| 2509 | * Since LessTif is apparently having problems with the creation of |
| 2510 | * properly localized string, we use LtoR here. The symptom is that the |
| 2511 | * string sill not show properly in multiple lines as it does in native |
| 2512 | * Motif. |
| 2513 | */ |
| 2514 | label = XmStringCreateLtoR((char *)message, STRING_TAG); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2515 | if (label == NULL) |
| 2516 | return -1; |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2517 | w = XtVaCreateManagedWidget("dialogMessage", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2518 | xmLabelGadgetClass, form, |
| 2519 | XmNlabelString, label, |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2520 | XmNalignment, XmALIGNMENT_BEGINNING, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2521 | XmNtopAttachment, XmATTACH_FORM, |
| 2522 | XmNtopOffset, 8, |
| 2523 | #ifdef HAVE_XPM |
| 2524 | XmNleftAttachment, XmATTACH_WIDGET, |
| 2525 | XmNleftWidget, dialogpixmap, |
| 2526 | #else |
| 2527 | XmNleftAttachment, XmATTACH_FORM, |
| 2528 | #endif |
| 2529 | XmNleftOffset, 8, |
| 2530 | XmNrightAttachment, XmATTACH_FORM, |
| 2531 | XmNrightOffset, 8, |
| 2532 | XmNbottomAttachment, XmATTACH_FORM, |
| 2533 | XmNbottomOffset, 8, |
| 2534 | NULL); |
| 2535 | XmStringFree(label); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2536 | set_fontlist(w); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2537 | |
| 2538 | if (textfield != NULL) |
| 2539 | { |
| 2540 | XtVaSetValues(form, |
| 2541 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 2542 | XmNbottomWidget, dialogtextfield, |
| 2543 | NULL); |
| 2544 | } |
| 2545 | else |
| 2546 | { |
| 2547 | if (butcount > 0) |
| 2548 | XtVaSetValues(form, |
| 2549 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 2550 | XmNbottomWidget, separator, |
| 2551 | NULL); |
| 2552 | else |
| 2553 | XtVaSetValues(form, |
| 2554 | XmNbottomAttachment, XmATTACH_FORM, |
| 2555 | NULL); |
| 2556 | } |
| 2557 | |
| 2558 | if (dfltbutton < 1) |
| 2559 | dfltbutton = 1; |
| 2560 | if (dfltbutton > butcount) |
| 2561 | dfltbutton = butcount; |
| 2562 | XtVaSetValues(dialogform, |
| 2563 | XmNdefaultButton, buttons[dfltbutton - 1], NULL); |
| 2564 | if (textfield != NULL) |
| 2565 | XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL); |
| 2566 | else |
| 2567 | XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1], |
| 2568 | NULL); |
| 2569 | |
| 2570 | manage_centered(dialogform); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2571 | activate_dialog_mnemonics(dialogform); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2572 | |
| 2573 | if (textfield != NULL && *textfield != NUL) |
| 2574 | { |
| 2575 | /* This only works after the textfield has been realised. */ |
| 2576 | XmTextFieldSetSelection(dialogtextfield, |
| 2577 | (XmTextPosition)0, (XmTextPosition)STRLEN(textfield), |
| 2578 | XtLastTimestampProcessed(gui.dpy)); |
| 2579 | XmTextFieldSetCursorPosition(dialogtextfield, |
| 2580 | (XmTextPosition)STRLEN(textfield)); |
| 2581 | } |
| 2582 | |
| 2583 | app = XtWidgetToApplicationContext(dialogform); |
| 2584 | |
| 2585 | /* Loop until a button is pressed or the dialog is killed somehow. */ |
| 2586 | dialogStatus = -1; |
| 2587 | for (;;) |
| 2588 | { |
| 2589 | XtAppProcessEvent(app, (XtInputMask)XtIMAll); |
| 2590 | if (dialogStatus >= 0 || !XtIsManaged(dialogform)) |
| 2591 | break; |
| 2592 | } |
| 2593 | |
| 2594 | vim_free(buttons); |
| 2595 | |
| 2596 | if (textfield != NULL) |
| 2597 | { |
| 2598 | p = (char_u *)XmTextGetString(dialogtextfield); |
| 2599 | if (p == NULL || dialogStatus < 0) |
| 2600 | *textfield = NUL; |
| 2601 | else |
| 2602 | { |
| 2603 | STRNCPY(textfield, p, IOSIZE); |
| 2604 | textfield[IOSIZE - 1] = NUL; |
| 2605 | } |
| 2606 | } |
| 2607 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2608 | suppress_dialog_mnemonics(dialogform); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2609 | XtDestroyWidget(dialogform); |
| 2610 | |
| 2611 | return dialogStatus; |
| 2612 | } |
| 2613 | #endif /* FEAT_GUI_DIALOG */ |
| 2614 | |
| 2615 | #if defined(FEAT_FOOTER) || defined(PROTO) |
| 2616 | |
| 2617 | static int |
| 2618 | gui_mch_compute_footer_height() |
| 2619 | { |
| 2620 | Dimension height; /* total Toolbar height */ |
| 2621 | Dimension top; /* XmNmarginTop */ |
| 2622 | Dimension bottom; /* XmNmarginBottom */ |
| 2623 | Dimension shadow; /* XmNshadowThickness */ |
| 2624 | |
| 2625 | XtVaGetValues(footer, |
| 2626 | XmNheight, &height, |
| 2627 | XmNmarginTop, &top, |
| 2628 | XmNmarginBottom, &bottom, |
| 2629 | XmNshadowThickness, &shadow, |
| 2630 | NULL); |
| 2631 | |
| 2632 | return (int) height + top + bottom + (shadow << 1); |
| 2633 | } |
| 2634 | |
| 2635 | #if 0 /* not used */ |
| 2636 | void |
| 2637 | gui_mch_set_footer_pos(h) |
| 2638 | int h; /* textArea height */ |
| 2639 | { |
| 2640 | XtVaSetValues(footer, |
| 2641 | XmNtopOffset, h + 7, |
| 2642 | NULL); |
| 2643 | } |
| 2644 | #endif |
| 2645 | |
| 2646 | void |
| 2647 | gui_mch_enable_footer(showit) |
| 2648 | int showit; |
| 2649 | { |
| 2650 | if (showit) |
| 2651 | { |
| 2652 | gui.footer_height = gui_mch_compute_footer_height(); |
| 2653 | XtManageChild(footer); |
| 2654 | } |
| 2655 | else |
| 2656 | { |
| 2657 | gui.footer_height = 0; |
| 2658 | XtUnmanageChild(footer); |
| 2659 | } |
| 2660 | XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL); |
| 2661 | } |
| 2662 | |
| 2663 | void |
| 2664 | gui_mch_set_footer(s) |
| 2665 | char_u *s; |
| 2666 | { |
| 2667 | XmString xms; |
| 2668 | |
| 2669 | xms = XmStringCreate((char *)s, STRING_TAG); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2670 | if (xms != NULL) |
| 2671 | { |
| 2672 | XtVaSetValues(footer, XmNlabelString, xms, NULL); |
| 2673 | XmStringFree(xms); |
| 2674 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | #endif |
| 2678 | |
| 2679 | |
| 2680 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 2681 | void |
| 2682 | gui_mch_show_toolbar(int showit) |
| 2683 | { |
| 2684 | Cardinal numChildren; /* how many children toolBar has */ |
| 2685 | |
| 2686 | if (toolBar == (Widget)0) |
| 2687 | return; |
| 2688 | XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL); |
| 2689 | if (showit && numChildren > 0) |
| 2690 | { |
| 2691 | /* Assume that we want to show the toolbar if p_toolbar contains |
| 2692 | * valid option settings, therefore p_toolbar must not be NULL. |
| 2693 | */ |
| 2694 | WidgetList children; |
| 2695 | |
| 2696 | XtVaGetValues(toolBar, XmNchildren, &children, NULL); |
| 2697 | { |
| 2698 | void (*action)(BalloonEval *); |
| 2699 | int text = 0; |
| 2700 | |
| 2701 | if (strstr((const char *)p_toolbar, "tooltips")) |
| 2702 | action = &gui_mch_enable_beval_area; |
| 2703 | else |
| 2704 | action = &gui_mch_disable_beval_area; |
| 2705 | if (strstr((const char *)p_toolbar, "text")) |
| 2706 | text = 1; |
| 2707 | else if (strstr((const char *)p_toolbar, "icons")) |
| 2708 | text = -1; |
| 2709 | if (text != 0) |
| 2710 | { |
| 2711 | vimmenu_T *toolbar; |
| 2712 | vimmenu_T *cur; |
| 2713 | |
| 2714 | for (toolbar = root_menu; toolbar; toolbar = toolbar->next) |
| 2715 | if (menu_is_toolbar(toolbar->dname)) |
| 2716 | break; |
| 2717 | /* Assumption: toolbar is NULL if there is no toolbar, |
| 2718 | * otherwise it contains the toolbar menu structure. |
| 2719 | * |
| 2720 | * Assumption: "numChildren" == the number of items in the list |
| 2721 | * of items beginning with toolbar->children. |
| 2722 | */ |
| 2723 | if (toolbar) |
| 2724 | { |
| 2725 | for (cur = toolbar->children; cur; cur = cur->next) |
| 2726 | { |
| 2727 | Arg args[1]; |
| 2728 | int n = 0; |
| 2729 | |
| 2730 | /* Enable/Disable tooltip (OK to enable while |
| 2731 | * currently enabled) |
| 2732 | */ |
| 2733 | if (cur->tip != NULL) |
| 2734 | (*action)(cur->tip); |
| 2735 | if (!menu_is_separator(cur->name)) |
| 2736 | { |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2737 | if (text == 1 || cur->xpm == NULL) |
| 2738 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2739 | XtSetArg(args[n], XmNlabelType, XmSTRING); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2740 | ++n; |
| 2741 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2742 | if (cur->id != NULL) |
| 2743 | { |
| 2744 | XtUnmanageChild(cur->id); |
| 2745 | XtSetValues(cur->id, args, n); |
| 2746 | XtManageChild(cur->id); |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | gui.toolbar_height = gui_mch_compute_toolbar_height(); |
| 2754 | XtManageChild(XtParent(toolBar)); |
| 2755 | XtVaSetValues(textAreaForm, |
| 2756 | XmNtopAttachment, XmATTACH_WIDGET, |
| 2757 | XmNtopWidget, XtParent(toolBar), |
| 2758 | NULL); |
| 2759 | if (XtIsManaged(menuBar)) |
| 2760 | XtVaSetValues(XtParent(toolBar), |
| 2761 | XmNtopAttachment, XmATTACH_WIDGET, |
| 2762 | XmNtopWidget, menuBar, |
| 2763 | NULL); |
| 2764 | else |
| 2765 | XtVaSetValues(XtParent(toolBar), |
| 2766 | XmNtopAttachment, XmATTACH_FORM, |
| 2767 | NULL); |
| 2768 | } |
| 2769 | else |
| 2770 | { |
| 2771 | gui.toolbar_height = 0; |
| 2772 | if (XtIsManaged(menuBar)) |
| 2773 | XtVaSetValues(textAreaForm, |
| 2774 | XmNtopAttachment, XmATTACH_WIDGET, |
| 2775 | XmNtopWidget, menuBar, |
| 2776 | NULL); |
| 2777 | else |
| 2778 | XtVaSetValues(textAreaForm, |
| 2779 | XmNtopAttachment, XmATTACH_FORM, |
| 2780 | NULL); |
| 2781 | |
| 2782 | XtUnmanageChild(XtParent(toolBar)); |
| 2783 | } |
| 2784 | gui_set_shellsize(FALSE, FALSE); |
| 2785 | } |
| 2786 | |
| 2787 | /* |
| 2788 | * A toolbar button has been pushed; now reset the input focus |
| 2789 | * such that the user can type page up/down etc. and have the |
| 2790 | * input go to the editor window, not the button |
| 2791 | */ |
| 2792 | static void |
Bram Moolenaar | f9980f1 | 2005-01-03 20:58:59 +0000 | [diff] [blame] | 2793 | reset_focus() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2794 | { |
| 2795 | if (textArea != NULL) |
| 2796 | XmProcessTraversal(textArea, XmTRAVERSE_CURRENT); |
| 2797 | } |
| 2798 | |
| 2799 | int |
| 2800 | gui_mch_compute_toolbar_height() |
| 2801 | { |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2802 | Dimension borders; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2803 | Dimension height; /* total Toolbar height */ |
| 2804 | Dimension whgt; /* height of each widget */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2805 | WidgetList children; /* list of toolBar's children */ |
| 2806 | Cardinal numChildren; /* how many children toolBar has */ |
| 2807 | int i; |
| 2808 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2809 | borders = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2810 | height = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2811 | if (toolBar != (Widget)0 && toolBarFrame != (Widget)0) |
| 2812 | { /* get height of XmFrame parent */ |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2813 | Dimension fst; |
| 2814 | Dimension fmh; |
| 2815 | Dimension tst; |
| 2816 | Dimension tmh; |
| 2817 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2818 | XtVaGetValues(toolBarFrame, |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2819 | XmNshadowThickness, &fst, |
| 2820 | XmNmarginHeight, &fmh, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2821 | NULL); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2822 | borders += fst + fmh; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2823 | XtVaGetValues(toolBar, |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2824 | XmNshadowThickness, &tst, |
| 2825 | XmNmarginHeight, &tmh, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2826 | XmNchildren, &children, |
| 2827 | XmNnumChildren, &numChildren, NULL); |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2828 | borders += tst + tmh; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2829 | for (i = 0; i < numChildren; i++) |
| 2830 | { |
| 2831 | whgt = 0; |
| 2832 | XtVaGetValues(children[i], XmNheight, &whgt, NULL); |
| 2833 | if (height < whgt) |
| 2834 | height = whgt; |
| 2835 | } |
| 2836 | } |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2837 | #ifdef LESSTIF_VERSION |
| 2838 | /* Hack: When starting up we get wrong dimensions. */ |
| 2839 | if (height < 10) |
| 2840 | height = 24; |
| 2841 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2842 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 2843 | return (int)(height + (borders << 1)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2846 | # ifdef FEAT_FOOTER |
| 2847 | /* |
| 2848 | * The next toolbar enter/leave callbacks should really do balloon help. But |
| 2849 | * I have to use footer help for backwards compatability. Hopefully both will |
| 2850 | * get implemented and the user will have a choice. |
| 2851 | */ |
| 2852 | /*ARGSUSED*/ |
| 2853 | static void |
| 2854 | toolbarbutton_enter_cb(w, client_data, event, cont) |
| 2855 | Widget w; |
| 2856 | XtPointer client_data; |
| 2857 | XEvent *event; |
| 2858 | Boolean *cont; |
| 2859 | { |
| 2860 | vimmenu_T *menu = (vimmenu_T *) client_data; |
| 2861 | |
| 2862 | if (menu->strings[MENU_INDEX_TIP] != NULL) |
| 2863 | { |
| 2864 | if (vim_strchr(p_go, GO_FOOTER) != NULL) |
| 2865 | gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | /*ARGSUSED*/ |
| 2870 | static void |
| 2871 | toolbarbutton_leave_cb(w, client_data, event, cont) |
| 2872 | Widget w; |
| 2873 | XtPointer client_data; |
| 2874 | XEvent *event; |
| 2875 | Boolean *cont; |
| 2876 | { |
| 2877 | gui_mch_set_footer((char_u *) ""); |
| 2878 | } |
| 2879 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2880 | #endif |
| 2881 | |
| 2882 | /* |
| 2883 | * Set the colors of Widget "id" to the menu colors. |
| 2884 | */ |
| 2885 | static void |
| 2886 | gui_motif_menu_colors(id) |
| 2887 | Widget id; |
| 2888 | { |
| 2889 | if (gui.menu_bg_pixel != INVALCOLOR) |
| 2890 | #if (XmVersion >= 1002) |
| 2891 | XmChangeColor(id, gui.menu_bg_pixel); |
| 2892 | #else |
| 2893 | XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL); |
| 2894 | #endif |
| 2895 | if (gui.menu_fg_pixel != INVALCOLOR) |
| 2896 | XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL); |
| 2897 | } |
| 2898 | |
| 2899 | /* |
| 2900 | * Set the colors of Widget "id" to the scrollbar colors. |
| 2901 | */ |
| 2902 | static void |
| 2903 | gui_motif_scroll_colors(id) |
| 2904 | Widget id; |
| 2905 | { |
| 2906 | if (gui.scroll_bg_pixel != INVALCOLOR) |
| 2907 | #if (XmVersion >= 1002) |
| 2908 | XmChangeColor(id, gui.scroll_bg_pixel); |
| 2909 | #else |
| 2910 | XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL); |
| 2911 | #endif |
| 2912 | if (gui.scroll_fg_pixel != INVALCOLOR) |
| 2913 | XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL); |
| 2914 | } |
| 2915 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2916 | /* |
| 2917 | * Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font. |
| 2918 | */ |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2919 | /*ARGSUSED*/ |
| 2920 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2921 | gui_motif_menu_fontlist(id) |
| 2922 | Widget id; |
| 2923 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2924 | #ifdef FEAT_MENU |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2925 | #ifdef FONTSET_ALWAYS |
| 2926 | if (gui.menu_fontset != NOFONTSET) |
| 2927 | { |
| 2928 | XmFontList fl; |
| 2929 | |
| 2930 | fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset); |
| 2931 | if (fl != NULL) |
| 2932 | { |
| 2933 | if (XtIsManaged(id)) |
| 2934 | { |
| 2935 | XtUnmanageChild(id); |
| 2936 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 2937 | /* We should force the widget to recalculate it's |
| 2938 | * geometry now. */ |
| 2939 | XtManageChild(id); |
| 2940 | } |
| 2941 | else |
| 2942 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 2943 | XmFontListFree(fl); |
| 2944 | } |
| 2945 | } |
| 2946 | #else |
| 2947 | if (gui.menu_font != NOFONT) |
| 2948 | { |
| 2949 | XmFontList fl; |
| 2950 | |
| 2951 | fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font); |
| 2952 | if (fl != NULL) |
| 2953 | { |
| 2954 | if (XtIsManaged(id)) |
| 2955 | { |
| 2956 | XtUnmanageChild(id); |
| 2957 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 2958 | /* We should force the widget to recalculate it's |
| 2959 | * geometry now. */ |
| 2960 | XtManageChild(id); |
| 2961 | } |
| 2962 | else |
| 2963 | XtVaSetValues(id, XmNfontList, fl, NULL); |
| 2964 | XmFontListFree(fl); |
| 2965 | } |
| 2966 | } |
| 2967 | #endif |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 2968 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2971 | |
| 2972 | /* |
| 2973 | * We don't create it twice for the sake of speed. |
| 2974 | */ |
| 2975 | |
| 2976 | typedef struct _SharedFindReplace |
| 2977 | { |
| 2978 | Widget dialog; /* the main dialog widget */ |
| 2979 | Widget wword; /* 'Exact match' check button */ |
| 2980 | Widget mcase; /* 'match case' check button */ |
| 2981 | Widget up; /* search direction 'Up' radio button */ |
| 2982 | Widget down; /* search direction 'Down' radio button */ |
| 2983 | Widget what; /* 'Find what' entry text widget */ |
| 2984 | Widget with; /* 'Replace with' entry text widget */ |
| 2985 | Widget find; /* 'Find Next' action button */ |
| 2986 | Widget replace; /* 'Replace With' action button */ |
| 2987 | Widget all; /* 'Replace All' action button */ |
| 2988 | Widget undo; /* 'Undo' action button */ |
| 2989 | |
| 2990 | Widget cancel; |
| 2991 | } SharedFindReplace; |
| 2992 | |
| 2993 | static SharedFindReplace find_widgets = { NULL }; |
| 2994 | static SharedFindReplace repl_widgets = { NULL }; |
| 2995 | |
| 2996 | static void find_replace_destroy_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data)); |
| 2997 | static void find_replace_dismiss_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data)); |
| 2998 | static void entry_activate_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data)); |
| 2999 | static void find_replace_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data)); |
| 3000 | static void find_replace_keypress __ARGS((Widget w, SharedFindReplace * frdp, XKeyEvent * event)); |
| 3001 | static void find_replace_dialog_create __ARGS((char_u *entry_text, int do_replace)); |
| 3002 | |
| 3003 | /*ARGSUSED*/ |
| 3004 | static void |
| 3005 | find_replace_destroy_callback(w, client_data, call_data) |
| 3006 | Widget w; |
| 3007 | XtPointer client_data; |
| 3008 | XtPointer call_data; |
| 3009 | { |
| 3010 | SharedFindReplace *cd = (SharedFindReplace *)client_data; |
| 3011 | |
Bram Moolenaar | b7fcef5 | 2005-01-02 11:31:05 +0000 | [diff] [blame] | 3012 | if (cd != NULL) |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3013 | /* suppress_dialog_mnemonics(cd->dialog); */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3014 | cd->dialog = (Widget)0; |
| 3015 | } |
| 3016 | |
| 3017 | /*ARGSUSED*/ |
| 3018 | static void |
| 3019 | find_replace_dismiss_callback(w, client_data, call_data) |
| 3020 | Widget w; |
| 3021 | XtPointer client_data; |
| 3022 | XtPointer call_data; |
| 3023 | { |
| 3024 | SharedFindReplace *cd = (SharedFindReplace *)client_data; |
| 3025 | |
| 3026 | if (cd != NULL) |
| 3027 | XtUnmanageChild(cd->dialog); |
| 3028 | } |
| 3029 | |
| 3030 | /*ARGSUSED*/ |
| 3031 | static void |
| 3032 | entry_activate_callback(w, client_data, call_data) |
| 3033 | Widget w; |
| 3034 | XtPointer client_data; |
| 3035 | XtPointer call_data; |
| 3036 | { |
| 3037 | XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT); |
| 3038 | } |
| 3039 | |
| 3040 | /*ARGSUSED*/ |
| 3041 | static void |
| 3042 | find_replace_callback(w, client_data, call_data) |
| 3043 | Widget w; |
| 3044 | XtPointer client_data; |
| 3045 | XtPointer call_data; |
| 3046 | { |
| 3047 | long_u flags = (long_u)client_data; |
| 3048 | char *find_text, *repl_text; |
| 3049 | Boolean direction_down = TRUE; |
| 3050 | Boolean wword; |
| 3051 | Boolean mcase; |
| 3052 | SharedFindReplace *sfr; |
| 3053 | |
| 3054 | if (flags == FRD_UNDO) |
| 3055 | { |
| 3056 | char_u *save_cpo = p_cpo; |
| 3057 | |
| 3058 | /* No need to be Vi compatible here. */ |
| 3059 | p_cpo = (char_u *)""; |
| 3060 | u_undo(1); |
| 3061 | p_cpo = save_cpo; |
| 3062 | gui_update_screen(); |
| 3063 | return; |
| 3064 | } |
| 3065 | |
| 3066 | /* Get the search/replace strings from the dialog */ |
| 3067 | if (flags == FRD_FINDNEXT) |
| 3068 | { |
| 3069 | repl_text = NULL; |
| 3070 | sfr = &find_widgets; |
| 3071 | } |
| 3072 | else |
| 3073 | { |
| 3074 | repl_text = XmTextFieldGetString(repl_widgets.with); |
| 3075 | sfr = &repl_widgets; |
| 3076 | } |
| 3077 | find_text = XmTextFieldGetString(sfr->what); |
| 3078 | XtVaGetValues(sfr->down, XmNset, &direction_down, NULL); |
| 3079 | XtVaGetValues(sfr->wword, XmNset, &wword, NULL); |
| 3080 | XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL); |
| 3081 | if (wword) |
| 3082 | flags |= FRD_WHOLE_WORD; |
| 3083 | if (mcase) |
| 3084 | flags |= FRD_MATCH_CASE; |
| 3085 | |
| 3086 | (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, |
| 3087 | direction_down); |
| 3088 | |
| 3089 | if (find_text != NULL) |
| 3090 | XtFree(find_text); |
| 3091 | if (repl_text != NULL) |
| 3092 | XtFree(repl_text); |
| 3093 | } |
| 3094 | |
| 3095 | /*ARGSUSED*/ |
| 3096 | static void |
| 3097 | find_replace_keypress(w, frdp, event) |
| 3098 | Widget w; |
| 3099 | SharedFindReplace *frdp; |
| 3100 | XKeyEvent *event; |
| 3101 | { |
| 3102 | KeySym keysym; |
| 3103 | |
| 3104 | if (frdp == NULL) |
| 3105 | return; |
| 3106 | |
| 3107 | keysym = XLookupKeysym(event, 0); |
| 3108 | |
| 3109 | /* the scape key pops the whole dialog down */ |
| 3110 | if (keysym == XK_Escape) |
| 3111 | XtUnmanageChild(frdp->dialog); |
| 3112 | } |
| 3113 | |
| 3114 | static void |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3115 | set_label(w, label) |
| 3116 | Widget w; |
| 3117 | char_u *label; |
| 3118 | { |
| 3119 | XmString str; |
| 3120 | char_u *p, *next; |
| 3121 | KeySym mnemonic = NUL; |
| 3122 | |
| 3123 | if (!w) |
| 3124 | return; |
| 3125 | |
| 3126 | p = vim_strsave(label); |
| 3127 | if (p == NULL) |
| 3128 | return; |
| 3129 | for (next = p; *next; ++next) |
| 3130 | { |
| 3131 | if (*next == DLG_HOTKEY_CHAR) |
| 3132 | { |
| 3133 | int len = STRLEN(next); |
| 3134 | |
| 3135 | if (len > 0) |
| 3136 | { |
| 3137 | mch_memmove(next, next + 1, len); |
| 3138 | mnemonic = next[0]; |
| 3139 | } |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | str = XmStringCreateSimple((char *)p); |
| 3144 | vim_free(p); |
| 3145 | if (str) |
| 3146 | { |
| 3147 | XtVaSetValues(w, |
| 3148 | XmNlabelString, str, |
| 3149 | XmNmnemonic, mnemonic, |
| 3150 | NULL); |
| 3151 | XmStringFree(str); |
| 3152 | } |
| 3153 | gui_motif_menu_fontlist(w); |
| 3154 | } |
| 3155 | |
| 3156 | static void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3157 | find_replace_dialog_create(arg, do_replace) |
| 3158 | char_u *arg; |
| 3159 | int do_replace; |
| 3160 | { |
| 3161 | SharedFindReplace *frdp; |
| 3162 | Widget separator; |
| 3163 | Widget input_form; |
| 3164 | Widget button_form; |
| 3165 | Widget toggle_form; |
| 3166 | Widget frame; |
| 3167 | XmString str; |
| 3168 | int n; |
| 3169 | Arg args[6]; |
| 3170 | int wword = FALSE; |
| 3171 | int mcase = !p_ic; |
| 3172 | Dimension width; |
| 3173 | Dimension widest; |
| 3174 | char_u *entry_text; |
| 3175 | |
| 3176 | frdp = do_replace ? &repl_widgets : &find_widgets; |
| 3177 | |
| 3178 | /* Get the search string to use. */ |
| 3179 | entry_text = get_find_dialog_text(arg, &wword, &mcase); |
| 3180 | |
| 3181 | /* If the dialog already exists, just raise it. */ |
| 3182 | if (frdp->dialog) |
| 3183 | { |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3184 | gui_motif_synch_fonts(); |
| 3185 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3186 | /* If the window is already up, just pop it to the top */ |
| 3187 | if (XtIsManaged(frdp->dialog)) |
| 3188 | XMapRaised(XtDisplay(frdp->dialog), |
| 3189 | XtWindow(XtParent(frdp->dialog))); |
| 3190 | else |
| 3191 | XtManageChild(frdp->dialog); |
| 3192 | XtPopup(XtParent(frdp->dialog), XtGrabNone); |
| 3193 | XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT); |
| 3194 | |
| 3195 | if (entry_text != NULL) |
| 3196 | XmTextFieldSetString(frdp->what, (char *)entry_text); |
| 3197 | vim_free(entry_text); |
| 3198 | |
| 3199 | XtVaSetValues(frdp->wword, XmNset, wword, NULL); |
| 3200 | return; |
| 3201 | } |
| 3202 | |
| 3203 | /* Create a fresh new dialog window */ |
| 3204 | if (do_replace) |
| 3205 | str = XmStringCreateSimple(_("VIM - Search and Replace...")); |
| 3206 | else |
| 3207 | str = XmStringCreateSimple(_("VIM - Search...")); |
| 3208 | |
| 3209 | n = 0; |
| 3210 | XtSetArg(args[n], XmNautoUnmanage, False); n++; |
| 3211 | XtSetArg(args[n], XmNnoResize, True); n++; |
| 3212 | XtSetArg(args[n], XmNdialogTitle, str); n++; |
| 3213 | |
| 3214 | frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n); |
| 3215 | XmStringFree(str); |
| 3216 | XtAddCallback(frdp->dialog, XmNdestroyCallback, |
| 3217 | find_replace_destroy_callback, frdp); |
| 3218 | |
| 3219 | button_form = XtVaCreateWidget("buttonForm", |
| 3220 | xmFormWidgetClass, frdp->dialog, |
| 3221 | XmNrightAttachment, XmATTACH_FORM, |
| 3222 | XmNrightOffset, 4, |
| 3223 | XmNtopAttachment, XmATTACH_FORM, |
| 3224 | XmNtopOffset, 4, |
| 3225 | XmNbottomAttachment, XmATTACH_FORM, |
| 3226 | XmNbottomOffset, 4, |
| 3227 | NULL); |
| 3228 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3229 | frdp->find = XtVaCreateManagedWidget("findButton", |
| 3230 | xmPushButtonWidgetClass, button_form, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3231 | XmNsensitive, True, |
| 3232 | XmNtopAttachment, XmATTACH_FORM, |
| 3233 | XmNleftAttachment, XmATTACH_FORM, |
| 3234 | XmNrightAttachment, XmATTACH_FORM, |
| 3235 | NULL); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3236 | set_label(frdp->find, _("Find &Next")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3237 | |
| 3238 | XtAddCallback(frdp->find, XmNactivateCallback, |
| 3239 | find_replace_callback, |
| 3240 | (XtPointer) (do_replace ? FRD_R_FINDNEXT : FRD_FINDNEXT)); |
| 3241 | |
| 3242 | if (do_replace) |
| 3243 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3244 | frdp->replace = XtVaCreateManagedWidget("replaceButton", |
| 3245 | xmPushButtonWidgetClass, button_form, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3246 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3247 | XmNtopWidget, frdp->find, |
| 3248 | XmNleftAttachment, XmATTACH_FORM, |
| 3249 | XmNrightAttachment, XmATTACH_FORM, |
| 3250 | NULL); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3251 | set_label(frdp->replace, _("&Replace")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3252 | XtAddCallback(frdp->replace, XmNactivateCallback, |
| 3253 | find_replace_callback, (XtPointer)FRD_REPLACE); |
| 3254 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3255 | frdp->all = XtVaCreateManagedWidget("replaceAllButton", |
| 3256 | xmPushButtonWidgetClass, button_form, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3257 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3258 | XmNtopWidget, frdp->replace, |
| 3259 | XmNleftAttachment, XmATTACH_FORM, |
| 3260 | XmNrightAttachment, XmATTACH_FORM, |
| 3261 | NULL); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3262 | set_label(frdp->all, _("Replace &All")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3263 | XtAddCallback(frdp->all, XmNactivateCallback, |
| 3264 | find_replace_callback, (XtPointer)FRD_REPLACEALL); |
| 3265 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3266 | frdp->undo = XtVaCreateManagedWidget("undoButton", |
| 3267 | xmPushButtonWidgetClass, button_form, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3268 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3269 | XmNtopWidget, frdp->all, |
| 3270 | XmNleftAttachment, XmATTACH_FORM, |
| 3271 | XmNrightAttachment, XmATTACH_FORM, |
| 3272 | NULL); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3273 | set_label(frdp->undo, _("&Undo")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3274 | XtAddCallback(frdp->undo, XmNactivateCallback, |
| 3275 | find_replace_callback, (XtPointer)FRD_UNDO); |
| 3276 | } |
| 3277 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3278 | frdp->cancel = XtVaCreateManagedWidget("closeButton", |
| 3279 | xmPushButtonWidgetClass, button_form, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3280 | XmNleftAttachment, XmATTACH_FORM, |
| 3281 | XmNrightAttachment, XmATTACH_FORM, |
| 3282 | XmNbottomAttachment, XmATTACH_FORM, |
| 3283 | NULL); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3284 | set_label(frdp->cancel, _("&Cancel")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3285 | XtAddCallback(frdp->cancel, XmNactivateCallback, |
| 3286 | find_replace_dismiss_callback, frdp); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3287 | gui_motif_menu_fontlist(frdp->cancel); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3288 | |
| 3289 | XtManageChild(button_form); |
| 3290 | |
| 3291 | n = 0; |
| 3292 | XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; |
| 3293 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++; |
| 3294 | XtSetArg(args[n], XmNrightWidget, button_form); n++; |
| 3295 | XtSetArg(args[n], XmNrightOffset, 4); n++; |
| 3296 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 3297 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 3298 | separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n); |
| 3299 | XtManageChild(separator); |
| 3300 | |
| 3301 | input_form = XtVaCreateWidget("inputForm", |
| 3302 | xmFormWidgetClass, frdp->dialog, |
| 3303 | XmNleftAttachment, XmATTACH_FORM, |
| 3304 | XmNleftOffset, 4, |
| 3305 | XmNrightAttachment, XmATTACH_WIDGET, |
| 3306 | XmNrightWidget, separator, |
| 3307 | XmNrightOffset, 4, |
| 3308 | XmNtopAttachment, XmATTACH_FORM, |
| 3309 | XmNtopOffset, 4, |
| 3310 | NULL); |
| 3311 | |
| 3312 | { |
| 3313 | Widget label_what; |
| 3314 | Widget label_with = (Widget)0; |
| 3315 | |
| 3316 | str = XmStringCreateSimple(_("Find what:")); |
| 3317 | label_what = XtVaCreateManagedWidget("whatLabel", |
| 3318 | xmLabelGadgetClass, input_form, |
| 3319 | XmNlabelString, str, |
| 3320 | XmNleftAttachment, XmATTACH_FORM, |
| 3321 | XmNtopAttachment, XmATTACH_FORM, |
| 3322 | XmNtopOffset, 4, |
| 3323 | NULL); |
| 3324 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3325 | gui_motif_menu_fontlist(label_what); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3326 | |
| 3327 | frdp->what = XtVaCreateManagedWidget("whatText", |
| 3328 | xmTextFieldWidgetClass, input_form, |
| 3329 | XmNtopAttachment, XmATTACH_FORM, |
| 3330 | XmNrightAttachment, XmATTACH_FORM, |
| 3331 | XmNleftAttachment, XmATTACH_FORM, |
| 3332 | NULL); |
| 3333 | |
| 3334 | if (do_replace) |
| 3335 | { |
| 3336 | frdp->with = XtVaCreateManagedWidget("withText", |
| 3337 | xmTextFieldWidgetClass, input_form, |
| 3338 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3339 | XmNtopWidget, frdp->what, |
| 3340 | XmNtopOffset, 4, |
| 3341 | XmNleftAttachment, XmATTACH_FORM, |
| 3342 | XmNrightAttachment, XmATTACH_FORM, |
| 3343 | XmNbottomAttachment, XmATTACH_FORM, |
| 3344 | NULL); |
| 3345 | |
| 3346 | XtAddCallback(frdp->with, XmNactivateCallback, |
| 3347 | find_replace_callback, (XtPointer) FRD_R_FINDNEXT); |
| 3348 | |
| 3349 | str = XmStringCreateSimple(_("Replace with:")); |
| 3350 | label_with = XtVaCreateManagedWidget("withLabel", |
| 3351 | xmLabelGadgetClass, input_form, |
| 3352 | XmNlabelString, str, |
| 3353 | XmNleftAttachment, XmATTACH_FORM, |
| 3354 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3355 | XmNtopWidget, frdp->what, |
| 3356 | XmNtopOffset, 4, |
| 3357 | XmNbottomAttachment, XmATTACH_FORM, |
| 3358 | NULL); |
| 3359 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3360 | gui_motif_menu_fontlist(label_with); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3361 | |
| 3362 | /* |
| 3363 | * Make the entry activation only change the input focus onto the |
| 3364 | * with item. |
| 3365 | */ |
| 3366 | XtAddCallback(frdp->what, XmNactivateCallback, |
| 3367 | entry_activate_callback, frdp->with); |
| 3368 | XtAddEventHandler(frdp->with, KeyPressMask, False, |
| 3369 | (XtEventHandler)find_replace_keypress, |
| 3370 | (XtPointer) frdp); |
| 3371 | |
| 3372 | } |
| 3373 | else |
| 3374 | { |
| 3375 | /* |
| 3376 | * Make the entry activation do the search. |
| 3377 | */ |
| 3378 | XtAddCallback(frdp->what, XmNactivateCallback, |
| 3379 | find_replace_callback, (XtPointer)FRD_FINDNEXT); |
| 3380 | } |
| 3381 | XtAddEventHandler(frdp->what, KeyPressMask, False, |
| 3382 | (XtEventHandler)find_replace_keypress, |
| 3383 | (XtPointer)frdp); |
| 3384 | |
| 3385 | /* Get the maximum width between the label widgets and line them up. |
| 3386 | */ |
| 3387 | n = 0; |
| 3388 | XtSetArg(args[n], XmNwidth, &width); n++; |
| 3389 | XtGetValues(label_what, args, n); |
| 3390 | widest = width; |
| 3391 | if (do_replace) |
| 3392 | { |
| 3393 | XtGetValues(label_with, args, n); |
| 3394 | if (width > widest) |
| 3395 | widest = width; |
| 3396 | } |
| 3397 | |
| 3398 | XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL); |
| 3399 | if (do_replace) |
| 3400 | XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL); |
| 3401 | |
| 3402 | } |
| 3403 | |
| 3404 | XtManageChild(input_form); |
| 3405 | |
| 3406 | { |
| 3407 | Widget radio_box; |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3408 | Widget w; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3409 | |
| 3410 | frame = XtVaCreateWidget("directionFrame", |
| 3411 | xmFrameWidgetClass, frdp->dialog, |
| 3412 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3413 | XmNtopWidget, input_form, |
| 3414 | XmNtopOffset, 4, |
| 3415 | XmNbottomAttachment, XmATTACH_FORM, |
| 3416 | XmNbottomOffset, 4, |
| 3417 | XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET, |
| 3418 | XmNrightWidget, input_form, |
| 3419 | NULL); |
| 3420 | |
| 3421 | str = XmStringCreateSimple(_("Direction")); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3422 | w = XtVaCreateManagedWidget("directionFrameLabel", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3423 | xmLabelGadgetClass, frame, |
| 3424 | XmNlabelString, str, |
| 3425 | XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, |
| 3426 | XmNchildType, XmFRAME_TITLE_CHILD, |
| 3427 | NULL); |
| 3428 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3429 | gui_motif_menu_fontlist(w); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3430 | |
| 3431 | radio_box = XmCreateRadioBox(frame, "radioBox", |
| 3432 | (ArgList)NULL, 0); |
| 3433 | |
| 3434 | str = XmStringCreateSimple( _("Up")); |
| 3435 | frdp->up = XtVaCreateManagedWidget("upRadioButton", |
| 3436 | xmToggleButtonGadgetClass, radio_box, |
| 3437 | XmNlabelString, str, |
| 3438 | XmNset, False, |
| 3439 | NULL); |
| 3440 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3441 | gui_motif_menu_fontlist(frdp->up); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3442 | |
| 3443 | str = XmStringCreateSimple(_("Down")); |
| 3444 | frdp->down = XtVaCreateManagedWidget("downRadioButton", |
| 3445 | xmToggleButtonGadgetClass, radio_box, |
| 3446 | XmNlabelString, str, |
| 3447 | XmNset, True, |
| 3448 | NULL); |
| 3449 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3450 | gui_motif_menu_fontlist(frdp->down); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3451 | |
| 3452 | XtManageChild(radio_box); |
| 3453 | XtManageChild(frame); |
| 3454 | } |
| 3455 | |
| 3456 | toggle_form = XtVaCreateWidget("toggleForm", |
| 3457 | xmFormWidgetClass, frdp->dialog, |
| 3458 | XmNleftAttachment, XmATTACH_FORM, |
| 3459 | XmNleftOffset, 4, |
| 3460 | XmNrightAttachment, XmATTACH_WIDGET, |
| 3461 | XmNrightWidget, frame, |
| 3462 | XmNrightOffset, 4, |
| 3463 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3464 | XmNtopWidget, input_form, |
| 3465 | XmNtopOffset, 4, |
| 3466 | XmNbottomAttachment, XmATTACH_FORM, |
| 3467 | XmNbottomOffset, 4, |
| 3468 | NULL); |
| 3469 | |
| 3470 | str = XmStringCreateSimple(_("Match whole word only")); |
| 3471 | frdp->wword = XtVaCreateManagedWidget("wordToggle", |
| 3472 | xmToggleButtonGadgetClass, toggle_form, |
| 3473 | XmNlabelString, str, |
| 3474 | XmNtopAttachment, XmATTACH_FORM, |
| 3475 | XmNtopOffset, 4, |
| 3476 | XmNleftAttachment, XmATTACH_FORM, |
| 3477 | XmNleftOffset, 4, |
| 3478 | XmNset, wword, |
| 3479 | NULL); |
| 3480 | XmStringFree(str); |
| 3481 | |
| 3482 | str = XmStringCreateSimple(_("Match case")); |
| 3483 | frdp->mcase = XtVaCreateManagedWidget("caseToggle", |
| 3484 | xmToggleButtonGadgetClass, toggle_form, |
| 3485 | XmNlabelString, str, |
| 3486 | XmNleftAttachment, XmATTACH_FORM, |
| 3487 | XmNleftOffset, 4, |
| 3488 | XmNtopAttachment, XmATTACH_WIDGET, |
| 3489 | XmNtopWidget, frdp->wword, |
| 3490 | XmNtopOffset, 4, |
| 3491 | XmNset, mcase, |
| 3492 | NULL); |
| 3493 | XmStringFree(str); |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3494 | gui_motif_menu_fontlist(frdp->wword); |
| 3495 | gui_motif_menu_fontlist(frdp->mcase); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3496 | |
| 3497 | XtManageChild(toggle_form); |
| 3498 | |
| 3499 | if (entry_text != NULL) |
| 3500 | XmTextFieldSetString(frdp->what, (char *)entry_text); |
| 3501 | vim_free(entry_text); |
| 3502 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3503 | gui_motif_synch_fonts(); |
| 3504 | |
| 3505 | manage_centered(frdp->dialog); |
| 3506 | activate_dialog_mnemonics(frdp->dialog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3507 | XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT); |
| 3508 | } |
| 3509 | |
| 3510 | void |
| 3511 | gui_mch_find_dialog(eap) |
| 3512 | exarg_T *eap; |
| 3513 | { |
| 3514 | if (!gui.in_use) |
| 3515 | return; |
| 3516 | |
| 3517 | find_replace_dialog_create(eap->arg, FALSE); |
| 3518 | } |
| 3519 | |
| 3520 | |
| 3521 | void |
| 3522 | gui_mch_replace_dialog(eap) |
| 3523 | exarg_T *eap; |
| 3524 | { |
| 3525 | if (!gui.in_use) |
| 3526 | return; |
| 3527 | |
| 3528 | find_replace_dialog_create(eap->arg, TRUE); |
| 3529 | } |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 3530 | |
| 3531 | /* |
| 3532 | * Synchronize all gui elements, which are dependant upon the |
| 3533 | * main text font used. Those are in esp. the find/replace dialogs. |
| 3534 | * If you don't understand why this should be needed, please try to |
| 3535 | * search for "piê¶æ" in iso8859-2. |
| 3536 | */ |
| 3537 | void |
| 3538 | gui_motif_synch_fonts(void) |
| 3539 | { |
| 3540 | SharedFindReplace *frdp; |
| 3541 | int do_replace; |
| 3542 | XFontStruct *font; |
| 3543 | XmFontList font_list; |
| 3544 | |
| 3545 | /* FIXME: Unless we find out how to create a XmFontList from a XFontSet, |
| 3546 | * we just give up here on font synchronization. */ |
| 3547 | font = (XFontStruct *)gui.norm_font; |
| 3548 | if (font == NULL) |
| 3549 | return; |
| 3550 | |
| 3551 | font_list = gui_motif_create_fontlist(font); |
| 3552 | |
| 3553 | /* OK this loop is a bit tricky... */ |
| 3554 | for (do_replace = 0; do_replace <= 1; ++do_replace) |
| 3555 | { |
| 3556 | frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); |
| 3557 | if (frdp->dialog) |
| 3558 | { |
| 3559 | XtVaSetValues(frdp->what, XmNfontList, font_list, NULL); |
| 3560 | if (do_replace) |
| 3561 | XtVaSetValues(frdp->with, XmNfontList, font_list, NULL); |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | XmFontListFree(font_list); |
| 3566 | } |