3 /* change further to gtkviwindow have no knowledge of ipvi */
6 #include <gdk/gdkkeysyms.h>
10 #include <zvt/zvtterm.h>
15 #include "../common/common.h"
16 #include "../ipc/ip.h"
19 #include "gtkviscreen.h"
20 #include "gtkviwindow.h"
28 static void gtk_vi_window_class_init (GtkViWindowClass
*klass
);
29 static void gtk_vi_window_init (GtkViWindow
*vi
);
30 static void gtk_vi_window_destroy (GtkObject
*object
);
32 static int vi_key_press_event
__P((GtkWidget
*, GdkEventKey
*, GtkViWindow
*));
33 static void vi_map
__P((GtkWidget
*, GtkWidget
*));
34 static void vi_resized
__P((GtkWidget
*, int, int, IPVIWIN
*));
35 static void vi_adjustment_value_changed
__P((GtkAdjustment
*, IPVIWIN
*));
37 static void vi_input_func
__P((gpointer
, gint
, GdkInputCondition
));
39 static void vi_init_window
__P((GtkViWindow
*window
, int));
41 static int vi_addstr
__P((IPVIWIN
*, const char *, u_int32_t
));
42 static int vi_waddstr
__P((IPVIWIN
*, const CHAR_T
*, u_int32_t
));
43 static int vi_attribute
__P((IPVIWIN
*,u_int32_t
,u_int32_t
));
44 static int vi_bell
__P((IPVIWIN
*));
45 static int vi_busyon
__P((IPVIWIN
*, const char *, u_int32_t
));
46 static int vi_busyoff
__P((IPVIWIN
*));
47 static int vi_clrtoeol
__P((IPVIWIN
*));
48 static int vi_deleteln
__P((IPVIWIN
*));
49 static int vi_discard
__P((IPVIWIN
*));
50 static int vi_editopt
__P((IPVIWIN
*, const char *, u_int32_t
,
51 const char *, u_int32_t
, u_int32_t
));
52 static int vi_insertln
__P((IPVIWIN
*));
53 static int vi_move
__P((IPVIWIN
*, u_int32_t
, u_int32_t
));
54 static int vi_quit
__P((IPVIWIN
*));
55 static int vi_redraw
__P((IPVIWIN
*));
56 static int vi_refresh
__P((IPVIWIN
*));
57 static int vi_rename
__P((IPVIWIN
*, const char *, u_int32_t
));
58 static int vi_rewrite
__P((IPVIWIN
*, u_int32_t
));
59 static int vi_scrollbar
__P((IPVIWIN
*, u_int32_t
, u_int32_t
, u_int32_t
));
60 static int vi_select
__P((IPVIWIN
*, const char *, u_int32_t
));
61 static int vi_split
__P((IPVIWIN
*));
62 static int vi_ex_init
__P((IPVIWIN
*));
63 static int vi_vi_init
__P((IPVIWIN
*));
64 static int vi_fork
__P((IPVIWIN
*));
66 static GtkWidgetClass
*parent_class
= NULL
;
67 static guint vi_window_signals
[LAST_SIGNAL
] = { 0 };
70 gtk_vi_window_get_type (void)
72 static GtkType vi_window_type
= 0;
76 static const GtkTypeInfo vi_window_info
=
80 sizeof (GtkViWindowClass
),
81 (GtkClassInitFunc
) gtk_vi_window_class_init
,
82 (GtkObjectInitFunc
) gtk_vi_window_init
,
83 /* reserved_1 */ NULL
,
84 /* reserved_2 */ NULL
,
85 (GtkClassInitFunc
) NULL
,
88 vi_window_type
= gtk_type_unique (GTK_TYPE_NOTEBOOK
, &vi_window_info
);
91 return vi_window_type
;
95 gtk_vi_window_class_init (GtkViWindowClass
*class)
97 GtkObjectClass
*object_class
;
99 object_class
= (GtkObjectClass
*) class;
100 parent_class
= gtk_type_class (GTK_TYPE_WIDGET
);
102 vi_window_signals
[RENAME
] =
103 gtk_signal_new ("rename",
105 GTK_CLASS_TYPE(object_class
),
106 GTK_SIGNAL_OFFSET (GtkViScreenClass
, rename
),
107 gtk_marshal_VOID__STRING
,
108 GTK_TYPE_NONE
, 1, GTK_TYPE_STRING
, 0);
111 gtk_object_class_add_signals(object_class
, vi_window_signals
, LAST_SIGNAL
);
114 object_class
->destroy
= gtk_vi_window_destroy
;
118 gtk_vi_window_init (GtkViWindow
*vi
)
123 gtk_vi_window_new (GtkVi
*vi
)
126 GtkWidget
*vi_widget
;
135 window
= gtk_type_new(gtk_vi_window_get_type());
138 //vi->vi_window = GTK_WIDGET(window);
140 vi_widget
= gtk_vi_screen_new(NULL
);
141 gtk_widget_show(GTK_WIDGET(vi_widget
));
145 window
->vi_screen
= vi_widget
;
147 vscroll
= gtk_vscrollbar_new(GTK_VI_SCREEN(vi_widget
)->vadj
);
148 gtk_widget_show(vscroll
);
150 table
= gtk_table_new(2, 2, FALSE
);
151 gtk_table_attach_defaults(GTK_TABLE(table
), GTK_WIDGET(vi_widget
),
153 gtk_table_attach(GTK_TABLE(table
), vscroll
, 1, 2, 0, 1,
154 (GtkAttachOptions
)0, GTK_FILL
, 0, 0);
155 gtk_widget_show(table
);
156 gtk_signal_connect(GTK_OBJECT(table
), "map", GTK_SIGNAL_FUNC(vi_map
),
157 vi_widget
/*->ipvi*/);
158 window
->table
= table
;
161 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(window
), FALSE
);
162 gtk_notebook_set_show_border(GTK_NOTEBOOK(window
), FALSE
);
163 gtk_notebook_append_page(GTK_NOTEBOOK(window
), table
, NULL
);
170 term
= zvt_term_new();
171 zvt_term_set_blink(ZVT_TERM(term
), FALSE
);
172 zvt_term_get_ptys(ZVT_TERM(term
), 0, pty
);
173 fd
= pty
[1]; /* slave */
174 gtk_widget_show(term
);
175 gtk_notebook_append_page(GTK_NOTEBOOK(window
), term
, NULL
);
180 vi_init_window(window
, fd
);
182 gtk_signal_connect(GTK_OBJECT(vi_widget
), "resized",
183 GTK_SIGNAL_FUNC(vi_resized
), window
->ipviwin
);
184 gtk_signal_connect(GTK_OBJECT(vi_widget
), "key_press_event",
185 (GtkSignalFunc
) vi_key_press_event
, window
);
186 window
->value_changed
=
187 gtk_signal_connect(GTK_OBJECT(GTK_VI_SCREEN(vi_widget
)->vadj
),
189 (GtkSignalFunc
) vi_adjustment_value_changed
, window
->ipviwin
);
191 return GTK_WIDGET(window
);
195 gtk_vi_window_destroy (GtkObject
*object
)
197 GtkViWindow
*vi_window
;
199 g_return_if_fail (object
!= NULL
);
200 g_return_if_fail (GTK_IS_VI_WINDOW (object
));
202 vi_window
= (GtkViWindow
*) object
;
204 if (vi_window
->table
) {
205 gtk_signal_disconnect_by_data(GTK_OBJECT(vi_window
->table
),
206 vi_window
->vi_screen
);
207 vi_window
->table
= 0;
210 if (vi_window
->vi_screen
) {
211 gtk_signal_disconnect_by_data(GTK_OBJECT(vi_window
->vi_screen
),
213 gtk_signal_disconnect(GTK_OBJECT(GTK_VI_SCREEN(vi_window
->vi_screen
)->vadj
),
214 vi_window
->value_changed
);
215 gtk_widget_destroy(vi_window
->vi_screen
);
216 vi_window
->vi_screen
= 0;
219 GTK_OBJECT_CLASS(parent_class
)->destroy (object
);
223 gtk_vi_window_scrollbar(GtkViWindow
*vi
, guint top
, guint size
, guint max
)
225 GtkViScreen
*vi_screen
;
226 /* work around gcc bug */
227 volatile guint mymax
= max
;
228 volatile guint mysize
= size
;
230 vi_screen
= GTK_VI_SCREEN(vi
->vi_screen
);
231 vi_screen
->vadj
->value
= top
;
232 vi_screen
->vadj
->upper
= mymax
;
233 vi_screen
->vadj
->page_size
=
234 vi_screen
->vadj
->page_increment
= mysize
;
235 gtk_signal_handler_block(GTK_OBJECT(vi_screen
->vadj
), vi
->value_changed
);
236 gtk_adjustment_changed(vi_screen
->vadj
);
238 gtk_adjustment_value_changed(vi_screen->vadj);
240 gtk_signal_handler_unblock(GTK_OBJECT(vi_screen
->vadj
), vi
->value_changed
);
244 * PUBLIC: void gtk_vi_quit __P((GtkViWindow*, gint));
247 gtk_vi_quit(vi
, write
)
252 vi
->ipviwin
->wq(vi
->ipviwin
);
254 vi
->ipviwin
->quit(vi
->ipviwin
);
258 * PUBLIC: void gtk_vi_show_term __P((GtkViWindow*, gint));
261 gtk_vi_show_term(window
, show
)
265 gtk_notebook_set_page(GTK_NOTEBOOK(window
), show
? 1 : 0);
269 * PUBLIC: void gtk_vi_key_press_event __P((GtkViWindow*, GdkEventKey*));
272 gtk_vi_key_press_event(window
, event
)
281 {GDK_Home
, GTK_STRUCT_OFFSET(IPVI
, c_bol
) },
282 //{VI_C_BOTTOM, GTK_STRUCT_OFFSET(IPVI, c_bottom) },
283 {GDK_End
, GTK_STRUCT_OFFSET(IPVI
, c_eol
) },
284 {GDK_Insert
, GTK_STRUCT_OFFSET(IPVI
, c_insert
) },
285 {GDK_Left
, GTK_STRUCT_OFFSET(IPVI
, c_left
) },
286 {GDK_Right
, GTK_STRUCT_OFFSET(IPVI
, c_right
) },
287 //{VI_C_TOP, GTK_STRUCT_OFFSET(IPVI, c_top) },
298 { GDK_Page_Up
, 'B' - '@' },
299 { GDK_Page_Down
, 'F' - '@' },
301 char key
= event
->keyval
;
305 for (i
= 0; i
< sizeof(table
)/sizeof(*table
); ++i
)
306 if (table
[i
].key
== event
->keyval
) {
307 int (*fun
) __P((IPVI
*)) =
308 *(int (**) __P((IPVI
*)) )(((char *)vi
->ipvi
)+table
[i
].offset
);
313 for (i
= 0; i
< sizeof(table
)/sizeof(*table
); ++i
)
314 if (table
[i
].keyval
== event
->keyval
) {
315 window
->ipviwin
->string(window
->ipviwin
, &table
[i
].key
, 1);
319 if (event
->state
& GDK_CONTROL_MASK
) {
320 if ((key
>= 'a') && (key
<= 'z'))
325 fprintf(stderr, "key_press %d %d %d %c %p\n",
326 event->length, event->keyval, event->keyval, key, ipvi);
328 if (event
->length
> 0)
329 window
->ipviwin
->string(window
->ipviwin
, &key
, 1);
335 vi_key_press_event(vi_screen
, event
, vi
)
337 GtkWidget
*vi_screen
;
342 handled
= gtk_accel_groups_activate (GTK_OBJECT (vi
),
343 event
->keyval
, (GdkModifierType
) event
->state
);
347 gtk_vi_key_press_event(vi
, event
);
348 gtk_signal_emit_stop_by_name(GTK_OBJECT(vi_screen
), "key_press_event");
354 vi_map(table
, vi_screen
)
355 GtkWidget
*vi_screen
;
358 gtk_widget_grab_focus(vi_screen
);
362 vi_resized(vi_screen
, rows
, cols
, ipviwin
)
365 GtkWidget
*vi_screen
;
367 GtkViWindow
*vi_window
= GTK_VI_WINDOW((GtkVi
*)(ipviwin
->private_data
));
369 ipviwin
->resize(ipviwin
, rows
, cols
);
370 vi_window
->resized
= 1;
374 vi_adjustment_value_changed (adjustment
, ipviwin
)
375 GtkAdjustment
*adjustment
;
378 GtkViWindow
*vi_window
= GTK_VI_WINDOW((GtkVi
*)(ipviwin
->private_data
));
380 if (vi_window
->resized
)
381 ipviwin
->c_settop(ipviwin
, adjustment
->value
);
386 vi_input_func (gpointer data
, gint source
, GdkInputCondition condition
)
388 IPVIWIN
*ipviwin
= (IPVIWIN
*) data
;
390 (void)ipviwin
->input(ipviwin
, source
);
394 vi_init_window (GtkViWindow
*window
, int fd
)
396 static struct ip_si_operations ipsi_ops_gtk
= {
416 (IPFunc_a
)vi_waddstr
,
418 GtkVi
*vi
= window
->vi
;
420 vi
->ipvi
->new_window(vi
->ipvi
, &window
->ipviwin
, fd
);
422 window
->ipviwin
->private_data
= window
;
423 window
->ipviwin
->set_ops(window
->ipviwin
, &ipsi_ops_gtk
);
424 window
->input_func
= gtk_input_add_full(window
->ipviwin
->ifd
,
426 vi_input_func
, 0, (gpointer
)window
->ipviwin
, 0);
430 vi_addstr(ipviwin
, str
, len
)
435 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
437 gtk_vi_screen_addstr(GTK_VI_SCREEN(vi
->vi_screen
), str
, len
);
442 vi_waddstr(ipviwin
, str
, len
)
447 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
449 gtk_vi_screen_waddstr(GTK_VI_SCREEN(vi
->vi_screen
), str
, len
/sizeof(CHAR_T
));
454 vi_attribute(ipviwin
,attribute
,on
)
456 u_int32_t attribute
, on
;
458 GtkViWindow
* window
= (GtkViWindow
*)(ipviwin
->private_data
);
460 if (attribute
== SA_ALTERNATE
) {
461 gtk_vi_show_term(window
, !on
);
464 gtk_vi_screen_attribute(GTK_VI_SCREEN(window
->vi_screen
), attribute
, on
);
473 fprintf(stderr, "vi_bell\n");
478 * Future... implement visible bell.
480 XBell(XtDisplay(__vi_screen
->area
), 0);
486 vi_busyon (IPVIWIN
* ipviwin
, const char *a
, u_int32_t s
)
489 fprintf(stderr, "vi_busyon\n");
492 __vi_set_cursor(__vi_screen
, 1);
502 fprintf(stderr, "vi_busyoff\n");
505 __vi_set_cursor(__vi_screen
, 0);
514 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
516 gtk_vi_screen_clrtoel(GTK_VI_SCREEN(vi
->vi_screen
));
524 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
526 gtk_vi_screen_deleteln(GTK_VI_SCREEN(vi
->vi_screen
));
531 vi_editopt (IPVIWIN
* a
, const char *b
, u_int32_t c
,
532 const char *d
, u_int32_t e
, u_int32_t f
)
535 fprintf(stderr, "%p %p vi_editopt\n", a, a->private_data);
549 fprintf(stderr, "vi_discard\n");
561 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
563 gtk_vi_screen_insertln(GTK_VI_SCREEN(vi
->vi_screen
));
568 vi_move(ipviwin
, row
, col
)
573 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
575 gtk_vi_screen_move(GTK_VI_SCREEN(vi
->vi_screen
), row
, col
);
583 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
585 gtk_widget_draw(GTK_WIDGET(vi
->vi_screen
), NULL
);
593 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
595 gtk_vi_screen_refresh(GTK_VI_SCREEN(vi
->vi_screen
));
603 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
605 gtk_input_remove(vi
->input_func
);
606 gtk_widget_destroy(GTK_WIDGET(vi
));
611 vi_rename(ipviwin
, str
, len
)
616 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
618 gchar
* name
= g_strndup(str
, len
);
619 gtk_signal_emit_by_name(GTK_OBJECT(vi
), "rename", name
);
625 vi_rewrite(ipviwin
, row
)
629 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
631 gtk_vi_screen_rewrite(GTK_VI_SCREEN(vi
->vi_screen
), row
);
637 vi_scrollbar(ipviwin
, top
, size
, max
)
639 u_int32_t top
, size
, max
;
641 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
643 gtk_vi_window_scrollbar(vi
, top
, size
, max
);
648 static int vi_select (IPVIWIN
* a
, const char * b
, u_int32_t c
)
651 fprintf(stderr, "vi_select\n");
663 fprintf(stderr
, "vi_split\n");
674 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
677 gtk_vi_show_term(vi, 1);
686 GtkViWindow
* vi
= (GtkViWindow
*)(ipviwin
->private_data
);
689 gtk_vi_show_term(vi, 0);