2 #include "icons/guipixbufs.h"
7 set_default_size(WIN_WIDTH,WIN_HEIGHT);
10 // custom icons for the toolbar
11 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
13 Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
14 2328, gui_icons_move);
15 Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
16 2328, gui_icons_addnode);
17 Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
18 2328, gui_icons_addlink);
19 Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
20 2328, gui_icons_delete);
21 Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
22 2328, gui_icons_editlink);
23 Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
24 2328, gui_icons_editnode);
25 Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
26 2328, gui_icons_newmap);
28 Gtk::IconSource move_icon_source;
29 move_icon_source.set_pixbuf(p_move_pixbuf);
30 Gtk::IconSet move_icon_set;
31 move_icon_set.add_source(move_icon_source);
32 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
34 Gtk::IconSource addnode_icon_source;
35 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
36 Gtk::IconSet addnode_icon_set;
37 addnode_icon_set.add_source(addnode_icon_source);
38 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
40 Gtk::IconSource addlink_icon_source;
41 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
42 Gtk::IconSet addlink_icon_set;
43 addlink_icon_set.add_source(addlink_icon_source);
44 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
46 Gtk::IconSource delete_icon_source;
47 delete_icon_source.set_pixbuf(p_delete_pixbuf);
48 Gtk::IconSet delete_icon_set;
49 delete_icon_set.add_source(delete_icon_source);
50 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
52 Gtk::IconSource editlink_icon_source;
53 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
54 Gtk::IconSet editlink_icon_set;
55 editlink_icon_set.add_source(editlink_icon_source);
56 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
58 Gtk::IconSource editnode_icon_source;
59 editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
60 Gtk::IconSet editnode_icon_set;
61 editnode_icon_set.add_source(editnode_icon_source);
62 p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
64 Gtk::IconSource newmap_icon_source;
65 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
66 Gtk::IconSet newmap_icon_set;
67 newmap_icon_set.add_source(newmap_icon_source);
68 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
70 p_icon_factory->add_default();
72 ag=Gtk::ActionGroup::create();
74 ag->add( Gtk::Action::create("FileMenu", "_File") );
75 ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
76 sigc::mem_fun(*this, &MainWin::newTab));
77 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
78 sigc::mem_fun(*this, &MainWin::newFile));
79 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
80 sigc::mem_fun(*this, &MainWin::openFile));
81 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
82 sigc::mem_fun(*this, &MainWin::saveFile));
83 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
84 sigc::mem_fun(*this, &MainWin::saveFileAs));
85 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
86 sigc::mem_fun(*this, &MainWin::close));
87 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
88 sigc::mem_fun(*this, &MainWin::hide));
90 ag->add( Gtk::Action::create("ViewMenu", "_View") );
91 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
92 sigc::mem_fun(*this, &MainWin::zoomIn));
93 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
94 sigc::mem_fun(*this, &MainWin::zoomOut));
95 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
96 sigc::mem_fun(*this, &MainWin::zoomFit));
97 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
98 sigc::mem_fun(*this, &MainWin::zoom100));
100 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
101 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
102 sigc::mem_fun(*this, &MainWin::createMapWin));
104 Gtk::RadioAction::Group tool_group;
105 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
106 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
107 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
108 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
109 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
110 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
111 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
112 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
114 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
115 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
116 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
117 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
119 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
120 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
122 uim=Gtk::UIManager::create();
123 uim->insert_action_group(ag);
124 add_accel_group(uim->get_accel_group());
129 Glib::ustring ui_info =
131 " <menubar name='MenuBar'>"
132 " <menu action='FileMenu'>"
133 " <menuitem action='FileNewTab'/>"
134 " <menuitem action='FileNew'/>"
135 " <menuitem action='FileOpen'/>"
136 " <menuitem action='FileSave'/>"
137 " <menuitem action='FileSaveAs'/>"
138 " <menuitem action='Close'/>"
139 " <menuitem action='Quit'/>"
141 " <menu action='ViewMenu'>"
142 " <menuitem action='ViewZoomIn' />"
143 " <menuitem action='ViewZoomOut' />"
144 " <menuitem action='ViewZoom100' />"
145 " <menuitem action='ViewZoomFit' />"
147 " <menu action='ShowMenu'>"
148 " <menuitem action='ShowMaps'/>"
151 " <toolbar name='ToolBar'>"
152 " <toolitem action='FileNew' />"
153 " <toolitem action='FileOpen' />"
154 " <toolitem action='FileSave' />"
155 " <toolitem action='Close' />"
157 " <toolitem action='ViewZoomIn' />"
158 " <toolitem action='ViewZoomOut' />"
159 " <toolitem action='ViewZoom100' />"
160 " <toolitem action='ViewZoomFit' />"
162 " <toolitem action='MoveItem' />"
163 " <toolitem action='CreateNode' />"
164 " <toolitem action='CreateEdge' />"
165 " <toolitem action='EraseItem' />"
166 " <toolitem action='EditEdgeMap' />"
167 " <toolitem action='EditNodeMap' />"
169 " <toolitem action='AddMap' />"
173 uim->add_ui_from_string(ui_info);
176 catch(const Glib::Error& ex)
178 std::cerr << "building menus failed: " << ex.what();
181 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
183 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
186 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
189 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
190 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
193 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
197 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
199 vbox.pack_start(notebook);
204 void MainWin::set_tabtitle(std::string name)
206 tabnames[active_tab]=name;
207 set_title(tabnames[active_tab] + " - " + prog_name);
208 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
211 void MainWin::readFile(const std::string & filename)
214 tabs[active_tab]->readFile(filename);
217 void MainWin::newTab()
219 int size=tabs.size();
221 tabnames.resize(size+1);
223 tabs[active_tab]=new NoteBookTab();
224 tabnames[active_tab]="unsaved file";
225 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
226 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
227 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
228 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
229 notebook.set_current_page(size);
230 set_tabtitle(tabnames[active_tab]);
233 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
237 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
238 set_title(tabnames[active_tab]);
241 void MainWin::onCloseTab()
245 void MainWin::newFile()
249 tabs[active_tab]->newFile();
253 void MainWin::openFile()
257 tabs[active_tab]->openFile();
261 void MainWin::saveFile()
265 tabs[active_tab]->saveFile();
269 void MainWin::saveFileAs()
273 tabs[active_tab]->saveFileAs();
277 void MainWin::close()
281 tabs[active_tab]->close();
285 void MainWin::zoomIn()
289 tabs[active_tab]->gd_canvas->zoomIn();
293 void MainWin::zoomOut()
297 tabs[active_tab]->gd_canvas->zoomOut();
301 void MainWin::zoomFit()
305 tabs[active_tab]->gd_canvas->zoomFit();
309 void MainWin::zoom100()
313 tabs[active_tab]->gd_canvas->zoom100();
317 void MainWin::createMapWin()
321 tabs[active_tab]->createMapWin(tabnames[active_tab]);
325 void MainWin::changeEditorialTool(int tool)
330 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
334 void MainWin::createNewMapWin()
338 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
343 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
345 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
347 for(;nbti!=tabs.end();nbti++)
358 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);