ladanyi@53: #include "main_win.h" alpar@76: #include "icons/guipixbufs.h" ladanyi@6: ladanyi@68: MainWin::MainWin() : hegyi@82: newmapwin("Creating new map", gd_canvas), hegyi@82: mapwin("Map Setup", mapstorage, gd_canvas, newmapwin), hegyi@82: gd_canvas(mapstorage, mapwin, (Gtk::Window *)this) ladanyi@6: { ladanyi@68: set_title ("unsaved file - " + prog_name); ladanyi@6: set_default_size(WIN_WIDTH,WIN_HEIGHT); ladanyi@6: add(vbox); ladanyi@6: ladanyi@60: ladanyi@60: // custom icons for the toolbar ladanyi@60: ladanyi@60: Glib::RefPtr p_icon_factory = Gtk::IconFactory::create(); ladanyi@60: ladanyi@61: Glib::RefPtr p_move_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_move); ladanyi@61: Glib::RefPtr p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_addnode); ladanyi@61: Glib::RefPtr p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_addlink); ladanyi@61: Glib::RefPtr p_delete_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_delete); ladanyi@61: Glib::RefPtr p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_editlink); ladanyi@61: Glib::RefPtr p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_editnode); ladanyi@61: Glib::RefPtr p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_newmap); ladanyi@60: ladanyi@60: Gtk::IconSource move_icon_source; ladanyi@61: move_icon_source.set_pixbuf(p_move_pixbuf); ladanyi@60: Gtk::IconSet move_icon_set; ladanyi@60: move_icon_set.add_source(move_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource addnode_icon_source; ladanyi@61: addnode_icon_source.set_pixbuf(p_addnode_pixbuf); ladanyi@60: Gtk::IconSet addnode_icon_set; ladanyi@60: addnode_icon_set.add_source(addnode_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource addlink_icon_source; ladanyi@61: addlink_icon_source.set_pixbuf(p_addlink_pixbuf); ladanyi@60: Gtk::IconSet addlink_icon_set; ladanyi@60: addlink_icon_set.add_source(addlink_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource delete_icon_source; ladanyi@61: delete_icon_source.set_pixbuf(p_delete_pixbuf); ladanyi@60: Gtk::IconSet delete_icon_set; ladanyi@60: delete_icon_set.add_source(delete_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource editlink_icon_source; ladanyi@61: editlink_icon_source.set_pixbuf(p_editlink_pixbuf); ladanyi@60: Gtk::IconSet editlink_icon_set; ladanyi@60: editlink_icon_set.add_source(editlink_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource editnode_icon_source; ladanyi@61: editnode_icon_source.set_pixbuf(p_editnode_pixbuf); ladanyi@60: Gtk::IconSet editnode_icon_set; ladanyi@60: editnode_icon_set.add_source(editnode_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource newmap_icon_source; ladanyi@61: newmap_icon_source.set_pixbuf(p_newmap_pixbuf); ladanyi@60: Gtk::IconSet newmap_icon_set; ladanyi@60: newmap_icon_set.add_source(newmap_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); ladanyi@60: ladanyi@60: p_icon_factory->add_default(); ladanyi@60: ladanyi@60: ladanyi@6: ag=Gtk::ActionGroup::create(); ladanyi@6: ladanyi@6: ag->add( Gtk::Action::create("FileMenu", "_File") ); ladanyi@6: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), ladanyi@6: sigc::mem_fun(*this, &MainWin::newFile)); ladanyi@6: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), ladanyi@6: sigc::mem_fun(*this, &MainWin::openFile)); ladanyi@6: ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), ladanyi@6: sigc::mem_fun(*this, &MainWin::saveFile)); ladanyi@6: ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), ladanyi@6: sigc::mem_fun(*this, &MainWin::saveFileAs)); ladanyi@53: ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), ladanyi@53: sigc::mem_fun(*this, &MainWin::close)); ladanyi@53: ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), hegyi@47: sigc::mem_fun(*this, &MainWin::hide)); ladanyi@6: ladanyi@6: ag->add( Gtk::Action::create("ViewMenu", "_View") ); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100)); ladanyi@6: ladanyi@6: ag->add( Gtk::Action::create("ShowMenu", "_Show") ); ladanyi@6: ag->add( Gtk::Action::create("ShowMaps", "_Maps"), hegyi@47: sigc::mem_fun(this->mapwin, &MapWin::show)); ladanyi@6: ladanyi@53: Gtk::RadioAction::Group tool_group; ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), ladanyi@53: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"), hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) ); ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"), hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) ); ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"), hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) ); ladanyi@60: ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"), hegyi@32: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) ); ladanyi@60: ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"), hegyi@32: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) ); ladanyi@60: ladanyi@60: ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), hegyi@41: sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) ); hegyi@22: ladanyi@6: uim=Gtk::UIManager::create(); ladanyi@6: uim->insert_action_group(ag); ladanyi@6: add_accel_group(uim->get_accel_group()); ladanyi@6: ladanyi@6: try ladanyi@6: { ladanyi@6: ladanyi@6: Glib::ustring ui_info = ladanyi@6: "" ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@53: " " ladanyi@53: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@87: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@53: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@87: " " hegyi@22: " " ladanyi@53: " " hegyi@22: " " hegyi@22: " " hegyi@22: " " hegyi@32: " " hegyi@32: " " ladanyi@60: " " hegyi@41: " " ladanyi@6: " " ladanyi@6: ""; ladanyi@6: ladanyi@6: uim->add_ui_from_string(ui_info); ladanyi@6: ladanyi@6: } ladanyi@6: catch(const Glib::Error& ex) ladanyi@6: { ladanyi@6: std::cerr << "building menus failed: " << ex.what(); ladanyi@6: } ladanyi@6: ladanyi@6: Gtk::Widget* menubar = uim->get_widget("/MenuBar"); ladanyi@6: if (menubar){ ladanyi@6: vbox.pack_start(*menubar, Gtk::PACK_SHRINK); ladanyi@6: } ladanyi@6: ladanyi@6: Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); ladanyi@6: if (toolbar) ladanyi@6: { ladanyi@6: static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); ladanyi@6: vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); ladanyi@6: } ladanyi@6: ladanyi@6: Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow()); ladanyi@87: pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN); ladanyi@6: pScrolledWindow->add(gd_canvas); ladanyi@6: vbox.pack_start(*pScrolledWindow); hegyi@50: hegyi@50: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); hegyi@50: tooltips.enable(); ladanyi@6: ladanyi@6: show_all_children(); ladanyi@6: } ladanyi@6: ladanyi@57: void MainWin::readFile(const std::string &file) ladanyi@57: { ladanyi@57: mapstorage.readFromFile(file); ladanyi@57: mapstorage.file_name = file; ladanyi@57: mapstorage.modified = false; ladanyi@57: gd_canvas.drawGraph(); ladanyi@57: mapwin.update(); ladanyi@68: set_title(Glib::filename_display_basename(file) + " - " + prog_name); ladanyi@57: } ladanyi@57: ladanyi@6: void MainWin::newFile() ladanyi@6: { ladanyi@53: if (mapstorage.modified) ladanyi@53: { ladanyi@56: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@56: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@53: switch (mdialog.run()) ladanyi@53: { ladanyi@53: case Gtk::RESPONSE_CANCEL: ladanyi@53: return; ladanyi@53: case Gtk::RESPONSE_REJECT: ladanyi@53: break; ladanyi@53: case Gtk::RESPONSE_ACCEPT: ladanyi@53: saveFile(); ladanyi@53: break; ladanyi@53: } ladanyi@53: } ladanyi@53: gd_canvas.clear(); ladanyi@53: mapstorage.clear(); ladanyi@53: mapwin.update(); ladanyi@68: set_title("unsaved file - " + prog_name); ladanyi@6: } ladanyi@6: ladanyi@6: void MainWin::openFile() ladanyi@6: { ladanyi@53: if (mapstorage.modified) ladanyi@53: { ladanyi@56: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@56: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@53: switch (mdialog.run()) ladanyi@53: { ladanyi@53: case Gtk::RESPONSE_CANCEL: ladanyi@53: return; ladanyi@53: case Gtk::RESPONSE_REJECT: ladanyi@53: break; ladanyi@53: case Gtk::RESPONSE_ACCEPT: ladanyi@53: saveFile(); ladanyi@53: break; ladanyi@53: } ladanyi@53: } ladanyi@53: Gtk::FileChooserDialog fcdialog("Open File"); ladanyi@53: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@53: fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); ladanyi@53: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) ladanyi@53: { ladanyi@68: gd_canvas.clear(); ladanyi@68: mapstorage.clear(); ladanyi@53: Glib::ustring filename = fcdialog.get_filename(); ladanyi@63: if (!mapstorage.readFromFile(filename)) ladanyi@63: { ladanyi@63: mapstorage.file_name = filename; ladanyi@63: mapstorage.modified = false; ladanyi@63: gd_canvas.drawGraph(); ladanyi@63: mapwin.update(); ladanyi@68: set_title(Glib::filename_display_basename(filename) + " - " + prog_name); ladanyi@63: } ladanyi@53: } ladanyi@6: } ladanyi@6: ladanyi@6: void MainWin::saveFile() ladanyi@6: { ladanyi@53: if (mapstorage.file_name == "") { ladanyi@53: saveFileAs(); ladanyi@53: } ladanyi@53: else ladanyi@53: { ladanyi@53: mapstorage.writeToFile(mapstorage.file_name); ladanyi@53: mapstorage.modified = false; ladanyi@68: set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " + ladanyi@68: prog_name); ladanyi@53: } ladanyi@6: } ladanyi@6: ladanyi@6: void MainWin::saveFileAs() ladanyi@6: { ladanyi@53: Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); ladanyi@53: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@53: fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@53: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) ladanyi@53: { ladanyi@53: Glib::ustring filename = fcdialog.get_filename(); ladanyi@53: mapstorage.file_name = filename; ladanyi@53: mapstorage.writeToFile(filename); ladanyi@53: mapstorage.modified = false; ladanyi@68: set_title(Glib::filename_display_basename(filename) + " - " + prog_name); ladanyi@53: } ladanyi@6: } ladanyi@53: ladanyi@53: void MainWin::close() ladanyi@53: { ladanyi@53: if (mapstorage.modified) ladanyi@53: { ladanyi@56: Gtk::MessageDialog mdialog("Save changes before closing?", true, ladanyi@56: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); ladanyi@53: switch (mdialog.run()) ladanyi@53: { ladanyi@53: case Gtk::RESPONSE_CANCEL: ladanyi@53: return; ladanyi@53: case Gtk::RESPONSE_REJECT: ladanyi@53: break; ladanyi@53: case Gtk::RESPONSE_ACCEPT: ladanyi@53: saveFile(); ladanyi@53: break; ladanyi@53: } ladanyi@53: } ladanyi@53: gd_canvas.clear(); ladanyi@53: mapstorage.clear(); ladanyi@53: mapwin.update(); ladanyi@68: set_title("unsaved file - " + prog_name); ladanyi@53: }