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