ladanyi@1606: #include "main_win.h" ladanyi@1635: #include "guipixbufs.h" ladanyi@1442: ladanyi@1606: MainWin::MainWin(const std::string& title) : ladanyi@1606: mapwin("Map Setup", mapstorage, gd_canvas), hegyi@1614: newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin, (Gtk::Window *)this) ladanyi@1442: { ladanyi@1442: set_title (title); ladanyi@1442: set_default_size(WIN_WIDTH,WIN_HEIGHT); ladanyi@1442: add(vbox); ladanyi@1442: 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), ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit)); ladanyi@1442: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), ladanyi@1442: 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@1598: sigc::mem_fun(this->mapwin, &MapWin::show)); ladanyi@1442: ladanyi@1606: Gtk::RadioAction::Group tool_group; ladanyi@1634: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), ladanyi@1606: 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@1502: 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@1502: 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@1502: 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@1550: 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@1550: 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@1592: sigc::mem_fun ( this->newmapwin, &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@1442: " " 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@1442: " " 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@1442: 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; ladanyi@1616: gd_canvas.drawGraph(); ladanyi@1616: mapwin.update(); 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: } ladanyi@1606: gd_canvas.clear(); ladanyi@1606: mapstorage.clear(); ladanyi@1606: mapwin.update(); 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: gd_canvas.clear(); ladanyi@1606: mapstorage.clear(); 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: { 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; ladanyi@1645: gd_canvas.drawGraph(); ladanyi@1645: mapwin.update(); 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@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@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: } ladanyi@1606: gd_canvas.clear(); ladanyi@1606: mapstorage.clear(); ladanyi@1606: mapwin.update(); ladanyi@1606: }