hegyi@1885: // -*- C++ -*- //
hegyi@1885: 
hegyi@1885: #ifndef MAPSELECTOR_H
hegyi@1885: #define MAPSELECTOR_H
hegyi@1885: 
hegyi@1885: class MapSelector;
hegyi@1885: 
hegyi@1885: #include <all_include.h>
hegyi@1885: #include <map_win.h>
hegyi@1885: #include <libgnomecanvasmm.h>
hegyi@1885: #include <libgnomecanvasmm/polygon.h>
hegyi@1885: 
hegyi@1892: ///A widget by which node and edgemaps can be selected, deselected and created.
hegyi@1892: 
hegyi@1892: ///During the usage of \ref glemon we have to select
hegyi@1892: ///maps several times. We also need some aid-function
hegyi@1892: ///like new map creation and deselecting previously
hegyi@1892: ///selected map. Instead of writing a the mapselection
hegyi@1892: ///at all occurences we can use this widget by connecting
hegyi@1892: ///its signals to the correct place.
hegyi@1885: class MapSelector : public Gtk::HBox
hegyi@1885: {
hegyi@1885:  protected:
hegyi@1892:   ///This signal indicates that the selection has been changed by user.
hegyi@1885:   sigc::signal<void, std::string> signal_cbt;
hegyi@1892: 
hegyi@1892:   ///Signal that indicates that user wants to create a new map.
hegyi@1885:   sigc::signal<void, bool> signal_newmapwin;
hegyi@1885: 
hegyi@1892:   ///If this is true, beyond the mapnames a 'Default' selection is available as well.
hegyi@1892: 
hegyi@1892:   ///For example \ref MapWin needs 'Default' option as well. In this case no map
hegyi@1892:   ///will be visualized by the appropriate property.
hegyi@1892:   ///But \ref AlgoWin do not need 'Default' option, because if no map is selected,
hegyi@1892:   ///no algorithm can be run.
hegyi@1892:   ///Its value is got and set in contructor.
hegyi@1885:   bool def;
hegyi@1885: 
hegyi@1892:   ///Are the names of edgemaps or nodemaps stored here.
hegyi@1885:   bool itisedge;
hegyi@1885: 
hegyi@1892:   ///Shows whether 'Default' option is selected or not.
hegyi@1885:   bool default_state;
hegyi@1885: 
hegyi@1892:   ///It is true when the new button had been pressed but the new map has not been registrated yet.
hegyi@1892: 
hegyi@1892:   ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector
hegyi@1892:   ///this variable is set to true. When the new map
hegyi@1892:   ///is done, it will be registrated in all existing \ref MapSelector 
hegyi@1892:   ///by \ref append_text function. That function checks
hegyi@1892:   ///whether this variable is true. If it is true that means
hegyi@1892:   ///that this \ref MapSelector has requested \ref NewMapWin.
hegyi@1892:   ///Therefore it set itself to the recently created map.
hegyi@1892:   ///After that \ref set_new_map is set again false, not to
hegyi@1892:   ///set maps active if \ref MapSelector piece is not the requester.
hegyi@1885:   bool set_new_map;
hegyi@1885: 
hegyi@1892:   ///The widget that holds the names of maps.
hegyi@1892: 
hegyi@1892:   ///It can be rolled down
hegyi@1892:   ///Names in it are selectable.
hegyi@1885:   Gtk::ComboBoxText cbt;
hegyi@1885: 
hegyi@1892:   ///New button.
hegyi@1885: 
hegyi@1892:   ///By pressing it
hegyi@1892:   ///\ref NewMapWin wilol pop-up
hegyi@1892:   Gtk::Button * newbut;
hegyi@1892: 
hegyi@1892:   ///Reset button.
hegyi@1892: 
hegyi@1892:   ///If pressed \ref cbt will
hegyi@1892:   ///set to 'Default' option.
hegyi@1892:   ///
hegyi@1892:   ///It is visible only if \ref def is true.
hegyi@1892:   Gtk::Button * defbut;
hegyi@1892: 
hegyi@1892:   ///Container in which GUI elements are packed.
hegyi@1885:   Gtk::HBox hbox;
hegyi@1885: 
hegyi@1892:   ///Shows purpose of \ref MapSelector piece.
hegyi@1885:   Gtk::Label * label;
hegyi@1885: 
hegyi@1885:  public:
hegyi@1885: 
hegyi@1892:   ///Constructor of \ref MapSelector
hegyi@1885: 
hegyi@1892:   ///Creates the layout and binds signal to the correct place.
hegyi@1892:   ///\param optionlist list of names to place in \ref cbt
hegyi@1892:   ///\param act preselected option
hegyi@1892:   ///\param purpose text of label indicating purpose of \ref MapStorage
hegyi@1892:   ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames.
hegyi@1892:   ///\param def do we need 'Default' option. See \ref def.
hegyi@1892:   MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true);
hegyi@1892: 
hegyi@1893:   ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
hegyi@1885:   sigc::signal<void, std::string> signal_cbt_ch();
hegyi@1892: 
hegyi@1893:   ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin)
hegyi@1885:   sigc::signal<void, bool> signal_newmapwin_needed();
hegyi@1885: 
hegyi@1892:   ///Maintain \ref cbt.
hegyi@1892: 
hegyi@1892:   ///Fills in \ref cbt with names, taking
hegyi@1892:   ///into account that the previously selected option
hegyi@1892:   ///has to be set back after the operation.
hegyi@1885:   void update_list( std::vector<std::string> );
hegyi@1885: 
hegyi@1892:   ///Handles changement in \ref cbt.
hegyi@1892: 
hegyi@1892:   ///In default case it emits a signal with the selected option.
hegyi@1892:   ///But if 'Default' option is selected, it resets the \ref MapSelector
hegyi@1885:   virtual void comboChanged();
hegyi@1885: 
hegyi@1892:   ///Requests a \ref NewMapWin
hegyi@1892: 
hegyi@1892:   ///See \ref set_new_map.
hegyi@1892:   ///First it sets \ref set_new_map true to be identified
hegyi@1892:   ///at registration of new map that
hegyi@1892:   ///it has sent the \ref signal_newmapwin, therefore it
hegyi@1892:   ///has to set \ref cbt to that option.
hegyi@1885:   virtual void new_but_pressed();
hegyi@1885: 
hegyi@1892:   ///If called, 'Default' option is selected, that means unselection of any maps.
hegyi@1892: 
hegyi@1892:   ///Practically this means that if this is called,
hegyi@1892:   ///properties of graph will set to default state.
hegyi@1892:   ///The function achieves this by emitting appropriately
hegyi@1892:   ///parametrized signal_cbt.
hegyi@1885:   virtual void reset();
hegyi@1885: 
hegyi@1892:   ///Returns the currently selected option.
hegyi@1885:   Glib::ustring get_active_text();
hegyi@1892: 
hegyi@1892:   ///Sets the parameter active in \ref cbt.
hegyi@1892: 
hegyi@1892:   ///\param new_value the
hegyi@1892:   ///new value to be set in \ref cbt.
hegyi@1892:   void set_active_text(Glib::ustring new_value);
hegyi@1892: 
hegyi@1892:   ///Sets the parameter active in \ref cbt.
hegyi@1892:   ///\param index the
hegyi@1892:   ///index of row to be set in \ref cbt.
hegyi@1885:   void set_active(int index){cbt.set_active(index);};
hegyi@1892: 
hegyi@1892:   ///Clear all options from \ref cbt.
hegyi@1885:   void clear(){cbt.clear();};
hegyi@1892: 
hegyi@1892:   ///Appends a new option to the existing ones in \ref cbt.
hegyi@1892: 
hegyi@1892:   ///If \ref set_new_map is true, the
hegyi@1892:   ///\ref MapSelector has requested the opened \ref NewMapWin,
hegyi@1892:   ///from that the option to append is coming. In this case
hegyi@1892:   ///this function  will set \ref cbt to the new option.
hegyi@1892:   ///\param new_option new option to append
hegyi@1892:   void append_text(Glib::ustring new_option);
hegyi@1885: };
hegyi@1885: #endif //MAPSELECTOR_H