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::newFile()
138 if (mapstorage.modified)
140 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
141 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
142 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
143 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
144 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
145 switch (mdialog.run())
147 case Gtk::RESPONSE_CANCEL:
149 case Gtk::RESPONSE_REJECT:
151 case Gtk::RESPONSE_ACCEPT:
161 void MainWin::openFile()
163 if (mapstorage.modified)
165 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
166 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
167 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
168 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
169 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
170 switch (mdialog.run())
172 case Gtk::RESPONSE_CANCEL:
174 case Gtk::RESPONSE_REJECT:
176 case Gtk::RESPONSE_ACCEPT:
183 Gtk::FileChooserDialog fcdialog("Open File");
184 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
185 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
186 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
188 Glib::ustring filename = fcdialog.get_filename();
189 mapstorage.readFromFile(filename);
190 mapstorage.file_name = filename;
191 mapstorage.modified = false;
192 gd_canvas.drawGraph();
197 void MainWin::saveFile()
199 if (mapstorage.file_name == "") {
204 mapstorage.writeToFile(mapstorage.file_name);
205 mapstorage.modified = false;
209 void MainWin::saveFileAs()
211 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
212 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
213 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
214 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
216 Glib::ustring filename = fcdialog.get_filename();
217 mapstorage.file_name = filename;
218 mapstorage.writeToFile(filename);
219 mapstorage.modified = false;
223 void MainWin::close()
225 if (mapstorage.modified)
227 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
228 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
229 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
230 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
231 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
232 switch (mdialog.run())
234 case Gtk::RESPONSE_CANCEL:
236 case Gtk::RESPONSE_REJECT:
238 case Gtk::RESPONSE_ACCEPT: