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)
9 set_default_size(WIN_WIDTH,WIN_HEIGHT);
12 ag=Gtk::ActionGroup::create();
14 ag->add( Gtk::Action::create("FileMenu", "_File") );
15 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
16 sigc::mem_fun(*this, &MainWin::newFile));
17 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
18 sigc::mem_fun(*this, &MainWin::openFile));
19 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
20 sigc::mem_fun(*this, &MainWin::saveFile));
21 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
22 sigc::mem_fun(*this, &MainWin::saveFileAs));
23 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
24 sigc::mem_fun(*this, &MainWin::close));
25 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
26 sigc::mem_fun(*this, &MainWin::hide));
28 ag->add( Gtk::Action::create("ViewMenu", "_View") );
29 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
30 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
31 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
32 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
33 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
34 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
35 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
36 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
38 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
39 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
40 sigc::mem_fun(this->mapwin, &MapWin::show));
42 Gtk::RadioAction::Group tool_group;
43 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
44 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
45 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
46 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
47 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
48 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
49 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
50 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
51 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
52 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
53 ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
54 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
55 ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW),
56 sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
58 uim=Gtk::UIManager::create();
59 uim->insert_action_group(ag);
60 add_accel_group(uim->get_accel_group());
65 Glib::ustring ui_info =
67 " <menubar name='MenuBar'>"
68 " <menu action='FileMenu'>"
69 " <menuitem action='FileNew'/>"
70 " <menuitem action='FileOpen'/>"
71 " <menuitem action='FileSave'/>"
72 " <menuitem action='FileSaveAs'/>"
73 " <menuitem action='Close'/>"
74 " <menuitem action='Quit'/>"
76 " <menu action='ViewMenu'>"
77 " <menuitem action='ViewZoomIn' />"
78 " <menuitem action='ViewZoomOut' />"
79 " <menuitem action='ViewZoomFit' />"
80 " <menuitem action='ViewZoom100' />"
82 " <menu action='ShowMenu'>"
83 " <menuitem action='ShowMaps'/>"
86 " <toolbar name='ToolBar'>"
87 " <toolitem action='FileNew' />"
88 " <toolitem action='FileOpen' />"
89 " <toolitem action='FileSave' />"
90 " <toolitem action='Close' />"
92 " <toolitem action='ViewZoomIn' />"
93 " <toolitem action='ViewZoomOut' />"
94 " <toolitem action='ViewZoomFit' />"
95 " <toolitem action='ViewZoom100' />"
97 " <toolitem action='MoveItem' />"
98 " <toolitem action='CreateNode' />"
99 " <toolitem action='CreateEdge' />"
100 " <toolitem action='EraseItem' />"
101 " <toolitem action='EditEdgeMap' />"
102 " <toolitem action='EditNodeMap' />"
103 " <toolitem action='AddMap' />"
107 uim->add_ui_from_string(ui_info);
110 catch(const Glib::Error& ex)
112 std::cerr << "building menus failed: " << ex.what();
115 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
117 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
120 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
123 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
124 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
127 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
128 pScrolledWindow->add(gd_canvas);
129 vbox.pack_start(*pScrolledWindow);
131 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
137 void MainWin::newFile()
139 if (mapstorage.modified)
141 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
143 mdialog.set_message("<b>Save changes before closing?</b>", true);
144 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
145 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
146 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
147 switch (mdialog.run())
149 case Gtk::RESPONSE_CANCEL:
151 case Gtk::RESPONSE_REJECT:
153 case Gtk::RESPONSE_ACCEPT:
163 void MainWin::openFile()
165 if (mapstorage.modified)
167 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
169 mdialog.set_message("<b>Save changes before closing?</b>", true);
170 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
171 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
172 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
173 switch (mdialog.run())
175 case Gtk::RESPONSE_CANCEL:
177 case Gtk::RESPONSE_REJECT:
179 case Gtk::RESPONSE_ACCEPT:
186 Gtk::FileChooserDialog fcdialog("Open File");
187 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
188 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
189 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
191 Glib::ustring filename = fcdialog.get_filename();
192 mapstorage.readFromFile(filename);
193 mapstorage.file_name = filename;
194 mapstorage.modified = false;
195 gd_canvas.drawGraph();
200 void MainWin::saveFile()
202 if (mapstorage.file_name == "") {
207 mapstorage.writeToFile(mapstorage.file_name);
208 mapstorage.modified = false;
212 void MainWin::saveFileAs()
214 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
215 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
216 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
217 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
219 Glib::ustring filename = fcdialog.get_filename();
220 mapstorage.file_name = filename;
221 mapstorage.writeToFile(filename);
222 mapstorage.modified = false;
226 void MainWin::close()
228 if (mapstorage.modified)
230 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
232 mdialog.set_message("<b>Save changes before closing?</b>", true);
233 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
234 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
235 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
236 switch (mdialog.run())
238 case Gtk::RESPONSE_CANCEL:
240 case Gtk::RESPONSE_REJECT:
242 case Gtk::RESPONSE_ACCEPT: