gui/main_win.cc
author athos
Fri, 10 Jun 2005 12:50:43 +0000
changeset 1473 876c7b7f4dae
parent 1442 1e3c69aa035b
child 1502 371aba7d61ca
permissions -rw-r--r--
Some tests have been developed, bugs got fixed.
     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)
     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   uim=Gtk::UIManager::create();
    41   uim->insert_action_group(ag);
    42   add_accel_group(uim->get_accel_group());
    43 
    44   try
    45   {
    46 
    47     Glib::ustring ui_info =
    48       "<ui>"
    49       "  <menubar name='MenuBar'>"
    50       "    <menu action='FileMenu'>"
    51       "      <menuitem action='FileNew'/>"
    52       "      <menuitem action='FileOpen'/>"
    53       "      <menuitem action='FileSave'/>"
    54       "      <menuitem action='FileSaveAs'/>"
    55       "      <menuitem action='FileQuit'/>"
    56       "    </menu>"
    57       "    <menu action='ViewMenu'>"
    58       "      <menuitem action='ViewZoomIn' />"
    59       "      <menuitem action='ViewZoomOut' />"
    60       "      <menuitem action='ViewZoomFit' />"
    61       "      <menuitem action='ViewZoom100' />"
    62       "    </menu>"
    63       "    <menu action='ShowMenu'>"
    64       "      <menuitem action='ShowMaps'/>"
    65       "      <menuitem action='ShowEditorials'/>"
    66       "    </menu>"
    67       "  </menubar>"
    68       "  <toolbar name='ToolBar'>"
    69       "    <toolitem action='FileNew' />"
    70       "    <toolitem action='FileOpen' />"
    71       "    <toolitem action='FileSave' />"
    72       "    <separator />"
    73       "    <toolitem action='ViewZoomIn' />"
    74       "    <toolitem action='ViewZoomOut' />"
    75       "    <toolitem action='ViewZoomFit' />"
    76       "    <toolitem action='ViewZoom100' />"
    77       "  </toolbar>"
    78       "</ui>";
    79 
    80     uim->add_ui_from_string(ui_info);
    81 
    82   }
    83   catch(const Glib::Error& ex)
    84   {
    85     std::cerr << "building menus failed: " <<  ex.what();
    86   }
    87 
    88   Gtk::Widget* menubar = uim->get_widget("/MenuBar");
    89   if (menubar){
    90     vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
    91   }
    92 
    93   Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
    94   if (toolbar)
    95   {
    96     static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
    97     vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
    98   }
    99 
   100   Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
   101   pScrolledWindow->add(gd_canvas);
   102   vbox.pack_start(*pScrolledWindow);
   103   //vbox.pack_start(gd_canvas);
   104 
   105   show_all_children();
   106 }
   107 
   108 void MainWin::showMaps()
   109 {
   110   mapwin.show();
   111 }
   112 
   113 void MainWin::showEditorials()
   114 {
   115   editwin.show();
   116 }
   117 
   118 void MainWin::quit()
   119 {
   120   hide();
   121 }
   122 
   123 void MainWin::newFile()
   124 {
   125   std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
   126 }
   127 
   128 void MainWin::openFile()
   129 {
   130   std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
   131 }
   132 
   133 void MainWin::saveFile()
   134 {
   135   std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
   136 }
   137 
   138 void MainWin::saveFileAs()
   139 {
   140   std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
   141 }