gui/main_win.cc
author alpar
Thu, 09 Jun 2005 09:49:56 +0000
changeset 1459 2ee881cf30a8
parent 1441 fd4b6f6d592a
child 1468 d0ccb2fdeeff
permissions -rw-r--r--
- InDegMap fixed
- OutDegMap added
- test cases added for them both
ladanyi@1442
     1
#include <main_win.h>
ladanyi@1442
     2
ladanyi@1442
     3
MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
ladanyi@1442
     4
    MapStorage & ms):mapwin("Map Setup", ms, 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));
ladanyi@1442
    37
ladanyi@1442
    38
  uim=Gtk::UIManager::create();
ladanyi@1442
    39
  uim->insert_action_group(ag);
ladanyi@1442
    40
  add_accel_group(uim->get_accel_group());
ladanyi@1442
    41
ladanyi@1442
    42
  try
ladanyi@1442
    43
  {
ladanyi@1442
    44
ladanyi@1442
    45
    Glib::ustring ui_info =
ladanyi@1442
    46
      "<ui>"
ladanyi@1442
    47
      "  <menubar name='MenuBar'>"
ladanyi@1442
    48
      "    <menu action='FileMenu'>"
ladanyi@1442
    49
      "      <menuitem action='FileNew'/>"
ladanyi@1442
    50
      "      <menuitem action='FileOpen'/>"
ladanyi@1442
    51
      "      <menuitem action='FileSave'/>"
ladanyi@1442
    52
      "      <menuitem action='FileSaveAs'/>"
ladanyi@1442
    53
      "      <menuitem action='FileQuit'/>"
ladanyi@1442
    54
      "    </menu>"
ladanyi@1442
    55
      "    <menu action='ViewMenu'>"
ladanyi@1442
    56
      "      <menuitem action='ViewZoomIn' />"
ladanyi@1442
    57
      "      <menuitem action='ViewZoomOut' />"
ladanyi@1442
    58
      "      <menuitem action='ViewZoomFit' />"
ladanyi@1442
    59
      "      <menuitem action='ViewZoom100' />"
ladanyi@1442
    60
      "    </menu>"
ladanyi@1442
    61
      "    <menu action='ShowMenu'>"
ladanyi@1442
    62
      "      <menuitem action='ShowMaps'/>"
ladanyi@1442
    63
      "    </menu>"
ladanyi@1442
    64
      "  </menubar>"
ladanyi@1442
    65
      "  <toolbar name='ToolBar'>"
ladanyi@1442
    66
      "    <toolitem action='FileNew' />"
ladanyi@1442
    67
      "    <toolitem action='FileOpen' />"
ladanyi@1442
    68
      "    <toolitem action='FileSave' />"
ladanyi@1442
    69
      "    <separator />"
ladanyi@1442
    70
      "    <toolitem action='ViewZoomIn' />"
ladanyi@1442
    71
      "    <toolitem action='ViewZoomOut' />"
ladanyi@1442
    72
      "    <toolitem action='ViewZoomFit' />"
ladanyi@1442
    73
      "    <toolitem action='ViewZoom100' />"
ladanyi@1442
    74
      "  </toolbar>"
ladanyi@1442
    75
      "</ui>";
ladanyi@1442
    76
ladanyi@1442
    77
    uim->add_ui_from_string(ui_info);
ladanyi@1442
    78
ladanyi@1442
    79
  }
ladanyi@1442
    80
  catch(const Glib::Error& ex)
ladanyi@1442
    81
  {
ladanyi@1442
    82
    std::cerr << "building menus failed: " <<  ex.what();
ladanyi@1442
    83
  }
ladanyi@1442
    84
ladanyi@1442
    85
  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@1442
    86
  if (menubar){
ladanyi@1442
    87
    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
ladanyi@1442
    88
  }
ladanyi@1442
    89
ladanyi@1442
    90
  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@1442
    91
  if (toolbar)
ladanyi@1442
    92
  {
ladanyi@1442
    93
    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
ladanyi@1442
    94
    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
ladanyi@1442
    95
  }
ladanyi@1442
    96
ladanyi@1442
    97
  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
ladanyi@1442
    98
  pScrolledWindow->add(gd_canvas);
ladanyi@1442
    99
  vbox.pack_start(*pScrolledWindow);
ladanyi@1442
   100
  //vbox.pack_start(gd_canvas);
ladanyi@1442
   101
ladanyi@1442
   102
  show_all_children();
ladanyi@1442
   103
}
ladanyi@1442
   104
ladanyi@1442
   105
void MainWin::showMaps()
ladanyi@1442
   106
{
ladanyi@1442
   107
  mapwin.show();
ladanyi@1442
   108
}
ladanyi@1442
   109
ladanyi@1442
   110
void MainWin::quit()
ladanyi@1442
   111
{
ladanyi@1442
   112
  hide();
ladanyi@1442
   113
}
ladanyi@1442
   114
ladanyi@1442
   115
void MainWin::newFile()
ladanyi@1442
   116
{
ladanyi@1442
   117
  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
ladanyi@1442
   118
}
ladanyi@1442
   119
ladanyi@1442
   120
void MainWin::openFile()
ladanyi@1442
   121
{
ladanyi@1442
   122
  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
ladanyi@1442
   123
}
ladanyi@1442
   124
ladanyi@1442
   125
void MainWin::saveFile()
ladanyi@1442
   126
{
ladanyi@1442
   127
  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
ladanyi@1442
   128
}
ladanyi@1442
   129
ladanyi@1442
   130
void MainWin::saveFileAs()
ladanyi@1442
   131
{
ladanyi@1442
   132
  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
ladanyi@1442
   133
}