ladanyi@1606
|
1 |
#include "main_win.h"
|
ladanyi@1442
|
2 |
|
ladanyi@1606
|
3 |
MainWin::MainWin(const std::string& title) :
|
ladanyi@1606
|
4 |
mapwin("Map Setup", mapstorage, gd_canvas),
|
hegyi@1614
|
5 |
newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin, (Gtk::Window *)this)
|
ladanyi@1442
|
6 |
{
|
ladanyi@1442
|
7 |
set_title (title);
|
ladanyi@1442
|
8 |
set_default_size(WIN_WIDTH,WIN_HEIGHT);
|
ladanyi@1442
|
9 |
add(vbox);
|
ladanyi@1442
|
10 |
|
ladanyi@1442
|
11 |
ag=Gtk::ActionGroup::create();
|
ladanyi@1442
|
12 |
|
ladanyi@1442
|
13 |
ag->add( Gtk::Action::create("FileMenu", "_File") );
|
ladanyi@1442
|
14 |
ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
|
ladanyi@1442
|
15 |
sigc::mem_fun(*this, &MainWin::newFile));
|
ladanyi@1442
|
16 |
ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
|
ladanyi@1442
|
17 |
sigc::mem_fun(*this, &MainWin::openFile));
|
ladanyi@1442
|
18 |
ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
|
ladanyi@1442
|
19 |
sigc::mem_fun(*this, &MainWin::saveFile));
|
ladanyi@1442
|
20 |
ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
|
ladanyi@1442
|
21 |
sigc::mem_fun(*this, &MainWin::saveFileAs));
|
ladanyi@1606
|
22 |
ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
|
ladanyi@1606
|
23 |
sigc::mem_fun(*this, &MainWin::close));
|
ladanyi@1606
|
24 |
ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
|
hegyi@1598
|
25 |
sigc::mem_fun(*this, &MainWin::hide));
|
ladanyi@1442
|
26 |
|
ladanyi@1442
|
27 |
ag->add( Gtk::Action::create("ViewMenu", "_View") );
|
ladanyi@1442
|
28 |
ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
|
ladanyi@1442
|
29 |
sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
|
ladanyi@1442
|
30 |
ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
|
ladanyi@1442
|
31 |
sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
|
ladanyi@1442
|
32 |
ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
|
ladanyi@1442
|
33 |
sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
|
ladanyi@1442
|
34 |
ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
|
ladanyi@1442
|
35 |
sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
|
ladanyi@1442
|
36 |
|
ladanyi@1442
|
37 |
ag->add( Gtk::Action::create("ShowMenu", "_Show") );
|
ladanyi@1442
|
38 |
ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
|
hegyi@1598
|
39 |
sigc::mem_fun(this->mapwin, &MapWin::show));
|
ladanyi@1442
|
40 |
|
ladanyi@1606
|
41 |
Gtk::RadioAction::Group tool_group;
|
ladanyi@1606
|
42 |
ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
|
ladanyi@1606
|
43 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
|
ladanyi@1606
|
44 |
ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
|
hegyi@1502
|
45 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
|
ladanyi@1606
|
46 |
ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
|
hegyi@1502
|
47 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
|
ladanyi@1606
|
48 |
ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
|
hegyi@1502
|
49 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
|
hegyi@1550
|
50 |
ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
|
hegyi@1550
|
51 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
|
hegyi@1550
|
52 |
ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
|
hegyi@1550
|
53 |
sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
|
hegyi@1592
|
54 |
ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW),
|
hegyi@1592
|
55 |
sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
|
hegyi@1502
|
56 |
|
ladanyi@1442
|
57 |
uim=Gtk::UIManager::create();
|
ladanyi@1442
|
58 |
uim->insert_action_group(ag);
|
ladanyi@1442
|
59 |
add_accel_group(uim->get_accel_group());
|
ladanyi@1442
|
60 |
|
ladanyi@1442
|
61 |
try
|
ladanyi@1442
|
62 |
{
|
ladanyi@1442
|
63 |
|
ladanyi@1442
|
64 |
Glib::ustring ui_info =
|
ladanyi@1442
|
65 |
"<ui>"
|
ladanyi@1442
|
66 |
" <menubar name='MenuBar'>"
|
ladanyi@1442
|
67 |
" <menu action='FileMenu'>"
|
ladanyi@1442
|
68 |
" <menuitem action='FileNew'/>"
|
ladanyi@1442
|
69 |
" <menuitem action='FileOpen'/>"
|
ladanyi@1442
|
70 |
" <menuitem action='FileSave'/>"
|
ladanyi@1442
|
71 |
" <menuitem action='FileSaveAs'/>"
|
ladanyi@1606
|
72 |
" <menuitem action='Close'/>"
|
ladanyi@1606
|
73 |
" <menuitem action='Quit'/>"
|
ladanyi@1442
|
74 |
" </menu>"
|
ladanyi@1442
|
75 |
" <menu action='ViewMenu'>"
|
ladanyi@1442
|
76 |
" <menuitem action='ViewZoomIn' />"
|
ladanyi@1442
|
77 |
" <menuitem action='ViewZoomOut' />"
|
ladanyi@1442
|
78 |
" <menuitem action='ViewZoomFit' />"
|
ladanyi@1442
|
79 |
" <menuitem action='ViewZoom100' />"
|
ladanyi@1442
|
80 |
" </menu>"
|
ladanyi@1442
|
81 |
" <menu action='ShowMenu'>"
|
ladanyi@1442
|
82 |
" <menuitem action='ShowMaps'/>"
|
ladanyi@1442
|
83 |
" </menu>"
|
ladanyi@1442
|
84 |
" </menubar>"
|
ladanyi@1442
|
85 |
" <toolbar name='ToolBar'>"
|
ladanyi@1442
|
86 |
" <toolitem action='FileNew' />"
|
ladanyi@1442
|
87 |
" <toolitem action='FileOpen' />"
|
ladanyi@1442
|
88 |
" <toolitem action='FileSave' />"
|
ladanyi@1606
|
89 |
" <toolitem action='Close' />"
|
ladanyi@1442
|
90 |
" <separator />"
|
ladanyi@1442
|
91 |
" <toolitem action='ViewZoomIn' />"
|
ladanyi@1442
|
92 |
" <toolitem action='ViewZoomOut' />"
|
ladanyi@1442
|
93 |
" <toolitem action='ViewZoomFit' />"
|
ladanyi@1442
|
94 |
" <toolitem action='ViewZoom100' />"
|
hegyi@1502
|
95 |
" <separator />"
|
ladanyi@1606
|
96 |
" <toolitem action='MoveItem' />"
|
hegyi@1502
|
97 |
" <toolitem action='CreateNode' />"
|
hegyi@1502
|
98 |
" <toolitem action='CreateEdge' />"
|
hegyi@1502
|
99 |
" <toolitem action='EraseItem' />"
|
hegyi@1550
|
100 |
" <toolitem action='EditEdgeMap' />"
|
hegyi@1550
|
101 |
" <toolitem action='EditNodeMap' />"
|
hegyi@1592
|
102 |
" <toolitem action='AddMap' />"
|
ladanyi@1442
|
103 |
" </toolbar>"
|
ladanyi@1442
|
104 |
"</ui>";
|
ladanyi@1442
|
105 |
|
ladanyi@1442
|
106 |
uim->add_ui_from_string(ui_info);
|
ladanyi@1442
|
107 |
|
ladanyi@1442
|
108 |
}
|
ladanyi@1442
|
109 |
catch(const Glib::Error& ex)
|
ladanyi@1442
|
110 |
{
|
ladanyi@1442
|
111 |
std::cerr << "building menus failed: " << ex.what();
|
ladanyi@1442
|
112 |
}
|
ladanyi@1442
|
113 |
|
ladanyi@1442
|
114 |
Gtk::Widget* menubar = uim->get_widget("/MenuBar");
|
ladanyi@1442
|
115 |
if (menubar){
|
ladanyi@1442
|
116 |
vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
|
ladanyi@1442
|
117 |
}
|
ladanyi@1442
|
118 |
|
ladanyi@1442
|
119 |
Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
|
ladanyi@1442
|
120 |
if (toolbar)
|
ladanyi@1442
|
121 |
{
|
ladanyi@1442
|
122 |
static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
|
ladanyi@1442
|
123 |
vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
|
ladanyi@1442
|
124 |
}
|
ladanyi@1442
|
125 |
|
ladanyi@1442
|
126 |
Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
|
ladanyi@1442
|
127 |
pScrolledWindow->add(gd_canvas);
|
ladanyi@1442
|
128 |
vbox.pack_start(*pScrolledWindow);
|
hegyi@1601
|
129 |
|
hegyi@1601
|
130 |
tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
|
hegyi@1601
|
131 |
tooltips.enable();
|
ladanyi@1442
|
132 |
|
ladanyi@1442
|
133 |
show_all_children();
|
ladanyi@1442
|
134 |
}
|
ladanyi@1442
|
135 |
|
ladanyi@1616
|
136 |
void MainWin::readFile(const std::string &file)
|
ladanyi@1616
|
137 |
{
|
ladanyi@1616
|
138 |
mapstorage.readFromFile(file);
|
ladanyi@1616
|
139 |
mapstorage.file_name = file;
|
ladanyi@1616
|
140 |
mapstorage.modified = false;
|
ladanyi@1616
|
141 |
gd_canvas.drawGraph();
|
ladanyi@1616
|
142 |
mapwin.update();
|
ladanyi@1616
|
143 |
}
|
ladanyi@1616
|
144 |
|
ladanyi@1442
|
145 |
void MainWin::newFile()
|
ladanyi@1442
|
146 |
{
|
ladanyi@1606
|
147 |
if (mapstorage.modified)
|
ladanyi@1606
|
148 |
{
|
ladanyi@1615
|
149 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
ladanyi@1615
|
150 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
ladanyi@1606
|
151 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
ladanyi@1606
|
152 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1606
|
153 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1606
|
154 |
switch (mdialog.run())
|
ladanyi@1606
|
155 |
{
|
ladanyi@1606
|
156 |
case Gtk::RESPONSE_CANCEL:
|
ladanyi@1606
|
157 |
return;
|
ladanyi@1606
|
158 |
case Gtk::RESPONSE_REJECT:
|
ladanyi@1606
|
159 |
break;
|
ladanyi@1606
|
160 |
case Gtk::RESPONSE_ACCEPT:
|
ladanyi@1606
|
161 |
saveFile();
|
ladanyi@1606
|
162 |
break;
|
ladanyi@1606
|
163 |
}
|
ladanyi@1606
|
164 |
}
|
ladanyi@1606
|
165 |
gd_canvas.clear();
|
ladanyi@1606
|
166 |
mapstorage.clear();
|
ladanyi@1606
|
167 |
mapwin.update();
|
ladanyi@1442
|
168 |
}
|
ladanyi@1442
|
169 |
|
ladanyi@1442
|
170 |
void MainWin::openFile()
|
ladanyi@1442
|
171 |
{
|
ladanyi@1606
|
172 |
if (mapstorage.modified)
|
ladanyi@1606
|
173 |
{
|
ladanyi@1615
|
174 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
ladanyi@1615
|
175 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
ladanyi@1606
|
176 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
ladanyi@1606
|
177 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1606
|
178 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1606
|
179 |
switch (mdialog.run())
|
ladanyi@1606
|
180 |
{
|
ladanyi@1606
|
181 |
case Gtk::RESPONSE_CANCEL:
|
ladanyi@1606
|
182 |
return;
|
ladanyi@1606
|
183 |
case Gtk::RESPONSE_REJECT:
|
ladanyi@1606
|
184 |
break;
|
ladanyi@1606
|
185 |
case Gtk::RESPONSE_ACCEPT:
|
ladanyi@1606
|
186 |
saveFile();
|
ladanyi@1606
|
187 |
break;
|
ladanyi@1606
|
188 |
}
|
ladanyi@1606
|
189 |
}
|
ladanyi@1606
|
190 |
gd_canvas.clear();
|
ladanyi@1606
|
191 |
mapstorage.clear();
|
ladanyi@1606
|
192 |
Gtk::FileChooserDialog fcdialog("Open File");
|
ladanyi@1606
|
193 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1606
|
194 |
fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1606
|
195 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
ladanyi@1606
|
196 |
{
|
ladanyi@1606
|
197 |
Glib::ustring filename = fcdialog.get_filename();
|
ladanyi@1606
|
198 |
mapstorage.readFromFile(filename);
|
ladanyi@1606
|
199 |
mapstorage.file_name = filename;
|
ladanyi@1606
|
200 |
mapstorage.modified = false;
|
ladanyi@1606
|
201 |
gd_canvas.drawGraph();
|
ladanyi@1606
|
202 |
mapwin.update();
|
ladanyi@1606
|
203 |
}
|
ladanyi@1442
|
204 |
}
|
ladanyi@1442
|
205 |
|
ladanyi@1442
|
206 |
void MainWin::saveFile()
|
ladanyi@1442
|
207 |
{
|
ladanyi@1606
|
208 |
if (mapstorage.file_name == "") {
|
ladanyi@1606
|
209 |
saveFileAs();
|
ladanyi@1606
|
210 |
}
|
ladanyi@1606
|
211 |
else
|
ladanyi@1606
|
212 |
{
|
ladanyi@1606
|
213 |
mapstorage.writeToFile(mapstorage.file_name);
|
ladanyi@1606
|
214 |
mapstorage.modified = false;
|
ladanyi@1606
|
215 |
}
|
ladanyi@1442
|
216 |
}
|
ladanyi@1442
|
217 |
|
ladanyi@1442
|
218 |
void MainWin::saveFileAs()
|
ladanyi@1442
|
219 |
{
|
ladanyi@1606
|
220 |
Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
|
ladanyi@1606
|
221 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1606
|
222 |
fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1606
|
223 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
ladanyi@1606
|
224 |
{
|
ladanyi@1606
|
225 |
Glib::ustring filename = fcdialog.get_filename();
|
ladanyi@1606
|
226 |
mapstorage.file_name = filename;
|
ladanyi@1606
|
227 |
mapstorage.writeToFile(filename);
|
ladanyi@1606
|
228 |
mapstorage.modified = false;
|
ladanyi@1606
|
229 |
}
|
ladanyi@1442
|
230 |
}
|
ladanyi@1606
|
231 |
|
ladanyi@1606
|
232 |
void MainWin::close()
|
ladanyi@1606
|
233 |
{
|
ladanyi@1606
|
234 |
if (mapstorage.modified)
|
ladanyi@1606
|
235 |
{
|
ladanyi@1615
|
236 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
ladanyi@1615
|
237 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
ladanyi@1606
|
238 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
ladanyi@1606
|
239 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1606
|
240 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1606
|
241 |
switch (mdialog.run())
|
ladanyi@1606
|
242 |
{
|
ladanyi@1606
|
243 |
case Gtk::RESPONSE_CANCEL:
|
ladanyi@1606
|
244 |
return;
|
ladanyi@1606
|
245 |
case Gtk::RESPONSE_REJECT:
|
ladanyi@1606
|
246 |
break;
|
ladanyi@1606
|
247 |
case Gtk::RESPONSE_ACCEPT:
|
ladanyi@1606
|
248 |
saveFile();
|
ladanyi@1606
|
249 |
break;
|
ladanyi@1606
|
250 |
}
|
ladanyi@1606
|
251 |
}
|
ladanyi@1606
|
252 |
gd_canvas.clear();
|
ladanyi@1606
|
253 |
mapstorage.clear();
|
ladanyi@1606
|
254 |
mapwin.update();
|
ladanyi@1606
|
255 |
}
|