blob: 234d25066947832b6e8682802fc345d1c4801cfa [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Photon GUI support by Julian Kinraid
5 *
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 *
9 *
10 * Clipboard support is in os_qnx.c
11 * PhAttach() is called in os_qnx.c:qnx_init()
12 */
13
14#include "vim.h"
15
Bram Moolenaar82881492012-11-20 16:53:39 +010016/* cproto fails on missing include files */
17#ifndef PROTO
18# ifdef FEAT_TOOLBAR
19# include <photon/PxImage.h>
20# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000021#endif
22
23#if !defined(__QNX__)
24/* Used when generating prototypes. */
25# define PgColor_t int
26# define PhEvent_t int
27# define PhPoint_t int
28# define PtWidget_t int
29# define Pg_BLACK 0
30# define PtCallbackF_t int
31# define PtCallbackInfo_t int
32# define PhTile_t int
33# define PtWidget_t int
34# define PhImage_t int
35#endif
36
37#define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a[0]))
Bram Moolenaard2221132011-07-27 14:09:09 +020038#define RGB(r, g, b) PgRGB(r, g, b)
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
Bram Moolenaard2221132011-07-27 14:09:09 +020040#define EVENT_BUFFER_SIZE sizeof(PhEvent_t) + 1000
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
42/* Some defines for gui_mch_mousehide() */
43#define MOUSE_HIDE TRUE
44#define MOUSE_SHOW FALSE
45
46/* Optional support for using a PtPanelGroup widget, needs work */
47#undef USE_PANEL_GROUP
48
49#ifdef USE_PANEL_GROUP
50static char *empty_title = " ";
51static char **panel_titles = NULL;
52static ushort_t num_panels = 0;
53static short pg_margin_left, pg_margin_right, pg_margin_top, pg_margin_bottom;
54#endif
55
56#define GUI_PH_MARGIN 4 /* Size of the bevel */
57
58#define GUI_PH_MOUSE_TYPE Ph_CURSOR_INSERT
59static PgColor_t gui_ph_mouse_color = Pg_BLACK;
60
61static PhPoint_t gui_ph_raw_offset;
62static PtWidget_t *gui_ph_timer_cursor; /* handle cursor blinking */
63static PtWidget_t *gui_ph_timer_timeout; /* used in gui_mch_wait_for_chars */
Bram Moolenaar84a05ac2013-05-06 04:24:17 +020064static short is_timeout; /* Has the timeout occurred? */
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66/*
67 * This is set inside the mouse callback for a right mouse
68 * button click, and used for the popup menus
69 */
70static PhPoint_t abs_mouse;
71
72/* Try and avoid redraws while a resize is in progress */
73static int is_ignore_draw = FALSE;
74
75/* Used for converting to/from utf-8 and other charsets */
76static struct PxTransCtrl *charset_translate;
77
78/*
79 * Cursor blink functions.
80 *
81 * This is a simple state machine:
82 * BLINK_NONE not blinking at all
83 * BLINK_OFF blinking, cursor is not shown
84 * BLINK_ON blinking, cursor is shown
85 */
86static enum {
87 BLINK_NONE,
88 BLINK_OFF,
89 BLINK_ON
90} blink_state = BLINK_NONE;
91
92static long_u blink_waittime = 700;
93static long_u blink_ontime = 400;
94static long_u blink_offtime = 250;
95
96static struct
97{
98 int key_sym;
99 char_u vim_code0;
100 char_u vim_code1;
101} special_keys[] =
102{
103 {Pk_Up, 'k', 'u'},
104 {Pk_Down, 'k', 'd'},
105 {Pk_Left, 'k', 'l'},
106 {Pk_Right, 'k', 'r'},
107
108 {Pk_F1, 'k', '1'},
109 {Pk_F2, 'k', '2'},
110 {Pk_F3, 'k', '3'},
111 {Pk_F4, 'k', '4'},
112 {Pk_F5, 'k', '5'},
113 {Pk_F6, 'k', '6'},
114 {Pk_F7, 'k', '7'},
115 {Pk_F8, 'k', '8'},
116 {Pk_F9, 'k', '9'},
117 {Pk_F10, 'k', ';'},
118
119 {Pk_F11, 'F', '1'},
120 {Pk_F12, 'F', '2'},
121 {Pk_F13, 'F', '3'},
122 {Pk_F14, 'F', '4'},
123 {Pk_F15, 'F', '5'},
124 {Pk_F16, 'F', '6'},
125 {Pk_F17, 'F', '7'},
126 {Pk_F18, 'F', '8'},
127 {Pk_F19, 'F', '9'},
128 {Pk_F20, 'F', 'A'},
129
130 {Pk_F21, 'F', 'B'},
131 {Pk_F22, 'F', 'C'},
132 {Pk_F23, 'F', 'D'},
133 {Pk_F24, 'F', 'E'},
134 {Pk_F25, 'F', 'F'},
135 {Pk_F26, 'F', 'G'},
136 {Pk_F27, 'F', 'H'},
137 {Pk_F28, 'F', 'I'},
138 {Pk_F29, 'F', 'J'},
139
140 {Pk_F30, 'F', 'K'},
141 {Pk_F31, 'F', 'L'},
142 {Pk_F32, 'F', 'M'},
143 {Pk_F33, 'F', 'N'},
144 {Pk_F34, 'F', 'O'},
145 {Pk_F35, 'F', 'P'},
146
147 {Pk_Help, '%', '1'},
148 {Pk_BackSpace, 'k', 'b'},
149 {Pk_Insert, 'k', 'I'},
150 {Pk_Delete, 'k', 'D'},
151 {Pk_Home, 'k', 'h'},
152 {Pk_End, '@', '7'},
153 {Pk_Prior, 'k', 'P'},
154 {Pk_Next, 'k', 'N'},
155 {Pk_Print, '%', '9'},
156
157 {Pk_KP_Add, 'K', '6'},
158 {Pk_KP_Subtract,'K', '7'},
159 {Pk_KP_Divide, 'K', '8'},
160 {Pk_KP_Multiply,'K', '9'},
161 {Pk_KP_Enter, 'K', 'A'},
162
163 {Pk_KP_0, KS_EXTRA, KE_KINS}, /* Insert */
164 {Pk_KP_Decimal, KS_EXTRA, KE_KDEL}, /* Delete */
165
166 {Pk_KP_4, 'k', 'l'}, /* Left */
167 {Pk_KP_6, 'k', 'r'}, /* Right */
168 {Pk_KP_8, 'k', 'u'}, /* Up */
169 {Pk_KP_2, 'k', 'd'}, /* Down */
170
171 {Pk_KP_7, 'K', '1'}, /* Home */
172 {Pk_KP_1, 'K', '4'}, /* End */
173
174 {Pk_KP_9, 'K', '3'}, /* Page Up */
175 {Pk_KP_3, 'K', '5'}, /* Page Down */
176
177 {Pk_KP_5, '&', '8'}, /* Undo */
178
179 /* Keys that we want to be able to use any modifier with: */
180 {Pk_Return, CAR, NUL},
181 {Pk_space, ' ', NUL},
182 {Pk_Tab, TAB, NUL},
183 {Pk_Escape, ESC, NUL},
184 {NL, NL, NUL},
185 {CAR, CAR, NUL},
186
187 /* End of list marker: */
188 {0, 0, 0}
189};
190
191
192/****************************************************************************/
193
194static PtCallbackF_t gui_ph_handle_timer_cursor;
195static PtCallbackF_t gui_ph_handle_timer_timeout;
196
197static PtCallbackF_t gui_ph_handle_window_cb;
198
199static PtCallbackF_t gui_ph_handle_scrollbar;
200static PtCallbackF_t gui_ph_handle_keyboard;
201static PtCallbackF_t gui_ph_handle_mouse;
202static PtCallbackF_t gui_ph_handle_pulldown_menu;
203static PtCallbackF_t gui_ph_handle_menu;
204static PtCallbackF_t gui_ph_handle_focus; /* focus change of text area */
205
206static PtCallbackF_t gui_ph_handle_menu_resize;
207
208/* When a menu is unrealized, give focus back to vimTextArea */
209static PtCallbackF_t gui_ph_handle_menu_unrealized;
210
211#ifdef USE_PANEL_GROUP
Bram Moolenaard2221132011-07-27 14:09:09 +0200212static void gui_ph_get_panelgroup_margins(short*, short*, short*, short*);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213#endif
214
Bram Moolenaard2221132011-07-27 14:09:09 +0200215static void gui_ph_draw_start(void);
216static void gui_ph_draw_end(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217
218/* Set the text for the balloon */
Bram Moolenaard2221132011-07-27 14:09:09 +0200219static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220 PtWidget_t *widget,
221 int position,
222 char *text,
223 char *font,
224 PgColor_t fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200225 PgColor_t text_color);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226
227/****************************************************************************/
228
Bram Moolenaard2221132011-07-27 14:09:09 +0200229static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230 PtWidget_t *widget,
231 int position,
232 char *text,
233 char *font,
234 PgColor_t fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200235 PgColor_t text_color)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236{
237 PtArg_t arg;
238 vimmenu_T *menu;
239 char_u *tooltip;
240
Bram Moolenaard2221132011-07-27 14:09:09 +0200241 PtSetArg(&arg, Pt_ARG_POINTER, &menu, 0);
242 PtGetResources(widget, 1, &arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243
244 /* Override the text and position */
245
246 tooltip = text;
Bram Moolenaard2221132011-07-27 14:09:09 +0200247 if (menu != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248 {
249 int index = MENU_INDEX_TIP;
Bram Moolenaard2221132011-07-27 14:09:09 +0200250 if (menu->strings[ index ] != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251 tooltip = menu->strings[ index ];
252 }
253
Bram Moolenaard2221132011-07-27 14:09:09 +0200254 return PtInflateBalloon(
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255 window,
256 widget,
257 /* Don't put the balloon at the bottom,
258 * it gets drawn over by gfx done in the PtRaw */
259 Pt_BALLOON_TOP,
260 tooltip,
261 font,
262 fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200263 text_color);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264}
265
266 static void
Bram Moolenaard2221132011-07-27 14:09:09 +0200267gui_ph_resize_container(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268{
269 PhArea_t area;
270
Bram Moolenaard2221132011-07-27 14:09:09 +0200271 PtWidgetArea(gui.vimWindow, &area);
272 PtWidgetPos (gui.vimContainer, &area.pos);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
Bram Moolenaard2221132011-07-27 14:09:09 +0200274 PtSetResource(gui.vimContainer, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275}
276
277 static int
278gui_ph_handle_menu_resize(
279 PtWidget_t *widget,
280 void *other,
Bram Moolenaard2221132011-07-27 14:09:09 +0200281 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282{
283 PtContainerCallback_t *sizes = info->cbdata;
284 PtWidget_t *container;
285 PhPoint_t below_menu;
286 int_u height;
287
288 height = sizes->new_dim.h;
289
Bram Moolenaarccc18222007-05-10 18:25:20 +0000290 /* Because vim treats the toolbar and menubar separately,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291 * and here they're lumped together into a PtToolbarGroup,
292 * we only need either menu_height or toolbar_height set at once */
Bram Moolenaard2221132011-07-27 14:09:09 +0200293 if (gui.menu_is_active)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000294 {
295 gui.menu_height = height;
296 gui.toolbar_height = 0;
297 }
298#ifdef FEAT_TOOLBAR
299 else
300 gui.toolbar_height = height;
301#endif
302
303 below_menu.x = 0;
304 below_menu.y = height;
305
306#ifdef USE_PANEL_GROUP
307 container = gui.vimPanelGroup;
308#else
309 container = gui.vimContainer;
310#endif
311
Bram Moolenaard2221132011-07-27 14:09:09 +0200312 PtSetResource(container, Pt_ARG_POS, &below_menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313
314 gui_ph_resize_container();
315
316#ifdef USE_PANEL_GROUP
317 gui_ph_get_panelgroup_margins(
318 &pg_margin_top, &pg_margin_bottom,
Bram Moolenaard2221132011-07-27 14:09:09 +0200319 &pg_margin_left, &pg_margin_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320#endif
Bram Moolenaard2221132011-07-27 14:09:09 +0200321 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322}
323
324/*
325 * Pt_ARG_TIMER_REPEAT isn't used because the on & off times
326 * are different
327 */
328 static int
329gui_ph_handle_timer_cursor(
330 PtWidget_t *widget,
331 void *data,
Bram Moolenaard2221132011-07-27 14:09:09 +0200332 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333{
Bram Moolenaard2221132011-07-27 14:09:09 +0200334 if (blink_state == BLINK_ON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335 {
336 gui_undraw_cursor();
337 blink_state = BLINK_OFF;
Bram Moolenaard2221132011-07-27 14:09:09 +0200338 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
339 blink_offtime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000340 }
341 else
342 {
343 gui_update_cursor(TRUE, FALSE);
344 blink_state = BLINK_ON;
Bram Moolenaard2221132011-07-27 14:09:09 +0200345 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
346 blink_ontime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200348 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349}
350
351 static int
352gui_ph_handle_timer_timeout(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
353{
354 is_timeout = TRUE;
355
Bram Moolenaard2221132011-07-27 14:09:09 +0200356 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357}
358
359 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200360gui_ph_handle_window_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361{
362 PhWindowEvent_t *we = info->cbdata;
363 ushort_t *width, *height;
364
Bram Moolenaard0988c52011-08-10 12:19:04 +0200365 switch (we->event_f) {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366 case Ph_WM_CLOSE:
367 gui_shell_closed();
368 break;
369
370 case Ph_WM_FOCUS:
371 /* Just in case it's hidden and needs to be shown */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200372 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373
Bram Moolenaard0988c52011-08-10 12:19:04 +0200374 if (we->event_state == Ph_WM_EVSTATE_FOCUS)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375 {
376 gui_focus_change(TRUE);
377 gui_mch_start_blink();
378 }
379 else
380 {
381 gui_focus_change(FALSE);
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +0100382 gui_mch_stop_blink(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000383 }
384 break;
385
386 case Ph_WM_RESIZE:
Bram Moolenaard0988c52011-08-10 12:19:04 +0200387 PtGetResource(gui.vimWindow, Pt_ARG_WIDTH, &width, 0);
388 PtGetResource(gui.vimWindow, Pt_ARG_HEIGHT, &height, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389#ifdef USE_PANEL_GROUP
390 width -= (pg_margin_left + pg_margin_right);
391 height -= (pg_margin_top + pg_margin_bottom);
392#endif
Bram Moolenaard0988c52011-08-10 12:19:04 +0200393 gui_resize_shell(*width, *height);
394 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395 is_ignore_draw = FALSE;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200396 PtEndFlux(gui.vimContainer);
397 PtContainerRelease(gui.vimContainer);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 break;
399
400 default:
401 break;
402 }
403
Bram Moolenaard2221132011-07-27 14:09:09 +0200404 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405}
406
407 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200408gui_ph_handle_scrollbar(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409{
410 PtScrollbarCallback_t *scroll;
411 scrollbar_T *sb;
412 int value, dragging = FALSE;
413
414 scroll = info->cbdata;
415
416 sb = (scrollbar_T *) data;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200417 if (sb != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418 {
419 value = scroll->position;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200420 switch (scroll->action)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421 {
422 case Pt_SCROLL_DRAGGED:
423 dragging = TRUE;
424 break;
425
426 case Pt_SCROLL_SET:
427 /* FIXME: return straight away here? */
Bram Moolenaard2221132011-07-27 14:09:09 +0200428 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429 break;
430 }
431
432 gui_drag_scrollbar(sb, value, dragging);
433 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200434 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435}
436
437 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200438gui_ph_handle_keyboard(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439{
440 PhKeyEvent_t *key;
441 unsigned char string[6];
442 int len, i;
443 int ch, modifiers;
444
Bram Moolenaard0988c52011-08-10 12:19:04 +0200445 key = PhGetData(info->event);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446
447 ch = modifiers = len = 0;
448
Bram Moolenaard0988c52011-08-10 12:19:04 +0200449 if (p_mh)
450 gui_mch_mousehide(MOUSE_HIDE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
452 /* We're a good lil photon program, aren't we? yes we are, yeess wee arrr */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200453 if (key->key_flags & Pk_KF_Compose)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454 {
Bram Moolenaard2221132011-07-27 14:09:09 +0200455 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456 }
457
Bram Moolenaard0988c52011-08-10 12:19:04 +0200458 if ((key->key_flags & Pk_KF_Cap_Valid) &&
459 PkIsKeyDown(key->key_flags))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460 {
461#ifdef FEAT_MENU
462 /*
463 * Only show the menu if the Alt key is down, and the Shift & Ctrl
464 * keys aren't down, as well as the other conditions
465 */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200466 if (((key->key_mods & Pk_KM_Alt) &&
467 !(key->key_mods & Pk_KM_Shift) &&
468 !(key->key_mods & Pk_KM_Ctrl)) &&
Bram Moolenaar071d4272004-06-13 20:20:40 +0000469 gui.menu_is_active &&
Bram Moolenaard0988c52011-08-10 12:19:04 +0200470 (*p_wak == 'y' ||
471 (*p_wak == 'm' &&
472 gui_is_menu_shortcut(key->key_cap))))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473 {
474 /* Fallthrough and let photon look for the hotkey */
Bram Moolenaard2221132011-07-27 14:09:09 +0200475 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476 }
477#endif
478
Bram Moolenaar15d63192011-09-14 16:05:15 +0200479 for (i = 0; special_keys[i].key_sym != 0; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480 {
Bram Moolenaard0988c52011-08-10 12:19:04 +0200481 if (special_keys[i].key_sym == key->key_cap)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482 {
483 len = 0;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200484 if (special_keys[i].vim_code1 == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485 ch = special_keys[i].vim_code0;
486 else
487 {
488 /* Detect if a keypad number key has been pressed
489 * and change the key if Num Lock is on */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200490 if (key->key_cap >= Pk_KP_Enter && key->key_cap <= Pk_KP_9
491 && (key->key_mods & Pk_KM_Num_Lock))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492 {
493 /* FIXME: For now, just map the key to a ascii value
494 * (see <photon/PkKeyDef.h>) */
495 ch = key->key_cap - 0xf080;
496 }
497 else
Bram Moolenaard0988c52011-08-10 12:19:04 +0200498 ch = TO_SPECIAL(special_keys[i].vim_code0,
499 special_keys[i].vim_code1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500 }
501 break;
502 }
503 }
504
Bram Moolenaard0988c52011-08-10 12:19:04 +0200505 if (key->key_mods & Pk_KM_Ctrl)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 modifiers |= MOD_MASK_CTRL;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200507 if (key->key_mods & Pk_KM_Alt)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 modifiers |= MOD_MASK_ALT;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200509 if (key->key_mods & Pk_KM_Shift)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 modifiers |= MOD_MASK_SHIFT;
511
512 /* Is this not a special key? */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200513 if (special_keys[i].key_sym == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 {
Bram Moolenaard0988c52011-08-10 12:19:04 +0200515 ch = PhTo8859_1(key);
Bram Moolenaar13505972019-01-24 15:04:48 +0100516 if (ch == -1 || (enc_utf8 && ch > 127))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 {
Bram Moolenaard0988c52011-08-10 12:19:04 +0200518 len = PhKeyToMb(string, key);
519 if (len > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {
521 static char buf[6];
522 int src_taken, dst_made;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200523 if (enc_utf8 != TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {
525 PxTranslateFromUTF(
526 charset_translate,
527 string,
528 len,
529 &src_taken,
530 buf,
531 6,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200532 &dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200534 add_to_input_buf(buf, dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 }
536 else
537 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200538 add_to_input_buf(string, len);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 }
540
Bram Moolenaard2221132011-07-27 14:09:09 +0200541 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 }
543 len = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 ch = key->key_cap;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200545 if (ch < 0xff)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {
547 /* FIXME: is this the right thing to do? */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200548 if (modifiers & MOD_MASK_CTRL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {
550 modifiers &= ~MOD_MASK_CTRL;
551
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200552 if ((ch >= 'a' && ch <= 'z') ||
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 ch == '[' ||
554 ch == ']' ||
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200555 ch == '\\')
556 ch = Ctrl_chr(ch);
557 else if (ch == '2')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 ch = NUL;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200559 else if (ch == '6')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 ch = 0x1e;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200561 else if (ch == '-')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 ch = 0x1f;
563 else
564 modifiers |= MOD_MASK_CTRL;
565 }
566
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200567 if (modifiers & MOD_MASK_ALT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200569 ch = Meta(ch);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 modifiers &= ~MOD_MASK_ALT;
571 }
572 }
573 else
574 {
Bram Moolenaard2221132011-07-27 14:09:09 +0200575 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 }
577 }
578 else
579 modifiers &= ~MOD_MASK_SHIFT;
580 }
581
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200582 ch = simplify_key(ch, &modifiers);
583 if (modifiers)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {
585 string[ len++ ] = CSI;
586 string[ len++ ] = KS_MODIFIER;
587 string[ len++ ] = modifiers;
588 }
589
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200590 if (IS_SPECIAL(ch))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 {
592 string[ len++ ] = CSI;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200593 string[ len++ ] = K_SECOND(ch);
594 string[ len++ ] = K_THIRD(ch);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595 }
596 else
597 {
598 string[ len++ ] = ch;
599 }
600
601 if (len == 1 && ((ch == Ctrl_C && ctrl_c_interrupts)
602 || ch == intr_char))
603 {
604 trash_input_buf();
605 got_int = TRUE;
606 }
607
608 if (len == 1 && string[0] == CSI)
609 {
610 /* Turn CSI into K_CSI. */
611 string[ len++ ] = KS_EXTRA;
612 string[ len++ ] = KE_CSI;
613 }
614
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200615 if (len > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200617 add_to_input_buf(string, len);
Bram Moolenaard2221132011-07-27 14:09:09 +0200618 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 }
620 }
621
Bram Moolenaard2221132011-07-27 14:09:09 +0200622 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623}
624
625 static int
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200626gui_ph_handle_mouse(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627{
628 PhPointerEvent_t *pointer;
629 PhRect_t *pos;
630 int button = 0, repeated_click, modifiers = 0x0;
631 short mouse_x, mouse_y;
632
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200633 pointer = PhGetData(info->event);
634 pos = PhGetRects(info->event);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200636 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637
638 /*
639 * Coordinates need to be relative to the base window,
640 * not relative to the vimTextArea widget
641 */
642 mouse_x = pos->ul.x + gui.border_width;
643 mouse_y = pos->ul.y + gui.border_width;
644
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200645 if (info->event->type == Ph_EV_PTR_MOTION_NOBUTTON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200647 gui_mouse_moved(mouse_x, mouse_y);
Bram Moolenaard2221132011-07-27 14:09:09 +0200648 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 }
650
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200651 if (pointer->key_mods & Pk_KM_Shift)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652 modifiers |= MOUSE_SHIFT;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200653 if (pointer->key_mods & Pk_KM_Ctrl)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 modifiers |= MOUSE_CTRL;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200655 if (pointer->key_mods & Pk_KM_Alt)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 modifiers |= MOUSE_ALT;
657
658 /*
659 * FIXME More than one button may be involved, but for
660 * now just deal with one
661 */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200662 if (pointer->buttons & Ph_BUTTON_SELECT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 button = MOUSE_LEFT;
664
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200665 if (pointer->buttons & Ph_BUTTON_MENU)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {
667 button = MOUSE_RIGHT;
668 /* Need the absolute coordinates for the popup menu */
669 abs_mouse.x = pointer->pos.x;
670 abs_mouse.y = pointer->pos.y;
671 }
672
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200673 if (pointer->buttons & Ph_BUTTON_ADJUST)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 button = MOUSE_MIDDLE;
675
676 /* Catch a real release (not phantom or other releases */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200677 if (info->event->type == Ph_EV_BUT_RELEASE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 button = MOUSE_RELEASE;
679
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200680 if (info->event->type & Ph_EV_PTR_MOTION_BUTTON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 button = MOUSE_DRAG;
682
683#if 0
684 /* Vim doesn't use button repeats */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200685 if (info->event->type & Ph_EV_BUT_REPEAT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000686 button = MOUSE_DRAG;
687#endif
688
689 /* Don't do anything if it is one of the phantom mouse release events */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200690 if ((button != MOUSE_RELEASE) ||
691 (info->event->subtype == Ph_EV_RELEASE_REAL))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {
693 repeated_click = (pointer->click_count >= 2) ? TRUE : FALSE;
694
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200695 gui_send_mouse_event(button , mouse_x, mouse_y, repeated_click, modifiers);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 }
697
Bram Moolenaard2221132011-07-27 14:09:09 +0200698 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699}
700
701/* Handle a focus change of the PtRaw widget */
702 static int
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200703gui_ph_handle_focus(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704{
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200705 if (info->reason == Pt_CB_LOST_FOCUS)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200707 PtRemoveEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON,
708 gui_ph_handle_mouse, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200710 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 }
712 else
713 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200714 PtAddEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON,
715 gui_ph_handle_mouse, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200717 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718}
719
720 static void
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200721gui_ph_handle_raw_draw(PtWidget_t *widget, PhTile_t *damage)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722{
723 PhRect_t *r;
724 PhPoint_t offset;
725 PhPoint_t translation;
726
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200727 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 return;
729
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200730 PtSuperClassDraw(PtBasic, widget, damage);
731 PgGetTranslation(&translation);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 PgClearTranslation();
733
734#if 0
735 /*
Bram Moolenaarccc18222007-05-10 18:25:20 +0000736 * This causes some weird problems, with drawing being done from
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737 * within this raw drawing function (rather than just simple clearing
738 * and text drawing done by gui_redraw)
739 *
740 * The main problem is when PhBlit is used, and the cursor appearing
741 * in places where it shouldn't
742 */
743 out_flush();
744#endif
745
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200746 PtWidgetOffset(widget, &offset);
747 PhTranslatePoint(&offset, PtWidgetPos(gui.vimTextArea, NULL));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748
749#if 1
750 /* Redraw individual damage regions */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200751 if (damage->next != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 damage = damage->next;
753
Bram Moolenaar15d63192011-09-14 16:05:15 +0200754 while (damage != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755 {
756 r = &damage->rect;
757 gui_redraw(
758 r->ul.x - offset.x, r->ul.y - offset.y,
759 r->lr.x - r->ul.x + 1,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200760 r->lr.y - r->ul.y + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761 damage = damage->next;
762 }
763#else
764 /* Redraw the rectangle that covers all the damaged regions */
765 r = &damage->rect;
766 gui_redraw(
767 r->ul.x - offset.x, r->ul.y - offset.y,
768 r->lr.x - r->ul.x + 1,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200769 r->lr.y - r->ul.y + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770#endif
771
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200772 PgSetTranslation(&translation, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773}
774
775 static int
776gui_ph_handle_pulldown_menu(
777 PtWidget_t *widget,
778 void *data,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200779 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780{
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200781 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782 {
783 vimmenu_T *menu = (vimmenu_T *) data;
784
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200785 PtPositionMenu(menu->submenu_id, NULL);
786 PtRealizeWidget(menu->submenu_id);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 }
788
Bram Moolenaard2221132011-07-27 14:09:09 +0200789 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790}
791
792/* This is used for pulldown/popup menus and also toolbar buttons */
793 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +0200794gui_ph_handle_menu(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795{
Bram Moolenaar15d63192011-09-14 16:05:15 +0200796 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 {
798 vimmenu_T *menu = (vimmenu_T *) data;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200799 gui_menu_cb(menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200801 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802}
803
804/* Stop focus from disappearing into the menubar... */
805 static int
806gui_ph_handle_menu_unrealized(
807 PtWidget_t *widget,
808 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200809 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810{
Bram Moolenaar15d63192011-09-14 16:05:15 +0200811 PtGiveFocus(gui.vimTextArea, NULL);
Bram Moolenaard2221132011-07-27 14:09:09 +0200812 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813}
814
815 static int
816gui_ph_handle_window_open(
817 PtWidget_t *widget,
818 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200819 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820{
Bram Moolenaar15d63192011-09-14 16:05:15 +0200821 gui_set_shellsize(FALSE, TRUE, RESIZE_BOTH);
Bram Moolenaard2221132011-07-27 14:09:09 +0200822 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823}
824
825/****************************************************************************/
826
827#define DRAW_START gui_ph_draw_start()
828#define DRAW_END gui_ph_draw_end()
829
830/* TODO: Set a clipping rect? */
831 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200832gui_ph_draw_start(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833{
Bram Moolenaara0b19972009-07-01 14:13:18 +0000834 PhGC_t *gc;
835
836 gc = PgGetGC();
Bram Moolenaar15d63192011-09-14 16:05:15 +0200837 PgSetRegion(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)));
838 PgClearClippingsCx(gc);
839 PgClearTranslationCx(gc);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840
Bram Moolenaar15d63192011-09-14 16:05:15 +0200841 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
842 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843
Bram Moolenaar15d63192011-09-14 16:05:15 +0200844 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845}
846
847 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200848gui_ph_draw_end(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849{
850 gui_ph_raw_offset.x = -gui_ph_raw_offset.x;
851 gui_ph_raw_offset.y = -gui_ph_raw_offset.y;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200852 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853}
854
855#ifdef USE_PANEL_GROUP
856 static vimmenu_T *
Bram Moolenaar15d63192011-09-14 16:05:15 +0200857gui_ph_find_buffer_item(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858{
859 vimmenu_T *top_level = root_menu;
860 vimmenu_T *items = NULL;
861
Bram Moolenaar15d63192011-09-14 16:05:15 +0200862 while (top_level != NULL &&
863 (STRCMP(top_level->dname, "Buffers") != 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 top_level = top_level->next;
865
Bram Moolenaar15d63192011-09-14 16:05:15 +0200866 if (top_level != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 {
868 items = top_level->children;
869
Bram Moolenaar15d63192011-09-14 16:05:15 +0200870 while (items != NULL &&
871 (STRCMP(items->dname, name) != 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000872 items = items->next;
873 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200874 return items;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875}
876
877 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200878gui_ph_pg_set_buffer_num(int_u buf_num)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879{
880 int i;
881 char search[16];
882 char *mark;
883
Bram Moolenaar15d63192011-09-14 16:05:15 +0200884 if (gui.vimTextArea == NULL || buf_num == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000885 return;
886
887 search[0] = '(';
Bram Moolenaar15d63192011-09-14 16:05:15 +0200888 ultoa(buf_num, &search[1], 10);
889 STRCAT(search, ")");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890
Bram Moolenaar15d63192011-09-14 16:05:15 +0200891 for (i = 0; i < num_panels; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {
893 /* find the last "(" in the panel title and see if the buffer
894 * number in the title matches the one we're looking for */
Bram Moolenaar15d63192011-09-14 16:05:15 +0200895 mark = STRRCHR(panel_titles[ i ], '(');
896 if (mark != NULL && STRCMP(mark, search) == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200898 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_CURRENT_INDEX,
899 i, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 }
901 }
902}
903
904 static int
905gui_ph_handle_pg_change(
906 PtWidget_t *widget,
907 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200908 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909{
910 vimmenu_T *menu;
911 PtPanelGroupCallback_t *panel;
912
Bram Moolenaar15d63192011-09-14 16:05:15 +0200913 if (info->event != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {
915 panel = info->cbdata;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200916 if (panel->new_panel != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200918 menu = gui_ph_find_buffer_item(panel->new_panel);
919 if (menu)
920 gui_menu_cb(menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 }
922 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200923 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924}
925
926 static void
927gui_ph_get_panelgroup_margins(
928 short *top,
929 short *bottom,
930 short *left,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200931 short *right)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000932{
933 unsigned short abs_raw_x, abs_raw_y, abs_panel_x, abs_panel_y;
934 const unsigned short *margin_top, *margin_bottom;
935 const unsigned short *margin_left, *margin_right;
936
Bram Moolenaar15d63192011-09-14 16:05:15 +0200937 PtGetAbsPosition(gui.vimTextArea, &abs_raw_x, &abs_raw_y);
938 PtGetAbsPosition(gui.vimPanelGroup, &abs_panel_x, &abs_panel_y);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000939
Bram Moolenaar15d63192011-09-14 16:05:15 +0200940 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_RIGHT, &margin_right, 0);
941 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_BOTTOM, &margin_bottom, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942
943 abs_raw_x -= abs_panel_x;
944 abs_raw_y -= abs_panel_y;
945
946 *top = abs_raw_y;
947 *bottom = *margin_bottom;
948
949 *left = abs_raw_x;
950 *right = *margin_right;
951}
952
953/* Used for the tabs for PtPanelGroup */
954 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +0200955gui_ph_is_buffer_item(vimmenu_T *menu, vimmenu_T *parent)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956{
957 char *mark;
958
Bram Moolenaar15d63192011-09-14 16:05:15 +0200959 if (STRCMP(parent->dname, "Buffers") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {
961 /* Look for '(' digits ')' */
Bram Moolenaar15d63192011-09-14 16:05:15 +0200962 mark = vim_strchr(menu->dname, '(');
963 if (mark != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {
965 mark++;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200966 while (isdigit(*mark))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 mark++;
968
Bram Moolenaar15d63192011-09-14 16:05:15 +0200969 if (*mark == ')')
Bram Moolenaard2221132011-07-27 14:09:09 +0200970 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 }
972 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200973 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974}
975
976 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200977gui_ph_pg_add_buffer(char *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978{
979 char **new_titles = NULL;
980
Bram Moolenaar15d63192011-09-14 16:05:15 +0200981 new_titles = (char **) alloc((num_panels + 1) * sizeof(char **));
982 if (new_titles != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200984 if (num_panels > 0)
985 memcpy(new_titles, panel_titles, num_panels * sizeof(char **));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986
987 new_titles[ num_panels++ ] = name;
988
Bram Moolenaar15d63192011-09-14 16:05:15 +0200989 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles,
990 num_panels);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991
Bram Moolenaar15d63192011-09-14 16:05:15 +0200992 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 panel_titles = new_titles;
994 }
995}
996
997 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200998gui_ph_pg_remove_buffer(char *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999{
1000 int i;
1001 char **new_titles = NULL;
1002
1003 /* If there is only 1 panel, we just use the temporary place holder */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001004 if (num_panels > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001006 new_titles = (char **) alloc((num_panels - 1) * sizeof(char **));
1007 if (new_titles != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {
1009 char **s = new_titles;
1010 /* Copy all the titles except the one we're removing */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001011 for (i = 0; i < num_panels; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001013 if (STRCMP(panel_titles[ i ], name) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {
1015 *s++ = panel_titles[ i ];
1016 }
1017 }
1018 num_panels--;
1019
Bram Moolenaar15d63192011-09-14 16:05:15 +02001020 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles,
1021 num_panels);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022
Bram Moolenaar15d63192011-09-14 16:05:15 +02001023 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024 panel_titles = new_titles;
1025 }
1026 }
1027 else
1028 {
1029 num_panels--;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001030 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, &empty_title,
1031 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032
Bram Moolenaard23a8232018-02-10 18:45:26 +01001033 VIM_CLEAR(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 }
1035}
1036
1037/* When a buffer item is deleted from the buffer menu */
1038 static int
1039gui_ph_handle_buffer_remove(
1040 PtWidget_t *widget,
1041 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001042 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043{
1044 vimmenu_T *menu;
1045
Bram Moolenaar15d63192011-09-14 16:05:15 +02001046 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 {
1048 menu = (vimmenu_T *) data;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001049 gui_ph_pg_remove_buffer(menu->dname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050 }
1051
Bram Moolenaard2221132011-07-27 14:09:09 +02001052 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053}
1054#endif
1055
1056 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001057gui_ph_pane_resize(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001059 if (PtWidgetIsRealized(widget))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {
1061 is_ignore_draw = TRUE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001062 PtStartFlux(gui.vimContainer);
1063 PtContainerHold(gui.vimContainer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 }
1065
Bram Moolenaard2221132011-07-27 14:09:09 +02001066 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067}
1068
1069/****************************************************************************/
1070
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 void
Bram Moolenaar15d63192011-09-14 16:05:15 +02001072gui_ph_encoding_changed(int new_encoding)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073{
1074 /* Default encoding is latin1 */
1075 char *charset = "latin1";
1076 int i;
1077
1078 struct {
1079 int encoding;
1080 char *name;
1081 } charsets[] = {
1082 { DBCS_JPN, "SHIFT_JIS" },
1083 { DBCS_KOR, "csEUCKR" },
1084 { DBCS_CHT, "big5" },
1085 { DBCS_CHS, "gb" }
1086 };
1087
Bram Moolenaar15d63192011-09-14 16:05:15 +02001088 for (i = 0; i < ARRAY_LENGTH(charsets); i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001090 if (new_encoding == charsets[ i ].encoding)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 charset = charsets[ i ].name;
1092 }
1093
Bram Moolenaar15d63192011-09-14 16:05:15 +02001094 charset_translate = PxTranslateSet(charset_translate, charset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096
1097/****************************************************************************/
1098/****************************************************************************/
1099
1100 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001101gui_mch_prepare(int *argc, char **argv)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001103 PtInit(NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104}
1105
1106 int
1107gui_mch_init(void)
1108{
1109 PtArg_t args[10];
1110 int flags = 0, n = 0;
1111
Bram Moolenaarccc18222007-05-10 18:25:20 +00001112 PhDim_t window_size = {100, 100}; /* Arbitrary values */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 PhPoint_t pos = {0, 0};
1114
Bram Moolenaar15d63192011-09-14 16:05:15 +02001115 gui.event_buffer = (PhEvent_t *) alloc(EVENT_BUFFER_SIZE);
1116 if (gui.event_buffer == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001117 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118
1119 /* Get a translation so we can convert from ISO Latin-1 to UTF */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001120 charset_translate = PxTranslateSet(NULL, "latin1");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121
1122 /* The +2 is for the 1 pixel dark line on each side */
1123 gui.border_offset = gui.border_width = GUI_PH_MARGIN + 2;
1124
1125 /* Handle close events ourselves */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001126 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE);
1127 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
1128 Ph_WM_CLOSE | Ph_WM_RESIZE | Ph_WM_FOCUS);
1129 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0);
1130 gui.vimWindow = PtCreateWidget(PtWindow, NULL, n, args);
1131 if (gui.vimWindow == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001132 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133
Bram Moolenaar15d63192011-09-14 16:05:15 +02001134 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW, gui_ph_handle_window_cb, NULL);
1135 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW_OPENING,
1136 gui_ph_handle_window_open, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137
1138 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001139 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_ALL, Pt_IS_ANCHORED);
1140 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0);
1141 PtSetArg(&args[ n++ ], Pt_ARG_POS, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142
1143#ifdef USE_PANEL_GROUP
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001144 /* Put in a temporary place holder title */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001145 PtSetArg(&args[ n++ ], Pt_ARG_PG_PANEL_TITLES, &empty_title, 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146
Bram Moolenaar15d63192011-09-14 16:05:15 +02001147 gui.vimPanelGroup = PtCreateWidget(PtPanelGroup, gui.vimWindow, n, args);
1148 if (gui.vimPanelGroup == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001149 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150
Bram Moolenaar15d63192011-09-14 16:05:15 +02001151 PtAddCallback(gui.vimPanelGroup, Pt_CB_PG_PANEL_SWITCHING,
1152 gui_ph_handle_pg_change, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153#else
1154 /* Turn off all edge decorations */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001155 PtSetArg(&args[ n++ ], Pt_ARG_BASIC_FLAGS, Pt_FALSE, Pt_ALL);
1156 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, 0, 0);
1157 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 0, 0);
1158 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 0, 0);
1159 PtSetArg(&args[ n++ ], Pt_ARG_CONTAINER_FLAGS, Pt_TRUE, Pt_AUTO_EXTENT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160
Bram Moolenaar15d63192011-09-14 16:05:15 +02001161 gui.vimContainer = PtCreateWidget(PtPane, gui.vimWindow, n, args);
1162 if (gui.vimContainer == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001163 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164
Bram Moolenaar15d63192011-09-14 16:05:15 +02001165 PtAddCallback(gui.vimContainer, Pt_CB_RESIZE, gui_ph_pane_resize, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166#endif
1167
1168 /* Size for the text area is set in gui_mch_set_text_area_pos */
1169 n = 0;
1170
Bram Moolenaar15d63192011-09-14 16:05:15 +02001171 PtSetArg(&args[ n++ ], Pt_ARG_RAW_DRAW_F, gui_ph_handle_raw_draw, 1);
1172 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, GUI_PH_MARGIN, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173 /*
1174 * Using focus render also causes the whole widget to be redrawn
1175 * whenever it changes focus, which is very annoying :p
1176 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001177 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE,
1178 Pt_GETS_FOCUS | Pt_HIGHLIGHTED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179#ifndef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001180 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_TYPE, GUI_PH_MOUSE_TYPE, 0);
1181 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_COLOR, gui_ph_mouse_color, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#endif
1183
Bram Moolenaar15d63192011-09-14 16:05:15 +02001184 gui.vimTextArea = PtCreateWidget(PtRaw, Pt_DFLT_PARENT, n, args);
1185 if (gui.vimTextArea == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001186 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187
1188 /* TODO: use PtAddEventHandlers instead? */
1189 /* Not using Ph_EV_BUT_REPEAT because vim wouldn't use it anyway */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001190 PtAddEventHandler(gui.vimTextArea,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE | Ph_EV_PTR_MOTION_BUTTON,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001192 gui_ph_handle_mouse, NULL);
1193 PtAddEventHandler(gui.vimTextArea, Ph_EV_KEY,
1194 gui_ph_handle_keyboard, NULL);
1195 PtAddCallback(gui.vimTextArea, Pt_CB_GOT_FOCUS,
1196 gui_ph_handle_focus, NULL);
1197 PtAddCallback(gui.vimTextArea, Pt_CB_LOST_FOCUS,
1198 gui_ph_handle_focus, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199
1200 /*
1201 * Now that the text area widget has been created, set up the colours,
1202 * which wil call PtSetResource from gui_mch_new_colors
1203 */
1204
1205 /*
1206 * Create the two timers, not as accurate as using the kernel timer
1207 * functions, but good enough
1208 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001209 gui_ph_timer_cursor = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL);
1210 if (gui_ph_timer_cursor == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001211 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212
Bram Moolenaar15d63192011-09-14 16:05:15 +02001213 gui_ph_timer_timeout = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL);
1214 if (gui_ph_timer_timeout == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001215 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216
Bram Moolenaar15d63192011-09-14 16:05:15 +02001217 PtAddCallback(gui_ph_timer_cursor, Pt_CB_TIMER_ACTIVATE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 gui_ph_handle_timer_cursor, NULL);
Bram Moolenaar15d63192011-09-14 16:05:15 +02001219 PtAddCallback(gui_ph_timer_timeout, Pt_CB_TIMER_ACTIVATE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 gui_ph_handle_timer_timeout, NULL);
1221
1222#ifdef FEAT_MENU
1223 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001224 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
1225 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_LEFT_RIGHT,
1226 Pt_IS_ANCHORED);
1227 gui.vimToolBarGroup = PtCreateWidget(PtToolbarGroup, gui.vimWindow,
1228 n, args);
1229 if (gui.vimToolBarGroup == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001230 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231
Bram Moolenaar15d63192011-09-14 16:05:15 +02001232 PtAddCallback(gui.vimToolBarGroup, Pt_CB_RESIZE,
1233 gui_ph_handle_menu_resize, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234
1235 n = 0;
1236 flags = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001237 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
1238 if (! vim_strchr(p_go, GO_MENUS))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 {
1240 flags |= Pt_DELAY_REALIZE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001241 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE, flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001243 gui.vimMenuBar = PtCreateWidget(PtMenuBar, gui.vimToolBarGroup, n, args);
1244 if (gui.vimMenuBar == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001245 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246
1247# ifdef FEAT_TOOLBAR
1248 n = 0;
1249
Bram Moolenaar15d63192011-09-14 16:05:15 +02001250 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS,
1251 Pt_ANCHOR_LEFT_RIGHT |Pt_TOP_ANCHORED_TOP, Pt_IS_ANCHORED);
1252 PtSetArg(&args[ n++ ], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
1253 Pt_RESIZE_Y_AS_REQUIRED);
1254 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255
1256 flags = Pt_GETS_FOCUS;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001257 if (! vim_strchr(p_go, GO_TOOLBAR))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 flags |= Pt_DELAY_REALIZE;
1259
Bram Moolenaar15d63192011-09-14 16:05:15 +02001260 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE, flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261
Bram Moolenaar15d63192011-09-14 16:05:15 +02001262 gui.vimToolBar = PtCreateWidget(PtToolbar, gui.vimToolBarGroup, n, args);
1263 if (gui.vimToolBar == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001264 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265
1266 /*
1267 * Size for the toolbar is fetched in gui_mch_show_toolbar, after
1268 * the buttons have been added and the toolbar has resized it's height
1269 * for the buttons to fit
1270 */
1271# endif
1272
1273#endif
1274
Bram Moolenaard2221132011-07-27 14:09:09 +02001275 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276}
1277
1278 int
1279gui_mch_init_check(void)
1280{
Bram Moolenaard2221132011-07-27 14:09:09 +02001281 return (is_photon_available == TRUE) ? OK : FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282}
1283
1284 int
1285gui_mch_open(void)
1286{
1287 gui.norm_pixel = Pg_BLACK;
1288 gui.back_pixel = Pg_WHITE;
1289
1290 set_normal_colors();
1291
1292 gui_check_colors();
1293 gui.def_norm_pixel = gui.norm_pixel;
1294 gui.def_back_pixel = gui.back_pixel;
1295
1296 highlight_gui_started();
1297
1298 if (gui_win_x != -1 && gui_win_y != -1)
1299 gui_mch_set_winpos(gui_win_x, gui_win_y);
1300
Bram Moolenaar15d63192011-09-14 16:05:15 +02001301 return (PtRealizeWidget(gui.vimWindow) == 0) ? OK : FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302}
1303
1304 void
1305gui_mch_exit(int rc)
1306{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001307 PtDestroyWidget(gui.vimWindow);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308
Bram Moolenaar15d63192011-09-14 16:05:15 +02001309 PxTranslateSet(charset_translate, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310
Bram Moolenaar15d63192011-09-14 16:05:15 +02001311 vim_free(gui.event_buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312
1313#ifdef USE_PANEL_GROUPS
Bram Moolenaar15d63192011-09-14 16:05:15 +02001314 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315#endif
1316}
1317
1318/****************************************************************************/
1319/* events */
1320
1321/* When no events are available, photon will call this function, working is
1322 * set to FALSE, and the gui_mch_update loop will exit. */
1323 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001324exit_gui_mch_update(void *data)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325{
1326 *(int *)data = FALSE;
Bram Moolenaard2221132011-07-27 14:09:09 +02001327 return Pt_END;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328}
1329
1330 void
1331gui_mch_update(void)
1332{
1333 int working = TRUE;
1334
Bram Moolenaar15d63192011-09-14 16:05:15 +02001335 PtAppAddWorkProc(NULL, exit_gui_mch_update, &working);
1336 while ((working == TRUE) && !vim_is_input_buf_full())
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337 {
1338 PtProcessEvent();
1339 }
1340}
1341
1342 int
1343gui_mch_wait_for_chars(int wtime)
1344{
1345 is_timeout = FALSE;
1346
Bram Moolenaar15d63192011-09-14 16:05:15 +02001347 if (wtime > 0)
1348 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, wtime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349
Bram Moolenaar15d63192011-09-14 16:05:15 +02001350 while (1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {
1352 PtProcessEvent();
Bram Moolenaar15d63192011-09-14 16:05:15 +02001353 if (input_available())
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001355 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, 0, 0);
Bram Moolenaard2221132011-07-27 14:09:09 +02001356 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001358 else if (is_timeout == TRUE)
Bram Moolenaard2221132011-07-27 14:09:09 +02001359 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 }
1361}
1362
Bram Moolenaar15d63192011-09-14 16:05:15 +02001363#if defined(FEAT_BROWSE) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364/*
1365 * Put up a file requester.
1366 * Returns the selected name in allocated memory, or NULL for Cancel.
1367 * saving, select file to write
1368 * title title for the window
1369 * default_name default name (well duh!)
1370 * ext not used (extension added)
1371 * initdir initial directory, NULL for current dir
1372 * filter not used (file name filter)
1373 */
1374 char_u *
1375gui_mch_browse(
1376 int saving,
1377 char_u *title,
1378 char_u *default_name,
1379 char_u *ext,
1380 char_u *initdir,
1381 char_u *filter)
1382{
1383 PtFileSelectionInfo_t file;
1384 int flags;
1385 char_u *default_path;
1386 char_u *open_text = NULL;
1387
1388 flags = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001389 memset(&file, 0, sizeof(file));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390
Bram Moolenaar15d63192011-09-14 16:05:15 +02001391 default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1);
1392 if (default_path != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001394 if (saving == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {
1396 /* Don't need Pt_FSR_CONFIRM_EXISTING, vim will ask anyway */
1397 flags |= Pt_FSR_NO_FCHECK;
1398 open_text = "&Save";
1399 }
1400
1401 /* combine the directory and filename into a single path */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001402 if (initdir == NULL || *initdir == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001404 mch_dirname(default_path, MAXPATHL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 initdir = default_path;
1406 }
1407 else
1408 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001409 STRCPY(default_path, initdir);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 initdir = default_path;
1411 }
1412
Bram Moolenaar15d63192011-09-14 16:05:15 +02001413 if (default_name != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001415 if (default_path[ STRLEN(default_path) - 1 ] != '/')
1416 STRCAT(default_path, "/");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417
Bram Moolenaar15d63192011-09-14 16:05:15 +02001418 STRCAT(default_path, default_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 }
1420
1421 /* TODO: add a filter? */
1422 PtFileSelection(
1423 gui.vimWindow,
1424 NULL,
1425 title,
1426 default_path,
1427 NULL,
1428 open_text,
1429 NULL,
1430 NULL,
1431 &file,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001432 flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433
Bram Moolenaar15d63192011-09-14 16:05:15 +02001434 vim_free(default_path);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435
Bram Moolenaar15d63192011-09-14 16:05:15 +02001436 if (file.ret == Pt_FSDIALOG_BTN1)
Bram Moolenaard2221132011-07-27 14:09:09 +02001437 return vim_strsave(file.path);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 }
Bram Moolenaard2221132011-07-27 14:09:09 +02001439 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440}
1441#endif
1442
Bram Moolenaar15d63192011-09-14 16:05:15 +02001443#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444static PtWidget_t *gui_ph_dialog_text = NULL;
1445
1446 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001447gui_ph_dialog_close(int button, void *data)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448{
1449 PtModalCtrl_t *modal_ctrl = data;
1450 char_u *dialog_text, *vim_text;
1451
Bram Moolenaar15d63192011-09-14 16:05:15 +02001452 if (gui_ph_dialog_text != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001454 PtGetResource(gui_ph_dialog_text, Pt_ARG_TEXT_STRING, &dialog_text, 0);
1455 PtGetResource(gui_ph_dialog_text, Pt_ARG_POINTER, &vim_text, 0);
1456 STRNCPY(vim_text, dialog_text, IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 }
1458
Bram Moolenaar15d63192011-09-14 16:05:15 +02001459 PtModalUnblock(modal_ctrl, (void *) button);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460
Bram Moolenaard2221132011-07-27 14:09:09 +02001461 return Pt_TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462}
1463
1464 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001465gui_ph_dialog_text_enter(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001467 if (info->reason_subtype == Pt_EDIT_ACTIVATE)
1468 gui_ph_dialog_close(1, data);
Bram Moolenaard2221132011-07-27 14:09:09 +02001469 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470}
1471
1472 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001473gui_ph_dialog_esc(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474{
1475 PhKeyEvent_t *key;
1476
Bram Moolenaar15d63192011-09-14 16:05:15 +02001477 key = PhGetData(info->event);
1478 if ((key->key_flags & Pk_KF_Cap_Valid) && (key->key_cap == Pk_Escape))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001480 gui_ph_dialog_close(0, data);
Bram Moolenaard2221132011-07-27 14:09:09 +02001481 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482 }
Bram Moolenaard2221132011-07-27 14:09:09 +02001483 return Pt_PROCESS;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484}
1485
1486 int
1487gui_mch_dialog(
1488 int type,
1489 char_u *title,
1490 char_u *message,
1491 char_u *buttons,
1492 int default_button,
Bram Moolenaard2c340a2011-01-17 20:08:11 +01001493 char_u *textfield,
1494 int ex_cmd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495{
1496 char_u *str;
1497 char_u **button_array;
1498 char_u *buttons_copy;
1499
1500 int button_count;
1501 int i, len;
1502 int dialog_result = -1;
1503
1504 /* FIXME: the vertical option in guioptions is blatantly ignored */
1505 /* FIXME: so is the type */
1506
1507 button_count = len = i = 0;
1508
Bram Moolenaar15d63192011-09-14 16:05:15 +02001509 if (buttons == NULL || *buttons == NUL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001510 return -1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511
1512 /* There is one less separator than buttons, so bump up the button count */
1513 button_count = 1;
1514
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001515 /* Count string length and number of separators */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001516 for (str = buttons; *str; str++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {
1518 len++;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001519 if (*str == DLG_BUTTON_SEP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 button_count++;
1521 }
1522
Bram Moolenaar15d63192011-09-14 16:05:15 +02001523 if (title == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 title = "Vim";
1525
Bram Moolenaar15d63192011-09-14 16:05:15 +02001526 buttons_copy = alloc(len + 1);
1527 button_array = (char_u **) alloc(button_count * sizeof(char_u *));
1528 if (buttons_copy != NULL && button_array != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001530 STRCPY(buttons_copy, buttons);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531
1532 /*
1533 * Convert DLG_BUTTON_SEP into NUL's and fill in
1534 * button_array with the pointer to each NUL terminated string
1535 */
1536 str = buttons_copy;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001537 for (i = 0; i < button_count; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 {
1539 button_array[ i ] = str;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001540 for (; *str; str++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001542 if (*str == DLG_BUTTON_SEP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {
1544 *str++ = NUL;
1545 break;
1546 }
1547 }
1548 }
1549#ifndef FEAT_GUI_TEXTDIALOG
1550 dialog_result = PtAlert(
1551 gui.vimWindow, NULL,
1552 title,
1553 NULL,
1554 message, NULL,
1555 button_count, (const char **) button_array, NULL,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001556 default_button, 0, Pt_MODAL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557#else
1558 /* Writing the dialog ourselves lets us add extra features, like
1559 * trapping the escape key and returning 0 to vim */
1560 {
1561 int n;
1562 PtArg_t args[5];
1563 PtWidget_t *dialog, *pane;
1564 PtModalCtrl_t modal_ctrl;
1565 PtDialogInfo_t di;
1566
Bram Moolenaar15d63192011-09-14 16:05:15 +02001567 memset(&di, 0, sizeof(di));
1568 memset(&modal_ctrl, 0, sizeof(modal_ctrl));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569
1570 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001571 PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0);
1572 PtSetArg(&args[n++], Pt_ARG_WIDTH, 350, 0);
1573 PtSetArg(&args[n++], Pt_ARG_GROUP_ORIENTATION,
1574 Pt_GROUP_VERTICAL, 0);
1575 PtSetArg(&args[n++], Pt_ARG_GROUP_FLAGS,
1576 Pt_TRUE, Pt_GROUP_NO_KEYS | Pt_GROUP_STRETCH_HORIZONTAL);
1577 PtSetArg(&args[n++], Pt_ARG_CONTAINER_FLAGS, Pt_FALSE, Pt_TRUE);
1578 pane = PtCreateWidget(PtGroup, NULL, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579
1580 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001581 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, message, 0);
1582 PtCreateWidget(PtLabel, pane, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583
Bram Moolenaar15d63192011-09-14 16:05:15 +02001584 if (textfield != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {
1586 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001587 PtSetArg(&args[n++], Pt_ARG_MAX_LENGTH, IOSIZE - 1, 0);
1588 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, textfield, 0);
1589 PtSetArg(&args[n++], Pt_ARG_POINTER, textfield, 0);
1590 gui_ph_dialog_text = PtCreateWidget(PtText, pane, n, args);
1591 PtAddCallback(gui_ph_dialog_text, Pt_CB_ACTIVATE,
1592 gui_ph_dialog_text_enter, &modal_ctrl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 }
1594
1595 di.parent = gui.vimWindow;
1596 di.pane = pane;
1597 di.title = title;
1598 di.buttons = (const char **) button_array;
1599 di.nbtns = button_count;
1600 di.def_btn = default_button;
1601 /* This is just to give the dialog the close button.
1602 * We check for the Escape key ourselves and return 0 */
1603 di.esc_btn = button_count;
1604 di.callback = gui_ph_dialog_close;
1605 di.data = &modal_ctrl;
1606
Bram Moolenaar15d63192011-09-14 16:05:15 +02001607 dialog = PtCreateDialog(&di);
1608 PtAddFilterCallback(dialog, Ph_EV_KEY,
1609 gui_ph_dialog_esc, &modal_ctrl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610
Bram Moolenaar15d63192011-09-14 16:05:15 +02001611 if (gui_ph_dialog_text != NULL)
1612 PtGiveFocus(gui_ph_dialog_text, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613
1614 /* Open dialog, block the vim window and wait for the dialog to close */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001615 PtRealizeWidget(dialog);
1616 PtMakeModal(dialog, Ph_CURSOR_NOINPUT, Ph_CURSOR_DEFAULT_COLOR);
1617 dialog_result = (int) PtModalBlock(&modal_ctrl, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618
Bram Moolenaar15d63192011-09-14 16:05:15 +02001619 PtDestroyWidget(dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 gui_ph_dialog_text = NULL;
1621 }
1622#endif
1623 }
1624
Bram Moolenaar15d63192011-09-14 16:05:15 +02001625 vim_free(button_array);
1626 vim_free(buttons_copy);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627
Bram Moolenaard2221132011-07-27 14:09:09 +02001628 return dialog_result;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629}
1630#endif
1631/****************************************************************************/
1632/* window size/position/state */
1633
1634 int
1635gui_mch_get_winpos(int *x, int *y)
1636{
1637 PhPoint_t *pos;
1638
Bram Moolenaar15d63192011-09-14 16:05:15 +02001639 pos = PtWidgetPos(gui.vimWindow, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640
1641 *x = pos->x;
1642 *y = pos->y;
1643
Bram Moolenaard2221132011-07-27 14:09:09 +02001644 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645}
1646
1647 void
1648gui_mch_set_winpos(int x, int y)
1649{
1650 PhPoint_t pos = { x, y };
1651
Bram Moolenaar15d63192011-09-14 16:05:15 +02001652 PtSetResource(gui.vimWindow, Pt_ARG_POS, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653}
1654
1655 void
1656gui_mch_set_shellsize(int width, int height,
Bram Moolenaarafa24992006-03-27 20:58:26 +00001657 int min_width, int min_height, int base_width, int base_height,
1658 int direction)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659{
1660 PhDim_t window_size = { width, height };
1661 PhDim_t min_size = { min_width, min_height };
1662
1663#ifdef USE_PANEL_GROUP
1664 window_size.w += pg_margin_left + pg_margin_right;
1665 window_size.h += pg_margin_top + pg_margin_bottom;
1666#endif
1667
Bram Moolenaar15d63192011-09-14 16:05:15 +02001668 PtSetResource(gui.vimWindow, Pt_ARG_MINIMUM_DIM, &min_size, 0);
1669 PtSetResource(gui.vimWindow, Pt_ARG_DIM, &window_size, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670
Bram Moolenaar15d63192011-09-14 16:05:15 +02001671 if (! PtWidgetIsRealized(gui.vimWindow))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 gui_ph_resize_container();
1673}
1674
1675/*
1676 * Return the amount of screen space that hasn't been allocated (such as
1677 * by the shelf).
1678 */
1679 void
1680gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
1681{
1682 PhRect_t console;
1683
Bram Moolenaar15d63192011-09-14 16:05:15 +02001684 PhWindowQueryVisible(Ph_QUERY_WORKSPACE, 0,
1685 PhInputGroup(NULL), &console);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686
1687 *screen_w = console.lr.x - console.ul.x + 1;
1688 *screen_h = console.lr.y - console.ul.y + 1;
1689}
1690
1691 void
1692gui_mch_iconify(void)
1693{
1694 PhWindowEvent_t event;
1695
Bram Moolenaar15d63192011-09-14 16:05:15 +02001696 memset(&event, 0, sizeof (event));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 event.event_f = Ph_WM_HIDE;
1698 event.event_state = Ph_WM_EVSTATE_HIDE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001699 event.rid = PtWidgetRid(gui.vimWindow);
1700 PtForwardWindowEvent(&event);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701}
1702
1703#if defined(FEAT_EVAL) || defined(PROTO)
1704/*
1705 * Bring the Vim window to the foreground.
1706 */
1707 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001708gui_mch_set_foreground(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709{
1710 PhWindowEvent_t event;
1711
Bram Moolenaar15d63192011-09-14 16:05:15 +02001712 memset(&event, 0, sizeof (event));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 event.event_f = Ph_WM_TOFRONT;
1714 event.event_state = Ph_WM_EVSTATE_FFRONT;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001715 event.rid = PtWidgetRid(gui.vimWindow);
1716 PtForwardWindowEvent(&event);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717}
1718#endif
1719
1720 void
1721gui_mch_settitle(char_u *title, char_u *icon)
1722{
1723#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02001724 gui_ph_pg_set_buffer_num(curwin->w_buffer->b_fnum);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02001726 PtSetResource(gui.vimWindow, Pt_ARG_WINDOW_TITLE, title, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 /* Not sure what to do with the icon text, set balloon text somehow? */
1728}
1729
1730/****************************************************************************/
1731/* Scrollbar */
1732
1733 void
1734gui_mch_set_scrollbar_thumb(scrollbar_T *sb, int val, int size, int max)
1735{
1736 int n = 0;
1737 PtArg_t args[3];
1738
Bram Moolenaar15d63192011-09-14 16:05:15 +02001739 PtSetArg(&args[ n++ ], Pt_ARG_MAXIMUM, max, 0);
1740 PtSetArg(&args[ n++ ], Pt_ARG_SLIDER_SIZE, size, 0);
1741 PtSetArg(&args[ n++ ], Pt_ARG_GAUGE_VALUE, val, 0);
1742 PtSetResources(sb->id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743}
1744
1745 void
1746gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
1747{
1748 PhArea_t area = {{ x, y }, { w, h }};
1749
Bram Moolenaar15d63192011-09-14 16:05:15 +02001750 PtSetResource(sb->id, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751}
1752
1753 void
1754gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
1755{
1756 int n = 0;
1757/* int anchor_flags = 0;*/
1758 PtArg_t args[4];
1759
1760 /*
1761 * Stop the scrollbar from being realized when the parent
1762 * is realized, so it can be explicitly realized by vim.
1763 *
1764 * Also, don't let the scrollbar get focus
1765 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001766 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE,
1767 Pt_DELAY_REALIZE | Pt_GETS_FOCUS);
1768 PtSetArg(&args[ n++ ], Pt_ARG_SCROLLBAR_FLAGS, Pt_SCROLLBAR_SHOW_ARROWS, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769#if 0
1770 /* Don't need this anchoring for the scrollbars */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001771 if (orient == SBAR_HORIZ)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {
1773 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM |
1774 Pt_LEFT_ANCHORED_LEFT | Pt_RIGHT_ANCHORED_RIGHT;
1775 }
1776 else
1777 {
1778 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM | Pt_TOP_ANCHORED_TOP;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001779 if (sb->wp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001781 if (sb == &sb->wp->w_scrollbars[ SBAR_LEFT ])
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 anchor_flags |= Pt_LEFT_ANCHORED_LEFT;
1783 else
1784 anchor_flags |= Pt_RIGHT_ANCHORED_RIGHT;
1785 }
1786 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001787 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, anchor_flags, Pt_IS_ANCHORED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02001789 PtSetArg(&args[ n++ ], Pt_ARG_ORIENTATION,
1790 (orient == SBAR_HORIZ) ? Pt_HORIZONTAL : Pt_VERTICAL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02001792 sb->id = PtCreateWidget(PtScrollbar, gui.vimPanelGroup, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001794 sb->id = PtCreateWidget(PtScrollbar, gui.vimContainer, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795#endif
1796
Bram Moolenaar15d63192011-09-14 16:05:15 +02001797 PtAddCallback(sb->id, Pt_CB_SCROLLBAR_MOVE, gui_ph_handle_scrollbar, sb);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798}
1799
1800 void
1801gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
1802{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001803 if (flag != 0)
1804 PtRealizeWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001806 PtUnrealizeWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807}
1808
1809 void
1810gui_mch_destroy_scrollbar(scrollbar_T *sb)
1811{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001812 PtDestroyWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 sb->id = NULL;
1814}
1815
1816/****************************************************************************/
1817/* Mouse functions */
1818
1819#if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1820/* The last set mouse pointer shape is remembered, to be used when it goes
1821 * from hidden to not hidden. */
1822static int last_shape = 0;
1823
1824/* Table for shape IDs. Keep in sync with the mshape_names[] table in
1825 * misc2.c! */
1826static int mshape_ids[] =
1827{
1828 Ph_CURSOR_POINTER, /* arrow */
1829 Ph_CURSOR_NONE, /* blank */
1830 Ph_CURSOR_INSERT, /* beam */
1831 Ph_CURSOR_DRAG_VERTICAL, /* updown */
1832 Ph_CURSOR_DRAG_VERTICAL, /* udsizing */
1833 Ph_CURSOR_DRAG_HORIZONTAL, /* leftright */
1834 Ph_CURSOR_DRAG_HORIZONTAL, /* lrsizing */
1835 Ph_CURSOR_WAIT, /* busy */
1836 Ph_CURSOR_DONT, /* no */
1837 Ph_CURSOR_CROSSHAIR, /* crosshair */
1838 Ph_CURSOR_FINGER, /* hand1 */
1839 Ph_CURSOR_FINGER, /* hand2 */
1840 Ph_CURSOR_FINGER, /* pencil */
1841 Ph_CURSOR_QUESTION_POINT, /* question */
1842 Ph_CURSOR_POINTER, /* right-arrow */
1843 Ph_CURSOR_POINTER, /* up-arrow */
1844 Ph_CURSOR_POINTER /* last one */
1845};
1846
1847 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001848mch_set_mouse_shape(int shape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849{
1850 int id;
1851
1852 if (!gui.in_use)
1853 return;
1854
1855 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
Bram Moolenaar15d63192011-09-14 16:05:15 +02001856 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE,
1857 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 else
1859 {
1860 if (shape >= MSHAPE_NUMBERED)
1861 id = Ph_CURSOR_POINTER;
1862 else
1863 id = mshape_ids[shape];
1864
Bram Moolenaar15d63192011-09-14 16:05:15 +02001865 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, id, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 }
1867 if (shape != MSHAPE_HIDE)
1868 last_shape = shape;
1869}
1870#endif
1871
1872 void
1873gui_mch_mousehide(int hide)
1874{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001875 if (gui.pointer_hidden != hide)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {
1877 gui.pointer_hidden = hide;
1878#ifdef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001879 if (hide)
1880 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE,
1881 Ph_CURSOR_NONE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001883 mch_set_mouse_shape(last_shape);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001885 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE,
1886 (hide == MOUSE_SHOW) ? GUI_PH_MOUSE_TYPE : Ph_CURSOR_NONE,
1887 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888#endif
1889 }
1890}
1891
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00001892 void
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001893gui_mch_getmouse(int *x, int *y)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894{
1895 PhCursorInfo_t info;
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001896 short ix, iy;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897
1898 /* FIXME: does this return the correct position,
1899 * with respect to the border? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001900 PhQueryCursor(PhInputGroup(NULL), &info);
1901 PtGetAbsPosition(gui.vimTextArea , &ix, &iy);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001903 *x = info.pos.x - ix;
1904 *y = info.pos.y - iy;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905}
1906
1907 void
1908gui_mch_setmouse(int x, int y)
1909{
1910 short abs_x, abs_y;
1911
Bram Moolenaar15d63192011-09-14 16:05:15 +02001912 PtGetAbsPosition(gui.vimTextArea, &abs_x, &abs_y);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 /* Add the border offset? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001914 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + x, abs_y + y);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915}
1916
1917/****************************************************************************/
1918/* Colours */
1919
1920/*
1921 * Return the RGB value of a pixel as a long.
1922 */
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02001923 guicolor_T
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924gui_mch_get_rgb(guicolor_T pixel)
1925{
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02001926 return (guicolor_T)(PgRGB(PgRedValue(pixel),
1927 PgGreenValue(pixel), PgBlueValue(pixel)));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928}
1929
1930 void
1931gui_mch_new_colors(void)
1932{
1933#if 0 /* Don't bother changing the cursor colour */
1934 short color_diff;
1935
1936 /*
1937 * If there isn't enough difference between the background colour and
1938 * the mouse pointer colour then change the mouse pointer colour
1939 */
1940 color_diff = gui_get_lightness(gui_ph_mouse_color)
1941 - gui_get_lightness(gui.back_pixel);
1942
Bram Moolenaar15d63192011-09-14 16:05:15 +02001943 if (abs(color_diff) < 64)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {
1945 short r, g, b;
1946 /* not a great algorithm... */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001947 r = PgRedValue(gui_ph_mouse_color) ^ 255;
1948 g = PgGreenValue(gui_ph_mouse_color) ^ 255;
1949 b = PgBlueValue(gui_ph_mouse_color) ^ 255;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950
1951#ifndef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001952 gui_ph_mouse_color = PgRGB(r, g, b);
1953 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_COLOR,
1954 gui_ph_mouse_color, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955#endif
1956 }
1957#endif
1958
Bram Moolenaar15d63192011-09-14 16:05:15 +02001959 PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960}
1961
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962/*
Bram Moolenaarccc18222007-05-10 18:25:20 +00001963 * This should be split out into a separate file,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 * every port does basically the same thing.
1965 *
1966 * This is the gui_w32.c version (i think..)
1967 * Return INVALCOLOR when failed.
1968 */
1969
1970 guicolor_T
1971gui_mch_get_color(char_u *name)
1972{
Bram Moolenaarab302212016-04-26 20:59:29 +02001973 return gui_get_color_cmn(name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974}
1975
Bram Moolenaar26af85d2017-07-23 16:45:10 +02001976 guicolor_T
1977gui_mch_get_rgb_color(int r, int g, int b)
1978{
1979 return gui_get_rgb_color_cmn(r, g, b);
1980}
1981
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 void
1983gui_mch_set_fg_color(guicolor_T color)
1984{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001985 PgSetTextColor(color);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986}
1987
1988 void
1989gui_mch_set_bg_color(guicolor_T color)
1990{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001991 PgSetFillColor(color);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992}
1993
1994 void
Bram Moolenaare2cc9702005-03-15 22:43:58 +00001995gui_mch_set_sp_color(guicolor_T color)
1996{
1997}
1998
1999 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000gui_mch_invert_rectangle(int row, int col, int nr, int nc)
2001{
2002 PhRect_t rect;
2003
Bram Moolenaar15d63192011-09-14 16:05:15 +02002004 rect.ul.x = FILL_X(col);
2005 rect.ul.y = FILL_Y(row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006
2007 /* FIXME: This has an off by one pixel problem */
2008 rect.lr.x = rect.ul.x + nc * gui.char_width;
2009 rect.lr.y = rect.ul.y + nr * gui.char_height;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002010 if (nc > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 rect.lr.x -= 1;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002012 if (nr > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 rect.lr.y -= 1;
2014
2015 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002016 PgSetDrawMode(Pg_DrawModeDSTINVERT);
2017 PgDrawRect(&rect, Pg_DRAW_FILL);
2018 PgSetDrawMode(Pg_DrawModeSRCCOPY);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 DRAW_END;
2020}
2021
2022 void
2023gui_mch_clear_block(int row1, int col1, int row2, int col2)
2024{
2025 PhRect_t block = {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002026 { FILL_X(col1), FILL_Y(row1) },
2027 { FILL_X(col2 + 1) - 1, FILL_Y(row2 + 1) - 1}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 };
2029
2030 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002031 gui_mch_set_bg_color(gui.back_pixel);
2032 PgDrawRect(&block, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 DRAW_END;
2034}
2035
2036 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01002037gui_mch_clear_all(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038{
2039 PhRect_t text_rect = {
2040 { gui.border_width, gui.border_width },
2041 { Columns * gui.char_width + gui.border_width - 1 ,
2042 Rows * gui.char_height + gui.border_width - 1 }
2043 };
2044
Bram Moolenaar15d63192011-09-14 16:05:15 +02002045 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 return;
2047
2048 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002049 gui_mch_set_bg_color(gui.back_pixel);
2050 PgDrawRect(&text_rect, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 DRAW_END;
2052}
2053
2054 void
2055gui_mch_delete_lines(int row, int num_lines)
2056{
2057 PhRect_t rect;
2058 PhPoint_t delta;
2059
Bram Moolenaar15d63192011-09-14 16:05:15 +02002060 rect.ul.x = FILL_X(gui.scroll_region_left);
2061 rect.ul.y = FILL_Y(row + num_lines);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062
Bram Moolenaar15d63192011-09-14 16:05:15 +02002063 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1;
2064 rect.lr.y = FILL_Y(gui.scroll_region_bot + 1) - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065
Bram Moolenaar15d63192011-09-14 16:05:15 +02002066 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
2067 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
2068 PhTranslateRect(&rect, &gui_ph_raw_offset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069
2070 delta.x = 0;
2071 delta.y = -num_lines * gui.char_height;
2072
2073 PgFlush();
2074
Bram Moolenaar15d63192011-09-14 16:05:15 +02002075 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)), &rect, &delta);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076
2077 gui_clear_block(
2078 gui.scroll_region_bot - num_lines + 1,
2079 gui.scroll_region_left,
2080 gui.scroll_region_bot,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002081 gui.scroll_region_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082}
2083
2084 void
2085gui_mch_insert_lines(int row, int num_lines)
2086{
2087 PhRect_t rect;
2088 PhPoint_t delta;
2089
Bram Moolenaar15d63192011-09-14 16:05:15 +02002090 rect.ul.x = FILL_X(gui.scroll_region_left);
2091 rect.ul.y = FILL_Y(row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092
Bram Moolenaar15d63192011-09-14 16:05:15 +02002093 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1;
2094 rect.lr.y = FILL_Y(gui.scroll_region_bot - num_lines + 1) - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095
Bram Moolenaar15d63192011-09-14 16:05:15 +02002096 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
2097 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
2098 PhTranslateRect(&rect, &gui_ph_raw_offset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099
2100 delta.x = 0;
2101 delta.y = num_lines * gui.char_height;
2102
2103 PgFlush();
2104
Bram Moolenaar15d63192011-09-14 16:05:15 +02002105 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)) , &rect, &delta);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106
Bram Moolenaar15d63192011-09-14 16:05:15 +02002107 gui_clear_block(row, gui.scroll_region_left,
2108 row + num_lines - 1, gui.scroll_region_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109}
2110
2111 void
2112gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
2113{
2114 static char *utf8_buffer = NULL;
2115 static int utf8_len = 0;
2116
Bram Moolenaar15d63192011-09-14 16:05:15 +02002117 PhPoint_t pos = { TEXT_X(col), TEXT_Y(row) };
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 PhRect_t rect;
2119
Bram Moolenaar15d63192011-09-14 16:05:15 +02002120 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 return;
2122
2123 DRAW_START;
2124
Bram Moolenaar15d63192011-09-14 16:05:15 +02002125 if (!(flags & DRAW_TRANSP))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {
2127 PgDrawIRect(
Bram Moolenaar15d63192011-09-14 16:05:15 +02002128 FILL_X(col), FILL_Y(row),
2129 FILL_X(col + len) - 1, FILL_Y(row + 1) - 1,
2130 Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 }
2132
Bram Moolenaar15d63192011-09-14 16:05:15 +02002133 if (flags & DRAW_UNDERL)
2134 PgSetUnderline(gui.norm_pixel, Pg_TRANSPARENT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135
Bram Moolenaar13505972019-01-24 15:04:48 +01002136 if (charset_translate != NULL && enc_utf8 == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {
2138 int src_taken, dst_made;
2139
2140 /* Use a static buffer to avoid large amounts of de/allocations */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002141 if (utf8_len < len)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002143 utf8_buffer = realloc(utf8_buffer, len * MB_LEN_MAX);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 utf8_len = len;
2145 }
2146
2147 PxTranslateToUTF(
2148 charset_translate,
2149 s,
2150 len,
2151 &src_taken,
2152 utf8_buffer,
2153 utf8_len,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002154 &dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 s = utf8_buffer;
2156 len = dst_made;
2157 }
2158
Bram Moolenaar15d63192011-09-14 16:05:15 +02002159 PgDrawText(s, len, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160
Bram Moolenaar15d63192011-09-14 16:05:15 +02002161 if (flags & DRAW_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {
2163 /* FIXME: try and only calculate these values once... */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002164 rect.ul.x = FILL_X(col) + 1;
2165 rect.ul.y = FILL_Y(row);
2166 rect.lr.x = FILL_X(col + len) - 1;
2167 rect.lr.y = FILL_Y(row + 1) - 1;
2168 /* PgSetUserClip(NULL) causes the scrollbar to not redraw... */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169#if 0
2170 pos.x++;
2171
Bram Moolenaar15d63192011-09-14 16:05:15 +02002172 PgSetUserClip(&rect);
2173 PgDrawText(s, len, &pos, 0);
2174 PgSetUserClip(NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002176 rect.lr.y -= (p_linespace + 1) / 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 /* XXX: DrawTextArea doesn't work with phditto */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002178 PgDrawTextArea(s, len, &rect, Pg_TEXT_BOTTOM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#endif
2180 }
2181
Bram Moolenaar15d63192011-09-14 16:05:15 +02002182 if (flags & DRAW_UNDERL)
2183 PgSetUnderline(Pg_TRANSPARENT, Pg_TRANSPARENT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184
2185 DRAW_END;
2186}
2187
2188/****************************************************************************/
2189/* Cursor */
2190
2191 void
2192gui_mch_draw_hollow_cursor(guicolor_T color)
2193{
2194 PhRect_t r;
2195
2196 /* FIXME: Double width characters */
2197
Bram Moolenaar15d63192011-09-14 16:05:15 +02002198 r.ul.x = FILL_X(gui.col);
2199 r.ul.y = FILL_Y(gui.row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 r.lr.x = r.ul.x + gui.char_width - 1;
2201 r.lr.y = r.ul.y + gui.char_height - 1;
2202
2203 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002204 PgSetStrokeColor(color);
2205 PgDrawRect(&r, Pg_DRAW_STROKE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002206 DRAW_END;
2207}
2208
2209 void
2210gui_mch_draw_part_cursor(int w, int h, guicolor_T color)
2211{
2212 PhRect_t r;
2213
Bram Moolenaar15d63192011-09-14 16:05:15 +02002214 r.ul.x = FILL_X(gui.col);
2215 r.ul.y = FILL_Y(gui.row) + gui.char_height - h;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 r.lr.x = r.ul.x + w - 1;
2217 r.lr.y = r.ul.y + h - 1;
2218
2219 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002220 gui_mch_set_bg_color(color);
2221 PgDrawRect(&r, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 DRAW_END;
2223}
2224
Bram Moolenaar703a8042016-06-04 16:24:32 +02002225 int
2226gui_mch_is_blinking(void)
2227{
2228 return blink_state != BLINK_NONE;
2229}
2230
Bram Moolenaar9d5d3c92016-07-07 16:43:02 +02002231 int
2232gui_mch_is_blink_off(void)
2233{
2234 return blink_state == BLINK_OFF;
2235}
2236
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 void
2238gui_mch_set_blinking(long wait, long on, long off)
2239{
2240 blink_waittime = wait;
2241 blink_ontime = on;
2242 blink_offtime = off;
2243}
2244
2245 void
2246gui_mch_start_blink(void)
2247{
2248 /* Only turn on the timer on if none of the times are zero */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002249 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002251 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
2252 blink_waittime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 blink_state = BLINK_ON;
2254 gui_update_cursor(TRUE, FALSE);
2255 }
2256}
2257
2258 void
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +01002259gui_mch_stop_blink(int may_call_gui_update_cursor)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002261 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, 0, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +01002263 if (blink_state == BLINK_OFF && may_call_gui_update_cursor)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264 gui_update_cursor(TRUE, FALSE);
2265
2266 blink_state = BLINK_NONE;
2267}
2268
2269/****************************************************************************/
2270/* miscellaneous functions */
2271
2272 void
2273gui_mch_beep(void)
2274{
2275 PtBeep();
2276}
2277
2278 void
2279gui_mch_flash(int msec)
2280{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002281 PgSetFillXORColor(Pg_BLACK, Pg_WHITE);
2282 PgSetDrawMode(Pg_DRAWMODE_XOR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 gui_mch_clear_all();
2284 gui_mch_flush();
2285
Bram Moolenaar15d63192011-09-14 16:05:15 +02002286 ui_delay((long) msec, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287
2288 gui_mch_clear_all();
Bram Moolenaar15d63192011-09-14 16:05:15 +02002289 PgSetDrawMode(Pg_DRAWMODE_OPAQUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 gui_mch_flush();
2291}
2292
2293 void
2294gui_mch_flush(void)
2295{
2296 PgFlush();
2297}
2298
2299 void
2300gui_mch_set_text_area_pos(int x, int y, int w, int h)
2301{
2302 PhArea_t area = {{x, y}, {w, h}};
2303
Bram Moolenaar15d63192011-09-14 16:05:15 +02002304 PtSetResource(gui.vimTextArea, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305}
2306
2307 int
2308gui_mch_haskey(char_u *name)
2309{
2310 int i;
2311
2312 for (i = 0; special_keys[i].key_sym != 0; i++)
2313 if (name[0] == special_keys[i].vim_code0 &&
2314 name[1] == special_keys[i].vim_code1)
Bram Moolenaard2221132011-07-27 14:09:09 +02002315 return OK;
2316 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317}
2318
2319/****************************************************************************/
2320/* Menu */
2321
2322#ifdef FEAT_TOOLBAR
2323#include "toolbar.phi"
2324
2325static PhImage_t *gui_ph_toolbar_images[] = {
2326 &tb_new_phi,
2327 &tb_open_phi,
2328 &tb_save_phi,
2329 &tb_undo_phi,
2330 &tb_redo_phi,
2331 &tb_cut_phi,
2332 &tb_copy_phi,
2333 &tb_paste_phi,
2334 &tb_print_phi,
2335 &tb_help_phi,
2336 &tb_find_phi,
2337 &tb_save_all_phi,
2338 &tb_save_session_phi,
2339 &tb_new_session_phi,
2340 &tb_load_session_phi,
2341 &tb_macro_phi,
2342 &tb_replace_phi,
2343 &tb_close_phi,
2344 &tb_maximize_phi,
2345 &tb_minimize_phi,
2346 &tb_split_phi,
2347 &tb_shell_phi,
2348 &tb_find_prev_phi,
2349 &tb_find_next_phi,
2350 &tb_find_help_phi,
2351 &tb_make_phi,
2352 &tb_jump_phi,
2353 &tb_ctags_phi,
2354 &tb_vsplit_phi,
2355 &tb_maxwidth_phi,
2356 &tb_minwidth_phi
2357};
2358
2359static PhImage_t *
Bram Moolenaar15d63192011-09-14 16:05:15 +02002360gui_ph_toolbar_load_icon(char_u *iconfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361{
2362 static PhImage_t external_icon;
2363 PhImage_t *temp_phi = NULL;
2364
Bram Moolenaar15d63192011-09-14 16:05:15 +02002365 temp_phi = PxLoadImage(iconfile, NULL);
2366 if (temp_phi != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {
2368 /* The label widget will free the image/palette/etc. for us when
2369 * it's destroyed */
2370 temp_phi->flags |= Ph_RELEASE_IMAGE_ALL;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002371 memcpy(&external_icon, temp_phi, sizeof(external_icon));
2372 free(temp_phi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373
2374 temp_phi = &external_icon;
2375 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002376 return temp_phi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377}
2378
2379/*
2380 * This returns either a builtin icon image, an external image or NULL
2381 * if it can't find either. The caller can't and doesn't need to try and
2382 * free() the returned image, and it can't store the image pointer.
2383 * (When setting the Pt_ARG_LABEL_IMAGE resource, the contents of the
2384 * PhImage_t are copied, and the original PhImage_t aren't needed anymore).
2385 */
2386static PhImage_t *
Bram Moolenaar15d63192011-09-14 16:05:15 +02002387gui_ph_toolbar_find_icon(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388{
2389 char_u full_pathname[ MAXPATHL + 1 ];
2390 PhImage_t *icon = NULL;
2391
Bram Moolenaar15d63192011-09-14 16:05:15 +02002392 if (menu->icon_builtin == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002394 if (menu->iconfile != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 /* TODO: use gui_find_iconfile() */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002396 icon = gui_ph_toolbar_load_icon(menu->iconfile);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397
2398 /* TODO: Restrict loading to just .png? Search for any format? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002399 if ((icon == NULL) &&
2400 ((gui_find_bitmap(menu->name, full_pathname, "gif") == OK) ||
2401 (gui_find_bitmap(menu->name, full_pathname, "png") == OK)))
2402 icon = gui_ph_toolbar_load_icon(full_pathname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403
Bram Moolenaar15d63192011-09-14 16:05:15 +02002404 if (icon != NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002405 return icon;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 }
2407
Bram Moolenaar15d63192011-09-14 16:05:15 +02002408 if (menu->iconidx >= 0 &&
2409 (menu->iconidx < ARRAY_LENGTH(gui_ph_toolbar_images)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {
Bram Moolenaard2221132011-07-27 14:09:09 +02002411 return gui_ph_toolbar_images[menu->iconidx];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 }
2413
Bram Moolenaard2221132011-07-27 14:09:09 +02002414 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415}
2416#endif
2417
Bram Moolenaar15d63192011-09-14 16:05:15 +02002418#if defined(FEAT_MENU) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 void
2420gui_mch_enable_menu(int flag)
2421{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002422 if (flag != 0)
2423 PtRealizeWidget(gui.vimMenuBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002425 PtUnrealizeWidget(gui.vimMenuBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426}
2427
2428 void
2429gui_mch_set_menu_pos(int x, int y, int w, int h)
2430{
2431 /* Nothing */
2432}
2433
2434/* Change the position of a menu button in the parent */
2435 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +02002436gui_ph_position_menu(PtWidget_t *widget, int priority)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437{
2438 PtWidget_t *traverse;
2439 vimmenu_T *menu;
2440
Bram Moolenaar15d63192011-09-14 16:05:15 +02002441 traverse = PtWidgetChildBack(PtWidgetParent(widget));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442
2443 /* Iterate through the list of widgets in traverse, until
2444 * we find the position we want to insert our widget into */
2445 /* TODO: traverse from front to back, possible speedup? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002446 while (traverse != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002448 PtGetResource(traverse, Pt_ARG_POINTER, &menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449
Bram Moolenaar15d63192011-09-14 16:05:15 +02002450 if (menu != NULL &&
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 priority < menu->priority &&
Bram Moolenaar15d63192011-09-14 16:05:15 +02002452 widget != traverse)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {
2454 /* Insert the widget before the current traverse widget */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002455 PtWidgetInsert(widget, traverse, 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 return;
2457 }
2458
Bram Moolenaar15d63192011-09-14 16:05:15 +02002459 traverse = PtWidgetBrotherInFront(traverse);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 }
2461}
2462
2463/* the index is ignored because it's not useful for our purposes */
2464 void
2465gui_mch_add_menu(vimmenu_T *menu, int index)
2466{
2467 vimmenu_T *parent = menu->parent;
2468 char_u *accel_key;
2469 char_u mnemonic_str[MB_LEN_MAX];
2470 int n;
2471 PtArg_t args[5];
2472
2473 menu->submenu_id = menu->id = NULL;
2474
Bram Moolenaar15d63192011-09-14 16:05:15 +02002475 if (menu_is_menubar(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {
2477
Bram Moolenaar15d63192011-09-14 16:05:15 +02002478 accel_key = vim_strchr(menu->name, '&');
2479 if (accel_key != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {
2481 mnemonic_str[0] = accel_key[1];
2482 mnemonic_str[1] = NUL;
2483 }
2484
2485 /* Create the menu button */
2486 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002487 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2488 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0);
2489 if (accel_key != NULL)
2490 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str, 0);
2491 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492
Bram Moolenaar15d63192011-09-14 16:05:15 +02002493 if (parent != NULL)
2494 PtSetArg(&args[ n++ ], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495
Bram Moolenaar15d63192011-09-14 16:05:15 +02002496 menu->id = PtCreateWidget(PtMenuButton,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 (parent == NULL) ? gui.vimMenuBar : parent->submenu_id,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002498 n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499
Bram Moolenaar15d63192011-09-14 16:05:15 +02002500 PtAddCallback(menu->id, Pt_CB_ARM, gui_ph_handle_pulldown_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501
2502 /* Create the actual menu */
2503 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002504 if (parent != NULL)
2505 PtSetArg(&args[ n++ ], Pt_ARG_MENU_FLAGS, Pt_TRUE, Pt_MENU_CHILD);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506
Bram Moolenaar15d63192011-09-14 16:05:15 +02002507 menu->submenu_id = PtCreateWidget(PtMenu, menu->id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508
Bram Moolenaar15d63192011-09-14 16:05:15 +02002509 if (parent == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002511 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED,
2512 gui_ph_handle_menu_unrealized, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513
Bram Moolenaar15d63192011-09-14 16:05:15 +02002514 if (menu->mnemonic != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002516 PtAddHotkeyHandler(gui.vimWindow, tolower(menu->mnemonic),
2517 Pk_KM_Alt, 0, menu, gui_ph_handle_pulldown_menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 }
2519 }
2520
Bram Moolenaar15d63192011-09-14 16:05:15 +02002521 gui_ph_position_menu(menu->id, menu->priority);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522
2523 /* Redraw menubar here instead of gui_mch_draw_menubar */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002524 if (gui.menu_is_active)
2525 PtRealizeWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002527 else if (menu_is_popup(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002529 menu->submenu_id = PtCreateWidget(PtMenu, gui.vimWindow, 0, NULL);
2530 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED,
2531 gui_ph_handle_menu_unrealized, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 }
2533}
2534
2535 void
2536gui_mch_add_menu_item(vimmenu_T *menu, int index)
2537{
2538 vimmenu_T *parent = menu->parent;
2539 char_u *accel_key;
2540 char_u mnemonic_str[MB_LEN_MAX];
2541 int n;
2542 PtArg_t args[13];
2543
2544 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002545 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546
2547#ifdef FEAT_TOOLBAR
Bram Moolenaar15d63192011-09-14 16:05:15 +02002548 if (menu_is_toolbar(parent->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002550 if (menu_is_separator(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002552 PtSetArg(&args[ n++ ], Pt_ARG_SEP_FLAGS,
2553 Pt_SEP_VERTICAL, Pt_SEP_ORIENTATION);
2554 PtSetArg(&args[ n++ ], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0);
2555 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS,
2556 Pt_TRUE, Pt_ANCHOR_TOP_BOTTOM);
2557 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, 2, 0);
2558 menu->id = PtCreateWidget(PtSeparator, gui.vimToolBar, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 }
2560 else
2561 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002562 if (strstr((const char *) p_toolbar, "text") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002564 PtSetArg(&args[ n++ ], Pt_ARG_BALLOON_POSITION,
2565 Pt_BALLOON_BOTTOM, 0);
2566 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2567 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_FONT, "TextFont08", 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002569 if ((strstr((const char *) p_toolbar, "icons") != NULL) &&
2570 (gui_ph_toolbar_images != NULL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002572 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_IMAGE,
2573 gui_ph_toolbar_find_icon(menu), 0);
2574 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_TYPE, Pt_TEXT_IMAGE, 0);
2575 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_IMAGE_SPACING, 0, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002577 if (strstr((const char *) p_toolbar, "tooltips") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002579 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_BALLOON,
2580 gui_ph_show_tooltip, 0);
2581 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_FLAGS,
2582 Pt_TRUE, Pt_SHOW_BALLOON);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002584 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 1, 0);
2585 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 1, 0);
2586 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_FALSE,
2587 Pt_HIGHLIGHTED | Pt_GETS_FOCUS);
2588 PtSetArg(&args[ n++ ], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0);
2589 menu->id = PtCreateWidget(PtButton, gui.vimToolBar, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590
Bram Moolenaar15d63192011-09-14 16:05:15 +02002591 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 }
2593 /* Update toolbar if it's open */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002594 if (PtWidgetIsRealized(gui.vimToolBar))
2595 PtRealizeWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 }
2597 else
2598#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02002599 if (menu_is_separator(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002601 menu->id = PtCreateWidget(PtSeparator, parent->submenu_id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 }
2603 else
2604 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002605 accel_key = vim_strchr(menu->name, '&');
2606 if (accel_key != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {
2608 mnemonic_str[0] = accel_key[1];
2609 mnemonic_str[1] = NUL;
2610 }
2611
Bram Moolenaar15d63192011-09-14 16:05:15 +02002612 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2613 if (accel_key != NULL)
2614 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str,
2615 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616
Bram Moolenaar15d63192011-09-14 16:05:15 +02002617 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618
Bram Moolenaar15d63192011-09-14 16:05:15 +02002619 menu->id = PtCreateWidget(PtMenuButton, parent->submenu_id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620
Bram Moolenaar15d63192011-09-14 16:05:15 +02002621 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622
2623#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02002624 if (gui_ph_is_buffer_item(menu, parent) == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002626 PtAddCallback(menu->id, Pt_CB_DESTROYED,
2627 gui_ph_handle_buffer_remove, menu);
2628 gui_ph_pg_add_buffer(menu->dname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 }
2630#endif
2631 }
2632
Bram Moolenaar15d63192011-09-14 16:05:15 +02002633 gui_ph_position_menu(menu->id, menu->priority);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634}
2635
2636 void
2637gui_mch_destroy_menu(vimmenu_T *menu)
2638{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002639 if (menu->submenu_id != NULL)
2640 PtDestroyWidget(menu->submenu_id);
2641 if (menu->id != NULL)
2642 PtDestroyWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643
2644 menu->submenu_id = NULL;
2645 menu->id = NULL;
2646}
2647
2648 void
2649gui_mch_menu_grey(vimmenu_T *menu, int grey)
2650{
2651 long flags, mask, fields;
2652
Bram Moolenaar15d63192011-09-14 16:05:15 +02002653 if (menu->id == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 return;
2655
Bram Moolenaar15d63192011-09-14 16:05:15 +02002656 flags = PtWidgetFlags(menu->id);
2657 if (PtWidgetIsClass(menu->id, PtMenuButton) &&
2658 PtWidgetIsClass(PtWidgetParent(menu->id), PtMenu))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {
2660 fields = Pt_FALSE;
2661 mask = Pt_SELECTABLE | Pt_HIGHLIGHTED;
2662 }
2663 else
2664 {
2665 fields = Pt_TRUE;
2666 mask = Pt_BLOCKED | Pt_GHOST;
2667 }
2668
Bram Moolenaar15d63192011-09-14 16:05:15 +02002669 if (! grey)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 fields = ~fields;
2671
Bram Moolenaar15d63192011-09-14 16:05:15 +02002672 PtSetResource(menu->id, Pt_ARG_FLAGS, fields,
2673 mask);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674}
2675
2676 void
2677gui_mch_menu_hidden(vimmenu_T *menu, int hidden)
2678{
2679 /* TODO: [un]realize the widget? */
2680}
2681
2682 void
2683gui_mch_draw_menubar(void)
2684{
2685 /* The only time a redraw is needed is when a menu button
2686 * is added to the menubar, and that is detected and the bar
2687 * redrawn in gui_mch_add_menu_item
2688 */
2689}
2690
2691 void
2692gui_mch_show_popupmenu(vimmenu_T *menu)
2693{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002694 PtSetResource(menu->submenu_id, Pt_ARG_POS, &abs_mouse, 0);
2695 PtRealizeWidget(menu->submenu_id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696}
2697
2698 void
2699gui_mch_toggle_tearoffs(int enable)
2700{
2701 /* No tearoffs yet */
2702}
2703
2704#endif
2705
Bram Moolenaar15d63192011-09-14 16:05:15 +02002706#if defined(FEAT_TOOLBAR) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 void
2708gui_mch_show_toolbar(int showit)
2709{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002710 if (showit)
2711 PtRealizeWidget(gui.vimToolBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002713 PtUnrealizeWidget(gui.vimToolBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714}
2715#endif
2716
2717/****************************************************************************/
2718/* Fonts */
2719
2720 static GuiFont
2721gui_ph_get_font(
2722 char_u *font_name,
2723 int_u font_flags,
2724 int_u font_size,
2725 /* Check whether the resulting font has the font flags and size that
2726 * was asked for */
2727 int_u enforce
2728 )
2729{
2730 char_u *font_tag;
2731 FontQueryInfo info;
2732 int_u style;
2733
Bram Moolenaar15d63192011-09-14 16:05:15 +02002734 font_tag = alloc(MAX_FONT_TAG);
2735 if (font_tag != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002737 if (PfGenerateFontName(font_name, font_flags, font_size,
2738 font_tag) != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {
2740 /* Enforce some limits on the font used */
2741 style = PHFONT_INFO_FIXED;
2742
Bram Moolenaar15d63192011-09-14 16:05:15 +02002743 if (enforce & PF_STYLE_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 style |= PHFONT_INFO_BOLD;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002745 if (enforce & PF_STYLE_ANTIALIAS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 style |= PHFONT_INFO_ALIAS;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002747 if (enforce & PF_STYLE_ITALIC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 style |= PHFONT_INFO_ITALIC;
2749
Bram Moolenaar15d63192011-09-14 16:05:15 +02002750 PfQueryFontInfo(font_tag, &info);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751
Bram Moolenaar15d63192011-09-14 16:05:15 +02002752 if (info.size == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 font_size = 0;
2754
2755 /* Make sure font size matches, and that the font style
2756 * at least has the bits we're checking for */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002757 if (font_size == info.size &&
2758 style == (info.style & style))
Bram Moolenaard2221132011-07-27 14:09:09 +02002759 return (GuiFont)font_tag;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002761 vim_free(font_tag);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002763 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764}
2765
2766/*
2767 * Split up the vim font name
2768 *
2769 * vim_font is in the form of
2770 * <name>:s<height>:a:b:i
2771 *
2772 * a = antialias
2773 * b = bold
2774 * i = italic
2775 *
2776 */
2777
2778 static int
2779gui_ph_parse_font_name(
2780 char_u *vim_font,
2781 char_u **font_name,
2782 int_u *font_flags,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002783 int_u *font_size)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784{
2785 char_u *mark;
2786 int_u name_len, size;
2787
Bram Moolenaar15d63192011-09-14 16:05:15 +02002788 mark = vim_strchr(vim_font, ':');
2789 if (mark == NULL)
2790 name_len = STRLEN(vim_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002792 name_len = (int_u) (mark - vim_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793
Bram Moolenaar15d63192011-09-14 16:05:15 +02002794 *font_name = vim_strnsave(vim_font, name_len);
Bram Moolenaard0988c52011-08-10 12:19:04 +02002795 if (*font_name != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002797 if (mark != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002799 while (*mark != NUL && *mark++ == ':')
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002801 switch (tolower(*mark++))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {
2803 case 'a': *font_flags |= PF_STYLE_ANTIALIAS; break;
2804 case 'b': *font_flags |= PF_STYLE_BOLD; break;
2805 case 'i': *font_flags |= PF_STYLE_ITALIC; break;
2806
2807 case 's':
Bram Moolenaar15d63192011-09-14 16:05:15 +02002808 size = getdigits(&mark);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 /* Restrict the size to some vague limits */
Bram Moolenaard0988c52011-08-10 12:19:04 +02002810 if (size < 1 || size > 100)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 size = 8;
2812
2813 *font_size = size;
2814 break;
2815
2816 default:
2817 break;
2818 }
2819 }
2820 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002821 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002823 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824}
2825
2826 int
2827gui_mch_init_font(char_u *vim_font_name, int fontset)
2828{
2829 char_u *font_tag;
2830 char_u *font_name = NULL;
2831 int_u font_flags = 0;
2832 int_u font_size = 12;
2833
2834 FontQueryInfo info;
2835 PhRect_t extent;
2836
Bram Moolenaard0988c52011-08-10 12:19:04 +02002837 if (vim_font_name == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {
2839 /* Default font */
Bram Moolenaara0b19972009-07-01 14:13:18 +00002840 vim_font_name = "PC Terminal";
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 }
2842
Bram Moolenaar15d63192011-09-14 16:05:15 +02002843 if (STRCMP(vim_font_name, "*") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002845 font_tag = PtFontSelection(gui.vimWindow, NULL, NULL,
2846 "pcterm12", -1, PHFONT_FIXED, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847
Bram Moolenaard0988c52011-08-10 12:19:04 +02002848 if (font_tag == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002849 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850
Bram Moolenaar15d63192011-09-14 16:05:15 +02002851 gui_mch_free_font(gui.norm_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 gui.norm_font = font_tag;
2853
Bram Moolenaar15d63192011-09-14 16:05:15 +02002854 PfQueryFontInfo(font_tag, &info);
2855 font_name = vim_strsave(info.font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 }
2857 else
2858 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002859 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags,
2860 &font_size) == FALSE)
Bram Moolenaard2221132011-07-27 14:09:09 +02002861 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862
Bram Moolenaar15d63192011-09-14 16:05:15 +02002863 font_tag = gui_ph_get_font(font_name, font_flags, font_size, 0);
Bram Moolenaard0988c52011-08-10 12:19:04 +02002864 if (font_tag == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002866 vim_free(font_name);
Bram Moolenaard2221132011-07-27 14:09:09 +02002867 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 }
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002869
Bram Moolenaar15d63192011-09-14 16:05:15 +02002870 gui_mch_free_font(gui.norm_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 gui.norm_font = font_tag;
2872 }
2873
Bram Moolenaar15d63192011-09-14 16:05:15 +02002874 gui_mch_free_font(gui.bold_font);
2875 gui.bold_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_BOLD,
2876 font_size, PF_STYLE_BOLD);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877
Bram Moolenaar15d63192011-09-14 16:05:15 +02002878 gui_mch_free_font(gui.ital_font);
2879 gui.ital_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_ITALIC,
2880 font_size, PF_STYLE_ITALIC);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881
2882 /* This extent was brought to you by the letter 'g' */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002883 PfExtentText(&extent, NULL, font_tag, "g", 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884
2885 gui.char_width = extent.lr.x - extent.ul.x + 1;
2886 gui.char_height = (- extent.ul.y) + extent.lr.y + 1;
2887 gui.char_ascent = - extent.ul.y;
2888
Bram Moolenaar15d63192011-09-14 16:05:15 +02002889 vim_free(font_name);
Bram Moolenaard2221132011-07-27 14:09:09 +02002890 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891}
2892
Bram Moolenaar02743632005-07-25 20:42:36 +00002893/*
2894 * Adjust gui.char_height (after 'linespace' was changed).
2895 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 int
Bram Moolenaar02743632005-07-25 20:42:36 +00002897gui_mch_adjust_charheight(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898{
2899 FontQueryInfo info;
2900
Bram Moolenaar15d63192011-09-14 16:05:15 +02002901 PfQueryFontInfo(gui.norm_font, &info);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902
2903 gui.char_height = - info.ascender + info.descender + p_linespace;
2904 gui.char_ascent = - info.ascender + p_linespace / 2;
2905
Bram Moolenaard2221132011-07-27 14:09:09 +02002906 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907}
2908
2909 GuiFont
2910gui_mch_get_font(char_u *vim_font_name, int report_error)
2911{
2912 char_u *font_name;
2913 char_u *font_tag;
2914 int_u font_size = 12;
2915 int_u font_flags = 0;
2916
Bram Moolenaar15d63192011-09-14 16:05:15 +02002917 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags,
2918 &font_size) != FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002920 font_tag = gui_ph_get_font(font_name, font_flags, font_size, -1);
2921 vim_free(font_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922
Bram Moolenaard0988c52011-08-10 12:19:04 +02002923 if (font_tag != NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002924 return (GuiFont)font_tag;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 }
2926
Bram Moolenaard0988c52011-08-10 12:19:04 +02002927 if (report_error)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01002928 semsg(e_font, vim_font_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929
Bram Moolenaard2221132011-07-27 14:09:09 +02002930 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931}
2932
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002933#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002934/*
2935 * Return the name of font "font" in allocated memory.
2936 * Don't know how to get the actual name, thus use the provided name.
2937 */
2938 char_u *
Bram Moolenaar68c2f632016-01-30 17:24:07 +01002939gui_mch_get_fontname(GuiFont font, char_u *name)
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002940{
2941 if (name == NULL)
2942 return NULL;
2943 return vim_strsave(name);
2944}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002945#endif
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002946
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 void
2948gui_mch_set_font(GuiFont font)
2949{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002950 PgSetFont(font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951}
2952
2953 void
2954gui_mch_free_font(GuiFont font)
2955{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002956 vim_free(font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957}
2958