1 /* vi:set ts=8 sts=4 sw=4: 2 * 3 * VIM - Vi IMproved by Bram Moolenaar 4 * 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 */ 9 10 /* For debugging */ 11 /* #define D(x) printf x; */ 12 #define D(x) 13 14 #if defined(FEAT_GUI_AMIGA) 15 # include <intuition/intuition.h> 16 #endif 17 18 #ifdef FEAT_GUI_MOTIF 19 # define FEAT_GUI_X11 20 # include <Xm/Xm.h> 21 #endif 22 23 #ifdef FEAT_GUI_ATHENA 24 # define FEAT_GUI_X11 25 # include <X11/Intrinsic.h> 26 # include <X11/StringDefs.h> 27 #endif 28 29 #ifdef FEAT_BEVAL 30 # include "gui_beval.h" 31 #endif 32 33 #ifdef FEAT_GUI_KDE 34 # include <X11/Intrinsic.h> 35 36 /* used only as pointer to, so casting to int is ok */ 37 # ifdef __cplusplus 38 class QScrollBar; 39 class QPopupMenu; 40 class QFont; 41 class VimWidget; 42 # else 43 # define QScrollBar int 44 # define QPopupMenu int 45 # define QFont int 46 # define VimWidget int 47 # endif 48 #endif 49 50 #ifdef FEAT_GUI_GTK 51 # include <X11/Intrinsic.h> 52 # include <gtk/gtk.h> 53 #endif 54 55 #ifdef FEAT_GUI_BEOS 56 # include "gui_beos.h" 57 #endif 58 59 #ifdef FEAT_GUI_MAC 60 # include <Types.h> 61 /*# include <Memory.h>*/ 62 # include <Quickdraw.h> 63 # include <Fonts.h> 64 # include <Events.h> 65 # include <Menus.h> 66 # if !(defined (TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON)) 67 # include <Windows.h> 68 # endif 69 # include <Controls.h> 70 /*# include <TextEdit.h>*/ 71 # include <Dialogs.h> 72 # include <OSUtils.h> 73 /* 74 # include <ToolUtils.h> 75 # include <SegLoad.h>*/ 76 #endif 77 78 #ifdef RISCOS 79 # include "gui_riscos.h" 80 #endif 81 82 #ifdef FEAT_GUI_PHOTON 83 # include <Ph.h> 84 # include <Pt.h> 85 # include "photon/PxProto.h" 86 #endif 87 88 /* 89 * On some systems, when we compile with the GUI, we always use it. On Mac 90 * there is no terminal version, and on Windows we can't figure out how to 91 * fork one off with :gui. 92 */ 93 #if defined(FEAT_GUI_MSWIN) || (defined(FEAT_GUI_MAC) && !defined(MACOS_X_UNIX)) 94 # define ALWAYS_USE_GUI 95 #endif 96 97 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) || defined(HAVE_GTK2) 98 # define USE_ON_FLY_SCROLL 99 #endif 100 101 /* 102 * GUIs that support dropping files on a running Vim. 103 */ 104 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) \ 105 || defined(FEAT_GUI_BEOS) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) 106 # define HAVE_DROP_FILE 107 #endif 108 109 /* 110 * This define makes menus always use a fontset. 111 * We're not sure if this code always works, thus it can be disabled. 112 */ 113 #ifdef FEAT_XFONTSET 114 # define FONTSET_ALWAYS 115 #endif 116 117 /* 118 * These macros convert between character row/column and pixel coordinates. 119 * TEXT_X - Convert character column into X pixel coord for drawing strings. 120 * TEXT_Y - Convert character row into Y pixel coord for drawing strings. 121 * FILL_X - Convert character column into X pixel coord for filling the area 122 * under the character. 123 * FILL_Y - Convert character row into Y pixel coord for filling the area 124 * under the character. 125 * X_2_COL - Convert X pixel coord into character column. 126 * Y_2_ROW - Convert Y pixel coord into character row. 127 */ 128 #ifdef FEAT_GUI_W32 129 # define TEXT_X(col) ((col) * gui.char_width) 130 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent) 131 # define FILL_X(col) ((col) * gui.char_width) 132 # define FILL_Y(row) ((row) * gui.char_height) 133 # define X_2_COL(x) ((x) / gui.char_width) 134 # define Y_2_ROW(y) ((y) / gui.char_height) 135 #else 136 # define TEXT_X(col) ((col) * gui.char_width + gui.border_offset) 137 # define FILL_X(col) ((col) * gui.char_width + gui.border_offset) 138 # define X_2_COL(x) (((x) - gui.border_offset) / gui.char_width) 139 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent \ 140 + gui.border_offset) 141 # define FILL_Y(row) ((row) * gui.char_height + gui.border_offset) 142 # define Y_2_ROW(y) (((y) - gui.border_offset) / gui.char_height) 143 #endif 144 145 /* Indices for arrays of scrollbars */ 146 #define SBAR_NONE -1 147 #define SBAR_LEFT 0 148 #define SBAR_RIGHT 1 149 #define SBAR_BOTTOM 2 150 151 /* Orientations for scrollbars */ 152 #define SBAR_VERT 0 153 #define SBAR_HORIZ 1 154 155 /* Default size of scrollbar */ 156 #define SB_DEFAULT_WIDTH 16 157 158 /* Default height of the menu bar */ 159 #define MENU_DEFAULT_HEIGHT 1 /* figure it out at runtime */ 160 161 /* Flags for gui_mch_outstr_nowrap() */ 162 #define GUI_MON_WRAP_CURSOR 0x01 /* wrap cursor at end of line */ 163 #define GUI_MON_INVERT 0x02 /* invert the characters */ 164 #define GUI_MON_IS_CURSOR 0x04 /* drawing cursor */ 165 #define GUI_MON_TRS_CURSOR 0x08 /* drawing transparent cursor */ 166 #define GUI_MON_NOCLEAR 0x10 /* don't clear selection */ 167 168 /* Flags for gui_mch_draw_string() */ 169 #define DRAW_TRANSP 0x01 /* draw with transparant bg */ 170 #define DRAW_BOLD 0x02 /* draw bold text */ 171 #define DRAW_UNDERL 0x04 /* draw underline text */ 172 #if defined(RISCOS) || defined(HAVE_GTK2) || defined (FEAT_GUI_KDE) 173 # define DRAW_ITALIC 0x08 /* draw italic text */ 174 #endif 175 #define DRAW_CURSOR 0x10 /* drawing block cursor (win32) */ 176 177 /* For our own tearoff menu item */ 178 #define TEAR_STRING "-->Detach" 179 #define TEAR_LEN (9) /* length of above string */ 180 181 /* for the toolbar */ 182 #ifdef FEAT_GUI_W16 183 # define TOOLBAR_BUTTON_HEIGHT 15 184 # define TOOLBAR_BUTTON_WIDTH 16 185 #else 186 # define TOOLBAR_BUTTON_HEIGHT 18 187 # define TOOLBAR_BUTTON_WIDTH 18 188 #endif 189 #define TOOLBAR_BORDER_HEIGHT 12 /* room above+below buttons for MSWindows */ 190 191 #if defined(NO_CONSOLE) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) || defined(FEAT_GUI_X11) 192 # define NO_CONSOLE_INPUT /* use no_console_input() to check if there 193 is no console input possible */ 194 #endif 195 196 typedef struct GuiScrollbar 197 { 198 long ident; /* Unique identifier for each scrollbar */ 199 struct window *wp; /* Scrollbar's window, NULL for bottom */ 200 int type; /* one of SBAR_{LEFT,RIGHT,BOTTOM} */ 201 long value; /* Represents top line number visible */ 202 #ifdef FEAT_GUI_ATHENA 203 int pixval; /* pixel count of value */ 204 #endif 205 long size; /* Size of scrollbar thumb */ 206 long max; /* Number of lines in buffer */ 207 208 /* Values measured in characters: */ 209 int top; /* Top of scroll bar (chars from row 0) */ 210 int height; /* Current height of scroll bar in rows */ 211 #ifdef FEAT_VERTSPLIT 212 int width; /* Current width of scroll bar in cols */ 213 #endif 214 int status_height; /* Height of status line */ 215 #ifdef FEAT_GUI_KDE 216 QScrollBar *w; 217 #endif 218 #ifdef FEAT_GUI_X11 219 Widget id; /* Id of real scroll bar */ 220 #endif 221 #ifdef FEAT_GUI_GTK 222 GtkWidget *id; /* Id of real scroll bar */ 223 unsigned long handler_id; /* Id of "value_changed" signal handler */ 224 #endif 225 226 #ifdef FEAT_GUI_MSWIN 227 HWND id; /* Id of real scroll bar */ 228 int scroll_shift; /* The scrollbar stuff can handle only up to 229 32767 lines. When the file is longer, 230 scroll_shift is set to the number of shifts 231 to reduce the count. */ 232 #endif 233 #if FEAT_GUI_BEOS 234 VimScrollBar *id; /* Pointer to real scroll bar */ 235 #endif 236 #ifdef FEAT_GUI_MAC 237 ControlHandle id; /* A handle to the scrollbar */ 238 #endif 239 #ifdef RISCOS 240 int id; /* Window handle of scrollbar window */ 241 #endif 242 #ifdef FEAT_GUI_PHOTON 243 PtWidget_t *id; 244 #endif 245 } scrollbar_T; 246 247 typedef long guicolor_T; /* handle for a GUI color; for X11 this should 248 be "Pixel", but that's an unsigned and we 249 need a signed value */ 250 #define INVALCOLOR (guicolor_T)-11111 /* number for invalid color; on 32 bit 251 displays there is a tiny chance this is an 252 actual color */ 253 254 #ifdef FEAT_GUI_KDE 255 typedef QFont *GuiFont; 256 typedef QFont *GuiFontset; 257 # define NOFONT (GuiFont)NULL 258 # define NOFONTSET (GuiFontset)NULL 259 #endif 260 #ifdef FEAT_GUI_GTK 261 # ifdef HAVE_GTK2 262 typedef PangoFontDescription *GuiFont; /* handle for a GUI font */ 263 typedef PangoFontDescription *GuiFontset; /* handle for a GUI fontset */ 264 # else 265 typedef GdkFont *GuiFont; /* handle for a GUI font */ 266 typedef GdkFont *GuiFontset; /* handle for a GUI fontset */ 267 # endif 268 # define NOFONT (GuiFont)NULL 269 # define NOFONTSET (GuiFontset)NULL 270 #else 271 # ifdef FEAT_GUI_PHOTON 272 typedef char *GuiFont; 273 typedef char *GuiFontset; 274 # define NOFONT (GuiFont)NULL 275 # define NOFONTSET (GuiFontset)NULL 276 # else 277 # ifdef FEAT_GUI_X11 278 typedef XFontStruct *GuiFont; /* handle for a GUI font */ 279 typedef XFontSet GuiFontset; /* handle for a GUI fontset */ 280 # define NOFONT (GuiFont)0 281 # define NOFONTSET (GuiFontset)0 282 # else 283 # if !defined(FEAT_GUI_KDE) 284 typedef long_u GuiFont; /* handle for a GUI font */ 285 typedef long_u GuiFontset; /* handle for a GUI fontset */ 286 # define NOFONT (GuiFont)0 287 # define NOFONTSET (GuiFontset)0 288 # endif 289 # endif 290 # endif 291 #endif 292 293 typedef struct Gui 294 { 295 int in_focus; /* Vim has input focus */ 296 int in_use; /* Is the GUI being used? */ 297 int starting; /* GUI will start in a little while */ 298 int shell_created; /* Has the shell been created yet? */ 299 int dying; /* Is vim dying? Then output to terminal */ 300 int dofork; /* Use fork() when GUI is starting */ 301 int dragged_sb; /* Which scrollbar being dragged, if any? */ 302 win_T *dragged_wp; /* Which WIN's sb being dragged, if any? */ 303 int pointer_hidden; /* Is the mouse pointer hidden? */ 304 int col; /* Current cursor column in GUI display */ 305 int row; /* Current cursor row in GUI display */ 306 int cursor_col; /* Physical cursor column in GUI display */ 307 int cursor_row; /* Physical cursor row in GUI display */ 308 char cursor_is_valid; /* There is a cursor at cursor_row/col */ 309 int num_cols; /* Number of columns */ 310 int num_rows; /* Number of rows */ 311 int scroll_region_top; /* Top (first) line of scroll region */ 312 int scroll_region_bot; /* Bottom (last) line of scroll region */ 313 int scroll_region_left; /* Left (first) column of scroll region */ 314 int scroll_region_right; /* Right (last) col. of scroll region */ 315 int highlight_mask; /* Highlight attribute mask */ 316 int scrollbar_width; /* Width of vertical scrollbars */ 317 int scrollbar_height; /* Height of horizontal scrollbar */ 318 int left_sbar_x; /* Calculated x coord for left scrollbar */ 319 int right_sbar_x; /* Calculated x coord for right scrollbar */ 320 321 #ifdef FEAT_MENU 322 # ifndef FEAT_GUI_GTK 323 int menu_height; /* Height of the menu bar */ 324 int menu_width; /* Width of the menu bar */ 325 # endif 326 char menu_is_active; /* TRUE if menu is present */ 327 # ifdef FEAT_GUI_ATHENA 328 char menu_height_fixed; /* TRUE if menu height fixed */ 329 # endif 330 #endif 331 332 scrollbar_T bottom_sbar; /* Bottom scrollbar */ 333 int which_scrollbars[3];/* Which scrollbar boxes are active? */ 334 int prev_wrap; /* For updating the horizontal scrollbar */ 335 int char_width; /* Width of char in pixels */ 336 int char_height; /* Height of char in pixels + 'linespace' */ 337 int char_ascent; /* Ascent of char in pixels */ 338 int border_width; /* Width of our border around text area */ 339 int border_offset; /* Total pixel offset for all borders */ 340 341 GuiFont norm_font; /* Normal font */ 342 #ifndef HAVE_GTK2 343 GuiFont bold_font; /* Bold font */ 344 GuiFont ital_font; /* Italic font */ 345 GuiFont boldital_font; /* Bold-Italic font */ 346 #else 347 int font_can_bold; /* Whether norm_font supports bold weight. 348 * The styled font variants are not used. */ 349 #endif 350 351 #if defined(FEAT_MENU) && !defined(HAVE_GTK2) 352 # ifdef FONTSET_ALWAYS 353 GuiFontset menu_fontset; /* set of fonts for multi-byte chars */ 354 # else 355 GuiFont menu_font; /* menu item font */ 356 # endif 357 #endif 358 #ifdef FEAT_MBYTE 359 GuiFont wide_font; /* 'guifontwide' font */ 360 #endif 361 #ifdef FEAT_XFONTSET 362 GuiFontset fontset; /* set of fonts for multi-byte chars */ 363 #endif 364 guicolor_T back_pixel; /* Color of background */ 365 guicolor_T norm_pixel; /* Color of normal text */ 366 guicolor_T def_back_pixel; /* default Color of background */ 367 guicolor_T def_norm_pixel; /* default Color of normal text */ 368 369 #ifdef FEAT_GUI_X11 370 char *rsrc_menu_fg_name; /* Color of menu and dialog foregound */ 371 guicolor_T menu_fg_pixel; /* Same in Pixel format */ 372 char *rsrc_menu_bg_name; /* Color of menu and dialog backgound */ 373 guicolor_T menu_bg_pixel; /* Same in Pixel format */ 374 char *rsrc_scroll_fg_name; /* Color of scrollbar foreground */ 375 guicolor_T scroll_fg_pixel; /* Same in Pixel format */ 376 char *rsrc_scroll_bg_name; /* Color of scrollbar background */ 377 guicolor_T scroll_bg_pixel; /* Same in Pixel format */ 378 379 # ifdef FEAT_GUI_MOTIF 380 guicolor_T menu_def_fg_pixel; /* Default menu foreground */ 381 guicolor_T menu_def_bg_pixel; /* Default menu background */ 382 guicolor_T scroll_def_fg_pixel; /* Default scrollbar foreground */ 383 guicolor_T scroll_def_bg_pixel; /* Default scrollbar background */ 384 # endif 385 Display *dpy; /* X display */ 386 Window wid; /* Window id of text area */ 387 int visibility; /* Is shell partially/fully obscured? */ 388 GC text_gc; 389 GC back_gc; 390 GC invert_gc; 391 Cursor blank_pointer; /* Blank pointer */ 392 393 /* X Resources */ 394 char_u *rsrc_font_name; /* Resource font name, used if 'guifont' 395 not set */ 396 char_u *rsrc_bold_font_name; /* Resource bold font name */ 397 char_u *rsrc_ital_font_name; /* Resource italic font name */ 398 char_u *rsrc_boldital_font_name; /* Resource bold-italic font name */ 399 char_u *rsrc_menu_font_name; /* Resource menu Font name */ 400 Bool rsrc_rev_video; /* Use reverse video? */ 401 402 char_u *geom; /* Geometry, eg "80x24" */ 403 Bool color_approx; /* Some color was approximated */ 404 #endif 405 406 #ifdef FEAT_GUI_KDE 407 VimWidget *w; /* Vim widget */ 408 Display *dpy; /* X display */ 409 QFont *current_font; 410 char_u *fontname; /* font name from font selection dialog */ 411 #endif 412 413 #ifdef FEAT_GUI_GTK 414 int visibility; /* Is shell partially/fully obscured? */ 415 GdkCursor *blank_pointer; /* Blank pointer */ 416 417 /* X Resources */ 418 char_u *geom; /* Geometry, eg "80x24" */ 419 420 GtkWidget *mainwin; /* top level GTK window */ 421 GtkWidget *formwin; /* manages all the windows below */ 422 GtkWidget *drawarea; /* the "text" area */ 423 # ifdef FEAT_MENU 424 GtkWidget *menubar; /* menubar */ 425 # endif 426 # ifdef FEAT_TOOLBAR 427 GtkWidget *toolbar; /* toolbar */ 428 # endif 429 # ifdef FEAT_GUI_GNOME 430 GtkWidget *menubar_h; /* menubar handle */ 431 GtkWidget *toolbar_h; /* toolbar handle */ 432 # endif 433 GdkColor *fgcolor; /* GDK-styled foreground color */ 434 GdkColor *bgcolor; /* GDK-styled background color */ 435 # ifndef HAVE_GTK2 436 GuiFont current_font; 437 # endif 438 GdkGC *text_gc; /* cached GC for normal text */ 439 # ifdef HAVE_GTK2 440 PangoContext *text_context; /* the context used for all text */ 441 PangoFont *ascii_font; /* cached font for ASCII strings */ 442 PangoGlyphString *ascii_glyphs; /* cached code point -> glyph map */ 443 # endif 444 445 GtkAccelGroup *accel_group; 446 # ifndef HAVE_GTK2 447 GtkWidget *fontdlg; /* font selection dialog window */ 448 char_u *fontname; /* font name from font selection dialog */ 449 # endif 450 GtkWidget *filedlg; /* file selection dialog */ 451 char_u *browse_fname; /* file name from filedlg */ 452 #endif /* FEAT_GUI_GTK */ 453 454 #ifdef FEAT_FOOTER 455 int footer_height; /* height of the message footer */ 456 #endif 457 458 #if defined(FEAT_TOOLBAR) \ 459 && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) 460 int toolbar_height; /* height of the toolbar */ 461 #endif 462 463 #ifdef FEAT_BEVAL_TIP 464 /* Tooltip properties; also used for balloon evaluation */ 465 char_u *rsrc_tooltip_font_name; /* tooltip font name */ 466 char *rsrc_tooltip_fg_name; /* tooltip foreground color name */ 467 char *rsrc_tooltip_bg_name; /* tooltip background color name */ 468 guicolor_T tooltip_fg_pixel; /* tooltip foreground color */ 469 guicolor_T tooltip_bg_pixel; /* tooltip background color */ 470 XFontSet tooltip_fontset; /* tooltip fontset */ 471 #endif 472 473 #ifdef FEAT_GUI_MSWIN 474 GuiFont currFont; /* Current font */ 475 guicolor_T currFgColor; /* Current foreground text color */ 476 guicolor_T currBgColor; /* Current background text color */ 477 #endif 478 479 #ifdef FEAT_GUI_BEOS 480 VimApp *vimApp; 481 VimWindow *vimWindow; 482 VimFormView *vimForm; 483 VimTextAreaView *vimTextArea; 484 int vdcmp; /* Vim Direct Communication Message Port */ 485 #endif 486 487 #ifdef FEAT_GUI_MAC 488 WindowPtr VimWindow; 489 MenuHandle MacOSHelpMenu; /* Help menu provided by the MacOS */ 490 int MacOSHelpItems; /* Nr of help-items supplied by MacOS */ 491 int MacOSHaveCntxMenu; /* Contextual menu available */ 492 WindowPtr wid; /* Window id of text area */ 493 int visibility; /* Is window partially/fully obscured? */ 494 #endif 495 496 #if defined(FEAT_GUI_AMIGA) 497 struct Window *window; /* a handle to the amiga window */ 498 struct Menu *menu; /* a pointer to the first menu */ 499 struct TextFont *textfont; /* a pointer to the font structure */ 500 #endif 501 502 #ifdef RISCOS 503 int window_handle; 504 char_u *window_title; 505 int window_title_size; 506 int fg_colour; /* in 0xBBGGRR format */ 507 int bg_colour; 508 #endif 509 510 #ifdef FEAT_GUI_PHOTON 511 PtWidget_t *vimWindow; /* PtWindow */ 512 PtWidget_t *vimTextArea; /* PtRaw */ 513 PtWidget_t *vimContainer; /* PtPanel */ 514 # if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) 515 PtWidget_t *vimToolBarGroup; 516 # endif 517 # ifdef FEAT_MENU 518 PtWidget_t *vimMenuBar; 519 # endif 520 # ifdef FEAT_TOOLBAR 521 PtWidget_t *vimToolBar; 522 int toolbar_height; 523 # endif 524 PhEvent_t *event_buffer; 525 #endif 526 527 #ifdef FEAT_XIM 528 char *rsrc_input_method; 529 char *rsrc_preedit_type_name; 530 #endif 531 } gui_T; 532 533 extern gui_T gui; /* this is defined in gui.c */ 534 535 /* definitions of available window positionings for gui_*_position_in_parent() 536 */ 537 typedef enum 538 { 539 VW_POS_MOUSE, 540 VW_POS_CENTER, 541 VW_POS_TOP_CENTER 542 } 543 gui_win_pos_T; 544 545 #ifdef FIND_REPLACE_DIALOG 546 /* 547 * Flags used to distinguish the different contexts in which the 548 * find/replace callback may be called. 549 */ 550 # define FRD_FINDNEXT 1 /* Find next in find dialog */ 551 # define FRD_R_FINDNEXT 2 /* Find next in repl dialog */ 552 # define FRD_REPLACE 3 /* Replace once */ 553 # define FRD_REPLACEALL 4 /* Replace remaining matches */ 554 # define FRD_UNDO 5 /* Undo replaced text */ 555 # define FRD_TYPE_MASK 7 /* Mask for the callback type */ 556 /* Flags which change the way searching is done. */ 557 # define FRD_WHOLE_WORD 0x08 /* match whole word only */ 558 # define FRD_MATCH_CASE 0x10 /* match case */ 559 #endif 560