1 #include <glibmm/i18n.h>
3 #include <libglademm/xml.h>
5 #include <gtkmm/menu.h>
6 #include <gtkmm/menuitem.h>
7 #include <gtkmm/accelkey.h>
8 #include <gtkmm/stock.h>
9 #include <gtkmm/menubar.h>
10 #include <gtkmm/menushell.h>
11 #include <gtkmm/toolbar.h>
12 #include <gtkmm/uimanager.h>
16 #include "MainWindow.h"
17 #include "TestWidget.h"
18 #include "GraphWindow.h"
22 MainWindow :: MainWindow (void) :
25 set_title (_("Main window"));
27 set_default_size (800, 600);
31 pActionGroup
= Gtk::ActionGroup::create();
32 pActionGroup
->add (Gtk::Action::create ("FileMenu", _("_File")));
33 pActionGroup
->add (Gtk::Action::create ("FileNew", Gtk::Stock::NEW
), sigc::mem_fun (*this, &MainWindow::fileNew
));
34 Glib::RefPtr
<Gtk::Action
> fileOpenAct
= Gtk::Action::create ("FileOpen", Gtk::Stock::OPEN
);//, _("_Open"), _("Open file from current path"));
35 Gtk::AccelKey
fileOpenKey ('O', Gdk::CONTROL_MASK
);
36 // ("<Control>o");('O', Gdk::CONTROL_MASK);//, "<MainWindow>/_File/Open" );
37 pActionGroup
->add ( fileOpenAct
, fileOpenKey
,
38 sigc::mem_fun (*this, &MainWindow::fileOpen
));
39 fileOpenAct
->connect_accelerator ();
40 pActionGroup
->add (Gtk::Action::create ("FileQuit", Gtk::Stock::QUIT
),
41 sigc::mem_fun (*this, &MainWindow::fileQuit
));
42 //Gtk::MenuItem fileItem (Glib::ustring(_("File")), true);
43 //menuBar.append (fileItem);
44 pActionGroup
->add (Gtk::Action::create ("EditMenu", "_Edit"));
45 pActionGroup
->add (Gtk::Action::create ("EditCut", Gtk::Stock::CUT
),
46 sigc::mem_fun (*this, &MainWindow::editCut
));
47 pActionGroup
->add (Gtk::Action::create ("EditCopy", Gtk::Stock::COPY
),
48 sigc::mem_fun (*this, &MainWindow::editCopy
));
49 pActionGroup
->add (Gtk::Action::create ("EditPaste", Gtk::Stock::PASTE
),
50 sigc::mem_fun (*this, &MainWindow::editPaste
));
54 Glib::RefPtr
<Gtk::Action
> DataAction
= Gtk::Action::create ("DataMenu", "_Data");
55 pActionGroup
->add (DataAction
, Gtk::AccelKey ("<Alt>d"));
56 Glib::RefPtr
<Gtk::Action
> DataViewAction
= Gtk::Action::create ("DataView", "_View");
57 pActionGroup
->add (DataViewAction
, Gtk::AccelKey("<Alt>v"),
58 sigc::mem_fun (*this, &MainWindow::dataView
));
59 Glib::RefPtr
<Gtk::Action
> DataGraphAction
= Gtk::Action::create ("DataGraph", "_Graph");
60 pActionGroup
->add (DataGraphAction
, Gtk::AccelKey ("<Alt>g"),
61 sigc::mem_fun (*this, &MainWindow::graphView
));
66 pActionGroup
->add (Gtk::Action::create("HelpMenu", "_Help") );
67 pActionGroup
->add (Gtk::Action::create("HelpAbout", Gtk::Stock::HELP
),
68 sigc::mem_fun(*this, &MainWindow::onHelp
));
70 pUIManager
= Gtk::UIManager::create ();
71 pUIManager
->insert_action_group (pActionGroup
);
73 add_accel_group (pUIManager
->get_accel_group());
75 Gtk::UIManager::ui_merge_id m_uid0
= pUIManager
->add_ui_from_file ("menu.xml");
76 pUIManager
->ensure_update ();
78 pMenuBar
= (Gtk::MenuBar
*)pUIManager
->get_widget("/MenuBar");
79 DataAction
->set_accel_group (this->get_accel_group());
80 DataViewAction
->set_accel_group (this->get_accel_group());
81 DataGraphAction
->set_accel_group (this->get_accel_group());
82 Gtk::MenuItem
*dataItem
= DataAction
->create_menu_item ();
83 Gtk::Menu
*dVMenu
= new Gtk::Menu ();
84 dataItem
->set_submenu (*dVMenu
);
85 Gtk::MenuItem
*dataViewItem
= DataViewAction
->create_menu_item ();
86 pMenuBar
->insert (*dataItem
, 2);
87 dVMenu
->append (*dataViewItem
);
88 Gtk::MenuItem
*dataGraphItem
= DataGraphAction
->create_menu_item ();
89 dVMenu
->append (*dataGraphItem
);
91 pToolBar
= (Gtk::Toolbar
*)pUIManager
->get_widget ("/ToolBar");
93 vBox
.pack_start (*pMenuBar
, Gtk::PACK_SHRINK
);
94 vBox
.pack_start (*pToolBar
, Gtk::PACK_SHRINK
);
95 frame
.set_size_request (-1, 500);
96 vBox
.pack_start (frame
);
97 vBox
.pack_start (statusBar
);
102 MainWindow :: ~MainWindow (void)
111 void MainWindow :: fileNew (void)
113 cout
<< __FUNCTION__
<< ' ' << "File new" << '\n';
116 void MainWindow :: fileOpen (void)
118 cout
<< __FUNCTION__
<< ' ' << "File open" << '\n';
121 void MainWindow :: fileQuit (void)
123 cout
<< __FUNCTION__
<< ' ' << "Quit" << '\n';
127 void MainWindow :: editCut (void)
129 cout
<< __FUNCTION__
<< ' ' << "Edit cut" << '\n';
132 void MainWindow :: editCopy (void)
134 cout
<< __FUNCTION__
<< ' ' << "Edit copy" << '\n';
137 void MainWindow :: editPaste (void)
139 cout
<< __FUNCTION__
<< ' ' << "Edit paste" << '\n';
142 void MainWindow :: onHelp (void)
144 cout
<< __FUNCTION__
<< ' ' << "Help" << '\n';
147 void MainWindow :: dataView (void)
149 cout
<< __FUNCTION__
<< ' ' << "Data view" << '\n';
150 TestWidget
*tWidget
= new TestWidget ();
151 tWidget
->set_modal (true);
154 Gtk::Main::run (*tWidget
);
159 void MainWindow :: graphView (void)
161 cout
<< __FUNCTION__
<< ' ' << "Graph" << std::endl
;
162 Glib::RefPtr
<Gnome::Glade::Xml
> refXml (0);
163 #ifdef GLIBMM_EXCEPTIONS_ENABLED
166 refXml
= Gnome::Glade::Xml::create ("ui/GraphWidget.glade", "GraphWindow");
168 catch (const Gnome::Glade::XmlError
& ex
)
170 std::cerr
<< ex
.what() << std::endl
;
174 std::auto_ptr
<Gnome::Glade::XmlError
> error
;
175 refXml
= Gnome::Glade::Xml::create ("ui/GraphWidget.glade", "GraphWindow", "", error
);
178 std::cerr
<< error
->what() << std::endl
;
183 refXml
->get_widget_derived ("GraphWindow", gW
);
187 Gtk::Main::run (*gW
);