1*84d9c625SLionel Sambuc /*-
2*84d9c625SLionel Sambuc * Copyright (c) 1999
3*84d9c625SLionel Sambuc * Sven Verdoolaege. All rights reserved.
4*84d9c625SLionel Sambuc *
5*84d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
6*84d9c625SLionel Sambuc */
7*84d9c625SLionel Sambuc
8*84d9c625SLionel Sambuc #include "config.h"
9*84d9c625SLionel Sambuc
10*84d9c625SLionel Sambuc #include <sys/types.h>
11*84d9c625SLionel Sambuc #include <sys/queue.h>
12*84d9c625SLionel Sambuc #include <bitstring.h>
13*84d9c625SLionel Sambuc
14*84d9c625SLionel Sambuc #include <sys/time.h>
15*84d9c625SLionel Sambuc #include <sys/types.h>
16*84d9c625SLionel Sambuc #include <unistd.h>
17*84d9c625SLionel Sambuc
18*84d9c625SLionel Sambuc #include "../common/common.h"
19*84d9c625SLionel Sambuc #include "../ipc/ip.h"
20*84d9c625SLionel Sambuc
21*84d9c625SLionel Sambuc #include <gtk/gtk.h>
22*84d9c625SLionel Sambuc #include "gtkvi.h"
23*84d9c625SLionel Sambuc #include "gtkviwindow.h"
24*84d9c625SLionel Sambuc #include "gtkviscreen.h"
25*84d9c625SLionel Sambuc #include "gtk_extern.h"
26*84d9c625SLionel Sambuc
27*84d9c625SLionel Sambuc static void vi_destroyed __P((GtkWidget*,GtkWidget*));
28*84d9c625SLionel Sambuc static void vi_rename __P((GtkWidget*,gchar*,GtkWidget*));
29*84d9c625SLionel Sambuc static void vi_quit __P((GtkViWindow*, int));
30*84d9c625SLionel Sambuc
31*84d9c625SLionel Sambuc static void win_toplevel(GtkViWindow *win);
32*84d9c625SLionel Sambuc static void create_toplevel(GtkVi *vi);
33*84d9c625SLionel Sambuc
34*84d9c625SLionel Sambuc static GtkItemFactoryEntry menu_items[] = {
35*84d9c625SLionel Sambuc { "/_File", NULL, NULL, 0, "<Branch>" },
36*84d9c625SLionel Sambuc { "/File/E_xit", NULL, vi_quit, 1, NULL },
37*84d9c625SLionel Sambuc { "/File/_Quit", NULL, vi_quit, 0, NULL },
38*84d9c625SLionel Sambuc { "/_Window", NULL, NULL, 0, "<Branch>" },
39*84d9c625SLionel Sambuc { "/Window/New Window", NULL, win_toplevel, 0, NULL },
40*84d9c625SLionel Sambuc #if 0 /*wrong argument anyway*/
41*84d9c625SLionel Sambuc { "/Window/Show Terminal", NULL, gtk_vi_show_term, 1, NULL },
42*84d9c625SLionel Sambuc { "/Window/Show Vi", NULL, gtk_vi_show_term, 0, NULL },
43*84d9c625SLionel Sambuc #endif
44*84d9c625SLionel Sambuc };
45*84d9c625SLionel Sambuc
46*84d9c625SLionel Sambuc static int n_toplevel = 0;
47*84d9c625SLionel Sambuc
48*84d9c625SLionel Sambuc int
main(int argc,char ** argv)49*84d9c625SLionel Sambuc main(int argc, char **argv)
50*84d9c625SLionel Sambuc {
51*84d9c625SLionel Sambuc GtkVi *vi;
52*84d9c625SLionel Sambuc
53*84d9c625SLionel Sambuc gtk_set_locale ();
54*84d9c625SLionel Sambuc
55*84d9c625SLionel Sambuc gtk_init (&argc, &argv);
56*84d9c625SLionel Sambuc
57*84d9c625SLionel Sambuc gtk_vi_init(&vi, argc, argv);
58*84d9c625SLionel Sambuc
59*84d9c625SLionel Sambuc create_toplevel(vi);
60*84d9c625SLionel Sambuc
61*84d9c625SLionel Sambuc gtk_main();
62*84d9c625SLionel Sambuc
63*84d9c625SLionel Sambuc return 0;
64*84d9c625SLionel Sambuc }
65*84d9c625SLionel Sambuc
66*84d9c625SLionel Sambuc static
win_toplevel(GtkViWindow * win)67*84d9c625SLionel Sambuc void win_toplevel(GtkViWindow *win)
68*84d9c625SLionel Sambuc {
69*84d9c625SLionel Sambuc create_toplevel(win->vi);
70*84d9c625SLionel Sambuc }
71*84d9c625SLionel Sambuc
72*84d9c625SLionel Sambuc static
create_toplevel(GtkVi * vi)73*84d9c625SLionel Sambuc void create_toplevel(GtkVi *vi)
74*84d9c625SLionel Sambuc {
75*84d9c625SLionel Sambuc GtkWidget *window;
76*84d9c625SLionel Sambuc GtkWidget *box, *menubar;
77*84d9c625SLionel Sambuc GtkWidget *vi_window;
78*84d9c625SLionel Sambuc gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
79*84d9c625SLionel Sambuc GtkItemFactory *factory;
80*84d9c625SLionel Sambuc GtkAccelGroup *accel;
81*84d9c625SLionel Sambuc
82*84d9c625SLionel Sambuc window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
83*84d9c625SLionel Sambuc ++n_toplevel;
84*84d9c625SLionel Sambuc
85*84d9c625SLionel Sambuc box = gtk_vbox_new(FALSE, 0);
86*84d9c625SLionel Sambuc gtk_container_add(GTK_CONTAINER(window), box);
87*84d9c625SLionel Sambuc gtk_widget_show(box);
88*84d9c625SLionel Sambuc
89*84d9c625SLionel Sambuc vi_window = gtk_vi_window_new(vi);
90*84d9c625SLionel Sambuc
91*84d9c625SLionel Sambuc accel = gtk_accel_group_new();
92*84d9c625SLionel Sambuc factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel);
93*84d9c625SLionel Sambuc gtk_item_factory_create_items (factory, nmenu_items, menu_items, (gpointer)vi_window);
94*84d9c625SLionel Sambuc gtk_accel_group_attach(accel, GTK_OBJECT(window));
95*84d9c625SLionel Sambuc menubar = gtk_item_factory_get_widget (factory, "<main>");
96*84d9c625SLionel Sambuc gtk_widget_show(menubar);
97*84d9c625SLionel Sambuc gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, FALSE, 0);
98*84d9c625SLionel Sambuc
99*84d9c625SLionel Sambuc gtk_accel_group_attach(accel, GTK_OBJECT(vi_window));
100*84d9c625SLionel Sambuc gtk_widget_show(vi_window);
101*84d9c625SLionel Sambuc
102*84d9c625SLionel Sambuc gtk_signal_connect(GTK_OBJECT(vi_window), "rename",
103*84d9c625SLionel Sambuc GTK_SIGNAL_FUNC(vi_rename),
104*84d9c625SLionel Sambuc window);
105*84d9c625SLionel Sambuc gtk_signal_connect(GTK_OBJECT(GTK_VI_WINDOW(vi_window)->vi_screen), "destroy",
106*84d9c625SLionel Sambuc GTK_SIGNAL_FUNC(vi_destroyed),
107*84d9c625SLionel Sambuc window);
108*84d9c625SLionel Sambuc gtk_box_pack_start(GTK_BOX(box), vi_window, TRUE, TRUE, 0);
109*84d9c625SLionel Sambuc
110*84d9c625SLionel Sambuc /*
111*84d9c625SLionel Sambuc gtk_widget_grab_focus(GTK_WIDGET(vi->vi));
112*84d9c625SLionel Sambuc */
113*84d9c625SLionel Sambuc
114*84d9c625SLionel Sambuc gtk_widget_show(window);
115*84d9c625SLionel Sambuc }
116*84d9c625SLionel Sambuc
117*84d9c625SLionel Sambuc static void
vi_quit(GtkViWindow * vi,gint write)118*84d9c625SLionel Sambuc vi_quit(GtkViWindow *vi, gint write)
119*84d9c625SLionel Sambuc {
120*84d9c625SLionel Sambuc gtk_vi_quit(vi, write);
121*84d9c625SLionel Sambuc }
122*84d9c625SLionel Sambuc
123*84d9c625SLionel Sambuc static void
vi_destroyed(GtkWidget * vi,GtkWidget * window)124*84d9c625SLionel Sambuc vi_destroyed(GtkWidget *vi, GtkWidget *window)
125*84d9c625SLionel Sambuc {
126*84d9c625SLionel Sambuc gtk_widget_destroy(window);
127*84d9c625SLionel Sambuc if (!--n_toplevel)
128*84d9c625SLionel Sambuc gtk_main_quit();
129*84d9c625SLionel Sambuc }
130*84d9c625SLionel Sambuc
131*84d9c625SLionel Sambuc static void
vi_rename(GtkWidget * vi,gchar * name,GtkWidget * window)132*84d9c625SLionel Sambuc vi_rename(GtkWidget *vi, gchar *name, GtkWidget *window)
133*84d9c625SLionel Sambuc {
134*84d9c625SLionel Sambuc gtk_window_set_title(GTK_WINDOW(window), name);
135*84d9c625SLionel Sambuc }
136