COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/main_win.cc @ 1591:03aa0a6c8dca

Last change on this file since 1591:03aa0a6c8dca was 1585:0e3ef435bdc3, checked in by Hegyi Péter, 15 years ago

Initializing adding new maps.

File size: 5.9 KB
Line 
1#include <main_win.h>
2
3MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
4    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
5{
6  set_title (title);
7  set_default_size(WIN_WIDTH,WIN_HEIGHT);
8  add(vbox);
9
10  ag=Gtk::ActionGroup::create();
11
12  ag->add( Gtk::Action::create("FileMenu", "_File") );
13  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
14      sigc::mem_fun(*this, &MainWin::newFile));
15  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
16      sigc::mem_fun(*this, &MainWin::openFile));
17  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
18      sigc::mem_fun(*this, &MainWin::saveFile));
19  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
20      sigc::mem_fun(*this, &MainWin::saveFileAs));
21  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
22      sigc::mem_fun(*this, &MainWin::quit));
23
24  ag->add( Gtk::Action::create("ViewMenu", "_View") );
25  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
26      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
27  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
28      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
29  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
30      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
31  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
32      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
33 
34  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
35  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
36      sigc::mem_fun(*this, &MainWin::showMaps));
37  ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
38      sigc::mem_fun(*this, &MainWin::showEditorials));
39
40  ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
41      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
42  ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
43      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
44  ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
45      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
46  ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
47      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
48  ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
49      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
50  ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
51      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
52  ag->add( Gtk::Action::create("AddEdgeMap", Gtk::Stock::NEW),
53      sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::addNewEdgeMap ) );
54  ag->add( Gtk::Action::create("AddNodeMap", Gtk::Stock::NEW),
55      sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::addNewNodeMap ) );
56
57  uim=Gtk::UIManager::create();
58  uim->insert_action_group(ag);
59  add_accel_group(uim->get_accel_group());
60
61  try
62  {
63
64    Glib::ustring ui_info =
65      "<ui>"
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='FileQuit'/>"
73      "    </menu>"
74      "    <menu action='ViewMenu'>"
75      "      <menuitem action='ViewZoomIn' />"
76      "      <menuitem action='ViewZoomOut' />"
77      "      <menuitem action='ViewZoomFit' />"
78      "      <menuitem action='ViewZoom100' />"
79      "    </menu>"
80      "    <menu action='ShowMenu'>"
81      "      <menuitem action='ShowMaps'/>"
82      "      <menuitem action='ShowEditorials'/>"
83      "    </menu>"
84      "  </menubar>"
85      "  <toolbar name='ToolBar'>"
86      "    <toolitem action='FileNew' />"
87      "    <toolitem action='FileOpen' />"
88      "    <toolitem action='FileSave' />"
89      "    <separator />"
90      "    <toolitem action='ViewZoomIn' />"
91      "    <toolitem action='ViewZoomOut' />"
92      "    <toolitem action='ViewZoomFit' />"
93      "    <toolitem action='ViewZoom100' />"
94      "    <separator />"
95      "    <toolitem action='CreateNode' />"
96      "    <toolitem action='CreateEdge' />"
97      "    <toolitem action='EraseItem' />"
98      "    <toolitem action='MoveItem' />"
99      "    <toolitem action='EditEdgeMap' />"
100      "    <toolitem action='EditNodeMap' />"
101      "    <toolitem action='AddEdgeMap' />"
102      "    <toolitem action='AddNodeMap' />"
103      "  </toolbar>"
104      "</ui>";
105
106    uim->add_ui_from_string(ui_info);
107
108  }
109  catch(const Glib::Error& ex)
110  {
111    std::cerr << "building menus failed: " <<  ex.what();
112  }
113
114  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
115  if (menubar){
116    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
117  }
118
119  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
120  if (toolbar)
121  {
122    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
123    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
124  }
125
126  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
127  pScrolledWindow->add(gd_canvas);
128  vbox.pack_start(*pScrolledWindow);
129  //vbox.pack_start(gd_canvas);
130
131  show_all_children();
132}
133
134void MainWin::showMaps()
135{
136  mapwin.show();
137}
138
139void MainWin::showEditorials()
140{
141  editwin.show();
142}
143
144void MainWin::quit()
145{
146  hide();
147}
148
149void MainWin::newFile()
150{
151  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
152}
153
154void MainWin::openFile()
155{
156  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
157}
158
159void MainWin::saveFile()
160{
161  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
162}
163
164void MainWin::saveFileAs()
165{
166  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
167}
Note: See TracBrowser for help on using the repository browser.