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