gui/main_win.cc
author hegyi
Fri, 22 Jul 2005 11:04:27 +0000
changeset 1581 9bb83c7f479b
parent 1512 e54392395480
child 1585 0e3ef435bdc3
permissions -rw-r--r--
There were bugs, created yesterday, and there is still one. (I hope only one :) )
     1 #include <main_win.h>
     2 
     3 MainWin::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 
    53   uim=Gtk::UIManager::create();
    54   uim->insert_action_group(ag);
    55   add_accel_group(uim->get_accel_group());
    56 
    57   try
    58   {
    59 
    60     Glib::ustring ui_info =
    61       "<ui>"
    62       "  <menubar name='MenuBar'>"
    63       "    <menu action='FileMenu'>"
    64       "      <menuitem action='FileNew'/>"
    65       "      <menuitem action='FileOpen'/>"
    66       "      <menuitem action='FileSave'/>"
    67       "      <menuitem action='FileSaveAs'/>"
    68       "      <menuitem action='FileQuit'/>"
    69       "    </menu>"
    70       "    <menu action='ViewMenu'>"
    71       "      <menuitem action='ViewZoomIn' />"
    72       "      <menuitem action='ViewZoomOut' />"
    73       "      <menuitem action='ViewZoomFit' />"
    74       "      <menuitem action='ViewZoom100' />"
    75       "    </menu>"
    76       "    <menu action='ShowMenu'>"
    77       "      <menuitem action='ShowMaps'/>"
    78       "      <menuitem action='ShowEditorials'/>"
    79       "    </menu>"
    80       "  </menubar>"
    81       "  <toolbar name='ToolBar'>"
    82       "    <toolitem action='FileNew' />"
    83       "    <toolitem action='FileOpen' />"
    84       "    <toolitem action='FileSave' />"
    85       "    <separator />"
    86       "    <toolitem action='ViewZoomIn' />"
    87       "    <toolitem action='ViewZoomOut' />"
    88       "    <toolitem action='ViewZoomFit' />"
    89       "    <toolitem action='ViewZoom100' />"
    90       "    <separator />"
    91       "    <toolitem action='CreateNode' />"
    92       "    <toolitem action='CreateEdge' />"
    93       "    <toolitem action='EraseItem' />"
    94       "    <toolitem action='MoveItem' />"
    95       "    <toolitem action='EditEdgeMap' />"
    96       "    <toolitem action='EditNodeMap' />"
    97       "  </toolbar>"
    98       "</ui>";
    99 
   100     uim->add_ui_from_string(ui_info);
   101 
   102   }
   103   catch(const Glib::Error& ex)
   104   {
   105     std::cerr << "building menus failed: " <<  ex.what();
   106   }
   107 
   108   Gtk::Widget* menubar = uim->get_widget("/MenuBar");
   109   if (menubar){
   110     vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
   111   }
   112 
   113   Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
   114   if (toolbar)
   115   {
   116     static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
   117     vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
   118   }
   119 
   120   Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
   121   pScrolledWindow->add(gd_canvas);
   122   vbox.pack_start(*pScrolledWindow);
   123   //vbox.pack_start(gd_canvas);
   124 
   125   show_all_children();
   126 }
   127 
   128 void MainWin::showMaps()
   129 {
   130   mapwin.show();
   131 }
   132 
   133 void MainWin::showEditorials()
   134 {
   135   editwin.show();
   136 }
   137 
   138 void MainWin::quit()
   139 {
   140   hide();
   141 }
   142 
   143 void MainWin::newFile()
   144 {
   145   std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
   146 }
   147 
   148 void MainWin::openFile()
   149 {
   150   std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
   151 }
   152 
   153 void MainWin::saveFile()
   154 {
   155   std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
   156 }
   157 
   158 void MainWin::saveFileAs()
   159 {
   160   std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
   161 }