1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Motif support by Robert Webb
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.
14 #ifdef FEAT_GUI_ATHENA
15 # include <X11/Intrinsic.h>
16 # include <X11/StringDefs.h>
20 # include "gui_beval.h"
24 # ifdef VMS /* undef MIN and MAX because Intrinsic.h redefines them anyway */
32 # include <X11/Intrinsic.h>
38 /*# include <Memory.h>*/
39 # include <Quickdraw.h>
43 # if !(defined (TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON))
46 # include <Controls.h>
47 /*# include <TextEdit.h>*/
51 # include <ToolUtils.h>
52 # include <SegLoad.h>*/
56 # include "gui_riscos.h"
59 #ifdef FEAT_GUI_PHOTON
62 # include "photon/PxProto.h"
66 * On some systems, when we compile with the GUI, we always use it. On Mac
67 * there is no terminal version, and on Windows we can't figure out how to
68 * fork one off with :gui.
70 #if defined(FEAT_GUI_MSWIN) || (defined(FEAT_GUI_MAC) && !defined(MACOS_X_UNIX))
71 # define ALWAYS_USE_GUI
75 * On some systems scrolling needs to be done right away instead of in the
78 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) || defined(HAVE_GTK2) \
79 || defined(FEAT_GUI_MACVIM)
80 # define USE_ON_FLY_SCROLL
84 * GUIs that support dropping files on a running Vim.
86 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) \
87 || defined(FEAT_GUI_GTK)
88 # define HAVE_DROP_FILE
92 * This define makes menus always use a fontset.
93 * We're not sure if this code always works, thus it can be disabled.
96 # define FONTSET_ALWAYS
100 * These macros convert between character row/column and pixel coordinates.
101 * TEXT_X - Convert character column into X pixel coord for drawing strings.
102 * TEXT_Y - Convert character row into Y pixel coord for drawing strings.
103 * FILL_X - Convert character column into X pixel coord for filling the area
104 * under the character.
105 * FILL_Y - Convert character row into Y pixel coord for filling the area
106 * under the character.
107 * X_2_COL - Convert X pixel coord into character column.
108 * Y_2_ROW - Convert Y pixel coord into character row.
111 # define TEXT_X(col) ((col) * gui.char_width)
112 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent)
113 # define FILL_X(col) ((col) * gui.char_width)
114 # define FILL_Y(row) ((row) * gui.char_height)
115 # define X_2_COL(x) ((x) / gui.char_width)
116 # define Y_2_ROW(y) ((y) / gui.char_height)
118 # define TEXT_X(col) ((col) * gui.char_width + gui.border_offset)
119 # define FILL_X(col) ((col) * gui.char_width + gui.border_offset)
120 # define X_2_COL(x) (((x) - gui.border_offset) / gui.char_width)
121 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent \
123 # define FILL_Y(row) ((row) * gui.char_height + gui.border_offset)
124 # define Y_2_ROW(y) (((y) - gui.border_offset) / gui.char_height)
127 /* Indices for arrays of scrollbars */
131 #define SBAR_BOTTOM 2
133 /* Orientations for scrollbars */
137 /* Default size of scrollbar */
138 #define SB_DEFAULT_WIDTH 16
140 /* Default height of the menu bar */
141 #define MENU_DEFAULT_HEIGHT 1 /* figure it out at runtime */
143 /* Flags for gui_mch_outstr_nowrap() */
144 #define GUI_MON_WRAP_CURSOR 0x01 /* wrap cursor at end of line */
145 #define GUI_MON_INVERT 0x02 /* invert the characters */
146 #define GUI_MON_IS_CURSOR 0x04 /* drawing cursor */
147 #define GUI_MON_TRS_CURSOR 0x08 /* drawing transparent cursor */
148 #define GUI_MON_NOCLEAR 0x10 /* don't clear selection */
150 /* Flags for gui_mch_draw_string() */
151 #define DRAW_TRANSP 0x01 /* draw with transparent bg */
152 #define DRAW_BOLD 0x02 /* draw bold text */
153 #define DRAW_UNDERL 0x04 /* draw underline text */
154 #define DRAW_UNDERC 0x08 /* draw undercurl text */
155 #if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
156 # define DRAW_ITALIC 0x10 /* draw italic text */
158 #define DRAW_CURSOR 0x20 /* drawing block cursor (win32) */
159 #define DRAW_WIDE 0x40 /* drawing wide char (MacVim) */
160 #define DRAW_COMP 0x80 /* drawing composing char (MacVim) */
162 /* For our own tearoff menu item */
163 #define TEAR_STRING "-->Detach"
164 #define TEAR_LEN (9) /* length of above string */
166 /* for the toolbar */
168 # define TOOLBAR_BUTTON_HEIGHT 15
169 # define TOOLBAR_BUTTON_WIDTH 16
171 # define TOOLBAR_BUTTON_HEIGHT 18
172 # define TOOLBAR_BUTTON_WIDTH 18
174 #define TOOLBAR_BORDER_HEIGHT 12 /* room above+below buttons for MSWindows */
176 #ifdef FEAT_GUI_MSWIN
177 # define TABLINE_HEIGHT 22
179 #ifdef FEAT_GUI_MOTIF
180 # define TABLINE_HEIGHT 30
183 #if defined(NO_CONSOLE) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
184 # define NO_CONSOLE_INPUT /* use no_console_input() to check if there
185 is no console input possible */
188 typedef struct GuiScrollbar
190 long ident
; /* Unique identifier for each scrollbar */
191 win_T
*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 */
197 long size
; /* Size of scrollbar thumb */
198 long max
; /* Number of lines in buffer */
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 */
206 int status_height
; /* Height of status line */
208 Widget id
; /* Id of real scroll bar */
211 GtkWidget
*id
; /* Id of real scroll bar */
212 unsigned long handler_id
; /* Id of "value_changed" signal handler */
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. */
223 ControlHandle id
; /* A handle to the scrollbar */
226 int id
; /* Window handle of scrollbar window */
228 #ifdef FEAT_GUI_PHOTON
233 typedef 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
240 #if defined(FEAT_GUI_MACVIM)
241 typedef void *GuiFont
;
242 typedef void *GuiFontset
;
243 # define NOFONT (GuiFont)NULL
244 # define NOFONTSET (GuiFontset)NULL
245 #elif defined(FEAT_GUI_GTK)
247 typedef PangoFontDescription
*GuiFont
; /* handle for a GUI font */
248 typedef PangoFontDescription
*GuiFontset
; /* handle for a GUI fontset */
250 typedef GdkFont
*GuiFont
; /* handle for a GUI font */
251 typedef GdkFont
*GuiFontset
; /* handle for a GUI fontset */
253 # define NOFONT (GuiFont)NULL
254 # define NOFONTSET (GuiFontset)NULL
256 # ifdef FEAT_GUI_PHOTON
257 typedef char *GuiFont
;
258 typedef char *GuiFontset
;
259 # define NOFONT (GuiFont)NULL
260 # define NOFONTSET (GuiFontset)NULL
263 typedef XFontStruct
*GuiFont
; /* handle for a GUI font */
264 typedef XFontSet GuiFontset
; /* handle for a GUI fontset */
265 # define NOFONT (GuiFont)0
266 # define NOFONTSET (GuiFontset)0
268 typedef long_u GuiFont
; /* handle for a GUI font */
269 typedef long_u GuiFontset
; /* handle for a GUI fontset */
270 # define NOFONT (GuiFont)0
271 # define NOFONTSET (GuiFontset)0
278 int in_focus
; /* Vim has input focus */
279 int in_use
; /* Is the GUI being used? */
280 int starting
; /* GUI will start in a little while */
281 int shell_created
; /* Has the shell been created yet? */
282 int dying
; /* Is vim dying? Then output to terminal */
283 int dofork
; /* Use fork() when GUI is starting */
284 int dragged_sb
; /* Which scrollbar being dragged, if any? */
285 win_T
*dragged_wp
; /* Which WIN's sb being dragged, if any? */
286 int pointer_hidden
; /* Is the mouse pointer hidden? */
287 int col
; /* Current cursor column in GUI display */
288 int row
; /* Current cursor row in GUI display */
289 int cursor_col
; /* Physical cursor column in GUI display */
290 int cursor_row
; /* Physical cursor row in GUI display */
291 char cursor_is_valid
; /* There is a cursor at cursor_row/col */
292 int num_cols
; /* Number of columns */
293 int num_rows
; /* Number of rows */
294 int scroll_region_top
; /* Top (first) line of scroll region */
295 int scroll_region_bot
; /* Bottom (last) line of scroll region */
296 int scroll_region_left
; /* Left (first) column of scroll region */
297 int scroll_region_right
; /* Right (last) col. of scroll region */
298 int highlight_mask
; /* Highlight attribute mask */
299 int scrollbar_width
; /* Width of vertical scrollbars */
300 int scrollbar_height
; /* Height of horizontal scrollbar */
301 int left_sbar_x
; /* Calculated x coord for left scrollbar */
302 int right_sbar_x
; /* Calculated x coord for right scrollbar */
305 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
306 int menu_height
; /* Height of the menu bar */
307 int menu_width
; /* Width of the menu bar */
309 char menu_is_active
; /* TRUE if menu is present */
310 # ifdef FEAT_GUI_ATHENA
311 char menu_height_fixed
; /* TRUE if menu height fixed */
315 scrollbar_T bottom_sbar
; /* Bottom scrollbar */
316 int which_scrollbars
[3];/* Which scrollbar boxes are active? */
317 int prev_wrap
; /* For updating the horizontal scrollbar */
318 int char_width
; /* Width of char cell in pixels */
319 int char_height
; /* Height of char cell in pixels, includes
321 int char_ascent
; /* Ascent of char in pixels */
322 int border_width
; /* Width of our border around text area */
323 int border_offset
; /* Total pixel offset for all borders */
325 GuiFont norm_font
; /* Normal font */
327 GuiFont bold_font
; /* Bold font */
328 GuiFont ital_font
; /* Italic font */
329 GuiFont boldital_font
; /* Bold-Italic font */
331 int font_can_bold
; /* Whether norm_font supports bold weight.
332 * The styled font variants are not used. */
335 #if defined(FEAT_MENU) && !defined(HAVE_GTK2)
336 # ifdef FONTSET_ALWAYS
337 GuiFontset menu_fontset
; /* set of fonts for multi-byte chars */
339 GuiFont menu_font
; /* menu item font */
343 GuiFont wide_font
; /* 'guifontwide' font */
346 GuiFontset fontset
; /* set of fonts for multi-byte chars */
348 guicolor_T back_pixel
; /* Color of background */
349 guicolor_T norm_pixel
; /* Color of normal text */
350 guicolor_T def_back_pixel
; /* default Color of background */
351 guicolor_T def_norm_pixel
; /* default Color of normal text */
354 char *rsrc_menu_fg_name
; /* Color of menu & dialog foreground */
355 guicolor_T menu_fg_pixel
; /* Same in Pixel format */
356 char *rsrc_menu_bg_name
; /* Color of menu & dialog background */
357 guicolor_T menu_bg_pixel
; /* Same in Pixel format */
358 char *rsrc_scroll_fg_name
; /* Color of scrollbar foreground */
359 guicolor_T scroll_fg_pixel
; /* Same in Pixel format */
360 char *rsrc_scroll_bg_name
; /* Color of scrollbar background */
361 guicolor_T scroll_bg_pixel
; /* Same in Pixel format */
363 # ifdef FEAT_GUI_MOTIF
364 guicolor_T menu_def_fg_pixel
; /* Default menu foreground */
365 guicolor_T menu_def_bg_pixel
; /* Default menu background */
366 guicolor_T scroll_def_fg_pixel
; /* Default scrollbar foreground */
367 guicolor_T scroll_def_bg_pixel
; /* Default scrollbar background */
369 Display
*dpy
; /* X display */
370 Window wid
; /* Window id of text area */
371 int visibility
; /* Is shell partially/fully obscured? */
375 Cursor blank_pointer
; /* Blank pointer */
378 char_u
*rsrc_font_name
; /* Resource font name, used if 'guifont'
380 char_u
*rsrc_bold_font_name
; /* Resource bold font name */
381 char_u
*rsrc_ital_font_name
; /* Resource italic font name */
382 char_u
*rsrc_boldital_font_name
; /* Resource bold-italic font name */
383 char_u
*rsrc_menu_font_name
; /* Resource menu Font name */
384 Bool rsrc_rev_video
; /* Use reverse video? */
386 char_u
*geom
; /* Geometry, eg "80x24" */
387 Bool color_approx
; /* Some color was approximated */
391 int visibility
; /* Is shell partially/fully obscured? */
392 GdkCursor
*blank_pointer
; /* Blank pointer */
395 char_u
*geom
; /* Geometry, eg "80x24" */
397 GtkWidget
*mainwin
; /* top level GTK window */
398 GtkWidget
*formwin
; /* manages all the windows below */
399 GtkWidget
*drawarea
; /* the "text" area */
401 GtkWidget
*menubar
; /* menubar */
404 GtkWidget
*toolbar
; /* toolbar */
406 # ifdef FEAT_GUI_GNOME
407 GtkWidget
*menubar_h
; /* menubar handle */
408 GtkWidget
*toolbar_h
; /* toolbar handle */
410 GdkColor
*fgcolor
; /* GDK-styled foreground color */
411 GdkColor
*bgcolor
; /* GDK-styled background color */
412 GdkColor
*spcolor
; /* GDK-styled special color */
414 GuiFont current_font
;
416 GdkGC
*text_gc
; /* cached GC for normal text */
418 PangoContext
*text_context
; /* the context used for all text */
419 PangoFont
*ascii_font
; /* cached font for ASCII strings */
420 PangoGlyphString
*ascii_glyphs
; /* cached code point -> glyph map */
422 # ifdef FEAT_GUI_TABLINE
423 GtkWidget
*tabline
; /* tab pages line handle */
426 GtkAccelGroup
*accel_group
;
428 GtkWidget
*fontdlg
; /* font selection dialog window */
429 char_u
*fontname
; /* font name from font selection dialog */
431 GtkWidget
*filedlg
; /* file selection dialog */
432 char_u
*browse_fname
; /* file name from filedlg */
433 #endif /* FEAT_GUI_GTK */
435 #if defined(FEAT_GUI_TABLINE) \
436 && (defined(FEAT_GUI_W32) || defined(FEAT_GUI_MOTIF) \
437 || defined(FEAT_GUI_MAC))
442 int footer_height
; /* height of the message footer */
445 #if defined(FEAT_TOOLBAR) \
446 && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF))
447 int toolbar_height
; /* height of the toolbar */
450 #ifdef FEAT_BEVAL_TIP
451 /* Tooltip properties; also used for balloon evaluation */
452 char_u
*rsrc_tooltip_font_name
; /* tooltip font name */
453 char *rsrc_tooltip_fg_name
; /* tooltip foreground color name */
454 char *rsrc_tooltip_bg_name
; /* tooltip background color name */
455 guicolor_T tooltip_fg_pixel
; /* tooltip foreground color */
456 guicolor_T tooltip_bg_pixel
; /* tooltip background color */
457 XFontSet tooltip_fontset
; /* tooltip fontset */
460 #ifdef FEAT_GUI_MSWIN
461 GuiFont currFont
; /* Current font */
462 guicolor_T currFgColor
; /* Current foreground text color */
463 guicolor_T currBgColor
; /* Current background text color */
464 guicolor_T currSpColor
; /* Current special text color */
469 MenuHandle MacOSHelpMenu
; /* Help menu provided by the MacOS */
470 int MacOSHelpItems
; /* Nr of help-items supplied by MacOS */
471 WindowPtr wid
; /* Window id of text area */
472 int visibility
; /* Is window partially/fully obscured? */
477 char_u
*window_title
;
478 int window_title_size
;
479 int fg_colour
; /* in 0xBBGGRR format */
483 #ifdef FEAT_GUI_PHOTON
484 PtWidget_t
*vimWindow
; /* PtWindow */
485 PtWidget_t
*vimTextArea
; /* PtRaw */
486 PtWidget_t
*vimContainer
; /* PtPanel */
487 # if defined(FEAT_MENU) || defined(FEAT_TOOLBAR)
488 PtWidget_t
*vimToolBarGroup
;
491 PtWidget_t
*vimMenuBar
;
494 PtWidget_t
*vimToolBar
;
497 PhEvent_t
*event_buffer
;
500 #if defined(FEAT_XIM) && !defined(FEAT_GUI_MACVIM)
501 char *rsrc_input_method
;
502 char *rsrc_preedit_type_name
;
505 #ifdef FEAT_GUI_SCROLL_WHEEL_FORCE
506 int scroll_wheel_force
;
510 extern gui_T gui
; /* this is defined in gui.c */
512 /* definitions of available window positionings for gui_*_position_in_parent()
521 #ifdef FIND_REPLACE_DIALOG
523 * Flags used to distinguish the different contexts in which the
524 * find/replace callback may be called.
526 # define FRD_FINDNEXT 1 /* Find next in find dialog */
527 # define FRD_R_FINDNEXT 2 /* Find next in repl dialog */
528 # define FRD_REPLACE 3 /* Replace once */
529 # define FRD_REPLACEALL 4 /* Replace remaining matches */
530 # define FRD_UNDO 5 /* Undo replaced text */
531 # define FRD_TYPE_MASK 7 /* Mask for the callback type */
532 /* Flags which change the way searching is done. */
533 # define FRD_WHOLE_WORD 0x08 /* match whole word only */
534 # define FRD_MATCH_CASE 0x10 /* match case */
537 #ifdef HAVE_GTK2 || FEAT_GUI_MACVIM
539 * Convenience macros to convert from 'encoding' to 'termencoding' and
540 * vice versa. If no conversion is necessary the passed-in pointer is
541 * returned as is, without allocating any memory. Thus additional _FREE()
542 * macros are provided. The _FREE() macros also set the pointer to NULL,
543 * in order to avoid bugs due to illegal memory access only happening if
544 * 'encoding' != utf-8...
546 * Defining these macros as pure expressions looks a bit tricky but
547 * avoids depending on the context of the macro expansion. One of the
548 * rare occasions where the comma operator comes in handy :)
550 * Note: Do NOT keep the result around when handling control back to
551 * the main Vim! The user could change 'encoding' at any time.
553 # define CONVERT_TO_UTF8(String) \
554 ((output_conv.vc_type == CONV_NONE || (String) == NULL) \
556 : string_convert(&output_conv, (String), NULL))
558 # define CONVERT_TO_UTF8_FREE(String) \
559 ((String) = ((output_conv.vc_type == CONV_NONE) \
561 : (vim_free(String), (char_u *)NULL)))
563 # define CONVERT_FROM_UTF8(String) \
564 ((input_conv.vc_type == CONV_NONE || (String) == NULL) \
566 : string_convert(&input_conv, (String), NULL))
568 # define CONVERT_FROM_UTF8_FREE(String) \
569 ((String) = ((input_conv.vc_type == CONV_NONE) \
571 : (vim_free(String), (char_u *)NULL)))
574 # define CONVERT_TO_UTF8(String) (String)
575 # define CONVERT_TO_UTF8_FREE(String) ((String) = (char_u *)NULL)
576 # define CONVERT_FROM_UTF8(String) (String)
577 # define CONVERT_FROM_UTF8_FREE(String) ((String) = (char_u *)NULL)
578 #endif /* HAVE_GTK2 */