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 # define USE_ON_FLY_SCROLL
83 * GUIs that support dropping files on a running Vim.
85 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) \
86 || defined(FEAT_GUI_GTK)
87 # define HAVE_DROP_FILE
91 * This define makes menus always use a fontset.
92 * We're not sure if this code always works, thus it can be disabled.
95 # define FONTSET_ALWAYS
99 * These macros convert between character row/column and pixel coordinates.
100 * TEXT_X - Convert character column into X pixel coord for drawing strings.
101 * TEXT_Y - Convert character row into Y pixel coord for drawing strings.
102 * FILL_X - Convert character column into X pixel coord for filling the area
103 * under the character.
104 * FILL_Y - Convert character row into Y pixel coord for filling the area
105 * under the character.
106 * X_2_COL - Convert X pixel coord into character column.
107 * Y_2_ROW - Convert Y pixel coord into character row.
110 # define TEXT_X(col) ((col) * gui.char_width)
111 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent)
112 # define FILL_X(col) ((col) * gui.char_width)
113 # define FILL_Y(row) ((row) * gui.char_height)
114 # define X_2_COL(x) ((x) / gui.char_width)
115 # define Y_2_ROW(y) ((y) / gui.char_height)
117 # define TEXT_X(col) ((col) * gui.char_width + gui.border_offset)
118 # define FILL_X(col) ((col) * gui.char_width + gui.border_offset)
119 # define X_2_COL(x) (((x) - gui.border_offset) / gui.char_width)
120 # define TEXT_Y(row) ((row) * gui.char_height + gui.char_ascent \
122 # define FILL_Y(row) ((row) * gui.char_height + gui.border_offset)
123 # define Y_2_ROW(y) (((y) - gui.border_offset) / gui.char_height)
126 /* Indices for arrays of scrollbars */
130 #define SBAR_BOTTOM 2
132 /* Orientations for scrollbars */
136 /* Default size of scrollbar */
137 #define SB_DEFAULT_WIDTH 16
139 /* Default height of the menu bar */
140 #define MENU_DEFAULT_HEIGHT 1 /* figure it out at runtime */
142 /* Flags for gui_mch_outstr_nowrap() */
143 #define GUI_MON_WRAP_CURSOR 0x01 /* wrap cursor at end of line */
144 #define GUI_MON_INVERT 0x02 /* invert the characters */
145 #define GUI_MON_IS_CURSOR 0x04 /* drawing cursor */
146 #define GUI_MON_TRS_CURSOR 0x08 /* drawing transparent cursor */
147 #define GUI_MON_NOCLEAR 0x10 /* don't clear selection */
149 /* Flags for gui_mch_draw_string() */
150 #define DRAW_TRANSP 0x01 /* draw with transparent bg */
151 #define DRAW_BOLD 0x02 /* draw bold text */
152 #define DRAW_UNDERL 0x04 /* draw underline text */
153 #define DRAW_UNDERC 0x08 /* draw undercurl text */
154 #if defined(RISCOS) || defined(HAVE_GTK2)
155 # define DRAW_ITALIC 0x10 /* draw italic text */
157 #define DRAW_CURSOR 0x20 /* drawing block cursor (win32) */
159 /* For our own tearoff menu item */
160 #define TEAR_STRING "-->Detach"
161 #define TEAR_LEN (9) /* length of above string */
163 /* for the toolbar */
165 # define TOOLBAR_BUTTON_HEIGHT 15
166 # define TOOLBAR_BUTTON_WIDTH 16
168 # define TOOLBAR_BUTTON_HEIGHT 18
169 # define TOOLBAR_BUTTON_WIDTH 18
171 #define TOOLBAR_BORDER_HEIGHT 12 /* room above+below buttons for MSWindows */
173 #ifdef FEAT_GUI_MSWIN
174 # define TABLINE_HEIGHT 22
176 #ifdef FEAT_GUI_MOTIF
177 # define TABLINE_HEIGHT 30
180 #if defined(NO_CONSOLE) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
181 # define NO_CONSOLE_INPUT /* use no_console_input() to check if there
182 is no console input possible */
185 typedef struct GuiScrollbar
187 long ident
; /* Unique identifier for each scrollbar */
188 win_T
*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 */
194 long size
; /* Size of scrollbar thumb */
195 long max
; /* Number of lines in buffer */
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 */
203 int status_height
; /* Height of status line */
205 Widget id
; /* Id of real scroll bar */
208 GtkWidget
*id
; /* Id of real scroll bar */
209 unsigned long handler_id
; /* Id of "value_changed" signal handler */
212 #ifdef FEAT_GUI_MSWIN
213 HWND id
; /* Id of real scroll bar */
214 int scroll_shift
; /* The scrollbar stuff can handle only up to
215 32767 lines. When the file is longer,
216 scroll_shift is set to the number of shifts
217 to reduce the count. */
220 ControlHandle id
; /* A handle to the scrollbar */
223 int id
; /* Window handle of scrollbar window */
225 #ifdef FEAT_GUI_PHOTON
230 typedef long guicolor_T
; /* handle for a GUI color; for X11 this should
231 be "Pixel", but that's an unsigned and we
232 need a signed value */
233 #define INVALCOLOR (guicolor_T)-11111 /* number for invalid color; on 32 bit
234 displays there is a tiny chance this is an
239 typedef PangoFontDescription
*GuiFont
; /* handle for a GUI font */
240 typedef PangoFontDescription
*GuiFontset
; /* handle for a GUI fontset */
242 typedef GdkFont
*GuiFont
; /* handle for a GUI font */
243 typedef GdkFont
*GuiFontset
; /* handle for a GUI fontset */
245 # define NOFONT (GuiFont)NULL
246 # define NOFONTSET (GuiFontset)NULL
248 # ifdef FEAT_GUI_PHOTON
249 typedef char *GuiFont
;
250 typedef char *GuiFontset
;
251 # define NOFONT (GuiFont)NULL
252 # define NOFONTSET (GuiFontset)NULL
255 typedef XFontStruct
*GuiFont
; /* handle for a GUI font */
256 typedef XFontSet GuiFontset
; /* handle for a GUI fontset */
257 # define NOFONT (GuiFont)0
258 # define NOFONTSET (GuiFontset)0
260 typedef long_u GuiFont
; /* handle for a GUI font */
261 typedef long_u GuiFontset
; /* handle for a GUI fontset */
262 # define NOFONT (GuiFont)0
263 # define NOFONTSET (GuiFontset)0
270 int in_focus
; /* Vim has input focus */
271 int in_use
; /* Is the GUI being used? */
272 int starting
; /* GUI will start in a little while */
273 int shell_created
; /* Has the shell been created yet? */
274 int dying
; /* Is vim dying? Then output to terminal */
275 int dofork
; /* Use fork() when GUI is starting */
276 int dragged_sb
; /* Which scrollbar being dragged, if any? */
277 win_T
*dragged_wp
; /* Which WIN's sb being dragged, if any? */
278 int pointer_hidden
; /* Is the mouse pointer hidden? */
279 int col
; /* Current cursor column in GUI display */
280 int row
; /* Current cursor row in GUI display */
281 int cursor_col
; /* Physical cursor column in GUI display */
282 int cursor_row
; /* Physical cursor row in GUI display */
283 char cursor_is_valid
; /* There is a cursor at cursor_row/col */
284 int num_cols
; /* Number of columns */
285 int num_rows
; /* Number of rows */
286 int scroll_region_top
; /* Top (first) line of scroll region */
287 int scroll_region_bot
; /* Bottom (last) line of scroll region */
288 int scroll_region_left
; /* Left (first) column of scroll region */
289 int scroll_region_right
; /* Right (last) col. of scroll region */
290 int highlight_mask
; /* Highlight attribute mask */
291 int scrollbar_width
; /* Width of vertical scrollbars */
292 int scrollbar_height
; /* Height of horizontal scrollbar */
293 int left_sbar_x
; /* Calculated x coord for left scrollbar */
294 int right_sbar_x
; /* Calculated x coord for right scrollbar */
297 # ifndef FEAT_GUI_GTK
298 int menu_height
; /* Height of the menu bar */
299 int menu_width
; /* Width of the menu bar */
301 char menu_is_active
; /* TRUE if menu is present */
302 # ifdef FEAT_GUI_ATHENA
303 char menu_height_fixed
; /* TRUE if menu height fixed */
307 scrollbar_T bottom_sbar
; /* Bottom scrollbar */
308 int which_scrollbars
[3];/* Which scrollbar boxes are active? */
309 int prev_wrap
; /* For updating the horizontal scrollbar */
310 int char_width
; /* Width of char cell in pixels */
311 int char_height
; /* Height of char cell in pixels, includes
313 int char_ascent
; /* Ascent of char in pixels */
314 int border_width
; /* Width of our border around text area */
315 int border_offset
; /* Total pixel offset for all borders */
317 GuiFont norm_font
; /* Normal font */
319 GuiFont bold_font
; /* Bold font */
320 GuiFont ital_font
; /* Italic font */
321 GuiFont boldital_font
; /* Bold-Italic font */
323 int font_can_bold
; /* Whether norm_font supports bold weight.
324 * The styled font variants are not used. */
327 #if defined(FEAT_MENU) && !defined(HAVE_GTK2)
328 # ifdef FONTSET_ALWAYS
329 GuiFontset menu_fontset
; /* set of fonts for multi-byte chars */
331 GuiFont menu_font
; /* menu item font */
335 GuiFont wide_font
; /* 'guifontwide' font */
338 GuiFontset fontset
; /* set of fonts for multi-byte chars */
340 guicolor_T back_pixel
; /* Color of background */
341 guicolor_T norm_pixel
; /* Color of normal text */
342 guicolor_T def_back_pixel
; /* default Color of background */
343 guicolor_T def_norm_pixel
; /* default Color of normal text */
346 char *rsrc_menu_fg_name
; /* Color of menu & dialog foreground */
347 guicolor_T menu_fg_pixel
; /* Same in Pixel format */
348 char *rsrc_menu_bg_name
; /* Color of menu & dialog background */
349 guicolor_T menu_bg_pixel
; /* Same in Pixel format */
350 char *rsrc_scroll_fg_name
; /* Color of scrollbar foreground */
351 guicolor_T scroll_fg_pixel
; /* Same in Pixel format */
352 char *rsrc_scroll_bg_name
; /* Color of scrollbar background */
353 guicolor_T scroll_bg_pixel
; /* Same in Pixel format */
355 # ifdef FEAT_GUI_MOTIF
356 guicolor_T menu_def_fg_pixel
; /* Default menu foreground */
357 guicolor_T menu_def_bg_pixel
; /* Default menu background */
358 guicolor_T scroll_def_fg_pixel
; /* Default scrollbar foreground */
359 guicolor_T scroll_def_bg_pixel
; /* Default scrollbar background */
361 Display
*dpy
; /* X display */
362 Window wid
; /* Window id of text area */
363 int visibility
; /* Is shell partially/fully obscured? */
367 Cursor blank_pointer
; /* Blank pointer */
370 char_u
*rsrc_font_name
; /* Resource font name, used if 'guifont'
372 char_u
*rsrc_bold_font_name
; /* Resource bold font name */
373 char_u
*rsrc_ital_font_name
; /* Resource italic font name */
374 char_u
*rsrc_boldital_font_name
; /* Resource bold-italic font name */
375 char_u
*rsrc_menu_font_name
; /* Resource menu Font name */
376 Bool rsrc_rev_video
; /* Use reverse video? */
378 char_u
*geom
; /* Geometry, eg "80x24" */
379 Bool color_approx
; /* Some color was approximated */
383 int visibility
; /* Is shell partially/fully obscured? */
384 GdkCursor
*blank_pointer
; /* Blank pointer */
387 char_u
*geom
; /* Geometry, eg "80x24" */
389 GtkWidget
*mainwin
; /* top level GTK window */
390 GtkWidget
*formwin
; /* manages all the windows below */
391 GtkWidget
*drawarea
; /* the "text" area */
393 GtkWidget
*menubar
; /* menubar */
396 GtkWidget
*toolbar
; /* toolbar */
398 # ifdef FEAT_GUI_GNOME
399 GtkWidget
*menubar_h
; /* menubar handle */
400 GtkWidget
*toolbar_h
; /* toolbar handle */
402 GdkColor
*fgcolor
; /* GDK-styled foreground color */
403 GdkColor
*bgcolor
; /* GDK-styled background color */
404 GdkColor
*spcolor
; /* GDK-styled special color */
406 GuiFont current_font
;
408 GdkGC
*text_gc
; /* cached GC for normal text */
410 PangoContext
*text_context
; /* the context used for all text */
411 PangoFont
*ascii_font
; /* cached font for ASCII strings */
412 PangoGlyphString
*ascii_glyphs
; /* cached code point -> glyph map */
414 # ifdef FEAT_GUI_TABLINE
415 GtkWidget
*tabline
; /* tab pages line handle */
418 GtkAccelGroup
*accel_group
;
420 GtkWidget
*fontdlg
; /* font selection dialog window */
421 char_u
*fontname
; /* font name from font selection dialog */
423 GtkWidget
*filedlg
; /* file selection dialog */
424 char_u
*browse_fname
; /* file name from filedlg */
425 #endif /* FEAT_GUI_GTK */
427 #if defined(FEAT_GUI_TABLINE) \
428 && (defined(FEAT_GUI_W32) || defined(FEAT_GUI_MOTIF) \
429 || defined(FEAT_GUI_MAC))
434 int footer_height
; /* height of the message footer */
437 #if defined(FEAT_TOOLBAR) \
438 && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF))
439 int toolbar_height
; /* height of the toolbar */
442 #ifdef FEAT_BEVAL_TIP
443 /* Tooltip properties; also used for balloon evaluation */
444 char_u
*rsrc_tooltip_font_name
; /* tooltip font name */
445 char *rsrc_tooltip_fg_name
; /* tooltip foreground color name */
446 char *rsrc_tooltip_bg_name
; /* tooltip background color name */
447 guicolor_T tooltip_fg_pixel
; /* tooltip foreground color */
448 guicolor_T tooltip_bg_pixel
; /* tooltip background color */
449 XFontSet tooltip_fontset
; /* tooltip fontset */
452 #ifdef FEAT_GUI_MSWIN
453 GuiFont currFont
; /* Current font */
454 guicolor_T currFgColor
; /* Current foreground text color */
455 guicolor_T currBgColor
; /* Current background text color */
456 guicolor_T currSpColor
; /* Current special text color */
461 MenuHandle MacOSHelpMenu
; /* Help menu provided by the MacOS */
462 int MacOSHelpItems
; /* Nr of help-items supplied by MacOS */
463 WindowPtr wid
; /* Window id of text area */
464 int visibility
; /* Is window partially/fully obscured? */
469 char_u
*window_title
;
470 int window_title_size
;
471 int fg_colour
; /* in 0xBBGGRR format */
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
;
483 PtWidget_t
*vimMenuBar
;
486 PtWidget_t
*vimToolBar
;
489 PhEvent_t
*event_buffer
;
493 char *rsrc_input_method
;
494 char *rsrc_preedit_type_name
;
498 extern gui_T gui
; /* this is defined in gui.c */
500 /* definitions of available window positionings for gui_*_position_in_parent()
509 #ifdef FIND_REPLACE_DIALOG
511 * Flags used to distinguish the different contexts in which the
512 * find/replace callback may be called.
514 # define FRD_FINDNEXT 1 /* Find next in find dialog */
515 # define FRD_R_FINDNEXT 2 /* Find next in repl dialog */
516 # define FRD_REPLACE 3 /* Replace once */
517 # define FRD_REPLACEALL 4 /* Replace remaining matches */
518 # define FRD_UNDO 5 /* Undo replaced text */
519 # define FRD_TYPE_MASK 7 /* Mask for the callback type */
520 /* Flags which change the way searching is done. */
521 # define FRD_WHOLE_WORD 0x08 /* match whole word only */
522 # define FRD_MATCH_CASE 0x10 /* match case */
527 * Convenience macros to convert from 'encoding' to 'termencoding' and
528 * vice versa. If no conversion is necessary the passed-in pointer is
529 * returned as is, without allocating any memory. Thus additional _FREE()
530 * macros are provided. The _FREE() macros also set the pointer to NULL,
531 * in order to avoid bugs due to illegal memory access only happening if
532 * 'encoding' != utf-8...
534 * Defining these macros as pure expressions looks a bit tricky but
535 * avoids depending on the context of the macro expansion. One of the
536 * rare occasions where the comma operator comes in handy :)
538 * Note: Do NOT keep the result around when handling control back to
539 * the main Vim! The user could change 'encoding' at any time.
541 # define CONVERT_TO_UTF8(String) \
542 ((output_conv.vc_type == CONV_NONE || (String) == NULL) \
544 : string_convert(&output_conv, (String), NULL))
546 # define CONVERT_TO_UTF8_FREE(String) \
547 ((String) = ((output_conv.vc_type == CONV_NONE) \
549 : (vim_free(String), (char_u *)NULL)))
551 # define CONVERT_FROM_UTF8(String) \
552 ((input_conv.vc_type == CONV_NONE || (String) == NULL) \
554 : string_convert(&input_conv, (String), NULL))
556 # define CONVERT_FROM_UTF8_FREE(String) \
557 ((String) = ((input_conv.vc_type == CONV_NONE) \
559 : (vim_free(String), (char_u *)NULL)))
562 # define CONVERT_TO_UTF8(String) (String)
563 # define CONVERT_TO_UTF8_FREE(String) ((String) = (char_u *)NULL)
564 # define CONVERT_FROM_UTF8(String) (String)
565 # define CONVERT_FROM_UTF8_FREE(String) ((String) = (char_u *)NULL)
566 #endif /* HAVE_GTK2 */