MeshTex  3.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
GenericMainMenu.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright 2012 Joel Baxter
9  *
10  * This file is part of MeshTex.
11  *
12  * MeshTex is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * MeshTex is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #if !defined(INCLUDED_GENERICMAINMENU_H)
27 #define INCLUDED_GENERICMAINMENU_H
28 
29 #include <string>
30 #include <map>
31 
32 #include "RefCounted.h"
33 #include "GenericDialog.h"
34 
35 #include "generic/callback.h"
36 #include "generic/referencecounted.h"
37 
42 #define MENU_SEPARATOR "-"
43 
54 {
55 protected: // protected methods
56 
58 
60  virtual ~GenericMainMenu();
62 
63 private: // private methods
64 
66 
68  const GenericMainMenu& operator=(const GenericMainMenu&);
70 
71 public: // public methods
72 
74 
75  virtual void Dispatch(const char *command);
76  virtual void CommandDialogShow(const std::string& commandString);
77  const std::string& GetCommandList() const;
78  const std::string& GetCommandLabelList() const;
80 
81 protected: // protected types
86  typedef Callback1<const std::string&, void> CommandCallback;
87 
97  template<typename ObjectClass, void (ObjectClass::*member)(const std::string&)>
99  public MemberCaller1<ObjectClass, const std::string&, member>
100  {
101  public:
107  CommandCallbackMethod(ObjectClass& object) :
108  MemberCaller1<ObjectClass, const std::string&, member>(object) {}
109  };
110 
111 protected: // protected methods
112 
114 
115  virtual void BeginEntries();
116  virtual void AddSeparator();
117  virtual std::string AddEntry(const char *commandLabel,
118  const char *command,
119  const CommandCallback& commandCallback);
120  virtual void AddDialogShowEntry(const char *commandLabel,
121  const char *command,
122  const SmartPointer<GenericDialog>& dialog);
123  virtual void EndEntries();
125 
126 private: // private types
127 
131  typedef std::map<std::string, SmartPointer<GenericDialog> > DialogMap;
132 
133 private: // private member vars
134 
138  std::string _menuCommands;
139 
143  std::string _menuCommandLabels;
144 
148  std::map<std::string, CommandCallback> _dispatchMap;
149 
154 };
155 
156 #endif // #if !defined(INCLUDED_GENERICMAINMENU_H)