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.
ladanyi@1442
     1
#include <main_win.h>
ladanyi@1442
     2
ladanyi@1442
     3
MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
hegyi@1468
     4
    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
ladanyi@1442
     5
{
ladanyi@1442
     6
  set_title (title);
ladanyi@1442
     7
  set_default_size(WIN_WIDTH,WIN_HEIGHT);
ladanyi@1442
     8
  add(vbox);
ladanyi@1442
     9
ladanyi@1442
    10
  ag=Gtk::ActionGroup::create();
ladanyi@1442
    11
ladanyi@1442
    12
  ag->add( Gtk::Action::create("FileMenu", "_File") );
ladanyi@1442
    13
  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
ladanyi@1442
    14
      sigc::mem_fun(*this, &MainWin::newFile));
ladanyi@1442
    15
  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
ladanyi@1442
    16
      sigc::mem_fun(*this, &MainWin::openFile));
ladanyi@1442
    17
  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
ladanyi@1442
    18
      sigc::mem_fun(*this, &MainWin::saveFile));
ladanyi@1442
    19
  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
ladanyi@1442
    20
      sigc::mem_fun(*this, &MainWin::saveFileAs));
ladanyi@1442
    21
  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
ladanyi@1442
    22
      sigc::mem_fun(*this, &MainWin::quit));
ladanyi@1442
    23
ladanyi@1442
    24
  ag->add( Gtk::Action::create("ViewMenu", "_View") );
ladanyi@1442
    25
  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
ladanyi@1442
    26
      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
ladanyi@1442
    27
  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
ladanyi@1442
    28
      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
ladanyi@1442
    29
  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
ladanyi@1442
    30
      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
ladanyi@1442
    31
  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
ladanyi@1442
    32
      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
ladanyi@1442
    33
  
ladanyi@1442
    34
  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
ladanyi@1442
    35
  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
ladanyi@1442
    36
      sigc::mem_fun(*this, &MainWin::showMaps));
hegyi@1468
    37
  ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
hegyi@1468
    38
      sigc::mem_fun(*this, &MainWin::showEditorials));
ladanyi@1442
    39
ladanyi@1442
    40
  uim=Gtk::UIManager::create();
ladanyi@1442
    41
  uim->insert_action_group(ag);
ladanyi@1442
    42
  add_accel_group(uim->get_accel_group());
ladanyi@1442
    43
ladanyi@1442
    44
  try
ladanyi@1442
    45
  {
ladanyi@1442
    46
ladanyi@1442
    47
    Glib::ustring ui_info =
ladanyi@1442
    48
      "<ui>"
ladanyi@1442
    49
      "  <menubar name='MenuBar'>"
ladanyi@1442
    50
      "    <menu action='FileMenu'>"
ladanyi@1442
    51
      "      <menuitem action='FileNew'/>"
ladanyi@1442
    52
      "      <menuitem action='FileOpen'/>"
ladanyi@1442
    53
      "      <menuitem action='FileSave'/>"
ladanyi@1442
    54
      "      <menuitem action='FileSaveAs'/>"
ladanyi@1442
    55
      "      <menuitem action='FileQuit'/>"
ladanyi@1442
    56
      "    </menu>"
ladanyi@1442
    57
      "    <menu action='ViewMenu'>"
ladanyi@1442
    58
      "      <menuitem action='ViewZoomIn' />"
ladanyi@1442
    59
      "      <menuitem action='ViewZoomOut' />"
ladanyi@1442
    60
      "      <menuitem action='ViewZoomFit' />"
ladanyi@1442
    61
      "      <menuitem action='ViewZoom100' />"
ladanyi@1442
    62
      "    </menu>"
ladanyi@1442
    63
      "    <menu action='ShowMenu'>"
ladanyi@1442
    64
      "      <menuitem action='ShowMaps'/>"
hegyi@1468
    65
      "      <menuitem action='ShowEditorials'/>"
ladanyi@1442
    66
      "    </menu>"
ladanyi@1442
    67
      "  </menubar>"
ladanyi@1442
    68
      "  <toolbar name='ToolBar'>"
ladanyi@1442
    69
      "    <toolitem action='FileNew' />"
ladanyi@1442
    70
      "    <toolitem action='FileOpen' />"
ladanyi@1442
    71
      "    <toolitem action='FileSave' />"
ladanyi@1442
    72
      "    <separator />"
ladanyi@1442
    73
      "    <toolitem action='ViewZoomIn' />"
ladanyi@1442
    74
      "    <toolitem action='ViewZoomOut' />"
ladanyi@1442
    75
      "    <toolitem action='ViewZoomFit' />"
ladanyi@1442
    76
      "    <toolitem action='ViewZoom100' />"
ladanyi@1442
    77
      "  </toolbar>"
ladanyi@1442
    78
      "</ui>";
ladanyi@1442
    79
ladanyi@1442
    80
    uim->add_ui_from_string(ui_info);
ladanyi@1442
    81
ladanyi@1442
    82
  }
ladanyi@1442
    83
  catch(const Glib::Error& ex)
ladanyi@1442
    84
  {
ladanyi@1442
    85
    std::cerr << "building menus failed: " <<  ex.what();
ladanyi@1442
    86
  }
ladanyi@1442
    87
ladanyi@1442
    88
  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@1442
    89
  if (menubar){
ladanyi@1442
    90
    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
ladanyi@1442
    91
  }
ladanyi@1442
    92
ladanyi@1442
    93
  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@1442
    94
  if (toolbar)
ladanyi@1442
    95
  {
ladanyi@1442
    96
    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
ladanyi@1442
    97
    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
ladanyi@1442
    98
  }
ladanyi@1442
    99
ladanyi@1442
   100
  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
ladanyi@1442
   101
  pScrolledWindow->add(gd_canvas);
ladanyi@1442
   102
  vbox.pack_start(*pScrolledWindow);
ladanyi@1442
   103
  //vbox.pack_start(gd_canvas);
ladanyi@1442
   104
ladanyi@1442
   105
  show_all_children();
ladanyi@1442
   106
}
ladanyi@1442
   107
ladanyi@1442
   108
void MainWin::showMaps()
ladanyi@1442
   109
{
ladanyi@1442
   110
  mapwin.show();
ladanyi@1442
   111
}
ladanyi@1442
   112
hegyi@1468
   113
void MainWin::showEditorials()
hegyi@1468
   114
{
hegyi@1468
   115
  editwin.show();
hegyi@1468
   116
}
hegyi@1468
   117
ladanyi@1442
   118
void MainWin::quit()
ladanyi@1442
   119
{
ladanyi@1442
   120
  hide();
ladanyi@1442
   121
}
ladanyi@1442
   122
ladanyi@1442
   123
void MainWin::newFile()
ladanyi@1442
   124
{
ladanyi@1442
   125
  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
ladanyi@1442
   126
}
ladanyi@1442
   127
ladanyi@1442
   128
void MainWin::openFile()
ladanyi@1442
   129
{
ladanyi@1442
   130
  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
ladanyi@1442
   131
}
ladanyi@1442
   132
ladanyi@1442
   133
void MainWin::saveFile()
ladanyi@1442
   134
{
ladanyi@1442
   135
  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
ladanyi@1442
   136
}
ladanyi@1442
   137
ladanyi@1442
   138
void MainWin::saveFileAs()
ladanyi@1442
   139
{
ladanyi@1442
   140
  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
ladanyi@1442
   141
}