2 #include "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("FileCloseTab", "_Close Tab"),
78 sigc::mem_fun(*this, &MainWin::closeTab));
79 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
80 sigc::mem_fun(*this, &MainWin::newFile));
81 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
82 sigc::mem_fun(*this, &MainWin::openFile));
83 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
84 sigc::mem_fun(*this, &MainWin::saveFile));
85 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
86 sigc::mem_fun(*this, &MainWin::saveFileAs));
87 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
88 sigc::mem_fun(*this, &MainWin::close));
89 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
90 sigc::mem_fun(*this, &MainWin::hide));
92 ag->add( Gtk::Action::create("ViewMenu", "_View") );
93 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
94 sigc::mem_fun(*this, &MainWin::zoomIn));
95 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
96 sigc::mem_fun(*this, &MainWin::zoomOut));
97 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
98 sigc::mem_fun(*this, &MainWin::zoomFit));
99 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
100 sigc::mem_fun(*this, &MainWin::zoom100));
102 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
103 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
104 sigc::mem_fun(*this, &MainWin::createMapWin));
106 Gtk::RadioAction::Group tool_group;
107 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
108 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
109 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
110 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
111 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
112 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
113 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
114 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
116 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
117 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
118 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
119 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
121 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
122 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
124 uim=Gtk::UIManager::create();
125 uim->insert_action_group(ag);
126 add_accel_group(uim->get_accel_group());
131 Glib::ustring ui_info =
133 " <menubar name='MenuBar'>"
134 " <menu action='FileMenu'>"
135 " <menuitem action='FileNewTab'/>"
136 " <menuitem action='FileCloseTab'/>"
137 " <menuitem action='FileNew'/>"
138 " <menuitem action='FileOpen'/>"
139 " <menuitem action='FileSave'/>"
140 " <menuitem action='FileSaveAs'/>"
141 " <menuitem action='Close'/>"
142 " <menuitem action='Quit'/>"
144 " <menu action='ViewMenu'>"
145 " <menuitem action='ViewZoomIn' />"
146 " <menuitem action='ViewZoomOut' />"
147 " <menuitem action='ViewZoom100' />"
148 " <menuitem action='ViewZoomFit' />"
150 " <menu action='ShowMenu'>"
151 " <menuitem action='ShowMaps'/>"
154 " <toolbar name='ToolBar'>"
155 " <toolitem action='FileNew' />"
156 " <toolitem action='FileOpen' />"
157 " <toolitem action='FileSave' />"
158 " <toolitem action='Close' />"
160 " <toolitem action='ViewZoomIn' />"
161 " <toolitem action='ViewZoomOut' />"
162 " <toolitem action='ViewZoom100' />"
163 " <toolitem action='ViewZoomFit' />"
165 " <toolitem action='MoveItem' />"
166 " <toolitem action='CreateNode' />"
167 " <toolitem action='CreateEdge' />"
168 " <toolitem action='EraseItem' />"
169 " <toolitem action='EditEdgeMap' />"
170 " <toolitem action='EditNodeMap' />"
172 " <toolitem action='AddMap' />"
176 uim->add_ui_from_string(ui_info);
179 catch(const Glib::Error& ex)
181 std::cerr << "building menus failed: " << ex.what();
184 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
186 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
189 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
192 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
193 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
196 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
200 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
202 vbox.pack_start(notebook);
207 void MainWin::set_tabtitle(std::string name)
209 tabnames[active_tab]=name;
210 set_title(tabnames[active_tab] + " - " + prog_name);
211 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
214 void MainWin::readFile(const std::string & filename)
217 tabs[active_tab]->readFile(filename);
220 void MainWin::newTab()
222 int size=tabs.size();
224 tabnames.resize(size+1);
226 tabs[active_tab]=new NoteBookTab();
227 tabnames[active_tab]="unsaved file";
228 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
229 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
230 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
231 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
232 notebook.set_current_page(size);
233 set_tabtitle(tabnames[active_tab]);
236 void MainWin::closeTab()
240 //tabs vector will be decreased with the deleted value
241 int size=tabs.size();
244 for(int i=active_tab+1;i<size;i++)
250 //if size==1 resize will delete the only element
253 int old_active_tab=active_tab;
254 notebook.remove_page(active_tab);
256 //If the first tab was active, upon delete notebook
257 //will first switch one tab upper and not lower like
258 //in the case, when not the first tab was active.
259 //But after deletion it will become the first tab,
260 //and this should be registrated in tabs vector,
262 if(old_active_tab==0)
267 //if this was the last page in notebook, there is
276 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
280 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
281 set_title(tabnames[active_tab]);
284 void MainWin::onCloseTab()
288 void MainWin::newFile()
292 tabs[active_tab]->newFile();
296 void MainWin::openFile()
300 tabs[active_tab]->openFile();
304 void MainWin::saveFile()
308 tabs[active_tab]->saveFile();
312 void MainWin::saveFileAs()
316 tabs[active_tab]->saveFileAs();
320 void MainWin::close()
324 tabs[active_tab]->close();
328 void MainWin::zoomIn()
332 tabs[active_tab]->gd_canvas->zoomIn();
336 void MainWin::zoomOut()
340 tabs[active_tab]->gd_canvas->zoomOut();
344 void MainWin::zoomFit()
348 tabs[active_tab]->gd_canvas->zoomFit();
352 void MainWin::zoom100()
356 tabs[active_tab]->gd_canvas->zoom100();
360 void MainWin::createMapWin()
364 tabs[active_tab]->createMapWin(tabnames[active_tab]);
368 void MainWin::changeEditorialTool(int tool)
373 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
377 void MainWin::createNewMapWin()
381 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
386 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
388 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
390 for(;nbti!=tabs.end();nbti++)
401 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);