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