icc need this...
... and she's right.
2 #include "guipixbufs.h"
4 MainWin::MainWin(const std::string& title) :
5 mapwin("Map Setup", mapstorage, gd_canvas),
6 newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin, (Gtk::Window *)this)
9 set_default_size(WIN_WIDTH,WIN_HEIGHT);
13 // custom icons for the toolbar
15 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
17 Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
18 2328, gui_icons_move);
19 Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
20 2328, gui_icons_addnode);
21 Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
22 2328, gui_icons_addlink);
23 Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
24 2328, gui_icons_delete);
25 Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
26 2328, gui_icons_editlink);
27 Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
28 2328, gui_icons_editnode);
29 Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
30 2328, gui_icons_newmap);
32 Gtk::IconSource move_icon_source;
33 move_icon_source.set_pixbuf(p_move_pixbuf);
34 Gtk::IconSet move_icon_set;
35 move_icon_set.add_source(move_icon_source);
36 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
38 Gtk::IconSource addnode_icon_source;
39 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
40 Gtk::IconSet addnode_icon_set;
41 addnode_icon_set.add_source(addnode_icon_source);
42 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
44 Gtk::IconSource addlink_icon_source;
45 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
46 Gtk::IconSet addlink_icon_set;
47 addlink_icon_set.add_source(addlink_icon_source);
48 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
50 Gtk::IconSource delete_icon_source;
51 delete_icon_source.set_pixbuf(p_delete_pixbuf);
52 Gtk::IconSet delete_icon_set;
53 delete_icon_set.add_source(delete_icon_source);
54 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
56 Gtk::IconSource editlink_icon_source;
57 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
58 Gtk::IconSet editlink_icon_set;
59 editlink_icon_set.add_source(editlink_icon_source);
60 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
62 Gtk::IconSource editnode_icon_source;
63 editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
64 Gtk::IconSet editnode_icon_set;
65 editnode_icon_set.add_source(editnode_icon_source);
66 p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
68 Gtk::IconSource newmap_icon_source;
69 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
70 Gtk::IconSet newmap_icon_set;
71 newmap_icon_set.add_source(newmap_icon_source);
72 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
74 p_icon_factory->add_default();
77 ag=Gtk::ActionGroup::create();
79 ag->add( Gtk::Action::create("FileMenu", "_File") );
80 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
81 sigc::mem_fun(*this, &MainWin::newFile));
82 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
83 sigc::mem_fun(*this, &MainWin::openFile));
84 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
85 sigc::mem_fun(*this, &MainWin::saveFile));
86 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
87 sigc::mem_fun(*this, &MainWin::saveFileAs));
88 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
89 sigc::mem_fun(*this, &MainWin::close));
90 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
91 sigc::mem_fun(*this, &MainWin::hide));
93 ag->add( Gtk::Action::create("ViewMenu", "_View") );
94 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
95 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
96 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
97 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
98 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
99 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
100 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
101 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
103 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
104 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
105 sigc::mem_fun(this->mapwin, &MapWin::show));
107 Gtk::RadioAction::Group tool_group;
108 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
109 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
110 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
111 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
112 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
113 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
114 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
115 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
117 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
118 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
119 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
120 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
122 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
123 sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
125 uim=Gtk::UIManager::create();
126 uim->insert_action_group(ag);
127 add_accel_group(uim->get_accel_group());
132 Glib::ustring ui_info =
134 " <menubar name='MenuBar'>"
135 " <menu action='FileMenu'>"
136 " <menuitem action='FileNew'/>"
137 " <menuitem action='FileOpen'/>"
138 " <menuitem action='FileSave'/>"
139 " <menuitem action='FileSaveAs'/>"
140 " <menuitem action='Close'/>"
141 " <menuitem action='Quit'/>"
143 " <menu action='ViewMenu'>"
144 " <menuitem action='ViewZoomIn' />"
145 " <menuitem action='ViewZoomOut' />"
146 " <menuitem action='ViewZoomFit' />"
147 " <menuitem action='ViewZoom100' />"
149 " <menu action='ShowMenu'>"
150 " <menuitem action='ShowMaps'/>"
153 " <toolbar name='ToolBar'>"
154 " <toolitem action='FileNew' />"
155 " <toolitem action='FileOpen' />"
156 " <toolitem action='FileSave' />"
157 " <toolitem action='Close' />"
159 " <toolitem action='ViewZoomIn' />"
160 " <toolitem action='ViewZoomOut' />"
161 " <toolitem action='ViewZoomFit' />"
162 " <toolitem action='ViewZoom100' />"
164 " <toolitem action='MoveItem' />"
165 " <toolitem action='CreateNode' />"
166 " <toolitem action='CreateEdge' />"
167 " <toolitem action='EraseItem' />"
168 " <toolitem action='EditEdgeMap' />"
169 " <toolitem action='EditNodeMap' />"
171 " <toolitem action='AddMap' />"
175 uim->add_ui_from_string(ui_info);
178 catch(const Glib::Error& ex)
180 std::cerr << "building menus failed: " << ex.what();
183 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
185 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
188 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
191 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
192 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
195 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
196 pScrolledWindow->add(gd_canvas);
197 vbox.pack_start(*pScrolledWindow);
199 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
205 void MainWin::readFile(const std::string &file)
207 mapstorage.readFromFile(file);
208 mapstorage.file_name = file;
209 mapstorage.modified = false;
210 gd_canvas.drawGraph();
214 void MainWin::newFile()
216 if (mapstorage.modified)
218 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
219 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
220 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
221 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
222 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
223 switch (mdialog.run())
225 case Gtk::RESPONSE_CANCEL:
227 case Gtk::RESPONSE_REJECT:
229 case Gtk::RESPONSE_ACCEPT:
239 void MainWin::openFile()
241 if (mapstorage.modified)
243 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
244 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
245 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
246 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
247 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
248 switch (mdialog.run())
250 case Gtk::RESPONSE_CANCEL:
252 case Gtk::RESPONSE_REJECT:
254 case Gtk::RESPONSE_ACCEPT:
261 Gtk::FileChooserDialog fcdialog("Open File");
262 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
263 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
264 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
266 Glib::ustring filename = fcdialog.get_filename();
267 mapstorage.readFromFile(filename);
268 mapstorage.file_name = filename;
269 mapstorage.modified = false;
270 gd_canvas.drawGraph();
275 void MainWin::saveFile()
277 if (mapstorage.file_name == "") {
282 mapstorage.writeToFile(mapstorage.file_name);
283 mapstorage.modified = false;
287 void MainWin::saveFileAs()
289 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
290 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
291 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
292 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
294 Glib::ustring filename = fcdialog.get_filename();
295 mapstorage.file_name = filename;
296 mapstorage.writeToFile(filename);
297 mapstorage.modified = false;
301 void MainWin::close()
303 if (mapstorage.modified)
305 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
306 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
307 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
308 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
309 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
310 switch (mdialog.run())
312 case Gtk::RESPONSE_CANCEL:
314 case Gtk::RESPONSE_REJECT:
316 case Gtk::RESPONSE_ACCEPT: