2 #include "icons/guipixbufs.h"
4 MainWin::MainWin():mapwinexists(false)
6 gd_canvas=new GraphDisplayerCanvas(*this);
8 set_title ("unsaved file - " + prog_name);
9 set_default_size(WIN_WIDTH,WIN_HEIGHT);
12 //connecting signals - controller character
13 mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
15 // custom icons for the toolbar
17 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
19 Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
20 2328, gui_icons_move);
21 Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
22 2328, gui_icons_addnode);
23 Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
24 2328, gui_icons_addlink);
25 Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
26 2328, gui_icons_delete);
27 Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
28 2328, gui_icons_editlink);
29 Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
30 2328, gui_icons_editnode);
31 Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
32 2328, gui_icons_newmap);
34 Gtk::IconSource move_icon_source;
35 move_icon_source.set_pixbuf(p_move_pixbuf);
36 Gtk::IconSet move_icon_set;
37 move_icon_set.add_source(move_icon_source);
38 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
40 Gtk::IconSource addnode_icon_source;
41 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
42 Gtk::IconSet addnode_icon_set;
43 addnode_icon_set.add_source(addnode_icon_source);
44 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
46 Gtk::IconSource addlink_icon_source;
47 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
48 Gtk::IconSet addlink_icon_set;
49 addlink_icon_set.add_source(addlink_icon_source);
50 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
52 Gtk::IconSource delete_icon_source;
53 delete_icon_source.set_pixbuf(p_delete_pixbuf);
54 Gtk::IconSet delete_icon_set;
55 delete_icon_set.add_source(delete_icon_source);
56 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
58 Gtk::IconSource editlink_icon_source;
59 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
60 Gtk::IconSet editlink_icon_set;
61 editlink_icon_set.add_source(editlink_icon_source);
62 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
64 Gtk::IconSource editnode_icon_source;
65 editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
66 Gtk::IconSet editnode_icon_set;
67 editnode_icon_set.add_source(editnode_icon_source);
68 p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
70 Gtk::IconSource newmap_icon_source;
71 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
72 Gtk::IconSet newmap_icon_set;
73 newmap_icon_set.add_source(newmap_icon_source);
74 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
76 p_icon_factory->add_default();
79 ag=Gtk::ActionGroup::create();
81 ag->add( Gtk::Action::create("FileMenu", "_File") );
82 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
83 sigc::mem_fun(*this, &MainWin::newFile));
84 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
85 sigc::mem_fun(*this, &MainWin::openFile));
86 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
87 sigc::mem_fun(*this, &MainWin::saveFile));
88 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
89 sigc::mem_fun(*this, &MainWin::saveFileAs));
90 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
91 sigc::mem_fun(*this, &MainWin::close));
92 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
93 sigc::mem_fun(*this, &MainWin::hide));
95 ag->add( Gtk::Action::create("ViewMenu", "_View") );
96 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
97 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn));
98 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
99 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut));
100 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
101 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit));
102 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
103 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoom100));
105 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
106 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
107 sigc::mem_fun(*this, &MainWin::createMapWin));
109 Gtk::RadioAction::Group tool_group;
110 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
111 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) );
112 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
113 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) );
114 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
115 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) );
116 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
117 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) );
119 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
120 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) );
121 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
122 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) );
124 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
125 sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) );
127 uim=Gtk::UIManager::create();
128 uim->insert_action_group(ag);
129 add_accel_group(uim->get_accel_group());
134 Glib::ustring ui_info =
136 " <menubar name='MenuBar'>"
137 " <menu action='FileMenu'>"
138 " <menuitem action='FileNew'/>"
139 " <menuitem action='FileOpen'/>"
140 " <menuitem action='FileSave'/>"
141 " <menuitem action='FileSaveAs'/>"
142 " <menuitem action='Close'/>"
143 " <menuitem action='Quit'/>"
145 " <menu action='ViewMenu'>"
146 " <menuitem action='ViewZoomIn' />"
147 " <menuitem action='ViewZoomOut' />"
148 " <menuitem action='ViewZoom100' />"
149 " <menuitem action='ViewZoomFit' />"
151 " <menu action='ShowMenu'>"
152 " <menuitem action='ShowMaps'/>"
155 " <toolbar name='ToolBar'>"
156 " <toolitem action='FileNew' />"
157 " <toolitem action='FileOpen' />"
158 " <toolitem action='FileSave' />"
159 " <toolitem action='Close' />"
161 " <toolitem action='ViewZoomIn' />"
162 " <toolitem action='ViewZoomOut' />"
163 " <toolitem action='ViewZoom100' />"
164 " <toolitem action='ViewZoomFit' />"
166 " <toolitem action='MoveItem' />"
167 " <toolitem action='CreateNode' />"
168 " <toolitem action='CreateEdge' />"
169 " <toolitem action='EraseItem' />"
170 " <toolitem action='EditEdgeMap' />"
171 " <toolitem action='EditNodeMap' />"
173 " <toolitem action='AddMap' />"
177 uim->add_ui_from_string(ui_info);
180 catch(const Glib::Error& ex)
182 std::cerr << "building menus failed: " << ex.what();
185 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
187 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
190 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
193 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
194 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
197 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
198 pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN);
199 pScrolledWindow->add(*gd_canvas);
200 vbox.pack_start(*pScrolledWindow);
202 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
208 void MainWin::readFile(const std::string &file)
210 mapstorage.readFromFile(file);
211 mapstorage.file_name = file;
212 mapstorage.modified = false;
213 gd_canvas->drawGraph();
216 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
218 set_title(Glib::filename_display_basename(file) + " - " + prog_name);
221 void MainWin::newFile()
223 if (mapstorage.modified)
225 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
226 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
227 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
228 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
229 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
230 switch (mdialog.run())
232 case Gtk::RESPONSE_CANCEL:
234 case Gtk::RESPONSE_REJECT:
236 case Gtk::RESPONSE_ACCEPT:
245 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
247 set_title("unsaved file - " + prog_name);
250 void MainWin::openFile()
252 if (mapstorage.modified)
254 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
255 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
256 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
257 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
258 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
259 switch (mdialog.run())
261 case Gtk::RESPONSE_CANCEL:
263 case Gtk::RESPONSE_REJECT:
265 case Gtk::RESPONSE_ACCEPT:
270 Gtk::FileChooserDialog fcdialog("Open File");
271 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
272 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
273 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
277 Glib::ustring filename = fcdialog.get_filename();
278 if (!mapstorage.readFromFile(filename))
280 mapstorage.file_name = filename;
281 mapstorage.modified = false;
282 gd_canvas->drawGraph();
285 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
287 set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
292 void MainWin::saveFile()
294 if (mapstorage.file_name == "") {
299 mapstorage.writeToFile(mapstorage.file_name);
300 mapstorage.modified = false;
301 set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " +
306 void MainWin::saveFileAs()
308 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
309 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
310 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
311 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
313 Glib::ustring filename = fcdialog.get_filename();
314 mapstorage.file_name = filename;
315 mapstorage.writeToFile(filename);
316 mapstorage.modified = false;
317 set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
321 void MainWin::close()
323 if (mapstorage.modified)
325 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
326 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
327 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
328 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
329 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
330 switch (mdialog.run())
332 case Gtk::RESPONSE_CANCEL:
334 case Gtk::RESPONSE_REJECT:
336 case Gtk::RESPONSE_ACCEPT:
345 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
347 set_title("unsaved file - " + prog_name);
350 void MainWin::propertyChange(bool itisedge, int prop, std::string mapname)
352 mapstorage.changeActiveMap(itisedge, prop, mapname);
355 void MainWin::popupNewMapWin(bool itisedge, int prop)
358 (new NewMapWin("NewMapWin", *this, itisedge, false))->run();
361 std::string MainWin::getActiveEdgeMap(int prop)
363 return mapstorage.getActiveEdgeMap(prop);
366 std::string MainWin::getActiveNodeMap(int prop)
368 return mapstorage.getActiveNodeMap(prop);
371 void MainWin::registerNewEdgeMap(std::string mapname)
375 mapwin->registerNewEdgeMap(mapname);
379 void MainWin::registerNewNodeMap(std::string mapname)
383 mapwin->registerNewNodeMap(mapname);
387 void MainWin::createMapWin()
391 mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
397 void MainWin::closeMapWin()