1 /* change further to gtkviwindow have no knowledge of ipvi */
4 #include <gdk/gdkkeysyms.h>
8 #include <zvt/zvtterm.h>
13 #include "../common/common.h"
14 #include "../ipc/ip.h"
17 #include "gtkviscreen.h"
18 #include "gtkviwindow.h"
26 static void gtk_vi_window_class_init (GtkViWindowClass
*klass
);
27 static void gtk_vi_window_init (GtkViWindow
*vi
);
28 static void gtk_vi_window_destroy (GtkObject
*object
);
30 static int vi_key_press_event
__P((GtkWidget
*, GdkEventKey
*, GtkViWindow
*));
31 static void vi_map
__P((GtkWidget
*, GtkWidget
*));
32 static void vi_resized
__P((GtkWidget
*, int, int, IPVIWIN
*));
33 static void vi_adjustment_value_changed
__P((GtkAdjustment
*, IPVIWIN
*));
35 static void vi_input_func
__P((gpointer
, gint
, GdkInputCondition
));
37 static void vi_init_window
__P((GtkViWindow
*window
, int));
39 static int vi_addstr
__P((IPVIWIN
*, const char *, u_int32_t
));
40 static int vi_waddstr
__P((IPVIWIN
*, const CHAR_T
*, u_int32_t
));
41 static int vi_attribute
__P((IPVIWIN
*,u_int32_t
,u_int32_t
));
42 static int vi_bell
__P((IPVIWIN
*));
43 static int vi_busyon
__P((IPVIWIN
*, const char *, u_int32_t
));
44 static int vi_busyoff
__P((IPVIWIN
*));
45 static int vi_clrtoeol
__P((IPVIWIN
*));
46 static int vi_deleteln
__P((IPVIWIN
*));
47 static int vi_discard
__P((IPVIWIN
*));
48 static int vi_editopt
__P((IPVIWIN
*, const char *, u_int32_t
,
49 const char *, u_int32_t
, u_int32_t
));
50 static int vi_insertln
__P((IPVIWIN
*));
51 static int vi_move
__P((IPVIWIN
*, u_int32_t
, u_int32_t
));
52 static int vi_quit
__P((IPVIWIN
*));
53 static int vi_redraw
__P((IPVIWIN
*));
54 static int vi_refresh
__P((IPVIWIN
*));
55 static int vi_rename
__P((IPVIWIN
*, const char *, u_int32_t
));
56 static int vi_rewrite
__P((IPVIWIN
*, u_int32_t
));
57 static int vi_scrollbar
__P((IPVIWIN
*, u_int32_t
, u_int32_t
, u_int32_t
));
58 static int vi_select
__P((IPVIWIN
*, const char *, u_int32_t
));
59 static int vi_split
__P((IPVIWIN
*));
60 static int vi_ex_init
__P((IPVIWIN
*));
61 static int vi_vi_init
__P((IPVIWIN
*));
62 static int vi_fork
__P((IPVIWIN
*));
64 static GtkWidgetClass
*parent_class
= NULL
;
65 static guint vi_window_signals
[LAST_SIGNAL
] = { 0 };
68 gtk_vi_window_get_type (void)
70 static GtkType vi_window_type
= 0;
74 static const GtkTypeInfo vi_window_info
=
78 sizeof (GtkViWindowClass
),
79 (GtkClassInitFunc
) gtk_vi_window_class_init
,
80 (GtkObjectInitFunc
) gtk_vi_window_init
,
81 /* reserved_1 */ NULL
,
82 /* reserved_2 */ NULL
,
83 (GtkClassInitFunc
) NULL
,
86 vi_window_type
= gtk_type_unique (GTK_TYPE_NOTEBOOK
, &vi_window_info
);
89 return vi_window_type
;
93 gtk_vi_window_class_init (GtkViWindowClass
*class)
95 GtkObjectClass
*object_class
;
97 object_class
= (GtkObjectClass
*) class;
98 parent_class
= gtk_type_class (GTK_TYPE_WIDGET
);
100 vi_window_signals
[RENAME
] =
101 gtk_signal_new ("rename",
103 GTK_CLASS_TYPE(object_class
),
104 GTK_SIGNAL_OFFSET (GtkViScreenClass
, rename
),
105 gtk_marshal_VOID__STRING
,
106 GTK_TYPE_NONE
, 1, GTK_TYPE_STRING
, 0);
109 gtk_object_class_add_signals(object_class
, vi_window_signals
, LAST_SIGNAL
);
112 object_class
->destroy
= gtk_vi_window_destroy
;
116 gtk_vi_window_init (GtkViWindow
*vi
)
121 gtk_vi_window_new (GtkVi
*vi
)
124 GtkWidget
*vi_widget
;
133 window
= gtk_type_new(gtk_vi_window_get_type());
136 //vi->vi_window = GTK_WIDGET(window);
138 vi_widget
= gtk_vi_screen_new(NULL
);
139 gtk_widget_show(GTK_WIDGET(vi_widget
));
143 window
->vi_screen
= vi_widget
;
145 vscroll
= gtk_vscrollbar_new(GTK_VI_SCREEN(vi_widget
)->vadj
);
146 gtk_widget_show(vscroll
);
148 table
= gtk_table_new(2, 2, FALSE
);
149 gtk_table_attach_defaults(GTK_TABLE(table
), GTK_WIDGET(vi_widget
),
151 gtk_table_attach(GTK_TABLE(table
), vscroll
, 1, 2, 0, 1,
152 (GtkAttachOptions
)0, GTK_FILL
, 0, 0);
153 gtk_widget_show(table
);
154 gtk_signal_connect(GTK_OBJECT(table
), "map", GTK_SIGNAL_FUNC(vi_map
),
155 vi_widget
/*->ipvi*/);
156 window
->table
= table
;
159 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(window
), FALSE
);
160 gtk_notebook_set_show_border(GTK_NOTEBOOK(window
), FALSE
);
161 gtk_notebook_append_page(GTK_NOTEBOOK(window
), table
, NULL
);
168 term
= zvt_term_new();
169 zvt_term_set_blink(ZVT_TERM(term
), FALSE
);
170 zvt_term_get_ptys(ZVT_TERM(term
), 0, pty
);
171 fd
= pty
[1]; /* slave */
172 gtk_widget_show(term
);
173 gtk_notebook_append_page(GTK_NOTEBOOK(window
), term
, NULL
);
178 vi_init_window(window
, fd
);
180 gtk_signal_connect(GTK_OBJECT(vi_widget
), "resized",
181 GTK_SIGNAL_FUNC(vi_resized
), window
->ipviwin
);
182 gtk_signal_connect(GTK_OBJECT(vi_widget
), "key_press_event",
183 (GtkSignalFunc
) vi_key_press_event
, window
);
184 window
->value_changed
=
185 gtk_signal_connect(GTK_OBJECT(GTK_VI_SCREEN(vi_widget
)->vadj
),
187 (GtkSignalFunc
) vi_adjustment_value_changed
, window
->ipviwin
);
189 return GTK_WIDGET(window
);
193 gtk_vi_window_destroy (GtkObject
*object
)
195 GtkViWindow
*vi_window
;
197 g_return_if_fail (object
!= NULL
);
198 g_return_if_fail (GTK_IS_VI_WINDOW (object
));
200 vi_window
= (GtkViWindow
*) object
;
202 if (vi_window
->table
) {
203 gtk_signal_disconnect_by_data(GTK_OBJECT(vi_window
->table
),
204 vi_window
->vi_screen
);
205 vi_window
->table
= 0;
208 if (vi_window
->vi_screen
) {
209 gtk_signal_disconnect_by_data(GTK_OBJECT(vi_window
->vi_screen
),
211 gtk_signal_disconnect(GTK_OBJECT(GTK_VI_SCREEN(vi_window
->vi_screen
)->vadj
),
212 vi_window
->value_changed
);
213 gtk_widget_destroy(vi_window
->vi_screen
);
214 vi_window
->vi_screen
= 0;
217 GTK_OBJECT_CLASS(parent_class
)->destroy (object
);
221 gtk_vi_window_scrollbar(GtkViWindow
*vi
, guint top
, guint size
, guint max
)
223 GtkViScreen
*vi_screen
;
224 /* work around gcc bug */
225 volatile guint mymax
= max
;
226 volatile guint mysize
= size
;
228 vi_screen
= GTK_VI_SCREEN(vi
->vi_screen
);
229 vi_screen
->vadj
->value
= top
;
230 vi_screen
->vadj
->upper
= mymax
;
231 vi_screen
->vadj
->page_size
=
232 vi_screen
->vadj
->page_increment
= mysize
;
233 gtk_signal_handler_block(GTK_OBJECT(vi_screen
->vadj
), vi
->value_changed
);
234 gtk_adjustment_changed(vi_screen
->vadj
);
236 gtk_adjustment_value_changed(vi_screen->vadj);
238 gtk_signal_handler_unblock(GTK_OBJECT(vi_screen
->vadj
), vi
->value_changed
);
242 * PUBLIC: void gtk_vi_quit __P((GtkViWindow*, gint));
245 gtk_vi_quit(vi
, write
)
250 vi
->ipviwin
->wq(vi
->ipviwin
);
252 vi
->ipviwin
->quit(vi
->ipviwin
);
256 * PUBLIC: void gtk_vi_show_term __P((GtkViWindow*, gint));
259 gtk_vi_show_term(window
, show
)
263 gtk_notebook_set_page(GTK_NOTEBOOK(window
), show
? 1 : 0);
267 * PUBLIC: void gtk_vi_key_press_event __P((GtkViWindow*, GdkEventKey*));
270 gtk_vi_key_press_event(window
, event
)
279 {GDK_Home
, GTK_STRUCT_OFFSET(IPVI
, c_bol
) },
280 //{VI_C_BOTTOM, GTK_STRUCT_OFFSET(IPVI, c_bottom) },
281 {GDK_End
, GTK_STRUCT_OFFSET(IPVI
, c_eol
) },
282 {GDK_Insert
, GTK_STRUCT_OFFSET(IPVI
, c_insert
) },
283 {GDK_Left
, GTK_STRUCT_OFFSET(IPVI
, c_left
) },
284 {GDK_Right
, GTK_STRUCT_OFFSET(IPVI
, c_right
) },
285 //{VI_C_TOP, GTK_STRUCT_OFFSET(IPVI, c_top) },
296 { GDK_Page_Up
, 'B' - '@' },
297 { GDK_Page_Down
, 'F' - '@' },
299 char key
= event
->keyval
;
303 for (i
= 0; i
< sizeof(table
)/sizeof(*table
); ++i
)
304 if (table
[i
].key
== event
->keyval
) {
305 int (*fun
) __P((IPVI
*)) =
306 *(int (**) __P((IPVI
*)) )(((char *)vi
->ipvi
)+table
[i
].offset
);
311 for (i
= 0; i
< sizeof(table
)/sizeof(*table
); ++i
)
312 if (table
[i
].keyval
== event
->keyval
) {
313 window
->ipviwin
->string(window
->ipviwin
, &table
[i
].key
, 1);
317 if (event
->state
& GDK_CONTROL_MASK
) {
318 if ((key
>= 'a') && (key
<= 'z'))
323 fprintf(stderr, "key_press %d %d %d %c %p\n",
324 event->length, event->keyval, event->keyval, key, ipvi);
326 if (event
->length
> 0)
327 window
->ipviwin
->string(window
->ipviwin
, &key
, 1);
333 vi_key_press_event(vi_screen
, event
, vi
)
335 GtkWidget
*vi_screen
;
340 handled
= gtk_accel_groups_activate (GTK_OBJECT (vi
),
341 event
->keyval
, (GdkModifierType
) event
->state
);
345 gtk_vi_key_press_event(vi
, event
);
346 gtk_signal_emit_stop_by_name(GTK_OBJECT(vi_screen
), "key_press_event");
352 vi_map(table
, vi_screen
)
353 GtkWidget
*vi_screen
;
356 gtk_widget_grab_focus(vi_screen
);
360 vi_resized(vi_screen
, rows
, cols
, ipviwin
)
363 GtkWidget
*vi_screen
;
365 GtkViWindow
*vi_window
= GTK_VI_WINDOW((GtkVi
*)(ipviwin
->private_data
));
367 ipviwin
->resize(ipviwin
, rows
, cols
);
368 vi_window
->resized
= 1;
372 vi_adjustment_value_changed (adjustment
, ipviwin
)
373 GtkAdjustment
*adjustment
;
376 GtkViWindow
*vi_window
= GTK_VI_WINDOW((GtkVi
*)(ipviwin
->private_data
));
378 if (vi_window
->resized
)
379 ipviwin
->c_settop(ipviwin
, adjustment
->value
);
384 vi_input_func (gpointer data
, gint source
, GdkInputCondition condition
)
386 IPVIWIN
*ipviwin
= (IPVIWIN
*) data
;
388 (void)ipviwin
->input(ipviwin
, source
);
392 vi_init_window (GtkViWindow
*window
, int fd
)
394 static struct ip_si_operations ipsi_ops_gtk
= {
414 (IPFunc_a
)vi_waddstr
,
416 GtkVi
*vi
= window
->vi
;
418 vi
->ipvi
->new_window(vi
->ipvi
, &window
->ipviwin
, fd
);
420 window
->ipviwin
->private_data
= window
;
421 window
->ipviwin
->set_ops(window
->ipviwin
, &ipsi_ops_gtk
);
422 window
->input_func
= gtk_input_add_full(window
->ipviwin
->ifd
,
424 vi_input_func
, 0, (gpointer
)window
->ipviwin
, 0);
428 vi_addstr(ipviwin
, str
, len
)
433 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
435 gtk_vi_screen_addstr(GTK_VI_SCREEN(vi
->vi_screen
), str
, len
);
440 vi_waddstr(ipviwin
, str
, len
)
445 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
447 gtk_vi_screen_waddstr(GTK_VI_SCREEN(vi
->vi_screen
), str
, len
/sizeof(CHAR_T
));
452 vi_attribute(ipviwin
,attribute
,on
)
454 u_int32_t attribute
, on
;
456 GtkViWindow
* window
= (GtkViWindow
*)(ipviwin
->private_data
);
458 if (attribute
== SA_ALTERNATE
) {
459 gtk_vi_show_term(window
, !on
);
462 gtk_vi_screen_attribute(GTK_VI_SCREEN(window
->vi_screen
), attribute
, on
);
471 fprintf(stderr, "vi_bell\n");
476 * Future... implement visible bell.
478 XBell(XtDisplay(__vi_screen
->area
), 0);
484 vi_busyon (IPVIWIN
* ipviwin
, const char *a
, u_int32_t s
)
487 fprintf(stderr, "vi_busyon\n");
490 __vi_set_cursor(__vi_screen
, 1);
500 fprintf(stderr, "vi_busyoff\n");
503 __vi_set_cursor(__vi_screen
, 0);
512 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
514 gtk_vi_screen_clrtoel(GTK_VI_SCREEN(vi
->vi_screen
));
522 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
524 gtk_vi_screen_deleteln(GTK_VI_SCREEN(vi
->vi_screen
));
529 vi_editopt (IPVIWIN
* a
, const char *b
, u_int32_t c
,
530 const char *d
, u_int32_t e
, u_int32_t f
)
533 fprintf(stderr, "%p %p vi_editopt\n", a, a->private_data);
547 fprintf(stderr, "vi_discard\n");
559 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
561 gtk_vi_screen_insertln(GTK_VI_SCREEN(vi
->vi_screen
));
566 vi_move(ipviwin
, row
, col
)
571 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
573 gtk_vi_screen_move(GTK_VI_SCREEN(vi
->vi_screen
), row
, col
);
581 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
583 gtk_widget_draw(GTK_WIDGET(vi
->vi_screen
), NULL
);
591 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
593 gtk_vi_screen_refresh(GTK_VI_SCREEN(vi
->vi_screen
));
601 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
603 gtk_input_remove(vi
->input_func
);
604 gtk_widget_destroy(GTK_WIDGET(vi
));
609 vi_rename(ipviwin
, str
, len
)
614 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
616 gchar
* name
= g_strndup(str
, len
);
617 gtk_signal_emit_by_name(GTK_OBJECT(vi
), "rename", name
);
623 vi_rewrite(ipviwin
, row
)
627 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
629 gtk_vi_screen_rewrite(GTK_VI_SCREEN(vi
->vi_screen
), row
);
635 vi_scrollbar(ipviwin
, top
, size
, max
)
637 u_int32_t top
, size
, max
;
639 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
641 gtk_vi_window_scrollbar(vi
, top
, size
, max
);
646 static int vi_select (IPVIWIN
* a
, const char * b
, u_int32_t c
)
649 fprintf(stderr, "vi_select\n");
661 fprintf(stderr
, "vi_split\n");
672 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
675 gtk_vi_show_term(vi, 1);
684 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
687 gtk_vi_show_term(vi, 0);