7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 * GUI/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 * See README.txt for an overview of the Vim source code.
|
|
9 */
|
|
10 /*
|
|
11 * Common code for the Motif and Athena GUI.
|
|
12 * Not used for GTK.
|
|
13 */
|
|
14
|
|
15 #include <X11/keysym.h>
|
|
16 #include <X11/Xatom.h>
|
|
17 #include <X11/StringDefs.h>
|
|
18 #include <X11/Intrinsic.h>
|
|
19 #include <X11/Shell.h>
|
|
20 #include <X11/cursorfont.h>
|
|
21
|
|
22 #include "vim.h"
|
|
23
|
|
24 /*
|
|
25 * For Workshop XpmP.h is preferred, because it makes the signs drawn with a
|
|
26 * transparent background instead of black.
|
|
27 */
|
|
28 #if defined(HAVE_XM_XPMP_H) && defined(FEAT_GUI_MOTIF) \
|
|
29 && (!defined(HAVE_X11_XPM_H) || defined(FEAT_SUN_WORKSHOP))
|
|
30 # include <Xm/XpmP.h>
|
|
31 #else
|
|
32 # ifdef HAVE_X11_XPM_H
|
|
33 # include <X11/xpm.h>
|
|
34 # endif
|
|
35 #endif
|
|
36
|
|
37 #ifdef FEAT_XFONTSET
|
|
38 # ifdef X_LOCALE
|
|
39 # include <X11/Xlocale.h>
|
|
40 # else
|
|
41 # include <locale.h>
|
|
42 # endif
|
|
43 #endif
|
|
44
|
|
45 #ifdef HAVE_X11_SUNKEYSYM_H
|
|
46 # include <X11/Sunkeysym.h>
|
|
47 #endif
|
|
48
|
|
49 #ifdef HAVE_X11_XMU_EDITRES_H
|
|
50 # include <X11/Xmu/Editres.h>
|
|
51 #endif
|
|
52
|
|
53 #ifdef FEAT_BEVAL_TIP
|
|
54 # include "gui_beval.h"
|
|
55 #endif
|
|
56
|
|
57 #define VIM_NAME "vim"
|
|
58 #define VIM_CLASS "Vim"
|
|
59
|
|
60 /* Default resource values */
|
|
61 #define DFLT_FONT "7x13"
|
|
62 #ifdef FONTSET_ALWAYS
|
|
63 # define DFLT_MENU_FONT XtDefaultFontSet
|
|
64 #else
|
|
65 # define DFLT_MENU_FONT XtDefaultFont
|
|
66 #endif
|
|
67 #define DFLT_TOOLTIP_FONT XtDefaultFontSet
|
|
68
|
|
69 #ifdef FEAT_GUI_ATHENA
|
|
70 # define DFLT_MENU_BG_COLOR "gray77"
|
|
71 # define DFLT_MENU_FG_COLOR "black"
|
|
72 # define DFLT_SCROLL_BG_COLOR "gray60"
|
|
73 # define DFLT_SCROLL_FG_COLOR "gray77"
|
|
74 # define DFLT_TOOLTIP_BG_COLOR "#ffffffff9191"
|
|
75 # define DFLT_TOOLTIP_FG_COLOR "#000000000000"
|
|
76 #else
|
|
77 /* use the default (CDE) colors */
|
|
78 # define DFLT_MENU_BG_COLOR ""
|
|
79 # define DFLT_MENU_FG_COLOR ""
|
|
80 # define DFLT_SCROLL_BG_COLOR ""
|
|
81 # define DFLT_SCROLL_FG_COLOR ""
|
|
82 # define DFLT_TOOLTIP_BG_COLOR "#ffffffff9191"
|
|
83 # define DFLT_TOOLTIP_FG_COLOR "#000000000000"
|
|
84 #endif
|
|
85
|
|
86 Widget vimShell = (Widget)0;
|
|
87
|
|
88 static Atom wm_atoms[2]; /* Window Manager Atoms */
|
|
89 #define DELETE_WINDOW_IDX 0 /* index in wm_atoms[] for WM_DELETE_WINDOW */
|
|
90 #define SAVE_YOURSELF_IDX 1 /* index in wm_atoms[] for WM_SAVE_YOURSELF */
|
|
91
|
|
92 #ifdef FEAT_XFONTSET
|
|
93 /*
|
|
94 * We either draw with a fontset (when current_fontset != NULL) or with a
|
|
95 * normal font (current_fontset == NULL, use gui.text_gc and gui.back_gc).
|
|
96 */
|
|
97 static XFontSet current_fontset = NULL;
|
|
98
|
|
99 #define XDrawString(dpy, win, gc, x, y, str, n) \
|
|
100 do \
|
|
101 { \
|
|
102 if (current_fontset != NULL) \
|
|
103 XmbDrawString(dpy, win, current_fontset, gc, x, y, str, n); \
|
|
104 else \
|
|
105 XDrawString(dpy, win, gc, x, y, str, n); \
|
|
106 } while (0)
|
|
107
|
|
108 #define XDrawString16(dpy, win, gc, x, y, str, n) \
|
|
109 do \
|
|
110 { \
|
|
111 if (current_fontset != NULL) \
|
|
112 XwcDrawString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \
|
|
113 else \
|
|
114 XDrawString16(dpy, win, gc, x, y, str, n); \
|
|
115 } while (0)
|
|
116
|
|
117 static int check_fontset_sanity __ARGS((XFontSet fs));
|
|
118 static int fontset_width __ARGS((XFontSet fs));
|
|
119 static int fontset_ascent __ARGS((XFontSet fs));
|
|
120 #endif
|
|
121
|
|
122 static guicolor_T prev_fg_color = INVALCOLOR;
|
|
123 static guicolor_T prev_bg_color = INVALCOLOR;
|
|
124
|
|
125 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
|
|
126 static XButtonPressedEvent last_mouse_event;
|
|
127 #endif
|
|
128
|
|
129 static int find_closest_color __ARGS((Colormap colormap, XColor *colorPtr));
|
|
130 static void gui_x11_timer_cb __ARGS((XtPointer timed_out, XtIntervalId *interval_id));
|
|
131 static void gui_x11_visibility_cb __ARGS((Widget w, XtPointer dud, XEvent *event, Boolean *dum));
|
|
132 static void gui_x11_expose_cb __ARGS((Widget w, XtPointer dud, XEvent *event, Boolean *dum));
|
|
133 static void gui_x11_resize_window_cb __ARGS((Widget w, XtPointer dud, XEvent *event, Boolean *dum));
|
|
134 static void gui_x11_focus_change_cb __ARGS((Widget w, XtPointer data, XEvent *event, Boolean *dum));
|
|
135 static void gui_x11_enter_cb __ARGS((Widget w, XtPointer data, XEvent *event, Boolean *dum));
|
|
136 static void gui_x11_leave_cb __ARGS((Widget w, XtPointer data, XEvent *event, Boolean *dum));
|
|
137 static void gui_x11_mouse_cb __ARGS((Widget w, XtPointer data, XEvent *event, Boolean *dum));
|
|
138 #ifdef FEAT_SNIFF
|
|
139 static void gui_x11_sniff_request_cb __ARGS((XtPointer closure, int *source, XtInputId *id));
|
|
140 #endif
|
|
141 static void gui_x11_check_copy_area __ARGS((void));
|
|
142 #ifdef FEAT_CLIENTSERVER
|
|
143 static void gui_x11_send_event_handler __ARGS((Widget, XtPointer, XEvent *, Boolean *));
|
|
144 #endif
|
|
145 static void gui_x11_wm_protocol_handler __ARGS((Widget, XtPointer, XEvent *, Boolean *));
|
|
146 static void gui_x11_blink_cb __ARGS((XtPointer timed_out, XtIntervalId *interval_id));
|
|
147 static Cursor gui_x11_create_blank_mouse __ARGS((void));
|
|
148
|
|
149
|
|
150 /*
|
|
151 * Keycodes recognized by vim.
|
|
152 * NOTE: when changing this, the table in gui_gtk_x11.c probably needs the
|
|
153 * same change!
|
|
154 */
|
|
155 static struct specialkey
|
|
156 {
|
|
157 KeySym key_sym;
|
|
158 char_u vim_code0;
|
|
159 char_u vim_code1;
|
|
160 } special_keys[] =
|
|
161 {
|
|
162 {XK_Up, 'k', 'u'},
|
|
163 {XK_Down, 'k', 'd'},
|
|
164 {XK_Left, 'k', 'l'},
|
|
165 {XK_Right, 'k', 'r'},
|
|
166
|
|
167 {XK_F1, 'k', '1'},
|
|
168 {XK_F2, 'k', '2'},
|
|
169 {XK_F3, 'k', '3'},
|
|
170 {XK_F4, 'k', '4'},
|
|
171 {XK_F5, 'k', '5'},
|
|
172 {XK_F6, 'k', '6'},
|
|
173 {XK_F7, 'k', '7'},
|
|
174 {XK_F8, 'k', '8'},
|
|
175 {XK_F9, 'k', '9'},
|
|
176 {XK_F10, 'k', ';'},
|
|
177
|
|
178 {XK_F11, 'F', '1'},
|
|
179 {XK_F12, 'F', '2'},
|
|
180 {XK_F13, 'F', '3'},
|
|
181 {XK_F14, 'F', '4'},
|
|
182 {XK_F15, 'F', '5'},
|
|
183 {XK_F16, 'F', '6'},
|
|
184 {XK_F17, 'F', '7'},
|
|
185 {XK_F18, 'F', '8'},
|
|
186 {XK_F19, 'F', '9'},
|
|
187 {XK_F20, 'F', 'A'},
|
|
188
|
|
189 {XK_F21, 'F', 'B'},
|
|
190 {XK_F22, 'F', 'C'},
|
|
191 {XK_F23, 'F', 'D'},
|
|
192 {XK_F24, 'F', 'E'},
|
|
193 {XK_F25, 'F', 'F'},
|
|
194 {XK_F26, 'F', 'G'},
|
|
195 {XK_F27, 'F', 'H'},
|
|
196 {XK_F28, 'F', 'I'},
|
|
197 {XK_F29, 'F', 'J'},
|
|
198 {XK_F30, 'F', 'K'},
|
|
199
|
|
200 {XK_F31, 'F', 'L'},
|
|
201 {XK_F32, 'F', 'M'},
|
|
202 {XK_F33, 'F', 'N'},
|
|
203 {XK_F34, 'F', 'O'},
|
|
204 {XK_F35, 'F', 'P'}, /* keysymdef.h defines up to F35 */
|
|
205 #ifdef SunXK_F36
|
|
206 {SunXK_F36, 'F', 'Q'},
|
|
207 {SunXK_F37, 'F', 'R'},
|
|
208 #endif
|
|
209
|
|
210 {XK_Help, '%', '1'},
|
|
211 {XK_Undo, '&', '8'},
|
|
212 {XK_BackSpace, 'k', 'b'},
|
|
213 {XK_Insert, 'k', 'I'},
|
|
214 {XK_Delete, 'k', 'D'},
|
|
215 {XK_Home, 'k', 'h'},
|
|
216 {XK_End, '@', '7'},
|
|
217 {XK_Prior, 'k', 'P'},
|
|
218 {XK_Next, 'k', 'N'},
|
|
219 {XK_Print, '%', '9'},
|
|
220
|
|
221 /* Keypad keys: */
|
|
222 #ifdef XK_KP_Left
|
|
223 {XK_KP_Left, 'k', 'l'},
|
|
224 {XK_KP_Right, 'k', 'r'},
|
|
225 {XK_KP_Up, 'k', 'u'},
|
|
226 {XK_KP_Down, 'k', 'd'},
|
|
227 {XK_KP_Insert, KS_EXTRA, (char_u)KE_KINS},
|
|
228 {XK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL},
|
|
229 {XK_KP_Home, 'K', '1'},
|
|
230 {XK_KP_End, 'K', '4'},
|
|
231 {XK_KP_Prior, 'K', '3'},
|
|
232 {XK_KP_Next, 'K', '5'},
|
|
233
|
|
234 {XK_KP_Add, 'K', '6'},
|
|
235 {XK_KP_Subtract, 'K', '7'},
|
|
236 {XK_KP_Divide, 'K', '8'},
|
|
237 {XK_KP_Multiply, 'K', '9'},
|
|
238 {XK_KP_Enter, 'K', 'A'},
|
|
239 {XK_KP_Decimal, 'K', 'B'},
|
|
240
|
|
241 {XK_KP_0, 'K', 'C'},
|
|
242 {XK_KP_1, 'K', 'D'},
|
|
243 {XK_KP_2, 'K', 'E'},
|
|
244 {XK_KP_3, 'K', 'F'},
|
|
245 {XK_KP_4, 'K', 'G'},
|
|
246 {XK_KP_5, 'K', 'H'},
|
|
247 {XK_KP_6, 'K', 'I'},
|
|
248 {XK_KP_7, 'K', 'J'},
|
|
249 {XK_KP_8, 'K', 'K'},
|
|
250 {XK_KP_9, 'K', 'L'},
|
|
251 #endif
|
|
252
|
|
253 /* End of list marker: */
|
|
254 {(KeySym)0, 0, 0}
|
|
255 };
|
|
256
|
|
257 #define XtNboldFont "boldFont"
|
|
258 #define XtCBoldFont "BoldFont"
|
|
259 #define XtNitalicFont "italicFont"
|
|
260 #define XtCItalicFont "ItalicFont"
|
|
261 #define XtNboldItalicFont "boldItalicFont"
|
|
262 #define XtCBoldItalicFont "BoldItalicFont"
|
|
263 #define XtNscrollbarWidth "scrollbarWidth"
|
|
264 #define XtCScrollbarWidth "ScrollbarWidth"
|
|
265 #define XtNmenuHeight "menuHeight"
|
|
266 #define XtCMenuHeight "MenuHeight"
|
|
267 #define XtNmenuFont "menuFont"
|
|
268 #define XtCMenuFont "MenuFont"
|
|
269 #define XtNmenuFontSet "menuFontSet"
|
|
270 #define XtCMenuFontSet "MenuFontSet"
|
|
271
|
|
272
|
|
273 /* Resources for setting the foreground and background colors of menus */
|
|
274 #define XtNmenuBackground "menuBackground"
|
|
275 #define XtCMenuBackground "MenuBackground"
|
|
276 #define XtNmenuForeground "menuForeground"
|
|
277 #define XtCMenuForeground "MenuForeground"
|
|
278
|
|
279 /* Resources for setting the foreground and background colors of scrollbars */
|
|
280 #define XtNscrollBackground "scrollBackground"
|
|
281 #define XtCScrollBackground "ScrollBackground"
|
|
282 #define XtNscrollForeground "scrollForeground"
|
|
283 #define XtCScrollForeground "ScrollForeground"
|
|
284
|
|
285 /* Resources for setting the foreground and background colors of tooltip */
|
|
286 #define XtNtooltipBackground "tooltipBackground"
|
|
287 #define XtCTooltipBackground "TooltipBackground"
|
|
288 #define XtNtooltipForeground "tooltipForeground"
|
|
289 #define XtCTooltipForeground "TooltipForeground"
|
|
290 #define XtNtooltipFont "tooltipFont"
|
|
291 #define XtCTooltipFont "TooltipFont"
|
|
292
|
|
293 /*
|
|
294 * X Resources:
|
|
295 */
|
|
296 static XtResource vim_resources[] =
|
|
297 {
|
|
298 {
|
|
299 XtNforeground,
|
|
300 XtCForeground,
|
|
301 XtRPixel,
|
|
302 sizeof(Pixel),
|
|
303 XtOffsetOf(gui_T, def_norm_pixel),
|
|
304 XtRString,
|
|
305 XtDefaultForeground
|
|
306 },
|
|
307 {
|
|
308 XtNbackground,
|
|
309 XtCBackground,
|
|
310 XtRPixel,
|
|
311 sizeof(Pixel),
|
|
312 XtOffsetOf(gui_T, def_back_pixel),
|
|
313 XtRString,
|
|
314 XtDefaultBackground
|
|
315 },
|
|
316 {
|
|
317 XtNfont,
|
|
318 XtCFont,
|
|
319 XtRString,
|
|
320 sizeof(String *),
|
|
321 XtOffsetOf(gui_T, rsrc_font_name),
|
|
322 XtRImmediate,
|
|
323 XtDefaultFont
|
|
324 },
|
|
325 {
|
|
326 XtNboldFont,
|
|
327 XtCBoldFont,
|
|
328 XtRString,
|
|
329 sizeof(String *),
|
|
330 XtOffsetOf(gui_T, rsrc_bold_font_name),
|
|
331 XtRImmediate,
|
|
332 ""
|
|
333 },
|
|
334 {
|
|
335 XtNitalicFont,
|
|
336 XtCItalicFont,
|
|
337 XtRString,
|
|
338 sizeof(String *),
|
|
339 XtOffsetOf(gui_T, rsrc_ital_font_name),
|
|
340 XtRImmediate,
|
|
341 ""
|
|
342 },
|
|
343 {
|
|
344 XtNboldItalicFont,
|
|
345 XtCBoldItalicFont,
|
|
346 XtRString,
|
|
347 sizeof(String *),
|
|
348 XtOffsetOf(gui_T, rsrc_boldital_font_name),
|
|
349 XtRImmediate,
|
|
350 ""
|
|
351 },
|
|
352 {
|
|
353 XtNgeometry,
|
|
354 XtCGeometry,
|
|
355 XtRString,
|
|
356 sizeof(String *),
|
|
357 XtOffsetOf(gui_T, geom),
|
|
358 XtRImmediate,
|
|
359 ""
|
|
360 },
|
|
361 {
|
|
362 XtNreverseVideo,
|
|
363 XtCReverseVideo,
|
|
364 XtRBool,
|
|
365 sizeof(Bool),
|
|
366 XtOffsetOf(gui_T, rsrc_rev_video),
|
|
367 XtRImmediate,
|
|
368 (XtPointer)False
|
|
369 },
|
|
370 {
|
|
371 XtNborderWidth,
|
|
372 XtCBorderWidth,
|
|
373 XtRInt,
|
|
374 sizeof(int),
|
|
375 XtOffsetOf(gui_T, border_width),
|
|
376 XtRImmediate,
|
|
377 (XtPointer)2
|
|
378 },
|
|
379 {
|
|
380 XtNscrollbarWidth,
|
|
381 XtCScrollbarWidth,
|
|
382 XtRInt,
|
|
383 sizeof(int),
|
|
384 XtOffsetOf(gui_T, scrollbar_width),
|
|
385 XtRImmediate,
|
|
386 (XtPointer)SB_DEFAULT_WIDTH
|
|
387 },
|
|
388 #ifdef FEAT_MENU
|
|
389 # ifdef FEAT_GUI_ATHENA /* with Motif the height is always computed */
|
|
390 {
|
|
391 XtNmenuHeight,
|
|
392 XtCMenuHeight,
|
|
393 XtRInt,
|
|
394 sizeof(int),
|
|
395 XtOffsetOf(gui_T, menu_height),
|
|
396 XtRImmediate,
|
|
397 (XtPointer)MENU_DEFAULT_HEIGHT /* Should figure out at run time */
|
|
398 },
|
|
399 # endif
|
|
400 {
|
|
401 # ifdef FONTSET_ALWAYS
|
|
402 XtNmenuFontSet,
|
|
403 XtCMenuFontSet,
|
|
404 #else
|
|
405 XtNmenuFont,
|
|
406 XtCMenuFont,
|
|
407 #endif
|
|
408 XtRString,
|
|
409 sizeof(char *),
|
|
410 XtOffsetOf(gui_T, rsrc_menu_font_name),
|
|
411 XtRString,
|
|
412 DFLT_MENU_FONT
|
|
413 },
|
|
414 #endif
|
|
415 {
|
|
416 XtNmenuForeground,
|
|
417 XtCMenuForeground,
|
|
418 XtRString,
|
|
419 sizeof(char *),
|
|
420 XtOffsetOf(gui_T, rsrc_menu_fg_name),
|
|
421 XtRString,
|
|
422 DFLT_MENU_FG_COLOR
|
|
423 },
|
|
424 {
|
|
425 XtNmenuBackground,
|
|
426 XtCMenuBackground,
|
|
427 XtRString,
|
|
428 sizeof(char *),
|
|
429 XtOffsetOf(gui_T, rsrc_menu_bg_name),
|
|
430 XtRString,
|
|
431 DFLT_MENU_BG_COLOR
|
|
432 },
|
|
433 {
|
|
434 XtNscrollForeground,
|
|
435 XtCScrollForeground,
|
|
436 XtRString,
|
|
437 sizeof(char *),
|
|
438 XtOffsetOf(gui_T, rsrc_scroll_fg_name),
|
|
439 XtRString,
|
|
440 DFLT_SCROLL_FG_COLOR
|
|
441 },
|
|
442 {
|
|
443 XtNscrollBackground,
|
|
444 XtCScrollBackground,
|
|
445 XtRString,
|
|
446 sizeof(char *),
|
|
447 XtOffsetOf(gui_T, rsrc_scroll_bg_name),
|
|
448 XtRString,
|
|
449 DFLT_SCROLL_BG_COLOR
|
|
450 },
|
|
451 #ifdef FEAT_BEVAL
|
|
452 {
|
|
453 XtNtooltipForeground,
|
|
454 XtCTooltipForeground,
|
|
455 XtRString,
|
|
456 sizeof(char *),
|
|
457 XtOffsetOf(gui_T, rsrc_tooltip_fg_name),
|
|
458 XtRString,
|
|
459 DFLT_TOOLTIP_FG_COLOR
|
|
460 },
|
|
461 {
|
|
462 XtNtooltipBackground,
|
|
463 XtCTooltipBackground,
|
|
464 XtRString,
|
|
465 sizeof(char *),
|
|
466 XtOffsetOf(gui_T, rsrc_tooltip_bg_name),
|
|
467 XtRString,
|
|
468 DFLT_TOOLTIP_BG_COLOR
|
|
469 },
|
|
470 {
|
|
471 XtNtooltipFont,
|
|
472 XtCTooltipFont,
|
|
473 XtRString,
|
|
474 sizeof(char *),
|
|
475 XtOffsetOf(gui_T, rsrc_tooltip_font_name),
|
|
476 XtRString,
|
|
477 DFLT_TOOLTIP_FONT
|
|
478 },
|
|
479 /* This one isn't really needed, keep for Sun Workshop? */
|
|
480 {
|
|
481 "balloonEvalFontSet",
|
|
482 XtCFontSet,
|
|
483 XtRFontSet,
|
|
484 sizeof(XFontSet),
|
|
485 XtOffsetOf(gui_T, tooltip_fontset),
|
|
486 XtRImmediate,
|
|
487 (XtPointer)NOFONTSET
|
|
488 },
|
|
489 #endif /* FEAT_BEVAL */
|
|
490 #ifdef FEAT_XIM
|
|
491 {
|
|
492 "preeditType",
|
|
493 "PreeditType",
|
|
494 XtRString,
|
|
495 sizeof(char*),
|
|
496 XtOffsetOf(gui_T, rsrc_preedit_type_name),
|
|
497 XtRString,
|
|
498 (XtPointer)"OverTheSpot,OffTheSpot,Root"
|
|
499 },
|
|
500 {
|
|
501 "inputMethod",
|
|
502 "InputMethod",
|
|
503 XtRString,
|
|
504 sizeof(char*),
|
|
505 XtOffsetOf(gui_T, rsrc_input_method),
|
|
506 XtRString,
|
|
507 NULL
|
|
508 },
|
|
509 #endif /* FEAT_XIM */
|
|
510 };
|
|
511
|
|
512 /*
|
|
513 * This table holds all the X GUI command line options allowed. This includes
|
|
514 * the standard ones so that we can skip them when vim is started without the
|
|
515 * GUI (but the GUI might start up later).
|
|
516 * When changing this, also update doc/vim_gui.txt and the usage message!!!
|
|
517 */
|
|
518 static XrmOptionDescRec cmdline_options[] =
|
|
519 {
|
|
520 /* We handle these options ourselves */
|
|
521 {"-bg", ".background", XrmoptionSepArg, NULL},
|
|
522 {"-background", ".background", XrmoptionSepArg, NULL},
|
|
523 {"-fg", ".foreground", XrmoptionSepArg, NULL},
|
|
524 {"-foreground", ".foreground", XrmoptionSepArg, NULL},
|
|
525 {"-fn", ".font", XrmoptionSepArg, NULL},
|
|
526 {"-font", ".font", XrmoptionSepArg, NULL},
|
|
527 {"-boldfont", ".boldFont", XrmoptionSepArg, NULL},
|
|
528 {"-italicfont", ".italicFont", XrmoptionSepArg, NULL},
|
|
529 {"-geom", ".geometry", XrmoptionSepArg, NULL},
|
|
530 {"-geometry", ".geometry", XrmoptionSepArg, NULL},
|
|
531 {"-reverse", "*reverseVideo", XrmoptionNoArg, "True"},
|
|
532 {"-rv", "*reverseVideo", XrmoptionNoArg, "True"},
|
|
533 {"+reverse", "*reverseVideo", XrmoptionNoArg, "False"},
|
|
534 {"+rv", "*reverseVideo", XrmoptionNoArg, "False"},
|
|
535 {"-display", ".display", XrmoptionSepArg, NULL},
|
|
536 {"-iconic", "*iconic", XrmoptionNoArg, "True"},
|
|
537 {"-name", ".name", XrmoptionSepArg, NULL},
|
|
538 {"-bw", ".borderWidth", XrmoptionSepArg, NULL},
|
|
539 {"-borderwidth", ".borderWidth", XrmoptionSepArg, NULL},
|
|
540 {"-sw", ".scrollbarWidth", XrmoptionSepArg, NULL},
|
|
541 {"-scrollbarwidth", ".scrollbarWidth", XrmoptionSepArg, NULL},
|
|
542 {"-mh", ".menuHeight", XrmoptionSepArg, NULL},
|
|
543 {"-menuheight", ".menuHeight", XrmoptionSepArg, NULL},
|
|
544 #ifdef FONTSET_ALWAYS
|
|
545 {"-mf", ".menuFontSet", XrmoptionSepArg, NULL},
|
|
546 {"-menufont", ".menuFontSet", XrmoptionSepArg, NULL},
|
|
547 {"-menufontset", ".menuFontSet", XrmoptionSepArg, NULL},
|
|
548 #else
|
|
549 {"-mf", ".menuFont", XrmoptionSepArg, NULL},
|
|
550 {"-menufont", ".menuFont", XrmoptionSepArg, NULL},
|
|
551 #endif
|
|
552 {"-xrm", NULL, XrmoptionResArg, NULL}
|
|
553 };
|
|
554
|
|
555 static int gui_argc = 0;
|
|
556 static char **gui_argv = NULL;
|
|
557
|
|
558 /*
|
|
559 * Call-back routines.
|
|
560 */
|
|
561
|
|
562 /* ARGSUSED */
|
|
563 static void
|
|
564 gui_x11_timer_cb(timed_out, interval_id)
|
|
565 XtPointer timed_out;
|
|
566 XtIntervalId *interval_id;
|
|
567 {
|
|
568 *((int *)timed_out) = TRUE;
|
|
569 }
|
|
570
|
|
571 /* ARGSUSED */
|
|
572 static void
|
|
573 gui_x11_visibility_cb(w, dud, event, dum)
|
|
574 Widget w;
|
|
575 XtPointer dud;
|
|
576 XEvent *event;
|
|
577 Boolean *dum;
|
|
578 {
|
|
579 if (event->type != VisibilityNotify)
|
|
580 return;
|
|
581
|
|
582 gui.visibility = event->xvisibility.state;
|
|
583
|
|
584 /*
|
|
585 * When we do an XCopyArea(), and the window is partially obscured, we want
|
|
586 * to receive an event to tell us whether it worked or not.
|
|
587 */
|
|
588 XSetGraphicsExposures(gui.dpy, gui.text_gc,
|
|
589 gui.visibility != VisibilityUnobscured);
|
|
590
|
|
591 /* This is needed for when redrawing is slow. */
|
|
592 gui_mch_update();
|
|
593 }
|
|
594
|
|
595 /* ARGSUSED */
|
|
596 static void
|
|
597 gui_x11_expose_cb(w, dud, event, dum)
|
|
598 Widget w;
|
|
599 XtPointer dud;
|
|
600 XEvent *event;
|
|
601 Boolean *dum;
|
|
602 {
|
|
603 XExposeEvent *gevent;
|
|
604 int new_x;
|
|
605
|
|
606 if (event->type != Expose)
|
|
607 return;
|
|
608
|
|
609 out_flush(); /* make sure all output has been processed */
|
|
610
|
|
611 gevent = (XExposeEvent *)event;
|
|
612 gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height);
|
|
613
|
|
614 new_x = FILL_X(0);
|
|
615
|
|
616 /* Clear the border areas if needed */
|
|
617 if (gevent->x < new_x)
|
|
618 XClearArea(gui.dpy, gui.wid, 0, 0, new_x, 0, False);
|
|
619 if (gevent->y < FILL_Y(0))
|
|
620 XClearArea(gui.dpy, gui.wid, 0, 0, 0, FILL_Y(0), False);
|
|
621 if (gevent->x > FILL_X(Columns))
|
|
622 XClearArea(gui.dpy, gui.wid, FILL_X((int)Columns), 0, 0, 0, False);
|
|
623 if (gevent->y > FILL_Y(Rows))
|
|
624 XClearArea(gui.dpy, gui.wid, 0, FILL_Y((int)Rows), 0, 0, False);
|
|
625
|
|
626 /* This is needed for when redrawing is slow. */
|
|
627 gui_mch_update();
|
|
628 }
|
|
629
|
|
630 #if (defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)) \
|
|
631 || defined(PROTO)
|
|
632 /*
|
|
633 * This function fills in the XRectangle object with the current
|
|
634 * x,y coordinates and height, width so that an XtVaSetValues to
|
|
635 * the same shell of those resources will restore the window to its
|
|
636 * formar position and dimensions.
|
|
637 *
|
|
638 * Note: This function may fail, in which case the XRectangle will
|
|
639 * be unchanged. Be sure to have the XRectangle set with the
|
|
640 * proper values for a failed condition prior to calling this
|
|
641 * function.
|
|
642 */
|
|
643 static void
|
|
644 shellRectangle(Widget shell, XRectangle *r)
|
|
645 {
|
|
646 Window rootw, shellw, child, parentw;
|
|
647 int absx, absy;
|
|
648 XWindowAttributes a;
|
|
649 Window *children;
|
|
650 unsigned int childrenCount;
|
|
651
|
|
652 shellw = XtWindow(shell);
|
|
653 if (shellw == 0)
|
|
654 return;
|
|
655 for (;;)
|
|
656 {
|
|
657 XQueryTree(XtDisplay(shell), shellw, &rootw, &parentw,
|
|
658 &children, &childrenCount);
|
|
659 XFree(children);
|
|
660 if (parentw == rootw)
|
|
661 break;
|
|
662 shellw = parentw;
|
|
663 }
|
|
664 XGetWindowAttributes(XtDisplay(shell), shellw, &a);
|
|
665 XTranslateCoordinates(XtDisplay(shell), shellw, a.root, 0, 0,
|
|
666 &absx, &absy, &child);
|
|
667 r->x = absx;
|
|
668 r->y = absy;
|
|
669 XtVaGetValues(shell, XmNheight, &r->height, XmNwidth, &r->width, NULL);
|
|
670 }
|
|
671 #endif
|
|
672
|
|
673 /* ARGSUSED */
|
|
674 static void
|
|
675 gui_x11_resize_window_cb(w, dud, event, dum)
|
|
676 Widget w;
|
|
677 XtPointer dud;
|
|
678 XEvent *event;
|
|
679 Boolean *dum;
|
|
680 {
|
|
681 static int lastWidth, lastHeight;
|
|
682
|
|
683 if (event->type != ConfigureNotify)
|
|
684 return;
|
|
685
|
|
686 if (event->xconfigure.width != lastWidth
|
|
687 || event->xconfigure.height != lastHeight)
|
|
688 {
|
|
689 lastWidth = event->xconfigure.width;
|
|
690 lastHeight = event->xconfigure.height;
|
|
691 gui_resize_shell(event->xconfigure.width, event->xconfigure.height
|
|
692 #ifdef FEAT_XIM
|
|
693 - xim_get_status_area_height()
|
|
694 #endif
|
|
695 );
|
|
696 }
|
|
697 #ifdef FEAT_SUN_WORKSHOP
|
|
698 if (usingSunWorkShop)
|
|
699 {
|
|
700 XRectangle rec;
|
|
701
|
|
702 shellRectangle(w, &rec);
|
|
703 workshop_frame_moved(rec.x, rec.y, rec.width, rec.height);
|
|
704 }
|
|
705 #endif
|
|
706 #ifdef FEAT_NETBEANS_INTG
|
|
707 if (usingNetbeans)
|
|
708 {
|
|
709 XRectangle rec;
|
|
710
|
|
711 shellRectangle(w, &rec);
|
|
712 netbeans_frame_moved(rec.x, rec.y);
|
|
713 }
|
|
714 #endif
|
|
715 #ifdef FEAT_XIM
|
|
716 xim_set_preedit();
|
|
717 #endif
|
|
718 }
|
|
719
|
|
720 /* ARGSUSED */
|
|
721 static void
|
|
722 gui_x11_focus_change_cb(w, data, event, dum)
|
|
723 Widget w;
|
|
724 XtPointer data;
|
|
725 XEvent *event;
|
|
726 Boolean *dum;
|
|
727 {
|
|
728 gui_focus_change(event->type == FocusIn);
|
|
729 }
|
|
730
|
|
731 /* ARGSUSED */
|
|
732 static void
|
|
733 gui_x11_enter_cb(w, data, event, dum)
|
|
734 Widget w;
|
|
735 XtPointer data;
|
|
736 XEvent *event;
|
|
737 Boolean *dum;
|
|
738 {
|
|
739 gui_focus_change(TRUE);
|
|
740 }
|
|
741
|
|
742 /* ARGSUSED */
|
|
743 static void
|
|
744 gui_x11_leave_cb(w, data, event, dum)
|
|
745 Widget w;
|
|
746 XtPointer data;
|
|
747 XEvent *event;
|
|
748 Boolean *dum;
|
|
749 {
|
|
750 gui_focus_change(FALSE);
|
|
751 }
|
|
752
|
|
753 #if defined(X_HAVE_UTF8_STRING) && defined(FEAT_MBYTE)
|
|
754 # if X_HAVE_UTF8_STRING
|
|
755 # define USE_UTF8LOOKUP
|
|
756 # endif
|
|
757 #endif
|
|
758
|
|
759 /* ARGSUSED */
|
|
760 void
|
|
761 gui_x11_key_hit_cb(w, dud, event, dum)
|
|
762 Widget w;
|
|
763 XtPointer dud;
|
|
764 XEvent *event;
|
|
765 Boolean *dum;
|
|
766 {
|
|
767 XKeyPressedEvent *ev_press;
|
|
768 #ifdef FEAT_XIM
|
|
769 char_u string2[256];
|
|
770 char_u string_shortbuf[256];
|
|
771 char_u *string = string_shortbuf;
|
|
772 Boolean string_alloced = False;
|
|
773 Status status;
|
|
774 #else
|
|
775 char_u string[4], string2[3];
|
|
776 #endif
|
|
777 KeySym key_sym, key_sym2;
|
|
778 int len, len2;
|
|
779 int i;
|
|
780 int modifiers;
|
|
781 int key;
|
|
782
|
|
783 ev_press = (XKeyPressedEvent *)event;
|
|
784
|
|
785 #ifdef FEAT_XIM
|
|
786 if (xic)
|
|
787 {
|
|
788 # ifdef USE_UTF8LOOKUP
|
|
789 /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even when
|
|
790 * the locale isn't utf-8. */
|
|
791 if (enc_utf8)
|
|
792 len = Xutf8LookupString(xic, ev_press, (char *)string,
|
|
793 sizeof(string_shortbuf), &key_sym, &status);
|
|
794 else
|
|
795 # endif
|
|
796 len = XmbLookupString(xic, ev_press, (char *)string,
|
|
797 sizeof(string_shortbuf), &key_sym, &status);
|
|
798 if (status == XBufferOverflow)
|
|
799 {
|
|
800 string = (char_u *)XtMalloc(len + 1);
|
|
801 string_alloced = True;
|
|
802 # ifdef USE_UTF8LOOKUP
|
|
803 /* XFree86 4.0.2 or newer: Be able to get UTF-8 characters even
|
|
804 * when the locale isn't utf-8. */
|
|
805 if (enc_utf8)
|
|
806 len = Xutf8LookupString(xic, ev_press, (char *)string,
|
|
807 len, &key_sym, &status);
|
|
808 else
|
|
809 # endif
|
|
810 len = XmbLookupString(xic, ev_press, (char *)string,
|
|
811 len, &key_sym, &status);
|
|
812 }
|
|
813 if (status == XLookupNone || status == XLookupChars)
|
|
814 key_sym = XK_VoidSymbol;
|
|
815
|
|
816 # ifdef FEAT_MBYTE
|
|
817 /* Do conversion from 'termencoding' to 'encoding'. When using
|
|
818 * Xutf8LookupString() it has already been done. */
|
|
819 if (len > 0 && input_conv.vc_type != CONV_NONE
|
|
820 # ifdef USE_UTF8LOOKUP
|
|
821 && !enc_utf8
|
|
822 # endif
|
|
823 )
|
|
824 {
|
|
825 int maxlen = len * 4 + 40; /* guessed */
|
|
826 char_u *p = (char_u *)XtMalloc(maxlen);
|
|
827
|
|
828 mch_memmove(p, string, len);
|
|
829 if (string_alloced)
|
|
830 XtFree((char *)string);
|
|
831 string = p;
|
|
832 string_alloced = True;
|
|
833 len = convert_input(p, len, maxlen);
|
|
834 }
|
|
835 # endif
|
|
836
|
|
837 /* Translate CSI to K_CSI, otherwise it could be recognized as the
|
|
838 * start of a special key. */
|
|
839 for (i = 0; i < len; ++i)
|
|
840 if (string[i] == CSI)
|
|
841 {
|
|
842 char_u *p = (char_u *)XtMalloc(len + 3);
|
|
843
|
|
844 mch_memmove(p, string, i + 1);
|
|
845 p[i + 1] = KS_EXTRA;
|
|
846 p[i + 2] = (int)KE_CSI;
|
|
847 mch_memmove(p + i + 3, string + i + 1, len - i);
|
|
848 if (string_alloced)
|
|
849 XtFree((char *)string);
|
|
850 string = p;
|
|
851 string_alloced = True;
|
|
852 i += 2;
|
|
853 len += 2;
|
|
854 }
|
|
855 }
|
|
856 else
|
|
857 #endif
|
|
858 len = XLookupString(ev_press, (char *)string, sizeof(string),
|
|
859 &key_sym, NULL);
|
|
860
|
|
861 #ifdef SunXK_F36
|
|
862 /*
|
|
863 * These keys have bogus lookup strings, and trapping them here is
|
|
864 * easier than trying to XRebindKeysym() on them with every possible
|
|
865 * combination of modifiers.
|
|
866 */
|
|
867 if (key_sym == SunXK_F36 || key_sym == SunXK_F37)
|
|
868 len = 0;
|
|
869 #endif
|
|
870
|
|
871 #ifdef FEAT_HANGULIN
|
|
872 if ((key_sym == XK_space) && (ev_press->state & ShiftMask))
|
|
873 {
|
|
874 hangul_input_state_toggle();
|
|
875 goto theend;
|
|
876 }
|
|
877 #endif
|
|
878
|
|
879 if (key_sym == XK_space)
|
|
880 string[0] = ' '; /* Otherwise Ctrl-Space doesn't work */
|
|
881
|
|
882 /*
|
|
883 * Only on some machines ^_ requires Ctrl+Shift+minus. For consistency,
|
|
884 * allow just Ctrl+minus too.
|
|
885 */
|
|
886 if (key_sym == XK_minus && (ev_press->state & ControlMask))
|
|
887 string[0] = Ctrl__;
|
|
888
|
|
889 #ifdef XK_ISO_Left_Tab
|
|
890 /* why do we get XK_ISO_Left_Tab instead of XK_Tab for shift-tab? */
|
|
891 if (key_sym == XK_ISO_Left_Tab)
|
|
892 {
|
|
893 key_sym = XK_Tab;
|
|
894 string[0] = TAB;
|
|
895 len = 1;
|
|
896 }
|
|
897 #endif
|
|
898
|
|
899 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character
|
|
900 * that already has the 8th bit set. And not when using a double-byte
|
|
901 * encoding, setting the 8th bit may make it the lead byte of a
|
|
902 * double-byte character. */
|
|
903 if (len == 1
|
|
904 && (ev_press->state & Mod1Mask)
|
|
905 && !(key_sym == XK_BackSpace || key_sym == XK_Delete)
|
|
906 && (string[0] & 0x80) == 0
|
|
907 #ifdef FEAT_MBYTE
|
|
908 && !enc_dbcs
|
|
909 #endif
|
|
910 )
|
|
911 {
|
|
912 #if defined(FEAT_MENU) && defined(FEAT_GUI_MOTIF)
|
|
913 /* Ignore ALT keys when they are used for the menu only */
|
|
914 if (gui.menu_is_active
|
|
915 && (p_wak[0] == 'y'
|
|
916 || (p_wak[0] == 'm' && gui_is_menu_shortcut(string[0]))))
|
|
917 goto theend;
|
|
918 #endif
|
|
919 /*
|
|
920 * Before we set the 8th bit, check to make sure the user doesn't
|
|
921 * already have a mapping defined for this sequence. We determine this
|
|
922 * by checking to see if the input would be the same without the
|
|
923 * Alt/Meta key.
|
|
924 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT.
|
|
925 */
|
|
926 ev_press->state &= ~Mod1Mask;
|
|
927 len2 = XLookupString(ev_press, (char *)string2, sizeof(string2),
|
|
928 &key_sym2, NULL);
|
|
929 if (key_sym2 == XK_space)
|
|
930 string2[0] = ' '; /* Otherwise Meta-Ctrl-Space doesn't work */
|
|
931 if ( len2 == 1
|
|
932 && string[0] == string2[0]
|
|
933 && !(key_sym == XK_Tab && (ev_press->state & ShiftMask)))
|
|
934 {
|
|
935 string[0] |= 0x80;
|
|
936 #ifdef FEAT_MBYTE
|
|
937 if (enc_utf8) /* convert to utf-8 */
|
|
938 {
|
|
939 string[1] = string[0] & 0xbf;
|
|
940 string[0] = ((unsigned)string[0] >> 6) + 0xc0;
|
|
941 if (string[1] == CSI)
|
|
942 {
|
|
943 string[2] = KS_EXTRA;
|
|
944 string[3] = (int)KE_CSI;
|
|
945 len = 4;
|
|
946 }
|
|
947 else
|
|
948 len = 2;
|
|
949 }
|
|
950 #endif
|
|
951 }
|
|
952 else
|
|
953 ev_press->state |= Mod1Mask;
|
|
954 }
|
|
955
|
|
956 if (len == 1 && string[0] == CSI)
|
|
957 {
|
|
958 string[1] = KS_EXTRA;
|
|
959 string[2] = (int)KE_CSI;
|
|
960 len = -3;
|
|
961 }
|
|
962
|
|
963 /* Check for special keys. Also do this when len == 1 (key has an ASCII
|
|
964 * value) to detect backspace, delete and keypad keys. */
|
|
965 if (len == 0 || len == 1)
|
|
966 {
|
|
967 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++)
|
|
968 {
|
|
969 if (special_keys[i].key_sym == key_sym)
|
|
970 {
|
|
971 string[0] = CSI;
|
|
972 string[1] = special_keys[i].vim_code0;
|
|
973 string[2] = special_keys[i].vim_code1;
|
|
974 len = -3;
|
|
975 break;
|
|
976 }
|
|
977 }
|
|
978 }
|
|
979
|
|
980 /* Unrecognised key is ignored. */
|
|
981 if (len == 0)
|
|
982 goto theend;
|
|
983
|
|
984 /* Special keys (and a few others) may have modifiers. Also when using a
|
|
985 * double-byte encoding (can't set the 8th bit). */
|
|
986 if (len == -3 || key_sym == XK_space || key_sym == XK_Tab
|
|
987 || key_sym == XK_Return || key_sym == XK_Linefeed
|
|
988 || key_sym == XK_Escape
|
|
989 #ifdef FEAT_MBYTE
|
|
990 || (enc_dbcs && len == 1 && (ev_press->state & Mod1Mask))
|
|
991 #endif
|
|
992 )
|
|
993 {
|
|
994 modifiers = 0;
|
|
995 if (ev_press->state & ShiftMask)
|
|
996 modifiers |= MOD_MASK_SHIFT;
|
|
997 if (ev_press->state & ControlMask)
|
|
998 modifiers |= MOD_MASK_CTRL;
|
|
999 if (ev_press->state & Mod1Mask)
|
|
1000 modifiers |= MOD_MASK_ALT;
|
|
1001
|
|
1002 /*
|
|
1003 * For some keys a shift modifier is translated into another key
|
|
1004 * code.
|
|
1005 */
|
|
1006 if (len == -3)
|
|
1007 key = TO_SPECIAL(string[1], string[2]);
|
|
1008 else
|
|
1009 key = string[0];
|
|
1010 key = simplify_key(key, &modifiers);
|
|
1011 if (key == CSI)
|
|
1012 key = K_CSI;
|
|
1013 if (IS_SPECIAL(key))
|
|
1014 {
|
|
1015 string[0] = CSI;
|
|
1016 string[1] = K_SECOND(key);
|
|
1017 string[2] = K_THIRD(key);
|
|
1018 len = 3;
|
|
1019 }
|
|
1020 else
|
|
1021 {
|
|
1022 string[0] = key;
|
|
1023 len = 1;
|
|
1024 }
|
|
1025
|
|
1026 if (modifiers != 0)
|
|
1027 {
|
|
1028 string2[0] = CSI;
|
|
1029 string2[1] = KS_MODIFIER;
|
|
1030 string2[2] = modifiers;
|
|
1031 add_to_input_buf(string2, 3);
|
|
1032 }
|
|
1033 }
|
|
1034
|
|
1035 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts)
|
|
1036 #ifdef UNIX
|
|
1037 || (intr_char != 0 && string[0] == intr_char)
|
|
1038 #endif
|
|
1039 ))
|
|
1040 {
|
|
1041 trash_input_buf();
|
|
1042 got_int = TRUE;
|
|
1043 }
|
|
1044
|
|
1045 add_to_input_buf(string, len);
|
|
1046
|
|
1047 /*
|
|
1048 * blank out the pointer if necessary
|
|
1049 */
|
|
1050 if (p_mh)
|
|
1051 gui_mch_mousehide(TRUE);
|
|
1052
|
|
1053 #if defined(FEAT_BEVAL_TIP)
|
|
1054 {
|
|
1055 BalloonEval *be;
|
|
1056
|
|
1057 if ((be = gui_mch_currently_showing_beval()) != NULL)
|
|
1058 gui_mch_unpost_balloon(be);
|
|
1059 }
|
|
1060 #endif
|
|
1061 theend:
|
|
1062 {} /* some compilers need a statement here */
|
|
1063 #ifdef FEAT_XIM
|
|
1064 if (string_alloced)
|
|
1065 XtFree((char *)string);
|
|
1066 #endif
|
|
1067 }
|
|
1068
|
|
1069 /* ARGSUSED */
|
|
1070 static void
|
|
1071 gui_x11_mouse_cb(w, dud, event, dum)
|
|
1072 Widget w;
|
|
1073 XtPointer dud;
|
|
1074 XEvent *event;
|
|
1075 Boolean *dum;
|
|
1076 {
|
|
1077 static XtIntervalId timer = (XtIntervalId)0;
|
|
1078 static int timed_out = TRUE;
|
|
1079
|
|
1080 int button;
|
|
1081 int repeated_click = FALSE;
|
|
1082 int x, y;
|
|
1083 int_u x_modifiers;
|
|
1084 int_u vim_modifiers;
|
|
1085
|
|
1086 if (event->type == MotionNotify)
|
|
1087 {
|
|
1088 /* Get the latest position, avoids lagging behind on a drag. */
|
|
1089 x = event->xmotion.x;
|
|
1090 y = event->xmotion.y;
|
|
1091 x_modifiers = event->xmotion.state;
|
|
1092 button = (x_modifiers & (Button1Mask | Button2Mask | Button3Mask))
|
|
1093 ? MOUSE_DRAG : ' ';
|
|
1094
|
|
1095 /*
|
|
1096 * if our pointer is currently hidden, then we should show it.
|
|
1097 */
|
|
1098 gui_mch_mousehide(FALSE);
|
|
1099
|
|
1100 if (button != MOUSE_DRAG) /* just moving the rodent */
|
|
1101 {
|
|
1102 #ifdef FEAT_MENU
|
|
1103 if (dud) /* moved in vimForm */
|
|
1104 y -= gui.menu_height;
|
|
1105 #endif
|
|
1106 gui_mouse_moved(x, y);
|
|
1107 return;
|
|
1108 }
|
|
1109 }
|
|
1110 else
|
|
1111 {
|
|
1112 x = event->xbutton.x;
|
|
1113 y = event->xbutton.y;
|
|
1114 if (event->type == ButtonPress)
|
|
1115 {
|
|
1116 /* Handle multiple clicks */
|
|
1117 if (!timed_out)
|
|
1118 {
|
|
1119 XtRemoveTimeOut(timer);
|
|
1120 repeated_click = TRUE;
|
|
1121 }
|
|
1122 timed_out = FALSE;
|
|
1123 timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
|
|
1124 gui_x11_timer_cb, &timed_out);
|
|
1125 switch (event->xbutton.button)
|
|
1126 {
|
|
1127 case Button1: button = MOUSE_LEFT; break;
|
|
1128 case Button2: button = MOUSE_MIDDLE; break;
|
|
1129 case Button3: button = MOUSE_RIGHT; break;
|
|
1130 case Button4: button = MOUSE_4; break;
|
|
1131 case Button5: button = MOUSE_5; break;
|
|
1132 default:
|
|
1133 return; /* Unknown button */
|
|
1134 }
|
|
1135 }
|
|
1136 else if (event->type == ButtonRelease)
|
|
1137 button = MOUSE_RELEASE;
|
|
1138 else
|
|
1139 return; /* Unknown mouse event type */
|
|
1140
|
|
1141 x_modifiers = event->xbutton.state;
|
|
1142 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
|
|
1143 last_mouse_event = event->xbutton;
|
|
1144 #endif
|
|
1145 }
|
|
1146
|
|
1147 vim_modifiers = 0x0;
|
|
1148 if (x_modifiers & ShiftMask)
|
|
1149 vim_modifiers |= MOUSE_SHIFT;
|
|
1150 if (x_modifiers & ControlMask)
|
|
1151 vim_modifiers |= MOUSE_CTRL;
|
|
1152 if (x_modifiers & Mod1Mask) /* Alt or Meta key */
|
|
1153 vim_modifiers |= MOUSE_ALT;
|
|
1154
|
|
1155 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers);
|
|
1156 }
|
|
1157
|
|
1158 #ifdef FEAT_SNIFF
|
|
1159 /* ARGSUSED */
|
|
1160 static void
|
|
1161 gui_x11_sniff_request_cb(closure, source, id)
|
|
1162 XtPointer closure;
|
|
1163 int *source;
|
|
1164 XtInputId *id;
|
|
1165 {
|
|
1166 static char_u bytes[3] = {CSI, (int)KS_EXTRA, (int)KE_SNIFF};
|
|
1167
|
|
1168 add_to_input_buf(bytes, 3);
|
|
1169 }
|
|
1170 #endif
|
|
1171
|
|
1172 /*
|
|
1173 * End of call-back routines
|
|
1174 */
|
|
1175
|
|
1176 /*
|
|
1177 * Parse the GUI related command-line arguments. Any arguments used are
|
|
1178 * deleted from argv, and *argc is decremented accordingly. This is called
|
|
1179 * when vim is started, whether or not the GUI has been started.
|
|
1180 */
|
|
1181 void
|
|
1182 gui_mch_prepare(argc, argv)
|
|
1183 int *argc;
|
|
1184 char **argv;
|
|
1185 {
|
|
1186 int arg;
|
|
1187 int i;
|
|
1188
|
|
1189 /*
|
|
1190 * Move all the entries in argv which are relevant to X into gui_argv.
|
|
1191 */
|
|
1192 gui_argc = 0;
|
|
1193 gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE);
|
|
1194 if (gui_argv == NULL)
|
|
1195 return;
|
|
1196 gui_argv[gui_argc++] = argv[0];
|
|
1197 arg = 1;
|
|
1198 while (arg < *argc)
|
|
1199 {
|
|
1200 /* Look for argv[arg] in cmdline_options[] table */
|
|
1201 for (i = 0; i < XtNumber(cmdline_options); i++)
|
|
1202 if (strcmp(argv[arg], cmdline_options[i].option) == 0)
|
|
1203 break;
|
|
1204
|
|
1205 if (i < XtNumber(cmdline_options))
|
|
1206 {
|
|
1207 /* Remember finding "-rv" or "-reverse" */
|
|
1208 if (strcmp("-rv", argv[arg]) == 0
|
|
1209 || strcmp("-reverse", argv[arg]) == 0)
|
|
1210 found_reverse_arg = TRUE;
|
|
1211 else if ((strcmp("-fn", argv[arg]) == 0
|
|
1212 || strcmp("-font", argv[arg]) == 0)
|
|
1213 && arg + 1 < *argc)
|
|
1214 font_argument = argv[arg + 1];
|
|
1215
|
|
1216 /* Found match in table, so move it into gui_argv */
|
|
1217 gui_argv[gui_argc++] = argv[arg];
|
|
1218 if (--*argc > arg)
|
|
1219 {
|
|
1220 mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg)
|
|
1221 * sizeof(char *));
|
|
1222 if (cmdline_options[i].argKind != XrmoptionNoArg)
|
|
1223 {
|
|
1224 /* Move the options argument as well */
|
|
1225 gui_argv[gui_argc++] = argv[arg];
|
|
1226 if (--*argc > arg)
|
|
1227 mch_memmove(&argv[arg], &argv[arg + 1], (*argc - arg)
|
|
1228 * sizeof(char *));
|
|
1229 }
|
|
1230 }
|
|
1231 argv[*argc] = NULL;
|
|
1232 }
|
|
1233 else
|
|
1234 #ifdef FEAT_SUN_WORKSHOP
|
|
1235 if (strcmp("-ws", argv[arg]) == 0)
|
|
1236 {
|
|
1237 usingSunWorkShop++;
|
|
1238 p_acd = TRUE;
|
|
1239 gui.dofork = FALSE; /* don't fork() when starting GUI */
|
|
1240 mch_memmove(&argv[arg], &argv[arg + 1],
|
|
1241 (--*argc - arg) * sizeof(char *));
|
|
1242 argv[*argc] = NULL;
|
|
1243 # ifdef WSDEBUG
|
|
1244 wsdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20);
|
|
1245 wsdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL");
|
|
1246 # endif
|
|
1247 }
|
|
1248 else
|
|
1249 #endif
|
|
1250 #ifdef FEAT_NETBEANS_INTG
|
|
1251 if (strncmp("-nb", argv[arg], 3) == 0)
|
|
1252 {
|
|
1253 usingNetbeans++;
|
|
1254 gui.dofork = FALSE; /* don't fork() when starting GUI */
|
|
1255 netbeansArg = argv[arg];
|
|
1256 mch_memmove(&argv[arg], &argv[arg + 1],
|
|
1257 (--*argc - arg) * sizeof(char *));
|
|
1258 argv[*argc] = NULL;
|
|
1259 }
|
|
1260 else
|
|
1261 #endif
|
|
1262 arg++;
|
|
1263 }
|
|
1264 }
|
|
1265
|
|
1266 #ifndef XtSpecificationRelease
|
|
1267 # define CARDINAL (Cardinal *)
|
|
1268 #else
|
|
1269 # if XtSpecificationRelease == 4
|
|
1270 # define CARDINAL (Cardinal *)
|
|
1271 # else
|
|
1272 # define CARDINAL (int *)
|
|
1273 # endif
|
|
1274 #endif
|
|
1275
|
|
1276 /*
|
|
1277 * Check if the GUI can be started. Called before gvimrc is sourced.
|
|
1278 * Return OK or FAIL.
|
|
1279 */
|
|
1280 int
|
|
1281 gui_mch_init_check()
|
|
1282 {
|
|
1283 #ifdef FEAT_XIM
|
|
1284 XtSetLanguageProc(NULL, NULL, NULL);
|
|
1285 #endif
|
|
1286 open_app_context();
|
|
1287 if (app_context != NULL)
|
|
1288 gui.dpy = XtOpenDisplay(app_context, 0, VIM_NAME, VIM_CLASS,
|
|
1289 cmdline_options, XtNumber(cmdline_options),
|
|
1290 CARDINAL &gui_argc, gui_argv);
|
|
1291
|
|
1292 if (app_context == NULL || gui.dpy == NULL)
|
|
1293 {
|
|
1294 gui.dying = TRUE;
|
|
1295 EMSG(_(e_opendisp));
|
|
1296 return FAIL;
|
|
1297 }
|
|
1298 return OK;
|
|
1299 }
|
|
1300
|
|
1301
|
|
1302 #ifdef USE_XSMP
|
|
1303 /*
|
|
1304 * Handle XSMP processing, de-registering the attachment upon error
|
|
1305 */
|
|
1306 static XtInputId _xsmp_xtinputid;
|
|
1307
|
|
1308 static void local_xsmp_handle_requests __ARGS((XtPointer c, int *s, XtInputId *i));
|
|
1309
|
|
1310 /*ARGSUSED*/
|
|
1311 static void
|
|
1312 local_xsmp_handle_requests(c, s, i)
|
|
1313 XtPointer c;
|
|
1314 int *s;
|
|
1315 XtInputId *i;
|
|
1316 {
|
|
1317 if (xsmp_handle_requests() == FAIL)
|
|
1318 XtRemoveInput(_xsmp_xtinputid);
|
|
1319 }
|
|
1320 #endif
|
|
1321
|
|
1322
|
|
1323 /*
|
|
1324 * Initialise the X GUI. Create all the windows, set up all the call-backs etc.
|
|
1325 * Returns OK for success, FAIL when the GUI can't be started.
|
|
1326 */
|
|
1327 int
|
|
1328 gui_mch_init()
|
|
1329 {
|
|
1330 XtGCMask gc_mask;
|
|
1331 XGCValues gc_vals;
|
|
1332 int x, y, mask;
|
|
1333 unsigned w, h;
|
|
1334
|
|
1335 #if 0
|
|
1336 /* Uncomment this to enable synchronous mode for debugging */
|
|
1337 XSynchronize(gui.dpy, True);
|
|
1338 #endif
|
|
1339
|
|
1340 vimShell = XtVaAppCreateShell(VIM_NAME, VIM_CLASS,
|
|
1341 applicationShellWidgetClass, gui.dpy, NULL);
|
|
1342
|
|
1343 /*
|
|
1344 * Get the application resources
|
|
1345 */
|
|
1346 XtVaGetApplicationResources(vimShell, (XtPointer)&gui,
|
|
1347 vim_resources, XtNumber(vim_resources), NULL);
|
|
1348
|
|
1349 gui.scrollbar_height = gui.scrollbar_width;
|
|
1350
|
|
1351 /*
|
|
1352 * Get the colors ourselves. Using the automatic conversion doesn't
|
|
1353 * handle looking for approximate colors.
|
|
1354 */
|
|
1355 /* NOTE: These next few lines are an exact duplicate of gui_athena.c's
|
|
1356 * gui_mch_def_colors(). Why?
|
|
1357 */
|
|
1358 gui.menu_fg_pixel = gui_get_color((char_u *)gui.rsrc_menu_fg_name);
|
|
1359 gui.menu_bg_pixel = gui_get_color((char_u *)gui.rsrc_menu_bg_name);
|
|
1360 gui.scroll_fg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_fg_name);
|
|
1361 gui.scroll_bg_pixel = gui_get_color((char_u *)gui.rsrc_scroll_bg_name);
|
|
1362 #ifdef FEAT_BEVAL
|
|
1363 gui.tooltip_fg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
|
|
1364 gui.tooltip_bg_pixel = gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
|
|
1365 #endif
|
|
1366
|
|
1367 #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA)
|
|
1368 /* If the menu height was set, don't change it at runtime */
|
|
1369 if (gui.menu_height != MENU_DEFAULT_HEIGHT)
|
|
1370 gui.menu_height_fixed = TRUE;
|
|
1371 #endif
|
|
1372
|
|
1373 /* Set default foreground and background colours */
|
|
1374 gui.norm_pixel = gui.def_norm_pixel;
|
|
1375 gui.back_pixel = gui.def_back_pixel;
|
|
1376
|
|
1377 /* Check if reverse video needs to be applied (on Sun it's done by X) */
|
|
1378 if (gui.rsrc_rev_video && gui_get_lightness(gui.back_pixel)
|
|
1379 > gui_get_lightness(gui.norm_pixel))
|
|
1380 {
|
|
1381 gui.norm_pixel = gui.def_back_pixel;
|
|
1382 gui.back_pixel = gui.def_norm_pixel;
|
|
1383 gui.def_norm_pixel = gui.norm_pixel;
|
|
1384 gui.def_back_pixel = gui.back_pixel;
|
|
1385 }
|
|
1386
|
|
1387 /* Get the colors from the "Normal", "Tooltip", "Scrollbar" and "Menu"
|
|
1388 * group (set in syntax.c or in a vimrc file) */
|
|
1389 set_normal_colors();
|
|
1390
|
|
1391 /*
|
|
1392 * Check that none of the colors are the same as the background color
|
|
1393 */
|
|
1394 gui_check_colors();
|
|
1395
|
|
1396 /*
|
|
1397 * Set up the GCs. The font attributes will be set in gui_init_font().
|
|
1398 */
|
|
1399 gc_mask = GCForeground | GCBackground;
|
|
1400 gc_vals.foreground = gui.norm_pixel;
|
|
1401 gc_vals.background = gui.back_pixel;
|
|
1402 gui.text_gc = XtGetGC(vimShell, gc_mask, &gc_vals);
|
|
1403
|
|
1404 gc_vals.foreground = gui.back_pixel;
|
|
1405 gc_vals.background = gui.norm_pixel;
|
|
1406 gui.back_gc = XtGetGC(vimShell, gc_mask, &gc_vals);
|
|
1407
|
|
1408 gc_mask |= GCFunction;
|
|
1409 gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel;
|
|
1410 gc_vals.background = gui.norm_pixel ^ gui.back_pixel;
|
|
1411 gc_vals.function = GXxor;
|
|
1412 gui.invert_gc = XtGetGC(vimShell, gc_mask, &gc_vals);
|
|
1413
|
|
1414 gui.visibility = VisibilityUnobscured;
|
|
1415 x11_setup_atoms(gui.dpy);
|
|
1416
|
|
1417 if (gui_win_x != -1 && gui_win_y != -1)
|
|
1418 gui_mch_set_winpos(gui_win_x, gui_win_y);
|
|
1419
|
|
1420 /* Now adapt the supplied(?) geometry-settings */
|
|
1421 /* Added by Kjetil Jacobsen <kjetilja@stud.cs.uit.no> */
|
|
1422 if (gui.geom != NULL && *gui.geom != NUL)
|
|
1423 {
|
|
1424 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h);
|
|
1425 if (mask & WidthValue)
|
|
1426 Columns = w;
|
|
1427 if (mask & HeightValue)
|
|
1428 Rows = h;
|
|
1429 /*
|
|
1430 * Set the (x,y) position of the main window only if specified in the
|
|
1431 * users geometry, so we get good defaults when they don't. This needs
|
|
1432 * to be done before the shell is popped up.
|
|
1433 */
|
|
1434 if (mask & (XValue|YValue))
|
|
1435 XtVaSetValues(vimShell, XtNgeometry, gui.geom, NULL);
|
|
1436 }
|
|
1437
|
|
1438 gui_x11_create_widgets();
|
|
1439
|
|
1440 /*
|
|
1441 * Add an icon to Vim (Marcel Douben: 11 May 1998).
|
|
1442 */
|
|
1443 if (vim_strchr(p_go, GO_ICON) != NULL)
|
|
1444 {
|
|
1445 #ifndef HAVE_XPM
|
|
1446 # include "vim_icon.xbm"
|
|
1447 # include "vim_mask.xbm"
|
|
1448
|
|
1449 Arg arg[2];
|
|
1450
|
|
1451 XtSetArg(arg[0], XtNiconPixmap,
|
|
1452 XCreateBitmapFromData(gui.dpy,
|
|
1453 DefaultRootWindow(gui.dpy),
|
|
1454 (char *)vim_icon_bits,
|
|
1455 vim_icon_width,
|
|
1456 vim_icon_height));
|
|
1457 XtSetArg(arg[1], XtNiconMask,
|
|
1458 XCreateBitmapFromData(gui.dpy,
|
|
1459 DefaultRootWindow(gui.dpy),
|
|
1460 (char *)vim_mask_icon_bits,
|
|
1461 vim_mask_icon_width,
|
|
1462 vim_mask_icon_height));
|
|
1463 XtSetValues(vimShell, arg, (Cardinal)2);
|
|
1464 #else
|
|
1465 /* Use Pixmaps, looking much nicer. */
|
|
1466
|
|
1467 /* If you get an error message here, you still need to unpack the runtime
|
|
1468 * archive! */
|
|
1469 # ifdef magick
|
|
1470 # undef magick
|
|
1471 # endif
|
|
1472 # define magick vim32x32
|
|
1473 # include "../runtime/vim32x32.xpm"
|
|
1474 # undef magick
|
|
1475 # define magick vim16x16
|
|
1476 # include "../runtime/vim16x16.xpm"
|
|
1477 # undef magick
|
|
1478 # define magick vim48x48
|
|
1479 # include "../runtime/vim48x48.xpm"
|
|
1480 # undef magick
|
|
1481
|
|
1482 static Pixmap icon = 0;
|
|
1483 static Pixmap icon_mask = 0;
|
|
1484 static char **magick = vim32x32;
|
|
1485 Window root_window;
|
|
1486 XIconSize *size;
|
|
1487 int number_sizes;
|
|
1488 Display *dsp;
|
|
1489 Screen *scr;
|
|
1490 XpmAttributes attr;
|
|
1491 Colormap cmap;
|
|
1492
|
|
1493 /*
|
|
1494 * Adjust the icon to the preferences of the actual window manager.
|
|
1495 */
|
|
1496 root_window = XRootWindowOfScreen(XtScreen(vimShell));
|
|
1497 if (XGetIconSizes(XtDisplay(vimShell), root_window,
|
|
1498 &size, &number_sizes) != 0)
|
|
1499 {
|
|
1500
|
|
1501 if (number_sizes > 0)
|
|
1502 {
|
|
1503 if (size->max_height >= 48 && size->max_height >= 48)
|
|
1504 magick = vim48x48;
|
|
1505 else if (size->max_height >= 32 && size->max_height >= 32)
|
|
1506 magick = vim32x32;
|
|
1507 else if (size->max_height >= 16 && size->max_height >= 16)
|
|
1508 magick = vim16x16;
|
|
1509 }
|
|
1510 }
|
|
1511
|
|
1512 dsp = XtDisplay(vimShell);
|
|
1513 scr = XtScreen(vimShell);
|
|
1514
|
|
1515 cmap = DefaultColormap(dsp, DefaultScreen(dsp));
|
|
1516 XtVaSetValues(vimShell, XtNcolormap, cmap, NULL);
|
|
1517
|
|
1518 attr.valuemask = 0L;
|
|
1519 attr.valuemask = XpmCloseness | XpmReturnPixels | XpmColormap | XpmDepth;
|
|
1520 attr.closeness = 65535; /* accuracy isn't crucial */
|
|
1521 attr.colormap = cmap;
|
|
1522 attr.depth = DefaultDepthOfScreen(scr);
|
|
1523
|
|
1524 if (!icon)
|
|
1525 XpmCreatePixmapFromData(dsp, root_window, magick, &icon,
|
|
1526 &icon_mask, &attr);
|
|
1527
|
|
1528 # ifdef FEAT_GUI_ATHENA
|
|
1529 XtVaSetValues(vimShell, XtNiconPixmap, icon, XtNiconMask, icon_mask, NULL);
|
|
1530 # else
|
|
1531 XtVaSetValues(vimShell, XmNiconPixmap, icon, XmNiconMask, icon_mask, NULL);
|
|
1532 # endif
|
|
1533 #endif
|
|
1534 }
|
|
1535
|
|
1536 if (gui.color_approx)
|
|
1537 EMSG(_("Vim E458: Cannot allocate colormap entry, some colors may be incorrect"));
|
|
1538
|
|
1539 #ifdef FEAT_SUN_WORKSHOP
|
|
1540 if (usingSunWorkShop)
|
|
1541 workshop_connect(app_context);
|
|
1542 #endif
|
|
1543
|
|
1544 #ifdef FEAT_BEVAL
|
|
1545 gui_init_tooltip_font();
|
|
1546 #endif
|
|
1547 #ifdef FEAT_MENU
|
|
1548 gui_init_menu_font();
|
|
1549 #endif
|
|
1550
|
|
1551 #ifdef USE_XSMP
|
|
1552 /* Attach listener on ICE connection */
|
|
1553 if (-1 != xsmp_icefd)
|
|
1554 _xsmp_xtinputid = XtAppAddInput(app_context, xsmp_icefd,
|
|
1555 (XtPointer)XtInputReadMask, local_xsmp_handle_requests, NULL);
|
|
1556 #endif
|
|
1557
|
|
1558 return OK;
|
|
1559 }
|
|
1560
|
|
1561 /*
|
|
1562 * Called when starting the GUI fails after calling gui_mch_init().
|
|
1563 */
|
|
1564 void
|
|
1565 gui_mch_uninit()
|
|
1566 {
|
|
1567 gui_x11_destroy_widgets();
|
|
1568 #ifndef LESSTIF_VERSION
|
|
1569 XtCloseDisplay(gui.dpy);
|
|
1570 #endif
|
|
1571 gui.dpy = NULL;
|
|
1572 vimShell = (Widget)0;
|
|
1573 }
|
|
1574
|
|
1575 /*
|
|
1576 * Called when the foreground or background color has been changed.
|
|
1577 */
|
|
1578 void
|
|
1579 gui_mch_new_colors()
|
|
1580 {
|
|
1581 long_u gc_mask;
|
|
1582 XGCValues gc_vals;
|
|
1583
|
|
1584 gc_mask = GCForeground | GCBackground;
|
|
1585 gc_vals.foreground = gui.norm_pixel;
|
|
1586 gc_vals.background = gui.back_pixel;
|
|
1587 if (gui.text_gc != NULL)
|
|
1588 XChangeGC(gui.dpy, gui.text_gc, gc_mask, &gc_vals);
|
|
1589
|
|
1590 gc_vals.foreground = gui.back_pixel;
|
|
1591 gc_vals.background = gui.norm_pixel;
|
|
1592 if (gui.back_gc != NULL)
|
|
1593 XChangeGC(gui.dpy, gui.back_gc, gc_mask, &gc_vals);
|
|
1594
|
|
1595 gc_mask |= GCFunction;
|
|
1596 gc_vals.foreground = gui.norm_pixel ^ gui.back_pixel;
|
|
1597 gc_vals.background = gui.norm_pixel ^ gui.back_pixel;
|
|
1598 gc_vals.function = GXxor;
|
|
1599 if (gui.invert_gc != NULL)
|
|
1600 XChangeGC(gui.dpy, gui.invert_gc, gc_mask, &gc_vals);
|
|
1601
|
|
1602 gui_x11_set_back_color();
|
|
1603 }
|
|
1604
|
|
1605 /*
|
|
1606 * Open the GUI window which was created by a call to gui_mch_init().
|
|
1607 */
|
|
1608 int
|
|
1609 gui_mch_open()
|
|
1610 {
|
|
1611 /* Actually open the window */
|
|
1612 XtPopup(vimShell, XtGrabNone);
|
|
1613
|
|
1614 gui.wid = gui_x11_get_wid();
|
|
1615 gui.blank_pointer = gui_x11_create_blank_mouse();
|
|
1616
|
|
1617 /*
|
|
1618 * Add a callback for the Close item on the window managers menu, and the
|
|
1619 * save-yourself event.
|
|
1620 */
|
|
1621 wm_atoms[SAVE_YOURSELF_IDX] =
|
|
1622 XInternAtom(gui.dpy, "WM_SAVE_YOURSELF", False);
|
|
1623 wm_atoms[DELETE_WINDOW_IDX] =
|
|
1624 XInternAtom(gui.dpy, "WM_DELETE_WINDOW", False);
|
|
1625 XSetWMProtocols(gui.dpy, XtWindow(vimShell), wm_atoms, 2);
|
|
1626 XtAddEventHandler(vimShell, NoEventMask, True, gui_x11_wm_protocol_handler,
|
|
1627 NULL);
|
|
1628 #ifdef HAVE_X11_XMU_EDITRES_H
|
|
1629 /*
|
|
1630 * Enable editres protocol (see "man editres").
|
|
1631 * Usually will need to add -lXmu to the linker line as well.
|
|
1632 */
|
|
1633 XtAddEventHandler(vimShell, (EventMask)0, True, _XEditResCheckMessages,
|
|
1634 (XtPointer)NULL);
|
|
1635 #endif
|
|
1636
|
|
1637 #ifdef FEAT_CLIENTSERVER
|
|
1638 if (serverName == NULL && serverDelayedStartName != NULL)
|
|
1639 {
|
|
1640 /* This is a :gui command in a plain vim with no previous server */
|
|
1641 commWindow = XtWindow(vimShell);
|
|
1642 (void)serverRegisterName(gui.dpy, serverDelayedStartName);
|
|
1643 }
|
|
1644 else
|
|
1645 {
|
|
1646 /*
|
|
1647 * Cannot handle "widget-less" windows with XtProcessEvent() we'll
|
|
1648 * have to change the "server" registration to that of the main window
|
|
1649 * If we have not registered a name yet, remember the window
|
|
1650 */
|
|
1651 serverChangeRegisteredWindow(gui.dpy, XtWindow(vimShell));
|
|
1652 }
|
|
1653 XtAddEventHandler(vimShell, PropertyChangeMask, False,
|
|
1654 gui_x11_send_event_handler, NULL);
|
|
1655 #endif
|
|
1656
|
|
1657
|
|
1658 #if defined(FEAT_MENU) && defined(FEAT_GUI_ATHENA)
|
|
1659 /* The Athena GUI needs this again after opening the window */
|
|
1660 gui_position_menu();
|
|
1661 # ifdef FEAT_TOOLBAR
|
|
1662 gui_mch_set_toolbar_pos(0, gui.menu_height, gui.menu_width,
|
|
1663 gui.toolbar_height);
|
|
1664 # endif
|
|
1665 #endif
|
|
1666
|
|
1667 /* Get the colors for the highlight groups (gui_check_colors() might have
|
|
1668 * changed them) */
|
|
1669 highlight_gui_started(); /* re-init colors and fonts */
|
|
1670
|
|
1671 #ifdef FEAT_HANGULIN
|
|
1672 hangul_keyboard_set();
|
|
1673 #endif
|
|
1674 #ifdef FEAT_XIM
|
|
1675 xim_init();
|
|
1676 #endif
|
|
1677 #ifdef FEAT_SUN_WORKSHOP
|
|
1678 workshop_postinit();
|
|
1679 #endif
|
|
1680
|
|
1681 return OK;
|
|
1682 }
|
|
1683
|
|
1684 #if defined(FEAT_BEVAL) || defined(PROTO)
|
|
1685 /*
|
|
1686 * Convert the tooltip fontset name to an XFontSet.
|
|
1687 */
|
|
1688 void
|
|
1689 gui_init_tooltip_font()
|
|
1690 {
|
|
1691 XrmValue from, to;
|
|
1692
|
|
1693 from.addr = (char *)gui.rsrc_tooltip_font_name;
|
|
1694 from.size = strlen(from.addr);
|
|
1695 to.addr = (XtPointer)&gui.tooltip_fontset;
|
|
1696 to.size = sizeof(XFontSet);
|
|
1697
|
|
1698 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False)
|
|
1699 {
|
|
1700 /* Failed. What to do? */
|
|
1701 }
|
|
1702 }
|
|
1703 #endif
|
|
1704
|
|
1705 #if defined(FEAT_MENU) || defined(PROTO)
|
|
1706 /* Convert the menu font/fontset name to an XFontStruct/XFontset */
|
|
1707 void
|
|
1708 gui_init_menu_font()
|
|
1709 {
|
|
1710 XrmValue from, to;
|
|
1711
|
|
1712 #ifdef FONTSET_ALWAYS
|
|
1713 from.addr = (char *)gui.rsrc_menu_font_name;
|
|
1714 from.size = strlen(from.addr);
|
|
1715 to.addr = (XtPointer)&gui.menu_fontset;
|
|
1716 to.size = sizeof(GuiFontset);
|
|
1717
|
|
1718 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontSet, &to) == False)
|
|
1719 {
|
|
1720 /* Failed. What to do? */
|
|
1721 }
|
|
1722 #else
|
|
1723 from.addr = (char *)gui.rsrc_menu_font_name;
|
|
1724 from.size = strlen(from.addr);
|
|
1725 to.addr = (XtPointer)&gui.menu_font;
|
|
1726 to.size = sizeof(GuiFont);
|
|
1727
|
|
1728 if (XtConvertAndStore(vimShell, XtRString, &from, XtRFontStruct, &to) == False)
|
|
1729 {
|
|
1730 /* Failed. What to do? */
|
|
1731 }
|
|
1732 #endif
|
|
1733 }
|
|
1734 #endif
|
|
1735
|
|
1736 /*ARGSUSED*/
|
|
1737 void
|
|
1738 gui_mch_exit(rc)
|
|
1739 int rc;
|
|
1740 {
|
|
1741 #if 0
|
|
1742 /* Lesstif gives an error message here, and so does Solaris. The man page
|
|
1743 * says that this isn't needed when exiting, so just skip it. */
|
|
1744 XtCloseDisplay(gui.dpy);
|
|
1745 #endif
|
|
1746 }
|
|
1747
|
|
1748 /*
|
|
1749 * Get the position of the top left corner of the window.
|
|
1750 */
|
|
1751 int
|
|
1752 gui_mch_get_winpos(x, y)
|
|
1753 int *x, *y;
|
|
1754 {
|
|
1755 Dimension xpos, ypos;
|
|
1756
|
|
1757 XtVaGetValues(vimShell,
|
|
1758 XtNx, &xpos,
|
|
1759 XtNy, &ypos,
|
|
1760 NULL);
|
|
1761 *x = xpos;
|
|
1762 *y = ypos;
|
|
1763 return OK;
|
|
1764 }
|
|
1765
|
|
1766 /*
|
|
1767 * Set the position of the top left corner of the window to the given
|
|
1768 * coordinates.
|
|
1769 */
|
|
1770 void
|
|
1771 gui_mch_set_winpos(x, y)
|
|
1772 int x, y;
|
|
1773 {
|
|
1774 XtVaSetValues(vimShell,
|
|
1775 XtNx, x,
|
|
1776 XtNy, y,
|
|
1777 NULL);
|
|
1778 }
|
|
1779
|
|
1780 void
|
|
1781 gui_mch_set_shellsize(width, height, min_width, min_height,
|
|
1782 base_width, base_height)
|
|
1783 int width;
|
|
1784 int height;
|
|
1785 int min_width;
|
|
1786 int min_height;
|
|
1787 int base_width;
|
|
1788 int base_height;
|
|
1789 {
|
|
1790 XtVaSetValues(vimShell,
|
|
1791 XtNwidthInc, gui.char_width,
|
|
1792 XtNheightInc, gui.char_height,
|
|
1793 #if defined(XtSpecificationRelease) && XtSpecificationRelease >= 4
|
|
1794 XtNbaseWidth, base_width,
|
|
1795 XtNbaseHeight, base_height,
|
|
1796 #endif
|
|
1797 XtNminWidth, min_width,
|
|
1798 XtNminHeight, min_height,
|
|
1799 XtNwidth, width,
|
|
1800 #ifdef FEAT_XIM
|
|
1801 XtNheight, height + xim_get_status_area_height(),
|
|
1802 #else
|
|
1803 XtNheight, height,
|
|
1804 #endif
|
|
1805 NULL);
|
|
1806 }
|
|
1807
|
|
1808 /*
|
|
1809 * Allow 10 pixels for horizontal borders, 30 for vertical borders.
|
|
1810 * Is there no way in X to find out how wide the borders really are?
|
|
1811 */
|
|
1812 void
|
|
1813 gui_mch_get_screen_dimensions(screen_w, screen_h)
|
|
1814 int *screen_w;
|
|
1815 int *screen_h;
|
|
1816 {
|
|
1817 *screen_w = DisplayWidth(gui.dpy, DefaultScreen(gui.dpy)) - 10;
|
|
1818 *screen_h = DisplayHeight(gui.dpy, DefaultScreen(gui.dpy)) - p_ghr;
|
|
1819 }
|
|
1820
|
|
1821 /*
|
|
1822 * Initialise vim to use the font "font_name". If it's NULL, pick a default
|
|
1823 * font.
|
|
1824 * If "fontset" is TRUE, load the "font_name" as a fontset.
|
|
1825 * Return FAIL if the font could not be loaded, OK otherwise.
|
|
1826 */
|
|
1827 /*ARGSUSED*/
|
|
1828 int
|
|
1829 gui_mch_init_font(font_name, do_fontset)
|
|
1830 char_u *font_name;
|
|
1831 int do_fontset;
|
|
1832 {
|
|
1833 XFontStruct *font = NULL;
|
|
1834
|
|
1835 #ifdef FEAT_XFONTSET
|
|
1836 XFontSet fontset = NULL;
|
|
1837
|
|
1838 if (do_fontset)
|
|
1839 {
|
|
1840 /* If 'guifontset' is set, VIM treats all font specifications as if
|
|
1841 * they were fontsets, and 'guifontset' becomes the default. */
|
|
1842 if (font_name != NULL)
|
|
1843 {
|
|
1844 fontset = (XFontSet)gui_mch_get_fontset(font_name, FALSE, TRUE);
|
|
1845 if (fontset == NULL)
|
|
1846 return FAIL;
|
|
1847 }
|
|
1848 }
|
|
1849 else
|
|
1850 #endif
|
|
1851 {
|
|
1852 if (font_name == NULL)
|
|
1853 {
|
|
1854 /*
|
|
1855 * If none of the fonts in 'font' could be loaded, try the one set
|
|
1856 * in the X resource, and finally just try using DFLT_FONT, which
|
|
1857 * will hopefully always be there.
|
|
1858 */
|
|
1859 font_name = gui.rsrc_font_name;
|
|
1860 font = (XFontStruct *)gui_mch_get_font(font_name, FALSE);
|
|
1861 if (font == NULL)
|
|
1862 font_name = (char_u *)DFLT_FONT;
|
|
1863 }
|
|
1864 if (font == NULL)
|
|
1865 font = (XFontStruct *)gui_mch_get_font(font_name, FALSE);
|
|
1866 if (font == NULL)
|
|
1867 return FAIL;
|
|
1868 }
|
|
1869
|
|
1870 gui_mch_free_font(gui.norm_font);
|
|
1871 #ifdef FEAT_XFONTSET
|
|
1872 gui_mch_free_fontset(gui.fontset);
|
|
1873
|
|
1874 if (fontset != NULL)
|
|
1875 {
|
|
1876 gui.norm_font = NOFONT;
|
|
1877 gui.fontset = (GuiFontset)fontset;
|
|
1878 gui.char_width = fontset_width(fontset);
|
|
1879 gui.char_height = fontset_height(fontset) + p_linespace;
|
|
1880 gui.char_ascent = fontset_ascent(fontset) + p_linespace / 2;
|
|
1881 }
|
|
1882 else
|
|
1883 #endif
|
|
1884 {
|
|
1885 gui.norm_font = (GuiFont)font;
|
|
1886 #ifdef FEAT_XFONTSET
|
|
1887 gui.fontset = NOFONTSET;
|
|
1888 #endif
|
|
1889 gui.char_width = font->max_bounds.width;
|
|
1890 gui.char_height = font->ascent + font->descent + p_linespace;
|
|
1891 gui.char_ascent = font->ascent + p_linespace / 2;
|
|
1892 }
|
|
1893
|
|
1894 hl_set_font_name(font_name);
|
|
1895
|
|
1896 /*
|
|
1897 * Try to load other fonts for bold, italic, and bold-italic.
|
|
1898 * We should also try to work out what font to use for these when they are
|
|
1899 * not specified by X resources, but we don't yet.
|
|
1900 */
|
|
1901 if (font_name == gui.rsrc_font_name)
|
|
1902 {
|
|
1903 if (gui.bold_font == NOFONT
|
|
1904 && gui.rsrc_bold_font_name != NULL
|
|
1905 && *gui.rsrc_bold_font_name != NUL)
|
|
1906 gui.bold_font = gui_mch_get_font(gui.rsrc_bold_font_name, FALSE);
|
|
1907 if (gui.ital_font == NOFONT
|
|
1908 && gui.rsrc_ital_font_name != NULL
|
|
1909 && *gui.rsrc_ital_font_name != NUL)
|
|
1910 gui.ital_font = gui_mch_get_font(gui.rsrc_ital_font_name, FALSE);
|
|
1911 if (gui.boldital_font == NOFONT
|
|
1912 && gui.rsrc_boldital_font_name != NULL
|
|
1913 && *gui.rsrc_boldital_font_name != NUL)
|
|
1914 gui.boldital_font = gui_mch_get_font(gui.rsrc_boldital_font_name,
|
|
1915 FALSE);
|
|
1916 }
|
|
1917 else
|
|
1918 {
|
|
1919 /* When not using the font specified by the resources, also don't use
|
|
1920 * the bold/italic fonts, otherwise setting 'guifont' will look very
|
|
1921 * strange. */
|
|
1922 if (gui.bold_font != NOFONT)
|
|
1923 {
|
|
1924 XFreeFont(gui.dpy, (XFontStruct *)gui.bold_font);
|
|
1925 gui.bold_font = NOFONT;
|
|
1926 }
|
|
1927 if (gui.ital_font != NOFONT)
|
|
1928 {
|
|
1929 XFreeFont(gui.dpy, (XFontStruct *)gui.ital_font);
|
|
1930 gui.ital_font = NOFONT;
|
|
1931 }
|
|
1932 if (gui.boldital_font != NOFONT)
|
|
1933 {
|
|
1934 XFreeFont(gui.dpy, (XFontStruct *)gui.boldital_font);
|
|
1935 gui.boldital_font = NOFONT;
|
|
1936 }
|
|
1937 }
|
|
1938
|
|
1939 return OK;
|
|
1940 }
|
|
1941
|
|
1942 /*
|
|
1943 * Get a font structure for highlighting.
|
|
1944 */
|
|
1945 GuiFont
|
|
1946 gui_mch_get_font(name, giveErrorIfMissing)
|
|
1947 char_u *name;
|
|
1948 int giveErrorIfMissing;
|
|
1949 {
|
|
1950 XFontStruct *font;
|
|
1951
|
|
1952 if (!gui.in_use || name == NULL) /* can't do this when GUI not running */
|
|
1953 return NOFONT;
|
|
1954
|
|
1955 font = XLoadQueryFont(gui.dpy, (char *)name);
|
|
1956
|
|
1957 if (font == NULL)
|
|
1958 {
|
|
1959 if (giveErrorIfMissing)
|
|
1960 EMSG2(_(e_font), name);
|
|
1961 return NOFONT;
|
|
1962 }
|
|
1963
|
|
1964 #ifdef DEBUG
|
|
1965 printf("Font Information for '%s':\n", name);
|
|
1966 printf(" w = %d, h = %d, ascent = %d, descent = %d\n",
|
|
1967 font->max_bounds.width, font->ascent + font->descent,
|
|
1968 font->ascent, font->descent);
|
|
1969 printf(" max ascent = %d, max descent = %d, max h = %d\n",
|
|
1970 font->max_bounds.ascent, font->max_bounds.descent,
|
|
1971 font->max_bounds.ascent + font->max_bounds.descent);
|
|
1972 printf(" min lbearing = %d, min rbearing = %d\n",
|
|
1973 font->min_bounds.lbearing, font->min_bounds.rbearing);
|
|
1974 printf(" max lbearing = %d, max rbearing = %d\n",
|
|
1975 font->max_bounds.lbearing, font->max_bounds.rbearing);
|
|
1976 printf(" leftink = %d, rightink = %d\n",
|
|
1977 (font->min_bounds.lbearing < 0),
|
|
1978 (font->max_bounds.rbearing > font->max_bounds.width));
|
|
1979 printf("\n");
|
|
1980 #endif
|
|
1981
|
|
1982 if (font->max_bounds.width != font->min_bounds.width)
|
|
1983 {
|
|
1984 EMSG2(_(e_fontwidth), name);
|
|
1985 XFreeFont(gui.dpy, font);
|
|
1986 return NOFONT;
|
|
1987 }
|
|
1988 return (GuiFont)font;
|
|
1989 }
|
|
1990
|
38
|
1991 /*
|
|
1992 * Return the name of font "font" in allocated memory.
|
|
1993 * Don't know how to get the actual name, thus use the provided name.
|
|
1994 */
|
|
1995 char_u *
|
|
1996 gui_mch_get_fontname(font, name)
|
|
1997 GuiFont font;
|
|
1998 char_u *name;
|
|
1999 {
|
|
2000 if (name == NULL)
|
|
2001 return NULL;
|
|
2002 return vim_strsave(name);
|
|
2003 }
|
|
2004
|
7
|
2005 int
|
|
2006 gui_mch_adjust_charsize()
|
|
2007 {
|
|
2008 #ifdef FEAT_XFONTSET
|
|
2009 if (gui.fontset != NOFONTSET)
|
|
2010 {
|
|
2011 gui.char_height = fontset_height((XFontSet)gui.fontset) + p_linespace;
|
|
2012 gui.char_ascent = fontset_ascent((XFontSet)gui.fontset)
|
|
2013 + p_linespace / 2;
|
|
2014 }
|
|
2015 else
|
|
2016 #endif
|
|
2017 {
|
|
2018 XFontStruct *font = (XFontStruct *)gui.norm_font;
|
|
2019
|
|
2020 gui.char_height = font->ascent + font->descent + p_linespace;
|
|
2021 gui.char_ascent = font->ascent + p_linespace / 2;
|
|
2022 }
|
|
2023 return OK;
|
|
2024 }
|
|
2025
|
|
2026 /*
|
|
2027 * Set the current text font.
|
|
2028 */
|
|
2029 void
|
|
2030 gui_mch_set_font(font)
|
|
2031 GuiFont font;
|
|
2032 {
|
|
2033 static Font prev_font = (Font)-1;
|
|
2034 Font fid = ((XFontStruct *)font)->fid;
|
|
2035
|
|
2036 if (fid != prev_font)
|
|
2037 {
|
|
2038 XSetFont(gui.dpy, gui.text_gc, fid);
|
|
2039 XSetFont(gui.dpy, gui.back_gc, fid);
|
|
2040 prev_font = fid;
|
|
2041 gui.char_ascent = ((XFontStruct *)font)->ascent + p_linespace / 2;
|
|
2042 }
|
|
2043 #ifdef FEAT_XFONTSET
|
|
2044 current_fontset = (XFontSet)NULL;
|
|
2045 #endif
|
|
2046 }
|
|
2047
|
|
2048 #if defined(FEAT_XFONTSET) || defined(PROTO)
|
|
2049 /*
|
|
2050 * Set the current text fontset.
|
|
2051 * Adjust the ascent, in case it's different.
|
|
2052 */
|
|
2053 void
|
|
2054 gui_mch_set_fontset(fontset)
|
|
2055 GuiFontset fontset;
|
|
2056 {
|
|
2057 current_fontset = (XFontSet)fontset;
|
|
2058 gui.char_ascent = fontset_ascent(current_fontset) + p_linespace / 2;
|
|
2059 }
|
|
2060 #endif
|
|
2061
|
|
2062 #if 0 /* not used */
|
|
2063 /*
|
|
2064 * Return TRUE if the two fonts given are equivalent.
|
|
2065 */
|
|
2066 int
|
|
2067 gui_mch_same_font(f1, f2)
|
|
2068 GuiFont f1;
|
|
2069 GuiFont f2;
|
|
2070 {
|
|
2071 #ifdef FEAT_XFONTSET
|
|
2072 if (gui.fontset != NULL)
|
|
2073 return f1 == f2;
|
|
2074 else
|
|
2075 #endif
|
|
2076 return ((XFontStruct *)f1)->fid == ((XFontStruct *)f2)->fid;
|
|
2077 }
|
|
2078 #endif
|
|
2079
|
|
2080 /*
|
|
2081 * If a font is not going to be used, free its structure.
|
|
2082 */
|
|
2083 void
|
|
2084 gui_mch_free_font(font)
|
|
2085 GuiFont font;
|
|
2086 {
|
|
2087 if (font != NOFONT)
|
|
2088 XFreeFont(gui.dpy, (XFontStruct *)font);
|
|
2089 }
|
|
2090
|
|
2091 #if defined(FEAT_XFONTSET) || defined(PROTO)
|
|
2092 /*
|
|
2093 * If a fontset is not going to be used, free its structure.
|
|
2094 */
|
|
2095 void
|
|
2096 gui_mch_free_fontset(fontset)
|
|
2097 GuiFontset fontset;
|
|
2098 {
|
|
2099 if (fontset != NOFONTSET)
|
|
2100 XFreeFontSet(gui.dpy, (XFontSet)fontset);
|
|
2101 }
|
|
2102
|
|
2103 /*
|
|
2104 * Load the fontset "name".
|
|
2105 * Return a reference to the fontset, or NOFONTSET when failing.
|
|
2106 */
|
|
2107 GuiFontset
|
|
2108 gui_mch_get_fontset(name, giveErrorIfMissing, fixed_width)
|
|
2109 char_u *name;
|
|
2110 int giveErrorIfMissing;
|
|
2111 int fixed_width;
|
|
2112 {
|
|
2113 XFontSet fontset;
|
|
2114 char **missing, *def_str;
|
|
2115 int num_missing;
|
|
2116
|
|
2117 if (!gui.in_use || name == NULL)
|
|
2118 return NOFONTSET;
|
|
2119
|
|
2120 fontset = XCreateFontSet(gui.dpy, (char *)name, &missing, &num_missing,
|
|
2121 &def_str);
|
|
2122 if (num_missing > 0)
|
|
2123 {
|
|
2124 int i;
|
|
2125
|
|
2126 if (giveErrorIfMissing)
|
|
2127 {
|
|
2128 EMSG2(_("E250: Fonts for the following charsets are missing in fontset %s:"), name);
|
|
2129 for (i = 0; i < num_missing; i++)
|
|
2130 EMSG2("%s", missing[i]);
|
|
2131 }
|
|
2132 XFreeStringList(missing);
|
|
2133 }
|
|
2134
|
|
2135 if (fontset == NULL)
|
|
2136 {
|
|
2137 if (giveErrorIfMissing)
|
|
2138 EMSG2(_(e_fontset), name);
|
|
2139 return NOFONTSET;
|
|
2140 }
|
|
2141
|
|
2142 if (fixed_width && check_fontset_sanity(fontset) == FAIL)
|
|
2143 {
|
|
2144 XFreeFontSet(gui.dpy, fontset);
|
|
2145 return NOFONTSET;
|
|
2146 }
|
|
2147 return (GuiFontset)fontset;
|
|
2148 }
|
|
2149
|
|
2150 /*
|
|
2151 * Check if fontset "fs" is fixed width.
|
|
2152 */
|
|
2153 static int
|
|
2154 check_fontset_sanity(fs)
|
|
2155 XFontSet fs;
|
|
2156 {
|
|
2157 XFontStruct **xfs;
|
|
2158 char **font_name;
|
|
2159 int fn;
|
|
2160 char *base_name;
|
|
2161 int i;
|
|
2162 int min_width;
|
|
2163 int min_font_idx = 0;
|
|
2164
|
|
2165 base_name = XBaseFontNameListOfFontSet(fs);
|
|
2166 fn = XFontsOfFontSet(fs, &xfs, &font_name);
|
|
2167 for (i = 0; i < fn; i++)
|
|
2168 {
|
|
2169 if (xfs[i]->max_bounds.width != xfs[i]->min_bounds.width)
|
|
2170 {
|
|
2171 EMSG2(_("E252: Fontset name: %s"), base_name);
|
|
2172 EMSG2(_("Font '%s' is not fixed-width"), font_name[i]);
|
|
2173 return FAIL;
|
|
2174 }
|
|
2175 }
|
|
2176 /* scan base font width */
|
|
2177 min_width = 32767;
|
|
2178 for (i = 0; i < fn; i++)
|
|
2179 {
|
|
2180 if (xfs[i]->max_bounds.width<min_width)
|
|
2181 {
|
|
2182 min_width = xfs[i]->max_bounds.width;
|
|
2183 min_font_idx = i;
|
|
2184 }
|
|
2185 }
|
|
2186 for (i = 0; i < fn; i++)
|
|
2187 {
|
|
2188 if ( xfs[i]->max_bounds.width != 2 * min_width
|
|
2189 && xfs[i]->max_bounds.width != min_width)
|
|
2190 {
|
|
2191 EMSG2(_("E253: Fontset name: %s\n"), base_name);
|
|
2192 EMSG2(_("Font0: %s\n"), font_name[min_font_idx]);
|
|
2193 EMSG2(_("Font1: %s\n"), font_name[i]);
|
|
2194 EMSGN(_("Font%ld width is not twice that of font0\n"), i);
|
|
2195 EMSGN(_("Font0 width: %ld\n"), xfs[min_font_idx]->max_bounds.width);
|
|
2196 EMSGN(_("Font1 width: %ld\n\n"), xfs[i]->max_bounds.width);
|
|
2197 return FAIL;
|
|
2198 }
|
|
2199 }
|
|
2200 /* it seems ok. Good Luck!! */
|
|
2201 return OK;
|
|
2202 }
|
|
2203
|
|
2204 static int
|
|
2205 fontset_width(fs)
|
|
2206 XFontSet fs;
|
|
2207 {
|
|
2208 return XmbTextEscapement(fs, "Vim", 3) / 3;
|
|
2209 }
|
|
2210
|
|
2211 int
|
|
2212 fontset_height(fs)
|
|
2213 XFontSet fs;
|
|
2214 {
|
|
2215 XFontSetExtents *extents;
|
|
2216
|
|
2217 extents = XExtentsOfFontSet(fs);
|
|
2218 return extents->max_logical_extent.height;
|
|
2219 }
|
|
2220
|
|
2221 #if (defined(FONTSET_ALWAYS) && defined(FEAT_GUI_ATHENA) \
|
|
2222 && defined(FEAT_MENU)) || defined(PROTO)
|
|
2223 /*
|
|
2224 * Returns the bounding box height around the actual glyph image of all
|
|
2225 * characters in all fonts of the fontset.
|
|
2226 */
|
|
2227 int
|
|
2228 fontset_height2(fs)
|
|
2229 XFontSet fs;
|
|
2230 {
|
|
2231 XFontSetExtents *extents;
|
|
2232
|
|
2233 extents = XExtentsOfFontSet(fs);
|
|
2234 return extents->max_ink_extent.height;
|
|
2235 }
|
|
2236 #endif
|
|
2237
|
|
2238 /* NOT USED YET
|
|
2239 static int
|
|
2240 fontset_descent(fs)
|
|
2241 XFontSet fs;
|
|
2242 {
|
|
2243 XFontSetExtents *extents;
|
|
2244
|
|
2245 extents = XExtentsOfFontSet (fs);
|
|
2246 return extents->max_logical_extent.height + extents->max_logical_extent.y;
|
|
2247 }
|
|
2248 */
|
|
2249
|
|
2250 static int
|
|
2251 fontset_ascent(fs)
|
|
2252 XFontSet fs;
|
|
2253 {
|
|
2254 XFontSetExtents *extents;
|
|
2255
|
|
2256 extents = XExtentsOfFontSet(fs);
|
|
2257 return -extents->max_logical_extent.y;
|
|
2258 }
|
|
2259
|
|
2260 #endif /* FEAT_XFONTSET */
|
|
2261
|
|
2262 /*
|
|
2263 * Return the Pixel value (color) for the given color name.
|
|
2264 * Return INVALCOLOR for error.
|
|
2265 */
|
|
2266 guicolor_T
|
|
2267 gui_mch_get_color(reqname)
|
|
2268 char_u *reqname;
|
|
2269 {
|
|
2270 int i;
|
|
2271 char_u *name = reqname;
|
|
2272 Colormap colormap;
|
|
2273 XColor color;
|
|
2274 static char *(vimnames[][2]) =
|
|
2275 {
|
|
2276 /* A number of colors that some X11 systems don't have */
|
|
2277 {"LightRed", "#FFBBBB"},
|
|
2278 {"LightGreen", "#88FF88"},
|
|
2279 {"LightMagenta","#FFBBFF"},
|
|
2280 {"DarkCyan", "#008888"},
|
|
2281 {"DarkBlue", "#0000BB"},
|
|
2282 {"DarkRed", "#BB0000"},
|
|
2283 {"DarkMagenta", "#BB00BB"},
|
|
2284 {"DarkGrey", "#BBBBBB"},
|
|
2285 {"DarkYellow", "#BBBB00"},
|
|
2286 {NULL, NULL}
|
|
2287 };
|
|
2288
|
|
2289 /* can't do this when GUI not running */
|
|
2290 if (!gui.in_use || *reqname == NUL)
|
|
2291 return INVALCOLOR;
|
|
2292
|
|
2293 colormap = DefaultColormap(gui.dpy, XDefaultScreen(gui.dpy));
|
|
2294
|
|
2295 /* Do this twice if the name isn't recognized. */
|
|
2296 while (name != NULL)
|
|
2297 {
|
|
2298 i = XParseColor(gui.dpy, colormap, (char *)name, &color);
|
|
2299
|
|
2300 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
|
|
2301 if (i == 0)
|
|
2302 {
|
|
2303 char *old;
|
|
2304
|
|
2305 /* The X11 system is trying to resolve named colors only by names
|
|
2306 * corresponding to the current locale language. But Vim scripts
|
|
2307 * usually contain the English color names. Therefore we have to
|
|
2308 * try a second time here with the native "C" locale set.
|
|
2309 * Hopefully, restoring the old locale this way works on all
|
|
2310 * systems...
|
|
2311 */
|
|
2312 old = setlocale(LC_ALL, NULL);
|
|
2313 if (old != NULL && STRCMP(old, "C") != 0)
|
|
2314 {
|
|
2315 old = (char *)vim_strsave((char_u *)old);
|
|
2316 setlocale(LC_ALL, "C");
|
|
2317 i = XParseColor(gui.dpy, colormap, (char *)name, &color);
|
|
2318 setlocale(LC_ALL, old);
|
|
2319 vim_free(old);
|
|
2320 }
|
|
2321 }
|
|
2322 #endif
|
|
2323 if (i != 0 && (XAllocColor(gui.dpy, colormap, &color) != 0
|
|
2324 || find_closest_color(colormap, &color) == OK))
|
|
2325 return (guicolor_T)color.pixel;
|
|
2326
|
|
2327 /* check for a few builtin names */
|
|
2328 for (i = 0; ; ++i)
|
|
2329 {
|
|
2330 if (vimnames[i][0] == NULL)
|
|
2331 {
|
|
2332 name = NULL;
|
|
2333 break;
|
|
2334 }
|
|
2335 if (STRICMP(name, vimnames[i][0]) == 0)
|
|
2336 {
|
|
2337 name = (char_u *)vimnames[i][1];
|
|
2338 break;
|
|
2339 }
|
|
2340 }
|
|
2341 }
|
|
2342
|
|
2343 return INVALCOLOR;
|
|
2344 }
|
|
2345
|
|
2346 /*
|
|
2347 * Find closest color for "colorPtr" in "colormap". set "colorPtr" to the
|
|
2348 * resulting color.
|
|
2349 * Based on a similar function in TCL.
|
|
2350 * Return FAIL if not able to find or allocate a color.
|
|
2351 */
|
|
2352 static int
|
|
2353 find_closest_color(colormap, colorPtr)
|
|
2354 Colormap colormap;
|
|
2355 XColor *colorPtr;
|
|
2356 {
|
|
2357 double tmp, distance, closestDistance;
|
|
2358 int i, closest, numFound, cmap_size;
|
|
2359 XColor *colortable;
|
|
2360 XVisualInfo template, *visInfoPtr;
|
|
2361
|
|
2362 template.visualid = XVisualIDFromVisual(DefaultVisual(gui.dpy,
|
|
2363 XDefaultScreen(gui.dpy)));
|
|
2364 visInfoPtr = XGetVisualInfo(gui.dpy, (long)VisualIDMask,
|
|
2365 &template, &numFound);
|
|
2366 if (numFound < 1)
|
|
2367 /* FindClosestColor couldn't lookup visual */
|
|
2368 return FAIL;
|
|
2369
|
|
2370 cmap_size = visInfoPtr->colormap_size;
|
|
2371 XFree((char *)visInfoPtr);
|
|
2372 colortable = (XColor *)alloc((unsigned)(cmap_size * sizeof(XColor)));
|
|
2373 if (!colortable)
|
|
2374 return FAIL; /* out of memory */
|
|
2375
|
|
2376 for (i = 0; i < cmap_size; i++)
|
|
2377 colortable[i].pixel = (unsigned long)i;
|
|
2378 XQueryColors (gui.dpy, colormap, colortable, cmap_size);
|
|
2379
|
|
2380 /*
|
|
2381 * Find the color that best approximates the desired one, then
|
|
2382 * try to allocate that color. If that fails, it must mean that
|
|
2383 * the color was read-write (so we can't use it, since it's owner
|
|
2384 * might change it) or else it was already freed. Try again,
|
|
2385 * over and over again, until something succeeds.
|
|
2386 */
|
|
2387 closestDistance = 1e30;
|
|
2388 closest = 0;
|
|
2389 for (i = 0; i < cmap_size; i++)
|
|
2390 {
|
|
2391 /*
|
|
2392 * Use Euclidean distance in RGB space, weighted by Y (of YIQ)
|
|
2393 * as the objective function; this accounts for differences
|
|
2394 * in the color sensitivity of the eye.
|
|
2395 */
|
|
2396 tmp = .30 * (((int)colorPtr->red) - (int)colortable[i].red);
|
|
2397 distance = tmp * tmp;
|
|
2398 tmp = .61 * (((int)colorPtr->green) - (int)colortable[i].green);
|
|
2399 distance += tmp * tmp;
|
|
2400 tmp = .11 * (((int)colorPtr->blue) - (int)colortable[i].blue);
|
|
2401 distance += tmp * tmp;
|
|
2402 if (distance < closestDistance)
|
|
2403 {
|
|
2404 closest = i;
|
|
2405 closestDistance = distance;
|
|
2406 }
|
|
2407 }
|
|
2408
|
|
2409 if (XAllocColor(gui.dpy, colormap, &colortable[closest]) != 0)
|
|
2410 {
|
|
2411 gui.color_approx = TRUE;
|
|
2412 *colorPtr = colortable[closest];
|
|
2413 }
|
|
2414
|
|
2415 free(colortable);
|
|
2416 return OK;
|
|
2417 }
|
|
2418
|
|
2419 void
|
|
2420 gui_mch_set_fg_color(color)
|
|
2421 guicolor_T color;
|
|
2422 {
|
|
2423 if (color != prev_fg_color)
|
|
2424 {
|
|
2425 XSetForeground(gui.dpy, gui.text_gc, (Pixel)color);
|
|
2426 prev_fg_color = color;
|
|
2427 }
|
|
2428 }
|
|
2429
|
|
2430 /*
|
|
2431 * Set the current text background color.
|
|
2432 */
|
|
2433 void
|
|
2434 gui_mch_set_bg_color(color)
|
|
2435 guicolor_T color;
|
|
2436 {
|
|
2437 if (color != prev_bg_color)
|
|
2438 {
|
|
2439 XSetBackground(gui.dpy, gui.text_gc, (Pixel)color);
|
|
2440 prev_bg_color = color;
|
|
2441 }
|
|
2442 }
|
|
2443
|
|
2444 /*
|
|
2445 * create a mouse pointer that is blank
|
|
2446 */
|
|
2447 static Cursor
|
|
2448 gui_x11_create_blank_mouse()
|
|
2449 {
|
|
2450 Pixmap blank_pixmap = XCreatePixmap(gui.dpy, gui.wid, 1, 1, 1);
|
|
2451 GC gc = XCreateGC(gui.dpy, blank_pixmap, (unsigned long)0, (XGCValues*)0);
|
|
2452 XDrawPoint(gui.dpy, blank_pixmap, gc, 0, 0);
|
|
2453 XFreeGC(gui.dpy, gc);
|
|
2454 return XCreatePixmapCursor(gui.dpy, blank_pixmap, blank_pixmap,
|
|
2455 (XColor*)&gui.norm_pixel, (XColor*)&gui.norm_pixel, 0, 0);
|
|
2456 }
|
|
2457
|
|
2458 void
|
|
2459 gui_mch_draw_string(row, col, s, len, flags)
|
|
2460 int row;
|
|
2461 int col;
|
|
2462 char_u *s;
|
|
2463 int len;
|
|
2464 int flags;
|
|
2465 {
|
|
2466 int cells = len;
|
|
2467 #ifdef FEAT_MBYTE
|
|
2468 static XChar2b *buf = NULL;
|
|
2469 static int buflen = 0;
|
|
2470 char_u *p;
|
|
2471 int wlen = 0;
|
|
2472 int c;
|
|
2473
|
|
2474 if (enc_utf8)
|
|
2475 {
|
|
2476 /* Convert UTF-8 byte sequence to 16 bit characters for the X
|
|
2477 * functions. Need a buffer for the 16 bit characters. Keep it
|
|
2478 * between calls, because allocating it each time is slow. */
|
|
2479 if (buflen < len)
|
|
2480 {
|
|
2481 XtFree((char *)buf);
|
|
2482 buf = (XChar2b *)XtMalloc(len * sizeof(XChar2b));
|
|
2483 buflen = len;
|
|
2484 }
|
|
2485 p = s;
|
|
2486 cells = 0;
|
|
2487 while (p < s + len)
|
|
2488 {
|
|
2489 c = utf_ptr2char(p);
|
|
2490 if (c >= 0x10000) /* show chars > 0xffff as ? */
|
|
2491 c = 0xbf;
|
|
2492 buf[wlen].byte1 = (unsigned)c >> 8;
|
|
2493 buf[wlen].byte2 = c;
|
|
2494 ++wlen;
|
|
2495 cells += utf_char2cells(c);
|
|
2496 p += utf_ptr2len_check(p);
|
|
2497 }
|
|
2498 }
|
|
2499 else if (has_mbyte)
|
|
2500 {
|
|
2501 cells = 0;
|
|
2502 for (p = s; p < s + len; )
|
|
2503 {
|
|
2504 cells += ptr2cells(p);
|
|
2505 p += (*mb_ptr2len_check)(p);
|
|
2506 }
|
|
2507 }
|
|
2508
|
|
2509 #endif
|
|
2510
|
|
2511 #ifdef FEAT_XFONTSET
|
|
2512 if (current_fontset != NULL)
|
|
2513 {
|
|
2514 /* Setup a clip rectangle to avoid spilling over in the next or
|
|
2515 * previous line. This is apparently needed for some fonts which are
|
|
2516 * used in a fontset. */
|
|
2517 XRectangle clip;
|
|
2518
|
|
2519 clip.x = 0;
|
|
2520 clip.y = 0;
|
|
2521 clip.height = gui.char_height;
|
|
2522 clip.width = gui.char_width * cells + 1;
|
|
2523 XSetClipRectangles(gui.dpy, gui.text_gc, FILL_X(col), FILL_Y(row),
|
|
2524 &clip, 1, Unsorted);
|
|
2525 }
|
|
2526 #endif
|
|
2527
|
|
2528 if (flags & DRAW_TRANSP)
|
|
2529 {
|
|
2530 #ifdef FEAT_MBYTE
|
|
2531 if (enc_utf8)
|
|
2532 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2533 TEXT_Y(row), buf, wlen);
|
|
2534 else
|
|
2535 #endif
|
|
2536 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2537 TEXT_Y(row), (char *)s, len);
|
|
2538 }
|
|
2539 else if (p_linespace != 0
|
|
2540 #ifdef FEAT_XFONTSET
|
|
2541 || current_fontset != NULL
|
|
2542 #endif
|
|
2543 )
|
|
2544 {
|
|
2545 XSetForeground(gui.dpy, gui.text_gc, prev_bg_color);
|
|
2546 XFillRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(col),
|
|
2547 FILL_Y(row), gui.char_width * cells, gui.char_height);
|
|
2548 XSetForeground(gui.dpy, gui.text_gc, prev_fg_color);
|
|
2549 #ifdef FEAT_MBYTE
|
|
2550 if (enc_utf8)
|
|
2551 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2552 TEXT_Y(row), buf, wlen);
|
|
2553 else
|
|
2554 #endif
|
|
2555 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2556 TEXT_Y(row), (char *)s, len);
|
|
2557 }
|
|
2558 else
|
|
2559 {
|
|
2560 /* XmbDrawImageString has bug, don't use it for fontset. */
|
|
2561 #ifdef FEAT_MBYTE
|
|
2562 if (enc_utf8)
|
|
2563 XDrawImageString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2564 TEXT_Y(row), buf, wlen);
|
|
2565 else
|
|
2566 #endif
|
|
2567 XDrawImageString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col),
|
|
2568 TEXT_Y(row), (char *)s, len);
|
|
2569 }
|
|
2570
|
|
2571 /* Bold trick: draw the text again with a one-pixel offset. */
|
|
2572 if (flags & DRAW_BOLD)
|
|
2573 {
|
|
2574 #ifdef FEAT_MBYTE
|
|
2575 if (enc_utf8)
|
|
2576 XDrawString16(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1,
|
|
2577 TEXT_Y(row), buf, wlen);
|
|
2578 else
|
|
2579 #endif
|
|
2580 XDrawString(gui.dpy, gui.wid, gui.text_gc, TEXT_X(col) + 1,
|
|
2581 TEXT_Y(row), (char *)s, len);
|
|
2582 }
|
|
2583
|
|
2584 /* Underline: draw a line at the bottom of the character cell. */
|
|
2585 if (flags & DRAW_UNDERL)
|
|
2586 XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col),
|
|
2587 FILL_Y(row + 1) - 1, FILL_X(col + cells) - 1, FILL_Y(row + 1) - 1);
|
|
2588
|
|
2589 #ifdef FEAT_XFONTSET
|
|
2590 if (current_fontset != NULL)
|
|
2591 XSetClipMask(gui.dpy, gui.text_gc, None);
|
|
2592 #endif
|
|
2593 }
|
|
2594
|
|
2595 /*
|
|
2596 * Return OK if the key with the termcap name "name" is supported.
|
|
2597 */
|
|
2598 int
|
|
2599 gui_mch_haskey(name)
|
|
2600 char_u *name;
|
|
2601 {
|
|
2602 int i;
|
|
2603
|
|
2604 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++)
|
|
2605 if (name[0] == special_keys[i].vim_code0 &&
|
|
2606 name[1] == special_keys[i].vim_code1)
|
|
2607 return OK;
|
|
2608 return FAIL;
|
|
2609 }
|
|
2610
|
|
2611 /*
|
|
2612 * Return the text window-id and display. Only required for X-based GUI's
|
|
2613 */
|
|
2614 int
|
|
2615 gui_get_x11_windis(win, dis)
|
|
2616 Window *win;
|
|
2617 Display **dis;
|
|
2618 {
|
|
2619 *win = XtWindow(vimShell);
|
|
2620 *dis = gui.dpy;
|
|
2621 return OK;
|
|
2622 }
|
|
2623
|
|
2624 void
|
|
2625 gui_mch_beep()
|
|
2626 {
|
|
2627 XBell(gui.dpy, 0);
|
|
2628 }
|
|
2629
|
|
2630 void
|
|
2631 gui_mch_flash(msec)
|
|
2632 int msec;
|
|
2633 {
|
|
2634 /* Do a visual beep by reversing the foreground and background colors */
|
|
2635 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0,
|
|
2636 FILL_X((int)Columns) + gui.border_offset,
|
|
2637 FILL_Y((int)Rows) + gui.border_offset);
|
|
2638 XSync(gui.dpy, False);
|
|
2639 ui_delay((long)msec, TRUE); /* wait for a few msec */
|
|
2640 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc, 0, 0,
|
|
2641 FILL_X((int)Columns) + gui.border_offset,
|
|
2642 FILL_Y((int)Rows) + gui.border_offset);
|
|
2643 }
|
|
2644
|
|
2645 /*
|
|
2646 * Invert a rectangle from row r, column c, for nr rows and nc columns.
|
|
2647 */
|
|
2648 void
|
|
2649 gui_mch_invert_rectangle(r, c, nr, nc)
|
|
2650 int r;
|
|
2651 int c;
|
|
2652 int nr;
|
|
2653 int nc;
|
|
2654 {
|
|
2655 XFillRectangle(gui.dpy, gui.wid, gui.invert_gc,
|
|
2656 FILL_X(c), FILL_Y(r), (nc) * gui.char_width, (nr) * gui.char_height);
|
|
2657 }
|
|
2658
|
|
2659 /*
|
|
2660 * Iconify the GUI window.
|
|
2661 */
|
|
2662 void
|
|
2663 gui_mch_iconify()
|
|
2664 {
|
|
2665 XIconifyWindow(gui.dpy, XtWindow(vimShell), DefaultScreen(gui.dpy));
|
|
2666 }
|
|
2667
|
|
2668 #if defined(FEAT_EVAL) || defined(PROTO)
|
|
2669 /*
|
|
2670 * Bring the Vim window to the foreground.
|
|
2671 */
|
|
2672 void
|
|
2673 gui_mch_set_foreground()
|
|
2674 {
|
|
2675 XMapRaised(gui.dpy, XtWindow(vimShell));
|
|
2676 }
|
|
2677 #endif
|
|
2678
|
|
2679 /*
|
|
2680 * Draw a cursor without focus.
|
|
2681 */
|
|
2682 void
|
|
2683 gui_mch_draw_hollow_cursor(color)
|
|
2684 guicolor_T color;
|
|
2685 {
|
|
2686 int w = 1;
|
|
2687
|
|
2688 #ifdef FEAT_MBYTE
|
|
2689 if (mb_lefthalve(gui.row, gui.col))
|
|
2690 w = 2;
|
|
2691 #endif
|
|
2692 gui_mch_set_fg_color(color);
|
|
2693 XDrawRectangle(gui.dpy, gui.wid, gui.text_gc, FILL_X(gui.col),
|
|
2694 FILL_Y(gui.row), w * gui.char_width - 1, gui.char_height - 1);
|
|
2695 }
|
|
2696
|
|
2697 /*
|
|
2698 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
|
|
2699 * color "color".
|
|
2700 */
|
|
2701 void
|
|
2702 gui_mch_draw_part_cursor(w, h, color)
|
|
2703 int w;
|
|
2704 int h;
|
|
2705 guicolor_T color;
|
|
2706 {
|
|
2707 gui_mch_set_fg_color(color);
|
|
2708
|
|
2709 XFillRectangle(gui.dpy, gui.wid, gui.text_gc,
|
|
2710 #ifdef FEAT_RIGHTLEFT
|
|
2711 /* vertical line should be on the right of current point */
|
|
2712 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w :
|
|
2713 #endif
|
|
2714 FILL_X(gui.col),
|
|
2715 FILL_Y(gui.row) + gui.char_height - h,
|
|
2716 w, h);
|
|
2717 }
|
|
2718
|
|
2719 /*
|
|
2720 * Catch up with any queued X events. This may put keyboard input into the
|
|
2721 * input buffer, call resize call-backs, trigger timers etc. If there is
|
|
2722 * nothing in the X event queue (& no timers pending), then we return
|
|
2723 * immediately.
|
|
2724 */
|
|
2725 void
|
|
2726 gui_mch_update()
|
|
2727 {
|
|
2728 XtInputMask mask, desired;
|
|
2729
|
|
2730 #ifdef ALT_X_INPUT
|
|
2731 if (suppress_alternate_input)
|
|
2732 desired = (XtIMXEvent | XtIMTimer);
|
|
2733 else
|
|
2734 #endif
|
|
2735 desired = (XtIMAll);
|
|
2736 while ((mask = XtAppPending(app_context)) && (mask & desired)
|
|
2737 && !vim_is_input_buf_full())
|
|
2738 XtAppProcessEvent(app_context, desired);
|
|
2739 }
|
|
2740
|
|
2741 /*
|
|
2742 * GUI input routine called by gui_wait_for_chars(). Waits for a character
|
|
2743 * from the keyboard.
|
|
2744 * wtime == -1 Wait forever.
|
|
2745 * wtime == 0 This should never happen.
|
|
2746 * wtime > 0 Wait wtime milliseconds for a character.
|
|
2747 * Returns OK if a character was found to be available within the given time,
|
|
2748 * or FAIL otherwise.
|
|
2749 */
|
|
2750 int
|
|
2751 gui_mch_wait_for_chars(wtime)
|
|
2752 long wtime;
|
|
2753 {
|
|
2754 int focus;
|
|
2755
|
|
2756 /*
|
|
2757 * Make this static, in case gui_x11_timer_cb is called after leaving
|
|
2758 * this function (otherwise a random value on the stack may be changed).
|
|
2759 */
|
|
2760 static int timed_out;
|
|
2761 XtIntervalId timer = (XtIntervalId)0;
|
|
2762 XtInputMask desired;
|
|
2763 #ifdef FEAT_SNIFF
|
|
2764 static int sniff_on = 0;
|
|
2765 static XtInputId sniff_input_id = 0;
|
|
2766 #endif
|
|
2767
|
|
2768 timed_out = FALSE;
|
|
2769
|
|
2770 #ifdef FEAT_SNIFF
|
|
2771 if (sniff_on && !want_sniff_request)
|
|
2772 {
|
|
2773 if (sniff_input_id)
|
|
2774 XtRemoveInput(sniff_input_id);
|
|
2775 sniff_on = 0;
|
|
2776 }
|
|
2777 else if (!sniff_on && want_sniff_request)
|
|
2778 {
|
|
2779 sniff_input_id = XtAppAddInput(app_context, fd_from_sniff,
|
|
2780 (XtPointer)XtInputReadMask, gui_x11_sniff_request_cb, 0);
|
|
2781 sniff_on = 1;
|
|
2782 }
|
|
2783 #endif
|
|
2784
|
|
2785 if (wtime > 0)
|
|
2786 timer = XtAppAddTimeOut(app_context, (long_u)wtime, gui_x11_timer_cb,
|
|
2787 &timed_out);
|
|
2788
|
|
2789 focus = gui.in_focus;
|
|
2790 #ifdef ALT_X_INPUT
|
|
2791 if (suppress_alternate_input)
|
|
2792 desired = (XtIMXEvent | XtIMTimer);
|
|
2793 else
|
|
2794 #endif
|
|
2795 desired = (XtIMAll);
|
|
2796 while (!timed_out)
|
|
2797 {
|
|
2798 /* Stop or start blinking when focus changes */
|
|
2799 if (gui.in_focus != focus)
|
|
2800 {
|
|
2801 if (gui.in_focus)
|
|
2802 gui_mch_start_blink();
|
|
2803 else
|
|
2804 gui_mch_stop_blink();
|
|
2805 focus = gui.in_focus;
|
|
2806 }
|
|
2807
|
|
2808 /*
|
|
2809 * Don't use gui_mch_update() because then we will spin-lock until a
|
|
2810 * char arrives, instead we use XtAppProcessEvent() to hang until an
|
|
2811 * event arrives. No need to check for input_buf_full because we are
|
|
2812 * returning as soon as it contains a single char. Note that
|
|
2813 * XtAppNextEvent() may not be used because it will not return after a
|
|
2814 * timer event has arrived -- webb
|
|
2815 */
|
|
2816 XtAppProcessEvent(app_context, desired);
|
|
2817
|
|
2818 if (input_available())
|
|
2819 {
|
|
2820 if (timer != (XtIntervalId)0 && !timed_out)
|
|
2821 XtRemoveTimeOut(timer);
|
|
2822 return OK;
|
|
2823 }
|
|
2824 }
|
|
2825 return FAIL;
|
|
2826 }
|
|
2827
|
|
2828 /*
|
|
2829 * Output routines.
|
|
2830 */
|
|
2831
|
|
2832 /* Flush any output to the screen */
|
|
2833 void
|
|
2834 gui_mch_flush()
|
|
2835 {
|
|
2836 XFlush(gui.dpy);
|
|
2837 }
|
|
2838
|
|
2839 /*
|
|
2840 * Clear a rectangular region of the screen from text pos (row1, col1) to
|
|
2841 * (row2, col2) inclusive.
|
|
2842 */
|
|
2843 void
|
|
2844 gui_mch_clear_block(row1, col1, row2, col2)
|
|
2845 int row1;
|
|
2846 int col1;
|
|
2847 int row2;
|
|
2848 int col2;
|
|
2849 {
|
|
2850 int x;
|
|
2851
|
|
2852 x = FILL_X(col1);
|
|
2853
|
|
2854 /* Clear one extra pixel at the far right, for when bold characters have
|
|
2855 * spilled over to the next column. */
|
|
2856 XFillRectangle(gui.dpy, gui.wid, gui.back_gc, x, FILL_Y(row1),
|
|
2857 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1),
|
|
2858 (row2 - row1 + 1) * gui.char_height);
|
|
2859 }
|
|
2860
|
|
2861 void
|
|
2862 gui_mch_clear_all()
|
|
2863 {
|
|
2864 XClearArea(gui.dpy, gui.wid, 0, 0, 0, 0, False);
|
|
2865 }
|
|
2866
|
|
2867 /*
|
|
2868 * Delete the given number of lines from the given row, scrolling up any
|
|
2869 * text further down within the scroll region.
|
|
2870 */
|
|
2871 void
|
|
2872 gui_mch_delete_lines(row, num_lines)
|
|
2873 int row;
|
|
2874 int num_lines;
|
|
2875 {
|
|
2876 if (gui.visibility == VisibilityFullyObscured)
|
|
2877 return; /* Can't see the window */
|
|
2878
|
|
2879 /* copy one extra pixel at the far right, for when bold has spilled
|
|
2880 * over */
|
|
2881 XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc,
|
|
2882 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
|
|
2883 gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1)
|
|
2884 + (gui.scroll_region_right == Columns - 1),
|
|
2885 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
2886 FILL_X(gui.scroll_region_left), FILL_Y(row));
|
|
2887
|
|
2888 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
|
|
2889 gui.scroll_region_left,
|
|
2890 gui.scroll_region_bot, gui.scroll_region_right);
|
|
2891 gui_x11_check_copy_area();
|
|
2892 }
|
|
2893
|
|
2894 /*
|
|
2895 * Insert the given number of lines before the given row, scrolling down any
|
|
2896 * following text within the scroll region.
|
|
2897 */
|
|
2898 void
|
|
2899 gui_mch_insert_lines(row, num_lines)
|
|
2900 int row;
|
|
2901 int num_lines;
|
|
2902 {
|
|
2903 if (gui.visibility == VisibilityFullyObscured)
|
|
2904 return; /* Can't see the window */
|
|
2905
|
|
2906 /* copy one extra pixel at the far right, for when bold has spilled
|
|
2907 * over */
|
|
2908 XCopyArea(gui.dpy, gui.wid, gui.wid, gui.text_gc,
|
|
2909 FILL_X(gui.scroll_region_left), FILL_Y(row),
|
|
2910 gui.char_width * (gui.scroll_region_right - gui.scroll_region_left + 1)
|
|
2911 + (gui.scroll_region_right == Columns - 1),
|
|
2912 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
2913 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines));
|
|
2914
|
|
2915 gui_clear_block(row, gui.scroll_region_left,
|
|
2916 row + num_lines - 1, gui.scroll_region_right);
|
|
2917 gui_x11_check_copy_area();
|
|
2918 }
|
|
2919
|
|
2920 /*
|
|
2921 * Update the region revealed by scrolling up/down.
|
|
2922 */
|
|
2923 static void
|
|
2924 gui_x11_check_copy_area()
|
|
2925 {
|
|
2926 XEvent event;
|
|
2927 XGraphicsExposeEvent *gevent;
|
|
2928
|
|
2929 if (gui.visibility != VisibilityPartiallyObscured)
|
|
2930 return;
|
|
2931
|
|
2932 XFlush(gui.dpy);
|
|
2933
|
|
2934 /* Wait to check whether the scroll worked or not */
|
|
2935 for (;;)
|
|
2936 {
|
|
2937 if (XCheckTypedEvent(gui.dpy, NoExpose, &event))
|
|
2938 return; /* The scroll worked. */
|
|
2939
|
|
2940 if (XCheckTypedEvent(gui.dpy, GraphicsExpose, &event))
|
|
2941 {
|
|
2942 gevent = (XGraphicsExposeEvent *)&event;
|
|
2943 gui_redraw(gevent->x, gevent->y, gevent->width, gevent->height);
|
|
2944 if (gevent->count == 0)
|
|
2945 return; /* This was the last expose event */
|
|
2946 }
|
|
2947 XSync(gui.dpy, False);
|
|
2948 }
|
|
2949 }
|
|
2950
|
|
2951 /*
|
|
2952 * X Selection stuff, for cutting and pasting text to other windows.
|
|
2953 */
|
|
2954
|
|
2955 void
|
|
2956 clip_mch_lose_selection(cbd)
|
|
2957 VimClipboard *cbd;
|
|
2958 {
|
|
2959 clip_x11_lose_selection(vimShell, cbd);
|
|
2960 }
|
|
2961
|
|
2962 int
|
|
2963 clip_mch_own_selection(cbd)
|
|
2964 VimClipboard *cbd;
|
|
2965 {
|
|
2966 return clip_x11_own_selection(vimShell, cbd);
|
|
2967 }
|
|
2968
|
|
2969 void
|
|
2970 clip_mch_request_selection(cbd)
|
|
2971 VimClipboard *cbd;
|
|
2972 {
|
|
2973 clip_x11_request_selection(vimShell, gui.dpy, cbd);
|
|
2974 }
|
|
2975
|
|
2976 void
|
|
2977 clip_mch_set_selection(cbd)
|
|
2978 VimClipboard *cbd;
|
|
2979 {
|
|
2980 clip_x11_set_selection(cbd);
|
|
2981 }
|
|
2982
|
|
2983 #if defined(FEAT_MENU) || defined(PROTO)
|
|
2984 /*
|
|
2985 * Menu stuff.
|
|
2986 */
|
|
2987
|
|
2988 /*
|
|
2989 * Make a menu either grey or not grey.
|
|
2990 */
|
|
2991 void
|
|
2992 gui_mch_menu_grey(menu, grey)
|
|
2993 vimmenu_T *menu;
|
|
2994 int grey;
|
|
2995 {
|
|
2996 if (menu->id != (Widget)0)
|
|
2997 {
|
|
2998 gui_mch_menu_hidden(menu, False);
|
|
2999 if (grey
|
|
3000 #ifdef FEAT_GUI_MOTIF
|
|
3001 || !menu->sensitive
|
|
3002 #endif
|
|
3003 )
|
|
3004 XtSetSensitive(menu->id, False);
|
|
3005 else
|
|
3006 XtSetSensitive(menu->id, True);
|
|
3007 }
|
|
3008 }
|
|
3009
|
|
3010 /*
|
|
3011 * Make menu item hidden or not hidden
|
|
3012 */
|
|
3013 void
|
|
3014 gui_mch_menu_hidden(menu, hidden)
|
|
3015 vimmenu_T *menu;
|
|
3016 int hidden;
|
|
3017 {
|
|
3018 if (menu->id != (Widget)0)
|
|
3019 {
|
|
3020 if (hidden)
|
|
3021 XtUnmanageChild(menu->id);
|
|
3022 else
|
|
3023 XtManageChild(menu->id);
|
|
3024 }
|
|
3025 }
|
|
3026
|
|
3027 /*
|
|
3028 * This is called after setting all the menus to grey/hidden or not.
|
|
3029 */
|
|
3030 void
|
|
3031 gui_mch_draw_menubar()
|
|
3032 {
|
|
3033 /* Nothing to do in X */
|
|
3034 }
|
|
3035
|
|
3036 /* ARGSUSED */
|
|
3037 void
|
|
3038 gui_x11_menu_cb(w, client_data, call_data)
|
|
3039 Widget w;
|
|
3040 XtPointer client_data, call_data;
|
|
3041 {
|
|
3042 gui_menu_cb((vimmenu_T *)client_data);
|
|
3043 }
|
|
3044
|
|
3045 #endif /* FEAT_MENU */
|
|
3046
|
|
3047
|
|
3048
|
|
3049 /*
|
|
3050 * Function called when window closed. Works like ":qa".
|
|
3051 * Should put up a requester!
|
|
3052 */
|
|
3053 /*ARGSUSED*/
|
|
3054 static void
|
|
3055 gui_x11_wm_protocol_handler(w, client_data, event, dum)
|
|
3056 Widget w;
|
|
3057 XtPointer client_data;
|
|
3058 XEvent *event;
|
|
3059 Boolean *dum;
|
|
3060 {
|
|
3061 /*
|
|
3062 * Only deal with Client messages.
|
|
3063 */
|
|
3064 if (event->type != ClientMessage)
|
|
3065 return;
|
|
3066
|
|
3067 /*
|
|
3068 * The WM_SAVE_YOURSELF event arrives when the window manager wants to
|
|
3069 * exit. That can be cancelled though, thus Vim shouldn't exit here.
|
|
3070 * Just sync our swap files.
|
|
3071 */
|
|
3072 if (((XClientMessageEvent *)event)->data.l[0] ==
|
|
3073 wm_atoms[SAVE_YOURSELF_IDX])
|
|
3074 {
|
|
3075 out_flush();
|
|
3076 ml_sync_all(FALSE, FALSE); /* preserve all swap files */
|
|
3077
|
|
3078 /* Set the window's WM_COMMAND property, to let the window manager
|
|
3079 * know we are done saving ourselves. We don't want to be restarted,
|
|
3080 * thus set argv to NULL. */
|
|
3081 XSetCommand(gui.dpy, XtWindow(vimShell), NULL, 0);
|
|
3082 return;
|
|
3083 }
|
|
3084
|
|
3085 if (((XClientMessageEvent *)event)->data.l[0] !=
|
|
3086 wm_atoms[DELETE_WINDOW_IDX])
|
|
3087 return;
|
|
3088
|
|
3089 gui_shell_closed();
|
|
3090 }
|
|
3091
|
|
3092 #ifdef FEAT_CLIENTSERVER
|
|
3093 /*
|
|
3094 * Function called when property changed. Check for incoming commands
|
|
3095 */
|
|
3096 /*ARGSUSED*/
|
|
3097 static void
|
|
3098 gui_x11_send_event_handler(w, client_data, event, dum)
|
|
3099 Widget w;
|
|
3100 XtPointer client_data;
|
|
3101 XEvent *event;
|
|
3102 Boolean *dum;
|
|
3103 {
|
|
3104 XPropertyEvent *e = (XPropertyEvent *) event;
|
|
3105
|
|
3106 if (e->type == PropertyNotify && e->window == commWindow
|
|
3107 && e->atom == commProperty && e->state == PropertyNewValue)
|
|
3108 {
|
|
3109 serverEventProc(gui.dpy, event);
|
|
3110 }
|
|
3111 }
|
|
3112 #endif
|
|
3113
|
|
3114 /*
|
|
3115 * Cursor blink functions.
|
|
3116 *
|
|
3117 * This is a simple state machine:
|
|
3118 * BLINK_NONE not blinking at all
|
|
3119 * BLINK_OFF blinking, cursor is not shown
|
|
3120 * BLINK_ON blinking, cursor is shown
|
|
3121 */
|
|
3122
|
|
3123 #define BLINK_NONE 0
|
|
3124 #define BLINK_OFF 1
|
|
3125 #define BLINK_ON 2
|
|
3126
|
|
3127 static int blink_state = BLINK_NONE;
|
|
3128 static long_u blink_waittime = 700;
|
|
3129 static long_u blink_ontime = 400;
|
|
3130 static long_u blink_offtime = 250;
|
|
3131 static XtIntervalId blink_timer = (XtIntervalId)0;
|
|
3132
|
|
3133 void
|
|
3134 gui_mch_set_blinking(waittime, on, off)
|
|
3135 long waittime, on, off;
|
|
3136 {
|
|
3137 blink_waittime = waittime;
|
|
3138 blink_ontime = on;
|
|
3139 blink_offtime = off;
|
|
3140 }
|
|
3141
|
|
3142 /*
|
|
3143 * Stop the cursor blinking. Show the cursor if it wasn't shown.
|
|
3144 */
|
|
3145 void
|
|
3146 gui_mch_stop_blink()
|
|
3147 {
|
|
3148 if (blink_timer != (XtIntervalId)0)
|
|
3149 {
|
|
3150 XtRemoveTimeOut(blink_timer);
|
|
3151 blink_timer = (XtIntervalId)0;
|
|
3152 }
|
|
3153 if (blink_state == BLINK_OFF)
|
|
3154 gui_update_cursor(TRUE, FALSE);
|
|
3155 blink_state = BLINK_NONE;
|
|
3156 }
|
|
3157
|
|
3158 /*
|
|
3159 * Start the cursor blinking. If it was already blinking, this restarts the
|
|
3160 * waiting time and shows the cursor.
|
|
3161 */
|
|
3162 void
|
|
3163 gui_mch_start_blink()
|
|
3164 {
|
|
3165 if (blink_timer != (XtIntervalId)0)
|
|
3166 XtRemoveTimeOut(blink_timer);
|
|
3167 /* Only switch blinking on if none of the times is zero */
|
|
3168 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
|
|
3169 {
|
|
3170 blink_timer = XtAppAddTimeOut(app_context, blink_waittime,
|
|
3171 gui_x11_blink_cb, NULL);
|
|
3172 blink_state = BLINK_ON;
|
|
3173 gui_update_cursor(TRUE, FALSE);
|
|
3174 }
|
|
3175 }
|
|
3176
|
|
3177 /* ARGSUSED */
|
|
3178 static void
|
|
3179 gui_x11_blink_cb(timed_out, interval_id)
|
|
3180 XtPointer timed_out;
|
|
3181 XtIntervalId *interval_id;
|
|
3182 {
|
|
3183 if (blink_state == BLINK_ON)
|
|
3184 {
|
|
3185 gui_undraw_cursor();
|
|
3186 blink_state = BLINK_OFF;
|
|
3187 blink_timer = XtAppAddTimeOut(app_context, blink_offtime,
|
|
3188 gui_x11_blink_cb, NULL);
|
|
3189 }
|
|
3190 else
|
|
3191 {
|
|
3192 gui_update_cursor(TRUE, FALSE);
|
|
3193 blink_state = BLINK_ON;
|
|
3194 blink_timer = XtAppAddTimeOut(app_context, blink_ontime,
|
|
3195 gui_x11_blink_cb, NULL);
|
|
3196 }
|
|
3197 }
|
|
3198
|
|
3199 /*
|
|
3200 * Return the RGB value of a pixel as a long.
|
|
3201 */
|
|
3202 long_u
|
|
3203 gui_mch_get_rgb(pixel)
|
|
3204 guicolor_T pixel;
|
|
3205 {
|
|
3206 XColor xc;
|
|
3207 Colormap colormap;
|
|
3208
|
|
3209 colormap = DefaultColormap(gui.dpy, XDefaultScreen(gui.dpy));
|
|
3210 xc.pixel = pixel;
|
|
3211 XQueryColor(gui.dpy, colormap, &xc);
|
|
3212
|
|
3213 return ((xc.red & 0xff00) << 8) + (xc.green & 0xff00)
|
|
3214 + ((unsigned)xc.blue >> 8);
|
|
3215 }
|
|
3216
|
|
3217 /*
|
|
3218 * Add the callback functions.
|
|
3219 */
|
|
3220 void
|
|
3221 gui_x11_callbacks(textArea, vimForm)
|
|
3222 Widget textArea;
|
|
3223 Widget vimForm;
|
|
3224 {
|
|
3225 XtAddEventHandler(textArea, VisibilityChangeMask, FALSE,
|
|
3226 gui_x11_visibility_cb, (XtPointer)0);
|
|
3227
|
|
3228 XtAddEventHandler(textArea, ExposureMask, FALSE, gui_x11_expose_cb,
|
|
3229 (XtPointer)0);
|
|
3230
|
|
3231 XtAddEventHandler(vimShell, StructureNotifyMask, FALSE,
|
|
3232 gui_x11_resize_window_cb, (XtPointer)0);
|
|
3233
|
|
3234 XtAddEventHandler(vimShell, FocusChangeMask, FALSE, gui_x11_focus_change_cb,
|
|
3235 (XtPointer)0);
|
|
3236 /*
|
|
3237 * Only install these enter/leave callbacks when 'p' in 'guioptions'.
|
|
3238 * Only needed for some window managers.
|
|
3239 */
|
|
3240 if (vim_strchr(p_go, GO_POINTER) != NULL)
|
|
3241 {
|
|
3242 XtAddEventHandler(vimShell, LeaveWindowMask, FALSE, gui_x11_leave_cb,
|
|
3243 (XtPointer)0);
|
|
3244 XtAddEventHandler(textArea, LeaveWindowMask, FALSE, gui_x11_leave_cb,
|
|
3245 (XtPointer)0);
|
|
3246 XtAddEventHandler(textArea, EnterWindowMask, FALSE, gui_x11_enter_cb,
|
|
3247 (XtPointer)0);
|
|
3248 XtAddEventHandler(vimShell, EnterWindowMask, FALSE, gui_x11_enter_cb,
|
|
3249 (XtPointer)0);
|
|
3250 }
|
|
3251
|
|
3252 XtAddEventHandler(vimForm, KeyPressMask, FALSE, gui_x11_key_hit_cb,
|
|
3253 (XtPointer)0);
|
|
3254 XtAddEventHandler(textArea, KeyPressMask, FALSE, gui_x11_key_hit_cb,
|
|
3255 (XtPointer)0);
|
|
3256
|
|
3257 /* get pointer moved events from scrollbar, needed for 'mousefocus' */
|
|
3258 XtAddEventHandler(vimForm, PointerMotionMask,
|
|
3259 FALSE, gui_x11_mouse_cb, (XtPointer)1);
|
|
3260 XtAddEventHandler(textArea, ButtonPressMask | ButtonReleaseMask |
|
|
3261 ButtonMotionMask | PointerMotionMask,
|
|
3262 FALSE, gui_x11_mouse_cb, (XtPointer)0);
|
|
3263 }
|
|
3264
|
|
3265 /*
|
|
3266 * Get current y mouse coordinate in text window.
|
|
3267 * Return -1 when unknown.
|
|
3268 */
|
|
3269 int
|
|
3270 gui_mch_get_mouse_x()
|
|
3271 {
|
|
3272 int rootx, rooty, winx, winy;
|
|
3273 Window root, child;
|
|
3274 unsigned int mask;
|
|
3275
|
|
3276 if (gui.wid && XQueryPointer(gui.dpy, gui.wid, &root, &child,
|
|
3277 &rootx, &rooty, &winx, &winy, &mask))
|
|
3278 return winx;
|
|
3279 return -1;
|
|
3280 }
|
|
3281
|
|
3282 int
|
|
3283 gui_mch_get_mouse_y()
|
|
3284 {
|
|
3285 int rootx, rooty, winx, winy;
|
|
3286 Window root, child;
|
|
3287 unsigned int mask;
|
|
3288
|
|
3289 if (gui.wid && XQueryPointer(gui.dpy, gui.wid, &root, &child,
|
|
3290 &rootx, &rooty, &winx, &winy, &mask))
|
|
3291 return winy;
|
|
3292 return -1;
|
|
3293 }
|
|
3294
|
|
3295 void
|
|
3296 gui_mch_setmouse(x, y)
|
|
3297 int x;
|
|
3298 int y;
|
|
3299 {
|
|
3300 if (gui.wid)
|
|
3301 XWarpPointer(gui.dpy, (Window)0, gui.wid, 0, 0, 0, 0, x, y);
|
|
3302 }
|
|
3303
|
|
3304 #if (defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)) || defined(PROTO)
|
|
3305 XButtonPressedEvent *
|
|
3306 gui_x11_get_last_mouse_event()
|
|
3307 {
|
|
3308 return &last_mouse_event;
|
|
3309 }
|
|
3310 #endif
|
|
3311
|
|
3312 #if defined(FEAT_SIGN_ICONS) || defined(PROTO)
|
|
3313
|
|
3314 /* Signs are currently always 2 chars wide. Hopefully the font is big enough
|
|
3315 * to provide room for the bitmap! */
|
|
3316 # define SIGN_WIDTH (gui.char_width * 2)
|
|
3317
|
|
3318 #if 0 /* not used */
|
|
3319 void
|
|
3320 gui_mch_clearsign(row)
|
|
3321 int row;
|
|
3322 {
|
|
3323 if (gui.in_use)
|
|
3324 XClearArea(gui.dpy, gui.wid, 0, TEXT_Y(row) - gui.char_height,
|
|
3325 SIGN_WIDTH, gui.char_height, FALSE);
|
|
3326 }
|
|
3327 #endif
|
|
3328
|
|
3329 void
|
|
3330 gui_mch_drawsign(row, col, typenr)
|
|
3331 int row;
|
|
3332 int col;
|
|
3333 int typenr;
|
|
3334 {
|
|
3335 XImage *sign;
|
|
3336
|
|
3337 if (gui.in_use && (sign = (XImage *)sign_get_image(typenr)) != NULL)
|
|
3338 {
|
|
3339 XClearArea(gui.dpy, gui.wid, TEXT_X(col), TEXT_Y(row) - sign->height,
|
|
3340 SIGN_WIDTH, gui.char_height, FALSE);
|
|
3341 XPutImage(gui.dpy, gui.wid, gui.text_gc, sign, 0, 0,
|
|
3342 TEXT_X(col) + (SIGN_WIDTH - sign->width) / 2,
|
|
3343 TEXT_Y(row) - sign->height,
|
|
3344 sign->width, sign->height);
|
|
3345 }
|
|
3346 }
|
|
3347
|
|
3348 void *
|
|
3349 gui_mch_register_sign(signfile)
|
|
3350 char_u *signfile;
|
|
3351 {
|
|
3352 XpmAttributes attrs;
|
|
3353 XImage *sign;
|
|
3354 int status;
|
|
3355
|
|
3356 /*
|
|
3357 * Setup the color substitution table.
|
|
3358 */
|
|
3359 sign = NULL;
|
|
3360 if (signfile[0] != NUL && signfile[0] != '-')
|
|
3361 {
|
|
3362 sign = (XImage *)alloc(sizeof(XImage));
|
|
3363 if (sign != NULL)
|
|
3364 {
|
|
3365 XpmColorSymbol color[5] =
|
|
3366 {
|
|
3367 {"none", NULL, 0},
|
|
3368 {"iconColor1", NULL, 0},
|
|
3369 {"bottomShadowColor", NULL, 0},
|
|
3370 {"topShadowColor", NULL, 0},
|
|
3371 {"selectColor", NULL, 0}
|
|
3372 };
|
|
3373 attrs.valuemask = XpmColorSymbols;
|
|
3374 attrs.numsymbols = 2;
|
|
3375 attrs.colorsymbols = color;
|
|
3376 attrs.colorsymbols[0].pixel = gui.back_pixel;
|
|
3377 attrs.colorsymbols[1].pixel = gui.norm_pixel;
|
|
3378 status = XpmReadFileToImage(gui.dpy, (char *)signfile,
|
|
3379 &sign, NULL, &attrs);
|
|
3380
|
|
3381 if (status == 0)
|
|
3382 {
|
|
3383 /* Sign width is fixed at two columns now.
|
|
3384 if (sign->width > gui.sign_width)
|
|
3385 gui.sign_width = sign->width + 8; */
|
|
3386 }
|
|
3387 else
|
|
3388 {
|
|
3389 vim_free(sign);
|
|
3390 sign = NULL;
|
|
3391 EMSG(_(e_signdata));
|
|
3392 }
|
|
3393 }
|
|
3394 }
|
|
3395
|
|
3396 return (void *)sign;
|
|
3397 }
|
|
3398
|
|
3399 void
|
|
3400 gui_mch_destroy_sign(sign)
|
|
3401 void *sign;
|
|
3402 {
|
|
3403 XFree(((XImage *)sign)->data);
|
|
3404 vim_free(sign);
|
|
3405 }
|
|
3406 #endif
|
|
3407
|
|
3408
|
|
3409 #ifdef FEAT_MOUSESHAPE
|
|
3410 /* The last set mouse pointer shape is remembered, to be used when it goes
|
|
3411 * from hidden to not hidden. */
|
|
3412 static int last_shape = 0;
|
|
3413 #endif
|
|
3414
|
|
3415 /*
|
|
3416 * Use the blank mouse pointer or not.
|
|
3417 */
|
|
3418 void
|
|
3419 gui_mch_mousehide(hide)
|
|
3420 int hide; /* TRUE = use blank ptr, FALSE = use parent ptr */
|
|
3421 {
|
|
3422 if (gui.pointer_hidden != hide)
|
|
3423 {
|
|
3424 gui.pointer_hidden = hide;
|
|
3425 if (hide)
|
|
3426 XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer);
|
|
3427 else
|
|
3428 #ifdef FEAT_MOUSESHAPE
|
|
3429 mch_set_mouse_shape(last_shape);
|
|
3430 #else
|
|
3431 XUndefineCursor(gui.dpy, gui.wid);
|
|
3432 #endif
|
|
3433 }
|
|
3434 }
|
|
3435
|
|
3436 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
|
|
3437
|
|
3438 /* Table for shape IDs. Keep in sync with the mshape_names[] table in
|
|
3439 * misc2.c! */
|
|
3440 static int mshape_ids[] =
|
|
3441 {
|
|
3442 XC_left_ptr, /* arrow */
|
|
3443 0, /* blank */
|
|
3444 XC_xterm, /* beam */
|
|
3445 XC_sb_v_double_arrow, /* updown */
|
|
3446 XC_sizing, /* udsizing */
|
|
3447 XC_sb_h_double_arrow, /* leftright */
|
|
3448 XC_sizing, /* lrsizing */
|
|
3449 XC_watch, /* busy */
|
|
3450 XC_X_cursor, /* no */
|
|
3451 XC_crosshair, /* crosshair */
|
|
3452 XC_hand1, /* hand1 */
|
|
3453 XC_hand2, /* hand2 */
|
|
3454 XC_pencil, /* pencil */
|
|
3455 XC_question_arrow, /* question */
|
|
3456 XC_right_ptr, /* right-arrow */
|
|
3457 XC_center_ptr, /* up-arrow */
|
|
3458 XC_left_ptr /* last one */
|
|
3459 };
|
|
3460
|
|
3461 void
|
|
3462 mch_set_mouse_shape(shape)
|
|
3463 int shape;
|
|
3464 {
|
|
3465 int id;
|
|
3466
|
|
3467 if (!gui.in_use)
|
|
3468 return;
|
|
3469
|
|
3470 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
|
|
3471 XDefineCursor(gui.dpy, gui.wid, gui.blank_pointer);
|
|
3472 else
|
|
3473 {
|
|
3474 if (shape >= MSHAPE_NUMBERED)
|
|
3475 {
|
|
3476 id = shape - MSHAPE_NUMBERED;
|
|
3477 if (id >= XC_num_glyphs)
|
|
3478 id = XC_left_ptr;
|
|
3479 else
|
|
3480 id &= ~1; /* they are always even (why?) */
|
|
3481 }
|
|
3482 else
|
|
3483 id = mshape_ids[shape];
|
|
3484
|
|
3485 XDefineCursor(gui.dpy, gui.wid, XCreateFontCursor(gui.dpy, id));
|
|
3486 }
|
|
3487 if (shape != MSHAPE_HIDE)
|
|
3488 last_shape = shape;
|
|
3489 }
|
|
3490 #endif
|
|
3491
|
|
3492 #if defined(FEAT_TOOLBAR) || defined(PROTO)
|
|
3493 /*
|
|
3494 * Icons used by the toolbar code.
|
|
3495 */
|
|
3496 #include "../pixmaps/tb_new.xpm"
|
|
3497 #include "../pixmaps/tb_open.xpm"
|
|
3498 #include "../pixmaps/tb_close.xpm"
|
|
3499 #include "../pixmaps/tb_save.xpm"
|
|
3500 #include "../pixmaps/tb_print.xpm"
|
|
3501 #include "../pixmaps/tb_cut.xpm"
|
|
3502 #include "../pixmaps/tb_copy.xpm"
|
|
3503 #include "../pixmaps/tb_paste.xpm"
|
|
3504 #include "../pixmaps/tb_find.xpm"
|
|
3505 #include "../pixmaps/tb_find_next.xpm"
|
|
3506 #include "../pixmaps/tb_find_prev.xpm"
|
|
3507 #include "../pixmaps/tb_find_help.xpm"
|
|
3508 #include "../pixmaps/tb_exit.xpm"
|
|
3509 #include "../pixmaps/tb_undo.xpm"
|
|
3510 #include "../pixmaps/tb_redo.xpm"
|
|
3511 #include "../pixmaps/tb_help.xpm"
|
|
3512 #include "../pixmaps/tb_macro.xpm"
|
|
3513 #include "../pixmaps/tb_make.xpm"
|
|
3514 #include "../pixmaps/tb_save_all.xpm"
|
|
3515 #include "../pixmaps/tb_jump.xpm"
|
|
3516 #include "../pixmaps/tb_ctags.xpm"
|
|
3517 #include "../pixmaps/tb_load_session.xpm"
|
|
3518 #include "../pixmaps/tb_save_session.xpm"
|
|
3519 #include "../pixmaps/tb_new_session.xpm"
|
|
3520 #include "../pixmaps/tb_blank.xpm"
|
|
3521 #include "../pixmaps/tb_maximize.xpm"
|
|
3522 #include "../pixmaps/tb_split.xpm"
|
|
3523 #include "../pixmaps/tb_minimize.xpm"
|
|
3524 #include "../pixmaps/tb_shell.xpm"
|
|
3525 #include "../pixmaps/tb_replace.xpm"
|
|
3526 #include "../pixmaps/tb_vsplit.xpm"
|
|
3527 #include "../pixmaps/tb_maxwidth.xpm"
|
|
3528 #include "../pixmaps/tb_minwidth.xpm"
|
|
3529
|
|
3530 /*
|
|
3531 * Those are the pixmaps used for the default buttons.
|
|
3532 */
|
|
3533 static char **(built_in_pixmaps[]) =
|
|
3534 {
|
|
3535 tb_new_xpm,
|
|
3536 tb_open_xpm,
|
|
3537 tb_save_xpm,
|
|
3538 tb_undo_xpm,
|
|
3539 tb_redo_xpm,
|
|
3540 tb_cut_xpm,
|
|
3541 tb_copy_xpm,
|
|
3542 tb_paste_xpm,
|
|
3543 tb_print_xpm,
|
|
3544 tb_help_xpm,
|
|
3545 tb_find_xpm,
|
|
3546 tb_save_all_xpm,
|
|
3547 tb_save_session_xpm,
|
|
3548 tb_new_session_xpm,
|
|
3549 tb_load_session_xpm,
|
|
3550 tb_macro_xpm,
|
|
3551 tb_replace_xpm,
|
|
3552 tb_close_xpm,
|
|
3553 tb_maximize_xpm,
|
|
3554 tb_minimize_xpm,
|
|
3555 tb_split_xpm,
|
|
3556 tb_shell_xpm,
|
|
3557 tb_find_prev_xpm,
|
|
3558 tb_find_next_xpm,
|
|
3559 tb_find_help_xpm,
|
|
3560 tb_make_xpm,
|
|
3561 tb_jump_xpm,
|
|
3562 tb_ctags_xpm,
|
|
3563 tb_vsplit_xpm,
|
|
3564 tb_maxwidth_xpm,
|
|
3565 tb_minwidth_xpm,
|
|
3566 tb_exit_xpm
|
|
3567 };
|
|
3568
|
|
3569 static void createXpmImages __ARGS((char_u *path, char **xpm, Pixmap *sen, Pixmap *insen));
|
|
3570
|
|
3571 /*
|
|
3572 * Allocated a pixmap for toolbar menu "menu".
|
|
3573 * Return in "sen" and "insen". "insen" can be NULL.
|
|
3574 */
|
|
3575 void
|
|
3576 get_toolbar_pixmap(menu, sen, insen)
|
|
3577 vimmenu_T *menu;
|
|
3578 Pixmap *sen;
|
|
3579 Pixmap *insen;
|
|
3580 {
|
|
3581 char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
|
|
3582 char **xpm = NULL; /* xpm array */
|
|
3583
|
|
3584 buf[0] = NUL; /* start with NULL path */
|
|
3585
|
|
3586 if (menu->iconfile != NULL)
|
|
3587 {
|
|
3588 /* Use the "icon=" argument. */
|
|
3589 gui_find_iconfile(menu->iconfile, buf, "xpm");
|
|
3590 createXpmImages(buf, NULL, sen, insen);
|
|
3591
|
|
3592 /* If it failed, try using the menu name. */
|
|
3593 if (*sen == (Pixmap)0 && gui_find_bitmap(menu->name, buf, "xpm") == OK)
|
|
3594 createXpmImages(buf, NULL, sen, insen);
|
|
3595 if (*sen != (Pixmap)0)
|
|
3596 return;
|
|
3597 }
|
|
3598
|
|
3599 if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
|
|
3600 {
|
|
3601 if (menu->iconidx >= 0 && menu->iconidx
|
|
3602 < (sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
|
|
3603 xpm = built_in_pixmaps[menu->iconidx];
|
|
3604 else
|
|
3605 xpm = tb_blank_xpm;
|
|
3606 }
|
|
3607
|
|
3608 if (xpm != NULL || buf[0] != NUL)
|
|
3609 createXpmImages(buf, xpm, sen, insen);
|
|
3610 }
|
|
3611
|
|
3612 /* Indices for named colors */
|
|
3613 #define BACKGROUND 0
|
|
3614 #define FOREGROUND 1
|
|
3615 #define BOTTOM_SHADOW 2
|
|
3616 #define TOP_SHADOW 3
|
|
3617 #define HIGHLIGHT 4
|
|
3618
|
|
3619 /*
|
|
3620 * Read an Xpm file, doing color substitutions for the foreground and
|
|
3621 * background colors. If there is an error reading a color xpm file,
|
|
3622 * drop back and read the monochrome file. If successful, create the
|
|
3623 * insensitive Pixmap too.
|
|
3624 */
|
|
3625 static void
|
|
3626 createXpmImages(path, xpm, sen, insen)
|
|
3627 char_u *path;
|
|
3628 char **xpm;
|
|
3629 Pixmap *sen;
|
|
3630 Pixmap *insen; /* can be NULL */
|
|
3631 {
|
|
3632 Window rootWindow;
|
|
3633 XpmAttributes attrs;
|
|
3634 XpmColorSymbol color[5] =
|
|
3635 {
|
|
3636 {"none", "none", 0},
|
|
3637 {"iconColor1", NULL, 0},
|
|
3638 {"bottomShadowColor", NULL, 0},
|
|
3639 {"topShadowColor", NULL, 0},
|
|
3640 {"selectColor", NULL, 0}
|
|
3641 };
|
|
3642 int screenNum;
|
|
3643 int status;
|
|
3644 Pixmap mask;
|
|
3645 Pixmap map;
|
|
3646
|
|
3647 gui_mch_get_toolbar_colors(
|
|
3648 &color[BACKGROUND].pixel,
|
|
3649 &color[FOREGROUND].pixel,
|
|
3650 &color[BOTTOM_SHADOW].pixel,
|
|
3651 &color[TOP_SHADOW].pixel,
|
|
3652 &color[HIGHLIGHT].pixel);
|
|
3653
|
|
3654 /* Setup the color subsititution table */
|
|
3655 attrs.valuemask = XpmColorSymbols;
|
|
3656 attrs.colorsymbols = color;
|
|
3657 attrs.numsymbols = 5;
|
|
3658
|
|
3659 screenNum = DefaultScreen(gui.dpy);
|
|
3660 rootWindow = RootWindow(gui.dpy, screenNum);
|
|
3661
|
|
3662 /* Create the "sensitive" pixmap */
|
|
3663 if (xpm != NULL)
|
|
3664 status = XpmCreatePixmapFromData(gui.dpy, rootWindow, xpm,
|
|
3665 &map, &mask, &attrs);
|
|
3666 else
|
|
3667 status = XpmReadFileToPixmap(gui.dpy, rootWindow, (char *)path,
|
|
3668 &map, &mask, &attrs);
|
|
3669 if (status == XpmSuccess && map != 0)
|
|
3670 {
|
|
3671 XGCValues gcvalues;
|
|
3672 GC back_gc;
|
|
3673 GC mask_gc;
|
|
3674
|
|
3675 /* Need to create new Pixmaps with the mask applied. */
|
|
3676 gcvalues.foreground = color[BACKGROUND].pixel;
|
|
3677 back_gc = XCreateGC(gui.dpy, map, GCForeground, &gcvalues);
|
|
3678 mask_gc = XCreateGC(gui.dpy, map, GCForeground, &gcvalues);
|
|
3679 XSetClipMask(gui.dpy, mask_gc, mask);
|
|
3680
|
|
3681 /* Create the "sensitive" pixmap. */
|
|
3682 *sen = XCreatePixmap(gui.dpy, rootWindow,
|
|
3683 attrs.width, attrs.height,
|
|
3684 DefaultDepth(gui.dpy, screenNum));
|
|
3685 XFillRectangle(gui.dpy, *sen, back_gc, 0, 0,
|
|
3686 attrs.width, attrs.height);
|
|
3687 XCopyArea(gui.dpy, map, *sen, mask_gc, 0, 0,
|
|
3688 attrs.width, attrs.height, 0, 0);
|
|
3689
|
|
3690 #ifdef FEAT_GUI_MOTIF /* not used for Athena */
|
|
3691 if (insen != NULL)
|
|
3692 {
|
|
3693 int x, y;
|
|
3694 int startX;
|
|
3695
|
|
3696 /* Create the "insensitive" pixmap. It's a copy of the "sensitive"
|
|
3697 * pixmap with half the pixels set to the background color. */
|
|
3698 *insen = XCreatePixmap(gui.dpy, rootWindow,
|
|
3699 attrs.width, attrs.height,
|
|
3700 DefaultDepth(gui.dpy, screenNum));
|
|
3701 XCopyArea(gui.dpy, *sen, *insen, back_gc, 0, 0,
|
|
3702 attrs.width, attrs.height, 0, 0);
|
|
3703 for (y = 0; y < attrs.height; y++)
|
|
3704 {
|
|
3705 if (y % 2 == 0)
|
|
3706 startX = 0;
|
|
3707 else
|
|
3708 startX = 1;
|
|
3709 for (x = startX; x < attrs.width; x += 2)
|
|
3710 XDrawPoint(gui.dpy, *insen, back_gc, x, y);
|
|
3711 }
|
|
3712
|
|
3713 }
|
|
3714 #endif
|
|
3715 XFreeGC(gui.dpy, back_gc);
|
|
3716 XFreeGC(gui.dpy, mask_gc);
|
|
3717 XFreePixmap(gui.dpy, map);
|
|
3718 }
|
|
3719 else
|
|
3720 {
|
|
3721 *sen = 0;
|
|
3722 if (insen != NULL)
|
|
3723 *insen = 0;
|
|
3724 }
|
|
3725
|
|
3726 XpmFreeAttributes(&attrs);
|
|
3727 }
|
|
3728 #endif
|
|
3729
|
|
3730 #if (defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)) || defined(PROTO)
|
|
3731 /*
|
|
3732 * Set the balloon-eval used for the tooltip of a toolbar menu item.
|
|
3733 * The check for a non-toolbar item was added, because there is a crash when
|
|
3734 * passing a normal menu item here. Can't explain that, but better avoid it.
|
|
3735 */
|
|
3736 void
|
|
3737 gui_mch_menu_set_tip(menu)
|
|
3738 vimmenu_T *menu;
|
|
3739 {
|
|
3740 if (menu->id != NULL && menu->parent != NULL
|
|
3741 && menu_is_toolbar(menu->parent->name))
|
|
3742 {
|
|
3743 /* Always destroy and create the balloon, in case the string was
|
|
3744 * changed. */
|
|
3745 if (menu->tip != NULL)
|
|
3746 {
|
|
3747 gui_mch_destroy_beval_area(menu->tip);
|
|
3748 menu->tip = NULL;
|
|
3749 }
|
|
3750 if (menu->strings[MENU_INDEX_TIP] != NULL)
|
|
3751 menu->tip = gui_mch_create_beval_area(
|
|
3752 menu->id,
|
|
3753 menu->strings[MENU_INDEX_TIP],
|
|
3754 NULL,
|
|
3755 NULL);
|
|
3756 }
|
|
3757 }
|
|
3758 #endif
|