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