ladanyi@1606: #include "main_win.h" ladanyi@1862: #include "guipixbufs.h" ladanyi@1442: hegyi@1849: MainWin::MainWin() ladanyi@1442: { hegyi@1849: set_title ("no file"); ladanyi@1442: set_default_size(WIN_WIDTH,WIN_HEIGHT); ladanyi@1442: add(vbox); ladanyi@1442: ladanyi@1634: // custom icons for the toolbar ladanyi@1634: Glib::RefPtr p_icon_factory = Gtk::IconFactory::create(); ladanyi@1634: ladanyi@1635: Glib::RefPtr p_move_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_move); ladanyi@1635: Glib::RefPtr p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_addnode); ladanyi@1635: Glib::RefPtr p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_addlink); ladanyi@1635: Glib::RefPtr p_delete_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_delete); ladanyi@1635: Glib::RefPtr p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_editlink); ladanyi@1635: Glib::RefPtr p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_editnode); ladanyi@1635: Glib::RefPtr p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@1635: 2328, gui_icons_newmap); ladanyi@1634: ladanyi@1634: Gtk::IconSource move_icon_source; ladanyi@1635: move_icon_source.set_pixbuf(p_move_pixbuf); ladanyi@1634: Gtk::IconSet move_icon_set; ladanyi@1634: move_icon_set.add_source(move_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource addnode_icon_source; ladanyi@1635: addnode_icon_source.set_pixbuf(p_addnode_pixbuf); ladanyi@1634: Gtk::IconSet addnode_icon_set; ladanyi@1634: addnode_icon_set.add_source(addnode_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource addlink_icon_source; ladanyi@1635: addlink_icon_source.set_pixbuf(p_addlink_pixbuf); ladanyi@1634: Gtk::IconSet addlink_icon_set; ladanyi@1634: addlink_icon_set.add_source(addlink_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource delete_icon_source; ladanyi@1635: delete_icon_source.set_pixbuf(p_delete_pixbuf); ladanyi@1634: Gtk::IconSet delete_icon_set; ladanyi@1634: delete_icon_set.add_source(delete_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource editlink_icon_source; ladanyi@1635: editlink_icon_source.set_pixbuf(p_editlink_pixbuf); ladanyi@1634: Gtk::IconSet editlink_icon_set; ladanyi@1634: editlink_icon_set.add_source(editlink_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource editnode_icon_source; ladanyi@1635: editnode_icon_source.set_pixbuf(p_editnode_pixbuf); ladanyi@1634: Gtk::IconSet editnode_icon_set; ladanyi@1634: editnode_icon_set.add_source(editnode_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set); ladanyi@1634: ladanyi@1634: Gtk::IconSource newmap_icon_source; ladanyi@1635: newmap_icon_source.set_pixbuf(p_newmap_pixbuf); ladanyi@1634: Gtk::IconSet newmap_icon_set; ladanyi@1634: newmap_icon_set.add_source(newmap_icon_source); ladanyi@1634: p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); ladanyi@1634: ladanyi@1634: p_icon_factory->add_default(); ladanyi@1634: ladanyi@1442: ag=Gtk::ActionGroup::create(); ladanyi@1442: ladanyi@1442: ag->add( Gtk::Action::create("FileMenu", "_File") ); hegyi@1869: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), hegyi@1849: sigc::mem_fun(*this, &MainWin::newTab)); ladanyi@1442: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), ladanyi@1442: sigc::mem_fun(*this, &MainWin::openFile)); hegyi@1869: ag->add( Gtk::Action::create("FileClearTab", "Clear Tab"), hegyi@1869: sigc::mem_fun(*this, &MainWin::newFile)); ladanyi@1442: ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), ladanyi@1442: sigc::mem_fun(*this, &MainWin::saveFile)); ladanyi@1442: ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), ladanyi@1442: sigc::mem_fun(*this, &MainWin::saveFileAs)); ladanyi@1606: ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), hegyi@1869: sigc::mem_fun(*this, &MainWin::closeTab)); ladanyi@1606: ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), hegyi@1598: sigc::mem_fun(*this, &MainWin::hide)); ladanyi@1442: ladanyi@1442: ag->add( Gtk::Action::create("ViewMenu", "_View") ); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), hegyi@1849: sigc::mem_fun(*this, &MainWin::zoomIn)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), hegyi@1849: sigc::mem_fun(*this, &MainWin::zoomOut)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), hegyi@1849: sigc::mem_fun(*this, &MainWin::zoomFit)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), hegyi@1849: sigc::mem_fun(*this, &MainWin::zoom100)); ladanyi@1442: ladanyi@1442: ag->add( Gtk::Action::create("ShowMenu", "_Show") ); ladanyi@1442: ag->add( Gtk::Action::create("ShowMaps", "_Maps"), hegyi@1838: sigc::mem_fun(*this, &MainWin::createMapWin)); ladanyi@1442: hegyi@1871: ag->add( Gtk::Action::create("AlgoMenu", "_Algorithms") ); hegyi@1871: ag->add( Gtk::Action::create("AlgoGeneral", "_General"), hegyi@1871: sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) ); hegyi@1876: ag->add( Gtk::Action::create("AlgoKruskal", "_Kruskal"), hegyi@1876: sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) ); hegyi@1871: ladanyi@1606: Gtk::RadioAction::Group tool_group; ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) ); ladanyi@1634: ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"), hegyi@1849: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) ); ladanyi@1634: ladanyi@1634: ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), hegyi@1849: sigc::mem_fun ( *this , &MainWin::createNewMapWin ) ); hegyi@1502: ladanyi@1442: uim=Gtk::UIManager::create(); ladanyi@1442: uim->insert_action_group(ag); ladanyi@1442: add_accel_group(uim->get_accel_group()); ladanyi@1442: ladanyi@1442: try ladanyi@1442: { ladanyi@1442: ladanyi@1442: Glib::ustring ui_info = ladanyi@1442: "" ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " hegyi@1869: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1606: " " ladanyi@1606: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1777: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " hegyi@1871: " " hegyi@1871: " " hegyi@1876: " " hegyi@1871: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1606: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1442: " " ladanyi@1777: " " hegyi@1502: " " ladanyi@1606: " " hegyi@1502: " " hegyi@1502: " " hegyi@1502: " " hegyi@1550: " " hegyi@1550: " " ladanyi@1634: " " hegyi@1592: " " ladanyi@1442: " " ladanyi@1442: ""; ladanyi@1442: ladanyi@1442: uim->add_ui_from_string(ui_info); ladanyi@1442: ladanyi@1442: } ladanyi@1442: catch(const Glib::Error& ex) ladanyi@1442: { ladanyi@1442: std::cerr << "building menus failed: " << ex.what(); ladanyi@1442: } ladanyi@1442: ladanyi@1442: Gtk::Widget* menubar = uim->get_widget("/MenuBar"); ladanyi@1442: if (menubar){ ladanyi@1442: vbox.pack_start(*menubar, Gtk::PACK_SHRINK); ladanyi@1442: } ladanyi@1442: ladanyi@1442: Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); ladanyi@1442: if (toolbar) ladanyi@1442: { ladanyi@1442: static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); ladanyi@1442: vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); ladanyi@1442: } ladanyi@1442: hegyi@1601: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); hegyi@1601: tooltips.enable(); ladanyi@1442: hegyi@1849: active_tab=-1; hegyi@1849: notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab)); hegyi@1849: ladanyi@1877: active_tool = MOVE; ladanyi@1877: hegyi@1849: vbox.pack_start(notebook); hegyi@1849: ladanyi@1442: show_all_children(); ladanyi@1442: } ladanyi@1442: hegyi@1849: void MainWin::set_tabtitle(std::string name) ladanyi@1616: { hegyi@1872: if(strinst.find(name)==strinst.end()) hegyi@1872: { hegyi@1872: tabnames[active_tab]=name; hegyi@1872: strinst[name]=1; hegyi@1872: } hegyi@1872: else hegyi@1872: { hegyi@1872: strinst[name]++; hegyi@1872: std::ostringstream o; hegyi@1872: o << strinst[name]; hegyi@1872: tabnames[active_tab]=name+" - "+o.str(); hegyi@1872: } hegyi@1849: set_title(tabnames[active_tab] + " - " + prog_name); hegyi@1849: notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); hegyi@1876: updateAlgoWinTabs(); hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::readFile(const std::string & filename) hegyi@1849: { hegyi@1849: newTab(); hegyi@1849: tabs[active_tab]->readFile(filename); hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::newTab() hegyi@1849: { hegyi@1849: int size=tabs.size(); hegyi@1849: tabs.resize(size+1); hegyi@1849: tabnames.resize(size+1); hegyi@1849: active_tab=size; hegyi@1849: tabs[active_tab]=new NoteBookTab(); hegyi@1849: tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle)); hegyi@1849: tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal)); hegyi@1849: tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool); hegyi@1849: notebook.append_page((Gtk::Widget&)(*(tabs[active_tab]))); hegyi@1849: notebook.set_current_page(size); hegyi@1872: set_tabtitle("unsaved file"); hegyi@1876: updateAlgoWinTabs(); hegyi@1849: } hegyi@1849: hegyi@1856: void MainWin::closeTab() hegyi@1856: { hegyi@1856: if(active_tab!=-1) hegyi@1856: { hegyi@1869: if (tabs[active_tab]->mapstorage.modified) hegyi@1869: { hegyi@1869: Gtk::MessageDialog mdialog("Save changes before closing?", true, hegyi@1869: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); hegyi@1869: mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); hegyi@1869: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1869: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@1869: switch (mdialog.run()) hegyi@1869: { hegyi@1869: case Gtk::RESPONSE_CANCEL: hegyi@1869: return; hegyi@1869: case Gtk::RESPONSE_REJECT: hegyi@1869: break; hegyi@1869: case Gtk::RESPONSE_ACCEPT: hegyi@1869: tabs[active_tab]->saveFile(); hegyi@1869: break; hegyi@1869: } hegyi@1869: } hegyi@1856: //tabs vector will be decreased with the deleted value hegyi@1856: int size=tabs.size(); hegyi@1856: if(size>1) hegyi@1856: { hegyi@1856: for(int i=active_tab+1;igd_canvas->changeEditorialTool(active_tool); hegyi@1849: set_title(tabnames[active_tab]); hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::onCloseTab() hegyi@1849: { ladanyi@1616: } ladanyi@1616: ladanyi@1442: void MainWin::newFile() ladanyi@1442: { hegyi@1849: if(active_tab!=-1) ladanyi@1606: { hegyi@1849: tabs[active_tab]->newFile(); ladanyi@1606: } ladanyi@1442: } hegyi@1849: ladanyi@1442: void MainWin::openFile() ladanyi@1442: { hegyi@1849: if(active_tab!=-1) ladanyi@1606: { hegyi@1849: tabs[active_tab]->openFile(); ladanyi@1606: } ladanyi@1442: } hegyi@1849: ladanyi@1442: void MainWin::saveFile() ladanyi@1442: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->saveFile(); hegyi@1849: } ladanyi@1442: } hegyi@1849: ladanyi@1442: void MainWin::saveFileAs() ladanyi@1442: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->saveFileAs(); hegyi@1849: } ladanyi@1442: } hegyi@1849: ladanyi@1606: void MainWin::close() ladanyi@1606: { hegyi@1849: if(active_tab!=-1) ladanyi@1606: { hegyi@1849: tabs[active_tab]->close(); hegyi@1838: } hegyi@1837: } hegyi@1837: hegyi@1849: void MainWin::zoomIn() hegyi@1837: { hegyi@1849: if(active_tab!=-1) hegyi@1838: { hegyi@1849: tabs[active_tab]->gd_canvas->zoomIn(); hegyi@1849: } hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::zoomOut() hegyi@1849: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->gd_canvas->zoomOut(); hegyi@1849: } hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::zoomFit() hegyi@1849: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->gd_canvas->zoomFit(); hegyi@1849: } hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::zoom100() hegyi@1849: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->gd_canvas->zoom100(); hegyi@1838: } hegyi@1837: } hegyi@1838: hegyi@1838: void MainWin::createMapWin() hegyi@1838: { hegyi@1849: if(active_tab!=-1) hegyi@1838: { hegyi@1849: tabs[active_tab]->createMapWin(tabnames[active_tab]); hegyi@1838: } hegyi@1838: } hegyi@1838: hegyi@1871: void MainWin::createAlgoWin(int algoid) hegyi@1871: { hegyi@1878: AlgoWin * aw=new AlgoWin(algoid, tabnames); hegyi@1871: aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin)); hegyi@1876: aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps)); hegyi@1871: aws.insert(aw); hegyi@1871: aw->show(); hegyi@1871: } hegyi@1871: hegyi@1876: void MainWin::updateAlgoWinTabs() hegyi@1871: { hegyi@1871: std::set< AlgoWin* >::iterator awsi=aws.begin(); hegyi@1871: for(;awsi!=aws.end();awsi++) hegyi@1871: { hegyi@1871: (*awsi)->update_tablist(tabnames); hegyi@1871: } hegyi@1871: } hegyi@1871: hegyi@1878: void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname) hegyi@1878: { hegyi@1878: int i=0; hegyi@1878: for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++) hegyi@1878: { hegyi@1878: } hegyi@1878: //awp->update_maplist(tabs[i]->mapstorage.getNodeMapList(),tabs[i]->mapstorage.getEdgeMapList()); hegyi@1878: awp->update_maplist(&(tabs[i]->mapstorage)); hegyi@1878: } hegyi@1878: hegyi@1878: void MainWin::deRegisterAlgoWin(AlgoWin * awp) hegyi@1878: { hegyi@1878: aws.erase(awp); hegyi@1878: } hegyi@1878: hegyi@1849: void MainWin::changeEditorialTool(int tool) hegyi@1838: { hegyi@1849: active_tool=tool; hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: tabs[active_tab]->gd_canvas->changeEditorialTool(tool); hegyi@1849: } hegyi@1838: } hegyi@1849: hegyi@1849: void MainWin::createNewMapWin() hegyi@1849: { hegyi@1849: if(active_tab!=-1) hegyi@1849: { hegyi@1849: NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab])); hegyi@1849: nmw->show(); hegyi@1849: } hegyi@1849: } hegyi@1849: hegyi@1849: void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge) hegyi@1849: { hegyi@1849: std::vector::iterator nbti=tabs.begin(); hegyi@1849: int i=0; hegyi@1849: for(;nbti!=tabs.end();nbti++) hegyi@1849: { hegyi@1849: if(*nbti!=nbt) hegyi@1849: { hegyi@1849: i++; hegyi@1849: } hegyi@1849: else hegyi@1849: { hegyi@1849: continue; hegyi@1849: } hegyi@1849: } hegyi@1849: NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false); hegyi@1849: nmw->run(); hegyi@1849: }