1 /* vi:set ts=8 sw=4 sts=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Photon GUI support by Julian Kinraid
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.
10 * Clipboard support is in os_qnx.c
11 * PhAttach() is called in os_qnx.c:qnx_init()
17 # include <photon/PxImage.h>
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
27 # define PtCallbackF_t int
28 # define PtCallbackInfo_t int
30 # define PtWidget_t int
31 # define PhImage_t int
34 #define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a[0]))
35 #define RGB(r,g,b) PgRGB(r,g,b)
37 #define EVENT_BUFFER_SIZE sizeof( PhEvent_t ) + 1000
39 /* Some defines for gui_mch_mousehide() */
40 #define MOUSE_HIDE TRUE
41 #define MOUSE_SHOW FALSE
43 /* Optional support for using a PtPanelGroup widget, needs work */
44 #undef USE_PANEL_GROUP
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
;
53 #define GUI_PH_MARGIN 4 /* Size of the bevel */
55 #define GUI_PH_MOUSE_TYPE Ph_CURSOR_INSERT
56 static PgColor_t gui_ph_mouse_color
= Pg_BLACK
;
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? */
64 * This is set inside the mouse callback for a right mouse
65 * button click, and used for the popup menus
67 static PhPoint_t abs_mouse
;
69 /* Try and avoid redraws while a resize is in progress */
70 static int is_ignore_draw
= FALSE
;
72 /* Used for converting to/from utf-8 and other charsets */
73 static struct PxTransCtrl
*charset_translate
;
76 * Cursor blink functions.
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
87 } blink_state
= BLINK_NONE
;
89 static long_u blink_waittime
= 700;
90 static long_u blink_ontime
= 400;
91 static long_u blink_offtime
= 250;
103 {Pk_Right
, 'k', 'r'},
145 {Pk_BackSpace
, 'k', 'b'},
146 {Pk_Insert
, 'k', 'I'},
147 {Pk_Delete
, 'k', 'D'},
150 {Pk_Prior
, 'k', 'P'},
152 {Pk_Print
, '%', '9'},
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'},
160 {Pk_KP_0
, KS_EXTRA
, KE_KINS
}, /* Insert */
161 {Pk_KP_Decimal
, KS_EXTRA
, KE_KDEL
}, /* Delete */
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 */
168 {Pk_KP_7
, 'K', '1'}, /* Home */
169 {Pk_KP_1
, 'K', '4'}, /* End */
171 {Pk_KP_9
, 'K', '3'}, /* Page Up */
172 {Pk_KP_3
, 'K', '5'}, /* Page Down */
174 {Pk_KP_5
, '&', '8'}, /* Undo */
176 /* Keys that we want to be able to use any modifier with: */
177 {Pk_Return
, CAR
, NUL
},
178 {Pk_space
, ' ', NUL
},
180 {Pk_Escape
, ESC
, NUL
},
184 /* End of list marker: */
189 /****************************************************************************/
191 static PtCallbackF_t gui_ph_handle_timer_cursor
;
192 static PtCallbackF_t gui_ph_handle_timer_timeout
;
194 static PtCallbackF_t gui_ph_handle_window_cb
;
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 */
203 static PtCallbackF_t gui_ph_handle_menu_resize
;
205 /* When a menu is unrealized, give focus back to vimTextArea */
206 static PtCallbackF_t gui_ph_handle_menu_unrealized
;
208 #ifdef USE_PANEL_GROUP
209 static void gui_ph_get_panelgroup_margins( short*, short*, short*, short* );
213 static PhImage_t
*gui_ph_toolbar_find_icon( vimmenu_T
*menu
);
216 static void gui_ph_draw_start( void );
217 static void gui_ph_draw_end( void );
219 /* Set the text for the balloon */
220 static PtWidget_t
* gui_ph_show_tooltip( PtWidget_t
*window
,
225 PgColor_t fill_color
,
226 PgColor_t text_color
);
228 /****************************************************************************/
230 static PtWidget_t
* gui_ph_show_tooltip( PtWidget_t
*window
,
235 PgColor_t fill_color
,
236 PgColor_t text_color
)
242 PtSetArg( &arg
, Pt_ARG_POINTER
, &menu
, 0 );
243 PtGetResources( widget
, 1, &arg
);
245 /* Override the text and position */
250 int index
= MENU_INDEX_TIP
;
251 if( menu
->strings
[ index
] != NULL
)
252 tooltip
= menu
->strings
[ index
];
255 return( PtInflateBalloon(
258 /* Don't put the balloon at the bottom,
259 * it gets drawn over by gfx done in the PtRaw */
268 gui_ph_resize_container( void )
272 PtWidgetArea( gui
.vimWindow
, &area
);
273 PtWidgetPos ( gui
.vimContainer
, &area
.pos
);
275 PtSetResource( gui
.vimContainer
, Pt_ARG_AREA
, &area
, 0 );
279 gui_ph_handle_menu_resize(
282 PtCallbackInfo_t
*info
)
284 PtContainerCallback_t
*sizes
= info
->cbdata
;
285 PtWidget_t
*container
;
286 PhPoint_t below_menu
;
289 height
= sizes
->new_dim
.h
;
291 /* Because vim treats the toolbar and menubar separately,
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
)
296 gui
.menu_height
= height
;
297 gui
.toolbar_height
= 0;
301 gui
.toolbar_height
= height
;
305 below_menu
.y
= height
;
307 #ifdef USE_PANEL_GROUP
308 container
= gui
.vimPanelGroup
;
310 container
= gui
.vimContainer
;
313 PtSetResource( container
, Pt_ARG_POS
, &below_menu
, 0 );
315 gui_ph_resize_container();
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
);
322 return( Pt_CONTINUE
);
326 * Pt_ARG_TIMER_REPEAT isn't used because the on & off times
330 gui_ph_handle_timer_cursor(
333 PtCallbackInfo_t
*info
)
335 if( blink_state
== BLINK_ON
)
338 blink_state
= BLINK_OFF
;
339 PtSetResource( gui_ph_timer_cursor
, Pt_ARG_TIMER_INITIAL
,
344 gui_update_cursor(TRUE
, FALSE
);
345 blink_state
= BLINK_ON
;
346 PtSetResource( gui_ph_timer_cursor
, Pt_ARG_TIMER_INITIAL
,
349 return( Pt_CONTINUE
);
353 gui_ph_handle_timer_timeout(PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
357 return( Pt_CONTINUE
);
361 gui_ph_handle_window_cb( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
363 PhWindowEvent_t
*we
= info
->cbdata
;
364 ushort_t
*width
, *height
;
366 switch( we
->event_f
) {
372 /* Just in case it's hidden and needs to be shown */
373 gui_mch_mousehide( MOUSE_SHOW
);
375 if( we
->event_state
== Ph_WM_EVSTATE_FOCUS
)
377 gui_focus_change(TRUE
);
378 gui_mch_start_blink();
382 gui_focus_change(FALSE
);
383 gui_mch_stop_blink();
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
);
394 gui_resize_shell( *width
, *height
);
395 gui_set_shellsize( FALSE
, FALSE
, RESIZE_BOTH
);
396 is_ignore_draw
= FALSE
;
397 PtEndFlux( gui
.vimContainer
);
398 PtContainerRelease( gui
.vimContainer
);
405 return( Pt_CONTINUE
);
409 gui_ph_handle_scrollbar( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
411 PtScrollbarCallback_t
*scroll
;
413 int value
, dragging
= FALSE
;
415 scroll
= info
->cbdata
;
417 sb
= (scrollbar_T
*) data
;
420 value
= scroll
->position
;
421 switch( scroll
->action
)
423 case Pt_SCROLL_DRAGGED
:
428 /* FIXME: return straight away here? */
429 return( Pt_CONTINUE
);
433 gui_drag_scrollbar(sb
, value
, dragging
);
435 return( Pt_CONTINUE
);
439 gui_ph_handle_keyboard( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
442 unsigned char string
[6];
446 key
= PhGetData( info
->event
);
448 ch
= modifiers
= len
= 0;
451 gui_mch_mousehide( MOUSE_HIDE
);
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
)
456 return( Pt_CONTINUE
);
459 if( (key
->key_flags
& Pk_KF_Cap_Valid
) &&
460 PkIsKeyDown( key
->key_flags
) )
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
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
&&
473 gui_is_menu_shortcut( key
->key_cap
) ) ) )
475 /* Fallthrough and let photon look for the hotkey */
476 return( Pt_CONTINUE
);
480 for( i
= 0; special_keys
[i
].key_sym
!= 0; i
++ )
482 if( special_keys
[i
].key_sym
== key
->key_cap
)
485 if( special_keys
[i
].vim_code1
== NUL
)
486 ch
= special_keys
[i
].vim_code0
;
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
) )
494 /* FIXME: For now, just map the key to a ascii value
495 * (see <photon/PkKeyDef.h>) */
496 ch
= key
->key_cap
- 0xf080;
499 ch
= TO_SPECIAL( special_keys
[i
].vim_code0
,
500 special_keys
[i
].vim_code1
);
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
;
513 /* Is this not a special key? */
514 if( special_keys
[i
].key_sym
== 0 )
516 ch
= PhTo8859_1( key
);
519 || ( enc_utf8
&& ch
> 127 )
524 len
= PhKeyToMb( string
, key
);
528 int src_taken
, dst_made
;
529 if( enc_utf8
!= TRUE
)
540 add_to_input_buf( buf
, dst_made
);
544 add_to_input_buf( string
, len
);
547 return( Pt_CONSUME
);
554 /* FIXME: is this the right thing to do? */
555 if( modifiers
& MOD_MASK_CTRL
)
557 modifiers
&= ~MOD_MASK_CTRL
;
559 if( ( ch
>= 'a' && ch
<= 'z' ) ||
571 modifiers
|= MOD_MASK_CTRL
;
574 if( modifiers
& MOD_MASK_ALT
)
577 modifiers
&= ~MOD_MASK_ALT
;
582 return( Pt_CONTINUE
);
586 modifiers
&= ~MOD_MASK_SHIFT
;
589 ch
= simplify_key( ch
, &modifiers
);
592 string
[ len
++ ] = CSI
;
593 string
[ len
++ ] = KS_MODIFIER
;
594 string
[ len
++ ] = modifiers
;
597 if( IS_SPECIAL( ch
) )
599 string
[ len
++ ] = CSI
;
600 string
[ len
++ ] = K_SECOND( ch
);
601 string
[ len
++ ] = K_THIRD( ch
);
605 string
[ len
++ ] = ch
;
608 if (len
== 1 && ((ch
== Ctrl_C
&& ctrl_c_interrupts
)
615 if (len
== 1 && string
[0] == CSI
)
617 /* Turn CSI into K_CSI. */
618 string
[ len
++ ] = KS_EXTRA
;
619 string
[ len
++ ] = KE_CSI
;
624 add_to_input_buf( string
, len
);
625 return( Pt_CONSUME
);
629 return( Pt_CONTINUE
);
633 gui_ph_handle_mouse( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
635 PhPointerEvent_t
*pointer
;
637 int button
= 0, repeated_click
, modifiers
= 0x0;
638 short mouse_x
, mouse_y
;
640 pointer
= PhGetData( info
->event
);
641 pos
= PhGetRects( info
->event
);
643 gui_mch_mousehide( MOUSE_SHOW
);
646 * Coordinates need to be relative to the base window,
647 * not relative to the vimTextArea widget
649 mouse_x
= pos
->ul
.x
+ gui
.border_width
;
650 mouse_y
= pos
->ul
.y
+ gui
.border_width
;
652 if( info
->event
->type
== Ph_EV_PTR_MOTION_NOBUTTON
)
654 gui_mouse_moved( mouse_x
, mouse_y
);
655 return( Pt_CONTINUE
);
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
;
666 * FIXME More than one button may be involved, but for
667 * now just deal with one
669 if( pointer
->buttons
& Ph_BUTTON_SELECT
)
672 if( pointer
->buttons
& Ph_BUTTON_MENU
)
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
;
680 if( pointer
->buttons
& Ph_BUTTON_ADJUST
)
681 button
= MOUSE_MIDDLE
;
683 /* Catch a real release (not phantom or other releases */
684 if( info
->event
->type
== Ph_EV_BUT_RELEASE
)
685 button
= MOUSE_RELEASE
;
687 if( info
->event
->type
& Ph_EV_PTR_MOTION_BUTTON
)
691 /* Vim doesn't use button repeats */
692 if( info
->event
->type
& Ph_EV_BUT_REPEAT
)
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
) )
700 repeated_click
= (pointer
->click_count
>= 2) ? TRUE
: FALSE
;
702 gui_send_mouse_event( button
, mouse_x
, mouse_y
, repeated_click
, modifiers
);
705 return( Pt_CONTINUE
);
708 /* Handle a focus change of the PtRaw widget */
710 gui_ph_handle_focus( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
712 if( info
->reason
== Pt_CB_LOST_FOCUS
)
714 PtRemoveEventHandler( gui
.vimTextArea
, Ph_EV_PTR_MOTION_NOBUTTON
,
715 gui_ph_handle_mouse
, NULL
);
717 gui_mch_mousehide( MOUSE_SHOW
);
721 PtAddEventHandler( gui
.vimTextArea
, Ph_EV_PTR_MOTION_NOBUTTON
,
722 gui_ph_handle_mouse
, NULL
);
724 return( Pt_CONTINUE
);
728 gui_ph_handle_raw_draw( PtWidget_t
*widget
, PhTile_t
*damage
)
732 PhPoint_t translation
;
734 if( is_ignore_draw
== TRUE
)
737 PtSuperClassDraw( PtBasic
, widget
, damage
);
738 PgGetTranslation( &translation
);
739 PgClearTranslation();
743 * This causes some weird problems, with drawing being done from
744 * within this raw drawing function (rather than just simple clearing
745 * and text drawing done by gui_redraw)
747 * The main problem is when PhBlit is used, and the cursor appearing
748 * in places where it shouldn't
753 PtWidgetOffset( widget
, &offset
);
754 PhTranslatePoint( &offset
, PtWidgetPos( gui
.vimTextArea
, NULL
) );
757 /* Redraw individual damage regions */
758 if( damage
->next
!= NULL
)
759 damage
= damage
->next
;
761 while( damage
!= NULL
)
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
;
771 /* Redraw the rectangle that covers all the damaged regions */
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 );
779 PgSetTranslation( &translation
, 0 );
783 gui_ph_handle_pulldown_menu(
786 PtCallbackInfo_t
*info
)
790 vimmenu_T
*menu
= (vimmenu_T
*) data
;
792 PtPositionMenu( menu
->submenu_id
, NULL
);
793 PtRealizeWidget( menu
->submenu_id
);
796 return( Pt_CONTINUE
);
799 /* This is used for pulldown/popup menus and also toolbar buttons */
801 gui_ph_handle_menu( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
805 vimmenu_T
*menu
= (vimmenu_T
*) data
;
808 return( Pt_CONTINUE
);
811 /* Stop focus from disappearing into the menubar... */
813 gui_ph_handle_menu_unrealized(
816 PtCallbackInfo_t
*info
)
818 PtGiveFocus( gui
.vimTextArea
, NULL
);
819 return( Pt_CONTINUE
);
823 gui_ph_handle_window_open(
826 PtCallbackInfo_t
*info
)
828 gui_set_shellsize( FALSE
, TRUE
, RESIZE_BOTH
);
829 return( Pt_CONTINUE
);
832 /****************************************************************************/
834 #define DRAW_START gui_ph_draw_start()
835 #define DRAW_END gui_ph_draw_end()
837 /* TODO: Set a clipping rect? */
839 gui_ph_draw_start( void )
841 PgSetRegion( PtWidgetRid( PtFindDisjoint( gui
.vimTextArea
) ) );
843 PtWidgetOffset( gui
.vimTextArea
, &gui_ph_raw_offset
);
844 PhTranslatePoint( &gui_ph_raw_offset
, PtWidgetPos( gui
.vimTextArea
, NULL
) );
846 PgSetTranslation( &gui_ph_raw_offset
, Pg_RELATIVE
);
850 gui_ph_draw_end( void )
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
);
857 #ifdef USE_PANEL_GROUP
859 gui_ph_find_buffer_item( char_u
*name
)
861 vimmenu_T
*top_level
= root_menu
;
862 vimmenu_T
*items
= NULL
;
864 while( top_level
!= NULL
&&
865 ( STRCMP( top_level
->dname
, "Buffers" ) != 0 ) )
866 top_level
= top_level
->next
;
868 if( top_level
!= NULL
)
870 items
= top_level
->children
;
872 while( items
!= NULL
&&
873 ( STRCMP( items
->dname
, name
) != 0 ) )
880 gui_ph_pg_set_buffer_num( int_u buf_num
)
886 if( gui
.vimTextArea
== NULL
|| buf_num
== 0 )
890 ultoa( buf_num
, &search
[1], 10 );
891 STRCAT( search
, ")" );
893 for( i
= 0; i
< num_panels
; i
++ )
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 )
900 PtSetResource( gui
.vimPanelGroup
, Pt_ARG_PG_CURRENT_INDEX
,
907 gui_ph_handle_pg_change(
910 PtCallbackInfo_t
*info
)
913 PtPanelGroupCallback_t
*panel
;
915 if( info
->event
!= NULL
)
917 panel
= info
->cbdata
;
918 if( panel
->new_panel
!= NULL
)
920 menu
= gui_ph_find_buffer_item( panel
->new_panel
);
925 return( Pt_CONTINUE
);
929 gui_ph_get_panelgroup_margins(
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
;
939 PtGetAbsPosition( gui
.vimTextArea
, &abs_raw_x
, &abs_raw_y
);
940 PtGetAbsPosition( gui
.vimPanelGroup
, &abs_panel_x
, &abs_panel_y
);
942 PtGetResource( gui
.vimPanelGroup
, Pt_ARG_MARGIN_RIGHT
, &margin_right
, 0 );
943 PtGetResource( gui
.vimPanelGroup
, Pt_ARG_MARGIN_BOTTOM
, &margin_bottom
, 0 );
945 abs_raw_x
-= abs_panel_x
;
946 abs_raw_y
-= abs_panel_y
;
949 *bottom
= *margin_bottom
;
952 *right
= *margin_right
;
955 /* Used for the tabs for PtPanelGroup */
957 gui_ph_is_buffer_item( vimmenu_T
*menu
, vimmenu_T
*parent
)
961 if( STRCMP( parent
->dname
, "Buffers" ) == 0 )
963 /* Look for '(' digits ')' */
964 mark
= vim_strchr( menu
->dname
, '(' );
968 while( isdigit( *mark
) )
979 gui_ph_pg_add_buffer(char *name
)
981 char **new_titles
= NULL
;
983 new_titles
= (char **) alloc( ( num_panels
+ 1 ) * sizeof( char ** ) );
984 if( new_titles
!= NULL
)
987 memcpy( new_titles
, panel_titles
, num_panels
* sizeof( char ** ) );
989 new_titles
[ num_panels
++ ] = name
;
991 PtSetResource( gui
.vimPanelGroup
, Pt_ARG_PG_PANEL_TITLES
, new_titles
,
994 vim_free( panel_titles
);
995 panel_titles
= new_titles
;
1000 gui_ph_pg_remove_buffer( char *name
)
1003 char **new_titles
= NULL
;
1005 /* If there is only 1 panel, we just use the temporary place holder */
1006 if( num_panels
> 1 )
1008 new_titles
= (char **) alloc( ( num_panels
- 1 ) * sizeof( char ** ) );
1009 if( new_titles
!= NULL
)
1011 char **s
= new_titles
;
1012 /* Copy all the titles except the one we're removing */
1013 for( i
= 0; i
< num_panels
; i
++ )
1015 if( STRCMP( panel_titles
[ i
], name
) != 0 )
1017 *s
++ = panel_titles
[ i
];
1022 PtSetResource( gui
.vimPanelGroup
, Pt_ARG_PG_PANEL_TITLES
, new_titles
,
1025 vim_free( panel_titles
);
1026 panel_titles
= new_titles
;
1032 PtSetResource( gui
.vimPanelGroup
, Pt_ARG_PG_PANEL_TITLES
, &empty_title
,
1035 vim_free( panel_titles
);
1036 panel_titles
= NULL
;
1040 /* When a buffer item is deleted from the buffer menu */
1042 gui_ph_handle_buffer_remove(
1045 PtCallbackInfo_t
*info
)
1051 menu
= (vimmenu_T
*) data
;
1052 gui_ph_pg_remove_buffer( menu
->dname
);
1055 return( Pt_CONTINUE
);
1060 gui_ph_pane_resize( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
1062 if( PtWidgetIsRealized( widget
) )
1064 is_ignore_draw
= TRUE
;
1065 PtStartFlux( gui
.vimContainer
);
1066 PtContainerHold( gui
.vimContainer
);
1069 return( Pt_CONTINUE
);
1072 /****************************************************************************/
1076 gui_ph_encoding_changed( int new_encoding
)
1078 /* Default encoding is latin1 */
1079 char *charset
= "latin1";
1086 { DBCS_JPN
, "SHIFT_JIS" },
1087 { DBCS_KOR
, "csEUCKR" },
1088 { DBCS_CHT
, "big5" },
1092 for( i
= 0; i
< ARRAY_LENGTH( charsets
); i
++ )
1094 if( new_encoding
== charsets
[ i
].encoding
)
1095 charset
= charsets
[ i
].name
;
1098 charset_translate
= PxTranslateSet( charset_translate
, charset
);
1102 /****************************************************************************/
1103 /****************************************************************************/
1106 gui_mch_prepare(argc
, argv
)
1117 int flags
= 0, n
= 0;
1119 PhDim_t window_size
= {100, 100}; /* Arbitrary values */
1120 PhPoint_t pos
= {0, 0};
1122 gui
.event_buffer
= (PhEvent_t
*) alloc( EVENT_BUFFER_SIZE
);
1123 if( gui
.event_buffer
== NULL
)
1126 /* Get a translation so we can convert from ISO Latin-1 to UTF */
1127 charset_translate
= PxTranslateSet( NULL
, "latin1" );
1129 /* The +2 is for the 1 pixel dark line on each side */
1130 gui
.border_offset
= gui
.border_width
= GUI_PH_MARGIN
+ 2;
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
)
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
);
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 );
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 );
1154 gui
.vimPanelGroup
= PtCreateWidget( PtPanelGroup
, gui
.vimWindow
, n
, args
);
1155 if( gui
.vimPanelGroup
== NULL
)
1158 PtAddCallback( gui
.vimPanelGroup
, Pt_CB_PG_PANEL_SWITCHING
,
1159 gui_ph_handle_pg_change
, NULL
);
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
);
1168 gui
.vimContainer
= PtCreateWidget( PtPane
, gui
.vimWindow
, n
, args
);
1169 if( gui
.vimContainer
== NULL
)
1172 PtAddCallback( gui
.vimContainer
, Pt_CB_RESIZE
, gui_ph_pane_resize
, NULL
);
1175 /* Size for the text area is set in gui_mch_set_text_area_pos */
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 );
1181 * Using focus render also causes the whole widget to be redrawn
1182 * whenever it changes focus, which is very annoying :p
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 );
1191 gui
.vimTextArea
= PtCreateWidget( PtRaw
, Pt_DFLT_PARENT
, n
, args
);
1192 if( gui
.vimTextArea
== NULL
)
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
);
1208 * Now that the text area widget has been created, set up the colours,
1209 * which wil call PtSetResource from gui_mch_new_colors
1213 * Create the two timers, not as accurate as using the kernel timer
1214 * functions, but good enough
1216 gui_ph_timer_cursor
= PtCreateWidget( PtTimer
, gui
.vimWindow
, 0, NULL
);
1217 if( gui_ph_timer_cursor
== NULL
)
1220 gui_ph_timer_timeout
= PtCreateWidget( PtTimer
, gui
.vimWindow
, 0, NULL
);
1221 if( gui_ph_timer_timeout
== NULL
)
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
);
1231 PtSetArg( &args
[ n
++ ], Pt_ARG_WIDTH
, window_size
.w
, 0 );
1232 PtSetArg( &args
[ n
++ ], Pt_ARG_ANCHOR_FLAGS
, Pt_ANCHOR_LEFT_RIGHT
,
1234 gui
.vimToolBarGroup
= PtCreateWidget( PtToolbarGroup
, gui
.vimWindow
,
1236 if( gui
.vimToolBarGroup
== NULL
)
1239 PtAddCallback( gui
.vimToolBarGroup
, Pt_CB_RESIZE
,
1240 gui_ph_handle_menu_resize
, NULL
);
1244 PtSetArg( &args
[ n
++ ], Pt_ARG_WIDTH
, window_size
.w
, 0 );
1245 if( ! vim_strchr( p_go
, GO_MENUS
) )
1247 flags
|= Pt_DELAY_REALIZE
;
1248 PtSetArg( &args
[ n
++ ], Pt_ARG_FLAGS
, Pt_TRUE
, flags
);
1250 gui
.vimMenuBar
= PtCreateWidget( PtMenuBar
, gui
.vimToolBarGroup
, n
, args
);
1251 if( gui
.vimMenuBar
== NULL
)
1254 # ifdef FEAT_TOOLBAR
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 );
1263 flags
= Pt_GETS_FOCUS
;
1264 if( ! vim_strchr( p_go
, GO_TOOLBAR
) )
1265 flags
|= Pt_DELAY_REALIZE
;
1267 PtSetArg( &args
[ n
++ ], Pt_ARG_FLAGS
, Pt_DELAY_REALIZE
, flags
);
1269 gui
.vimToolBar
= PtCreateWidget( PtToolbar
, gui
.vimToolBarGroup
, n
, args
);
1270 if( gui
.vimToolBar
== NULL
)
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
1286 gui_mch_init_check(void)
1288 return( (is_photon_available
== TRUE
) ? OK
: FAIL
);
1294 gui
.norm_pixel
= Pg_BLACK
;
1295 gui
.back_pixel
= Pg_WHITE
;
1297 set_normal_colors();
1300 gui
.def_norm_pixel
= gui
.norm_pixel
;
1301 gui
.def_back_pixel
= gui
.back_pixel
;
1303 highlight_gui_started();
1305 if (gui_win_x
!= -1 && gui_win_y
!= -1)
1306 gui_mch_set_winpos(gui_win_x
, gui_win_y
);
1308 return( (PtRealizeWidget( gui
.vimWindow
) == 0) ? OK
: FAIL
);
1312 gui_mch_exit(int rc
)
1314 PtDestroyWidget( gui
.vimWindow
);
1316 PxTranslateSet( charset_translate
, NULL
);
1318 vim_free( gui
.event_buffer
);
1320 #ifdef USE_PANEL_GROUPS
1321 vim_free( panel_titles
);
1325 /****************************************************************************/
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. */
1331 exit_gui_mch_update( void *data
)
1333 *(int *)data
= FALSE
;
1338 gui_mch_update(void)
1342 PtAppAddWorkProc( NULL
, exit_gui_mch_update
, &working
);
1343 while( ( working
== TRUE
) && !vim_is_input_buf_full())
1350 gui_mch_wait_for_chars(int wtime
)
1355 PtSetResource( gui_ph_timer_timeout
, Pt_ARG_TIMER_INITIAL
, wtime
, 0 );
1360 if( input_available() )
1362 PtSetResource( gui_ph_timer_timeout
, Pt_ARG_TIMER_INITIAL
, 0, 0 );
1365 else if( is_timeout
== TRUE
)
1370 #if defined( FEAT_BROWSE ) || defined( PROTO )
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)
1385 char_u
*default_name
,
1390 PtFileSelectionInfo_t file
;
1392 char_u
*default_path
;
1393 char_u
*open_text
= NULL
;
1396 memset( &file
, 0, sizeof( file
) );
1398 default_path
= alloc( MAXPATHL
+ 1 + NAME_MAX
+ 1 );
1399 if( default_path
!= NULL
)
1401 if( saving
== TRUE
)
1403 /* Don't need Pt_FSR_CONFIRM_EXISTING, vim will ask anyway */
1404 flags
|= Pt_FSR_NO_FCHECK
;
1405 open_text
= "&Save";
1408 /* combine the directory and filename into a single path */
1409 if( initdir
== NULL
|| *initdir
== NUL
)
1411 mch_dirname( default_path
, MAXPATHL
);
1412 initdir
= default_path
;
1416 STRCPY( default_path
, initdir
);
1417 initdir
= default_path
;
1420 if( default_name
!= NULL
)
1422 if( default_path
[ STRLEN( default_path
) - 1 ] != '/' )
1423 STRCAT( default_path
, "/" );
1425 STRCAT( default_path
, default_name
);
1428 /* TODO: add a filter? */
1441 vim_free( default_path
);
1443 if( file
.ret
== Pt_FSDIALOG_BTN1
)
1444 return( vim_strsave( file
.path
) );
1450 #if defined( FEAT_GUI_DIALOG ) || defined( PROTO )
1451 static PtWidget_t
*gui_ph_dialog_text
= NULL
;
1454 gui_ph_dialog_close( int button
, void *data
)
1456 PtModalCtrl_t
*modal_ctrl
= data
;
1457 char_u
*dialog_text
, *vim_text
;
1459 if( gui_ph_dialog_text
!= NULL
)
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 );
1466 PtModalUnblock( modal_ctrl
, (void *) button
);
1472 gui_ph_dialog_text_enter( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
1474 if( info
->reason_subtype
== Pt_EDIT_ACTIVATE
)
1475 gui_ph_dialog_close( 1, data
);
1476 return( Pt_CONTINUE
);
1480 gui_ph_dialog_esc( PtWidget_t
*widget
, void *data
, PtCallbackInfo_t
*info
)
1484 key
= PhGetData( info
->event
);
1485 if( ( key
->key_flags
& Pk_KF_Cap_Valid
) && ( key
->key_cap
== Pk_Escape
) )
1487 gui_ph_dialog_close( 0, data
);
1488 return( Pt_CONSUME
);
1490 return( Pt_PROCESS
);
1503 char_u
**button_array
;
1504 char_u
*buttons_copy
;
1508 int dialog_result
= -1;
1510 /* FIXME: the vertical option in guioptions is blatantly ignored */
1511 /* FIXME: so is the type */
1513 button_count
= len
= i
= 0;
1515 if( buttons
== NULL
|| *buttons
== NUL
)
1518 /* There is one less separator than buttons, so bump up the button count */
1521 /* Count string length and number of seperators */
1522 for( str
= buttons
; *str
; str
++ )
1525 if( *str
== DLG_BUTTON_SEP
)
1529 if ( title
== NULL
)
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
)
1536 STRCPY( buttons_copy
, buttons
);
1539 * Convert DLG_BUTTON_SEP into NUL's and fill in
1540 * button_array with the pointer to each NUL terminated string
1543 for( i
= 0; i
< button_count
; i
++ )
1545 button_array
[ i
] = str
;
1546 for( ; *str
; str
++ )
1548 if( *str
== DLG_BUTTON_SEP
)
1555 #ifndef FEAT_GUI_TEXTDIALOG
1556 dialog_result
= PtAlert(
1557 gui
.vimWindow
, NULL
,
1561 button_count
, (const char **) button_array
, NULL
,
1562 default_button
, 0, Pt_MODAL
);
1564 /* Writing the dialog ourselves lets us add extra features, like
1565 * trapping the escape key and returning 0 to vim */
1569 PtWidget_t
*dialog
, *pane
;
1570 PtModalCtrl_t modal_ctrl
;
1573 memset( &di
, 0, sizeof( di
) );
1574 memset( &modal_ctrl
, 0, sizeof( modal_ctrl
) );
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
);
1587 PtSetArg( &args
[n
++], Pt_ARG_TEXT_STRING
, message
, 0 );
1588 PtCreateWidget( PtLabel
, pane
, n
, args
);
1590 if( textfield
!= NULL
)
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
);
1601 di
.parent
= gui
.vimWindow
;
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
;
1613 dialog
= PtCreateDialog( &di
);
1614 PtAddFilterCallback( dialog
, Ph_EV_KEY
,
1615 gui_ph_dialog_esc
, &modal_ctrl
);
1617 if( gui_ph_dialog_text
!= NULL
)
1618 PtGiveFocus( gui_ph_dialog_text
, NULL
);
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 );
1625 PtDestroyWidget( dialog
);
1626 gui_ph_dialog_text
= NULL
;
1631 vim_free( button_array
);
1632 vim_free( buttons_copy
);
1634 return( dialog_result
);
1637 /****************************************************************************/
1638 /* window size/position/state */
1641 gui_mch_get_winpos(int *x
, int *y
)
1645 pos
= PtWidgetPos( gui
.vimWindow
, NULL
);
1654 gui_mch_set_winpos(int x
, int y
)
1656 PhPoint_t pos
= { x
, y
};
1658 PtSetResource( gui
.vimWindow
, Pt_ARG_POS
, &pos
, 0 );
1662 gui_mch_set_shellsize(int width
, int height
,
1663 int min_width
, int min_height
, int base_width
, int base_height
,
1666 PhDim_t window_size
= { width
, height
};
1667 PhDim_t min_size
= { min_width
, min_height
};
1669 #ifdef USE_PANEL_GROUP
1670 window_size
.w
+= pg_margin_left
+ pg_margin_right
;
1671 window_size
.h
+= pg_margin_top
+ pg_margin_bottom
;
1674 PtSetResource( gui
.vimWindow
, Pt_ARG_MINIMUM_DIM
, &min_size
, 0 );
1675 PtSetResource( gui
.vimWindow
, Pt_ARG_DIM
, &window_size
, 0 );
1677 if( ! PtWidgetIsRealized( gui
.vimWindow
) )
1678 gui_ph_resize_container();
1682 * Return the amount of screen space that hasn't been allocated (such as
1686 gui_mch_get_screen_dimensions(int *screen_w
, int *screen_h
)
1690 PhWindowQueryVisible( Ph_QUERY_WORKSPACE
, 0,
1691 PhInputGroup( NULL
), &console
);
1693 *screen_w
= console
.lr
.x
- console
.ul
.x
+ 1;
1694 *screen_h
= console
.lr
.y
- console
.ul
.y
+ 1;
1698 gui_mch_iconify(void)
1700 PhWindowEvent_t event
;
1702 memset( &event
, 0, sizeof (event
) );
1703 event
.event_f
= Ph_WM_HIDE
;
1704 event
.event_state
= Ph_WM_EVSTATE_HIDE
;
1705 event
.rid
= PtWidgetRid( gui
.vimWindow
);
1706 PtForwardWindowEvent( &event
);
1709 #if defined(FEAT_EVAL) || defined(PROTO)
1711 * Bring the Vim window to the foreground.
1714 gui_mch_set_foreground()
1716 PhWindowEvent_t event
;
1718 memset( &event
, 0, sizeof (event
) );
1719 event
.event_f
= Ph_WM_TOFRONT
;
1720 event
.event_state
= Ph_WM_EVSTATE_FFRONT
;
1721 event
.rid
= PtWidgetRid( gui
.vimWindow
);
1722 PtForwardWindowEvent( &event
);
1727 gui_mch_settitle(char_u
*title
, char_u
*icon
)
1729 #ifdef USE_PANEL_GROUP
1730 gui_ph_pg_set_buffer_num( curwin
->w_buffer
->b_fnum
);
1732 PtSetResource( gui
.vimWindow
, Pt_ARG_WINDOW_TITLE
, title
, 0 );
1733 /* Not sure what to do with the icon text, set balloon text somehow? */
1736 /****************************************************************************/
1740 gui_mch_set_scrollbar_thumb(scrollbar_T
*sb
, int val
, int size
, int max
)
1745 PtSetArg( &args
[ n
++ ], Pt_ARG_MAXIMUM
, max
, 0 );
1746 PtSetArg( &args
[ n
++ ], Pt_ARG_SLIDER_SIZE
, size
, 0 );
1747 PtSetArg( &args
[ n
++ ], Pt_ARG_GAUGE_VALUE
, val
, 0 );
1748 PtSetResources( sb
->id
, n
, args
);
1752 gui_mch_set_scrollbar_pos(scrollbar_T
*sb
, int x
, int y
, int w
, int h
)
1754 PhArea_t area
= {{ x
, y
}, { w
, h
}};
1756 PtSetResource( sb
->id
, Pt_ARG_AREA
, &area
, 0 );
1760 gui_mch_create_scrollbar(scrollbar_T
*sb
, int orient
)
1763 /* int anchor_flags = 0;*/
1767 * Stop the scrollbar from being realized when the parent
1768 * is realized, so it can be explicitly realized by vim.
1770 * Also, don't let the scrollbar get focus
1772 PtSetArg( &args
[ n
++ ], Pt_ARG_FLAGS
, Pt_DELAY_REALIZE
,
1773 Pt_DELAY_REALIZE
| Pt_GETS_FOCUS
);
1774 PtSetArg( &args
[ n
++ ], Pt_ARG_SCROLLBAR_FLAGS
, Pt_SCROLLBAR_SHOW_ARROWS
, 0);
1776 /* Don't need this anchoring for the scrollbars */
1777 if( orient
== SBAR_HORIZ
)
1779 anchor_flags
= Pt_BOTTOM_ANCHORED_BOTTOM
|
1780 Pt_LEFT_ANCHORED_LEFT
| Pt_RIGHT_ANCHORED_RIGHT
;
1784 anchor_flags
= Pt_BOTTOM_ANCHORED_BOTTOM
| Pt_TOP_ANCHORED_TOP
;
1785 if( sb
->wp
!= NULL
)
1787 if( sb
== &sb
->wp
->w_scrollbars
[ SBAR_LEFT
] )
1788 anchor_flags
|= Pt_LEFT_ANCHORED_LEFT
;
1790 anchor_flags
|= Pt_RIGHT_ANCHORED_RIGHT
;
1793 PtSetArg( &args
[ n
++ ], Pt_ARG_ANCHOR_FLAGS
, anchor_flags
, Pt_IS_ANCHORED
);
1795 PtSetArg( &args
[ n
++ ], Pt_ARG_ORIENTATION
,
1796 (orient
== SBAR_HORIZ
) ? Pt_HORIZONTAL
: Pt_VERTICAL
, 0 );
1797 #ifdef USE_PANEL_GROUP
1798 sb
->id
= PtCreateWidget( PtScrollbar
, gui
.vimPanelGroup
, n
, args
);
1800 sb
->id
= PtCreateWidget( PtScrollbar
, gui
.vimContainer
, n
, args
);
1803 PtAddCallback( sb
->id
, Pt_CB_SCROLLBAR_MOVE
, gui_ph_handle_scrollbar
, sb
);
1807 gui_mch_enable_scrollbar(scrollbar_T
*sb
, int flag
)
1810 PtRealizeWidget( sb
->id
);
1812 PtUnrealizeWidget( sb
->id
);
1816 gui_mch_destroy_scrollbar(scrollbar_T
*sb
)
1818 PtDestroyWidget( sb
->id
);
1822 /****************************************************************************/
1823 /* Mouse functions */
1825 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1826 /* The last set mouse pointer shape is remembered, to be used when it goes
1827 * from hidden to not hidden. */
1828 static int last_shape
= 0;
1830 /* Table for shape IDs. Keep in sync with the mshape_names[] table in
1832 static int mshape_ids
[] =
1834 Ph_CURSOR_POINTER
, /* arrow */
1835 Ph_CURSOR_NONE
, /* blank */
1836 Ph_CURSOR_INSERT
, /* beam */
1837 Ph_CURSOR_DRAG_VERTICAL
, /* updown */
1838 Ph_CURSOR_DRAG_VERTICAL
, /* udsizing */
1839 Ph_CURSOR_DRAG_HORIZONTAL
, /* leftright */
1840 Ph_CURSOR_DRAG_HORIZONTAL
, /* lrsizing */
1841 Ph_CURSOR_WAIT
, /* busy */
1842 Ph_CURSOR_DONT
, /* no */
1843 Ph_CURSOR_CROSSHAIR
, /* crosshair */
1844 Ph_CURSOR_FINGER
, /* hand1 */
1845 Ph_CURSOR_FINGER
, /* hand2 */
1846 Ph_CURSOR_FINGER
, /* pencil */
1847 Ph_CURSOR_QUESTION_POINT
, /* question */
1848 Ph_CURSOR_POINTER
, /* right-arrow */
1849 Ph_CURSOR_POINTER
, /* up-arrow */
1850 Ph_CURSOR_POINTER
/* last one */
1854 mch_set_mouse_shape(shape
)
1862 if (shape
== MSHAPE_HIDE
|| gui
.pointer_hidden
)
1863 PtSetResource( gui
.vimTextArea
, Pt_ARG_CURSOR_TYPE
, Ph_CURSOR_NONE
,
1867 if (shape
>= MSHAPE_NUMBERED
)
1868 id
= Ph_CURSOR_POINTER
;
1870 id
= mshape_ids
[shape
];
1872 PtSetResource( gui
.vimTextArea
, Pt_ARG_CURSOR_TYPE
, id
, 0 );
1874 if (shape
!= MSHAPE_HIDE
)
1880 gui_mch_mousehide(int hide
)
1882 if( gui
.pointer_hidden
!= hide
)
1884 gui
.pointer_hidden
= hide
;
1885 #ifdef FEAT_MOUSESHAPE
1887 PtSetResource( gui
.vimTextArea
, Pt_ARG_CURSOR_TYPE
,
1888 Ph_CURSOR_NONE
, 0 );
1890 mch_set_mouse_shape( last_shape
);
1892 PtSetResource( gui
.vimTextArea
, Pt_ARG_CURSOR_TYPE
,
1893 ( hide
== MOUSE_SHOW
) ? GUI_PH_MOUSE_TYPE
: Ph_CURSOR_NONE
,
1900 gui_mch_getmouse(int *x
, int *y
)
1902 PhCursorInfo_t info
;
1905 /* FIXME: does this return the correct position,
1906 * with respect to the border? */
1907 PhQueryCursor( PhInputGroup( NULL
), &info
);
1908 PtGetAbsPosition( gui
.vimTextArea
, &ix
, &iy
);
1910 *x
= info
.pos
.x
- ix
;
1911 *y
= info
.pos
.y
- iy
;
1915 gui_mch_setmouse(int x
, int y
)
1919 PtGetAbsPosition( gui
.vimTextArea
, &abs_x
, &abs_y
);
1920 /* Add the border offset? */
1921 PhMoveCursorAbs( PhInputGroup( NULL
), abs_x
+ x
, abs_y
+ y
);
1924 /****************************************************************************/
1928 * Return the RGB value of a pixel as a long.
1931 gui_mch_get_rgb(guicolor_T pixel
)
1933 return PgRGB(PgRedValue(pixel
), PgGreenValue(pixel
), PgBlueValue(pixel
));
1937 gui_mch_new_colors(void)
1939 #if 0 /* Don't bother changing the cursor colour */
1943 * If there isn't enough difference between the background colour and
1944 * the mouse pointer colour then change the mouse pointer colour
1946 color_diff
= gui_get_lightness(gui_ph_mouse_color
)
1947 - gui_get_lightness(gui
.back_pixel
);
1949 if( abs( color_diff
) < 64 )
1952 /* not a great algorithm... */
1953 r
= PgRedValue( gui_ph_mouse_color
) ^ 255;
1954 g
= PgGreenValue( gui_ph_mouse_color
) ^ 255;
1955 b
= PgBlueValue( gui_ph_mouse_color
) ^ 255;
1957 #ifndef FEAT_MOUSESHAPE
1958 gui_ph_mouse_color
= PgRGB( r
, g
, b
);
1959 PtSetResource( gui
.vimTextArea
, Pt_ARG_CURSOR_COLOR
,
1960 gui_ph_mouse_color
, 0 );
1965 PtSetResource( gui
.vimTextArea
, Pt_ARG_FILL_COLOR
, gui
.back_pixel
, 0 );
1974 if (c
>= 'a' && c
<= 'f')
1975 return( c
- 'a' + 10 );
1981 * This should be split out into a separate file,
1982 * every port does basically the same thing.
1984 * This is the gui_w32.c version (i think..)
1985 * Return INVALCOLOR when failed.
1989 gui_mch_get_color(char_u
*name
)
1995 typedef struct GuiColourTable
2001 static GuiColourTable table
[] =
2003 {"Black", RGB(0x00, 0x00, 0x00)},
2004 {"DarkGray", RGB(0x80, 0x80, 0x80)},
2005 {"DarkGrey", RGB(0x80, 0x80, 0x80)},
2006 {"Gray", RGB(0xC0, 0xC0, 0xC0)},
2007 {"Grey", RGB(0xC0, 0xC0, 0xC0)},
2008 {"LightGray", RGB(0xD3, 0xD3, 0xD3)},
2009 {"LightGrey", RGB(0xD3, 0xD3, 0xD3)},
2010 {"Gray10", RGB(0x1A, 0x1A, 0x1A)},
2011 {"Grey10", RGB(0x1A, 0x1A, 0x1A)},
2012 {"Gray20", RGB(0x33, 0x33, 0x33)},
2013 {"Grey20", RGB(0x33, 0x33, 0x33)},
2014 {"Gray30", RGB(0x4D, 0x4D, 0x4D)},
2015 {"Grey30", RGB(0x4D, 0x4D, 0x4D)},
2016 {"Gray40", RGB(0x66, 0x66, 0x66)},
2017 {"Grey40", RGB(0x66, 0x66, 0x66)},
2018 {"Gray50", RGB(0x7F, 0x7F, 0x7F)},
2019 {"Grey50", RGB(0x7F, 0x7F, 0x7F)},
2020 {"Gray60", RGB(0x99, 0x99, 0x99)},
2021 {"Grey60", RGB(0x99, 0x99, 0x99)},
2022 {"Gray70", RGB(0xB3, 0xB3, 0xB3)},
2023 {"Grey70", RGB(0xB3, 0xB3, 0xB3)},
2024 {"Gray80", RGB(0xCC, 0xCC, 0xCC)},
2025 {"Grey80", RGB(0xCC, 0xCC, 0xCC)},
2026 {"Gray90", RGB(0xE5, 0xE5, 0xE5)},
2027 {"Grey90", RGB(0xE5, 0xE5, 0xE5)},
2028 {"White", RGB(0xFF, 0xFF, 0xFF)},
2029 {"DarkRed", RGB(0x80, 0x00, 0x00)},
2030 {"Red", RGB(0xFF, 0x00, 0x00)},
2031 {"LightRed", RGB(0xFF, 0xA0, 0xA0)},
2032 {"DarkBlue", RGB(0x00, 0x00, 0x80)},
2033 {"Blue", RGB(0x00, 0x00, 0xFF)},
2034 {"LightBlue", RGB(0xA0, 0xA0, 0xFF)},
2035 {"DarkGreen", RGB(0x00, 0x80, 0x00)},
2036 {"Green", RGB(0x00, 0xFF, 0x00)},
2037 {"LightGreen", RGB(0xA0, 0xFF, 0xA0)},
2038 {"DarkCyan", RGB(0x00, 0x80, 0x80)},
2039 {"Cyan", RGB(0x00, 0xFF, 0xFF)},
2040 {"LightCyan", RGB(0xA0, 0xFF, 0xFF)},
2041 {"DarkMagenta", RGB(0x80, 0x00, 0x80)},
2042 {"Magenta", RGB(0xFF, 0x00, 0xFF)},
2043 {"LightMagenta", RGB(0xFF, 0xA0, 0xFF)},
2044 {"Brown", RGB(0x80, 0x40, 0x40)},
2045 {"Yellow", RGB(0xFF, 0xFF, 0x00)},
2046 {"LightYellow", RGB(0xFF, 0xFF, 0xA0)},
2047 {"SeaGreen", RGB(0x2E, 0x8B, 0x57)},
2048 {"Orange", RGB(0xFF, 0xA5, 0x00)},
2049 {"Purple", RGB(0xA0, 0x20, 0xF0)},
2050 {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)},
2051 {"Violet", RGB(0xEE, 0x82, 0xEE)},
2054 /* is name #rrggbb format? */
2055 if( name
[0] == '#' && STRLEN( name
) == 7 )
2057 r
= hex_digit( name
[1] ) * 16 + hex_digit( name
[2] );
2058 g
= hex_digit( name
[3] ) * 16 + hex_digit( name
[4] );
2059 b
= hex_digit( name
[5] ) * 16 + hex_digit( name
[6] );
2060 if( r
< 0 || g
< 0 || b
< 0 )
2062 return( RGB( r
, g
, b
) );
2065 for( i
= 0; i
< ARRAY_LENGTH( table
); i
++ )
2067 if( STRICMP( name
, table
[i
].name
) == 0 )
2068 return( table
[i
].colour
);
2072 * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt".
2075 #define LINE_LEN 100
2077 char line
[LINE_LEN
];
2080 fname
= expand_env_save((char_u
*)"$VIMRUNTIME/rgb.txt");
2084 fd
= fopen((char *)fname
, "rt");
2095 fgets(line
, LINE_LEN
, fd
);
2098 if (len
<= 1 || line
[len
-1] != '\n')
2103 i
= sscanf(line
, "%d %d %d %n", &r
, &g
, &b
, &pos
);
2109 if (STRICMP(color
, name
) == 0)
2112 return( (guicolor_T
) RGB(r
,g
,b
) );
2124 gui_mch_set_fg_color(guicolor_T color
)
2126 PgSetTextColor( color
);
2130 gui_mch_set_bg_color(guicolor_T color
)
2132 PgSetFillColor( color
);
2136 gui_mch_set_sp_color(guicolor_T color
)
2141 gui_mch_invert_rectangle(int row
, int col
, int nr
, int nc
)
2145 rect
.ul
.x
= FILL_X( col
);
2146 rect
.ul
.y
= FILL_Y( row
);
2148 /* FIXME: This has an off by one pixel problem */
2149 rect
.lr
.x
= rect
.ul
.x
+ nc
* gui
.char_width
;
2150 rect
.lr
.y
= rect
.ul
.y
+ nr
* gui
.char_height
;
2157 PgSetDrawMode( Pg_DrawModeDSTINVERT
);
2158 PgDrawRect( &rect
, Pg_DRAW_FILL
);
2159 PgSetDrawMode( Pg_DrawModeSRCCOPY
);
2164 gui_mch_clear_block(int row1
, int col1
, int row2
, int col2
)
2167 { FILL_X( col1
), FILL_Y( row1
) },
2168 { FILL_X( col2
+ 1 ) - 1, FILL_Y( row2
+ 1 ) - 1}
2172 gui_mch_set_bg_color( gui
.back_pixel
);
2173 PgDrawRect( &block
, Pg_DRAW_FILL
);
2180 PhRect_t text_rect
= {
2181 { gui
.border_width
, gui
.border_width
},
2182 { Columns
* gui
.char_width
+ gui
.border_width
- 1 ,
2183 Rows
* gui
.char_height
+ gui
.border_width
- 1 }
2186 if( is_ignore_draw
== TRUE
)
2190 gui_mch_set_bg_color( gui
.back_pixel
);
2191 PgDrawRect( &text_rect
, Pg_DRAW_FILL
);
2196 gui_mch_delete_lines(int row
, int num_lines
)
2201 rect
.ul
.x
= FILL_X( gui
.scroll_region_left
);
2202 rect
.ul
.y
= FILL_Y( row
+ num_lines
);
2204 rect
.lr
.x
= FILL_X( gui
.scroll_region_right
+ 1 ) - 1;
2205 rect
.lr
.y
= FILL_Y( gui
.scroll_region_bot
+ 1) - 1;
2207 PtWidgetOffset( gui
.vimTextArea
, &gui_ph_raw_offset
);
2208 PhTranslatePoint( &gui_ph_raw_offset
, PtWidgetPos(gui
.vimTextArea
, NULL
));
2209 PhTranslateRect( &rect
, &gui_ph_raw_offset
);
2212 delta
.y
= -num_lines
* gui
.char_height
;
2216 PhBlit( PtWidgetRid( PtFindDisjoint( gui
.vimTextArea
) ), &rect
, &delta
);
2219 gui
.scroll_region_bot
- num_lines
+ 1,
2220 gui
.scroll_region_left
,
2221 gui
.scroll_region_bot
,
2222 gui
.scroll_region_right
);
2226 gui_mch_insert_lines(int row
, int num_lines
)
2231 rect
.ul
.x
= FILL_X( gui
.scroll_region_left
);
2232 rect
.ul
.y
= FILL_Y( row
);
2234 rect
.lr
.x
= FILL_X( gui
.scroll_region_right
+ 1 ) - 1;
2235 rect
.lr
.y
= FILL_Y( gui
.scroll_region_bot
- num_lines
+ 1 ) - 1;
2237 PtWidgetOffset( gui
.vimTextArea
, &gui_ph_raw_offset
);
2238 PhTranslatePoint( &gui_ph_raw_offset
, PtWidgetPos( gui
.vimTextArea
, NULL
) );
2239 PhTranslateRect( &rect
, &gui_ph_raw_offset
);
2242 delta
.y
= num_lines
* gui
.char_height
;
2246 PhBlit( PtWidgetRid( PtFindDisjoint( gui
.vimTextArea
) ) , &rect
, &delta
);
2248 gui_clear_block( row
, gui
.scroll_region_left
,
2249 row
+ num_lines
- 1, gui
.scroll_region_right
);
2253 gui_mch_draw_string(int row
, int col
, char_u
*s
, int len
, int flags
)
2255 static char *utf8_buffer
= NULL
;
2256 static int utf8_len
= 0;
2258 PhPoint_t pos
= { TEXT_X( col
), TEXT_Y( row
) };
2261 if( is_ignore_draw
== TRUE
)
2266 if( !( flags
& DRAW_TRANSP
) )
2269 FILL_X( col
), FILL_Y( row
),
2270 FILL_X( col
+ len
) - 1, FILL_Y( row
+ 1 ) - 1,
2274 if( flags
& DRAW_UNDERL
)
2275 PgSetUnderline( gui
.norm_pixel
, Pg_TRANSPARENT
, 0 );
2277 if( charset_translate
!= NULL
2283 int src_taken
, dst_made
;
2285 /* Use a static buffer to avoid large amounts of de/allocations */
2286 if( utf8_len
< len
)
2288 utf8_buffer
= realloc( utf8_buffer
, len
* MB_LEN_MAX
);
2304 PgDrawText( s
, len
, &pos
, 0 );
2306 if( flags
& DRAW_BOLD
)
2308 /* FIXME: try and only calculate these values once... */
2309 rect
.ul
.x
= FILL_X( col
) + 1;
2310 rect
.ul
.y
= FILL_Y( row
);
2311 rect
.lr
.x
= FILL_X( col
+ len
) - 1;
2312 rect
.lr
.y
= FILL_Y( row
+ 1) - 1;
2313 /* PgSetUserClip( NULL ) causes the scrollbar to not redraw... */
2317 PgSetUserClip( &rect
);
2318 PgDrawText( s
, len
, &pos
, 0 );
2319 PgSetUserClip( NULL
);
2321 rect
.lr
.y
-= ( p_linespace
+ 1 ) / 2;
2322 /* XXX: DrawTextArea doesn't work with phditto */
2323 PgDrawTextArea( s
, len
, &rect
, Pg_TEXT_BOTTOM
);
2327 if( flags
& DRAW_UNDERL
)
2328 PgSetUnderline( Pg_TRANSPARENT
, Pg_TRANSPARENT
, 0 );
2333 /****************************************************************************/
2337 gui_mch_draw_hollow_cursor(guicolor_T color
)
2341 /* FIXME: Double width characters */
2343 r
.ul
.x
= FILL_X( gui
.col
);
2344 r
.ul
.y
= FILL_Y( gui
.row
);
2345 r
.lr
.x
= r
.ul
.x
+ gui
.char_width
- 1;
2346 r
.lr
.y
= r
.ul
.y
+ gui
.char_height
- 1;
2349 PgSetStrokeColor( color
);
2350 PgDrawRect( &r
, Pg_DRAW_STROKE
);
2355 gui_mch_draw_part_cursor(int w
, int h
, guicolor_T color
)
2359 r
.ul
.x
= FILL_X( gui
.col
);
2360 r
.ul
.y
= FILL_Y( gui
.row
) + gui
.char_height
- h
;
2361 r
.lr
.x
= r
.ul
.x
+ w
- 1;
2362 r
.lr
.y
= r
.ul
.y
+ h
- 1;
2365 gui_mch_set_bg_color( color
);
2366 PgDrawRect( &r
, Pg_DRAW_FILL
);
2371 gui_mch_set_blinking(long wait
, long on
, long off
)
2373 blink_waittime
= wait
;
2375 blink_offtime
= off
;
2379 gui_mch_start_blink(void)
2381 /* Only turn on the timer on if none of the times are zero */
2382 if( blink_waittime
&& blink_ontime
&& blink_offtime
&& gui
.in_focus
)
2384 PtSetResource( gui_ph_timer_cursor
, Pt_ARG_TIMER_INITIAL
,
2385 blink_waittime
, 0 );
2386 blink_state
= BLINK_ON
;
2387 gui_update_cursor(TRUE
, FALSE
);
2392 gui_mch_stop_blink(void)
2394 PtSetResource( gui_ph_timer_cursor
, Pt_ARG_TIMER_INITIAL
, 0, 0 );
2396 if( blink_state
== BLINK_OFF
)
2397 gui_update_cursor(TRUE
, FALSE
);
2399 blink_state
= BLINK_NONE
;
2402 /****************************************************************************/
2403 /* miscellaneous functions */
2412 gui_mch_flash(int msec
)
2414 PgSetFillXORColor( Pg_BLACK
, Pg_WHITE
);
2415 PgSetDrawMode( Pg_DRAWMODE_XOR
);
2416 gui_mch_clear_all();
2419 ui_delay( (long) msec
, TRUE
);
2421 gui_mch_clear_all();
2422 PgSetDrawMode( Pg_DRAWMODE_OPAQUE
);
2433 gui_mch_set_text_area_pos(int x
, int y
, int w
, int h
)
2435 PhArea_t area
= {{x
, y
}, {w
, h
}};
2437 PtSetResource( gui
.vimTextArea
, Pt_ARG_AREA
, &area
, 0 );
2441 gui_mch_haskey(char_u
*name
)
2445 for (i
= 0; special_keys
[i
].key_sym
!= 0; i
++)
2446 if (name
[0] == special_keys
[i
].vim_code0
&&
2447 name
[1] == special_keys
[i
].vim_code1
)
2452 /****************************************************************************/
2456 #include "toolbar.phi"
2458 static PhImage_t
*gui_ph_toolbar_images
[] = {
2471 &tb_save_session_phi
,
2472 &tb_new_session_phi
,
2473 &tb_load_session_phi
,
2493 gui_ph_toolbar_load_icon( char_u
*iconfile
)
2495 static PhImage_t external_icon
;
2496 PhImage_t
*temp_phi
= NULL
;
2498 temp_phi
= PxLoadImage( iconfile
, NULL
);
2499 if( temp_phi
!= NULL
)
2501 /* The label widget will free the image/palette/etc. for us when
2503 temp_phi
->flags
|= Ph_RELEASE_IMAGE_ALL
;
2504 memcpy( &external_icon
, temp_phi
, sizeof( external_icon
) );
2507 temp_phi
= &external_icon
;
2513 * This returns either a builtin icon image, an external image or NULL
2514 * if it can't find either. The caller can't and doesn't need to try and
2515 * free() the returned image, and it can't store the image pointer.
2516 * (When setting the Pt_ARG_LABEL_IMAGE resource, the contents of the
2517 * PhImage_t are copied, and the original PhImage_t aren't needed anymore).
2520 gui_ph_toolbar_find_icon( vimmenu_T
*menu
)
2522 char_u full_pathname
[ MAXPATHL
+ 1 ];
2523 PhImage_t
*icon
= NULL
;
2525 if( menu
->icon_builtin
== FALSE
)
2527 if( menu
->iconfile
!= NULL
)
2528 /* TODO: use gui_find_iconfile() */
2529 icon
= gui_ph_toolbar_load_icon( menu
->iconfile
);
2531 /* TODO: Restrict loading to just .png? Search for any format? */
2532 if( ( icon
== NULL
) &&
2533 ( ( gui_find_bitmap( menu
->name
, full_pathname
, "gif" ) == OK
) ||
2534 ( gui_find_bitmap( menu
->name
, full_pathname
, "png" ) == OK
) ) )
2535 icon
= gui_ph_toolbar_load_icon( full_pathname
);
2541 if( menu
->iconidx
>= 0 &&
2542 ( menu
->iconidx
< ARRAY_LENGTH( gui_ph_toolbar_images
) ) )
2544 return( gui_ph_toolbar_images
[ menu
->iconidx
] );
2551 #if defined( FEAT_MENU ) || defined( PROTO )
2553 gui_mch_enable_menu(int flag
)
2556 PtRealizeWidget( gui
.vimMenuBar
);
2558 PtUnrealizeWidget( gui
.vimMenuBar
);
2562 gui_mch_set_menu_pos(int x
, int y
, int w
, int h
)
2567 /* Change the position of a menu button in the parent */
2569 gui_ph_position_menu( PtWidget_t
*widget
, int priority
)
2571 PtWidget_t
*traverse
;
2574 traverse
= PtWidgetChildBack( PtWidgetParent( widget
) );
2576 /* Iterate through the list of widgets in traverse, until
2577 * we find the position we want to insert our widget into */
2578 /* TODO: traverse from front to back, possible speedup? */
2579 while( traverse
!= NULL
)
2581 PtGetResource( traverse
, Pt_ARG_POINTER
, &menu
, 0 );
2584 priority
< menu
->priority
&&
2585 widget
!= traverse
)
2587 /* Insert the widget before the current traverse widget */
2588 PtWidgetInsert( widget
, traverse
, 1 );
2592 traverse
= PtWidgetBrotherInFront( traverse
);
2596 /* the index is ignored because it's not useful for our purposes */
2598 gui_mch_add_menu(vimmenu_T
*menu
, int index
)
2600 vimmenu_T
*parent
= menu
->parent
;
2602 char_u mnemonic_str
[MB_LEN_MAX
];
2606 menu
->submenu_id
= menu
->id
= NULL
;
2608 if( menu_is_menubar( menu
->name
) )
2611 accel_key
= vim_strchr( menu
->name
, '&' );
2612 if( accel_key
!= NULL
)
2614 mnemonic_str
[0] = accel_key
[1];
2615 mnemonic_str
[1] = NUL
;
2618 /* Create the menu button */
2620 PtSetArg( &args
[ n
++ ], Pt_ARG_TEXT_STRING
, menu
->dname
, 0 );
2621 PtSetArg( &args
[ n
++ ], Pt_ARG_ACCEL_TEXT
, menu
->actext
, 0 );
2622 if( accel_key
!= NULL
)
2623 PtSetArg( &args
[ n
++ ], Pt_ARG_ACCEL_KEY
, mnemonic_str
, 0 );
2624 PtSetArg( &args
[ n
++ ], Pt_ARG_POINTER
, menu
, 0 );
2626 if( parent
!= NULL
)
2627 PtSetArg( &args
[ n
++ ], Pt_ARG_BUTTON_TYPE
, Pt_MENU_RIGHT
, 0 );
2629 menu
->id
= PtCreateWidget( PtMenuButton
,
2630 (parent
== NULL
) ? gui
.vimMenuBar
: parent
->submenu_id
,
2633 PtAddCallback( menu
->id
, Pt_CB_ARM
, gui_ph_handle_pulldown_menu
, menu
);
2635 /* Create the actual menu */
2637 if( parent
!= NULL
)
2638 PtSetArg( &args
[ n
++ ], Pt_ARG_MENU_FLAGS
, Pt_TRUE
, Pt_MENU_CHILD
);
2640 menu
->submenu_id
= PtCreateWidget( PtMenu
, menu
->id
, n
, args
);
2642 if( parent
== NULL
)
2644 PtAddCallback( menu
->submenu_id
, Pt_CB_UNREALIZED
,
2645 gui_ph_handle_menu_unrealized
, menu
);
2647 if( menu
->mnemonic
!= 0 )
2649 PtAddHotkeyHandler( gui
.vimWindow
, tolower( menu
->mnemonic
),
2650 Pk_KM_Alt
, 0, menu
, gui_ph_handle_pulldown_menu
);
2654 gui_ph_position_menu( menu
->id
, menu
->priority
);
2656 /* Redraw menubar here instead of gui_mch_draw_menubar */
2657 if( gui
.menu_is_active
)
2658 PtRealizeWidget( menu
->id
);
2660 else if( menu_is_popup( menu
->name
) )
2662 menu
->submenu_id
= PtCreateWidget( PtMenu
, gui
.vimWindow
, 0, NULL
);
2663 PtAddCallback( menu
->submenu_id
, Pt_CB_UNREALIZED
,
2664 gui_ph_handle_menu_unrealized
, menu
);
2669 gui_mch_add_menu_item(vimmenu_T
*menu
, int index
)
2671 vimmenu_T
*parent
= menu
->parent
;
2673 char_u mnemonic_str
[MB_LEN_MAX
];
2678 PtSetArg( &args
[ n
++ ], Pt_ARG_POINTER
, menu
, 0 );
2681 if( menu_is_toolbar( parent
->name
) )
2683 if( menu_is_separator( menu
->name
) )
2685 PtSetArg( &args
[ n
++ ], Pt_ARG_SEP_FLAGS
,
2686 Pt_SEP_VERTICAL
, Pt_SEP_ORIENTATION
);
2687 PtSetArg( &args
[ n
++ ], Pt_ARG_SEP_TYPE
, Pt_ETCHED_IN
, 0 );
2688 PtSetArg( &args
[ n
++ ], Pt_ARG_ANCHOR_FLAGS
,
2689 Pt_TRUE
, Pt_ANCHOR_TOP_BOTTOM
);
2690 PtSetArg( &args
[ n
++ ], Pt_ARG_WIDTH
, 2, 0 );
2691 menu
->id
= PtCreateWidget( PtSeparator
, gui
.vimToolBar
, n
, args
);
2695 if( strstr( (const char *) p_toolbar
, "text" ) != NULL
)
2697 PtSetArg( &args
[ n
++ ], Pt_ARG_BALLOON_POSITION
,
2698 Pt_BALLOON_BOTTOM
, 0 );
2699 PtSetArg( &args
[ n
++ ], Pt_ARG_TEXT_STRING
, menu
->dname
, 0 );
2700 PtSetArg( &args
[ n
++ ], Pt_ARG_TEXT_FONT
, "TextFont08", 0 );
2702 if( ( strstr( (const char *) p_toolbar
, "icons" ) != NULL
) &&
2703 ( gui_ph_toolbar_images
!= NULL
) )
2705 PtSetArg( &args
[ n
++ ], Pt_ARG_LABEL_IMAGE
,
2706 gui_ph_toolbar_find_icon( menu
), 0 );
2707 PtSetArg( &args
[ n
++ ], Pt_ARG_LABEL_TYPE
, Pt_TEXT_IMAGE
, 0 );
2708 PtSetArg( &args
[ n
++ ], Pt_ARG_TEXT_IMAGE_SPACING
, 0, 0 );
2710 if( strstr( (const char *) p_toolbar
, "tooltips" ) != NULL
)
2712 PtSetArg( &args
[ n
++ ], Pt_ARG_LABEL_BALLOON
,
2713 gui_ph_show_tooltip
, 0 );
2714 PtSetArg( &args
[ n
++ ], Pt_ARG_LABEL_FLAGS
,
2715 Pt_TRUE
, Pt_SHOW_BALLOON
);
2717 PtSetArg( &args
[ n
++ ], Pt_ARG_MARGIN_HEIGHT
, 1, 0 );
2718 PtSetArg( &args
[ n
++ ], Pt_ARG_MARGIN_WIDTH
, 1, 0 );
2719 PtSetArg( &args
[ n
++ ], Pt_ARG_FLAGS
, Pt_FALSE
,
2720 Pt_HIGHLIGHTED
| Pt_GETS_FOCUS
);
2721 PtSetArg( &args
[ n
++ ], Pt_ARG_FILL_COLOR
, Pg_TRANSPARENT
, 0 );
2722 menu
->id
= PtCreateWidget( PtButton
, gui
.vimToolBar
, n
, args
);
2724 PtAddCallback( menu
->id
, Pt_CB_ACTIVATE
, gui_ph_handle_menu
, menu
);
2726 /* Update toolbar if it's open */
2727 if( PtWidgetIsRealized( gui
.vimToolBar
) )
2728 PtRealizeWidget( menu
->id
);
2732 if( menu_is_separator( menu
->name
) )
2734 menu
->id
= PtCreateWidget( PtSeparator
, parent
->submenu_id
, n
, args
);
2738 accel_key
= vim_strchr( menu
->name
, '&' );
2739 if( accel_key
!= NULL
)
2741 mnemonic_str
[0] = accel_key
[1];
2742 mnemonic_str
[1] = NUL
;
2745 PtSetArg( &args
[ n
++ ], Pt_ARG_TEXT_STRING
, menu
->dname
, 0 );
2746 if( accel_key
!= NULL
)
2747 PtSetArg( &args
[ n
++ ], Pt_ARG_ACCEL_KEY
, mnemonic_str
,
2750 PtSetArg( &args
[ n
++ ], Pt_ARG_ACCEL_TEXT
, menu
->actext
, 0 );
2752 menu
->id
= PtCreateWidget( PtMenuButton
, parent
->submenu_id
, n
, args
);
2754 PtAddCallback( menu
->id
, Pt_CB_ACTIVATE
, gui_ph_handle_menu
, menu
);
2756 #ifdef USE_PANEL_GROUP
2757 if( gui_ph_is_buffer_item( menu
, parent
) == TRUE
)
2759 PtAddCallback( menu
->id
, Pt_CB_DESTROYED
,
2760 gui_ph_handle_buffer_remove
, menu
);
2761 gui_ph_pg_add_buffer( menu
->dname
);
2766 gui_ph_position_menu( menu
->id
, menu
->priority
);
2770 gui_mch_destroy_menu(vimmenu_T
*menu
)
2772 if( menu
->submenu_id
!= NULL
)
2773 PtDestroyWidget( menu
->submenu_id
);
2774 if( menu
->id
!= NULL
)
2775 PtDestroyWidget( menu
->id
);
2777 menu
->submenu_id
= NULL
;
2782 gui_mch_menu_grey(vimmenu_T
*menu
, int grey
)
2784 long flags
, mask
, fields
;
2786 if( menu
->id
== NULL
)
2789 flags
= PtWidgetFlags( menu
->id
);
2790 if( PtWidgetIsClass( menu
->id
, PtMenuButton
) &&
2791 PtWidgetIsClass( PtWidgetParent( menu
->id
), PtMenu
) )
2794 mask
= Pt_SELECTABLE
| Pt_HIGHLIGHTED
;
2799 mask
= Pt_BLOCKED
| Pt_GHOST
;
2805 PtSetResource( menu
->id
, Pt_ARG_FLAGS
, fields
,
2810 gui_mch_menu_hidden(vimmenu_T
*menu
, int hidden
)
2812 /* TODO: [un]realize the widget? */
2816 gui_mch_draw_menubar(void)
2818 /* The only time a redraw is needed is when a menu button
2819 * is added to the menubar, and that is detected and the bar
2820 * redrawn in gui_mch_add_menu_item
2825 gui_mch_show_popupmenu(vimmenu_T
*menu
)
2827 PtSetResource( menu
->submenu_id
, Pt_ARG_POS
, &abs_mouse
, 0 );
2828 PtRealizeWidget( menu
->submenu_id
);
2832 gui_mch_toggle_tearoffs(int enable
)
2834 /* No tearoffs yet */
2839 #if defined( FEAT_TOOLBAR ) || defined( PROTO )
2841 gui_mch_show_toolbar(int showit
)
2844 PtRealizeWidget( gui
.vimToolBar
);
2846 PtUnrealizeWidget( gui
.vimToolBar
);
2850 /****************************************************************************/
2858 /* Check whether the resulting font has the font flags and size that
2867 font_tag
= alloc( MAX_FONT_TAG
);
2868 if( font_tag
!= NULL
)
2870 if( PfGenerateFontName( font_name
, font_flags
, font_size
,
2871 font_tag
) != NULL
)
2873 /* Enforce some limits on the font used */
2874 style
= PHFONT_INFO_FIXED
;
2876 if( enforce
& PF_STYLE_BOLD
)
2877 style
|= PHFONT_INFO_BOLD
;
2878 if( enforce
& PF_STYLE_ANTIALIAS
)
2879 style
|= PHFONT_INFO_ALIAS
;
2880 if( enforce
& PF_STYLE_ITALIC
)
2881 style
|= PHFONT_INFO_ITALIC
;
2883 PfQueryFontInfo( font_tag
, &info
);
2885 if( info
.size
== 0 )
2888 /* Make sure font size matches, and that the font style
2889 * at least has the bits we're checking for */
2890 if( font_size
== info
.size
&&
2891 style
== (info
.style
& style
) )
2892 return( (GuiFont
) font_tag
);
2894 vim_free( font_tag
);
2900 * Split up the vim font name
2902 * vim_font is in the form of
2903 * <name>:s<height>:a:b:i
2912 gui_ph_parse_font_name(
2919 int_u name_len
, size
;
2921 mark
= vim_strchr( vim_font
, ':' );
2923 name_len
= STRLEN( vim_font
);
2925 name_len
= (int_u
) ( mark
- vim_font
);
2927 *font_name
= vim_strnsave( vim_font
, name_len
);
2928 if( *font_name
!= NULL
)
2932 while( *mark
!= NUL
&& *mark
++ == ':')
2934 switch( tolower( *mark
++ ) )
2936 case 'a': *font_flags
|= PF_STYLE_ANTIALIAS
; break;
2937 case 'b': *font_flags
|= PF_STYLE_BOLD
; break;
2938 case 'i': *font_flags
|= PF_STYLE_ITALIC
; break;
2941 size
= getdigits( &mark
);
2942 /* Restrict the size to some vague limits */
2943 if( size
< 1 || size
> 100 )
2960 gui_mch_init_font(char_u
*vim_font_name
, int fontset
)
2963 char_u
*font_name
= NULL
;
2964 int_u font_flags
= 0;
2965 int_u font_size
= 12;
2970 if( vim_font_name
== NULL
)
2973 vim_font_name
= "PC Term";
2976 if( STRCMP( vim_font_name
, "*" ) == 0 )
2978 font_tag
= PtFontSelection( gui
.vimWindow
, NULL
, NULL
,
2979 "pcterm12", -1, PHFONT_FIXED
, NULL
);
2981 if( font_tag
== NULL
)
2984 gui_mch_free_font( gui
.norm_font
);
2985 gui
.norm_font
= font_tag
;
2987 PfQueryFontInfo( font_tag
, &info
);
2988 font_name
= vim_strsave( info
.font
);
2992 if( gui_ph_parse_font_name( vim_font_name
, &font_name
, &font_flags
,
2993 &font_size
) == FALSE
)
2996 font_tag
= gui_ph_get_font( font_name
, font_flags
, font_size
, 0 );
2997 if( font_tag
== NULL
)
2999 vim_free( font_name
);
3003 gui_mch_free_font( gui
.norm_font
);
3004 gui
.norm_font
= font_tag
;
3007 gui_mch_free_font( gui
.bold_font
);
3008 gui
.bold_font
= gui_ph_get_font( font_name
, font_flags
| PF_STYLE_BOLD
,
3009 font_size
, PF_STYLE_BOLD
);
3011 gui_mch_free_font( gui
.ital_font
);
3012 gui
.ital_font
= gui_ph_get_font( font_name
, font_flags
| PF_STYLE_ITALIC
,
3013 font_size
, PF_STYLE_ITALIC
);
3015 /* This extent was brought to you by the letter 'g' */
3016 PfExtentText( &extent
, NULL
, font_tag
, "g", 1 );
3018 gui
.char_width
= extent
.lr
.x
- extent
.ul
.x
+ 1;
3019 gui
.char_height
= (- extent
.ul
.y
) + extent
.lr
.y
+ 1;
3020 gui
.char_ascent
= - extent
.ul
.y
;
3022 vim_free( font_name
);
3027 * Adjust gui.char_height (after 'linespace' was changed).
3030 gui_mch_adjust_charheight(void)
3034 PfQueryFontInfo( gui
.norm_font
, &info
);
3036 gui
.char_height
= - info
.ascender
+ info
.descender
+ p_linespace
;
3037 gui
.char_ascent
= - info
.ascender
+ p_linespace
/ 2;
3043 gui_mch_get_font(char_u
*vim_font_name
, int report_error
)
3047 int_u font_size
= 12;
3048 int_u font_flags
= 0;
3050 if( gui_ph_parse_font_name( vim_font_name
, &font_name
, &font_flags
,
3051 &font_size
) != FALSE
)
3053 font_tag
= gui_ph_get_font( font_name
, font_flags
, font_size
, -1 );
3054 vim_free( font_name
);
3056 if( font_tag
!= NULL
)
3057 return( (GuiFont
) font_tag
);
3061 EMSG2(e_font
, vim_font_name
);
3066 #if defined(FEAT_EVAL) || defined(PROTO)
3068 * Return the name of font "font" in allocated memory.
3069 * Don't know how to get the actual name, thus use the provided name.
3072 gui_mch_get_fontname(font
, name
)
3078 return vim_strsave(name
);
3083 gui_mch_set_font(GuiFont font
)
3089 gui_mch_free_font(GuiFont font
)