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