Mercurial > vim
annotate src/gui_photon.c @ 11181:13544aa85dc0 v8.0.0477
patch 8.0.0477: the client-server test may hang when failing
commit https://github.com/vim/vim/commit/42205551b140bee8b419b24abe210f56bb80b35e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 18 19:42:22 2017 +0100
patch 8.0.0477: the client-server test may hang when failing
Problem: The client-server test may hang when failing.
Solution: Set a timer. Add assert_report()
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 18 Mar 2017 19:45:05 +0100 |
parents | 4aead6a9b7a9 |
children | 5a5709918a98 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
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 | |
3927 | 16 /* cproto fails on missing include files */ |
17 #ifndef PROTO | |
18 # ifdef FEAT_TOOLBAR | |
19 # include <photon/PxImage.h> | |
20 # endif | |
7 | 21 #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])) | |
2980 | 38 #define RGB(r, g, b) PgRGB(r, g, b) |
39 | |
40 #define EVENT_BUFFER_SIZE sizeof(PhEvent_t) + 1000 | |
7 | 41 |
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 | |
50 static char *empty_title = " "; | |
51 static char **panel_titles = NULL; | |
52 static ushort_t num_panels = 0; | |
53 static 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 | |
59 static PgColor_t gui_ph_mouse_color = Pg_BLACK; | |
60 | |
61 static PhPoint_t gui_ph_raw_offset; | |
62 static PtWidget_t *gui_ph_timer_cursor; /* handle cursor blinking */ | |
63 static PtWidget_t *gui_ph_timer_timeout; /* used in gui_mch_wait_for_chars */ | |
4352 | 64 static short is_timeout; /* Has the timeout occurred? */ |
7 | 65 |
66 /* | |
67 * This is set inside the mouse callback for a right mouse | |
68 * button click, and used for the popup menus | |
69 */ | |
70 static PhPoint_t abs_mouse; | |
71 | |
72 /* Try and avoid redraws while a resize is in progress */ | |
73 static int is_ignore_draw = FALSE; | |
74 | |
75 /* Used for converting to/from utf-8 and other charsets */ | |
76 static 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 */ | |
86 static enum { | |
87 BLINK_NONE, | |
88 BLINK_OFF, | |
89 BLINK_ON | |
90 } blink_state = BLINK_NONE; | |
91 | |
92 static long_u blink_waittime = 700; | |
93 static long_u blink_ontime = 400; | |
94 static long_u blink_offtime = 250; | |
95 | |
96 static 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 | |
194 static PtCallbackF_t gui_ph_handle_timer_cursor; | |
195 static PtCallbackF_t gui_ph_handle_timer_timeout; | |
196 | |
197 static PtCallbackF_t gui_ph_handle_window_cb; | |
198 | |
199 static PtCallbackF_t gui_ph_handle_scrollbar; | |
200 static PtCallbackF_t gui_ph_handle_keyboard; | |
201 static PtCallbackF_t gui_ph_handle_mouse; | |
202 static PtCallbackF_t gui_ph_handle_pulldown_menu; | |
203 static PtCallbackF_t gui_ph_handle_menu; | |
204 static PtCallbackF_t gui_ph_handle_focus; /* focus change of text area */ | |
205 | |
206 static PtCallbackF_t gui_ph_handle_menu_resize; | |
207 | |
208 /* When a menu is unrealized, give focus back to vimTextArea */ | |
209 static PtCallbackF_t gui_ph_handle_menu_unrealized; | |
210 | |
211 #ifdef USE_PANEL_GROUP | |
2980 | 212 static void gui_ph_get_panelgroup_margins(short*, short*, short*, short*); |
7 | 213 #endif |
214 | |
215 #ifdef FEAT_TOOLBAR | |
2980 | 216 static PhImage_t *gui_ph_toolbar_find_icon(vimmenu_T *menu); |
7 | 217 #endif |
218 | |
2980 | 219 static void gui_ph_draw_start(void); |
220 static void gui_ph_draw_end(void); | |
7 | 221 |
222 /* Set the text for the balloon */ | |
2980 | 223 static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window, |
7 | 224 PtWidget_t *widget, |
225 int position, | |
226 char *text, | |
227 char *font, | |
228 PgColor_t fill_color, | |
2980 | 229 PgColor_t text_color); |
7 | 230 |
231 /****************************************************************************/ | |
232 | |
2980 | 233 static PtWidget_t * gui_ph_show_tooltip(PtWidget_t *window, |
7 | 234 PtWidget_t *widget, |
235 int position, | |
236 char *text, | |
237 char *font, | |
238 PgColor_t fill_color, | |
2980 | 239 PgColor_t text_color) |
7 | 240 { |
241 PtArg_t arg; | |
242 vimmenu_T *menu; | |
243 char_u *tooltip; | |
244 | |
2980 | 245 PtSetArg(&arg, Pt_ARG_POINTER, &menu, 0); |
246 PtGetResources(widget, 1, &arg); | |
7 | 247 |
248 /* Override the text and position */ | |
249 | |
250 tooltip = text; | |
2980 | 251 if (menu != NULL) |
7 | 252 { |
253 int index = MENU_INDEX_TIP; | |
2980 | 254 if (menu->strings[ index ] != NULL) |
7 | 255 tooltip = menu->strings[ index ]; |
256 } | |
257 | |
2980 | 258 return PtInflateBalloon( |
7 | 259 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, | |
2980 | 267 text_color); |
7 | 268 } |
269 | |
270 static void | |
2980 | 271 gui_ph_resize_container(void) |
7 | 272 { |
273 PhArea_t area; | |
274 | |
2980 | 275 PtWidgetArea(gui.vimWindow, &area); |
276 PtWidgetPos (gui.vimContainer, &area.pos); | |
277 | |
278 PtSetResource(gui.vimContainer, Pt_ARG_AREA, &area, 0); | |
7 | 279 } |
280 | |
281 static int | |
282 gui_ph_handle_menu_resize( | |
283 PtWidget_t *widget, | |
284 void *other, | |
2980 | 285 PtCallbackInfo_t *info) |
7 | 286 { |
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 | |
1214 | 294 /* Because vim treats the toolbar and menubar separately, |
7 | 295 * and here they're lumped together into a PtToolbarGroup, |
296 * we only need either menu_height or toolbar_height set at once */ | |
2980 | 297 if (gui.menu_is_active) |
7 | 298 { |
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 | |
2980 | 316 PtSetResource(container, Pt_ARG_POS, &below_menu, 0); |
7 | 317 |
318 gui_ph_resize_container(); | |
319 | |
320 #ifdef USE_PANEL_GROUP | |
321 gui_ph_get_panelgroup_margins( | |
322 &pg_margin_top, &pg_margin_bottom, | |
2980 | 323 &pg_margin_left, &pg_margin_right); |
7 | 324 #endif |
2980 | 325 return Pt_CONTINUE; |
7 | 326 } |
327 | |
328 /* | |
329 * Pt_ARG_TIMER_REPEAT isn't used because the on & off times | |
330 * are different | |
331 */ | |
332 static int | |
333 gui_ph_handle_timer_cursor( | |
334 PtWidget_t *widget, | |
335 void *data, | |
2980 | 336 PtCallbackInfo_t *info) |
7 | 337 { |
2980 | 338 if (blink_state == BLINK_ON) |
7 | 339 { |
340 gui_undraw_cursor(); | |
341 blink_state = BLINK_OFF; | |
2980 | 342 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, |
343 blink_offtime, 0); | |
7 | 344 } |
345 else | |
346 { | |
347 gui_update_cursor(TRUE, FALSE); | |
348 blink_state = BLINK_ON; | |
2980 | 349 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, |
350 blink_ontime, 0); | |
7 | 351 } |
2980 | 352 return Pt_CONTINUE; |
7 | 353 } |
354 | |
355 static int | |
356 gui_ph_handle_timer_timeout(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) | |
357 { | |
358 is_timeout = TRUE; | |
359 | |
2980 | 360 return Pt_CONTINUE; |
7 | 361 } |
362 | |
363 static int | |
2998 | 364 gui_ph_handle_window_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 365 { |
366 PhWindowEvent_t *we = info->cbdata; | |
367 ushort_t *width, *height; | |
368 | |
2998 | 369 switch (we->event_f) { |
7 | 370 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 */ | |
2998 | 376 gui_mch_mousehide(MOUSE_SHOW); |
377 | |
378 if (we->event_state == Ph_WM_EVSTATE_FOCUS) | |
7 | 379 { |
380 gui_focus_change(TRUE); | |
381 gui_mch_start_blink(); | |
382 } | |
383 else | |
384 { | |
385 gui_focus_change(FALSE); | |
386 gui_mch_stop_blink(); | |
387 } | |
388 break; | |
389 | |
390 case Ph_WM_RESIZE: | |
2998 | 391 PtGetResource(gui.vimWindow, Pt_ARG_WIDTH, &width, 0); |
392 PtGetResource(gui.vimWindow, Pt_ARG_HEIGHT, &height, 0); | |
7 | 393 #ifdef USE_PANEL_GROUP |
394 width -= (pg_margin_left + pg_margin_right); | |
395 height -= (pg_margin_top + pg_margin_bottom); | |
396 #endif | |
2998 | 397 gui_resize_shell(*width, *height); |
398 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); | |
7 | 399 is_ignore_draw = FALSE; |
2998 | 400 PtEndFlux(gui.vimContainer); |
401 PtContainerRelease(gui.vimContainer); | |
7 | 402 break; |
403 | |
404 default: | |
405 break; | |
406 } | |
407 | |
2980 | 408 return Pt_CONTINUE; |
7 | 409 } |
410 | |
411 static int | |
2998 | 412 gui_ph_handle_scrollbar(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 413 { |
414 PtScrollbarCallback_t *scroll; | |
415 scrollbar_T *sb; | |
416 int value, dragging = FALSE; | |
417 | |
418 scroll = info->cbdata; | |
419 | |
420 sb = (scrollbar_T *) data; | |
2998 | 421 if (sb != NULL) |
7 | 422 { |
423 value = scroll->position; | |
2998 | 424 switch (scroll->action) |
7 | 425 { |
426 case Pt_SCROLL_DRAGGED: | |
427 dragging = TRUE; | |
428 break; | |
429 | |
430 case Pt_SCROLL_SET: | |
431 /* FIXME: return straight away here? */ | |
2980 | 432 return Pt_CONTINUE; |
7 | 433 break; |
434 } | |
435 | |
436 gui_drag_scrollbar(sb, value, dragging); | |
437 } | |
2980 | 438 return Pt_CONTINUE; |
7 | 439 } |
440 | |
441 static int | |
2998 | 442 gui_ph_handle_keyboard(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 443 { |
444 PhKeyEvent_t *key; | |
445 unsigned char string[6]; | |
446 int len, i; | |
447 int ch, modifiers; | |
448 | |
2998 | 449 key = PhGetData(info->event); |
7 | 450 |
451 ch = modifiers = len = 0; | |
452 | |
2998 | 453 if (p_mh) |
454 gui_mch_mousehide(MOUSE_HIDE); | |
7 | 455 |
456 /* We're a good lil photon program, aren't we? yes we are, yeess wee arrr */ | |
2998 | 457 if (key->key_flags & Pk_KF_Compose) |
7 | 458 { |
2980 | 459 return Pt_CONTINUE; |
7 | 460 } |
461 | |
2998 | 462 if ((key->key_flags & Pk_KF_Cap_Valid) && |
463 PkIsKeyDown(key->key_flags)) | |
7 | 464 { |
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 */ | |
2998 | 470 if (((key->key_mods & Pk_KM_Alt) && |
471 !(key->key_mods & Pk_KM_Shift) && | |
472 !(key->key_mods & Pk_KM_Ctrl)) && | |
7 | 473 gui.menu_is_active && |
2998 | 474 (*p_wak == 'y' || |
475 (*p_wak == 'm' && | |
476 gui_is_menu_shortcut(key->key_cap)))) | |
7 | 477 { |
478 /* Fallthrough and let photon look for the hotkey */ | |
2980 | 479 return Pt_CONTINUE; |
7 | 480 } |
481 #endif | |
482 | |
3076 | 483 for (i = 0; special_keys[i].key_sym != 0; i++) |
7 | 484 { |
2998 | 485 if (special_keys[i].key_sym == key->key_cap) |
7 | 486 { |
487 len = 0; | |
2998 | 488 if (special_keys[i].vim_code1 == NUL) |
7 | 489 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 */ | |
2998 | 494 if (key->key_cap >= Pk_KP_Enter && key->key_cap <= Pk_KP_9 |
495 && (key->key_mods & Pk_KM_Num_Lock)) | |
7 | 496 { |
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 | |
2998 | 502 ch = TO_SPECIAL(special_keys[i].vim_code0, |
503 special_keys[i].vim_code1); | |
7 | 504 } |
505 break; | |
506 } | |
507 } | |
508 | |
2998 | 509 if (key->key_mods & Pk_KM_Ctrl) |
7 | 510 modifiers |= MOD_MASK_CTRL; |
2998 | 511 if (key->key_mods & Pk_KM_Alt) |
7 | 512 modifiers |= MOD_MASK_ALT; |
2998 | 513 if (key->key_mods & Pk_KM_Shift) |
7 | 514 modifiers |= MOD_MASK_SHIFT; |
515 | |
516 /* Is this not a special key? */ | |
2998 | 517 if (special_keys[i].key_sym == 0) |
7 | 518 { |
2998 | 519 ch = PhTo8859_1(key); |
520 if (ch == -1 | |
7 | 521 #ifdef FEAT_MBYTE |
2998 | 522 || (enc_utf8 && ch > 127) |
7 | 523 #endif |
524 ) | |
525 { | |
526 #ifdef FEAT_MBYTE | |
2998 | 527 len = PhKeyToMb(string, key); |
528 if (len > 0) | |
7 | 529 { |
530 static char buf[6]; | |
531 int src_taken, dst_made; | |
2998 | 532 if (enc_utf8 != TRUE) |
7 | 533 { |
534 PxTranslateFromUTF( | |
535 charset_translate, | |
536 string, | |
537 len, | |
538 &src_taken, | |
539 buf, | |
540 6, | |
3054 | 541 &dst_made); |
542 | |
543 add_to_input_buf(buf, dst_made); | |
7 | 544 } |
545 else | |
546 { | |
3054 | 547 add_to_input_buf(string, len); |
7 | 548 } |
549 | |
2980 | 550 return Pt_CONSUME; |
7 | 551 } |
552 len = 0; | |
553 #endif | |
554 ch = key->key_cap; | |
3054 | 555 if (ch < 0xff) |
7 | 556 { |
557 /* FIXME: is this the right thing to do? */ | |
3054 | 558 if (modifiers & MOD_MASK_CTRL) |
7 | 559 { |
560 modifiers &= ~MOD_MASK_CTRL; | |
561 | |
3054 | 562 if ((ch >= 'a' && ch <= 'z') || |
7 | 563 ch == '[' || |
564 ch == ']' || | |
3054 | 565 ch == '\\') |
566 ch = Ctrl_chr(ch); | |
567 else if (ch == '2') | |
7 | 568 ch = NUL; |
3054 | 569 else if (ch == '6') |
7 | 570 ch = 0x1e; |
3054 | 571 else if (ch == '-') |
7 | 572 ch = 0x1f; |
573 else | |
574 modifiers |= MOD_MASK_CTRL; | |
575 } | |
576 | |
3054 | 577 if (modifiers & MOD_MASK_ALT) |
7 | 578 { |
3054 | 579 ch = Meta(ch); |
7 | 580 modifiers &= ~MOD_MASK_ALT; |
581 } | |
582 } | |
583 else | |
584 { | |
2980 | 585 return Pt_CONTINUE; |
7 | 586 } |
587 } | |
588 else | |
589 modifiers &= ~MOD_MASK_SHIFT; | |
590 } | |
591 | |
3054 | 592 ch = simplify_key(ch, &modifiers); |
593 if (modifiers) | |
7 | 594 { |
595 string[ len++ ] = CSI; | |
596 string[ len++ ] = KS_MODIFIER; | |
597 string[ len++ ] = modifiers; | |
598 } | |
599 | |
3054 | 600 if (IS_SPECIAL(ch)) |
7 | 601 { |
602 string[ len++ ] = CSI; | |
3054 | 603 string[ len++ ] = K_SECOND(ch); |
604 string[ len++ ] = K_THIRD(ch); | |
7 | 605 } |
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 | |
3054 | 625 if (len > 0) |
7 | 626 { |
3054 | 627 add_to_input_buf(string, len); |
2980 | 628 return Pt_CONSUME; |
7 | 629 } |
630 } | |
631 | |
2980 | 632 return Pt_CONTINUE; |
7 | 633 } |
634 | |
635 static int | |
3054 | 636 gui_ph_handle_mouse(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 637 { |
638 PhPointerEvent_t *pointer; | |
639 PhRect_t *pos; | |
640 int button = 0, repeated_click, modifiers = 0x0; | |
641 short mouse_x, mouse_y; | |
642 | |
3054 | 643 pointer = PhGetData(info->event); |
644 pos = PhGetRects(info->event); | |
645 | |
646 gui_mch_mousehide(MOUSE_SHOW); | |
7 | 647 |
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 | |
3054 | 655 if (info->event->type == Ph_EV_PTR_MOTION_NOBUTTON) |
7 | 656 { |
3054 | 657 gui_mouse_moved(mouse_x, mouse_y); |
2980 | 658 return Pt_CONTINUE; |
7 | 659 } |
660 | |
3054 | 661 if (pointer->key_mods & Pk_KM_Shift) |
7 | 662 modifiers |= MOUSE_SHIFT; |
3054 | 663 if (pointer->key_mods & Pk_KM_Ctrl) |
7 | 664 modifiers |= MOUSE_CTRL; |
3054 | 665 if (pointer->key_mods & Pk_KM_Alt) |
7 | 666 modifiers |= MOUSE_ALT; |
667 | |
668 /* | |
669 * FIXME More than one button may be involved, but for | |
670 * now just deal with one | |
671 */ | |
3054 | 672 if (pointer->buttons & Ph_BUTTON_SELECT) |
7 | 673 button = MOUSE_LEFT; |
674 | |
3054 | 675 if (pointer->buttons & Ph_BUTTON_MENU) |
7 | 676 { |
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 | |
3054 | 683 if (pointer->buttons & Ph_BUTTON_ADJUST) |
7 | 684 button = MOUSE_MIDDLE; |
685 | |
686 /* Catch a real release (not phantom or other releases */ | |
3054 | 687 if (info->event->type == Ph_EV_BUT_RELEASE) |
7 | 688 button = MOUSE_RELEASE; |
689 | |
3054 | 690 if (info->event->type & Ph_EV_PTR_MOTION_BUTTON) |
7 | 691 button = MOUSE_DRAG; |
692 | |
693 #if 0 | |
694 /* Vim doesn't use button repeats */ | |
3054 | 695 if (info->event->type & Ph_EV_BUT_REPEAT) |
7 | 696 button = MOUSE_DRAG; |
697 #endif | |
698 | |
699 /* Don't do anything if it is one of the phantom mouse release events */ | |
3054 | 700 if ((button != MOUSE_RELEASE) || |
701 (info->event->subtype == Ph_EV_RELEASE_REAL)) | |
7 | 702 { |
703 repeated_click = (pointer->click_count >= 2) ? TRUE : FALSE; | |
704 | |
3054 | 705 gui_send_mouse_event(button , mouse_x, mouse_y, repeated_click, modifiers); |
7 | 706 } |
707 | |
2980 | 708 return Pt_CONTINUE; |
7 | 709 } |
710 | |
711 /* Handle a focus change of the PtRaw widget */ | |
712 static int | |
3054 | 713 gui_ph_handle_focus(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 714 { |
3054 | 715 if (info->reason == Pt_CB_LOST_FOCUS) |
7 | 716 { |
3054 | 717 PtRemoveEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON, |
718 gui_ph_handle_mouse, NULL); | |
719 | |
720 gui_mch_mousehide(MOUSE_SHOW); | |
7 | 721 } |
722 else | |
723 { | |
3054 | 724 PtAddEventHandler(gui.vimTextArea, Ph_EV_PTR_MOTION_NOBUTTON, |
725 gui_ph_handle_mouse, NULL); | |
7 | 726 } |
2980 | 727 return Pt_CONTINUE; |
7 | 728 } |
729 | |
730 static void | |
3054 | 731 gui_ph_handle_raw_draw(PtWidget_t *widget, PhTile_t *damage) |
7 | 732 { |
733 PhRect_t *r; | |
734 PhPoint_t offset; | |
735 PhPoint_t translation; | |
736 | |
3054 | 737 if (is_ignore_draw == TRUE) |
7 | 738 return; |
739 | |
3054 | 740 PtSuperClassDraw(PtBasic, widget, damage); |
741 PgGetTranslation(&translation); | |
7 | 742 PgClearTranslation(); |
743 | |
744 #if 0 | |
745 /* | |
1214 | 746 * This causes some weird problems, with drawing being done from |
7 | 747 * 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 | |
3054 | 756 PtWidgetOffset(widget, &offset); |
757 PhTranslatePoint(&offset, PtWidgetPos(gui.vimTextArea, NULL)); | |
7 | 758 |
759 #if 1 | |
760 /* Redraw individual damage regions */ | |
3054 | 761 if (damage->next != NULL) |
7 | 762 damage = damage->next; |
763 | |
3076 | 764 while (damage != NULL) |
7 | 765 { |
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, | |
3054 | 770 r->lr.y - r->ul.y + 1); |
7 | 771 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, | |
3054 | 779 r->lr.y - r->ul.y + 1); |
7 | 780 #endif |
781 | |
3054 | 782 PgSetTranslation(&translation, 0); |
7 | 783 } |
784 | |
785 static int | |
786 gui_ph_handle_pulldown_menu( | |
787 PtWidget_t *widget, | |
788 void *data, | |
3054 | 789 PtCallbackInfo_t *info) |
7 | 790 { |
3054 | 791 if (data != NULL) |
7 | 792 { |
793 vimmenu_T *menu = (vimmenu_T *) data; | |
794 | |
3054 | 795 PtPositionMenu(menu->submenu_id, NULL); |
796 PtRealizeWidget(menu->submenu_id); | |
7 | 797 } |
798 | |
2980 | 799 return Pt_CONTINUE; |
7 | 800 } |
801 | |
802 /* This is used for pulldown/popup menus and also toolbar buttons */ | |
803 static int | |
3076 | 804 gui_ph_handle_menu(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 805 { |
3076 | 806 if (data != NULL) |
7 | 807 { |
808 vimmenu_T *menu = (vimmenu_T *) data; | |
3076 | 809 gui_menu_cb(menu); |
7 | 810 } |
2980 | 811 return Pt_CONTINUE; |
7 | 812 } |
813 | |
814 /* Stop focus from disappearing into the menubar... */ | |
815 static int | |
816 gui_ph_handle_menu_unrealized( | |
817 PtWidget_t *widget, | |
818 void *data, | |
3076 | 819 PtCallbackInfo_t *info) |
7 | 820 { |
3076 | 821 PtGiveFocus(gui.vimTextArea, NULL); |
2980 | 822 return Pt_CONTINUE; |
7 | 823 } |
824 | |
825 static int | |
826 gui_ph_handle_window_open( | |
827 PtWidget_t *widget, | |
828 void *data, | |
3076 | 829 PtCallbackInfo_t *info) |
7 | 830 { |
3076 | 831 gui_set_shellsize(FALSE, TRUE, RESIZE_BOTH); |
2980 | 832 return Pt_CONTINUE; |
7 | 833 } |
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 | |
3076 | 842 gui_ph_draw_start(void) |
7 | 843 { |
1922 | 844 PhGC_t *gc; |
845 | |
846 gc = PgGetGC(); | |
3076 | 847 PgSetRegion(PtWidgetRid(PtFindDisjoint(gui.vimTextArea))); |
848 PgClearClippingsCx(gc); | |
849 PgClearTranslationCx(gc); | |
850 | |
851 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset); | |
852 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL)); | |
853 | |
854 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE); | |
7 | 855 } |
856 | |
857 static void | |
3076 | 858 gui_ph_draw_end(void) |
7 | 859 { |
860 gui_ph_raw_offset.x = -gui_ph_raw_offset.x; | |
861 gui_ph_raw_offset.y = -gui_ph_raw_offset.y; | |
3076 | 862 PgSetTranslation(&gui_ph_raw_offset, Pg_RELATIVE); |
7 | 863 } |
864 | |
865 #ifdef USE_PANEL_GROUP | |
866 static vimmenu_T * | |
3076 | 867 gui_ph_find_buffer_item(char_u *name) |
7 | 868 { |
869 vimmenu_T *top_level = root_menu; | |
870 vimmenu_T *items = NULL; | |
871 | |
3076 | 872 while (top_level != NULL && |
873 (STRCMP(top_level->dname, "Buffers") != 0)) | |
7 | 874 top_level = top_level->next; |
875 | |
3076 | 876 if (top_level != NULL) |
7 | 877 { |
878 items = top_level->children; | |
879 | |
3076 | 880 while (items != NULL && |
881 (STRCMP(items->dname, name) != 0)) | |
7 | 882 items = items->next; |
883 } | |
2980 | 884 return items; |
7 | 885 } |
886 | |
887 static void | |
3076 | 888 gui_ph_pg_set_buffer_num(int_u buf_num) |
7 | 889 { |
890 int i; | |
891 char search[16]; | |
892 char *mark; | |
893 | |
3076 | 894 if (gui.vimTextArea == NULL || buf_num == 0) |
7 | 895 return; |
896 | |
897 search[0] = '('; | |
3076 | 898 ultoa(buf_num, &search[1], 10); |
899 STRCAT(search, ")"); | |
900 | |
901 for (i = 0; i < num_panels; i++) | |
7 | 902 { |
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 */ | |
3076 | 905 mark = STRRCHR(panel_titles[ i ], '('); |
906 if (mark != NULL && STRCMP(mark, search) == 0) | |
7 | 907 { |
3076 | 908 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_CURRENT_INDEX, |
909 i, 0); | |
7 | 910 } |
911 } | |
912 } | |
913 | |
914 static int | |
915 gui_ph_handle_pg_change( | |
916 PtWidget_t *widget, | |
917 void *data, | |
3076 | 918 PtCallbackInfo_t *info) |
7 | 919 { |
920 vimmenu_T *menu; | |
921 PtPanelGroupCallback_t *panel; | |
922 | |
3076 | 923 if (info->event != NULL) |
7 | 924 { |
925 panel = info->cbdata; | |
3076 | 926 if (panel->new_panel != NULL) |
7 | 927 { |
3076 | 928 menu = gui_ph_find_buffer_item(panel->new_panel); |
929 if (menu) | |
930 gui_menu_cb(menu); | |
7 | 931 } |
932 } | |
2980 | 933 return Pt_CONTINUE; |
7 | 934 } |
935 | |
936 static void | |
937 gui_ph_get_panelgroup_margins( | |
938 short *top, | |
939 short *bottom, | |
940 short *left, | |
3076 | 941 short *right) |
7 | 942 { |
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 | |
3076 | 947 PtGetAbsPosition(gui.vimTextArea, &abs_raw_x, &abs_raw_y); |
948 PtGetAbsPosition(gui.vimPanelGroup, &abs_panel_x, &abs_panel_y); | |
949 | |
950 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_RIGHT, &margin_right, 0); | |
951 PtGetResource(gui.vimPanelGroup, Pt_ARG_MARGIN_BOTTOM, &margin_bottom, 0); | |
7 | 952 |
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 | |
3076 | 965 gui_ph_is_buffer_item(vimmenu_T *menu, vimmenu_T *parent) |
7 | 966 { |
967 char *mark; | |
968 | |
3076 | 969 if (STRCMP(parent->dname, "Buffers") == 0) |
7 | 970 { |
971 /* Look for '(' digits ')' */ | |
3076 | 972 mark = vim_strchr(menu->dname, '('); |
973 if (mark != NULL) | |
7 | 974 { |
975 mark++; | |
3076 | 976 while (isdigit(*mark)) |
7 | 977 mark++; |
978 | |
3076 | 979 if (*mark == ')') |
2980 | 980 return TRUE; |
7 | 981 } |
982 } | |
2980 | 983 return FALSE; |
7 | 984 } |
985 | |
986 static void | |
3076 | 987 gui_ph_pg_add_buffer(char *name) |
7 | 988 { |
989 char **new_titles = NULL; | |
990 | |
3076 | 991 new_titles = (char **) alloc((num_panels + 1) * sizeof(char **)); |
992 if (new_titles != NULL) | |
7 | 993 { |
3076 | 994 if (num_panels > 0) |
995 memcpy(new_titles, panel_titles, num_panels * sizeof(char **)); | |
7 | 996 |
997 new_titles[ num_panels++ ] = name; | |
998 | |
3076 | 999 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles, |
1000 num_panels); | |
1001 | |
1002 vim_free(panel_titles); | |
7 | 1003 panel_titles = new_titles; |
1004 } | |
1005 } | |
1006 | |
1007 static void | |
3076 | 1008 gui_ph_pg_remove_buffer(char *name) |
7 | 1009 { |
1010 int i; | |
1011 char **new_titles = NULL; | |
1012 | |
1013 /* If there is only 1 panel, we just use the temporary place holder */ | |
3076 | 1014 if (num_panels > 1) |
7 | 1015 { |
3076 | 1016 new_titles = (char **) alloc((num_panels - 1) * sizeof(char **)); |
1017 if (new_titles != NULL) | |
7 | 1018 { |
1019 char **s = new_titles; | |
1020 /* Copy all the titles except the one we're removing */ | |
3076 | 1021 for (i = 0; i < num_panels; i++) |
7 | 1022 { |
3076 | 1023 if (STRCMP(panel_titles[ i ], name) != 0) |
7 | 1024 { |
1025 *s++ = panel_titles[ i ]; | |
1026 } | |
1027 } | |
1028 num_panels--; | |
1029 | |
3076 | 1030 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, new_titles, |
1031 num_panels); | |
1032 | |
1033 vim_free(panel_titles); | |
7 | 1034 panel_titles = new_titles; |
1035 } | |
1036 } | |
1037 else | |
1038 { | |
1039 num_panels--; | |
3076 | 1040 PtSetResource(gui.vimPanelGroup, Pt_ARG_PG_PANEL_TITLES, &empty_title, |
1041 1); | |
1042 | |
1043 vim_free(panel_titles); | |
7 | 1044 panel_titles = NULL; |
1045 } | |
1046 } | |
1047 | |
1048 /* When a buffer item is deleted from the buffer menu */ | |
1049 static int | |
1050 gui_ph_handle_buffer_remove( | |
1051 PtWidget_t *widget, | |
1052 void *data, | |
3076 | 1053 PtCallbackInfo_t *info) |
7 | 1054 { |
1055 vimmenu_T *menu; | |
1056 | |
3076 | 1057 if (data != NULL) |
7 | 1058 { |
1059 menu = (vimmenu_T *) data; | |
3076 | 1060 gui_ph_pg_remove_buffer(menu->dname); |
7 | 1061 } |
1062 | |
2980 | 1063 return Pt_CONTINUE; |
7 | 1064 } |
1065 #endif | |
1066 | |
1067 static int | |
3076 | 1068 gui_ph_pane_resize(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 1069 { |
3076 | 1070 if (PtWidgetIsRealized(widget)) |
7 | 1071 { |
1072 is_ignore_draw = TRUE; | |
3076 | 1073 PtStartFlux(gui.vimContainer); |
1074 PtContainerHold(gui.vimContainer); | |
7 | 1075 } |
1076 | |
2980 | 1077 return Pt_CONTINUE; |
7 | 1078 } |
1079 | |
1080 /****************************************************************************/ | |
1081 | |
1082 #ifdef FEAT_MBYTE | |
1083 void | |
3076 | 1084 gui_ph_encoding_changed(int new_encoding) |
7 | 1085 { |
1086 /* Default encoding is latin1 */ | |
1087 char *charset = "latin1"; | |
1088 int i; | |
1089 | |
1090 struct { | |
1091 int encoding; | |
1092 char *name; | |
1093 } charsets[] = { | |
1094 { DBCS_JPN, "SHIFT_JIS" }, | |
1095 { DBCS_KOR, "csEUCKR" }, | |
1096 { DBCS_CHT, "big5" }, | |
1097 { DBCS_CHS, "gb" } | |
1098 }; | |
1099 | |
3076 | 1100 for (i = 0; i < ARRAY_LENGTH(charsets); i++) |
7 | 1101 { |
3076 | 1102 if (new_encoding == charsets[ i ].encoding) |
7 | 1103 charset = charsets[ i ].name; |
1104 } | |
1105 | |
3076 | 1106 charset_translate = PxTranslateSet(charset_translate, charset); |
7 | 1107 } |
1108 #endif | |
1109 | |
1110 /****************************************************************************/ | |
1111 /****************************************************************************/ | |
1112 | |
1113 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
1114 gui_mch_prepare(int *argc, char **argv) |
7 | 1115 { |
3076 | 1116 PtInit(NULL); |
7 | 1117 } |
1118 | |
1119 int | |
1120 gui_mch_init(void) | |
1121 { | |
1122 PtArg_t args[10]; | |
1123 int flags = 0, n = 0; | |
1124 | |
1214 | 1125 PhDim_t window_size = {100, 100}; /* Arbitrary values */ |
7 | 1126 PhPoint_t pos = {0, 0}; |
1127 | |
3076 | 1128 gui.event_buffer = (PhEvent_t *) alloc(EVENT_BUFFER_SIZE); |
1129 if (gui.event_buffer == NULL) | |
2980 | 1130 return FAIL; |
7 | 1131 |
1132 /* Get a translation so we can convert from ISO Latin-1 to UTF */ | |
3076 | 1133 charset_translate = PxTranslateSet(NULL, "latin1"); |
7 | 1134 |
1135 /* The +2 is for the 1 pixel dark line on each side */ | |
1136 gui.border_offset = gui.border_width = GUI_PH_MARGIN + 2; | |
1137 | |
1138 /* Handle close events ourselves */ | |
3076 | 1139 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE); |
1140 PtSetArg(&args[ n++ ], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, | |
1141 Ph_WM_CLOSE | Ph_WM_RESIZE | Ph_WM_FOCUS); | |
1142 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0); | |
1143 gui.vimWindow = PtCreateWidget(PtWindow, NULL, n, args); | |
1144 if (gui.vimWindow == NULL) | |
2980 | 1145 return FAIL; |
7 | 1146 |
3076 | 1147 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW, gui_ph_handle_window_cb, NULL); |
1148 PtAddCallback(gui.vimWindow, Pt_CB_WINDOW_OPENING, | |
1149 gui_ph_handle_window_open, NULL); | |
7 | 1150 |
1151 n = 0; | |
3076 | 1152 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_ALL, Pt_IS_ANCHORED); |
1153 PtSetArg(&args[ n++ ], Pt_ARG_DIM, &window_size, 0); | |
1154 PtSetArg(&args[ n++ ], Pt_ARG_POS, &pos, 0); | |
7 | 1155 |
1156 #ifdef USE_PANEL_GROUP | |
4352 | 1157 /* Put in a temporary place holder title */ |
3076 | 1158 PtSetArg(&args[ n++ ], Pt_ARG_PG_PANEL_TITLES, &empty_title, 1); |
1159 | |
1160 gui.vimPanelGroup = PtCreateWidget(PtPanelGroup, gui.vimWindow, n, args); | |
1161 if (gui.vimPanelGroup == NULL) | |
2980 | 1162 return FAIL; |
7 | 1163 |
3076 | 1164 PtAddCallback(gui.vimPanelGroup, Pt_CB_PG_PANEL_SWITCHING, |
1165 gui_ph_handle_pg_change, NULL); | |
7 | 1166 #else |
1167 /* Turn off all edge decorations */ | |
3076 | 1168 PtSetArg(&args[ n++ ], Pt_ARG_BASIC_FLAGS, Pt_FALSE, Pt_ALL); |
1169 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, 0, 0); | |
1170 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 0, 0); | |
1171 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 0, 0); | |
1172 PtSetArg(&args[ n++ ], Pt_ARG_CONTAINER_FLAGS, Pt_TRUE, Pt_AUTO_EXTENT); | |
1173 | |
1174 gui.vimContainer = PtCreateWidget(PtPane, gui.vimWindow, n, args); | |
1175 if (gui.vimContainer == NULL) | |
2980 | 1176 return FAIL; |
7 | 1177 |
3076 | 1178 PtAddCallback(gui.vimContainer, Pt_CB_RESIZE, gui_ph_pane_resize, NULL); |
7 | 1179 #endif |
1180 | |
1181 /* Size for the text area is set in gui_mch_set_text_area_pos */ | |
1182 n = 0; | |
1183 | |
3076 | 1184 PtSetArg(&args[ n++ ], Pt_ARG_RAW_DRAW_F, gui_ph_handle_raw_draw, 1); |
1185 PtSetArg(&args[ n++ ], Pt_ARG_BEVEL_WIDTH, GUI_PH_MARGIN, 0); | |
7 | 1186 /* |
1187 * Using focus render also causes the whole widget to be redrawn | |
1188 * whenever it changes focus, which is very annoying :p | |
1189 */ | |
3076 | 1190 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE, |
1191 Pt_GETS_FOCUS | Pt_HIGHLIGHTED); | |
7 | 1192 #ifndef FEAT_MOUSESHAPE |
3076 | 1193 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_TYPE, GUI_PH_MOUSE_TYPE, 0); |
1194 PtSetArg(&args[ n++ ], Pt_ARG_CURSOR_COLOR, gui_ph_mouse_color, 0); | |
7 | 1195 #endif |
1196 | |
3076 | 1197 gui.vimTextArea = PtCreateWidget(PtRaw, Pt_DFLT_PARENT, n, args); |
1198 if (gui.vimTextArea == NULL) | |
2980 | 1199 return FAIL; |
7 | 1200 |
1201 /* TODO: use PtAddEventHandlers instead? */ | |
1202 /* Not using Ph_EV_BUT_REPEAT because vim wouldn't use it anyway */ | |
3076 | 1203 PtAddEventHandler(gui.vimTextArea, |
7 | 1204 Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE | Ph_EV_PTR_MOTION_BUTTON, |
3076 | 1205 gui_ph_handle_mouse, NULL); |
1206 PtAddEventHandler(gui.vimTextArea, Ph_EV_KEY, | |
1207 gui_ph_handle_keyboard, NULL); | |
1208 PtAddCallback(gui.vimTextArea, Pt_CB_GOT_FOCUS, | |
1209 gui_ph_handle_focus, NULL); | |
1210 PtAddCallback(gui.vimTextArea, Pt_CB_LOST_FOCUS, | |
1211 gui_ph_handle_focus, NULL); | |
7 | 1212 |
1213 /* | |
1214 * Now that the text area widget has been created, set up the colours, | |
1215 * which wil call PtSetResource from gui_mch_new_colors | |
1216 */ | |
1217 | |
1218 /* | |
1219 * Create the two timers, not as accurate as using the kernel timer | |
1220 * functions, but good enough | |
1221 */ | |
3076 | 1222 gui_ph_timer_cursor = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL); |
1223 if (gui_ph_timer_cursor == NULL) | |
2980 | 1224 return FAIL; |
7 | 1225 |
3076 | 1226 gui_ph_timer_timeout = PtCreateWidget(PtTimer, gui.vimWindow, 0, NULL); |
1227 if (gui_ph_timer_timeout == NULL) | |
2980 | 1228 return FAIL; |
7 | 1229 |
3076 | 1230 PtAddCallback(gui_ph_timer_cursor, Pt_CB_TIMER_ACTIVATE, |
7 | 1231 gui_ph_handle_timer_cursor, NULL); |
3076 | 1232 PtAddCallback(gui_ph_timer_timeout, Pt_CB_TIMER_ACTIVATE, |
7 | 1233 gui_ph_handle_timer_timeout, NULL); |
1234 | |
1235 #ifdef FEAT_MENU | |
1236 n = 0; | |
3076 | 1237 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0); |
1238 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_ANCHOR_LEFT_RIGHT, | |
1239 Pt_IS_ANCHORED); | |
1240 gui.vimToolBarGroup = PtCreateWidget(PtToolbarGroup, gui.vimWindow, | |
1241 n, args); | |
1242 if (gui.vimToolBarGroup == NULL) | |
2980 | 1243 return FAIL; |
7 | 1244 |
3076 | 1245 PtAddCallback(gui.vimToolBarGroup, Pt_CB_RESIZE, |
1246 gui_ph_handle_menu_resize, NULL); | |
7 | 1247 |
1248 n = 0; | |
1249 flags = 0; | |
3076 | 1250 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0); |
1251 if (! vim_strchr(p_go, GO_MENUS)) | |
7 | 1252 { |
1253 flags |= Pt_DELAY_REALIZE; | |
3076 | 1254 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_TRUE, flags); |
7 | 1255 } |
3076 | 1256 gui.vimMenuBar = PtCreateWidget(PtMenuBar, gui.vimToolBarGroup, n, args); |
1257 if (gui.vimMenuBar == NULL) | |
2980 | 1258 return FAIL; |
7 | 1259 |
1260 # ifdef FEAT_TOOLBAR | |
1261 n = 0; | |
1262 | |
3076 | 1263 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, |
1264 Pt_ANCHOR_LEFT_RIGHT |Pt_TOP_ANCHORED_TOP, Pt_IS_ANCHORED); | |
1265 PtSetArg(&args[ n++ ], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, | |
1266 Pt_RESIZE_Y_AS_REQUIRED); | |
1267 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, window_size.w, 0); | |
7 | 1268 |
1269 flags = Pt_GETS_FOCUS; | |
3076 | 1270 if (! vim_strchr(p_go, GO_TOOLBAR)) |
7 | 1271 flags |= Pt_DELAY_REALIZE; |
1272 | |
3076 | 1273 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE, flags); |
1274 | |
1275 gui.vimToolBar = PtCreateWidget(PtToolbar, gui.vimToolBarGroup, n, args); | |
1276 if (gui.vimToolBar == NULL) | |
2980 | 1277 return FAIL; |
7 | 1278 |
1279 /* | |
1280 * Size for the toolbar is fetched in gui_mch_show_toolbar, after | |
1281 * the buttons have been added and the toolbar has resized it's height | |
1282 * for the buttons to fit | |
1283 */ | |
1284 # endif | |
1285 | |
1286 #endif | |
1287 | |
2980 | 1288 return OK; |
7 | 1289 } |
1290 | |
1291 int | |
1292 gui_mch_init_check(void) | |
1293 { | |
2980 | 1294 return (is_photon_available == TRUE) ? OK : FAIL; |
7 | 1295 } |
1296 | |
1297 int | |
1298 gui_mch_open(void) | |
1299 { | |
1300 gui.norm_pixel = Pg_BLACK; | |
1301 gui.back_pixel = Pg_WHITE; | |
1302 | |
1303 set_normal_colors(); | |
1304 | |
1305 gui_check_colors(); | |
1306 gui.def_norm_pixel = gui.norm_pixel; | |
1307 gui.def_back_pixel = gui.back_pixel; | |
1308 | |
1309 highlight_gui_started(); | |
1310 | |
1311 if (gui_win_x != -1 && gui_win_y != -1) | |
1312 gui_mch_set_winpos(gui_win_x, gui_win_y); | |
1313 | |
3076 | 1314 return (PtRealizeWidget(gui.vimWindow) == 0) ? OK : FAIL; |
7 | 1315 } |
1316 | |
1317 void | |
1318 gui_mch_exit(int rc) | |
1319 { | |
3076 | 1320 PtDestroyWidget(gui.vimWindow); |
1321 | |
1322 PxTranslateSet(charset_translate, NULL); | |
1323 | |
1324 vim_free(gui.event_buffer); | |
7 | 1325 |
1326 #ifdef USE_PANEL_GROUPS | |
3076 | 1327 vim_free(panel_titles); |
7 | 1328 #endif |
1329 } | |
1330 | |
1331 /****************************************************************************/ | |
1332 /* events */ | |
1333 | |
1334 /* When no events are available, photon will call this function, working is | |
1335 * set to FALSE, and the gui_mch_update loop will exit. */ | |
1336 static int | |
3076 | 1337 exit_gui_mch_update(void *data) |
7 | 1338 { |
1339 *(int *)data = FALSE; | |
2980 | 1340 return Pt_END; |
7 | 1341 } |
1342 | |
1343 void | |
1344 gui_mch_update(void) | |
1345 { | |
1346 int working = TRUE; | |
1347 | |
3076 | 1348 PtAppAddWorkProc(NULL, exit_gui_mch_update, &working); |
1349 while ((working == TRUE) && !vim_is_input_buf_full()) | |
7 | 1350 { |
1351 PtProcessEvent(); | |
1352 } | |
1353 } | |
1354 | |
1355 int | |
1356 gui_mch_wait_for_chars(int wtime) | |
1357 { | |
1358 is_timeout = FALSE; | |
1359 | |
3076 | 1360 if (wtime > 0) |
1361 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, wtime, 0); | |
1362 | |
1363 while (1) | |
7 | 1364 { |
1365 PtProcessEvent(); | |
3076 | 1366 if (input_available()) |
7 | 1367 { |
3076 | 1368 PtSetResource(gui_ph_timer_timeout, Pt_ARG_TIMER_INITIAL, 0, 0); |
2980 | 1369 return OK; |
7 | 1370 } |
3076 | 1371 else if (is_timeout == TRUE) |
2980 | 1372 return FAIL; |
7 | 1373 } |
1374 } | |
1375 | |
3076 | 1376 #if defined(FEAT_BROWSE) || defined(PROTO) |
7 | 1377 /* |
1378 * Put up a file requester. | |
1379 * Returns the selected name in allocated memory, or NULL for Cancel. | |
1380 * saving, select file to write | |
1381 * title title for the window | |
1382 * default_name default name (well duh!) | |
1383 * ext not used (extension added) | |
1384 * initdir initial directory, NULL for current dir | |
1385 * filter not used (file name filter) | |
1386 */ | |
1387 char_u * | |
1388 gui_mch_browse( | |
1389 int saving, | |
1390 char_u *title, | |
1391 char_u *default_name, | |
1392 char_u *ext, | |
1393 char_u *initdir, | |
1394 char_u *filter) | |
1395 { | |
1396 PtFileSelectionInfo_t file; | |
1397 int flags; | |
1398 char_u *default_path; | |
1399 char_u *open_text = NULL; | |
1400 | |
1401 flags = 0; | |
3076 | 1402 memset(&file, 0, sizeof(file)); |
1403 | |
1404 default_path = alloc(MAXPATHL + 1 + NAME_MAX + 1); | |
1405 if (default_path != NULL) | |
7 | 1406 { |
3076 | 1407 if (saving == TRUE) |
7 | 1408 { |
1409 /* Don't need Pt_FSR_CONFIRM_EXISTING, vim will ask anyway */ | |
1410 flags |= Pt_FSR_NO_FCHECK; | |
1411 open_text = "&Save"; | |
1412 } | |
1413 | |
1414 /* combine the directory and filename into a single path */ | |
3076 | 1415 if (initdir == NULL || *initdir == NUL) |
7 | 1416 { |
3076 | 1417 mch_dirname(default_path, MAXPATHL); |
7 | 1418 initdir = default_path; |
1419 } | |
1420 else | |
1421 { | |
3076 | 1422 STRCPY(default_path, initdir); |
7 | 1423 initdir = default_path; |
1424 } | |
1425 | |
3076 | 1426 if (default_name != NULL) |
7 | 1427 { |
3076 | 1428 if (default_path[ STRLEN(default_path) - 1 ] != '/') |
1429 STRCAT(default_path, "/"); | |
1430 | |
1431 STRCAT(default_path, default_name); | |
7 | 1432 } |
1433 | |
1434 /* TODO: add a filter? */ | |
1435 PtFileSelection( | |
1436 gui.vimWindow, | |
1437 NULL, | |
1438 title, | |
1439 default_path, | |
1440 NULL, | |
1441 open_text, | |
1442 NULL, | |
1443 NULL, | |
1444 &file, | |
3076 | 1445 flags); |
1446 | |
1447 vim_free(default_path); | |
1448 | |
1449 if (file.ret == Pt_FSDIALOG_BTN1) | |
2980 | 1450 return vim_strsave(file.path); |
7 | 1451 } |
2980 | 1452 return NULL; |
7 | 1453 } |
1454 #endif | |
1455 | |
3076 | 1456 #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
7 | 1457 static PtWidget_t *gui_ph_dialog_text = NULL; |
1458 | |
1459 static int | |
3076 | 1460 gui_ph_dialog_close(int button, void *data) |
7 | 1461 { |
1462 PtModalCtrl_t *modal_ctrl = data; | |
1463 char_u *dialog_text, *vim_text; | |
1464 | |
3076 | 1465 if (gui_ph_dialog_text != NULL) |
7 | 1466 { |
3076 | 1467 PtGetResource(gui_ph_dialog_text, Pt_ARG_TEXT_STRING, &dialog_text, 0); |
1468 PtGetResource(gui_ph_dialog_text, Pt_ARG_POINTER, &vim_text, 0); | |
1469 STRNCPY(vim_text, dialog_text, IOSIZE - 1); | |
7 | 1470 } |
1471 | |
3076 | 1472 PtModalUnblock(modal_ctrl, (void *) button); |
7 | 1473 |
2980 | 1474 return Pt_TRUE; |
7 | 1475 } |
1476 | |
1477 static int | |
3076 | 1478 gui_ph_dialog_text_enter(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 1479 { |
3076 | 1480 if (info->reason_subtype == Pt_EDIT_ACTIVATE) |
1481 gui_ph_dialog_close(1, data); | |
2980 | 1482 return Pt_CONTINUE; |
7 | 1483 } |
1484 | |
1485 static int | |
3076 | 1486 gui_ph_dialog_esc(PtWidget_t *widget, void *data, PtCallbackInfo_t *info) |
7 | 1487 { |
1488 PhKeyEvent_t *key; | |
1489 | |
3076 | 1490 key = PhGetData(info->event); |
1491 if ((key->key_flags & Pk_KF_Cap_Valid) && (key->key_cap == Pk_Escape)) | |
7 | 1492 { |
3076 | 1493 gui_ph_dialog_close(0, data); |
2980 | 1494 return Pt_CONSUME; |
7 | 1495 } |
2980 | 1496 return Pt_PROCESS; |
7 | 1497 } |
1498 | |
1499 int | |
1500 gui_mch_dialog( | |
1501 int type, | |
1502 char_u *title, | |
1503 char_u *message, | |
1504 char_u *buttons, | |
1505 int default_button, | |
2684 | 1506 char_u *textfield, |
1507 int ex_cmd) | |
7 | 1508 { |
1509 char_u *str; | |
1510 char_u **button_array; | |
1511 char_u *buttons_copy; | |
1512 | |
1513 int button_count; | |
1514 int i, len; | |
1515 int dialog_result = -1; | |
1516 | |
1517 /* FIXME: the vertical option in guioptions is blatantly ignored */ | |
1518 /* FIXME: so is the type */ | |
1519 | |
1520 button_count = len = i = 0; | |
1521 | |
3076 | 1522 if (buttons == NULL || *buttons == NUL) |
2980 | 1523 return -1; |
7 | 1524 |
1525 /* There is one less separator than buttons, so bump up the button count */ | |
1526 button_count = 1; | |
1527 | |
4352 | 1528 /* Count string length and number of separators */ |
3076 | 1529 for (str = buttons; *str; str++) |
7 | 1530 { |
1531 len++; | |
3076 | 1532 if (*str == DLG_BUTTON_SEP) |
7 | 1533 button_count++; |
1534 } | |
1535 | |
3076 | 1536 if (title == NULL) |
7 | 1537 title = "Vim"; |
1538 | |
3076 | 1539 buttons_copy = alloc(len + 1); |
1540 button_array = (char_u **) alloc(button_count * sizeof(char_u *)); | |
1541 if (buttons_copy != NULL && button_array != NULL) | |
7 | 1542 { |
3076 | 1543 STRCPY(buttons_copy, buttons); |
7 | 1544 |
1545 /* | |
1546 * Convert DLG_BUTTON_SEP into NUL's and fill in | |
1547 * button_array with the pointer to each NUL terminated string | |
1548 */ | |
1549 str = buttons_copy; | |
3076 | 1550 for (i = 0; i < button_count; i++) |
7 | 1551 { |
1552 button_array[ i ] = str; | |
3076 | 1553 for (; *str; str++) |
7 | 1554 { |
3076 | 1555 if (*str == DLG_BUTTON_SEP) |
7 | 1556 { |
1557 *str++ = NUL; | |
1558 break; | |
1559 } | |
1560 } | |
1561 } | |
1562 #ifndef FEAT_GUI_TEXTDIALOG | |
1563 dialog_result = PtAlert( | |
1564 gui.vimWindow, NULL, | |
1565 title, | |
1566 NULL, | |
1567 message, NULL, | |
1568 button_count, (const char **) button_array, NULL, | |
3076 | 1569 default_button, 0, Pt_MODAL); |
7 | 1570 #else |
1571 /* Writing the dialog ourselves lets us add extra features, like | |
1572 * trapping the escape key and returning 0 to vim */ | |
1573 { | |
1574 int n; | |
1575 PtArg_t args[5]; | |
1576 PtWidget_t *dialog, *pane; | |
1577 PtModalCtrl_t modal_ctrl; | |
1578 PtDialogInfo_t di; | |
1579 | |
3076 | 1580 memset(&di, 0, sizeof(di)); |
1581 memset(&modal_ctrl, 0, sizeof(modal_ctrl)); | |
7 | 1582 |
1583 n = 0; | |
3076 | 1584 PtSetArg(&args[n++], Pt_ARG_GROUP_ROWS_COLS, 0, 0); |
1585 PtSetArg(&args[n++], Pt_ARG_WIDTH, 350, 0); | |
1586 PtSetArg(&args[n++], Pt_ARG_GROUP_ORIENTATION, | |
1587 Pt_GROUP_VERTICAL, 0); | |
1588 PtSetArg(&args[n++], Pt_ARG_GROUP_FLAGS, | |
1589 Pt_TRUE, Pt_GROUP_NO_KEYS | Pt_GROUP_STRETCH_HORIZONTAL); | |
1590 PtSetArg(&args[n++], Pt_ARG_CONTAINER_FLAGS, Pt_FALSE, Pt_TRUE); | |
1591 pane = PtCreateWidget(PtGroup, NULL, n, args); | |
7 | 1592 |
1593 n = 0; | |
3076 | 1594 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, message, 0); |
1595 PtCreateWidget(PtLabel, pane, n, args); | |
1596 | |
1597 if (textfield != NULL) | |
7 | 1598 { |
1599 n = 0; | |
3076 | 1600 PtSetArg(&args[n++], Pt_ARG_MAX_LENGTH, IOSIZE - 1, 0); |
1601 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, textfield, 0); | |
1602 PtSetArg(&args[n++], Pt_ARG_POINTER, textfield, 0); | |
1603 gui_ph_dialog_text = PtCreateWidget(PtText, pane, n, args); | |
1604 PtAddCallback(gui_ph_dialog_text, Pt_CB_ACTIVATE, | |
1605 gui_ph_dialog_text_enter, &modal_ctrl); | |
7 | 1606 } |
1607 | |
1608 di.parent = gui.vimWindow; | |
1609 di.pane = pane; | |
1610 di.title = title; | |
1611 di.buttons = (const char **) button_array; | |
1612 di.nbtns = button_count; | |
1613 di.def_btn = default_button; | |
1614 /* This is just to give the dialog the close button. | |
1615 * We check for the Escape key ourselves and return 0 */ | |
1616 di.esc_btn = button_count; | |
1617 di.callback = gui_ph_dialog_close; | |
1618 di.data = &modal_ctrl; | |
1619 | |
3076 | 1620 dialog = PtCreateDialog(&di); |
1621 PtAddFilterCallback(dialog, Ph_EV_KEY, | |
1622 gui_ph_dialog_esc, &modal_ctrl); | |
1623 | |
1624 if (gui_ph_dialog_text != NULL) | |
1625 PtGiveFocus(gui_ph_dialog_text, NULL); | |
7 | 1626 |
1627 /* Open dialog, block the vim window and wait for the dialog to close */ | |
3076 | 1628 PtRealizeWidget(dialog); |
1629 PtMakeModal(dialog, Ph_CURSOR_NOINPUT, Ph_CURSOR_DEFAULT_COLOR); | |
1630 dialog_result = (int) PtModalBlock(&modal_ctrl, 0); | |
1631 | |
1632 PtDestroyWidget(dialog); | |
7 | 1633 gui_ph_dialog_text = NULL; |
1634 } | |
1635 #endif | |
1636 } | |
1637 | |
3076 | 1638 vim_free(button_array); |
1639 vim_free(buttons_copy); | |
7 | 1640 |
2980 | 1641 return dialog_result; |
7 | 1642 } |
1643 #endif | |
1644 /****************************************************************************/ | |
1645 /* window size/position/state */ | |
1646 | |
1647 int | |
1648 gui_mch_get_winpos(int *x, int *y) | |
1649 { | |
1650 PhPoint_t *pos; | |
1651 | |
3076 | 1652 pos = PtWidgetPos(gui.vimWindow, NULL); |
7 | 1653 |
1654 *x = pos->x; | |
1655 *y = pos->y; | |
1656 | |
2980 | 1657 return OK; |
7 | 1658 } |
1659 | |
1660 void | |
1661 gui_mch_set_winpos(int x, int y) | |
1662 { | |
1663 PhPoint_t pos = { x, y }; | |
1664 | |
3076 | 1665 PtSetResource(gui.vimWindow, Pt_ARG_POS, &pos, 0); |
7 | 1666 } |
1667 | |
1668 void | |
1669 gui_mch_set_shellsize(int width, int height, | |
812 | 1670 int min_width, int min_height, int base_width, int base_height, |
1671 int direction) | |
7 | 1672 { |
1673 PhDim_t window_size = { width, height }; | |
1674 PhDim_t min_size = { min_width, min_height }; | |
1675 | |
1676 #ifdef USE_PANEL_GROUP | |
1677 window_size.w += pg_margin_left + pg_margin_right; | |
1678 window_size.h += pg_margin_top + pg_margin_bottom; | |
1679 #endif | |
1680 | |
3076 | 1681 PtSetResource(gui.vimWindow, Pt_ARG_MINIMUM_DIM, &min_size, 0); |
1682 PtSetResource(gui.vimWindow, Pt_ARG_DIM, &window_size, 0); | |
1683 | |
1684 if (! PtWidgetIsRealized(gui.vimWindow)) | |
7 | 1685 gui_ph_resize_container(); |
1686 } | |
1687 | |
1688 /* | |
1689 * Return the amount of screen space that hasn't been allocated (such as | |
1690 * by the shelf). | |
1691 */ | |
1692 void | |
1693 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
1694 { | |
1695 PhRect_t console; | |
1696 | |
3076 | 1697 PhWindowQueryVisible(Ph_QUERY_WORKSPACE, 0, |
1698 PhInputGroup(NULL), &console); | |
7 | 1699 |
1700 *screen_w = console.lr.x - console.ul.x + 1; | |
1701 *screen_h = console.lr.y - console.ul.y + 1; | |
1702 } | |
1703 | |
1704 void | |
1705 gui_mch_iconify(void) | |
1706 { | |
1707 PhWindowEvent_t event; | |
1708 | |
3076 | 1709 memset(&event, 0, sizeof (event)); |
7 | 1710 event.event_f = Ph_WM_HIDE; |
1711 event.event_state = Ph_WM_EVSTATE_HIDE; | |
3076 | 1712 event.rid = PtWidgetRid(gui.vimWindow); |
1713 PtForwardWindowEvent(&event); | |
7 | 1714 } |
1715 | |
1716 #if defined(FEAT_EVAL) || defined(PROTO) | |
1717 /* | |
1718 * Bring the Vim window to the foreground. | |
1719 */ | |
1720 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
1721 gui_mch_set_foreground(void) |
7 | 1722 { |
1723 PhWindowEvent_t event; | |
1724 | |
3076 | 1725 memset(&event, 0, sizeof (event)); |
7 | 1726 event.event_f = Ph_WM_TOFRONT; |
1727 event.event_state = Ph_WM_EVSTATE_FFRONT; | |
3076 | 1728 event.rid = PtWidgetRid(gui.vimWindow); |
1729 PtForwardWindowEvent(&event); | |
7 | 1730 } |
1731 #endif | |
1732 | |
1733 void | |
1734 gui_mch_settitle(char_u *title, char_u *icon) | |
1735 { | |
1736 #ifdef USE_PANEL_GROUP | |
3076 | 1737 gui_ph_pg_set_buffer_num(curwin->w_buffer->b_fnum); |
7 | 1738 #endif |
3076 | 1739 PtSetResource(gui.vimWindow, Pt_ARG_WINDOW_TITLE, title, 0); |
7 | 1740 /* Not sure what to do with the icon text, set balloon text somehow? */ |
1741 } | |
1742 | |
1743 /****************************************************************************/ | |
1744 /* Scrollbar */ | |
1745 | |
1746 void | |
1747 gui_mch_set_scrollbar_thumb(scrollbar_T *sb, int val, int size, int max) | |
1748 { | |
1749 int n = 0; | |
1750 PtArg_t args[3]; | |
1751 | |
3076 | 1752 PtSetArg(&args[ n++ ], Pt_ARG_MAXIMUM, max, 0); |
1753 PtSetArg(&args[ n++ ], Pt_ARG_SLIDER_SIZE, size, 0); | |
1754 PtSetArg(&args[ n++ ], Pt_ARG_GAUGE_VALUE, val, 0); | |
1755 PtSetResources(sb->id, n, args); | |
7 | 1756 } |
1757 | |
1758 void | |
1759 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h) | |
1760 { | |
1761 PhArea_t area = {{ x, y }, { w, h }}; | |
1762 | |
3076 | 1763 PtSetResource(sb->id, Pt_ARG_AREA, &area, 0); |
7 | 1764 } |
1765 | |
1766 void | |
1767 gui_mch_create_scrollbar(scrollbar_T *sb, int orient) | |
1768 { | |
1769 int n = 0; | |
1770 /* int anchor_flags = 0;*/ | |
1771 PtArg_t args[4]; | |
1772 | |
1773 /* | |
1774 * Stop the scrollbar from being realized when the parent | |
1775 * is realized, so it can be explicitly realized by vim. | |
1776 * | |
1777 * Also, don't let the scrollbar get focus | |
1778 */ | |
3076 | 1779 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_DELAY_REALIZE, |
1780 Pt_DELAY_REALIZE | Pt_GETS_FOCUS); | |
1781 PtSetArg(&args[ n++ ], Pt_ARG_SCROLLBAR_FLAGS, Pt_SCROLLBAR_SHOW_ARROWS, 0); | |
7 | 1782 #if 0 |
1783 /* Don't need this anchoring for the scrollbars */ | |
3076 | 1784 if (orient == SBAR_HORIZ) |
7 | 1785 { |
1786 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM | | |
1787 Pt_LEFT_ANCHORED_LEFT | Pt_RIGHT_ANCHORED_RIGHT; | |
1788 } | |
1789 else | |
1790 { | |
1791 anchor_flags = Pt_BOTTOM_ANCHORED_BOTTOM | Pt_TOP_ANCHORED_TOP; | |
3076 | 1792 if (sb->wp != NULL) |
7 | 1793 { |
3076 | 1794 if (sb == &sb->wp->w_scrollbars[ SBAR_LEFT ]) |
7 | 1795 anchor_flags |= Pt_LEFT_ANCHORED_LEFT; |
1796 else | |
1797 anchor_flags |= Pt_RIGHT_ANCHORED_RIGHT; | |
1798 } | |
1799 } | |
3076 | 1800 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, anchor_flags, Pt_IS_ANCHORED); |
7 | 1801 #endif |
3076 | 1802 PtSetArg(&args[ n++ ], Pt_ARG_ORIENTATION, |
1803 (orient == SBAR_HORIZ) ? Pt_HORIZONTAL : Pt_VERTICAL, 0); | |
7 | 1804 #ifdef USE_PANEL_GROUP |
3076 | 1805 sb->id = PtCreateWidget(PtScrollbar, gui.vimPanelGroup, n, args); |
7 | 1806 #else |
3076 | 1807 sb->id = PtCreateWidget(PtScrollbar, gui.vimContainer, n, args); |
7 | 1808 #endif |
1809 | |
3076 | 1810 PtAddCallback(sb->id, Pt_CB_SCROLLBAR_MOVE, gui_ph_handle_scrollbar, sb); |
7 | 1811 } |
1812 | |
1813 void | |
1814 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
1815 { | |
3076 | 1816 if (flag != 0) |
1817 PtRealizeWidget(sb->id); | |
7 | 1818 else |
3076 | 1819 PtUnrealizeWidget(sb->id); |
7 | 1820 } |
1821 | |
1822 void | |
1823 gui_mch_destroy_scrollbar(scrollbar_T *sb) | |
1824 { | |
3076 | 1825 PtDestroyWidget(sb->id); |
7 | 1826 sb->id = NULL; |
1827 } | |
1828 | |
1829 /****************************************************************************/ | |
1830 /* Mouse functions */ | |
1831 | |
1832 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
1833 /* The last set mouse pointer shape is remembered, to be used when it goes | |
1834 * from hidden to not hidden. */ | |
1835 static int last_shape = 0; | |
1836 | |
1837 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
1838 * misc2.c! */ | |
1839 static int mshape_ids[] = | |
1840 { | |
1841 Ph_CURSOR_POINTER, /* arrow */ | |
1842 Ph_CURSOR_NONE, /* blank */ | |
1843 Ph_CURSOR_INSERT, /* beam */ | |
1844 Ph_CURSOR_DRAG_VERTICAL, /* updown */ | |
1845 Ph_CURSOR_DRAG_VERTICAL, /* udsizing */ | |
1846 Ph_CURSOR_DRAG_HORIZONTAL, /* leftright */ | |
1847 Ph_CURSOR_DRAG_HORIZONTAL, /* lrsizing */ | |
1848 Ph_CURSOR_WAIT, /* busy */ | |
1849 Ph_CURSOR_DONT, /* no */ | |
1850 Ph_CURSOR_CROSSHAIR, /* crosshair */ | |
1851 Ph_CURSOR_FINGER, /* hand1 */ | |
1852 Ph_CURSOR_FINGER, /* hand2 */ | |
1853 Ph_CURSOR_FINGER, /* pencil */ | |
1854 Ph_CURSOR_QUESTION_POINT, /* question */ | |
1855 Ph_CURSOR_POINTER, /* right-arrow */ | |
1856 Ph_CURSOR_POINTER, /* up-arrow */ | |
1857 Ph_CURSOR_POINTER /* last one */ | |
1858 }; | |
1859 | |
1860 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
1861 mch_set_mouse_shape(int shape) |
7 | 1862 { |
1863 int id; | |
1864 | |
1865 if (!gui.in_use) | |
1866 return; | |
1867 | |
1868 if (shape == MSHAPE_HIDE || gui.pointer_hidden) | |
3076 | 1869 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, |
1870 0); | |
7 | 1871 else |
1872 { | |
1873 if (shape >= MSHAPE_NUMBERED) | |
1874 id = Ph_CURSOR_POINTER; | |
1875 else | |
1876 id = mshape_ids[shape]; | |
1877 | |
3076 | 1878 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, id, 0); |
7 | 1879 } |
1880 if (shape != MSHAPE_HIDE) | |
1881 last_shape = shape; | |
1882 } | |
1883 #endif | |
1884 | |
1885 void | |
1886 gui_mch_mousehide(int hide) | |
1887 { | |
3076 | 1888 if (gui.pointer_hidden != hide) |
7 | 1889 { |
1890 gui.pointer_hidden = hide; | |
1891 #ifdef FEAT_MOUSESHAPE | |
3076 | 1892 if (hide) |
1893 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, | |
1894 Ph_CURSOR_NONE, 0); | |
7 | 1895 else |
3076 | 1896 mch_set_mouse_shape(last_shape); |
7 | 1897 #else |
3076 | 1898 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_TYPE, |
1899 (hide == MOUSE_SHOW) ? GUI_PH_MOUSE_TYPE : Ph_CURSOR_NONE, | |
1900 0); | |
7 | 1901 #endif |
1902 } | |
1903 } | |
1904 | |
95 | 1905 void |
87 | 1906 gui_mch_getmouse(int *x, int *y) |
7 | 1907 { |
1908 PhCursorInfo_t info; | |
87 | 1909 short ix, iy; |
7 | 1910 |
1911 /* FIXME: does this return the correct position, | |
1912 * with respect to the border? */ | |
3076 | 1913 PhQueryCursor(PhInputGroup(NULL), &info); |
1914 PtGetAbsPosition(gui.vimTextArea , &ix, &iy); | |
87 | 1915 |
1916 *x = info.pos.x - ix; | |
1917 *y = info.pos.y - iy; | |
7 | 1918 } |
1919 | |
1920 void | |
1921 gui_mch_setmouse(int x, int y) | |
1922 { | |
1923 short abs_x, abs_y; | |
1924 | |
3076 | 1925 PtGetAbsPosition(gui.vimTextArea, &abs_x, &abs_y); |
7 | 1926 /* Add the border offset? */ |
3076 | 1927 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + x, abs_y + y); |
7 | 1928 } |
1929 | |
1930 /****************************************************************************/ | |
1931 /* Colours */ | |
1932 | |
1933 /* | |
1934 * Return the RGB value of a pixel as a long. | |
1935 */ | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
1936 guicolor_T |
7 | 1937 gui_mch_get_rgb(guicolor_T pixel) |
1938 { | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
1939 return (guicolor_T)(PgRGB(PgRedValue(pixel), |
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9428
diff
changeset
|
1940 PgGreenValue(pixel), PgBlueValue(pixel))); |
7 | 1941 } |
1942 | |
1943 void | |
1944 gui_mch_new_colors(void) | |
1945 { | |
1946 #if 0 /* Don't bother changing the cursor colour */ | |
1947 short color_diff; | |
1948 | |
1949 /* | |
1950 * If there isn't enough difference between the background colour and | |
1951 * the mouse pointer colour then change the mouse pointer colour | |
1952 */ | |
1953 color_diff = gui_get_lightness(gui_ph_mouse_color) | |
1954 - gui_get_lightness(gui.back_pixel); | |
1955 | |
3076 | 1956 if (abs(color_diff) < 64) |
7 | 1957 { |
1958 short r, g, b; | |
1959 /* not a great algorithm... */ | |
3076 | 1960 r = PgRedValue(gui_ph_mouse_color) ^ 255; |
1961 g = PgGreenValue(gui_ph_mouse_color) ^ 255; | |
1962 b = PgBlueValue(gui_ph_mouse_color) ^ 255; | |
7 | 1963 |
1964 #ifndef FEAT_MOUSESHAPE | |
3076 | 1965 gui_ph_mouse_color = PgRGB(r, g, b); |
1966 PtSetResource(gui.vimTextArea, Pt_ARG_CURSOR_COLOR, | |
1967 gui_ph_mouse_color, 0); | |
7 | 1968 #endif |
1969 } | |
1970 #endif | |
1971 | |
3076 | 1972 PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0); |
7 | 1973 } |
1974 | |
1975 /* | |
1214 | 1976 * This should be split out into a separate file, |
7 | 1977 * every port does basically the same thing. |
1978 * | |
1979 * This is the gui_w32.c version (i think..) | |
1980 * Return INVALCOLOR when failed. | |
1981 */ | |
1982 | |
1983 guicolor_T | |
1984 gui_mch_get_color(char_u *name) | |
1985 { | |
9013
22c29a515b53
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1986 return gui_get_color_cmn(name); |
7 | 1987 } |
1988 | |
1989 void | |
1990 gui_mch_set_fg_color(guicolor_T color) | |
1991 { | |
3076 | 1992 PgSetTextColor(color); |
7 | 1993 } |
1994 | |
1995 void | |
1996 gui_mch_set_bg_color(guicolor_T color) | |
1997 { | |
3076 | 1998 PgSetFillColor(color); |
7 | 1999 } |
2000 | |
2001 void | |
205 | 2002 gui_mch_set_sp_color(guicolor_T color) |
2003 { | |
2004 } | |
2005 | |
2006 void | |
7 | 2007 gui_mch_invert_rectangle(int row, int col, int nr, int nc) |
2008 { | |
2009 PhRect_t rect; | |
2010 | |
3076 | 2011 rect.ul.x = FILL_X(col); |
2012 rect.ul.y = FILL_Y(row); | |
7 | 2013 |
2014 /* FIXME: This has an off by one pixel problem */ | |
2015 rect.lr.x = rect.ul.x + nc * gui.char_width; | |
2016 rect.lr.y = rect.ul.y + nr * gui.char_height; | |
3076 | 2017 if (nc > 0) |
7 | 2018 rect.lr.x -= 1; |
3076 | 2019 if (nr > 0) |
7 | 2020 rect.lr.y -= 1; |
2021 | |
2022 DRAW_START; | |
3076 | 2023 PgSetDrawMode(Pg_DrawModeDSTINVERT); |
2024 PgDrawRect(&rect, Pg_DRAW_FILL); | |
2025 PgSetDrawMode(Pg_DrawModeSRCCOPY); | |
7 | 2026 DRAW_END; |
2027 } | |
2028 | |
2029 void | |
2030 gui_mch_clear_block(int row1, int col1, int row2, int col2) | |
2031 { | |
2032 PhRect_t block = { | |
3076 | 2033 { FILL_X(col1), FILL_Y(row1) }, |
2034 { FILL_X(col2 + 1) - 1, FILL_Y(row2 + 1) - 1} | |
7 | 2035 }; |
2036 | |
2037 DRAW_START; | |
3076 | 2038 gui_mch_set_bg_color(gui.back_pixel); |
2039 PgDrawRect(&block, Pg_DRAW_FILL); | |
7 | 2040 DRAW_END; |
2041 } | |
2042 | |
2043 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
2044 gui_mch_clear_all(void) |
7 | 2045 { |
2046 PhRect_t text_rect = { | |
2047 { gui.border_width, gui.border_width }, | |
2048 { Columns * gui.char_width + gui.border_width - 1 , | |
2049 Rows * gui.char_height + gui.border_width - 1 } | |
2050 }; | |
2051 | |
3076 | 2052 if (is_ignore_draw == TRUE) |
7 | 2053 return; |
2054 | |
2055 DRAW_START; | |
3076 | 2056 gui_mch_set_bg_color(gui.back_pixel); |
2057 PgDrawRect(&text_rect, Pg_DRAW_FILL); | |
7 | 2058 DRAW_END; |
2059 } | |
2060 | |
2061 void | |
2062 gui_mch_delete_lines(int row, int num_lines) | |
2063 { | |
2064 PhRect_t rect; | |
2065 PhPoint_t delta; | |
2066 | |
3076 | 2067 rect.ul.x = FILL_X(gui.scroll_region_left); |
2068 rect.ul.y = FILL_Y(row + num_lines); | |
2069 | |
2070 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1; | |
2071 rect.lr.y = FILL_Y(gui.scroll_region_bot + 1) - 1; | |
2072 | |
2073 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset); | |
2074 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL)); | |
2075 PhTranslateRect(&rect, &gui_ph_raw_offset); | |
7 | 2076 |
2077 delta.x = 0; | |
2078 delta.y = -num_lines * gui.char_height; | |
2079 | |
2080 PgFlush(); | |
2081 | |
3076 | 2082 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)), &rect, &delta); |
7 | 2083 |
2084 gui_clear_block( | |
2085 gui.scroll_region_bot - num_lines + 1, | |
2086 gui.scroll_region_left, | |
2087 gui.scroll_region_bot, | |
3076 | 2088 gui.scroll_region_right); |
7 | 2089 } |
2090 | |
2091 void | |
2092 gui_mch_insert_lines(int row, int num_lines) | |
2093 { | |
2094 PhRect_t rect; | |
2095 PhPoint_t delta; | |
2096 | |
3076 | 2097 rect.ul.x = FILL_X(gui.scroll_region_left); |
2098 rect.ul.y = FILL_Y(row); | |
2099 | |
2100 rect.lr.x = FILL_X(gui.scroll_region_right + 1) - 1; | |
2101 rect.lr.y = FILL_Y(gui.scroll_region_bot - num_lines + 1) - 1; | |
2102 | |
2103 PtWidgetOffset(gui.vimTextArea, &gui_ph_raw_offset); | |
2104 PhTranslatePoint(&gui_ph_raw_offset, PtWidgetPos(gui.vimTextArea, NULL)); | |
2105 PhTranslateRect(&rect, &gui_ph_raw_offset); | |
7 | 2106 |
2107 delta.x = 0; | |
2108 delta.y = num_lines * gui.char_height; | |
2109 | |
2110 PgFlush(); | |
2111 | |
3076 | 2112 PhBlit(PtWidgetRid(PtFindDisjoint(gui.vimTextArea)) , &rect, &delta); |
2113 | |
2114 gui_clear_block(row, gui.scroll_region_left, | |
2115 row + num_lines - 1, gui.scroll_region_right); | |
7 | 2116 } |
2117 | |
2118 void | |
2119 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags) | |
2120 { | |
2121 static char *utf8_buffer = NULL; | |
2122 static int utf8_len = 0; | |
2123 | |
3076 | 2124 PhPoint_t pos = { TEXT_X(col), TEXT_Y(row) }; |
7 | 2125 PhRect_t rect; |
2126 | |
3076 | 2127 if (is_ignore_draw == TRUE) |
7 | 2128 return; |
2129 | |
2130 DRAW_START; | |
2131 | |
3076 | 2132 if (!(flags & DRAW_TRANSP)) |
7 | 2133 { |
2134 PgDrawIRect( | |
3076 | 2135 FILL_X(col), FILL_Y(row), |
2136 FILL_X(col + len) - 1, FILL_Y(row + 1) - 1, | |
2137 Pg_DRAW_FILL); | |
7 | 2138 } |
2139 | |
3076 | 2140 if (flags & DRAW_UNDERL) |
2141 PgSetUnderline(gui.norm_pixel, Pg_TRANSPARENT, 0); | |
2142 | |
2143 if (charset_translate != NULL | |
7 | 2144 #ifdef FEAT_MBYTE |
2145 && enc_utf8 == 0 | |
2146 #endif | |
3076 | 2147 ) |
7 | 2148 { |
2149 int src_taken, dst_made; | |
2150 | |
2151 /* Use a static buffer to avoid large amounts of de/allocations */ | |
3076 | 2152 if (utf8_len < len) |
7 | 2153 { |
3076 | 2154 utf8_buffer = realloc(utf8_buffer, len * MB_LEN_MAX); |
7 | 2155 utf8_len = len; |
2156 } | |
2157 | |
2158 PxTranslateToUTF( | |
2159 charset_translate, | |
2160 s, | |
2161 len, | |
2162 &src_taken, | |
2163 utf8_buffer, | |
2164 utf8_len, | |
3076 | 2165 &dst_made); |
7 | 2166 s = utf8_buffer; |
2167 len = dst_made; | |
2168 } | |
2169 | |
3076 | 2170 PgDrawText(s, len, &pos, 0); |
2171 | |
2172 if (flags & DRAW_BOLD) | |
7 | 2173 { |
2174 /* FIXME: try and only calculate these values once... */ | |
3076 | 2175 rect.ul.x = FILL_X(col) + 1; |
2176 rect.ul.y = FILL_Y(row); | |
2177 rect.lr.x = FILL_X(col + len) - 1; | |
2178 rect.lr.y = FILL_Y(row + 1) - 1; | |
2179 /* PgSetUserClip(NULL) causes the scrollbar to not redraw... */ | |
7 | 2180 #if 0 |
2181 pos.x++; | |
2182 | |
3076 | 2183 PgSetUserClip(&rect); |
2184 PgDrawText(s, len, &pos, 0); | |
2185 PgSetUserClip(NULL); | |
7 | 2186 #else |
3076 | 2187 rect.lr.y -= (p_linespace + 1) / 2; |
7 | 2188 /* XXX: DrawTextArea doesn't work with phditto */ |
3076 | 2189 PgDrawTextArea(s, len, &rect, Pg_TEXT_BOTTOM); |
7 | 2190 #endif |
2191 } | |
2192 | |
3076 | 2193 if (flags & DRAW_UNDERL) |
2194 PgSetUnderline(Pg_TRANSPARENT, Pg_TRANSPARENT, 0); | |
7 | 2195 |
2196 DRAW_END; | |
2197 } | |
2198 | |
2199 /****************************************************************************/ | |
2200 /* Cursor */ | |
2201 | |
2202 void | |
2203 gui_mch_draw_hollow_cursor(guicolor_T color) | |
2204 { | |
2205 PhRect_t r; | |
2206 | |
2207 /* FIXME: Double width characters */ | |
2208 | |
3076 | 2209 r.ul.x = FILL_X(gui.col); |
2210 r.ul.y = FILL_Y(gui.row); | |
7 | 2211 r.lr.x = r.ul.x + gui.char_width - 1; |
2212 r.lr.y = r.ul.y + gui.char_height - 1; | |
2213 | |
2214 DRAW_START; | |
3076 | 2215 PgSetStrokeColor(color); |
2216 PgDrawRect(&r, Pg_DRAW_STROKE); | |
7 | 2217 DRAW_END; |
2218 } | |
2219 | |
2220 void | |
2221 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
2222 { | |
2223 PhRect_t r; | |
2224 | |
3076 | 2225 r.ul.x = FILL_X(gui.col); |
2226 r.ul.y = FILL_Y(gui.row) + gui.char_height - h; | |
7 | 2227 r.lr.x = r.ul.x + w - 1; |
2228 r.lr.y = r.ul.y + h - 1; | |
2229 | |
2230 DRAW_START; | |
3076 | 2231 gui_mch_set_bg_color(color); |
2232 PgDrawRect(&r, Pg_DRAW_FILL); | |
7 | 2233 DRAW_END; |
2234 } | |
2235 | |
9213
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2236 int |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2237 gui_mch_is_blinking(void) |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2238 { |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2239 return blink_state != BLINK_NONE; |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2240 } |
bb86514cad15
commit https://github.com/vim/vim/commit/703a8044b5393d37d355b0b1054a9a5a13912a3f
Christian Brabandt <cb@256bit.org>
parents:
9013
diff
changeset
|
2241 |
9428
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2242 int |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2243 gui_mch_is_blink_off(void) |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2244 { |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2245 return blink_state == BLINK_OFF; |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2246 } |
0c7f47088e55
commit https://github.com/vim/vim/commit/9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d
Christian Brabandt <cb@256bit.org>
parents:
9213
diff
changeset
|
2247 |
7 | 2248 void |
2249 gui_mch_set_blinking(long wait, long on, long off) | |
2250 { | |
2251 blink_waittime = wait; | |
2252 blink_ontime = on; | |
2253 blink_offtime = off; | |
2254 } | |
2255 | |
2256 void | |
2257 gui_mch_start_blink(void) | |
2258 { | |
2259 /* Only turn on the timer on if none of the times are zero */ | |
3076 | 2260 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
7 | 2261 { |
3076 | 2262 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, |
2263 blink_waittime, 0); | |
7 | 2264 blink_state = BLINK_ON; |
2265 gui_update_cursor(TRUE, FALSE); | |
2266 } | |
2267 } | |
2268 | |
2269 void | |
2270 gui_mch_stop_blink(void) | |
2271 { | |
3076 | 2272 PtSetResource(gui_ph_timer_cursor, Pt_ARG_TIMER_INITIAL, 0, 0); |
2273 | |
2274 if (blink_state == BLINK_OFF) | |
7 | 2275 gui_update_cursor(TRUE, FALSE); |
2276 | |
2277 blink_state = BLINK_NONE; | |
2278 } | |
2279 | |
2280 /****************************************************************************/ | |
2281 /* miscellaneous functions */ | |
2282 | |
2283 void | |
2284 gui_mch_beep(void) | |
2285 { | |
2286 PtBeep(); | |
2287 } | |
2288 | |
2289 void | |
2290 gui_mch_flash(int msec) | |
2291 { | |
3076 | 2292 PgSetFillXORColor(Pg_BLACK, Pg_WHITE); |
2293 PgSetDrawMode(Pg_DRAWMODE_XOR); | |
7 | 2294 gui_mch_clear_all(); |
2295 gui_mch_flush(); | |
2296 | |
3076 | 2297 ui_delay((long) msec, TRUE); |
7 | 2298 |
2299 gui_mch_clear_all(); | |
3076 | 2300 PgSetDrawMode(Pg_DRAWMODE_OPAQUE); |
7 | 2301 gui_mch_flush(); |
2302 } | |
2303 | |
2304 void | |
2305 gui_mch_flush(void) | |
2306 { | |
2307 PgFlush(); | |
2308 } | |
2309 | |
2310 void | |
2311 gui_mch_set_text_area_pos(int x, int y, int w, int h) | |
2312 { | |
2313 PhArea_t area = {{x, y}, {w, h}}; | |
2314 | |
3076 | 2315 PtSetResource(gui.vimTextArea, Pt_ARG_AREA, &area, 0); |
7 | 2316 } |
2317 | |
2318 int | |
2319 gui_mch_haskey(char_u *name) | |
2320 { | |
2321 int i; | |
2322 | |
2323 for (i = 0; special_keys[i].key_sym != 0; i++) | |
2324 if (name[0] == special_keys[i].vim_code0 && | |
2325 name[1] == special_keys[i].vim_code1) | |
2980 | 2326 return OK; |
2327 return FAIL; | |
7 | 2328 } |
2329 | |
2330 /****************************************************************************/ | |
2331 /* Menu */ | |
2332 | |
2333 #ifdef FEAT_TOOLBAR | |
2334 #include "toolbar.phi" | |
2335 | |
2336 static PhImage_t *gui_ph_toolbar_images[] = { | |
2337 &tb_new_phi, | |
2338 &tb_open_phi, | |
2339 &tb_save_phi, | |
2340 &tb_undo_phi, | |
2341 &tb_redo_phi, | |
2342 &tb_cut_phi, | |
2343 &tb_copy_phi, | |
2344 &tb_paste_phi, | |
2345 &tb_print_phi, | |
2346 &tb_help_phi, | |
2347 &tb_find_phi, | |
2348 &tb_save_all_phi, | |
2349 &tb_save_session_phi, | |
2350 &tb_new_session_phi, | |
2351 &tb_load_session_phi, | |
2352 &tb_macro_phi, | |
2353 &tb_replace_phi, | |
2354 &tb_close_phi, | |
2355 &tb_maximize_phi, | |
2356 &tb_minimize_phi, | |
2357 &tb_split_phi, | |
2358 &tb_shell_phi, | |
2359 &tb_find_prev_phi, | |
2360 &tb_find_next_phi, | |
2361 &tb_find_help_phi, | |
2362 &tb_make_phi, | |
2363 &tb_jump_phi, | |
2364 &tb_ctags_phi, | |
2365 &tb_vsplit_phi, | |
2366 &tb_maxwidth_phi, | |
2367 &tb_minwidth_phi | |
2368 }; | |
2369 | |
2370 static PhImage_t * | |
3076 | 2371 gui_ph_toolbar_load_icon(char_u *iconfile) |
7 | 2372 { |
2373 static PhImage_t external_icon; | |
2374 PhImage_t *temp_phi = NULL; | |
2375 | |
3076 | 2376 temp_phi = PxLoadImage(iconfile, NULL); |
2377 if (temp_phi != NULL) | |
7 | 2378 { |
2379 /* The label widget will free the image/palette/etc. for us when | |
2380 * it's destroyed */ | |
2381 temp_phi->flags |= Ph_RELEASE_IMAGE_ALL; | |
3076 | 2382 memcpy(&external_icon, temp_phi, sizeof(external_icon)); |
2383 free(temp_phi); | |
7 | 2384 |
2385 temp_phi = &external_icon; | |
2386 } | |
2980 | 2387 return temp_phi; |
7 | 2388 } |
2389 | |
2390 /* | |
2391 * This returns either a builtin icon image, an external image or NULL | |
2392 * if it can't find either. The caller can't and doesn't need to try and | |
2393 * free() the returned image, and it can't store the image pointer. | |
2394 * (When setting the Pt_ARG_LABEL_IMAGE resource, the contents of the | |
2395 * PhImage_t are copied, and the original PhImage_t aren't needed anymore). | |
2396 */ | |
2397 static PhImage_t * | |
3076 | 2398 gui_ph_toolbar_find_icon(vimmenu_T *menu) |
7 | 2399 { |
2400 char_u full_pathname[ MAXPATHL + 1 ]; | |
2401 PhImage_t *icon = NULL; | |
2402 | |
3076 | 2403 if (menu->icon_builtin == FALSE) |
7 | 2404 { |
3076 | 2405 if (menu->iconfile != NULL) |
7 | 2406 /* TODO: use gui_find_iconfile() */ |
3076 | 2407 icon = gui_ph_toolbar_load_icon(menu->iconfile); |
7 | 2408 |
2409 /* TODO: Restrict loading to just .png? Search for any format? */ | |
3076 | 2410 if ((icon == NULL) && |
2411 ((gui_find_bitmap(menu->name, full_pathname, "gif") == OK) || | |
2412 (gui_find_bitmap(menu->name, full_pathname, "png") == OK))) | |
2413 icon = gui_ph_toolbar_load_icon(full_pathname); | |
2414 | |
2415 if (icon != NULL) | |
2980 | 2416 return icon; |
7 | 2417 } |
2418 | |
3076 | 2419 if (menu->iconidx >= 0 && |
2420 (menu->iconidx < ARRAY_LENGTH(gui_ph_toolbar_images))) | |
7 | 2421 { |
2980 | 2422 return gui_ph_toolbar_images[menu->iconidx]; |
7 | 2423 } |
2424 | |
2980 | 2425 return NULL; |
7 | 2426 } |
2427 #endif | |
2428 | |
3076 | 2429 #if defined(FEAT_MENU) || defined(PROTO) |
7 | 2430 void |
2431 gui_mch_enable_menu(int flag) | |
2432 { | |
3076 | 2433 if (flag != 0) |
2434 PtRealizeWidget(gui.vimMenuBar); | |
7 | 2435 else |
3076 | 2436 PtUnrealizeWidget(gui.vimMenuBar); |
7 | 2437 } |
2438 | |
2439 void | |
2440 gui_mch_set_menu_pos(int x, int y, int w, int h) | |
2441 { | |
2442 /* Nothing */ | |
2443 } | |
2444 | |
2445 /* Change the position of a menu button in the parent */ | |
2446 static void | |
3076 | 2447 gui_ph_position_menu(PtWidget_t *widget, int priority) |
7 | 2448 { |
2449 PtWidget_t *traverse; | |
2450 vimmenu_T *menu; | |
2451 | |
3076 | 2452 traverse = PtWidgetChildBack(PtWidgetParent(widget)); |
7 | 2453 |
2454 /* Iterate through the list of widgets in traverse, until | |
2455 * we find the position we want to insert our widget into */ | |
2456 /* TODO: traverse from front to back, possible speedup? */ | |
3076 | 2457 while (traverse != NULL) |
7 | 2458 { |
3076 | 2459 PtGetResource(traverse, Pt_ARG_POINTER, &menu, 0); |
2460 | |
2461 if (menu != NULL && | |
7 | 2462 priority < menu->priority && |
3076 | 2463 widget != traverse) |
7 | 2464 { |
2465 /* Insert the widget before the current traverse widget */ | |
3076 | 2466 PtWidgetInsert(widget, traverse, 1); |
7 | 2467 return; |
2468 } | |
2469 | |
3076 | 2470 traverse = PtWidgetBrotherInFront(traverse); |
7 | 2471 } |
2472 } | |
2473 | |
2474 /* the index is ignored because it's not useful for our purposes */ | |
2475 void | |
2476 gui_mch_add_menu(vimmenu_T *menu, int index) | |
2477 { | |
2478 vimmenu_T *parent = menu->parent; | |
2479 char_u *accel_key; | |
2480 char_u mnemonic_str[MB_LEN_MAX]; | |
2481 int n; | |
2482 PtArg_t args[5]; | |
2483 | |
2484 menu->submenu_id = menu->id = NULL; | |
2485 | |
3076 | 2486 if (menu_is_menubar(menu->name)) |
7 | 2487 { |
2488 | |
3076 | 2489 accel_key = vim_strchr(menu->name, '&'); |
2490 if (accel_key != NULL) | |
7 | 2491 { |
2492 mnemonic_str[0] = accel_key[1]; | |
2493 mnemonic_str[1] = NUL; | |
2494 } | |
2495 | |
2496 /* Create the menu button */ | |
2497 n = 0; | |
3076 | 2498 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0); |
2499 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0); | |
2500 if (accel_key != NULL) | |
2501 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str, 0); | |
2502 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0); | |
2503 | |
2504 if (parent != NULL) | |
2505 PtSetArg(&args[ n++ ], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0); | |
2506 | |
2507 menu->id = PtCreateWidget(PtMenuButton, | |
7 | 2508 (parent == NULL) ? gui.vimMenuBar : parent->submenu_id, |
3076 | 2509 n, args); |
2510 | |
2511 PtAddCallback(menu->id, Pt_CB_ARM, gui_ph_handle_pulldown_menu, menu); | |
7 | 2512 |
2513 /* Create the actual menu */ | |
2514 n = 0; | |
3076 | 2515 if (parent != NULL) |
2516 PtSetArg(&args[ n++ ], Pt_ARG_MENU_FLAGS, Pt_TRUE, Pt_MENU_CHILD); | |
2517 | |
2518 menu->submenu_id = PtCreateWidget(PtMenu, menu->id, n, args); | |
2519 | |
2520 if (parent == NULL) | |
7 | 2521 { |
3076 | 2522 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED, |
2523 gui_ph_handle_menu_unrealized, menu); | |
2524 | |
2525 if (menu->mnemonic != 0) | |
7 | 2526 { |
3076 | 2527 PtAddHotkeyHandler(gui.vimWindow, tolower(menu->mnemonic), |
2528 Pk_KM_Alt, 0, menu, gui_ph_handle_pulldown_menu); | |
7 | 2529 } |
2530 } | |
2531 | |
3076 | 2532 gui_ph_position_menu(menu->id, menu->priority); |
7 | 2533 |
2534 /* Redraw menubar here instead of gui_mch_draw_menubar */ | |
3076 | 2535 if (gui.menu_is_active) |
2536 PtRealizeWidget(menu->id); | |
7 | 2537 } |
3076 | 2538 else if (menu_is_popup(menu->name)) |
7 | 2539 { |
3076 | 2540 menu->submenu_id = PtCreateWidget(PtMenu, gui.vimWindow, 0, NULL); |
2541 PtAddCallback(menu->submenu_id, Pt_CB_UNREALIZED, | |
2542 gui_ph_handle_menu_unrealized, menu); | |
7 | 2543 } |
2544 } | |
2545 | |
2546 void | |
2547 gui_mch_add_menu_item(vimmenu_T *menu, int index) | |
2548 { | |
2549 vimmenu_T *parent = menu->parent; | |
2550 char_u *accel_key; | |
2551 char_u mnemonic_str[MB_LEN_MAX]; | |
2552 int n; | |
2553 PtArg_t args[13]; | |
2554 | |
2555 n = 0; | |
3076 | 2556 PtSetArg(&args[ n++ ], Pt_ARG_POINTER, menu, 0); |
7 | 2557 |
2558 #ifdef FEAT_TOOLBAR | |
3076 | 2559 if (menu_is_toolbar(parent->name)) |
7 | 2560 { |
3076 | 2561 if (menu_is_separator(menu->name)) |
7 | 2562 { |
3076 | 2563 PtSetArg(&args[ n++ ], Pt_ARG_SEP_FLAGS, |
2564 Pt_SEP_VERTICAL, Pt_SEP_ORIENTATION); | |
2565 PtSetArg(&args[ n++ ], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0); | |
2566 PtSetArg(&args[ n++ ], Pt_ARG_ANCHOR_FLAGS, | |
2567 Pt_TRUE, Pt_ANCHOR_TOP_BOTTOM); | |
2568 PtSetArg(&args[ n++ ], Pt_ARG_WIDTH, 2, 0); | |
2569 menu->id = PtCreateWidget(PtSeparator, gui.vimToolBar, n, args); | |
7 | 2570 } |
2571 else | |
2572 { | |
3076 | 2573 if (strstr((const char *) p_toolbar, "text") != NULL) |
7 | 2574 { |
3076 | 2575 PtSetArg(&args[ n++ ], Pt_ARG_BALLOON_POSITION, |
2576 Pt_BALLOON_BOTTOM, 0); | |
2577 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0); | |
2578 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_FONT, "TextFont08", 0); | |
7 | 2579 } |
3076 | 2580 if ((strstr((const char *) p_toolbar, "icons") != NULL) && |
2581 (gui_ph_toolbar_images != NULL)) | |
7 | 2582 { |
3076 | 2583 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_IMAGE, |
2584 gui_ph_toolbar_find_icon(menu), 0); | |
2585 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_TYPE, Pt_TEXT_IMAGE, 0); | |
2586 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_IMAGE_SPACING, 0, 0); | |
7 | 2587 } |
3076 | 2588 if (strstr((const char *) p_toolbar, "tooltips") != NULL) |
7 | 2589 { |
3076 | 2590 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_BALLOON, |
2591 gui_ph_show_tooltip, 0); | |
2592 PtSetArg(&args[ n++ ], Pt_ARG_LABEL_FLAGS, | |
2593 Pt_TRUE, Pt_SHOW_BALLOON); | |
7 | 2594 } |
3076 | 2595 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_HEIGHT, 1, 0); |
2596 PtSetArg(&args[ n++ ], Pt_ARG_MARGIN_WIDTH, 1, 0); | |
2597 PtSetArg(&args[ n++ ], Pt_ARG_FLAGS, Pt_FALSE, | |
2598 Pt_HIGHLIGHTED | Pt_GETS_FOCUS); | |
2599 PtSetArg(&args[ n++ ], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0); | |
2600 menu->id = PtCreateWidget(PtButton, gui.vimToolBar, n, args); | |
2601 | |
2602 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu); | |
7 | 2603 } |
2604 /* Update toolbar if it's open */ | |
3076 | 2605 if (PtWidgetIsRealized(gui.vimToolBar)) |
2606 PtRealizeWidget(menu->id); | |
7 | 2607 } |
2608 else | |
2609 #endif | |
3076 | 2610 if (menu_is_separator(menu->name)) |
7 | 2611 { |
3076 | 2612 menu->id = PtCreateWidget(PtSeparator, parent->submenu_id, n, args); |
7 | 2613 } |
2614 else | |
2615 { | |
3076 | 2616 accel_key = vim_strchr(menu->name, '&'); |
2617 if (accel_key != NULL) | |
7 | 2618 { |
2619 mnemonic_str[0] = accel_key[1]; | |
2620 mnemonic_str[1] = NUL; | |
2621 } | |
2622 | |
3076 | 2623 PtSetArg(&args[ n++ ], Pt_ARG_TEXT_STRING, menu->dname, 0); |
2624 if (accel_key != NULL) | |
2625 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_KEY, mnemonic_str, | |
2626 0); | |
2627 | |
2628 PtSetArg(&args[ n++ ], Pt_ARG_ACCEL_TEXT, menu->actext, 0); | |
2629 | |
2630 menu->id = PtCreateWidget(PtMenuButton, parent->submenu_id, n, args); | |
2631 | |
2632 PtAddCallback(menu->id, Pt_CB_ACTIVATE, gui_ph_handle_menu, menu); | |
7 | 2633 |
2634 #ifdef USE_PANEL_GROUP | |
3076 | 2635 if (gui_ph_is_buffer_item(menu, parent) == TRUE) |
7 | 2636 { |
3076 | 2637 PtAddCallback(menu->id, Pt_CB_DESTROYED, |
2638 gui_ph_handle_buffer_remove, menu); | |
2639 gui_ph_pg_add_buffer(menu->dname); | |
7 | 2640 } |
2641 #endif | |
2642 } | |
2643 | |
3076 | 2644 gui_ph_position_menu(menu->id, menu->priority); |
7 | 2645 } |
2646 | |
2647 void | |
2648 gui_mch_destroy_menu(vimmenu_T *menu) | |
2649 { | |
3076 | 2650 if (menu->submenu_id != NULL) |
2651 PtDestroyWidget(menu->submenu_id); | |
2652 if (menu->id != NULL) | |
2653 PtDestroyWidget(menu->id); | |
7 | 2654 |
2655 menu->submenu_id = NULL; | |
2656 menu->id = NULL; | |
2657 } | |
2658 | |
2659 void | |
2660 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
2661 { | |
2662 long flags, mask, fields; | |
2663 | |
3076 | 2664 if (menu->id == NULL) |
7 | 2665 return; |
2666 | |
3076 | 2667 flags = PtWidgetFlags(menu->id); |
2668 if (PtWidgetIsClass(menu->id, PtMenuButton) && | |
2669 PtWidgetIsClass(PtWidgetParent(menu->id), PtMenu)) | |
7 | 2670 { |
2671 fields = Pt_FALSE; | |
2672 mask = Pt_SELECTABLE | Pt_HIGHLIGHTED; | |
2673 } | |
2674 else | |
2675 { | |
2676 fields = Pt_TRUE; | |
2677 mask = Pt_BLOCKED | Pt_GHOST; | |
2678 } | |
2679 | |
3076 | 2680 if (! grey) |
7 | 2681 fields = ~fields; |
2682 | |
3076 | 2683 PtSetResource(menu->id, Pt_ARG_FLAGS, fields, |
2684 mask); | |
7 | 2685 } |
2686 | |
2687 void | |
2688 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
2689 { | |
2690 /* TODO: [un]realize the widget? */ | |
2691 } | |
2692 | |
2693 void | |
2694 gui_mch_draw_menubar(void) | |
2695 { | |
2696 /* The only time a redraw is needed is when a menu button | |
2697 * is added to the menubar, and that is detected and the bar | |
2698 * redrawn in gui_mch_add_menu_item | |
2699 */ | |
2700 } | |
2701 | |
2702 void | |
2703 gui_mch_show_popupmenu(vimmenu_T *menu) | |
2704 { | |
3076 | 2705 PtSetResource(menu->submenu_id, Pt_ARG_POS, &abs_mouse, 0); |
2706 PtRealizeWidget(menu->submenu_id); | |
7 | 2707 } |
2708 | |
2709 void | |
2710 gui_mch_toggle_tearoffs(int enable) | |
2711 { | |
2712 /* No tearoffs yet */ | |
2713 } | |
2714 | |
2715 #endif | |
2716 | |
3076 | 2717 #if defined(FEAT_TOOLBAR) || defined(PROTO) |
7 | 2718 void |
2719 gui_mch_show_toolbar(int showit) | |
2720 { | |
3076 | 2721 if (showit) |
2722 PtRealizeWidget(gui.vimToolBar); | |
7 | 2723 else |
3076 | 2724 PtUnrealizeWidget(gui.vimToolBar); |
7 | 2725 } |
2726 #endif | |
2727 | |
2728 /****************************************************************************/ | |
2729 /* Fonts */ | |
2730 | |
2731 static GuiFont | |
2732 gui_ph_get_font( | |
2733 char_u *font_name, | |
2734 int_u font_flags, | |
2735 int_u font_size, | |
2736 /* Check whether the resulting font has the font flags and size that | |
2737 * was asked for */ | |
2738 int_u enforce | |
2739 ) | |
2740 { | |
2741 char_u *font_tag; | |
2742 FontQueryInfo info; | |
2743 int_u style; | |
2744 | |
3076 | 2745 font_tag = alloc(MAX_FONT_TAG); |
2746 if (font_tag != NULL) | |
7 | 2747 { |
3076 | 2748 if (PfGenerateFontName(font_name, font_flags, font_size, |
2749 font_tag) != NULL) | |
7 | 2750 { |
2751 /* Enforce some limits on the font used */ | |
2752 style = PHFONT_INFO_FIXED; | |
2753 | |
3076 | 2754 if (enforce & PF_STYLE_BOLD) |
7 | 2755 style |= PHFONT_INFO_BOLD; |
3076 | 2756 if (enforce & PF_STYLE_ANTIALIAS) |
7 | 2757 style |= PHFONT_INFO_ALIAS; |
3076 | 2758 if (enforce & PF_STYLE_ITALIC) |
7 | 2759 style |= PHFONT_INFO_ITALIC; |
2760 | |
3076 | 2761 PfQueryFontInfo(font_tag, &info); |
2762 | |
2763 if (info.size == 0) | |
7 | 2764 font_size = 0; |
2765 | |
2766 /* Make sure font size matches, and that the font style | |
2767 * at least has the bits we're checking for */ | |
3076 | 2768 if (font_size == info.size && |
2769 style == (info.style & style)) | |
2980 | 2770 return (GuiFont)font_tag; |
7 | 2771 } |
3076 | 2772 vim_free(font_tag); |
7 | 2773 } |
2980 | 2774 return NULL; |
7 | 2775 } |
2776 | |
2777 /* | |
2778 * Split up the vim font name | |
2779 * | |
2780 * vim_font is in the form of | |
2781 * <name>:s<height>:a:b:i | |
2782 * | |
2783 * a = antialias | |
2784 * b = bold | |
2785 * i = italic | |
2786 * | |
2787 */ | |
2788 | |
2789 static int | |
2790 gui_ph_parse_font_name( | |
2791 char_u *vim_font, | |
2792 char_u **font_name, | |
2793 int_u *font_flags, | |
3076 | 2794 int_u *font_size) |
7 | 2795 { |
2796 char_u *mark; | |
2797 int_u name_len, size; | |
2798 | |
3076 | 2799 mark = vim_strchr(vim_font, ':'); |
2800 if (mark == NULL) | |
2801 name_len = STRLEN(vim_font); | |
7 | 2802 else |
3076 | 2803 name_len = (int_u) (mark - vim_font); |
2804 | |
2805 *font_name = vim_strnsave(vim_font, name_len); | |
2998 | 2806 if (*font_name != NULL) |
7 | 2807 { |
2998 | 2808 if (mark != NULL) |
7 | 2809 { |
2998 | 2810 while (*mark != NUL && *mark++ == ':') |
7 | 2811 { |
2998 | 2812 switch (tolower(*mark++)) |
7 | 2813 { |
2814 case 'a': *font_flags |= PF_STYLE_ANTIALIAS; break; | |
2815 case 'b': *font_flags |= PF_STYLE_BOLD; break; | |
2816 case 'i': *font_flags |= PF_STYLE_ITALIC; break; | |
2817 | |
2818 case 's': | |
3076 | 2819 size = getdigits(&mark); |
7 | 2820 /* Restrict the size to some vague limits */ |
2998 | 2821 if (size < 1 || size > 100) |
7 | 2822 size = 8; |
2823 | |
2824 *font_size = size; | |
2825 break; | |
2826 | |
2827 default: | |
2828 break; | |
2829 } | |
2830 } | |
2831 } | |
2980 | 2832 return TRUE; |
7 | 2833 } |
2980 | 2834 return FALSE; |
7 | 2835 } |
2836 | |
2837 int | |
2838 gui_mch_init_font(char_u *vim_font_name, int fontset) | |
2839 { | |
2840 char_u *font_tag; | |
2841 char_u *font_name = NULL; | |
2842 int_u font_flags = 0; | |
2843 int_u font_size = 12; | |
2844 | |
2845 FontQueryInfo info; | |
2846 PhRect_t extent; | |
2847 | |
2998 | 2848 if (vim_font_name == NULL) |
7 | 2849 { |
2850 /* Default font */ | |
1922 | 2851 vim_font_name = "PC Terminal"; |
7 | 2852 } |
2853 | |
3076 | 2854 if (STRCMP(vim_font_name, "*") == 0) |
7 | 2855 { |
3076 | 2856 font_tag = PtFontSelection(gui.vimWindow, NULL, NULL, |
2857 "pcterm12", -1, PHFONT_FIXED, NULL); | |
7 | 2858 |
2998 | 2859 if (font_tag == NULL) |
2980 | 2860 return FAIL; |
7 | 2861 |
3076 | 2862 gui_mch_free_font(gui.norm_font); |
7 | 2863 gui.norm_font = font_tag; |
2864 | |
3076 | 2865 PfQueryFontInfo(font_tag, &info); |
2866 font_name = vim_strsave(info.font); | |
7 | 2867 } |
2868 else | |
2869 { | |
3076 | 2870 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags, |
2871 &font_size) == FALSE) | |
2980 | 2872 return FAIL; |
7 | 2873 |
3076 | 2874 font_tag = gui_ph_get_font(font_name, font_flags, font_size, 0); |
2998 | 2875 if (font_tag == NULL) |
7 | 2876 { |
3076 | 2877 vim_free(font_name); |
2980 | 2878 return FAIL; |
7 | 2879 } |
37 | 2880 |
3076 | 2881 gui_mch_free_font(gui.norm_font); |
7 | 2882 gui.norm_font = font_tag; |
2883 } | |
2884 | |
3076 | 2885 gui_mch_free_font(gui.bold_font); |
2886 gui.bold_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_BOLD, | |
2887 font_size, PF_STYLE_BOLD); | |
2888 | |
2889 gui_mch_free_font(gui.ital_font); | |
2890 gui.ital_font = gui_ph_get_font(font_name, font_flags | PF_STYLE_ITALIC, | |
2891 font_size, PF_STYLE_ITALIC); | |
7 | 2892 |
2893 /* This extent was brought to you by the letter 'g' */ | |
3076 | 2894 PfExtentText(&extent, NULL, font_tag, "g", 1); |
7 | 2895 |
2896 gui.char_width = extent.lr.x - extent.ul.x + 1; | |
2897 gui.char_height = (- extent.ul.y) + extent.lr.y + 1; | |
2898 gui.char_ascent = - extent.ul.y; | |
2899 | |
3076 | 2900 vim_free(font_name); |
2980 | 2901 return OK; |
7 | 2902 } |
2903 | |
444 | 2904 /* |
2905 * Adjust gui.char_height (after 'linespace' was changed). | |
2906 */ | |
7 | 2907 int |
444 | 2908 gui_mch_adjust_charheight(void) |
7 | 2909 { |
2910 FontQueryInfo info; | |
2911 | |
3076 | 2912 PfQueryFontInfo(gui.norm_font, &info); |
7 | 2913 |
2914 gui.char_height = - info.ascender + info.descender + p_linespace; | |
2915 gui.char_ascent = - info.ascender + p_linespace / 2; | |
2916 | |
2980 | 2917 return OK; |
7 | 2918 } |
2919 | |
2920 GuiFont | |
2921 gui_mch_get_font(char_u *vim_font_name, int report_error) | |
2922 { | |
2923 char_u *font_name; | |
2924 char_u *font_tag; | |
2925 int_u font_size = 12; | |
2926 int_u font_flags = 0; | |
2927 | |
3076 | 2928 if (gui_ph_parse_font_name(vim_font_name, &font_name, &font_flags, |
2929 &font_size) != FALSE) | |
7 | 2930 { |
3076 | 2931 font_tag = gui_ph_get_font(font_name, font_flags, font_size, -1); |
2932 vim_free(font_name); | |
7 | 2933 |
2998 | 2934 if (font_tag != NULL) |
2980 | 2935 return (GuiFont)font_tag; |
7 | 2936 } |
2937 | |
2998 | 2938 if (report_error) |
3076 | 2939 EMSG2(e_font, vim_font_name); |
7 | 2940 |
2980 | 2941 return FAIL; |
7 | 2942 } |
2943 | |
44 | 2944 #if defined(FEAT_EVAL) || defined(PROTO) |
37 | 2945 /* |
2946 * Return the name of font "font" in allocated memory. | |
2947 * Don't know how to get the actual name, thus use the provided name. | |
2948 */ | |
2949 char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
4352
diff
changeset
|
2950 gui_mch_get_fontname(GuiFont font, char_u *name) |
37 | 2951 { |
2952 if (name == NULL) | |
2953 return NULL; | |
2954 return vim_strsave(name); | |
2955 } | |
44 | 2956 #endif |
37 | 2957 |
7 | 2958 void |
2959 gui_mch_set_font(GuiFont font) | |
2960 { | |
3076 | 2961 PgSetFont(font); |
7 | 2962 } |
2963 | |
2964 void | |
2965 gui_mch_free_font(GuiFont font) | |
2966 { | |
3076 | 2967 vim_free(font); |
7 | 2968 } |
2969 |