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