1 /* This file contains utility functions to create what would be a typical "main
2 * window" for an application.
6 * Measurements happen from the start of the destruction of the last window. Use
7 * GTimer rather than X timestamps to fix this (it uses gettimeofday() internally!)
9 * Make non-interactive as well by using the above.
19 quit_cb (GtkWidget *widget, gpointer data)
25 noop_cb (GtkWidget *widget, gpointer data)
30 static const GtkActionEntry menu_action_entries[] = {
31 { "FileMenu", NULL, "_File" },
32 { "EditMenu", NULL, "_Edit" },
33 { "ViewMenu", NULL, "_View" },
34 { "HelpMenu", NULL, "_Help" },
36 { "New", GTK_STOCK_NEW, "_New", "<control>N", "Create a new document", G_CALLBACK (noop_cb) },
37 { "Open", GTK_STOCK_OPEN, "_Open", "<control>O", "Open a file", G_CALLBACK (noop_cb) },
38 { "Save", GTK_STOCK_SAVE, "_Save", "<control>S", "Save the document", G_CALLBACK (noop_cb) },
39 { "SaveAs", GTK_STOCK_SAVE_AS, "Save _As...", NULL, "Save the document with a different name", NULL},
40 { "PrintPreview", GTK_STOCK_PRINT_PREVIEW, "Print Previe_w", NULL, "See how the document will be printed", G_CALLBACK (noop_cb) },
41 { "Print", GTK_STOCK_PRINT, "_Print", "<control>P", "Print the document", G_CALLBACK (noop_cb) },
42 { "Close", GTK_STOCK_CLOSE, "_Close", "<control>W", "Close the document", G_CALLBACK (noop_cb) },
43 { "Quit", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Quit the program", G_CALLBACK (quit_cb) },
45 { "Undo", GTK_STOCK_UNDO, "_Undo", "<control>Z", "Undo the last action", G_CALLBACK (noop_cb) },
46 { "Redo", GTK_STOCK_REDO, "_Redo", "<control>Y", "Redo the last action", G_CALLBACK (noop_cb) },
47 { "Cut", GTK_STOCK_CUT, "Cu_t", "<control>X", "Cut the selection to the clipboard", G_CALLBACK (noop_cb) },
48 { "Copy", GTK_STOCK_COPY, "_Copy", "<control>C", "Copy the selection to the clipboard", G_CALLBACK (noop_cb) },
49 { "Paste", GTK_STOCK_PASTE, "_Paste", "<control>V", "Paste the contents of the clipboard", G_CALLBACK (noop_cb) },
50 { "Delete", GTK_STOCK_DELETE, "_Delete", "Delete", "Delete the selection", G_CALLBACK (noop_cb) },
51 { "SelectAll", NULL, "Select _All", "<control>A", "Select the whole document", G_CALLBACK (noop_cb) },
52 { "Preferences", GTK_STOCK_PREFERENCES, "Pr_eferences", NULL, "Configure the application", G_CALLBACK (noop_cb) },
54 { "ZoomFit", GTK_STOCK_ZOOM_FIT, "Zoom to _Fit", NULL, "Zoom the document to fit the window", G_CALLBACK (noop_cb) },
55 { "Zoom100", GTK_STOCK_ZOOM_100, "Zoom _1:1", NULL, "Zoom to 1:1 scale", G_CALLBACK (noop_cb) },
56 { "ZoomIn", GTK_STOCK_ZOOM_IN, "Zoom _In", NULL, "Zoom into the document", G_CALLBACK (noop_cb) },
57 { "ZoomOut", GTK_STOCK_ZOOM_OUT, "Zoom _Out", NULL, "Zoom away from the document", G_CALLBACK (noop_cb) },
58 { "FullScreen", GTK_STOCK_FULLSCREEN, "Full _Screen", "F11", "Use the whole screen to view the document", G_CALLBACK (noop_cb) },
60 { "HelpContents", GTK_STOCK_HELP, "_Contents", "F1", "Show the table of contents for the help system", G_CALLBACK (noop_cb) },
61 { "About", GTK_STOCK_ABOUT, "_About", NULL, "About this application", G_CALLBACK (noop_cb) }
64 static const char ui_description[] =
66 " <menubar name=\"MainMenu\">"
67 " <menu action=\"FileMenu\">"
68 " <menuitem action=\"New\"/>"
69 " <menuitem action=\"Open\"/>"
70 " <menuitem action=\"Save\"/>"
71 " <menuitem action=\"SaveAs\"/>"
73 " <menuitem action=\"PrintPreview\"/>"
74 " <menuitem action=\"Print\"/>"
76 " <menuitem action=\"Close\"/>"
77 " <menuitem action=\"Quit\"/>"
79 " <menu action=\"EditMenu\">"
80 " <menuitem action=\"Undo\"/>"
81 " <menuitem action=\"Redo\"/>"
83 " <menuitem action=\"Cut\"/>"
84 " <menuitem action=\"Copy\"/>"
85 " <menuitem action=\"Paste\"/>"
86 " <menuitem action=\"Delete\"/>"
88 " <menuitem action=\"SelectAll\"/>"
90 " <menuitem action=\"Preferences\"/>"
92 " <menu action=\"ViewMenu\">"
93 " <menuitem action=\"ZoomFit\"/>"
94 " <menuitem action=\"Zoom100\"/>"
95 " <menuitem action=\"ZoomIn\"/>"
96 " <menuitem action=\"ZoomOut\"/>"
98 " <menuitem action=\"FullScreen\"/>"
100 " <menu action=\"HelpMenu\">"
101 " <menuitem action=\"HelpContents\"/>"
102 " <menuitem action=\"About\"/>"
105 " <toolbar name=\"MainToolbar\">"
106 " <toolitem action=\"New\"/>"
107 " <toolitem action=\"Open\"/>"
108 " <toolitem action=\"Save\"/>"
110 " <toolitem action=\"Print\"/>"
112 " <toolitem action=\"Undo\"/>"
113 " <toolitem action=\"Redo\"/>"
115 " <toolitem action=\"Cut\"/>"
116 " <toolitem action=\"Copy\"/>"
117 " <toolitem action=\"Paste\"/>"
121 static GtkUIManager *
125 GtkActionGroup *action_group;
128 ui = gtk_ui_manager_new ();
130 action_group = gtk_action_group_new ("Actions");
131 gtk_action_group_add_actions (action_group, menu_action_entries, G_N_ELEMENTS (menu_action_entries), NULL);
133 gtk_ui_manager_insert_action_group (ui, action_group, 0);
134 g_object_unref (action_group);
137 if (!gtk_ui_manager_add_ui_from_string (ui, ui_description, -1, &error))
138 g_error ("Could not parse the uimanager XML: %s", error->message);
144 menubar_new (GtkUIManager *ui)
146 return gtk_ui_manager_get_widget (ui, "/MainMenu");
150 toolbar_new (GtkUIManager *ui)
152 return gtk_ui_manager_get_widget (ui, "/MainToolbar");
156 drawing_area_new (void)
160 darea = gtk_drawing_area_new ();
161 gtk_widget_set_size_request (darea, 640, 480);
166 content_area_new (void)
170 notebook = gtk_notebook_new ();
172 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
174 gtk_label_new ("First"));
176 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
178 gtk_label_new ("Second"));
180 gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
182 gtk_label_new ("Third"));
188 status_bar_new (void)
190 return gtk_statusbar_new ();
194 delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
208 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
209 gtk_window_set_title (GTK_WINDOW (window), "Main window");
210 g_signal_connect (window, "delete-event",
211 G_CALLBACK (delete_event_cb), NULL);
213 ui = uimanager_new ();
214 g_signal_connect_swapped (window, "destroy",
215 G_CALLBACK (g_object_unref), ui);
217 vbox = gtk_vbox_new (FALSE, 0);
218 gtk_container_add (GTK_CONTAINER (window), vbox);
220 widget = menubar_new (ui);
221 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
223 widget = toolbar_new (ui);
224 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
226 widget = content_area_new ();
227 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
229 widget = status_bar_new ();
230 gtk_box_pack_end (GTK_BOX (vbox), widget, FALSE, FALSE, 0);