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