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