3 MainWin::MainWin(const std::string& title) :
4 mapwin("Map Setup", mapstorage, gd_canvas),
5 newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin, (Gtk::Window *)this)
8 set_default_size(WIN_WIDTH,WIN_HEIGHT);
11 ag=Gtk::ActionGroup::create();
13 ag->add( Gtk::Action::create("FileMenu", "_File") );
14 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
15 sigc::mem_fun(*this, &MainWin::newFile));
16 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
17 sigc::mem_fun(*this, &MainWin::openFile));
18 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
19 sigc::mem_fun(*this, &MainWin::saveFile));
20 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
21 sigc::mem_fun(*this, &MainWin::saveFileAs));
22 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
23 sigc::mem_fun(*this, &MainWin::close));
24 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
25 sigc::mem_fun(*this, &MainWin::hide));
27 ag->add( Gtk::Action::create("ViewMenu", "_View") );
28 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
29 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
30 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
31 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
32 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
33 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
34 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
35 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
37 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
38 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
39 sigc::mem_fun(this->mapwin, &MapWin::show));
41 Gtk::RadioAction::Group tool_group;
42 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
43 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
44 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
45 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
46 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
47 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
48 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
49 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
50 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
51 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
52 ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
53 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
54 ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW),
55 sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
57 uim=Gtk::UIManager::create();
58 uim->insert_action_group(ag);
59 add_accel_group(uim->get_accel_group());
64 Glib::ustring ui_info =
66 " <menubar name='MenuBar'>"
67 " <menu action='FileMenu'>"
68 " <menuitem action='FileNew'/>"
69 " <menuitem action='FileOpen'/>"
70 " <menuitem action='FileSave'/>"
71 " <menuitem action='FileSaveAs'/>"
72 " <menuitem action='Close'/>"
73 " <menuitem action='Quit'/>"
75 " <menu action='ViewMenu'>"
76 " <menuitem action='ViewZoomIn' />"
77 " <menuitem action='ViewZoomOut' />"
78 " <menuitem action='ViewZoomFit' />"
79 " <menuitem action='ViewZoom100' />"
81 " <menu action='ShowMenu'>"
82 " <menuitem action='ShowMaps'/>"
85 " <toolbar name='ToolBar'>"
86 " <toolitem action='FileNew' />"
87 " <toolitem action='FileOpen' />"
88 " <toolitem action='FileSave' />"
89 " <toolitem action='Close' />"
91 " <toolitem action='ViewZoomIn' />"
92 " <toolitem action='ViewZoomOut' />"
93 " <toolitem action='ViewZoomFit' />"
94 " <toolitem action='ViewZoom100' />"
96 " <toolitem action='MoveItem' />"
97 " <toolitem action='CreateNode' />"
98 " <toolitem action='CreateEdge' />"
99 " <toolitem action='EraseItem' />"
100 " <toolitem action='EditEdgeMap' />"
101 " <toolitem action='EditNodeMap' />"
102 " <toolitem action='AddMap' />"
106 uim->add_ui_from_string(ui_info);
109 catch(const Glib::Error& ex)
111 std::cerr << "building menus failed: " << ex.what();
114 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
116 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
119 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
122 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
123 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
126 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
127 pScrolledWindow->add(gd_canvas);
128 vbox.pack_start(*pScrolledWindow);
130 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
136 void MainWin::readFile(const std::string &file)
138 mapstorage.readFromFile(file);
139 mapstorage.file_name = file;
140 mapstorage.modified = false;
141 gd_canvas.drawGraph();
145 void MainWin::newFile()
147 if (mapstorage.modified)
149 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
150 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
151 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
152 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
153 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
154 switch (mdialog.run())
156 case Gtk::RESPONSE_CANCEL:
158 case Gtk::RESPONSE_REJECT:
160 case Gtk::RESPONSE_ACCEPT:
170 void MainWin::openFile()
172 if (mapstorage.modified)
174 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
175 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
176 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
177 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
178 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
179 switch (mdialog.run())
181 case Gtk::RESPONSE_CANCEL:
183 case Gtk::RESPONSE_REJECT:
185 case Gtk::RESPONSE_ACCEPT:
192 Gtk::FileChooserDialog fcdialog("Open File");
193 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
194 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
195 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
197 Glib::ustring filename = fcdialog.get_filename();
198 mapstorage.readFromFile(filename);
199 mapstorage.file_name = filename;
200 mapstorage.modified = false;
201 gd_canvas.drawGraph();
206 void MainWin::saveFile()
208 if (mapstorage.file_name == "") {
213 mapstorage.writeToFile(mapstorage.file_name);
214 mapstorage.modified = false;
218 void MainWin::saveFileAs()
220 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
221 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
222 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
223 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
225 Glib::ustring filename = fcdialog.get_filename();
226 mapstorage.file_name = filename;
227 mapstorage.writeToFile(filename);
228 mapstorage.modified = false;
232 void MainWin::close()
234 if (mapstorage.modified)
236 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
237 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
238 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
239 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
240 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
241 switch (mdialog.run())
243 case Gtk::RESPONSE_CANCEL:
245 case Gtk::RESPONSE_REJECT:
247 case Gtk::RESPONSE_ACCEPT: