gui/main_win.cc
author alpar
Wed, 07 Dec 2005 15:43:44 +0000
changeset 1855 c72636dcf0bd
parent 1838 b61682f0ee96
child 1856 3f0558065bcd
permissions -rw-r--r--
Eliminate warnins
ladanyi@1606
     1
#include "main_win.h"
alpar@1659
     2
#include "icons/guipixbufs.h"
ladanyi@1442
     3
hegyi@1849
     4
MainWin::MainWin()
ladanyi@1442
     5
{
hegyi@1849
     6
  set_title ("no file");
ladanyi@1442
     7
  set_default_size(WIN_WIDTH,WIN_HEIGHT);
ladanyi@1442
     8
  add(vbox);
ladanyi@1442
     9
ladanyi@1634
    10
  // custom icons for the toolbar
ladanyi@1634
    11
  Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
ladanyi@1634
    12
 
ladanyi@1635
    13
  Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    14
      2328, gui_icons_move);
ladanyi@1635
    15
  Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    16
      2328, gui_icons_addnode);
ladanyi@1635
    17
  Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    18
      2328, gui_icons_addlink);
ladanyi@1635
    19
  Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    20
      2328, gui_icons_delete);
ladanyi@1635
    21
  Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    22
      2328, gui_icons_editlink);
ladanyi@1635
    23
  Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    24
      2328, gui_icons_editnode);
ladanyi@1635
    25
  Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@1635
    26
      2328, gui_icons_newmap);
ladanyi@1634
    27
ladanyi@1634
    28
  Gtk::IconSource move_icon_source;
ladanyi@1635
    29
  move_icon_source.set_pixbuf(p_move_pixbuf);
ladanyi@1634
    30
  Gtk::IconSet move_icon_set;
ladanyi@1634
    31
  move_icon_set.add_source(move_icon_source);
ladanyi@1634
    32
  p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
ladanyi@1634
    33
ladanyi@1634
    34
  Gtk::IconSource addnode_icon_source;
ladanyi@1635
    35
  addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
ladanyi@1634
    36
  Gtk::IconSet addnode_icon_set;
ladanyi@1634
    37
  addnode_icon_set.add_source(addnode_icon_source);
ladanyi@1634
    38
  p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
ladanyi@1634
    39
ladanyi@1634
    40
  Gtk::IconSource addlink_icon_source;
ladanyi@1635
    41
  addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
ladanyi@1634
    42
  Gtk::IconSet addlink_icon_set;
ladanyi@1634
    43
  addlink_icon_set.add_source(addlink_icon_source);
ladanyi@1634
    44
  p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
ladanyi@1634
    45
ladanyi@1634
    46
  Gtk::IconSource delete_icon_source;
ladanyi@1635
    47
  delete_icon_source.set_pixbuf(p_delete_pixbuf);
ladanyi@1634
    48
  Gtk::IconSet delete_icon_set;
ladanyi@1634
    49
  delete_icon_set.add_source(delete_icon_source);
ladanyi@1634
    50
  p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
ladanyi@1634
    51
ladanyi@1634
    52
  Gtk::IconSource editlink_icon_source;
ladanyi@1635
    53
  editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
ladanyi@1634
    54
  Gtk::IconSet editlink_icon_set;
ladanyi@1634
    55
  editlink_icon_set.add_source(editlink_icon_source);
ladanyi@1634
    56
  p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
ladanyi@1634
    57
ladanyi@1634
    58
  Gtk::IconSource editnode_icon_source;
ladanyi@1635
    59
  editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
ladanyi@1634
    60
  Gtk::IconSet editnode_icon_set;
ladanyi@1634
    61
  editnode_icon_set.add_source(editnode_icon_source);
ladanyi@1634
    62
  p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
ladanyi@1634
    63
ladanyi@1634
    64
  Gtk::IconSource newmap_icon_source;
ladanyi@1635
    65
  newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
ladanyi@1634
    66
  Gtk::IconSet newmap_icon_set;
ladanyi@1634
    67
  newmap_icon_set.add_source(newmap_icon_source);
ladanyi@1634
    68
  p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
ladanyi@1634
    69
ladanyi@1634
    70
  p_icon_factory->add_default();
ladanyi@1634
    71
  
ladanyi@1442
    72
  ag=Gtk::ActionGroup::create();
ladanyi@1442
    73
ladanyi@1442
    74
  ag->add( Gtk::Action::create("FileMenu", "_File") );
hegyi@1849
    75
  ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
hegyi@1849
    76
      sigc::mem_fun(*this, &MainWin::newTab));
ladanyi@1442
    77
  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
ladanyi@1442
    78
      sigc::mem_fun(*this, &MainWin::newFile));
ladanyi@1442
    79
  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
ladanyi@1442
    80
      sigc::mem_fun(*this, &MainWin::openFile));
ladanyi@1442
    81
  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
ladanyi@1442
    82
      sigc::mem_fun(*this, &MainWin::saveFile));
ladanyi@1442
    83
  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
ladanyi@1442
    84
      sigc::mem_fun(*this, &MainWin::saveFileAs));
ladanyi@1606
    85
  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
ladanyi@1606
    86
      sigc::mem_fun(*this, &MainWin::close));
ladanyi@1606
    87
  ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
hegyi@1598
    88
      sigc::mem_fun(*this, &MainWin::hide));
ladanyi@1442
    89
ladanyi@1442
    90
  ag->add( Gtk::Action::create("ViewMenu", "_View") );
ladanyi@1442
    91
  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
hegyi@1849
    92
      sigc::mem_fun(*this, &MainWin::zoomIn));
ladanyi@1442
    93
  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
hegyi@1849
    94
      sigc::mem_fun(*this, &MainWin::zoomOut));
ladanyi@1442
    95
  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
hegyi@1849
    96
      sigc::mem_fun(*this, &MainWin::zoomFit));
ladanyi@1442
    97
  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
hegyi@1849
    98
      sigc::mem_fun(*this, &MainWin::zoom100));
ladanyi@1442
    99
  
ladanyi@1442
   100
  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
ladanyi@1442
   101
  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
hegyi@1838
   102
	   sigc::mem_fun(*this, &MainWin::createMapWin));
ladanyi@1442
   103
ladanyi@1606
   104
  Gtk::RadioAction::Group tool_group;
ladanyi@1634
   105
  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
hegyi@1849
   106
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
ladanyi@1634
   107
  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
hegyi@1849
   108
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
ladanyi@1634
   109
  ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
hegyi@1849
   110
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
ladanyi@1634
   111
  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
hegyi@1849
   112
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
ladanyi@1634
   113
ladanyi@1634
   114
  ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
hegyi@1849
   115
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
ladanyi@1634
   116
  ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
hegyi@1849
   117
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
ladanyi@1634
   118
ladanyi@1634
   119
  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
hegyi@1849
   120
      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
hegyi@1502
   121
ladanyi@1442
   122
  uim=Gtk::UIManager::create();
ladanyi@1442
   123
  uim->insert_action_group(ag);
ladanyi@1442
   124
  add_accel_group(uim->get_accel_group());
ladanyi@1442
   125
ladanyi@1442
   126
  try
ladanyi@1442
   127
  {
ladanyi@1442
   128
ladanyi@1442
   129
    Glib::ustring ui_info =
ladanyi@1442
   130
      "<ui>"
ladanyi@1442
   131
      "  <menubar name='MenuBar'>"
ladanyi@1442
   132
      "    <menu action='FileMenu'>"
hegyi@1849
   133
      "      <menuitem action='FileNewTab'/>"
ladanyi@1442
   134
      "      <menuitem action='FileNew'/>"
ladanyi@1442
   135
      "      <menuitem action='FileOpen'/>"
ladanyi@1442
   136
      "      <menuitem action='FileSave'/>"
ladanyi@1442
   137
      "      <menuitem action='FileSaveAs'/>"
ladanyi@1606
   138
      "      <menuitem action='Close'/>"
ladanyi@1606
   139
      "      <menuitem action='Quit'/>"
ladanyi@1442
   140
      "    </menu>"
ladanyi@1442
   141
      "    <menu action='ViewMenu'>"
ladanyi@1442
   142
      "      <menuitem action='ViewZoomIn' />"
ladanyi@1442
   143
      "      <menuitem action='ViewZoomOut' />"
ladanyi@1442
   144
      "      <menuitem action='ViewZoom100' />"
ladanyi@1777
   145
      "      <menuitem action='ViewZoomFit' />"
ladanyi@1442
   146
      "    </menu>"
ladanyi@1442
   147
      "    <menu action='ShowMenu'>"
ladanyi@1442
   148
      "      <menuitem action='ShowMaps'/>"
ladanyi@1442
   149
      "    </menu>"
ladanyi@1442
   150
      "  </menubar>"
ladanyi@1442
   151
      "  <toolbar name='ToolBar'>"
ladanyi@1442
   152
      "    <toolitem action='FileNew' />"
ladanyi@1442
   153
      "    <toolitem action='FileOpen' />"
ladanyi@1442
   154
      "    <toolitem action='FileSave' />"
ladanyi@1606
   155
      "    <toolitem action='Close' />"
ladanyi@1442
   156
      "    <separator />"
ladanyi@1442
   157
      "    <toolitem action='ViewZoomIn' />"
ladanyi@1442
   158
      "    <toolitem action='ViewZoomOut' />"
ladanyi@1442
   159
      "    <toolitem action='ViewZoom100' />"
ladanyi@1777
   160
      "    <toolitem action='ViewZoomFit' />"
hegyi@1502
   161
      "    <separator />"
ladanyi@1606
   162
      "    <toolitem action='MoveItem' />"
hegyi@1502
   163
      "    <toolitem action='CreateNode' />"
hegyi@1502
   164
      "    <toolitem action='CreateEdge' />"
hegyi@1502
   165
      "    <toolitem action='EraseItem' />"
hegyi@1550
   166
      "    <toolitem action='EditEdgeMap' />"
hegyi@1550
   167
      "    <toolitem action='EditNodeMap' />"
ladanyi@1634
   168
      "    <separator />"
hegyi@1592
   169
      "    <toolitem action='AddMap' />"
ladanyi@1442
   170
      "  </toolbar>"
ladanyi@1442
   171
      "</ui>";
ladanyi@1442
   172
ladanyi@1442
   173
    uim->add_ui_from_string(ui_info);
ladanyi@1442
   174
ladanyi@1442
   175
  }
ladanyi@1442
   176
  catch(const Glib::Error& ex)
ladanyi@1442
   177
  {
ladanyi@1442
   178
    std::cerr << "building menus failed: " <<  ex.what();
ladanyi@1442
   179
  }
ladanyi@1442
   180
ladanyi@1442
   181
  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@1442
   182
  if (menubar){
ladanyi@1442
   183
    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
ladanyi@1442
   184
  }
ladanyi@1442
   185
ladanyi@1442
   186
  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@1442
   187
  if (toolbar)
ladanyi@1442
   188
  {
ladanyi@1442
   189
    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
ladanyi@1442
   190
    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
ladanyi@1442
   191
  }
ladanyi@1442
   192
hegyi@1601
   193
  tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
hegyi@1601
   194
  tooltips.enable();
ladanyi@1442
   195
hegyi@1849
   196
  active_tab=-1;
hegyi@1849
   197
  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
hegyi@1849
   198
hegyi@1849
   199
  vbox.pack_start(notebook);
hegyi@1849
   200
  
ladanyi@1442
   201
  show_all_children();
ladanyi@1442
   202
}
ladanyi@1442
   203
hegyi@1849
   204
void MainWin::set_tabtitle(std::string name)
ladanyi@1616
   205
{
hegyi@1849
   206
  tabnames[active_tab]=name;
hegyi@1849
   207
  set_title(tabnames[active_tab] + " - " + prog_name);
hegyi@1849
   208
  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
hegyi@1849
   209
}
hegyi@1849
   210
hegyi@1849
   211
void MainWin::readFile(const std::string & filename)
hegyi@1849
   212
{
hegyi@1849
   213
  newTab();
hegyi@1849
   214
  tabs[active_tab]->readFile(filename);
hegyi@1849
   215
}
hegyi@1849
   216
hegyi@1849
   217
void MainWin::newTab()
hegyi@1849
   218
{
hegyi@1849
   219
  int size=tabs.size();
hegyi@1849
   220
  tabs.resize(size+1);
hegyi@1849
   221
  tabnames.resize(size+1);
hegyi@1849
   222
  active_tab=size;
hegyi@1849
   223
  tabs[active_tab]=new NoteBookTab();
hegyi@1849
   224
  tabnames[active_tab]="unsaved file";
hegyi@1849
   225
  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
hegyi@1849
   226
  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
hegyi@1849
   227
  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
hegyi@1849
   228
  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
hegyi@1849
   229
  notebook.set_current_page(size);
hegyi@1849
   230
  set_tabtitle(tabnames[active_tab]);
hegyi@1849
   231
}
hegyi@1849
   232
hegyi@1849
   233
void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
hegyi@1849
   234
{
hegyi@1849
   235
  page=page;
hegyi@1849
   236
  active_tab=page_num;
hegyi@1849
   237
  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
hegyi@1849
   238
  set_title(tabnames[active_tab]);
hegyi@1849
   239
}
hegyi@1849
   240
hegyi@1849
   241
void MainWin::onCloseTab()
hegyi@1849
   242
{
ladanyi@1616
   243
}
ladanyi@1616
   244
ladanyi@1442
   245
void MainWin::newFile()
ladanyi@1442
   246
{
hegyi@1849
   247
  if(active_tab!=-1)
ladanyi@1606
   248
    {
hegyi@1849
   249
      tabs[active_tab]->newFile();
ladanyi@1606
   250
    }
ladanyi@1442
   251
}
hegyi@1849
   252
 
ladanyi@1442
   253
void MainWin::openFile()
ladanyi@1442
   254
{
hegyi@1849
   255
  if(active_tab!=-1)
ladanyi@1606
   256
    {
hegyi@1849
   257
      tabs[active_tab]->openFile();
ladanyi@1606
   258
    }
ladanyi@1442
   259
}
hegyi@1849
   260
 
ladanyi@1442
   261
void MainWin::saveFile()
ladanyi@1442
   262
{
hegyi@1849
   263
  if(active_tab!=-1)
hegyi@1849
   264
    {
hegyi@1849
   265
      tabs[active_tab]->saveFile();
hegyi@1849
   266
    }
ladanyi@1442
   267
}
hegyi@1849
   268
 
ladanyi@1442
   269
void MainWin::saveFileAs()
ladanyi@1442
   270
{
hegyi@1849
   271
  if(active_tab!=-1)
hegyi@1849
   272
    {
hegyi@1849
   273
      tabs[active_tab]->saveFileAs();
hegyi@1849
   274
    }
ladanyi@1442
   275
}
hegyi@1849
   276
 
ladanyi@1606
   277
void MainWin::close()
ladanyi@1606
   278
{
hegyi@1849
   279
  if(active_tab!=-1)
ladanyi@1606
   280
    {
hegyi@1849
   281
      tabs[active_tab]->close();
hegyi@1838
   282
    }
hegyi@1837
   283
}
hegyi@1837
   284
hegyi@1849
   285
void MainWin::zoomIn()
hegyi@1837
   286
{
hegyi@1849
   287
  if(active_tab!=-1)
hegyi@1838
   288
    {
hegyi@1849
   289
      tabs[active_tab]->gd_canvas->zoomIn();
hegyi@1849
   290
    }
hegyi@1849
   291
}
hegyi@1849
   292
hegyi@1849
   293
void MainWin::zoomOut()
hegyi@1849
   294
{
hegyi@1849
   295
  if(active_tab!=-1)
hegyi@1849
   296
    {
hegyi@1849
   297
      tabs[active_tab]->gd_canvas->zoomOut();
hegyi@1849
   298
    }
hegyi@1849
   299
}
hegyi@1849
   300
hegyi@1849
   301
void MainWin::zoomFit()
hegyi@1849
   302
{
hegyi@1849
   303
  if(active_tab!=-1)
hegyi@1849
   304
    {
hegyi@1849
   305
      tabs[active_tab]->gd_canvas->zoomFit();
hegyi@1849
   306
    }
hegyi@1849
   307
}
hegyi@1849
   308
hegyi@1849
   309
void MainWin::zoom100()
hegyi@1849
   310
{
hegyi@1849
   311
  if(active_tab!=-1)
hegyi@1849
   312
    {
hegyi@1849
   313
      tabs[active_tab]->gd_canvas->zoom100();
hegyi@1838
   314
    }
hegyi@1837
   315
}
hegyi@1838
   316
hegyi@1838
   317
void MainWin::createMapWin()
hegyi@1838
   318
{
hegyi@1849
   319
  if(active_tab!=-1)
hegyi@1838
   320
    {
hegyi@1849
   321
      tabs[active_tab]->createMapWin(tabnames[active_tab]);
hegyi@1838
   322
    }
hegyi@1838
   323
}
hegyi@1838
   324
hegyi@1849
   325
void MainWin::changeEditorialTool(int tool)
hegyi@1838
   326
{
hegyi@1849
   327
  active_tool=tool;
hegyi@1849
   328
  if(active_tab!=-1)
hegyi@1849
   329
    {
hegyi@1849
   330
      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
hegyi@1849
   331
    }
hegyi@1838
   332
}
hegyi@1849
   333
hegyi@1849
   334
void MainWin::createNewMapWin()
hegyi@1849
   335
{
hegyi@1849
   336
  if(active_tab!=-1)
hegyi@1849
   337
    {
hegyi@1849
   338
      NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
hegyi@1849
   339
      nmw->show();
hegyi@1849
   340
    }
hegyi@1849
   341
}
hegyi@1849
   342
hegyi@1849
   343
void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
hegyi@1849
   344
{
hegyi@1849
   345
  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
hegyi@1849
   346
  int i=0;
hegyi@1849
   347
  for(;nbti!=tabs.end();nbti++)
hegyi@1849
   348
    {
hegyi@1849
   349
      if(*nbti!=nbt)
hegyi@1849
   350
	{
hegyi@1849
   351
	  i++;
hegyi@1849
   352
	}
hegyi@1849
   353
      else
hegyi@1849
   354
	{
hegyi@1849
   355
	  continue;
hegyi@1849
   356
	}
hegyi@1849
   357
    }
hegyi@1849
   358
  NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);
hegyi@1849
   359
  nmw->run();
hegyi@1849
   360
}