COIN-OR::LEMON - Graph Library

Changeset 1849:a4d1362397fe in lemon-0.x for gui/main_win.cc


Ignore:
Timestamp:
12/06/05 11:53:38 (14 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2414
Message:

Notebook style is provided. Without opportunity to close tabs. :-) But with all other necessary things (I think).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/main_win.cc

    r1838 r1849  
    22#include "icons/guipixbufs.h"
    33
    4 MainWin::MainWin():mapwinexists(false)
    5 {
    6   gd_canvas=new GraphDisplayerCanvas(*this);
    7 
    8   set_title ("unsaved file - " + prog_name);
     4MainWin::MainWin()
     5{
     6  set_title ("no file");
    97  set_default_size(WIN_WIDTH,WIN_HEIGHT);
    108  add(vbox);
    119
    12   //connecting signals - controller character
    13   mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
    14 
    1510  // custom icons for the toolbar
    16 
    1711  Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
    1812 
     
    7670  p_icon_factory->add_default();
    7771 
    78 
    7972  ag=Gtk::ActionGroup::create();
    8073
    8174  ag->add( Gtk::Action::create("FileMenu", "_File") );
     75  ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
     76      sigc::mem_fun(*this, &MainWin::newTab));
    8277  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    8378      sigc::mem_fun(*this, &MainWin::newFile));
     
    9590  ag->add( Gtk::Action::create("ViewMenu", "_View") );
    9691  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
    97       sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn));
     92      sigc::mem_fun(*this, &MainWin::zoomIn));
    9893  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
    99       sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut));
     94      sigc::mem_fun(*this, &MainWin::zoomOut));
    10095  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
    101       sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit));
     96      sigc::mem_fun(*this, &MainWin::zoomFit));
    10297  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
    103       sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoom100));
     98      sigc::mem_fun(*this, &MainWin::zoom100));
    10499 
    105100  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
     
    109104  Gtk::RadioAction::Group tool_group;
    110105  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
    111       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) );
     106      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
    112107  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
    113       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) );
     108      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
    114109  ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
    115       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) );
     110      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
    116111  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
    117       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) );
     112      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
    118113
    119114  ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
    120       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) );
     115      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
    121116  ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
    122       sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) );
     117      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
    123118
    124119  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
    125       sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) );
     120      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
    126121
    127122  uim=Gtk::UIManager::create();
     
    136131      "  <menubar name='MenuBar'>"
    137132      "    <menu action='FileMenu'>"
     133      "      <menuitem action='FileNewTab'/>"
    138134      "      <menuitem action='FileNew'/>"
    139135      "      <menuitem action='FileOpen'/>"
     
    195191  }
    196192
    197   Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
    198   pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN);
    199   pScrolledWindow->add(*gd_canvas);
    200   vbox.pack_start(*pScrolledWindow);
    201 
    202193  tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
    203194  tooltips.enable();
    204195
     196  active_tab=-1;
     197  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
     198
     199  vbox.pack_start(notebook);
     200 
    205201  show_all_children();
    206202}
    207203
    208 void MainWin::readFile(const std::string &file)
    209 {
    210   mapstorage.readFromFile(file);
    211   mapstorage.file_name = file;
    212   mapstorage.modified = false;
    213   gd_canvas->drawGraph();
    214   if(mapwinexists)
    215     {
    216       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    217     }
    218   set_title(Glib::filename_display_basename(file) + " - " + prog_name);
     204void MainWin::set_tabtitle(std::string name)
     205{
     206  tabnames[active_tab]=name;
     207  set_title(tabnames[active_tab] + " - " + prog_name);
     208  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
     209}
     210
     211void MainWin::readFile(const std::string & filename)
     212{
     213  newTab();
     214  tabs[active_tab]->readFile(filename);
     215}
     216
     217void MainWin::newTab()
     218{
     219  int size=tabs.size();
     220  tabs.resize(size+1);
     221  tabnames.resize(size+1);
     222  active_tab=size;
     223  tabs[active_tab]=new NoteBookTab();
     224  tabnames[active_tab]="unsaved file";
     225  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
     226  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
     227  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
     228  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
     229  notebook.set_current_page(size);
     230  set_tabtitle(tabnames[active_tab]);
     231}
     232
     233void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
     234{
     235  page=page;
     236  active_tab=page_num;
     237  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
     238  set_title(tabnames[active_tab]);
     239}
     240
     241void MainWin::onCloseTab()
     242{
    219243}
    220244
    221245void MainWin::newFile()
    222246{
    223   if (mapstorage.modified)
    224   {
    225     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    226         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    227     mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
    228     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    229     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    230     switch (mdialog.run())
    231     {
    232       case Gtk::RESPONSE_CANCEL:
    233         return;
    234       case Gtk::RESPONSE_REJECT:
    235         break;
    236       case Gtk::RESPONSE_ACCEPT:
    237         saveFile();
    238         break;
    239     }
    240   }
    241   gd_canvas->clear();
    242   mapstorage.clear();
    243   if(mapwinexists)
    244     {
    245       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    246     }
    247   set_title("unsaved file - " + prog_name);
    248 }
    249 
     247  if(active_tab!=-1)
     248    {
     249      tabs[active_tab]->newFile();
     250    }
     251}
     252 
    250253void MainWin::openFile()
    251254{
    252   if (mapstorage.modified)
    253   {
    254     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    255         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    256     mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
    257     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    258     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    259     switch (mdialog.run())
    260     {
    261       case Gtk::RESPONSE_CANCEL:
    262         return;
    263       case Gtk::RESPONSE_REJECT:
    264         break;
    265       case Gtk::RESPONSE_ACCEPT:
    266         saveFile();
    267         break;
    268     }
    269   }
    270   Gtk::FileChooserDialog fcdialog("Open File");
    271   fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    272   fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
    273   if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
    274   {
    275     gd_canvas->clear();
    276     mapstorage.clear();
    277     Glib::ustring filename = fcdialog.get_filename();
    278     if (!mapstorage.readFromFile(filename))
    279     {
    280       mapstorage.file_name = filename;
    281       mapstorage.modified = false;
    282       gd_canvas->drawGraph();
    283       if(mapwinexists)
     255  if(active_tab!=-1)
     256    {
     257      tabs[active_tab]->openFile();
     258    }
     259}
     260 
     261void MainWin::saveFile()
     262{
     263  if(active_tab!=-1)
     264    {
     265      tabs[active_tab]->saveFile();
     266    }
     267}
     268 
     269void MainWin::saveFileAs()
     270{
     271  if(active_tab!=-1)
     272    {
     273      tabs[active_tab]->saveFileAs();
     274    }
     275}
     276 
     277void MainWin::close()
     278{
     279  if(active_tab!=-1)
     280    {
     281      tabs[active_tab]->close();
     282    }
     283}
     284
     285void MainWin::zoomIn()
     286{
     287  if(active_tab!=-1)
     288    {
     289      tabs[active_tab]->gd_canvas->zoomIn();
     290    }
     291}
     292
     293void MainWin::zoomOut()
     294{
     295  if(active_tab!=-1)
     296    {
     297      tabs[active_tab]->gd_canvas->zoomOut();
     298    }
     299}
     300
     301void MainWin::zoomFit()
     302{
     303  if(active_tab!=-1)
     304    {
     305      tabs[active_tab]->gd_canvas->zoomFit();
     306    }
     307}
     308
     309void MainWin::zoom100()
     310{
     311  if(active_tab!=-1)
     312    {
     313      tabs[active_tab]->gd_canvas->zoom100();
     314    }
     315}
     316
     317void MainWin::createMapWin()
     318{
     319  if(active_tab!=-1)
     320    {
     321      tabs[active_tab]->createMapWin(tabnames[active_tab]);
     322    }
     323}
     324
     325void MainWin::changeEditorialTool(int tool)
     326{
     327  active_tool=tool;
     328  if(active_tab!=-1)
     329    {
     330      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
     331    }
     332}
     333
     334void MainWin::createNewMapWin()
     335{
     336  if(active_tab!=-1)
     337    {
     338      NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
     339      nmw->show();
     340    }
     341}
     342
     343void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
     344{
     345  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
     346  int i=0;
     347  for(;nbti!=tabs.end();nbti++)
     348    {
     349      if(*nbti!=nbt)
    284350        {
    285           mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
     351          i++;
    286352        }
    287       set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
    288     }
    289   }
    290 }
    291 
    292 void MainWin::saveFile()
    293 {
    294   if (mapstorage.file_name == "") {
    295     saveFileAs();
    296   }
    297   else
    298   {
    299     mapstorage.writeToFile(mapstorage.file_name);
    300     mapstorage.modified = false;
    301     set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " +
    302         prog_name);
    303   }
    304 }
    305 
    306 void MainWin::saveFileAs()
    307 {
    308   Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
    309   fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    310   fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    311   if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
    312   {
    313     Glib::ustring filename = fcdialog.get_filename();
    314     mapstorage.file_name = filename;
    315     mapstorage.writeToFile(filename);
    316     mapstorage.modified = false;
    317     set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
    318   }
    319 }
    320 
    321 void MainWin::close()
    322 {
    323   if (mapstorage.modified)
    324   {
    325     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    326         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    327     mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
    328     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    329     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    330     switch (mdialog.run())
    331     {
    332       case Gtk::RESPONSE_CANCEL:
    333         return;
    334       case Gtk::RESPONSE_REJECT:
    335         break;
    336       case Gtk::RESPONSE_ACCEPT:
    337         saveFile();
    338         break;
    339     }
    340   }
    341   gd_canvas->clear();
    342   mapstorage.clear();
    343   if(mapwinexists)
    344     {
    345       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    346     }
    347   set_title("unsaved file - " + prog_name);
    348 }
    349 
    350 void MainWin::propertyChange(bool itisedge, int prop, std::string mapname)
    351 {
    352   mapstorage.changeActiveMap(itisedge, prop, mapname);
    353 }
    354 
    355 void MainWin::popupNewMapWin(bool itisedge, int prop)
    356 {
    357   prop=prop;
    358   (new NewMapWin("NewMapWin", *this, itisedge, false))->run();
    359 }
    360 
    361 std::string MainWin::getActiveEdgeMap(int prop)
    362 {
    363   return mapstorage.getActiveEdgeMap(prop);
    364 }
    365 
    366 std::string MainWin::getActiveNodeMap(int prop)
    367 {
    368   return mapstorage.getActiveNodeMap(prop);
    369 }
    370 
    371 void MainWin::registerNewEdgeMap(std::string mapname)
    372 {
    373   if(mapwinexists)
    374     {
    375       mapwin->registerNewEdgeMap(mapname);
    376     }
    377 }
    378 
    379 void MainWin::registerNewNodeMap(std::string mapname)
    380 {
    381   if(mapwinexists)
    382     {
    383       mapwin->registerNewNodeMap(mapname);
    384     }
    385 }
    386 
    387 void MainWin::createMapWin()
    388 {
    389   if(!mapwinexists)
    390     {
    391       mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
    392       mapwin->show();
    393       mapwinexists=true;
    394     }
    395 }
    396 
    397 void MainWin::closeMapWin()
    398 {
    399   mapwinexists=false;
    400   delete mapwin;
    401 }
     353      else
     354        {
     355          continue;
     356        }
     357    }
     358  NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);
     359  nmw->run();
     360}
Note: See TracChangeset for help on using the changeset viewer.