gui/main_win.cc
author hegyi
Thu, 21 Jul 2005 19:28:29 +0000
changeset 1579 ed7da82bbecf
parent 1512 e54392395480
child 1585 0e3ef435bdc3
permissions -rw-r--r--
Edge and nodemap edition is done.
ladanyi@1442
     1
#include <main_win.h>
ladanyi@1442
     2
ladanyi@1442
     3
MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
hegyi@1512
     4
    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
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
hegyi@1502
    40
  ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
hegyi@1502
    41
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
hegyi@1502
    42
  ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
hegyi@1502
    43
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
hegyi@1502
    44
  ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
hegyi@1502
    45
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
hegyi@1502
    46
  ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
hegyi@1502
    47
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
hegyi@1550
    48
  ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
hegyi@1550
    49
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
hegyi@1550
    50
  ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
hegyi@1550
    51
      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
hegyi@1502
    52
ladanyi@1442
    53
  uim=Gtk::UIManager::create();
ladanyi@1442
    54
  uim->insert_action_group(ag);
ladanyi@1442
    55
  add_accel_group(uim->get_accel_group());
ladanyi@1442
    56
ladanyi@1442
    57
  try
ladanyi@1442
    58
  {
ladanyi@1442
    59
ladanyi@1442
    60
    Glib::ustring ui_info =
ladanyi@1442
    61
      "<ui>"
ladanyi@1442
    62
      "  <menubar name='MenuBar'>"
ladanyi@1442
    63
      "    <menu action='FileMenu'>"
ladanyi@1442
    64
      "      <menuitem action='FileNew'/>"
ladanyi@1442
    65
      "      <menuitem action='FileOpen'/>"
ladanyi@1442
    66
      "      <menuitem action='FileSave'/>"
ladanyi@1442
    67
      "      <menuitem action='FileSaveAs'/>"
ladanyi@1442
    68
      "      <menuitem action='FileQuit'/>"
ladanyi@1442
    69
      "    </menu>"
ladanyi@1442
    70
      "    <menu action='ViewMenu'>"
ladanyi@1442
    71
      "      <menuitem action='ViewZoomIn' />"
ladanyi@1442
    72
      "      <menuitem action='ViewZoomOut' />"
ladanyi@1442
    73
      "      <menuitem action='ViewZoomFit' />"
ladanyi@1442
    74
      "      <menuitem action='ViewZoom100' />"
ladanyi@1442
    75
      "    </menu>"
ladanyi@1442
    76
      "    <menu action='ShowMenu'>"
ladanyi@1442
    77
      "      <menuitem action='ShowMaps'/>"
hegyi@1468
    78
      "      <menuitem action='ShowEditorials'/>"
ladanyi@1442
    79
      "    </menu>"
ladanyi@1442
    80
      "  </menubar>"
ladanyi@1442
    81
      "  <toolbar name='ToolBar'>"
ladanyi@1442
    82
      "    <toolitem action='FileNew' />"
ladanyi@1442
    83
      "    <toolitem action='FileOpen' />"
ladanyi@1442
    84
      "    <toolitem action='FileSave' />"
ladanyi@1442
    85
      "    <separator />"
ladanyi@1442
    86
      "    <toolitem action='ViewZoomIn' />"
ladanyi@1442
    87
      "    <toolitem action='ViewZoomOut' />"
ladanyi@1442
    88
      "    <toolitem action='ViewZoomFit' />"
ladanyi@1442
    89
      "    <toolitem action='ViewZoom100' />"
hegyi@1502
    90
      "    <separator />"
hegyi@1502
    91
      "    <toolitem action='CreateNode' />"
hegyi@1502
    92
      "    <toolitem action='CreateEdge' />"
hegyi@1502
    93
      "    <toolitem action='EraseItem' />"
hegyi@1502
    94
      "    <toolitem action='MoveItem' />"
hegyi@1550
    95
      "    <toolitem action='EditEdgeMap' />"
hegyi@1550
    96
      "    <toolitem action='EditNodeMap' />"
ladanyi@1442
    97
      "  </toolbar>"
ladanyi@1442
    98
      "</ui>";
ladanyi@1442
    99
ladanyi@1442
   100
    uim->add_ui_from_string(ui_info);
ladanyi@1442
   101
ladanyi@1442
   102
  }
ladanyi@1442
   103
  catch(const Glib::Error& ex)
ladanyi@1442
   104
  {
ladanyi@1442
   105
    std::cerr << "building menus failed: " <<  ex.what();
ladanyi@1442
   106
  }
ladanyi@1442
   107
ladanyi@1442
   108
  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@1442
   109
  if (menubar){
ladanyi@1442
   110
    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
ladanyi@1442
   111
  }
ladanyi@1442
   112
ladanyi@1442
   113
  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@1442
   114
  if (toolbar)
ladanyi@1442
   115
  {
ladanyi@1442
   116
    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
ladanyi@1442
   117
    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
ladanyi@1442
   118
  }
ladanyi@1442
   119
ladanyi@1442
   120
  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
ladanyi@1442
   121
  pScrolledWindow->add(gd_canvas);
ladanyi@1442
   122
  vbox.pack_start(*pScrolledWindow);
ladanyi@1442
   123
  //vbox.pack_start(gd_canvas);
ladanyi@1442
   124
ladanyi@1442
   125
  show_all_children();
ladanyi@1442
   126
}
ladanyi@1442
   127
ladanyi@1442
   128
void MainWin::showMaps()
ladanyi@1442
   129
{
ladanyi@1442
   130
  mapwin.show();
ladanyi@1442
   131
}
ladanyi@1442
   132
hegyi@1468
   133
void MainWin::showEditorials()
hegyi@1468
   134
{
hegyi@1468
   135
  editwin.show();
hegyi@1468
   136
}
hegyi@1468
   137
ladanyi@1442
   138
void MainWin::quit()
ladanyi@1442
   139
{
ladanyi@1442
   140
  hide();
ladanyi@1442
   141
}
ladanyi@1442
   142
ladanyi@1442
   143
void MainWin::newFile()
ladanyi@1442
   144
{
ladanyi@1442
   145
  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
ladanyi@1442
   146
}
ladanyi@1442
   147
ladanyi@1442
   148
void MainWin::openFile()
ladanyi@1442
   149
{
ladanyi@1442
   150
  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
ladanyi@1442
   151
}
ladanyi@1442
   152
ladanyi@1442
   153
void MainWin::saveFile()
ladanyi@1442
   154
{
ladanyi@1442
   155
  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
ladanyi@1442
   156
}
ladanyi@1442
   157
ladanyi@1442
   158
void MainWin::saveFileAs()
ladanyi@1442
   159
{
ladanyi@1442
   160
  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
ladanyi@1442
   161
}