ladanyi@1606: #include "main_win.h" alpar@1659: #include "icons/guipixbufs.h" ladanyi@1442: hegyi@1838: MainWin::MainWin():mapwinexists(false) ladanyi@1442: { hegyi@1837: gd_canvas=new GraphDisplayerCanvas(*this); hegyi@1837: ladanyi@1650: set_title ("unsaved file - " + prog_name); ladanyi@1442: set_default_size(WIN_WIDTH,WIN_HEIGHT); ladanyi@1442: add(vbox); ladanyi@1442: hegyi@1837: //connecting signals - controller character hegyi@1837: mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange)); ladanyi@1634: ladanyi@1634: // custom icons for the toolbar ladanyi@1634: 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@1634: ladanyi@1442: ag=Gtk::ActionGroup::create(); ladanyi@1442: ladanyi@1442: ag->add( Gtk::Action::create("FileMenu", "_File") ); ladanyi@1442: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), ladanyi@1442: sigc::mem_fun(*this, &MainWin::newFile)); ladanyi@1442: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), ladanyi@1442: sigc::mem_fun(*this, &MainWin::openFile)); 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), ladanyi@1606: sigc::mem_fun(*this, &MainWin::close)); 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@1837: sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), hegyi@1837: sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), hegyi@1837: sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), hegyi@1837: sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::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: ladanyi@1606: Gtk::RadioAction::Group tool_group; ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) ); ladanyi@1634: ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) ); ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"), hegyi@1837: sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) ); ladanyi@1634: ladanyi@1634: ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), hegyi@1837: sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) ); 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: " " 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: " " 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: ladanyi@1442: Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow()); ladanyi@1777: pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN); hegyi@1837: pScrolledWindow->add(*gd_canvas); ladanyi@1442: vbox.pack_start(*pScrolledWindow); hegyi@1601: hegyi@1601: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); hegyi@1601: tooltips.enable(); ladanyi@1442: ladanyi@1442: show_all_children(); ladanyi@1442: } ladanyi@1442: ladanyi@1616: void MainWin::readFile(const std::string &file) ladanyi@1616: { ladanyi@1616: mapstorage.readFromFile(file); ladanyi@1616: mapstorage.file_name = file; ladanyi@1616: mapstorage.modified = false; hegyi@1837: gd_canvas->drawGraph(); hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); hegyi@1838: } ladanyi@1650: set_title(Glib::filename_display_basename(file) + " - " + prog_name); ladanyi@1616: } ladanyi@1616: ladanyi@1442: void MainWin::newFile() ladanyi@1442: { ladanyi@1606: if (mapstorage.modified) ladanyi@1606: { ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@1606: switch (mdialog.run()) ladanyi@1606: { ladanyi@1606: case Gtk::RESPONSE_CANCEL: ladanyi@1606: return; ladanyi@1606: case Gtk::RESPONSE_REJECT: ladanyi@1606: break; ladanyi@1606: case Gtk::RESPONSE_ACCEPT: ladanyi@1606: saveFile(); ladanyi@1606: break; ladanyi@1606: } ladanyi@1606: } hegyi@1837: gd_canvas->clear(); ladanyi@1606: mapstorage.clear(); hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); hegyi@1838: } ladanyi@1650: set_title("unsaved file - " + prog_name); ladanyi@1442: } ladanyi@1442: ladanyi@1442: void MainWin::openFile() ladanyi@1442: { ladanyi@1606: if (mapstorage.modified) ladanyi@1606: { ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@1606: switch (mdialog.run()) ladanyi@1606: { ladanyi@1606: case Gtk::RESPONSE_CANCEL: ladanyi@1606: return; ladanyi@1606: case Gtk::RESPONSE_REJECT: ladanyi@1606: break; ladanyi@1606: case Gtk::RESPONSE_ACCEPT: ladanyi@1606: saveFile(); ladanyi@1606: break; ladanyi@1606: } ladanyi@1606: } ladanyi@1606: Gtk::FileChooserDialog fcdialog("Open File"); ladanyi@1606: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@1606: fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); ladanyi@1606: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) ladanyi@1606: { hegyi@1837: gd_canvas->clear(); ladanyi@1650: mapstorage.clear(); ladanyi@1606: Glib::ustring filename = fcdialog.get_filename(); ladanyi@1645: if (!mapstorage.readFromFile(filename)) ladanyi@1645: { ladanyi@1645: mapstorage.file_name = filename; ladanyi@1645: mapstorage.modified = false; hegyi@1837: gd_canvas->drawGraph(); hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); hegyi@1838: } ladanyi@1650: set_title(Glib::filename_display_basename(filename) + " - " + prog_name); ladanyi@1645: } ladanyi@1606: } ladanyi@1442: } ladanyi@1442: ladanyi@1442: void MainWin::saveFile() ladanyi@1442: { ladanyi@1606: if (mapstorage.file_name == "") { ladanyi@1606: saveFileAs(); ladanyi@1606: } ladanyi@1606: else ladanyi@1606: { ladanyi@1606: mapstorage.writeToFile(mapstorage.file_name); ladanyi@1606: mapstorage.modified = false; ladanyi@1650: set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " + ladanyi@1650: prog_name); ladanyi@1606: } ladanyi@1442: } ladanyi@1442: ladanyi@1442: void MainWin::saveFileAs() ladanyi@1442: { ladanyi@1606: Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); ladanyi@1606: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@1606: fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@1606: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) ladanyi@1606: { ladanyi@1606: Glib::ustring filename = fcdialog.get_filename(); ladanyi@1606: mapstorage.file_name = filename; ladanyi@1606: mapstorage.writeToFile(filename); ladanyi@1606: mapstorage.modified = false; ladanyi@1650: set_title(Glib::filename_display_basename(filename) + " - " + prog_name); ladanyi@1606: } ladanyi@1442: } ladanyi@1606: ladanyi@1606: void MainWin::close() ladanyi@1606: { ladanyi@1606: if (mapstorage.modified) ladanyi@1606: { ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@1606: switch (mdialog.run()) ladanyi@1606: { ladanyi@1606: case Gtk::RESPONSE_CANCEL: ladanyi@1606: return; ladanyi@1606: case Gtk::RESPONSE_REJECT: ladanyi@1606: break; ladanyi@1606: case Gtk::RESPONSE_ACCEPT: ladanyi@1606: saveFile(); ladanyi@1606: break; ladanyi@1606: } ladanyi@1606: } hegyi@1837: gd_canvas->clear(); ladanyi@1606: mapstorage.clear(); hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); hegyi@1838: } ladanyi@1650: set_title("unsaved file - " + prog_name); ladanyi@1606: } hegyi@1837: hegyi@1837: void MainWin::propertyChange(bool itisedge, int prop, std::string mapname) hegyi@1837: { hegyi@1837: mapstorage.changeActiveMap(itisedge, prop, mapname); hegyi@1837: } hegyi@1837: hegyi@1837: void MainWin::popupNewMapWin(bool itisedge, int prop) hegyi@1837: { hegyi@1837: prop=prop; hegyi@1837: (new NewMapWin("NewMapWin", *this, itisedge, false))->run(); hegyi@1837: } hegyi@1837: hegyi@1837: std::string MainWin::getActiveEdgeMap(int prop) hegyi@1837: { hegyi@1837: return mapstorage.getActiveEdgeMap(prop); hegyi@1837: } hegyi@1837: hegyi@1837: std::string MainWin::getActiveNodeMap(int prop) hegyi@1837: { hegyi@1837: return mapstorage.getActiveNodeMap(prop); hegyi@1837: } hegyi@1837: hegyi@1837: void MainWin::registerNewEdgeMap(std::string mapname) hegyi@1837: { hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->registerNewEdgeMap(mapname); hegyi@1838: } hegyi@1837: } hegyi@1837: hegyi@1837: void MainWin::registerNewNodeMap(std::string mapname) hegyi@1837: { hegyi@1838: if(mapwinexists) hegyi@1838: { hegyi@1838: mapwin->registerNewNodeMap(mapname); hegyi@1838: } hegyi@1837: } hegyi@1838: hegyi@1838: void MainWin::createMapWin() hegyi@1838: { hegyi@1838: if(!mapwinexists) hegyi@1838: { hegyi@1838: mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this); hegyi@1838: mapwin->show(); hegyi@1838: mapwinexists=true; hegyi@1838: } hegyi@1838: } hegyi@1838: hegyi@1838: void MainWin::closeMapWin() hegyi@1838: { hegyi@1838: mapwinexists=false; hegyi@1838: delete mapwin; hegyi@1838: }