diff options
author | neoraider <devnull@localhost> | 2007-09-16 14:52:01 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-09-16 14:52:01 +0200 |
commit | 2bdbece75f9dcc9b98d7f9d5794c4b5e5f441b26 (patch) | |
tree | b7ee606f338a6f0bae32f34af6ed801c2281a083 /ui.cpp | |
parent | 61145c32c94d7b3e30c0016ea47f9e2dcb9ebbae (diff) | |
download | zoomedit-2bdbece75f9dcc9b98d7f9d5794c4b5e5f441b26.tar zoomedit-2bdbece75f9dcc9b98d7f9d5794c4b5e5f441b26.zip |
zoomedit: Kompiliert jetzt als C++-Programm
Diffstat (limited to 'ui.cpp')
-rw-r--r-- | ui.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
@@ -0,0 +1,103 @@ +#include "ui.h" +#include "draw.h" +#include "window.h" +#include <gtk/gtk.h> +#include <string.h> + + +static const gchar *uiData = +"<ui>" + "<menubar>" + "<menu action=\"fileMenu\">" + "<menuitem action=\"new\"/>" + "<menuitem action=\"open\"/>" + "<menuitem action=\"save\"/>" + "<menuitem action=\"saveAs\"/>" + "<separator/>" + "<menuitem action=\"quit\"/>" + "</menu>" + "</menubar>" + "<toolbar action=\"toolbar1\">" + "<separator/>" + "<toolitem action=\"zoomIn\"/>" + "<toolitem action=\"zoomOut\"/>" + "<separator/>" + "</toolbar>" +"</ui>"; + + +static void handleAction(GtkAction *action, gpointer user_data) { + const gchar* name = gtk_action_get_name(action); + + if(!strcmp(name, "zoomIn")) + zoomInCentered(1.2); + else if(!strcmp(name, "zoomOut")) + zoomOutCentered(1.2); +} + +static GtkActionGroup *createActions() { + GtkActionGroup *actionGroup = gtk_action_group_new("actions"); + GtkAction *action; + + action = gtk_action_new("fileMenu", "_File", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("toolbar1", "Toolbar", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("new", "_New", NULL, GTK_STOCK_NEW); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("open", "_Open", NULL, GTK_STOCK_OPEN); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("save", "_Save", NULL, GTK_STOCK_SAVE); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("saveAs", "Save _As", NULL, NULL); + gtk_action_group_add_action(actionGroup, action); + + action = gtk_action_new("zoomIn", "Zoom _in", NULL, GTK_STOCK_ZOOM_IN); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), NULL); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("zoomOut", "Zoom _out", NULL, GTK_STOCK_ZOOM_OUT); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), NULL); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + action = gtk_action_new("quit", "_Quit", NULL, GTK_STOCK_QUIT); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(gtk_main_quit), NULL); + gtk_action_group_add_action_with_accel(actionGroup, action, NULL); + + return actionGroup; +} + +static GtkUIManager* getUIManager() { + static GtkUIManager *uiManager = NULL; + + if(!uiManager) { + + + uiManager = gtk_ui_manager_new(); + gtk_ui_manager_add_ui_from_string(uiManager, uiData, -1, NULL); + + gtk_ui_manager_insert_action_group(uiManager, createActions(), 0); + + gtk_ui_manager_ensure_update(uiManager); + } + + return uiManager; +} + + +GtkWidget* getMenu() { + return gtk_ui_manager_get_widget(getUIManager(), "/ui/menubar"); +} + +GtkWidget* getToolbar() { + return gtk_ui_manager_get_widget(getUIManager(), "/ui/toolbar1"); +} + +GtkAccelGroup *getAccels() { + return gtk_ui_manager_get_accel_group(getUIManager()); +} |