ladanyi@1442: // -*- C++ -*- //
ladanyi@1442: 
ladanyi@1442: #ifndef MAIN_WIN_H
ladanyi@1442: #define MAIN_WIN_H
ladanyi@1442: 
ladanyi@1606: #include "all_include.h"
hegyi@1871: #include "algowin.h"
ladanyi@1606: #include "map_win.h"
ladanyi@1606: #include "new_map_win.h"
hegyi@1849: #include "nbtab.h"
ladanyi@1442: #include <libgnomecanvasmm.h>
ladanyi@1442: #include <libgnomecanvasmm/polygon.h>
ladanyi@1442: 
hegyi@1849: 
ladanyi@1442: ///This class is the main window of GUI.
hegyi@1889: 
hegyi@1889: ///It has menus, and a notebook. Notebook has different pages,
hegyi@1889: ///the so called tabs (\ref NoteBookTab). Each \ref NoteBookTab contains a canvas on which graphs can be drawn.
hegyi@1889: ///To manage creation and close of tabs and tabswitching is the task of MainWin.
ladanyi@1442: class MainWin : public Gtk::Window
ladanyi@1442: {
hegyi@1889:   ///Container in which the menus and the notebook is.
hegyi@1849:   Gtk::VBox vbox;
hegyi@1849: 
hegyi@1889:   ///The notebook that has tabs (\ref NoteBookTab) with different graphs.
hegyi@1849:   Gtk::Notebook notebook;
hegyi@1849: 
hegyi@1889:   ///The tool selected to manipulate graph.
hegyi@1889: 
hegyi@1889:   ///It has to be stored, because in case of tabswitching
hegyi@1889:   ///the correct tool has to be set for the actual graph.
hegyi@1849:   int active_tool;
hegyi@1849: 
hegyi@1889:   ///The number of active tab in the notebook.
hegyi@1849:   int active_tab;
hegyi@1889: 
hegyi@1889:   ///Vector of existing tabs in the notebook.
hegyi@1849:   std::vector<NoteBookTab *> tabs;
hegyi@1889: 
hegyi@1889:   ///Vector of the name of tabs.
hegyi@1889: 
hegyi@1889:   ///All \ref NoteBookTab has a name that is stored here. The index of the name
hegyi@1889:   ///is the same as the index of the \ref NoteBookTab in \ref tabs.
hegyi@1849:   std::vector<std::string> tabnames;
hegyi@1849: 
hegyi@1889:   ///Counter of occurence of the same file names.
hegyi@1889: 
hegyi@1889:   ///If a file is opened more than once we have to score
hegyi@1889:   ///the occurences to let the titles on tabs different.
hegyi@1889:   ///If more than one occurence is present, from the second
hegyi@1889:   ///one near the filename the number of the occurence appear.
hegyi@1872:   std::map<std::string, int> strinst;
hegyi@1872: 
hegyi@1889:   ///Set of opened \ref AlgoWin s.
hegyi@1889: 
hegyi@1889:   ///More than one \refAlgoWin can be opened. We have to
hegyi@1889:   ///communicate with them in case of new \ref NoteBookTab creation,
hegyi@1889:   ///\ref NoteBookTab close, or map change. Therefore we have to score
hegyi@1889:   ///their occurences.
hegyi@1871:   std::set< AlgoWin* > aws;
hegyi@1871: 
ladanyi@1442: public:
hegyi@1849:   
hegyi@1889:   ///Constructor of the \ref MainWin.
hegyi@1889: 
hegyi@1889:   ///It creates the menus, the toolbar and the notebook in which
hegyi@1889:   ///\ref NoteBookTab s take place. \ref NoteBookTab s are the
hegyi@1889:   ///holder of the canvases on which the graphs are drawn.
ladanyi@1650:   MainWin();
ladanyi@1606: 
hegyi@1889:   ///Sets title of tabs.
hegyi@1889: 
hegyi@1889:   ///It alse registrates it in \ref tabnames. If more than one
hegyi@1889:   ///occurence is in the notebook of the same file it has to
hegyi@1889:   ///extend tabname with the number of occurence.
hegyi@1849:   void set_tabtitle(std::string);
ladanyi@1442: 
ladanyi@1442:   ///ActionGroup for menu
ladanyi@1442:   Glib::RefPtr<Gtk::ActionGroup> ag;
ladanyi@1442: 
ladanyi@1442:   ///UIManager for menu
ladanyi@1442:   Glib::RefPtr<Gtk::UIManager> uim;
ladanyi@1442: 
hegyi@1889:   ///Creates a new \ref NoteBookTab and opens the given file.
hegyi@1889: 
hegyi@1889:   ///It is called only with command line parameters at stratup.
hegyi@1849:   void readFile(const std::string &);
ladanyi@1442: 
hegyi@1601:   ///Tooltips
hegyi@1601:   Gtk::Tooltips tooltips;
hegyi@1601: 
hegyi@1849:   //Call-backs of buttons
hegyi@1849: 
ladanyi@1442:   ///Callback for 'FileNew' action.
ladanyi@1442:   virtual void newFile();
ladanyi@1442:   ///Callback for 'FileOpen' action.
ladanyi@1442:   virtual void openFile();
ladanyi@1442:   ///Callback for 'FileSave' action.
ladanyi@1442:   virtual void saveFile();
ladanyi@1442:   ///Callback for 'FileSaveAs' action.
ladanyi@1442:   virtual void saveFileAs();
ladanyi@1606:   ///Callback for 'Close' action.
ladanyi@1606:   virtual void close();
hegyi@1837: 
hegyi@1849:   //Toolbar
hegyi@1889: 
hegyi@1889:   ///Callback for 'zoomIn' action.
hegyi@1889: 
hegyi@1889:   ///It calls the appropriate function in
hegyi@1889:   ///\ref GraphDisplayerCanvas
hegyi@1849:   virtual void zoomIn();
hegyi@1889:   ///Callback for 'zoomOut' action.
hegyi@1889: 
hegyi@1889:   ///It calls the appropriate function in
hegyi@1889:   ///\ref GraphDisplayerCanvas
hegyi@1849:   virtual void zoomOut();
hegyi@1889:   ///Callback for 'zoomFit' action.
hegyi@1889: 
hegyi@1889:   ///It calls the appropriate function in
hegyi@1889:   ///\ref GraphDisplayerCanvas
hegyi@1849:   virtual void zoomFit();
hegyi@1889:   ///Callback for 'zoom100' action.
hegyi@1889: 
hegyi@1889:   ///It calls the appropriate function in
hegyi@1889:   ///\ref GraphDisplayerCanvas
hegyi@1849:   virtual void zoom100();
hegyi@1837: 
hegyi@1889:   ///Callback for Show Maps menupoint.
hegyi@1889: 
hegyi@1889:   ///It calls the appropriate function in
hegyi@1889:   ///\ref NoteBookTab
hegyi@1849:   virtual void createMapWin();
hegyi@1837: 
hegyi@1889:   ///Pops up an Algorithm window.
hegyi@1889: 
hegyi@1889:   ///It not only creates but registrates the newly created \ref AlgoWin.
hegyi@1889:   ///It is necessary, because in case of changement between tabs or maps
hegyi@1889:   ///we have to communicate with it. Signals are also have to be connected
hegyi@1889:   ///to it, because \ref AlgoWin emits signals if it needs anything (maplist, deregistration).
hegyi@1889:   ///\param algo type of the algorithm to run.
hegyi@1889:   virtual void createAlgoWin(int algo);
hegyi@1889: 
hegyi@1889:   ///Deregisters AlgoWin
hegyi@1889: 
hegyi@1889:   ///This is the function connected to the closing signal of \ref AlgoWin.
hegyi@1889:   ///It only deletes the sender \ref AlgoWin from \ref aws. This function
hegyi@1889:   ///is called only by the closing \ref AlgoWin itself.
hegyi@1889:   ///\param aw the \ref AlgoWin to delete.
hegyi@1889:   virtual void deRegisterAlgoWin(AlgoWin * aw);
hegyi@1889: 
hegyi@1889:   ///Updates list of tabs in all of the \ref AlgoWin
hegyi@1889: 
hegyi@1889:   ///When \ref NoteBookTab inserted somewhere or closed one tablist in all \ref AlgoWin
hegyi@1889:   ///have to be updated. That is why we score all the opened \ref AlgoWin.
hegyi@1889:   ///During update \ref tabnames will be passed to each \ref AlgoWin.
hegyi@1876:   virtual void updateAlgoWinTabs();
hegyi@1871: 
hegyi@1889:   ///Refresh list of maps in the AlgoWin that requested it.
hegyi@1837: 
hegyi@1889:   ///In an \ref AlgoWin there is a ComboBoxText, in which
hegyi@1889:   ///a \ref NoteBookTab can be chosen that contains the graph and the maps,
hegyi@1889:   ///on which we would like to run algorithms. If we change the
hegyi@1889:   ///tab the available maps also have to be updated, because
hegyi@1889:   ///in the different tabs different maps are available. Therefore
hegyi@1889:   ///on tab change the \ref AlgoWin emits a signal that contains itself
hegyi@1889:   ///so that the appropriate maps can be sent to it. For the sake of simplicity
hegyi@1889:   ///the program answers this call with the mapstorage of the newly selected tab.
hegyi@1889:   ///\param aw the caller \ref AlgoWin
hegyi@1889:   ///\param tabname the newly selected tab in the \ref AlgoWin
hegyi@1889:   virtual void updateAlgoWinMaps(AlgoWin * aw, std::string tabname);
hegyi@1889: 
hegyi@1889:   ///Registrates the new graph-editor tool in hand.
hegyi@1889: 
hegyi@1889:   ///The editor-tool in hand is global, it is the same for all tab
hegyi@1889:   ///at the same time. Therefore the active tool has to be scored here (\ref active_tool).
hegyi@1889:   ///This function is the callback function of the editor-tool buttons. It sets \ref active_tool
hegyi@1889:   ///to the correct value.
hegyi@1889:   ///\param tool the newly selected graph-editor tool (See all_include.h)
hegyi@1889:   virtual void changeEditorialTool(int tool);
hegyi@1889: 
hegyi@1889:   ///Pops up a \ref NewMapWin dialog after requested by a \ref MapWin
hegyi@1889: 
hegyi@1889:   ///Each tab can pop-up a \ref MapWin. In \ref MapWin new tab can be created.
hegyi@1889:   ///In this case \ref NoteBookTab emits a signal. This function is connected to that signal.
hegyi@1889:   ///It sends the caller \ref NoteBookTab and whether an edgemap or a nodemap should be created.
hegyi@1889:   ///Caller \ref NoteBookTab is necessary for the window to be able to place the new map in its
hegyi@1889:   ///correct place.
hegyi@1889:   ///\param nbt the caller tab
hegyi@1889:   ///\param itisedge true if edgemap has to be created, false if nodemap
hegyi@1889:   virtual void createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge);
hegyi@1889: 
hegyi@1889:   ///Pops up a \ref NewMapWin dialog after requested by an \ref AlgoWin
hegyi@1889: 
hegyi@1889:   ///\ref AlgoWin can also can request a \ref NewMapWin to pop-up. 
hegyi@1889:   ///It emits a signal in this case. This function is bound to that signal.
hegyi@1889:   ///The signal contains the name of \ref NoteBookTab in which the new map has to be
hegyi@1889:   ///placed and whether the new map is an edgemap or a nodemap.
hegyi@1889:   ///\ref tabname the tab in which the new map has to be placed
hegyi@1889:   ///\ref itisedge true if the new map will be edge map, false if it will be nodemap
hegyi@1889:   virtual void createNewMapWinTabString(std::string tabname, bool itisedge);
hegyi@1889: 
hegyi@1889:   ///Pops up a \ref NewMapWin dialog if button on \ref MainWin has been pressed.
hegyi@1889: 
hegyi@1889:   ///In this case a general \ref NewMapWin will be popped up. This means that
hegyi@1889:   ///both edge and nodemap can be created by it. The new map will be placed in
hegyi@1889:   ///\MapStorage of the actual selected \ref NoteBookTab.
hegyi@1849:   virtual void createNewMapWin();
hegyi@1849: 
hegyi@1849:   //Notebook handlers
hegyi@1849:   ///Callback for 'FileNewTab' action.
hegyi@1849:   virtual void newTab();
hegyi@1889: 
hegyi@1889:   ///Callback for 'FileCloseTab' action.
hegyi@1889: 
hegyi@1889:   ///It closes the actual \ref NoteBookTab and registrates this event:
hegyi@1889:   ///data is shifted to the correct places in vectors.
hegyi@1856:   virtual void closeTab();
hegyi@1889: 
hegyi@1889:   ///Tabswitching handler
hegyi@1889: 
hegyi@1889:   ///Sets the variables that have to store the actual state, and it
hegyi@1889:   ///updates the title of window to the actually selected \ref NoteBookTab.
hegyi@1849:   virtual void onChangeTab(GtkNotebookPage*, guint);
ladanyi@1442: };
ladanyi@1442: 
ladanyi@1442: #endif //MAIN_WIN_H