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