blob: aad355bfa5b2a7daa3c432f618415b832fde32c7 [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 Moolenaar843ee412004-06-30 16:16:41 +0000164#if defined(RISCOS) || defined(HAVE_GTK2) || defined (FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165# define DRAW_ITALIC 0x08 /* draw italic text */
166#endif
167#define DRAW_CURSOR 0x10 /* drawing block cursor (win32) */
168
169/* For our own tearoff menu item */
170#define TEAR_STRING "-->Detach"
171#define TEAR_LEN (9) /* length of above string */
172
173/* for the toolbar */
174#ifdef FEAT_GUI_W16
175# define TOOLBAR_BUTTON_HEIGHT 15
176# define TOOLBAR_BUTTON_WIDTH 16
177#else
178# define TOOLBAR_BUTTON_HEIGHT 18
179# define TOOLBAR_BUTTON_WIDTH 18
180#endif
181#define TOOLBAR_BORDER_HEIGHT 12 /* room above+below buttons for MSWindows */
182
Bram Moolenaar843ee412004-06-30 16:16:41 +0000183#if defined(NO_CONSOLE) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184# define NO_CONSOLE_INPUT /* use no_console_input() to check if there
185 is no console input possible */
186#endif
187
188typedef struct GuiScrollbar
189{
190 long ident; /* Unique identifier for each scrollbar */
191 struct window *wp; /* Scrollbar's window, NULL for bottom */
192 int type; /* one of SBAR_{LEFT,RIGHT,BOTTOM} */
193 long value; /* Represents top line number visible */
194#ifdef FEAT_GUI_ATHENA
195 int pixval; /* pixel count of value */
196#endif
197 long size; /* Size of scrollbar thumb */
198 long max; /* Number of lines in buffer */
199
200 /* Values measured in characters: */
201 int top; /* Top of scroll bar (chars from row 0) */
202 int height; /* Current height of scroll bar in rows */
203#ifdef FEAT_VERTSPLIT
204 int width; /* Current width of scroll bar in cols */
205#endif
206 int status_height; /* Height of status line */
Bram Moolenaar843ee412004-06-30 16:16:41 +0000207#ifdef FEAT_GUI_KDE
208 QScrollBar *w;
209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210#ifdef FEAT_GUI_X11
211 Widget id; /* Id of real scroll bar */
212#endif
213#ifdef FEAT_GUI_GTK
214 GtkWidget *id; /* Id of real scroll bar */
215 unsigned long handler_id; /* Id of "value_changed" signal handler */
216#endif
217
218#ifdef FEAT_GUI_MSWIN
219 HWND id; /* Id of real scroll bar */
220 int scroll_shift; /* The scrollbar stuff can handle only up to
221 32767 lines. When the file is longer,
222 scroll_shift is set to the number of shifts
223 to reduce the count. */
224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225#ifdef FEAT_GUI_MAC
226 ControlHandle id; /* A handle to the scrollbar */
227#endif
228#ifdef RISCOS
229 int id; /* Window handle of scrollbar window */
230#endif
231#ifdef FEAT_GUI_PHOTON
232 PtWidget_t *id;
233#endif
234} scrollbar_T;
235
236typedef long guicolor_T; /* handle for a GUI color; for X11 this should
237 be "Pixel", but that's an unsigned and we
238 need a signed value */
239#define INVALCOLOR (guicolor_T)-11111 /* number for invalid color; on 32 bit
240 displays there is a tiny chance this is an
241 actual color */
242
Bram Moolenaar843ee412004-06-30 16:16:41 +0000243#ifdef FEAT_GUI_KDE
244 typedef QFont *GuiFont;
245 typedef QFont *GuiFontset;
246# define NOFONT (GuiFont)NULL
247# define NOFONTSET (GuiFontset)NULL
248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249#ifdef FEAT_GUI_GTK
250# ifdef HAVE_GTK2
251 typedef PangoFontDescription *GuiFont; /* handle for a GUI font */
252 typedef PangoFontDescription *GuiFontset; /* handle for a GUI fontset */
253# else
254 typedef GdkFont *GuiFont; /* handle for a GUI font */
255 typedef GdkFont *GuiFontset; /* handle for a GUI fontset */
256# endif
257# define NOFONT (GuiFont)NULL
258# define NOFONTSET (GuiFontset)NULL
259#else
260# ifdef FEAT_GUI_PHOTON
261 typedef char *GuiFont;
262 typedef char *GuiFontset;
263# define NOFONT (GuiFont)NULL
264# define NOFONTSET (GuiFontset)NULL
265# else
266# ifdef FEAT_GUI_X11
267 typedef XFontStruct *GuiFont; /* handle for a GUI font */
268 typedef XFontSet GuiFontset; /* handle for a GUI fontset */
269# define NOFONT (GuiFont)0
270# define NOFONTSET (GuiFontset)0
271# else
Bram Moolenaar843ee412004-06-30 16:16:41 +0000272# if !defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273 typedef long_u GuiFont; /* handle for a GUI font */
274 typedef long_u GuiFontset; /* handle for a GUI fontset */
275# define NOFONT (GuiFont)0
276# define NOFONTSET (GuiFontset)0
Bram Moolenaar843ee412004-06-30 16:16:41 +0000277# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278# endif
279# endif
280#endif
281
282typedef struct Gui
283{
284 int in_focus; /* Vim has input focus */
285 int in_use; /* Is the GUI being used? */
286 int starting; /* GUI will start in a little while */
287 int shell_created; /* Has the shell been created yet? */
288 int dying; /* Is vim dying? Then output to terminal */
289 int dofork; /* Use fork() when GUI is starting */
290 int dragged_sb; /* Which scrollbar being dragged, if any? */
291 win_T *dragged_wp; /* Which WIN's sb being dragged, if any? */
292 int pointer_hidden; /* Is the mouse pointer hidden? */
293 int col; /* Current cursor column in GUI display */
294 int row; /* Current cursor row in GUI display */
295 int cursor_col; /* Physical cursor column in GUI display */
296 int cursor_row; /* Physical cursor row in GUI display */
297 char cursor_is_valid; /* There is a cursor at cursor_row/col */
298 int num_cols; /* Number of columns */
299 int num_rows; /* Number of rows */
300 int scroll_region_top; /* Top (first) line of scroll region */
301 int scroll_region_bot; /* Bottom (last) line of scroll region */
302 int scroll_region_left; /* Left (first) column of scroll region */
303 int scroll_region_right; /* Right (last) col. of scroll region */
304 int highlight_mask; /* Highlight attribute mask */
305 int scrollbar_width; /* Width of vertical scrollbars */
306 int scrollbar_height; /* Height of horizontal scrollbar */
307 int left_sbar_x; /* Calculated x coord for left scrollbar */
308 int right_sbar_x; /* Calculated x coord for right scrollbar */
309
310#ifdef FEAT_MENU
311# ifndef FEAT_GUI_GTK
312 int menu_height; /* Height of the menu bar */
313 int menu_width; /* Width of the menu bar */
314# endif
315 char menu_is_active; /* TRUE if menu is present */
316# ifdef FEAT_GUI_ATHENA
317 char menu_height_fixed; /* TRUE if menu height fixed */
318# endif
319#endif
320
321 scrollbar_T bottom_sbar; /* Bottom scrollbar */
322 int which_scrollbars[3];/* Which scrollbar boxes are active? */
323 int prev_wrap; /* For updating the horizontal scrollbar */
324 int char_width; /* Width of char in pixels */
325 int char_height; /* Height of char in pixels + 'linespace' */
326 int char_ascent; /* Ascent of char in pixels */
327 int border_width; /* Width of our border around text area */
328 int border_offset; /* Total pixel offset for all borders */
329
330 GuiFont norm_font; /* Normal font */
331#ifndef HAVE_GTK2
332 GuiFont bold_font; /* Bold font */
333 GuiFont ital_font; /* Italic font */
334 GuiFont boldital_font; /* Bold-Italic font */
335#else
336 int font_can_bold; /* Whether norm_font supports bold weight.
337 * The styled font variants are not used. */
338#endif
339
340#if defined(FEAT_MENU) && !defined(HAVE_GTK2)
341# ifdef FONTSET_ALWAYS
342 GuiFontset menu_fontset; /* set of fonts for multi-byte chars */
343# else
344 GuiFont menu_font; /* menu item font */
345# endif
346#endif
347#ifdef FEAT_MBYTE
348 GuiFont wide_font; /* 'guifontwide' font */
349#endif
350#ifdef FEAT_XFONTSET
351 GuiFontset fontset; /* set of fonts for multi-byte chars */
352#endif
353 guicolor_T back_pixel; /* Color of background */
354 guicolor_T norm_pixel; /* Color of normal text */
355 guicolor_T def_back_pixel; /* default Color of background */
356 guicolor_T def_norm_pixel; /* default Color of normal text */
357
358#ifdef FEAT_GUI_X11
359 char *rsrc_menu_fg_name; /* Color of menu and dialog foregound */
360 guicolor_T menu_fg_pixel; /* Same in Pixel format */
361 char *rsrc_menu_bg_name; /* Color of menu and dialog backgound */
362 guicolor_T menu_bg_pixel; /* Same in Pixel format */
363 char *rsrc_scroll_fg_name; /* Color of scrollbar foreground */
364 guicolor_T scroll_fg_pixel; /* Same in Pixel format */
365 char *rsrc_scroll_bg_name; /* Color of scrollbar background */
366 guicolor_T scroll_bg_pixel; /* Same in Pixel format */
367
368# ifdef FEAT_GUI_MOTIF
369 guicolor_T menu_def_fg_pixel; /* Default menu foreground */
370 guicolor_T menu_def_bg_pixel; /* Default menu background */
371 guicolor_T scroll_def_fg_pixel; /* Default scrollbar foreground */
372 guicolor_T scroll_def_bg_pixel; /* Default scrollbar background */
373# endif
374 Display *dpy; /* X display */
375 Window wid; /* Window id of text area */
376 int visibility; /* Is shell partially/fully obscured? */
377 GC text_gc;
378 GC back_gc;
379 GC invert_gc;
380 Cursor blank_pointer; /* Blank pointer */
381
382 /* X Resources */
383 char_u *rsrc_font_name; /* Resource font name, used if 'guifont'
384 not set */
385 char_u *rsrc_bold_font_name; /* Resource bold font name */
386 char_u *rsrc_ital_font_name; /* Resource italic font name */
387 char_u *rsrc_boldital_font_name; /* Resource bold-italic font name */
388 char_u *rsrc_menu_font_name; /* Resource menu Font name */
389 Bool rsrc_rev_video; /* Use reverse video? */
390
391 char_u *geom; /* Geometry, eg "80x24" */
392 Bool color_approx; /* Some color was approximated */
393#endif
394
Bram Moolenaar843ee412004-06-30 16:16:41 +0000395#ifdef FEAT_GUI_KDE
396 VimWidget *w; /* Vim widget */
397 Display *dpy; /* X display */
398 QFont *current_font;
399 char_u *fontname; /* font name from font selection dialog */
400#endif
401
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402#ifdef FEAT_GUI_GTK
403 int visibility; /* Is shell partially/fully obscured? */
404 GdkCursor *blank_pointer; /* Blank pointer */
405
406 /* X Resources */
407 char_u *geom; /* Geometry, eg "80x24" */
408
409 GtkWidget *mainwin; /* top level GTK window */
410 GtkWidget *formwin; /* manages all the windows below */
411 GtkWidget *drawarea; /* the "text" area */
412# ifdef FEAT_MENU
413 GtkWidget *menubar; /* menubar */
414# endif
415# ifdef FEAT_TOOLBAR
416 GtkWidget *toolbar; /* toolbar */
417# endif
418# ifdef FEAT_GUI_GNOME
419 GtkWidget *menubar_h; /* menubar handle */
420 GtkWidget *toolbar_h; /* toolbar handle */
421# endif
422 GdkColor *fgcolor; /* GDK-styled foreground color */
423 GdkColor *bgcolor; /* GDK-styled background color */
424# ifndef HAVE_GTK2
425 GuiFont current_font;
426# endif
427 GdkGC *text_gc; /* cached GC for normal text */
428# ifdef HAVE_GTK2
429 PangoContext *text_context; /* the context used for all text */
430 PangoFont *ascii_font; /* cached font for ASCII strings */
431 PangoGlyphString *ascii_glyphs; /* cached code point -> glyph map */
432# endif
433
434 GtkAccelGroup *accel_group;
435# ifndef HAVE_GTK2
436 GtkWidget *fontdlg; /* font selection dialog window */
437 char_u *fontname; /* font name from font selection dialog */
438# endif
439 GtkWidget *filedlg; /* file selection dialog */
440 char_u *browse_fname; /* file name from filedlg */
441#endif /* FEAT_GUI_GTK */
442
443#ifdef FEAT_FOOTER
444 int footer_height; /* height of the message footer */
445#endif
446
447#if defined(FEAT_TOOLBAR) \
448 && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF))
449 int toolbar_height; /* height of the toolbar */
450#endif
451
452#ifdef FEAT_BEVAL_TIP
453 /* Tooltip properties; also used for balloon evaluation */
454 char_u *rsrc_tooltip_font_name; /* tooltip font name */
455 char *rsrc_tooltip_fg_name; /* tooltip foreground color name */
456 char *rsrc_tooltip_bg_name; /* tooltip background color name */
457 guicolor_T tooltip_fg_pixel; /* tooltip foreground color */
458 guicolor_T tooltip_bg_pixel; /* tooltip background color */
459 XFontSet tooltip_fontset; /* tooltip fontset */
460#endif
461
462#ifdef FEAT_GUI_MSWIN
463 GuiFont currFont; /* Current font */
464 guicolor_T currFgColor; /* Current foreground text color */
465 guicolor_T currBgColor; /* Current background text color */
466#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
517}
518gui_win_pos_T;
519
Bram Moolenaar7171abe2004-10-11 10:06:20 +0000520#ifdef FIND_REPLACE_DIALOG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521/*
522 * Flags used to distinguish the different contexts in which the
523 * find/replace callback may be called.
524 */
525# define FRD_FINDNEXT 1 /* Find next in find dialog */
526# define FRD_R_FINDNEXT 2 /* Find next in repl dialog */
527# define FRD_REPLACE 3 /* Replace once */
528# define FRD_REPLACEALL 4 /* Replace remaining matches */
529# define FRD_UNDO 5 /* Undo replaced text */
530# define FRD_TYPE_MASK 7 /* Mask for the callback type */
531/* Flags which change the way searching is done. */
532# define FRD_WHOLE_WORD 0x08 /* match whole word only */
533# define FRD_MATCH_CASE 0x10 /* match case */
534#endif