blob: 327b356514c2a5800986f82d32a8dedbdb74a1b5 [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
215#ifdef FEAT_TOOLBAR
Bram Moolenaard2221132011-07-27 14:09:09 +0200216static PhImage_t *gui_ph_toolbar_find_icon(vimmenu_T *menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217#endif
218
Bram Moolenaard2221132011-07-27 14:09:09 +0200219static void gui_ph_draw_start(void);
220static void gui_ph_draw_end(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221
222/* Set the text for the balloon */
Bram Moolenaard2221132011-07-27 14:09:09 +0200223static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224 PtWidget_t *widget,
225 int position,
226 char *text,
227 char *font,
228 PgColor_t fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200229 PgColor_t text_color);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230
231/****************************************************************************/
232
Bram Moolenaard2221132011-07-27 14:09:09 +0200233static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234 PtWidget_t *widget,
235 int position,
236 char *text,
237 char *font,
238 PgColor_t fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200239 PgColor_t text_color)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240{
241 PtArg_t arg;
242 vimmenu_T *menu;
243 char_u *tooltip;
244
Bram Moolenaard2221132011-07-27 14:09:09 +0200245 PtSetArg(&arg, Pt_ARG_POINTER, &menu, 0);
246 PtGetResources(widget, 1, &arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247
248 /* Override the text and position */
249
250 tooltip = text;
Bram Moolenaard2221132011-07-27 14:09:09 +0200251 if (menu != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252 {
253 int index = MENU_INDEX_TIP;
Bram Moolenaard2221132011-07-27 14:09:09 +0200254 if (menu->strings[ index ] != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255 tooltip = menu->strings[ index ];
256 }
257
Bram Moolenaard2221132011-07-27 14:09:09 +0200258 return PtInflateBalloon(
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259 window,
260 widget,
261 /* Don't put the balloon at the bottom,
262 * it gets drawn over by gfx done in the PtRaw */
263 Pt_BALLOON_TOP,
264 tooltip,
265 font,
266 fill_color,
Bram Moolenaard2221132011-07-27 14:09:09 +0200267 text_color);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268}
269
270 static void
Bram Moolenaard2221132011-07-27 14:09:09 +0200271gui_ph_resize_container(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272{
273 PhArea_t area;
274
Bram Moolenaard2221132011-07-27 14:09:09 +0200275 PtWidgetArea(gui.vimWindow, &area);
276 PtWidgetPos (gui.vimContainer, &area.pos);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277
Bram Moolenaard2221132011-07-27 14:09:09 +0200278 PtSetResource(gui.vimContainer, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279}
280
281 static int
282gui_ph_handle_menu_resize(
283 PtWidget_t *widget,
284 void *other,
Bram Moolenaard2221132011-07-27 14:09:09 +0200285 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286{
287 PtContainerCallback_t *sizes = info->cbdata;
288 PtWidget_t *container;
289 PhPoint_t below_menu;
290 int_u height;
291
292 height = sizes->new_dim.h;
293
Bram Moolenaarccc18222007-05-10 18:25:20 +0000294 /* Because vim treats the toolbar and menubar separately,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295 * and here they're lumped together into a PtToolbarGroup,
296 * we only need either menu_height or toolbar_height set at once */
Bram Moolenaard2221132011-07-27 14:09:09 +0200297 if (gui.menu_is_active)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000298 {
299 gui.menu_height = height;
300 gui.toolbar_height = 0;
301 }
302#ifdef FEAT_TOOLBAR
303 else
304 gui.toolbar_height = height;
305#endif
306
307 below_menu.x = 0;
308 below_menu.y = height;
309
310#ifdef USE_PANEL_GROUP
311 container = gui.vimPanelGroup;
312#else
313 container = gui.vimContainer;
314#endif
315
Bram Moolenaard2221132011-07-27 14:09:09 +0200316 PtSetResource(container, Pt_ARG_POS, &below_menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317
318 gui_ph_resize_container();
319
320#ifdef USE_PANEL_GROUP
321 gui_ph_get_panelgroup_margins(
322 &pg_margin_top, &pg_margin_bottom,
Bram Moolenaard2221132011-07-27 14:09:09 +0200323 &pg_margin_left, &pg_margin_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#endif
Bram Moolenaard2221132011-07-27 14:09:09 +0200325 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326}
327
328/*
329 * Pt_ARG_TIMER_REPEAT isn't used because the on & off times
330 * are different
331 */
332 static int
333gui_ph_handle_timer_cursor(
334 PtWidget_t *widget,
335 void *data,
Bram Moolenaard2221132011-07-27 14:09:09 +0200336 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337{
Bram Moolenaard2221132011-07-27 14:09:09 +0200338 if (blink_state == BLINK_ON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339 {
340 gui_undraw_cursor();
341 blink_state = BLINK_OFF;
Bram Moolenaard2221132011-07-27 14:09:09 +0200342 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
343 blink_offtime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344 }
345 else
346 {
347 gui_update_cursor(TRUE, FALSE);
348 blink_state = BLINK_ON;
Bram Moolenaard2221132011-07-27 14:09:09 +0200349 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
350 blink_ontime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200352 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353}
354
355 static int
356gui_ph_handle_timer_timeout(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
357{
358 is_timeout = TRUE;
359
Bram Moolenaard2221132011-07-27 14:09:09 +0200360 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361}
362
363 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200364gui_ph_handle_window_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365{
366 PhWindowEvent_t *we = info->cbdata;
367 ushort_t *width, *height;
368
Bram Moolenaard0988c52011-08-10 12:19:04 +0200369 switch (we->event_f) {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370 case Ph_WM_CLOSE:
371 gui_shell_closed();
372 break;
373
374 case Ph_WM_FOCUS:
375 /* Just in case it's hidden and needs to be shown */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200376 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377
Bram Moolenaard0988c52011-08-10 12:19:04 +0200378 if (we->event_state == Ph_WM_EVSTATE_FOCUS)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379 {
380 gui_focus_change(TRUE);
381 gui_mch_start_blink();
382 }
383 else
384 {
385 gui_focus_change(FALSE);
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +0100386 gui_mch_stop_blink(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387 }
388 break;
389
390 case Ph_WM_RESIZE:
Bram Moolenaard0988c52011-08-10 12:19:04 +0200391 PtGetResource(gui.vimWindow, Pt_ARG_WIDTH, &width, 0);
392 PtGetResource(gui.vimWindow, Pt_ARG_HEIGHT, &height, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393#ifdef USE_PANEL_GROUP
394 width -= (pg_margin_left + pg_margin_right);
395 height -= (pg_margin_top + pg_margin_bottom);
396#endif
Bram Moolenaard0988c52011-08-10 12:19:04 +0200397 gui_resize_shell(*width, *height);
398 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399 is_ignore_draw = FALSE;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200400 PtEndFlux(gui.vimContainer);
401 PtContainerRelease(gui.vimContainer);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402 break;
403
404 default:
405 break;
406 }
407
Bram Moolenaard2221132011-07-27 14:09:09 +0200408 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409}
410
411 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200412gui_ph_handle_scrollbar(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413{
414 PtScrollbarCallback_t *scroll;
415 scrollbar_T *sb;
416 int value, dragging = FALSE;
417
418 scroll = info->cbdata;
419
420 sb = (scrollbar_T *) data;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200421 if (sb != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422 {
423 value = scroll->position;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200424 switch (scroll->action)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425 {
426 case Pt_SCROLL_DRAGGED:
427 dragging = TRUE;
428 break;
429
430 case Pt_SCROLL_SET:
431 /* FIXME: return straight away here? */
Bram Moolenaard2221132011-07-27 14:09:09 +0200432 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433 break;
434 }
435
436 gui_drag_scrollbar(sb, value, dragging);
437 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200438 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439}
440
441 static int
Bram Moolenaard0988c52011-08-10 12:19:04 +0200442gui_ph_handle_keyboard(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443{
444 PhKeyEvent_t *key;
445 unsigned char string[6];
446 int len, i;
447 int ch, modifiers;
448
Bram Moolenaard0988c52011-08-10 12:19:04 +0200449 key = PhGetData(info->event);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450
451 ch = modifiers = len = 0;
452
Bram Moolenaard0988c52011-08-10 12:19:04 +0200453 if (p_mh)
454 gui_mch_mousehide(MOUSE_HIDE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
456 /* We're a good lil photon program, aren't we? yes we are, yeess wee arrr */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200457 if (key->key_flags & Pk_KF_Compose)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458 {
Bram Moolenaard2221132011-07-27 14:09:09 +0200459 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460 }
461
Bram Moolenaard0988c52011-08-10 12:19:04 +0200462 if ((key->key_flags & Pk_KF_Cap_Valid) &&
463 PkIsKeyDown(key->key_flags))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000464 {
465#ifdef FEAT_MENU
466 /*
467 * Only show the menu if the Alt key is down, and the Shift & Ctrl
468 * keys aren't down, as well as the other conditions
469 */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200470 if (((key->key_mods & Pk_KM_Alt) &&
471 !(key->key_mods & Pk_KM_Shift) &&
472 !(key->key_mods & Pk_KM_Ctrl)) &&
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473 gui.menu_is_active &&
Bram Moolenaard0988c52011-08-10 12:19:04 +0200474 (*p_wak == 'y' ||
475 (*p_wak == 'm' &&
476 gui_is_menu_shortcut(key->key_cap))))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477 {
478 /* Fallthrough and let photon look for the hotkey */
Bram Moolenaard2221132011-07-27 14:09:09 +0200479 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480 }
481#endif
482
Bram Moolenaar15d63192011-09-14 16:05:15 +0200483 for (i = 0; special_keys[i].key_sym != 0; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000484 {
Bram Moolenaard0988c52011-08-10 12:19:04 +0200485 if (special_keys[i].key_sym == key->key_cap)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000486 {
487 len = 0;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200488 if (special_keys[i].vim_code1 == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489 ch = special_keys[i].vim_code0;
490 else
491 {
492 /* Detect if a keypad number key has been pressed
493 * and change the key if Num Lock is on */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200494 if (key->key_cap >= Pk_KP_Enter && key->key_cap <= Pk_KP_9
495 && (key->key_mods & Pk_KM_Num_Lock))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496 {
497 /* FIXME: For now, just map the key to a ascii value
498 * (see <photon/PkKeyDef.h>) */
499 ch = key->key_cap - 0xf080;
500 }
501 else
Bram Moolenaard0988c52011-08-10 12:19:04 +0200502 ch = TO_SPECIAL(special_keys[i].vim_code0,
503 special_keys[i].vim_code1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 }
505 break;
506 }
507 }
508
Bram Moolenaard0988c52011-08-10 12:19:04 +0200509 if (key->key_mods & Pk_KM_Ctrl)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 modifiers |= MOD_MASK_CTRL;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200511 if (key->key_mods & Pk_KM_Alt)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 modifiers |= MOD_MASK_ALT;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200513 if (key->key_mods & Pk_KM_Shift)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 modifiers |= MOD_MASK_SHIFT;
515
516 /* Is this not a special key? */
Bram Moolenaard0988c52011-08-10 12:19:04 +0200517 if (special_keys[i].key_sym == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 {
Bram Moolenaard0988c52011-08-10 12:19:04 +0200519 ch = PhTo8859_1(key);
520 if (ch == -1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521#ifdef FEAT_MBYTE
Bram Moolenaard0988c52011-08-10 12:19:04 +0200522 || (enc_utf8 && ch > 127)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523#endif
524 )
525 {
526#ifdef FEAT_MBYTE
Bram Moolenaard0988c52011-08-10 12:19:04 +0200527 len = PhKeyToMb(string, key);
528 if (len > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {
530 static char buf[6];
531 int src_taken, dst_made;
Bram Moolenaard0988c52011-08-10 12:19:04 +0200532 if (enc_utf8 != TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {
534 PxTranslateFromUTF(
535 charset_translate,
536 string,
537 len,
538 &src_taken,
539 buf,
540 6,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200541 &dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200543 add_to_input_buf(buf, dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 }
545 else
546 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200547 add_to_input_buf(string, len);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000548 }
549
Bram Moolenaard2221132011-07-27 14:09:09 +0200550 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 }
552 len = 0;
553#endif
554 ch = key->key_cap;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200555 if (ch < 0xff)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {
557 /* FIXME: is this the right thing to do? */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200558 if (modifiers & MOD_MASK_CTRL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {
560 modifiers &= ~MOD_MASK_CTRL;
561
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200562 if ((ch >= 'a' && ch <= 'z') ||
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 ch == '[' ||
564 ch == ']' ||
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200565 ch == '\\')
566 ch = Ctrl_chr(ch);
567 else if (ch == '2')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 ch = NUL;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200569 else if (ch == '6')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 ch = 0x1e;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200571 else if (ch == '-')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 ch = 0x1f;
573 else
574 modifiers |= MOD_MASK_CTRL;
575 }
576
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200577 if (modifiers & MOD_MASK_ALT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200579 ch = Meta(ch);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 modifiers &= ~MOD_MASK_ALT;
581 }
582 }
583 else
584 {
Bram Moolenaard2221132011-07-27 14:09:09 +0200585 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 }
587 }
588 else
589 modifiers &= ~MOD_MASK_SHIFT;
590 }
591
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200592 ch = simplify_key(ch, &modifiers);
593 if (modifiers)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {
595 string[ len++ ] = CSI;
596 string[ len++ ] = KS_MODIFIER;
597 string[ len++ ] = modifiers;
598 }
599
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200600 if (IS_SPECIAL(ch))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {
602 string[ len++ ] = CSI;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200603 string[ len++ ] = K_SECOND(ch);
604 string[ len++ ] = K_THIRD(ch);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 }
606 else
607 {
608 string[ len++ ] = ch;
609 }
610
611 if (len == 1 && ((ch == Ctrl_C && ctrl_c_interrupts)
612 || ch == intr_char))
613 {
614 trash_input_buf();
615 got_int = TRUE;
616 }
617
618 if (len == 1 && string[0] == CSI)
619 {
620 /* Turn CSI into K_CSI. */
621 string[ len++ ] = KS_EXTRA;
622 string[ len++ ] = KE_CSI;
623 }
624
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200625 if (len > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200627 add_to_input_buf(string, len);
Bram Moolenaard2221132011-07-27 14:09:09 +0200628 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 }
630 }
631
Bram Moolenaard2221132011-07-27 14:09:09 +0200632 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633}
634
635 static int
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200636gui_ph_handle_mouse(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637{
638 PhPointerEvent_t *pointer;
639 PhRect_t *pos;
640 int button = 0, repeated_click, modifiers = 0x0;
641 short mouse_x, mouse_y;
642
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200643 pointer = PhGetData(info->event);
644 pos = PhGetRects(info->event);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200646 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647
648 /*
649 * Coordinates need to be relative to the base window,
650 * not relative to the vimTextArea widget
651 */
652 mouse_x = pos->ul.x + gui.border_width;
653 mouse_y = pos->ul.y + gui.border_width;
654
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200655 if (info->event->type == Ph_EV_PTR_MOTION_NOBUTTON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000656 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200657 gui_mouse_moved(mouse_x, mouse_y);
Bram Moolenaard2221132011-07-27 14:09:09 +0200658 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 }
660
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200661 if (pointer->key_mods & Pk_KM_Shift)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 modifiers |= MOUSE_SHIFT;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200663 if (pointer->key_mods & Pk_KM_Ctrl)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 modifiers |= MOUSE_CTRL;
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200665 if (pointer->key_mods & Pk_KM_Alt)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 modifiers |= MOUSE_ALT;
667
668 /*
669 * FIXME More than one button may be involved, but for
670 * now just deal with one
671 */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200672 if (pointer->buttons & Ph_BUTTON_SELECT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 button = MOUSE_LEFT;
674
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200675 if (pointer->buttons & Ph_BUTTON_MENU)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {
677 button = MOUSE_RIGHT;
678 /* Need the absolute coordinates for the popup menu */
679 abs_mouse.x = pointer->pos.x;
680 abs_mouse.y = pointer->pos.y;
681 }
682
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200683 if (pointer->buttons & Ph_BUTTON_ADJUST)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 button = MOUSE_MIDDLE;
685
686 /* Catch a real release (not phantom or other releases */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200687 if (info->event->type == Ph_EV_BUT_RELEASE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 button = MOUSE_RELEASE;
689
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200690 if (info->event->type & Ph_EV_PTR_MOTION_BUTTON)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 button = MOUSE_DRAG;
692
693#if 0
694 /* Vim doesn't use button repeats */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200695 if (info->event->type & Ph_EV_BUT_REPEAT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 button = MOUSE_DRAG;
697#endif
698
699 /* Don't do anything if it is one of the phantom mouse release events */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200700 if ((button != MOUSE_RELEASE) ||
701 (info->event->subtype == Ph_EV_RELEASE_REAL))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {
703 repeated_click = (pointer->click_count >= 2) ? TRUE : FALSE;
704
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200705 gui_send_mouse_event(button , mouse_x, mouse_y, repeated_click, modifiers);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 }
707
Bram Moolenaard2221132011-07-27 14:09:09 +0200708 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709}
710
711/* Handle a focus change of the PtRaw widget */
712 static int
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200713gui_ph_handle_focus(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714{
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200715 if (info->reason == Pt_CB_LOST_FOCUS)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200717 PtRemoveEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON,
718 gui_ph_handle_mouse, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200720 gui_mch_mousehide(MOUSE_SHOW);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 }
722 else
723 {
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200724 PtAddEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON,
725 gui_ph_handle_mouse, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200727 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728}
729
730 static void
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200731gui_ph_handle_raw_draw(PtWidget_t *widget, PhTile_t *damage)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732{
733 PhRect_t *r;
734 PhPoint_t offset;
735 PhPoint_t translation;
736
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200737 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 return;
739
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200740 PtSuperClassDraw(PtBasic, widget, damage);
741 PgGetTranslation(&translation);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 PgClearTranslation();
743
744#if 0
745 /*
Bram Moolenaarccc18222007-05-10 18:25:20 +0000746 * This causes some weird problems, with drawing being done from
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 * within this raw drawing function (rather than just simple clearing
748 * and text drawing done by gui_redraw)
749 *
750 * The main problem is when PhBlit is used, and the cursor appearing
751 * in places where it shouldn't
752 */
753 out_flush();
754#endif
755
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200756 PtWidgetOffset(widget, &offset);
757 PhTranslatePoint(&offset, PtWidgetPos(gui.vimTextArea, NULL));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758
759#if 1
760 /* Redraw individual damage regions */
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200761 if (damage->next != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762 damage = damage->next;
763
Bram Moolenaar15d63192011-09-14 16:05:15 +0200764 while (damage != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {
766 r = &damage->rect;
767 gui_redraw(
768 r->ul.x - offset.x, r->ul.y - offset.y,
769 r->lr.x - r->ul.x + 1,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200770 r->lr.y - r->ul.y + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771 damage = damage->next;
772 }
773#else
774 /* Redraw the rectangle that covers all the damaged regions */
775 r = &damage->rect;
776 gui_redraw(
777 r->ul.x - offset.x, r->ul.y - offset.y,
778 r->lr.x - r->ul.x + 1,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200779 r->lr.y - r->ul.y + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#endif
781
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200782 PgSetTranslation(&translation, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783}
784
785 static int
786gui_ph_handle_pulldown_menu(
787 PtWidget_t *widget,
788 void *data,
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200789 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790{
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200791 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792 {
793 vimmenu_T *menu = (vimmenu_T *) data;
794
Bram Moolenaar0d55ff12011-09-07 19:09:01 +0200795 PtPositionMenu(menu->submenu_id, NULL);
796 PtRealizeWidget(menu->submenu_id);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 }
798
Bram Moolenaard2221132011-07-27 14:09:09 +0200799 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800}
801
802/* This is used for pulldown/popup menus and also toolbar buttons */
803 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +0200804gui_ph_handle_menu(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805{
Bram Moolenaar15d63192011-09-14 16:05:15 +0200806 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {
808 vimmenu_T *menu = (vimmenu_T *) data;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200809 gui_menu_cb(menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200811 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812}
813
814/* Stop focus from disappearing into the menubar... */
815 static int
816gui_ph_handle_menu_unrealized(
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 PtGiveFocus(gui.vimTextArea, NULL);
Bram Moolenaard2221132011-07-27 14:09:09 +0200822 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823}
824
825 static int
826gui_ph_handle_window_open(
827 PtWidget_t *widget,
828 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200829 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830{
Bram Moolenaar15d63192011-09-14 16:05:15 +0200831 gui_set_shellsize(FALSE, TRUE, RESIZE_BOTH);
Bram Moolenaard2221132011-07-27 14:09:09 +0200832 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833}
834
835/****************************************************************************/
836
837#define DRAW_START gui_ph_draw_start()
838#define DRAW_END gui_ph_draw_end()
839
840/* TODO: Set a clipping rect? */
841 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200842gui_ph_draw_start(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843{
Bram Moolenaara0b19972009-07-01 14:13:18 +0000844 PhGC_t *gc;
845
846 gc = PgGetGC();
Bram Moolenaar15d63192011-09-14 16:05:15 +0200847 PgSetRegion(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)));
848 PgClearClippingsCx(gc);
849 PgClearTranslationCx(gc);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000850
Bram Moolenaar15d63192011-09-14 16:05:15 +0200851 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
852 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853
Bram Moolenaar15d63192011-09-14 16:05:15 +0200854 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000855}
856
857 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200858gui_ph_draw_end(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000859{
860 gui_ph_raw_offset.x = -gui_ph_raw_offset.x;
861 gui_ph_raw_offset.y = -gui_ph_raw_offset.y;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200862 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863}
864
865#ifdef USE_PANEL_GROUP
866 static vimmenu_T *
Bram Moolenaar15d63192011-09-14 16:05:15 +0200867gui_ph_find_buffer_item(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868{
869 vimmenu_T *top_level = root_menu;
870 vimmenu_T *items = NULL;
871
Bram Moolenaar15d63192011-09-14 16:05:15 +0200872 while (top_level != NULL &&
873 (STRCMP(top_level->dname, "Buffers") != 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000874 top_level = top_level->next;
875
Bram Moolenaar15d63192011-09-14 16:05:15 +0200876 if (top_level != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000877 {
878 items = top_level->children;
879
Bram Moolenaar15d63192011-09-14 16:05:15 +0200880 while (items != NULL &&
881 (STRCMP(items->dname, name) != 0))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 items = items->next;
883 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200884 return items;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000885}
886
887 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200888gui_ph_pg_set_buffer_num(int_u buf_num)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889{
890 int i;
891 char search[16];
892 char *mark;
893
Bram Moolenaar15d63192011-09-14 16:05:15 +0200894 if (gui.vimTextArea == NULL || buf_num == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 return;
896
897 search[0] = '(';
Bram Moolenaar15d63192011-09-14 16:05:15 +0200898 ultoa(buf_num, &search[1], 10);
899 STRCAT(search, ")");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900
Bram Moolenaar15d63192011-09-14 16:05:15 +0200901 for (i = 0; i < num_panels; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {
903 /* find the last "(" in the panel title and see if the buffer
904 * number in the title matches the one we're looking for */
Bram Moolenaar15d63192011-09-14 16:05:15 +0200905 mark = STRRCHR(panel_titles[ i ], '(');
906 if (mark != NULL && STRCMP(mark, search) == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200908 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_CURRENT_INDEX,
909 i, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 }
911 }
912}
913
914 static int
915gui_ph_handle_pg_change(
916 PtWidget_t *widget,
917 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200918 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919{
920 vimmenu_T *menu;
921 PtPanelGroupCallback_t *panel;
922
Bram Moolenaar15d63192011-09-14 16:05:15 +0200923 if (info->event != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {
925 panel = info->cbdata;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200926 if (panel->new_panel != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200928 menu = gui_ph_find_buffer_item(panel->new_panel);
929 if (menu)
930 gui_menu_cb(menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 }
932 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200933 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934}
935
936 static void
937gui_ph_get_panelgroup_margins(
938 short *top,
939 short *bottom,
940 short *left,
Bram Moolenaar15d63192011-09-14 16:05:15 +0200941 short *right)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942{
943 unsigned short abs_raw_x, abs_raw_y, abs_panel_x, abs_panel_y;
944 const unsigned short *margin_top, *margin_bottom;
945 const unsigned short *margin_left, *margin_right;
946
Bram Moolenaar15d63192011-09-14 16:05:15 +0200947 PtGetAbsPosition(gui.vimTextArea, &abs_raw_x, &abs_raw_y);
948 PtGetAbsPosition(gui.vimPanelGroup, &abs_panel_x, &abs_panel_y);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949
Bram Moolenaar15d63192011-09-14 16:05:15 +0200950 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_RIGHT, &margin_right, 0);
951 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_BOTTOM, &margin_bottom, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952
953 abs_raw_x -= abs_panel_x;
954 abs_raw_y -= abs_panel_y;
955
956 *top = abs_raw_y;
957 *bottom = *margin_bottom;
958
959 *left = abs_raw_x;
960 *right = *margin_right;
961}
962
963/* Used for the tabs for PtPanelGroup */
964 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +0200965gui_ph_is_buffer_item(vimmenu_T *menu, vimmenu_T *parent)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966{
967 char *mark;
968
Bram Moolenaar15d63192011-09-14 16:05:15 +0200969 if (STRCMP(parent->dname, "Buffers") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {
971 /* Look for '(' digits ')' */
Bram Moolenaar15d63192011-09-14 16:05:15 +0200972 mark = vim_strchr(menu->dname, '(');
973 if (mark != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974 {
975 mark++;
Bram Moolenaar15d63192011-09-14 16:05:15 +0200976 while (isdigit(*mark))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 mark++;
978
Bram Moolenaar15d63192011-09-14 16:05:15 +0200979 if (*mark == ')')
Bram Moolenaard2221132011-07-27 14:09:09 +0200980 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000981 }
982 }
Bram Moolenaard2221132011-07-27 14:09:09 +0200983 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984}
985
986 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +0200987gui_ph_pg_add_buffer(char *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988{
989 char **new_titles = NULL;
990
Bram Moolenaar15d63192011-09-14 16:05:15 +0200991 new_titles = (char **) alloc((num_panels + 1) * sizeof(char **));
992 if (new_titles != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993 {
Bram Moolenaar15d63192011-09-14 16:05:15 +0200994 if (num_panels > 0)
995 memcpy(new_titles, panel_titles, num_panels * sizeof(char **));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996
997 new_titles[ num_panels++ ] = name;
998
Bram Moolenaar15d63192011-09-14 16:05:15 +0200999 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles,
1000 num_panels);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001
Bram Moolenaar15d63192011-09-14 16:05:15 +02001002 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 panel_titles = new_titles;
1004 }
1005}
1006
1007 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +02001008gui_ph_pg_remove_buffer(char *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009{
1010 int i;
1011 char **new_titles = NULL;
1012
1013 /* If there is only 1 panel, we just use the temporary place holder */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001014 if (num_panels > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001016 new_titles = (char **) alloc((num_panels - 1) * sizeof(char **));
1017 if (new_titles != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {
1019 char **s = new_titles;
1020 /* Copy all the titles except the one we're removing */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001021 for (i = 0; i < num_panels; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001023 if (STRCMP(panel_titles[ i ], name) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024 {
1025 *s++ = panel_titles[ i ];
1026 }
1027 }
1028 num_panels--;
1029
Bram Moolenaar15d63192011-09-14 16:05:15 +02001030 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles,
1031 num_panels);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032
Bram Moolenaar15d63192011-09-14 16:05:15 +02001033 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 panel_titles = new_titles;
1035 }
1036 }
1037 else
1038 {
1039 num_panels--;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001040 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, &empty_title,
1041 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042
Bram Moolenaard23a8232018-02-10 18:45:26 +01001043 VIM_CLEAR(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 }
1045}
1046
1047/* When a buffer item is deleted from the buffer menu */
1048 static int
1049gui_ph_handle_buffer_remove(
1050 PtWidget_t *widget,
1051 void *data,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001052 PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053{
1054 vimmenu_T *menu;
1055
Bram Moolenaar15d63192011-09-14 16:05:15 +02001056 if (data != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {
1058 menu = (vimmenu_T *) data;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001059 gui_ph_pg_remove_buffer(menu->dname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 }
1061
Bram Moolenaard2221132011-07-27 14:09:09 +02001062 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063}
1064#endif
1065
1066 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001067gui_ph_pane_resize(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001069 if (PtWidgetIsRealized(widget))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {
1071 is_ignore_draw = TRUE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001072 PtStartFlux(gui.vimContainer);
1073 PtContainerHold(gui.vimContainer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 }
1075
Bram Moolenaard2221132011-07-27 14:09:09 +02001076 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077}
1078
1079/****************************************************************************/
1080
1081#ifdef FEAT_MBYTE
1082 void
Bram Moolenaar15d63192011-09-14 16:05:15 +02001083gui_ph_encoding_changed(int new_encoding)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084{
1085 /* Default encoding is latin1 */
1086 char *charset = "latin1";
1087 int i;
1088
1089 struct {
1090 int encoding;
1091 char *name;
1092 } charsets[] = {
1093 { DBCS_JPN, "SHIFT_JIS" },
1094 { DBCS_KOR, "csEUCKR" },
1095 { DBCS_CHT, "big5" },
1096 { DBCS_CHS, "gb" }
1097 };
1098
Bram Moolenaar15d63192011-09-14 16:05:15 +02001099 for (i = 0; i < ARRAY_LENGTH(charsets); i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001101 if (new_encoding == charsets[ i ].encoding)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 charset = charsets[ i ].name;
1103 }
1104
Bram Moolenaar15d63192011-09-14 16:05:15 +02001105 charset_translate = PxTranslateSet(charset_translate, charset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106}
1107#endif
1108
1109/****************************************************************************/
1110/****************************************************************************/
1111
1112 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001113gui_mch_prepare(int *argc, char **argv)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001115 PtInit(NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116}
1117
1118 int
1119gui_mch_init(void)
1120{
1121 PtArg_t args[10];
1122 int flags = 0, n = 0;
1123
Bram Moolenaarccc18222007-05-10 18:25:20 +00001124 PhDim_t window_size = {100, 100}; /* Arbitrary values */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 PhPoint_t pos = {0, 0};
1126
Bram Moolenaar15d63192011-09-14 16:05:15 +02001127 gui.event_buffer = (PhEvent_t *) alloc(EVENT_BUFFER_SIZE);
1128 if (gui.event_buffer == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001129 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130
1131 /* Get a translation so we can convert from ISO Latin-1 to UTF */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001132 charset_translate = PxTranslateSet(NULL, "latin1");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133
1134 /* The +2 is for the 1 pixel dark line on each side */
1135 gui.border_offset = gui.border_width = GUI_PH_MARGIN + 2;
1136
1137 /* Handle close events ourselves */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001138 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE);
1139 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
1140 Ph_WM_CLOSE | Ph_WM_RESIZE | Ph_WM_FOCUS);
1141 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0);
1142 gui.vimWindow = PtCreateWidget(PtWindow, NULL, n, args);
1143 if (gui.vimWindow == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001144 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145
Bram Moolenaar15d63192011-09-14 16:05:15 +02001146 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW, gui_ph_handle_window_cb, NULL);
1147 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW_OPENING,
1148 gui_ph_handle_window_open, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149
1150 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001151 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_ALL, Pt_IS_ANCHORED);
1152 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0);
1153 PtSetArg(&args[ n++ ], Pt_ARG_POS, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154
1155#ifdef USE_PANEL_GROUP
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001156 /* Put in a temporary place holder title */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001157 PtSetArg(&args[ n++ ], Pt_ARG_PG_PANEL_TITLES, &empty_title, 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158
Bram Moolenaar15d63192011-09-14 16:05:15 +02001159 gui.vimPanelGroup = PtCreateWidget(PtPanelGroup, gui.vimWindow, n, args);
1160 if (gui.vimPanelGroup == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001161 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162
Bram Moolenaar15d63192011-09-14 16:05:15 +02001163 PtAddCallback(gui.vimPanelGroup, Pt_CB_PG_PANEL_SWITCHING,
1164 gui_ph_handle_pg_change, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165#else
1166 /* Turn off all edge decorations */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001167 PtSetArg(&args[ n++ ], Pt_ARG_BASIC_FLAGS, Pt_FALSE, Pt_ALL);
1168 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, 0, 0);
1169 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 0, 0);
1170 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 0, 0);
1171 PtSetArg(&args[ n++ ], Pt_ARG_CONTAINER_FLAGS, Pt_TRUE, Pt_AUTO_EXTENT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172
Bram Moolenaar15d63192011-09-14 16:05:15 +02001173 gui.vimContainer = PtCreateWidget(PtPane, gui.vimWindow, n, args);
1174 if (gui.vimContainer == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001175 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176
Bram Moolenaar15d63192011-09-14 16:05:15 +02001177 PtAddCallback(gui.vimContainer, Pt_CB_RESIZE, gui_ph_pane_resize, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178#endif
1179
1180 /* Size for the text area is set in gui_mch_set_text_area_pos */
1181 n = 0;
1182
Bram Moolenaar15d63192011-09-14 16:05:15 +02001183 PtSetArg(&args[ n++ ], Pt_ARG_RAW_DRAW_F, gui_ph_handle_raw_draw, 1);
1184 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, GUI_PH_MARGIN, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185 /*
1186 * Using focus render also causes the whole widget to be redrawn
1187 * whenever it changes focus, which is very annoying :p
1188 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001189 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE,
1190 Pt_GETS_FOCUS | Pt_HIGHLIGHTED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191#ifndef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001192 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_TYPE, GUI_PH_MOUSE_TYPE, 0);
1193 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_COLOR, gui_ph_mouse_color, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194#endif
1195
Bram Moolenaar15d63192011-09-14 16:05:15 +02001196 gui.vimTextArea = PtCreateWidget(PtRaw, Pt_DFLT_PARENT, n, args);
1197 if (gui.vimTextArea == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001198 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199
1200 /* TODO: use PtAddEventHandlers instead? */
1201 /* Not using Ph_EV_BUT_REPEAT because vim wouldn't use it anyway */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001202 PtAddEventHandler(gui.vimTextArea,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE | Ph_EV_PTR_MOTION_BUTTON,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001204 gui_ph_handle_mouse, NULL);
1205 PtAddEventHandler(gui.vimTextArea, Ph_EV_KEY,
1206 gui_ph_handle_keyboard, NULL);
1207 PtAddCallback(gui.vimTextArea, Pt_CB_GOT_FOCUS,
1208 gui_ph_handle_focus, NULL);
1209 PtAddCallback(gui.vimTextArea, Pt_CB_LOST_FOCUS,
1210 gui_ph_handle_focus, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211
1212 /*
1213 * Now that the text area widget has been created, set up the colours,
1214 * which wil call PtSetResource from gui_mch_new_colors
1215 */
1216
1217 /*
1218 * Create the two timers, not as accurate as using the kernel timer
1219 * functions, but good enough
1220 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001221 gui_ph_timer_cursor = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL);
1222 if (gui_ph_timer_cursor == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001223 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224
Bram Moolenaar15d63192011-09-14 16:05:15 +02001225 gui_ph_timer_timeout = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL);
1226 if (gui_ph_timer_timeout == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001227 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228
Bram Moolenaar15d63192011-09-14 16:05:15 +02001229 PtAddCallback(gui_ph_timer_cursor, Pt_CB_TIMER_ACTIVATE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 gui_ph_handle_timer_cursor, NULL);
Bram Moolenaar15d63192011-09-14 16:05:15 +02001231 PtAddCallback(gui_ph_timer_timeout, Pt_CB_TIMER_ACTIVATE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 gui_ph_handle_timer_timeout, NULL);
1233
1234#ifdef FEAT_MENU
1235 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001236 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
1237 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_LEFT_RIGHT,
1238 Pt_IS_ANCHORED);
1239 gui.vimToolBarGroup = PtCreateWidget(PtToolbarGroup, gui.vimWindow,
1240 n, args);
1241 if (gui.vimToolBarGroup == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001242 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243
Bram Moolenaar15d63192011-09-14 16:05:15 +02001244 PtAddCallback(gui.vimToolBarGroup, Pt_CB_RESIZE,
1245 gui_ph_handle_menu_resize, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246
1247 n = 0;
1248 flags = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001249 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
1250 if (! vim_strchr(p_go, GO_MENUS))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 {
1252 flags |= Pt_DELAY_REALIZE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001253 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE, flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001255 gui.vimMenuBar = PtCreateWidget(PtMenuBar, gui.vimToolBarGroup, n, args);
1256 if (gui.vimMenuBar == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001257 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258
1259# ifdef FEAT_TOOLBAR
1260 n = 0;
1261
Bram Moolenaar15d63192011-09-14 16:05:15 +02001262 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS,
1263 Pt_ANCHOR_LEFT_RIGHT |Pt_TOP_ANCHORED_TOP, Pt_IS_ANCHORED);
1264 PtSetArg(&args[ n++ ], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
1265 Pt_RESIZE_Y_AS_REQUIRED);
1266 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267
1268 flags = Pt_GETS_FOCUS;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001269 if (! vim_strchr(p_go, GO_TOOLBAR))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 flags |= Pt_DELAY_REALIZE;
1271
Bram Moolenaar15d63192011-09-14 16:05:15 +02001272 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE, flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273
Bram Moolenaar15d63192011-09-14 16:05:15 +02001274 gui.vimToolBar = PtCreateWidget(PtToolbar, gui.vimToolBarGroup, n, args);
1275 if (gui.vimToolBar == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001276 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277
1278 /*
1279 * Size for the toolbar is fetched in gui_mch_show_toolbar, after
1280 * the buttons have been added and the toolbar has resized it's height
1281 * for the buttons to fit
1282 */
1283# endif
1284
1285#endif
1286
Bram Moolenaard2221132011-07-27 14:09:09 +02001287 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288}
1289
1290 int
1291gui_mch_init_check(void)
1292{
Bram Moolenaard2221132011-07-27 14:09:09 +02001293 return (is_photon_available == TRUE) ? OK : FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294}
1295
1296 int
1297gui_mch_open(void)
1298{
1299 gui.norm_pixel = Pg_BLACK;
1300 gui.back_pixel = Pg_WHITE;
1301
1302 set_normal_colors();
1303
1304 gui_check_colors();
1305 gui.def_norm_pixel = gui.norm_pixel;
1306 gui.def_back_pixel = gui.back_pixel;
1307
1308 highlight_gui_started();
1309
1310 if (gui_win_x != -1 && gui_win_y != -1)
1311 gui_mch_set_winpos(gui_win_x, gui_win_y);
1312
Bram Moolenaar15d63192011-09-14 16:05:15 +02001313 return (PtRealizeWidget(gui.vimWindow) == 0) ? OK : FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314}
1315
1316 void
1317gui_mch_exit(int rc)
1318{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001319 PtDestroyWidget(gui.vimWindow);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320
Bram Moolenaar15d63192011-09-14 16:05:15 +02001321 PxTranslateSet(charset_translate, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322
Bram Moolenaar15d63192011-09-14 16:05:15 +02001323 vim_free(gui.event_buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324
1325#ifdef USE_PANEL_GROUPS
Bram Moolenaar15d63192011-09-14 16:05:15 +02001326 vim_free(panel_titles);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327#endif
1328}
1329
1330/****************************************************************************/
1331/* events */
1332
1333/* When no events are available, photon will call this function, working is
1334 * set to FALSE, and the gui_mch_update loop will exit. */
1335 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001336exit_gui_mch_update(void *data)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337{
1338 *(int *)data = FALSE;
Bram Moolenaard2221132011-07-27 14:09:09 +02001339 return Pt_END;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340}
1341
1342 void
1343gui_mch_update(void)
1344{
1345 int working = TRUE;
1346
Bram Moolenaar15d63192011-09-14 16:05:15 +02001347 PtAppAddWorkProc(NULL, exit_gui_mch_update, &working);
1348 while ((working == TRUE) && !vim_is_input_buf_full())
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 {
1350 PtProcessEvent();
1351 }
1352}
1353
1354 int
1355gui_mch_wait_for_chars(int wtime)
1356{
1357 is_timeout = FALSE;
1358
Bram Moolenaar15d63192011-09-14 16:05:15 +02001359 if (wtime > 0)
1360 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, wtime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361
Bram Moolenaar15d63192011-09-14 16:05:15 +02001362 while (1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {
1364 PtProcessEvent();
Bram Moolenaar15d63192011-09-14 16:05:15 +02001365 if (input_available())
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001367 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, 0, 0);
Bram Moolenaard2221132011-07-27 14:09:09 +02001368 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001370 else if (is_timeout == TRUE)
Bram Moolenaard2221132011-07-27 14:09:09 +02001371 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 }
1373}
1374
Bram Moolenaar15d63192011-09-14 16:05:15 +02001375#if defined(FEAT_BROWSE) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376/*
1377 * Put up a file requester.
1378 * Returns the selected name in allocated memory, or NULL for Cancel.
1379 * saving, select file to write
1380 * title title for the window
1381 * default_name default name (well duh!)
1382 * ext not used (extension added)
1383 * initdir initial directory, NULL for current dir
1384 * filter not used (file name filter)
1385 */
1386 char_u *
1387gui_mch_browse(
1388 int saving,
1389 char_u *title,
1390 char_u *default_name,
1391 char_u *ext,
1392 char_u *initdir,
1393 char_u *filter)
1394{
1395 PtFileSelectionInfo_t file;
1396 int flags;
1397 char_u *default_path;
1398 char_u *open_text = NULL;
1399
1400 flags = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001401 memset(&file, 0, sizeof(file));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402
Bram Moolenaar15d63192011-09-14 16:05:15 +02001403 default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1);
1404 if (default_path != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001406 if (saving == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {
1408 /* Don't need Pt_FSR_CONFIRM_EXISTING, vim will ask anyway */
1409 flags |= Pt_FSR_NO_FCHECK;
1410 open_text = "&Save";
1411 }
1412
1413 /* combine the directory and filename into a single path */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001414 if (initdir == NULL || *initdir == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001416 mch_dirname(default_path, MAXPATHL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 initdir = default_path;
1418 }
1419 else
1420 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001421 STRCPY(default_path, initdir);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 initdir = default_path;
1423 }
1424
Bram Moolenaar15d63192011-09-14 16:05:15 +02001425 if (default_name != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001427 if (default_path[ STRLEN(default_path) - 1 ] != '/')
1428 STRCAT(default_path, "/");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429
Bram Moolenaar15d63192011-09-14 16:05:15 +02001430 STRCAT(default_path, default_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 }
1432
1433 /* TODO: add a filter? */
1434 PtFileSelection(
1435 gui.vimWindow,
1436 NULL,
1437 title,
1438 default_path,
1439 NULL,
1440 open_text,
1441 NULL,
1442 NULL,
1443 &file,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001444 flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445
Bram Moolenaar15d63192011-09-14 16:05:15 +02001446 vim_free(default_path);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447
Bram Moolenaar15d63192011-09-14 16:05:15 +02001448 if (file.ret == Pt_FSDIALOG_BTN1)
Bram Moolenaard2221132011-07-27 14:09:09 +02001449 return vim_strsave(file.path);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 }
Bram Moolenaard2221132011-07-27 14:09:09 +02001451 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452}
1453#endif
1454
Bram Moolenaar15d63192011-09-14 16:05:15 +02001455#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456static PtWidget_t *gui_ph_dialog_text = NULL;
1457
1458 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001459gui_ph_dialog_close(int button, void *data)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460{
1461 PtModalCtrl_t *modal_ctrl = data;
1462 char_u *dialog_text, *vim_text;
1463
Bram Moolenaar15d63192011-09-14 16:05:15 +02001464 if (gui_ph_dialog_text != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001466 PtGetResource(gui_ph_dialog_text, Pt_ARG_TEXT_STRING, &dialog_text, 0);
1467 PtGetResource(gui_ph_dialog_text, Pt_ARG_POINTER, &vim_text, 0);
1468 STRNCPY(vim_text, dialog_text, IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 }
1470
Bram Moolenaar15d63192011-09-14 16:05:15 +02001471 PtModalUnblock(modal_ctrl, (void *) button);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472
Bram Moolenaard2221132011-07-27 14:09:09 +02001473 return Pt_TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474}
1475
1476 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001477gui_ph_dialog_text_enter(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001479 if (info->reason_subtype == Pt_EDIT_ACTIVATE)
1480 gui_ph_dialog_close(1, data);
Bram Moolenaard2221132011-07-27 14:09:09 +02001481 return Pt_CONTINUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482}
1483
1484 static int
Bram Moolenaar15d63192011-09-14 16:05:15 +02001485gui_ph_dialog_esc(PtWidget_t *widget, void *data, PtCallbackInfo_t *info)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486{
1487 PhKeyEvent_t *key;
1488
Bram Moolenaar15d63192011-09-14 16:05:15 +02001489 key = PhGetData(info->event);
1490 if ((key->key_flags & Pk_KF_Cap_Valid) && (key->key_cap == Pk_Escape))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001492 gui_ph_dialog_close(0, data);
Bram Moolenaard2221132011-07-27 14:09:09 +02001493 return Pt_CONSUME;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001494 }
Bram Moolenaard2221132011-07-27 14:09:09 +02001495 return Pt_PROCESS;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496}
1497
1498 int
1499gui_mch_dialog(
1500 int type,
1501 char_u *title,
1502 char_u *message,
1503 char_u *buttons,
1504 int default_button,
Bram Moolenaard2c340a2011-01-17 20:08:11 +01001505 char_u *textfield,
1506 int ex_cmd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507{
1508 char_u *str;
1509 char_u **button_array;
1510 char_u *buttons_copy;
1511
1512 int button_count;
1513 int i, len;
1514 int dialog_result = -1;
1515
1516 /* FIXME: the vertical option in guioptions is blatantly ignored */
1517 /* FIXME: so is the type */
1518
1519 button_count = len = i = 0;
1520
Bram Moolenaar15d63192011-09-14 16:05:15 +02001521 if (buttons == NULL || *buttons == NUL)
Bram Moolenaard2221132011-07-27 14:09:09 +02001522 return -1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523
1524 /* There is one less separator than buttons, so bump up the button count */
1525 button_count = 1;
1526
Bram Moolenaar84a05ac2013-05-06 04:24:17 +02001527 /* Count string length and number of separators */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001528 for (str = buttons; *str; str++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {
1530 len++;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001531 if (*str == DLG_BUTTON_SEP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 button_count++;
1533 }
1534
Bram Moolenaar15d63192011-09-14 16:05:15 +02001535 if (title == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 title = "Vim";
1537
Bram Moolenaar15d63192011-09-14 16:05:15 +02001538 buttons_copy = alloc(len + 1);
1539 button_array = (char_u **) alloc(button_count * sizeof(char_u *));
1540 if (buttons_copy != NULL && button_array != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001542 STRCPY(buttons_copy, buttons);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543
1544 /*
1545 * Convert DLG_BUTTON_SEP into NUL's and fill in
1546 * button_array with the pointer to each NUL terminated string
1547 */
1548 str = buttons_copy;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001549 for (i = 0; i < button_count; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {
1551 button_array[ i ] = str;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001552 for (; *str; str++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001554 if (*str == DLG_BUTTON_SEP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {
1556 *str++ = NUL;
1557 break;
1558 }
1559 }
1560 }
1561#ifndef FEAT_GUI_TEXTDIALOG
1562 dialog_result = PtAlert(
1563 gui.vimWindow, NULL,
1564 title,
1565 NULL,
1566 message, NULL,
1567 button_count, (const char **) button_array, NULL,
Bram Moolenaar15d63192011-09-14 16:05:15 +02001568 default_button, 0, Pt_MODAL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569#else
1570 /* Writing the dialog ourselves lets us add extra features, like
1571 * trapping the escape key and returning 0 to vim */
1572 {
1573 int n;
1574 PtArg_t args[5];
1575 PtWidget_t *dialog, *pane;
1576 PtModalCtrl_t modal_ctrl;
1577 PtDialogInfo_t di;
1578
Bram Moolenaar15d63192011-09-14 16:05:15 +02001579 memset(&di, 0, sizeof(di));
1580 memset(&modal_ctrl, 0, sizeof(modal_ctrl));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581
1582 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001583 PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0);
1584 PtSetArg(&args[n++], Pt_ARG_WIDTH, 350, 0);
1585 PtSetArg(&args[n++], Pt_ARG_GROUP_ORIENTATION,
1586 Pt_GROUP_VERTICAL, 0);
1587 PtSetArg(&args[n++], Pt_ARG_GROUP_FLAGS,
1588 Pt_TRUE, Pt_GROUP_NO_KEYS | Pt_GROUP_STRETCH_HORIZONTAL);
1589 PtSetArg(&args[n++], Pt_ARG_CONTAINER_FLAGS, Pt_FALSE, Pt_TRUE);
1590 pane = PtCreateWidget(PtGroup, NULL, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591
1592 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001593 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, message, 0);
1594 PtCreateWidget(PtLabel, pane, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595
Bram Moolenaar15d63192011-09-14 16:05:15 +02001596 if (textfield != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {
1598 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001599 PtSetArg(&args[n++], Pt_ARG_MAX_LENGTH, IOSIZE - 1, 0);
1600 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, textfield, 0);
1601 PtSetArg(&args[n++], Pt_ARG_POINTER, textfield, 0);
1602 gui_ph_dialog_text = PtCreateWidget(PtText, pane, n, args);
1603 PtAddCallback(gui_ph_dialog_text, Pt_CB_ACTIVATE,
1604 gui_ph_dialog_text_enter, &modal_ctrl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 }
1606
1607 di.parent = gui.vimWindow;
1608 di.pane = pane;
1609 di.title = title;
1610 di.buttons = (const char **) button_array;
1611 di.nbtns = button_count;
1612 di.def_btn = default_button;
1613 /* This is just to give the dialog the close button.
1614 * We check for the Escape key ourselves and return 0 */
1615 di.esc_btn = button_count;
1616 di.callback = gui_ph_dialog_close;
1617 di.data = &modal_ctrl;
1618
Bram Moolenaar15d63192011-09-14 16:05:15 +02001619 dialog = PtCreateDialog(&di);
1620 PtAddFilterCallback(dialog, Ph_EV_KEY,
1621 gui_ph_dialog_esc, &modal_ctrl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622
Bram Moolenaar15d63192011-09-14 16:05:15 +02001623 if (gui_ph_dialog_text != NULL)
1624 PtGiveFocus(gui_ph_dialog_text, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625
1626 /* Open dialog, block the vim window and wait for the dialog to close */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001627 PtRealizeWidget(dialog);
1628 PtMakeModal(dialog, Ph_CURSOR_NOINPUT, Ph_CURSOR_DEFAULT_COLOR);
1629 dialog_result = (int) PtModalBlock(&modal_ctrl, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630
Bram Moolenaar15d63192011-09-14 16:05:15 +02001631 PtDestroyWidget(dialog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 gui_ph_dialog_text = NULL;
1633 }
1634#endif
1635 }
1636
Bram Moolenaar15d63192011-09-14 16:05:15 +02001637 vim_free(button_array);
1638 vim_free(buttons_copy);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639
Bram Moolenaard2221132011-07-27 14:09:09 +02001640 return dialog_result;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641}
1642#endif
1643/****************************************************************************/
1644/* window size/position/state */
1645
1646 int
1647gui_mch_get_winpos(int *x, int *y)
1648{
1649 PhPoint_t *pos;
1650
Bram Moolenaar15d63192011-09-14 16:05:15 +02001651 pos = PtWidgetPos(gui.vimWindow, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652
1653 *x = pos->x;
1654 *y = pos->y;
1655
Bram Moolenaard2221132011-07-27 14:09:09 +02001656 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657}
1658
1659 void
1660gui_mch_set_winpos(int x, int y)
1661{
1662 PhPoint_t pos = { x, y };
1663
Bram Moolenaar15d63192011-09-14 16:05:15 +02001664 PtSetResource(gui.vimWindow, Pt_ARG_POS, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665}
1666
1667 void
1668gui_mch_set_shellsize(int width, int height,
Bram Moolenaarafa24992006-03-27 20:58:26 +00001669 int min_width, int min_height, int base_width, int base_height,
1670 int direction)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671{
1672 PhDim_t window_size = { width, height };
1673 PhDim_t min_size = { min_width, min_height };
1674
1675#ifdef USE_PANEL_GROUP
1676 window_size.w += pg_margin_left + pg_margin_right;
1677 window_size.h += pg_margin_top + pg_margin_bottom;
1678#endif
1679
Bram Moolenaar15d63192011-09-14 16:05:15 +02001680 PtSetResource(gui.vimWindow, Pt_ARG_MINIMUM_DIM, &min_size, 0);
1681 PtSetResource(gui.vimWindow, Pt_ARG_DIM, &window_size, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682
Bram Moolenaar15d63192011-09-14 16:05:15 +02001683 if (! PtWidgetIsRealized(gui.vimWindow))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 gui_ph_resize_container();
1685}
1686
1687/*
1688 * Return the amount of screen space that hasn't been allocated (such as
1689 * by the shelf).
1690 */
1691 void
1692gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
1693{
1694 PhRect_t console;
1695
Bram Moolenaar15d63192011-09-14 16:05:15 +02001696 PhWindowQueryVisible(Ph_QUERY_WORKSPACE, 0,
1697 PhInputGroup(NULL), &console);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698
1699 *screen_w = console.lr.x - console.ul.x + 1;
1700 *screen_h = console.lr.y - console.ul.y + 1;
1701}
1702
1703 void
1704gui_mch_iconify(void)
1705{
1706 PhWindowEvent_t event;
1707
Bram Moolenaar15d63192011-09-14 16:05:15 +02001708 memset(&event, 0, sizeof (event));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 event.event_f = Ph_WM_HIDE;
1710 event.event_state = Ph_WM_EVSTATE_HIDE;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001711 event.rid = PtWidgetRid(gui.vimWindow);
1712 PtForwardWindowEvent(&event);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713}
1714
1715#if defined(FEAT_EVAL) || defined(PROTO)
1716/*
1717 * Bring the Vim window to the foreground.
1718 */
1719 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001720gui_mch_set_foreground(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721{
1722 PhWindowEvent_t event;
1723
Bram Moolenaar15d63192011-09-14 16:05:15 +02001724 memset(&event, 0, sizeof (event));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 event.event_f = Ph_WM_TOFRONT;
1726 event.event_state = Ph_WM_EVSTATE_FFRONT;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001727 event.rid = PtWidgetRid(gui.vimWindow);
1728 PtForwardWindowEvent(&event);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729}
1730#endif
1731
1732 void
1733gui_mch_settitle(char_u *title, char_u *icon)
1734{
1735#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02001736 gui_ph_pg_set_buffer_num(curwin->w_buffer->b_fnum);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02001738 PtSetResource(gui.vimWindow, Pt_ARG_WINDOW_TITLE, title, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 /* Not sure what to do with the icon text, set balloon text somehow? */
1740}
1741
1742/****************************************************************************/
1743/* Scrollbar */
1744
1745 void
1746gui_mch_set_scrollbar_thumb(scrollbar_T *sb, int val, int size, int max)
1747{
1748 int n = 0;
1749 PtArg_t args[3];
1750
Bram Moolenaar15d63192011-09-14 16:05:15 +02001751 PtSetArg(&args[ n++ ], Pt_ARG_MAXIMUM, max, 0);
1752 PtSetArg(&args[ n++ ], Pt_ARG_SLIDER_SIZE, size, 0);
1753 PtSetArg(&args[ n++ ], Pt_ARG_GAUGE_VALUE, val, 0);
1754 PtSetResources(sb->id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755}
1756
1757 void
1758gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
1759{
1760 PhArea_t area = {{ x, y }, { w, h }};
1761
Bram Moolenaar15d63192011-09-14 16:05:15 +02001762 PtSetResource(sb->id, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763}
1764
1765 void
1766gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
1767{
1768 int n = 0;
1769/* int anchor_flags = 0;*/
1770 PtArg_t args[4];
1771
1772 /*
1773 * Stop the scrollbar from being realized when the parent
1774 * is realized, so it can be explicitly realized by vim.
1775 *
1776 * Also, don't let the scrollbar get focus
1777 */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001778 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE,
1779 Pt_DELAY_REALIZE | Pt_GETS_FOCUS);
1780 PtSetArg(&args[ n++ ], Pt_ARG_SCROLLBAR_FLAGS, Pt_SCROLLBAR_SHOW_ARROWS, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781#if 0
1782 /* Don't need this anchoring for the scrollbars */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001783 if (orient == SBAR_HORIZ)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {
1785 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM |
1786 Pt_LEFT_ANCHORED_LEFT | Pt_RIGHT_ANCHORED_RIGHT;
1787 }
1788 else
1789 {
1790 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM | Pt_TOP_ANCHORED_TOP;
Bram Moolenaar15d63192011-09-14 16:05:15 +02001791 if (sb->wp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02001793 if (sb == &sb->wp->w_scrollbars[ SBAR_LEFT ])
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 anchor_flags |= Pt_LEFT_ANCHORED_LEFT;
1795 else
1796 anchor_flags |= Pt_RIGHT_ANCHORED_RIGHT;
1797 }
1798 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02001799 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, anchor_flags, Pt_IS_ANCHORED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02001801 PtSetArg(&args[ n++ ], Pt_ARG_ORIENTATION,
1802 (orient == SBAR_HORIZ) ? Pt_HORIZONTAL : Pt_VERTICAL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02001804 sb->id = PtCreateWidget(PtScrollbar, gui.vimPanelGroup, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001806 sb->id = PtCreateWidget(PtScrollbar, gui.vimContainer, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807#endif
1808
Bram Moolenaar15d63192011-09-14 16:05:15 +02001809 PtAddCallback(sb->id, Pt_CB_SCROLLBAR_MOVE, gui_ph_handle_scrollbar, sb);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810}
1811
1812 void
1813gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
1814{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001815 if (flag != 0)
1816 PtRealizeWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001818 PtUnrealizeWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819}
1820
1821 void
1822gui_mch_destroy_scrollbar(scrollbar_T *sb)
1823{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001824 PtDestroyWidget(sb->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 sb->id = NULL;
1826}
1827
1828/****************************************************************************/
1829/* Mouse functions */
1830
1831#if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1832/* The last set mouse pointer shape is remembered, to be used when it goes
1833 * from hidden to not hidden. */
1834static int last_shape = 0;
1835
1836/* Table for shape IDs. Keep in sync with the mshape_names[] table in
1837 * misc2.c! */
1838static int mshape_ids[] =
1839{
1840 Ph_CURSOR_POINTER, /* arrow */
1841 Ph_CURSOR_NONE, /* blank */
1842 Ph_CURSOR_INSERT, /* beam */
1843 Ph_CURSOR_DRAG_VERTICAL, /* updown */
1844 Ph_CURSOR_DRAG_VERTICAL, /* udsizing */
1845 Ph_CURSOR_DRAG_HORIZONTAL, /* leftright */
1846 Ph_CURSOR_DRAG_HORIZONTAL, /* lrsizing */
1847 Ph_CURSOR_WAIT, /* busy */
1848 Ph_CURSOR_DONT, /* no */
1849 Ph_CURSOR_CROSSHAIR, /* crosshair */
1850 Ph_CURSOR_FINGER, /* hand1 */
1851 Ph_CURSOR_FINGER, /* hand2 */
1852 Ph_CURSOR_FINGER, /* pencil */
1853 Ph_CURSOR_QUESTION_POINT, /* question */
1854 Ph_CURSOR_POINTER, /* right-arrow */
1855 Ph_CURSOR_POINTER, /* up-arrow */
1856 Ph_CURSOR_POINTER /* last one */
1857};
1858
1859 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01001860mch_set_mouse_shape(int shape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861{
1862 int id;
1863
1864 if (!gui.in_use)
1865 return;
1866
1867 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
Bram Moolenaar15d63192011-09-14 16:05:15 +02001868 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE,
1869 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 else
1871 {
1872 if (shape >= MSHAPE_NUMBERED)
1873 id = Ph_CURSOR_POINTER;
1874 else
1875 id = mshape_ids[shape];
1876
Bram Moolenaar15d63192011-09-14 16:05:15 +02001877 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, id, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 }
1879 if (shape != MSHAPE_HIDE)
1880 last_shape = shape;
1881}
1882#endif
1883
1884 void
1885gui_mch_mousehide(int hide)
1886{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001887 if (gui.pointer_hidden != hide)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {
1889 gui.pointer_hidden = hide;
1890#ifdef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001891 if (hide)
1892 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE,
1893 Ph_CURSOR_NONE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001895 mch_set_mouse_shape(last_shape);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02001897 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE,
1898 (hide == MOUSE_SHOW) ? GUI_PH_MOUSE_TYPE : Ph_CURSOR_NONE,
1899 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900#endif
1901 }
1902}
1903
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00001904 void
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001905gui_mch_getmouse(int *x, int *y)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906{
1907 PhCursorInfo_t info;
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001908 short ix, iy;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909
1910 /* FIXME: does this return the correct position,
1911 * with respect to the border? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001912 PhQueryCursor(PhInputGroup(NULL), &info);
1913 PtGetAbsPosition(gui.vimTextArea , &ix, &iy);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001915 *x = info.pos.x - ix;
1916 *y = info.pos.y - iy;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917}
1918
1919 void
1920gui_mch_setmouse(int x, int y)
1921{
1922 short abs_x, abs_y;
1923
Bram Moolenaar15d63192011-09-14 16:05:15 +02001924 PtGetAbsPosition(gui.vimTextArea, &abs_x, &abs_y);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 /* Add the border offset? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001926 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + x, abs_y + y);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927}
1928
1929/****************************************************************************/
1930/* Colours */
1931
1932/*
1933 * Return the RGB value of a pixel as a long.
1934 */
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02001935 guicolor_T
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936gui_mch_get_rgb(guicolor_T pixel)
1937{
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +02001938 return (guicolor_T)(PgRGB(PgRedValue(pixel),
1939 PgGreenValue(pixel), PgBlueValue(pixel)));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940}
1941
1942 void
1943gui_mch_new_colors(void)
1944{
1945#if 0 /* Don't bother changing the cursor colour */
1946 short color_diff;
1947
1948 /*
1949 * If there isn't enough difference between the background colour and
1950 * the mouse pointer colour then change the mouse pointer colour
1951 */
1952 color_diff = gui_get_lightness(gui_ph_mouse_color)
1953 - gui_get_lightness(gui.back_pixel);
1954
Bram Moolenaar15d63192011-09-14 16:05:15 +02001955 if (abs(color_diff) < 64)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {
1957 short r, g, b;
1958 /* not a great algorithm... */
Bram Moolenaar15d63192011-09-14 16:05:15 +02001959 r = PgRedValue(gui_ph_mouse_color) ^ 255;
1960 g = PgGreenValue(gui_ph_mouse_color) ^ 255;
1961 b = PgBlueValue(gui_ph_mouse_color) ^ 255;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962
1963#ifndef FEAT_MOUSESHAPE
Bram Moolenaar15d63192011-09-14 16:05:15 +02001964 gui_ph_mouse_color = PgRGB(r, g, b);
1965 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_COLOR,
1966 gui_ph_mouse_color, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967#endif
1968 }
1969#endif
1970
Bram Moolenaar15d63192011-09-14 16:05:15 +02001971 PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972}
1973
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974/*
Bram Moolenaarccc18222007-05-10 18:25:20 +00001975 * This should be split out into a separate file,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 * every port does basically the same thing.
1977 *
1978 * This is the gui_w32.c version (i think..)
1979 * Return INVALCOLOR when failed.
1980 */
1981
1982 guicolor_T
1983gui_mch_get_color(char_u *name)
1984{
Bram Moolenaarab302212016-04-26 20:59:29 +02001985 return gui_get_color_cmn(name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986}
1987
Bram Moolenaar26af85d2017-07-23 16:45:10 +02001988 guicolor_T
1989gui_mch_get_rgb_color(int r, int g, int b)
1990{
1991 return gui_get_rgb_color_cmn(r, g, b);
1992}
1993
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 void
1995gui_mch_set_fg_color(guicolor_T color)
1996{
Bram Moolenaar15d63192011-09-14 16:05:15 +02001997 PgSetTextColor(color);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998}
1999
2000 void
2001gui_mch_set_bg_color(guicolor_T color)
2002{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002003 PgSetFillColor(color);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004}
2005
2006 void
Bram Moolenaare2cc9702005-03-15 22:43:58 +00002007gui_mch_set_sp_color(guicolor_T color)
2008{
2009}
2010
2011 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012gui_mch_invert_rectangle(int row, int col, int nr, int nc)
2013{
2014 PhRect_t rect;
2015
Bram Moolenaar15d63192011-09-14 16:05:15 +02002016 rect.ul.x = FILL_X(col);
2017 rect.ul.y = FILL_Y(row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018
2019 /* FIXME: This has an off by one pixel problem */
2020 rect.lr.x = rect.ul.x + nc * gui.char_width;
2021 rect.lr.y = rect.ul.y + nr * gui.char_height;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002022 if (nc > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 rect.lr.x -= 1;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002024 if (nr > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 rect.lr.y -= 1;
2026
2027 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002028 PgSetDrawMode(Pg_DrawModeDSTINVERT);
2029 PgDrawRect(&rect, Pg_DRAW_FILL);
2030 PgSetDrawMode(Pg_DrawModeSRCCOPY);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 DRAW_END;
2032}
2033
2034 void
2035gui_mch_clear_block(int row1, int col1, int row2, int col2)
2036{
2037 PhRect_t block = {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002038 { FILL_X(col1), FILL_Y(row1) },
2039 { FILL_X(col2 + 1) - 1, FILL_Y(row2 + 1) - 1}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 };
2041
2042 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002043 gui_mch_set_bg_color(gui.back_pixel);
2044 PgDrawRect(&block, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 DRAW_END;
2046}
2047
2048 void
Bram Moolenaar68c2f632016-01-30 17:24:07 +01002049gui_mch_clear_all(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050{
2051 PhRect_t text_rect = {
2052 { gui.border_width, gui.border_width },
2053 { Columns * gui.char_width + gui.border_width - 1 ,
2054 Rows * gui.char_height + gui.border_width - 1 }
2055 };
2056
Bram Moolenaar15d63192011-09-14 16:05:15 +02002057 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 return;
2059
2060 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002061 gui_mch_set_bg_color(gui.back_pixel);
2062 PgDrawRect(&text_rect, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 DRAW_END;
2064}
2065
2066 void
2067gui_mch_delete_lines(int row, int num_lines)
2068{
2069 PhRect_t rect;
2070 PhPoint_t delta;
2071
Bram Moolenaar15d63192011-09-14 16:05:15 +02002072 rect.ul.x = FILL_X(gui.scroll_region_left);
2073 rect.ul.y = FILL_Y(row + num_lines);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074
Bram Moolenaar15d63192011-09-14 16:05:15 +02002075 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1;
2076 rect.lr.y = FILL_Y(gui.scroll_region_bot + 1) - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077
Bram Moolenaar15d63192011-09-14 16:05:15 +02002078 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
2079 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
2080 PhTranslateRect(&rect, &gui_ph_raw_offset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081
2082 delta.x = 0;
2083 delta.y = -num_lines * gui.char_height;
2084
2085 PgFlush();
2086
Bram Moolenaar15d63192011-09-14 16:05:15 +02002087 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)), &rect, &delta);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088
2089 gui_clear_block(
2090 gui.scroll_region_bot - num_lines + 1,
2091 gui.scroll_region_left,
2092 gui.scroll_region_bot,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002093 gui.scroll_region_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094}
2095
2096 void
2097gui_mch_insert_lines(int row, int num_lines)
2098{
2099 PhRect_t rect;
2100 PhPoint_t delta;
2101
Bram Moolenaar15d63192011-09-14 16:05:15 +02002102 rect.ul.x = FILL_X(gui.scroll_region_left);
2103 rect.ul.y = FILL_Y(row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104
Bram Moolenaar15d63192011-09-14 16:05:15 +02002105 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1;
2106 rect.lr.y = FILL_Y(gui.scroll_region_bot - num_lines + 1) - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107
Bram Moolenaar15d63192011-09-14 16:05:15 +02002108 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset);
2109 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL));
2110 PhTranslateRect(&rect, &gui_ph_raw_offset);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111
2112 delta.x = 0;
2113 delta.y = num_lines * gui.char_height;
2114
2115 PgFlush();
2116
Bram Moolenaar15d63192011-09-14 16:05:15 +02002117 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)) , &rect, &delta);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118
Bram Moolenaar15d63192011-09-14 16:05:15 +02002119 gui_clear_block(row, gui.scroll_region_left,
2120 row + num_lines - 1, gui.scroll_region_right);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121}
2122
2123 void
2124gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
2125{
2126 static char *utf8_buffer = NULL;
2127 static int utf8_len = 0;
2128
Bram Moolenaar15d63192011-09-14 16:05:15 +02002129 PhPoint_t pos = { TEXT_X(col), TEXT_Y(row) };
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 PhRect_t rect;
2131
Bram Moolenaar15d63192011-09-14 16:05:15 +02002132 if (is_ignore_draw == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 return;
2134
2135 DRAW_START;
2136
Bram Moolenaar15d63192011-09-14 16:05:15 +02002137 if (!(flags & DRAW_TRANSP))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {
2139 PgDrawIRect(
Bram Moolenaar15d63192011-09-14 16:05:15 +02002140 FILL_X(col), FILL_Y(row),
2141 FILL_X(col + len) - 1, FILL_Y(row + 1) - 1,
2142 Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 }
2144
Bram Moolenaar15d63192011-09-14 16:05:15 +02002145 if (flags & DRAW_UNDERL)
2146 PgSetUnderline(gui.norm_pixel, Pg_TRANSPARENT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147
Bram Moolenaar15d63192011-09-14 16:05:15 +02002148 if (charset_translate != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149#ifdef FEAT_MBYTE
2150 && enc_utf8 == 0
2151#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02002152 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {
2154 int src_taken, dst_made;
2155
2156 /* Use a static buffer to avoid large amounts of de/allocations */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002157 if (utf8_len < len)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002159 utf8_buffer = realloc(utf8_buffer, len * MB_LEN_MAX);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 utf8_len = len;
2161 }
2162
2163 PxTranslateToUTF(
2164 charset_translate,
2165 s,
2166 len,
2167 &src_taken,
2168 utf8_buffer,
2169 utf8_len,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002170 &dst_made);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 s = utf8_buffer;
2172 len = dst_made;
2173 }
2174
Bram Moolenaar15d63192011-09-14 16:05:15 +02002175 PgDrawText(s, len, &pos, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176
Bram Moolenaar15d63192011-09-14 16:05:15 +02002177 if (flags & DRAW_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {
2179 /* FIXME: try and only calculate these values once... */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002180 rect.ul.x = FILL_X(col) + 1;
2181 rect.ul.y = FILL_Y(row);
2182 rect.lr.x = FILL_X(col + len) - 1;
2183 rect.lr.y = FILL_Y(row + 1) - 1;
2184 /* PgSetUserClip(NULL) causes the scrollbar to not redraw... */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185#if 0
2186 pos.x++;
2187
Bram Moolenaar15d63192011-09-14 16:05:15 +02002188 PgSetUserClip(&rect);
2189 PgDrawText(s, len, &pos, 0);
2190 PgSetUserClip(NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191#else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002192 rect.lr.y -= (p_linespace + 1) / 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 /* XXX: DrawTextArea doesn't work with phditto */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002194 PgDrawTextArea(s, len, &rect, Pg_TEXT_BOTTOM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195#endif
2196 }
2197
Bram Moolenaar15d63192011-09-14 16:05:15 +02002198 if (flags & DRAW_UNDERL)
2199 PgSetUnderline(Pg_TRANSPARENT, Pg_TRANSPARENT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200
2201 DRAW_END;
2202}
2203
2204/****************************************************************************/
2205/* Cursor */
2206
2207 void
2208gui_mch_draw_hollow_cursor(guicolor_T color)
2209{
2210 PhRect_t r;
2211
2212 /* FIXME: Double width characters */
2213
Bram Moolenaar15d63192011-09-14 16:05:15 +02002214 r.ul.x = FILL_X(gui.col);
2215 r.ul.y = FILL_Y(gui.row);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 r.lr.x = r.ul.x + gui.char_width - 1;
2217 r.lr.y = r.ul.y + gui.char_height - 1;
2218
2219 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002220 PgSetStrokeColor(color);
2221 PgDrawRect(&r, Pg_DRAW_STROKE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 DRAW_END;
2223}
2224
2225 void
2226gui_mch_draw_part_cursor(int w, int h, guicolor_T color)
2227{
2228 PhRect_t r;
2229
Bram Moolenaar15d63192011-09-14 16:05:15 +02002230 r.ul.x = FILL_X(gui.col);
2231 r.ul.y = FILL_Y(gui.row) + gui.char_height - h;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 r.lr.x = r.ul.x + w - 1;
2233 r.lr.y = r.ul.y + h - 1;
2234
2235 DRAW_START;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002236 gui_mch_set_bg_color(color);
2237 PgDrawRect(&r, Pg_DRAW_FILL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 DRAW_END;
2239}
2240
Bram Moolenaar703a8042016-06-04 16:24:32 +02002241 int
2242gui_mch_is_blinking(void)
2243{
2244 return blink_state != BLINK_NONE;
2245}
2246
Bram Moolenaar9d5d3c92016-07-07 16:43:02 +02002247 int
2248gui_mch_is_blink_off(void)
2249{
2250 return blink_state == BLINK_OFF;
2251}
2252
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 void
2254gui_mch_set_blinking(long wait, long on, long off)
2255{
2256 blink_waittime = wait;
2257 blink_ontime = on;
2258 blink_offtime = off;
2259}
2260
2261 void
2262gui_mch_start_blink(void)
2263{
2264 /* Only turn on the timer on if none of the times are zero */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002265 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002267 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL,
2268 blink_waittime, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 blink_state = BLINK_ON;
2270 gui_update_cursor(TRUE, FALSE);
2271 }
2272}
2273
2274 void
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +01002275gui_mch_stop_blink(int may_call_gui_update_cursor)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002277 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, 0, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278
Bram Moolenaar1dd45fb2018-01-31 21:10:01 +01002279 if (blink_state == BLINK_OFF && may_call_gui_update_cursor)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 gui_update_cursor(TRUE, FALSE);
2281
2282 blink_state = BLINK_NONE;
2283}
2284
2285/****************************************************************************/
2286/* miscellaneous functions */
2287
2288 void
2289gui_mch_beep(void)
2290{
2291 PtBeep();
2292}
2293
2294 void
2295gui_mch_flash(int msec)
2296{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002297 PgSetFillXORColor(Pg_BLACK, Pg_WHITE);
2298 PgSetDrawMode(Pg_DRAWMODE_XOR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 gui_mch_clear_all();
2300 gui_mch_flush();
2301
Bram Moolenaar15d63192011-09-14 16:05:15 +02002302 ui_delay((long) msec, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303
2304 gui_mch_clear_all();
Bram Moolenaar15d63192011-09-14 16:05:15 +02002305 PgSetDrawMode(Pg_DRAWMODE_OPAQUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 gui_mch_flush();
2307}
2308
2309 void
2310gui_mch_flush(void)
2311{
2312 PgFlush();
2313}
2314
2315 void
2316gui_mch_set_text_area_pos(int x, int y, int w, int h)
2317{
2318 PhArea_t area = {{x, y}, {w, h}};
2319
Bram Moolenaar15d63192011-09-14 16:05:15 +02002320 PtSetResource(gui.vimTextArea, Pt_ARG_AREA, &area, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321}
2322
2323 int
2324gui_mch_haskey(char_u *name)
2325{
2326 int i;
2327
2328 for (i = 0; special_keys[i].key_sym != 0; i++)
2329 if (name[0] == special_keys[i].vim_code0 &&
2330 name[1] == special_keys[i].vim_code1)
Bram Moolenaard2221132011-07-27 14:09:09 +02002331 return OK;
2332 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333}
2334
2335/****************************************************************************/
2336/* Menu */
2337
2338#ifdef FEAT_TOOLBAR
2339#include "toolbar.phi"
2340
2341static PhImage_t *gui_ph_toolbar_images[] = {
2342 &tb_new_phi,
2343 &tb_open_phi,
2344 &tb_save_phi,
2345 &tb_undo_phi,
2346 &tb_redo_phi,
2347 &tb_cut_phi,
2348 &tb_copy_phi,
2349 &tb_paste_phi,
2350 &tb_print_phi,
2351 &tb_help_phi,
2352 &tb_find_phi,
2353 &tb_save_all_phi,
2354 &tb_save_session_phi,
2355 &tb_new_session_phi,
2356 &tb_load_session_phi,
2357 &tb_macro_phi,
2358 &tb_replace_phi,
2359 &tb_close_phi,
2360 &tb_maximize_phi,
2361 &tb_minimize_phi,
2362 &tb_split_phi,
2363 &tb_shell_phi,
2364 &tb_find_prev_phi,
2365 &tb_find_next_phi,
2366 &tb_find_help_phi,
2367 &tb_make_phi,
2368 &tb_jump_phi,
2369 &tb_ctags_phi,
2370 &tb_vsplit_phi,
2371 &tb_maxwidth_phi,
2372 &tb_minwidth_phi
2373};
2374
2375static PhImage_t *
Bram Moolenaar15d63192011-09-14 16:05:15 +02002376gui_ph_toolbar_load_icon(char_u *iconfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377{
2378 static PhImage_t external_icon;
2379 PhImage_t *temp_phi = NULL;
2380
Bram Moolenaar15d63192011-09-14 16:05:15 +02002381 temp_phi = PxLoadImage(iconfile, NULL);
2382 if (temp_phi != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {
2384 /* The label widget will free the image/palette/etc. for us when
2385 * it's destroyed */
2386 temp_phi->flags |= Ph_RELEASE_IMAGE_ALL;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002387 memcpy(&external_icon, temp_phi, sizeof(external_icon));
2388 free(temp_phi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389
2390 temp_phi = &external_icon;
2391 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002392 return temp_phi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393}
2394
2395/*
2396 * This returns either a builtin icon image, an external image or NULL
2397 * if it can't find either. The caller can't and doesn't need to try and
2398 * free() the returned image, and it can't store the image pointer.
2399 * (When setting the Pt_ARG_LABEL_IMAGE resource, the contents of the
2400 * PhImage_t are copied, and the original PhImage_t aren't needed anymore).
2401 */
2402static PhImage_t *
Bram Moolenaar15d63192011-09-14 16:05:15 +02002403gui_ph_toolbar_find_icon(vimmenu_T *menu)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404{
2405 char_u full_pathname[ MAXPATHL + 1 ];
2406 PhImage_t *icon = NULL;
2407
Bram Moolenaar15d63192011-09-14 16:05:15 +02002408 if (menu->icon_builtin == FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002410 if (menu->iconfile != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 /* TODO: use gui_find_iconfile() */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002412 icon = gui_ph_toolbar_load_icon(menu->iconfile);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413
2414 /* TODO: Restrict loading to just .png? Search for any format? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002415 if ((icon == NULL) &&
2416 ((gui_find_bitmap(menu->name, full_pathname, "gif") == OK) ||
2417 (gui_find_bitmap(menu->name, full_pathname, "png") == OK)))
2418 icon = gui_ph_toolbar_load_icon(full_pathname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419
Bram Moolenaar15d63192011-09-14 16:05:15 +02002420 if (icon != NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002421 return icon;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 }
2423
Bram Moolenaar15d63192011-09-14 16:05:15 +02002424 if (menu->iconidx >= 0 &&
2425 (menu->iconidx < ARRAY_LENGTH(gui_ph_toolbar_images)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {
Bram Moolenaard2221132011-07-27 14:09:09 +02002427 return gui_ph_toolbar_images[menu->iconidx];
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 }
2429
Bram Moolenaard2221132011-07-27 14:09:09 +02002430 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431}
2432#endif
2433
Bram Moolenaar15d63192011-09-14 16:05:15 +02002434#if defined(FEAT_MENU) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 void
2436gui_mch_enable_menu(int flag)
2437{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002438 if (flag != 0)
2439 PtRealizeWidget(gui.vimMenuBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002441 PtUnrealizeWidget(gui.vimMenuBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442}
2443
2444 void
2445gui_mch_set_menu_pos(int x, int y, int w, int h)
2446{
2447 /* Nothing */
2448}
2449
2450/* Change the position of a menu button in the parent */
2451 static void
Bram Moolenaar15d63192011-09-14 16:05:15 +02002452gui_ph_position_menu(PtWidget_t *widget, int priority)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453{
2454 PtWidget_t *traverse;
2455 vimmenu_T *menu;
2456
Bram Moolenaar15d63192011-09-14 16:05:15 +02002457 traverse = PtWidgetChildBack(PtWidgetParent(widget));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458
2459 /* Iterate through the list of widgets in traverse, until
2460 * we find the position we want to insert our widget into */
2461 /* TODO: traverse from front to back, possible speedup? */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002462 while (traverse != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002464 PtGetResource(traverse, Pt_ARG_POINTER, &menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465
Bram Moolenaar15d63192011-09-14 16:05:15 +02002466 if (menu != NULL &&
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 priority < menu->priority &&
Bram Moolenaar15d63192011-09-14 16:05:15 +02002468 widget != traverse)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {
2470 /* Insert the widget before the current traverse widget */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002471 PtWidgetInsert(widget, traverse, 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 return;
2473 }
2474
Bram Moolenaar15d63192011-09-14 16:05:15 +02002475 traverse = PtWidgetBrotherInFront(traverse);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 }
2477}
2478
2479/* the index is ignored because it's not useful for our purposes */
2480 void
2481gui_mch_add_menu(vimmenu_T *menu, int index)
2482{
2483 vimmenu_T *parent = menu->parent;
2484 char_u *accel_key;
2485 char_u mnemonic_str[MB_LEN_MAX];
2486 int n;
2487 PtArg_t args[5];
2488
2489 menu->submenu_id = menu->id = NULL;
2490
Bram Moolenaar15d63192011-09-14 16:05:15 +02002491 if (menu_is_menubar(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {
2493
Bram Moolenaar15d63192011-09-14 16:05:15 +02002494 accel_key = vim_strchr(menu->name, '&');
2495 if (accel_key != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {
2497 mnemonic_str[0] = accel_key[1];
2498 mnemonic_str[1] = NUL;
2499 }
2500
2501 /* Create the menu button */
2502 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002503 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2504 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0);
2505 if (accel_key != NULL)
2506 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str, 0);
2507 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508
Bram Moolenaar15d63192011-09-14 16:05:15 +02002509 if (parent != NULL)
2510 PtSetArg(&args[ n++ ], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511
Bram Moolenaar15d63192011-09-14 16:05:15 +02002512 menu->id = PtCreateWidget(PtMenuButton,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 (parent == NULL) ? gui.vimMenuBar : parent->submenu_id,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002514 n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515
Bram Moolenaar15d63192011-09-14 16:05:15 +02002516 PtAddCallback(menu->id, Pt_CB_ARM, gui_ph_handle_pulldown_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517
2518 /* Create the actual menu */
2519 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002520 if (parent != NULL)
2521 PtSetArg(&args[ n++ ], Pt_ARG_MENU_FLAGS, Pt_TRUE, Pt_MENU_CHILD);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522
Bram Moolenaar15d63192011-09-14 16:05:15 +02002523 menu->submenu_id = PtCreateWidget(PtMenu, menu->id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524
Bram Moolenaar15d63192011-09-14 16:05:15 +02002525 if (parent == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002527 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED,
2528 gui_ph_handle_menu_unrealized, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529
Bram Moolenaar15d63192011-09-14 16:05:15 +02002530 if (menu->mnemonic != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002532 PtAddHotkeyHandler(gui.vimWindow, tolower(menu->mnemonic),
2533 Pk_KM_Alt, 0, menu, gui_ph_handle_pulldown_menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 }
2535 }
2536
Bram Moolenaar15d63192011-09-14 16:05:15 +02002537 gui_ph_position_menu(menu->id, menu->priority);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538
2539 /* Redraw menubar here instead of gui_mch_draw_menubar */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002540 if (gui.menu_is_active)
2541 PtRealizeWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002543 else if (menu_is_popup(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002545 menu->submenu_id = PtCreateWidget(PtMenu, gui.vimWindow, 0, NULL);
2546 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED,
2547 gui_ph_handle_menu_unrealized, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 }
2549}
2550
2551 void
2552gui_mch_add_menu_item(vimmenu_T *menu, int index)
2553{
2554 vimmenu_T *parent = menu->parent;
2555 char_u *accel_key;
2556 char_u mnemonic_str[MB_LEN_MAX];
2557 int n;
2558 PtArg_t args[13];
2559
2560 n = 0;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002561 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562
2563#ifdef FEAT_TOOLBAR
Bram Moolenaar15d63192011-09-14 16:05:15 +02002564 if (menu_is_toolbar(parent->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002566 if (menu_is_separator(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002568 PtSetArg(&args[ n++ ], Pt_ARG_SEP_FLAGS,
2569 Pt_SEP_VERTICAL, Pt_SEP_ORIENTATION);
2570 PtSetArg(&args[ n++ ], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0);
2571 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS,
2572 Pt_TRUE, Pt_ANCHOR_TOP_BOTTOM);
2573 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, 2, 0);
2574 menu->id = PtCreateWidget(PtSeparator, gui.vimToolBar, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 }
2576 else
2577 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002578 if (strstr((const char *) p_toolbar, "text") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002580 PtSetArg(&args[ n++ ], Pt_ARG_BALLOON_POSITION,
2581 Pt_BALLOON_BOTTOM, 0);
2582 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2583 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_FONT, "TextFont08", 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002585 if ((strstr((const char *) p_toolbar, "icons") != NULL) &&
2586 (gui_ph_toolbar_images != NULL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002588 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_IMAGE,
2589 gui_ph_toolbar_find_icon(menu), 0);
2590 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_TYPE, Pt_TEXT_IMAGE, 0);
2591 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_IMAGE_SPACING, 0, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002593 if (strstr((const char *) p_toolbar, "tooltips") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002595 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_BALLOON,
2596 gui_ph_show_tooltip, 0);
2597 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_FLAGS,
2598 Pt_TRUE, Pt_SHOW_BALLOON);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002600 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 1, 0);
2601 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 1, 0);
2602 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_FALSE,
2603 Pt_HIGHLIGHTED | Pt_GETS_FOCUS);
2604 PtSetArg(&args[ n++ ], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0);
2605 menu->id = PtCreateWidget(PtButton, gui.vimToolBar, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606
Bram Moolenaar15d63192011-09-14 16:05:15 +02002607 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 }
2609 /* Update toolbar if it's open */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002610 if (PtWidgetIsRealized(gui.vimToolBar))
2611 PtRealizeWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 }
2613 else
2614#endif
Bram Moolenaar15d63192011-09-14 16:05:15 +02002615 if (menu_is_separator(menu->name))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002617 menu->id = PtCreateWidget(PtSeparator, parent->submenu_id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 }
2619 else
2620 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002621 accel_key = vim_strchr(menu->name, '&');
2622 if (accel_key != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {
2624 mnemonic_str[0] = accel_key[1];
2625 mnemonic_str[1] = NUL;
2626 }
2627
Bram Moolenaar15d63192011-09-14 16:05:15 +02002628 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0);
2629 if (accel_key != NULL)
2630 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str,
2631 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632
Bram Moolenaar15d63192011-09-14 16:05:15 +02002633 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634
Bram Moolenaar15d63192011-09-14 16:05:15 +02002635 menu->id = PtCreateWidget(PtMenuButton, parent->submenu_id, n, args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636
Bram Moolenaar15d63192011-09-14 16:05:15 +02002637 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638
2639#ifdef USE_PANEL_GROUP
Bram Moolenaar15d63192011-09-14 16:05:15 +02002640 if (gui_ph_is_buffer_item(menu, parent) == TRUE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002642 PtAddCallback(menu->id, Pt_CB_DESTROYED,
2643 gui_ph_handle_buffer_remove, menu);
2644 gui_ph_pg_add_buffer(menu->dname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 }
2646#endif
2647 }
2648
Bram Moolenaar15d63192011-09-14 16:05:15 +02002649 gui_ph_position_menu(menu->id, menu->priority);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650}
2651
2652 void
2653gui_mch_destroy_menu(vimmenu_T *menu)
2654{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002655 if (menu->submenu_id != NULL)
2656 PtDestroyWidget(menu->submenu_id);
2657 if (menu->id != NULL)
2658 PtDestroyWidget(menu->id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659
2660 menu->submenu_id = NULL;
2661 menu->id = NULL;
2662}
2663
2664 void
2665gui_mch_menu_grey(vimmenu_T *menu, int grey)
2666{
2667 long flags, mask, fields;
2668
Bram Moolenaar15d63192011-09-14 16:05:15 +02002669 if (menu->id == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 return;
2671
Bram Moolenaar15d63192011-09-14 16:05:15 +02002672 flags = PtWidgetFlags(menu->id);
2673 if (PtWidgetIsClass(menu->id, PtMenuButton) &&
2674 PtWidgetIsClass(PtWidgetParent(menu->id), PtMenu))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {
2676 fields = Pt_FALSE;
2677 mask = Pt_SELECTABLE | Pt_HIGHLIGHTED;
2678 }
2679 else
2680 {
2681 fields = Pt_TRUE;
2682 mask = Pt_BLOCKED | Pt_GHOST;
2683 }
2684
Bram Moolenaar15d63192011-09-14 16:05:15 +02002685 if (! grey)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 fields = ~fields;
2687
Bram Moolenaar15d63192011-09-14 16:05:15 +02002688 PtSetResource(menu->id, Pt_ARG_FLAGS, fields,
2689 mask);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690}
2691
2692 void
2693gui_mch_menu_hidden(vimmenu_T *menu, int hidden)
2694{
2695 /* TODO: [un]realize the widget? */
2696}
2697
2698 void
2699gui_mch_draw_menubar(void)
2700{
2701 /* The only time a redraw is needed is when a menu button
2702 * is added to the menubar, and that is detected and the bar
2703 * redrawn in gui_mch_add_menu_item
2704 */
2705}
2706
2707 void
2708gui_mch_show_popupmenu(vimmenu_T *menu)
2709{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002710 PtSetResource(menu->submenu_id, Pt_ARG_POS, &abs_mouse, 0);
2711 PtRealizeWidget(menu->submenu_id);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712}
2713
2714 void
2715gui_mch_toggle_tearoffs(int enable)
2716{
2717 /* No tearoffs yet */
2718}
2719
2720#endif
2721
Bram Moolenaar15d63192011-09-14 16:05:15 +02002722#if defined(FEAT_TOOLBAR) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 void
2724gui_mch_show_toolbar(int showit)
2725{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002726 if (showit)
2727 PtRealizeWidget(gui.vimToolBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002729 PtUnrealizeWidget(gui.vimToolBar);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730}
2731#endif
2732
2733/****************************************************************************/
2734/* Fonts */
2735
2736 static GuiFont
2737gui_ph_get_font(
2738 char_u *font_name,
2739 int_u font_flags,
2740 int_u font_size,
2741 /* Check whether the resulting font has the font flags and size that
2742 * was asked for */
2743 int_u enforce
2744 )
2745{
2746 char_u *font_tag;
2747 FontQueryInfo info;
2748 int_u style;
2749
Bram Moolenaar15d63192011-09-14 16:05:15 +02002750 font_tag = alloc(MAX_FONT_TAG);
2751 if (font_tag != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002753 if (PfGenerateFontName(font_name, font_flags, font_size,
2754 font_tag) != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {
2756 /* Enforce some limits on the font used */
2757 style = PHFONT_INFO_FIXED;
2758
Bram Moolenaar15d63192011-09-14 16:05:15 +02002759 if (enforce & PF_STYLE_BOLD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 style |= PHFONT_INFO_BOLD;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002761 if (enforce & PF_STYLE_ANTIALIAS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 style |= PHFONT_INFO_ALIAS;
Bram Moolenaar15d63192011-09-14 16:05:15 +02002763 if (enforce & PF_STYLE_ITALIC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 style |= PHFONT_INFO_ITALIC;
2765
Bram Moolenaar15d63192011-09-14 16:05:15 +02002766 PfQueryFontInfo(font_tag, &info);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767
Bram Moolenaar15d63192011-09-14 16:05:15 +02002768 if (info.size == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 font_size = 0;
2770
2771 /* Make sure font size matches, and that the font style
2772 * at least has the bits we're checking for */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002773 if (font_size == info.size &&
2774 style == (info.style & style))
Bram Moolenaard2221132011-07-27 14:09:09 +02002775 return (GuiFont)font_tag;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 }
Bram Moolenaar15d63192011-09-14 16:05:15 +02002777 vim_free(font_tag);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002779 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780}
2781
2782/*
2783 * Split up the vim font name
2784 *
2785 * vim_font is in the form of
2786 * <name>:s<height>:a:b:i
2787 *
2788 * a = antialias
2789 * b = bold
2790 * i = italic
2791 *
2792 */
2793
2794 static int
2795gui_ph_parse_font_name(
2796 char_u *vim_font,
2797 char_u **font_name,
2798 int_u *font_flags,
Bram Moolenaar15d63192011-09-14 16:05:15 +02002799 int_u *font_size)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800{
2801 char_u *mark;
2802 int_u name_len, size;
2803
Bram Moolenaar15d63192011-09-14 16:05:15 +02002804 mark = vim_strchr(vim_font, ':');
2805 if (mark == NULL)
2806 name_len = STRLEN(vim_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 else
Bram Moolenaar15d63192011-09-14 16:05:15 +02002808 name_len = (int_u) (mark - vim_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809
Bram Moolenaar15d63192011-09-14 16:05:15 +02002810 *font_name = vim_strnsave(vim_font, name_len);
Bram Moolenaard0988c52011-08-10 12:19:04 +02002811 if (*font_name != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002813 if (mark != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002815 while (*mark != NUL && *mark++ == ':')
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {
Bram Moolenaard0988c52011-08-10 12:19:04 +02002817 switch (tolower(*mark++))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {
2819 case 'a': *font_flags |= PF_STYLE_ANTIALIAS; break;
2820 case 'b': *font_flags |= PF_STYLE_BOLD; break;
2821 case 'i': *font_flags |= PF_STYLE_ITALIC; break;
2822
2823 case 's':
Bram Moolenaar15d63192011-09-14 16:05:15 +02002824 size = getdigits(&mark);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 /* Restrict the size to some vague limits */
Bram Moolenaard0988c52011-08-10 12:19:04 +02002826 if (size < 1 || size > 100)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 size = 8;
2828
2829 *font_size = size;
2830 break;
2831
2832 default:
2833 break;
2834 }
2835 }
2836 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002837 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 }
Bram Moolenaard2221132011-07-27 14:09:09 +02002839 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840}
2841
2842 int
2843gui_mch_init_font(char_u *vim_font_name, int fontset)
2844{
2845 char_u *font_tag;
2846 char_u *font_name = NULL;
2847 int_u font_flags = 0;
2848 int_u font_size = 12;
2849
2850 FontQueryInfo info;
2851 PhRect_t extent;
2852
Bram Moolenaard0988c52011-08-10 12:19:04 +02002853 if (vim_font_name == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {
2855 /* Default font */
Bram Moolenaara0b19972009-07-01 14:13:18 +00002856 vim_font_name = "PC Terminal";
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 }
2858
Bram Moolenaar15d63192011-09-14 16:05:15 +02002859 if (STRCMP(vim_font_name, "*") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002861 font_tag = PtFontSelection(gui.vimWindow, NULL, NULL,
2862 "pcterm12", -1, PHFONT_FIXED, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863
Bram Moolenaard0988c52011-08-10 12:19:04 +02002864 if (font_tag == NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002865 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866
Bram Moolenaar15d63192011-09-14 16:05:15 +02002867 gui_mch_free_font(gui.norm_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 gui.norm_font = font_tag;
2869
Bram Moolenaar15d63192011-09-14 16:05:15 +02002870 PfQueryFontInfo(font_tag, &info);
2871 font_name = vim_strsave(info.font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 }
2873 else
2874 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002875 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags,
2876 &font_size) == FALSE)
Bram Moolenaard2221132011-07-27 14:09:09 +02002877 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878
Bram Moolenaar15d63192011-09-14 16:05:15 +02002879 font_tag = gui_ph_get_font(font_name, font_flags, font_size, 0);
Bram Moolenaard0988c52011-08-10 12:19:04 +02002880 if (font_tag == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002882 vim_free(font_name);
Bram Moolenaard2221132011-07-27 14:09:09 +02002883 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 }
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002885
Bram Moolenaar15d63192011-09-14 16:05:15 +02002886 gui_mch_free_font(gui.norm_font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 gui.norm_font = font_tag;
2888 }
2889
Bram Moolenaar15d63192011-09-14 16:05:15 +02002890 gui_mch_free_font(gui.bold_font);
2891 gui.bold_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_BOLD,
2892 font_size, PF_STYLE_BOLD);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893
Bram Moolenaar15d63192011-09-14 16:05:15 +02002894 gui_mch_free_font(gui.ital_font);
2895 gui.ital_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_ITALIC,
2896 font_size, PF_STYLE_ITALIC);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897
2898 /* This extent was brought to you by the letter 'g' */
Bram Moolenaar15d63192011-09-14 16:05:15 +02002899 PfExtentText(&extent, NULL, font_tag, "g", 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900
2901 gui.char_width = extent.lr.x - extent.ul.x + 1;
2902 gui.char_height = (- extent.ul.y) + extent.lr.y + 1;
2903 gui.char_ascent = - extent.ul.y;
2904
Bram Moolenaar15d63192011-09-14 16:05:15 +02002905 vim_free(font_name);
Bram Moolenaard2221132011-07-27 14:09:09 +02002906 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907}
2908
Bram Moolenaar02743632005-07-25 20:42:36 +00002909/*
2910 * Adjust gui.char_height (after 'linespace' was changed).
2911 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 int
Bram Moolenaar02743632005-07-25 20:42:36 +00002913gui_mch_adjust_charheight(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914{
2915 FontQueryInfo info;
2916
Bram Moolenaar15d63192011-09-14 16:05:15 +02002917 PfQueryFontInfo(gui.norm_font, &info);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918
2919 gui.char_height = - info.ascender + info.descender + p_linespace;
2920 gui.char_ascent = - info.ascender + p_linespace / 2;
2921
Bram Moolenaard2221132011-07-27 14:09:09 +02002922 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923}
2924
2925 GuiFont
2926gui_mch_get_font(char_u *vim_font_name, int report_error)
2927{
2928 char_u *font_name;
2929 char_u *font_tag;
2930 int_u font_size = 12;
2931 int_u font_flags = 0;
2932
Bram Moolenaar15d63192011-09-14 16:05:15 +02002933 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags,
2934 &font_size) != FALSE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {
Bram Moolenaar15d63192011-09-14 16:05:15 +02002936 font_tag = gui_ph_get_font(font_name, font_flags, font_size, -1);
2937 vim_free(font_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938
Bram Moolenaard0988c52011-08-10 12:19:04 +02002939 if (font_tag != NULL)
Bram Moolenaard2221132011-07-27 14:09:09 +02002940 return (GuiFont)font_tag;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 }
2942
Bram Moolenaard0988c52011-08-10 12:19:04 +02002943 if (report_error)
Bram Moolenaar15d63192011-09-14 16:05:15 +02002944 EMSG2(e_font, vim_font_name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945
Bram Moolenaard2221132011-07-27 14:09:09 +02002946 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947}
2948
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002949#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002950/*
2951 * Return the name of font "font" in allocated memory.
2952 * Don't know how to get the actual name, thus use the provided name.
2953 */
2954 char_u *
Bram Moolenaar68c2f632016-01-30 17:24:07 +01002955gui_mch_get_fontname(GuiFont font, char_u *name)
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002956{
2957 if (name == NULL)
2958 return NULL;
2959 return vim_strsave(name);
2960}
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002961#endif
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002962
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 void
2964gui_mch_set_font(GuiFont font)
2965{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002966 PgSetFont(font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967}
2968
2969 void
2970gui_mch_free_font(GuiFont font)
2971{
Bram Moolenaar15d63192011-09-14 16:05:15 +02002972 vim_free(font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973}
2974