1 /*
2 * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 #ifndef __ZLAPPLICATIONWINDOW_H__
21 #define __ZLAPPLICATIONWINDOW_H__
22
23 #include <string>
24
25 #include "ZLApplication.h"
26 #include "ZLToolbar.h"
27
28 class ZLApplicationWindow {
29
30 public:
31 static ZLApplicationWindow &Instance();
32
33 private:
34 static ZLApplicationWindow *ourInstance;
35
36 protected:
37 ZLApplicationWindow(ZLApplication *application);
38
39 public:
40 virtual ~ZLApplicationWindow();
41
42 public:
43 ZLApplication &application() const;
44
45 protected:
46 virtual ZLViewWidget *createViewWidget() = 0;
47
48 virtual void init();
49
50 enum ToolbarType {
51 WINDOW_TOOLBAR,
52 FULLSCREEN_TOOLBAR
53 };
54
55 private:
56 void initToolbar(ToolbarType type);
57
58 protected:
59 // TODO: change to pure virtual
initMenu()60 virtual void initMenu() {};
61
62 ToolbarType type(const ZLToolbar::Item &item) const;
63 bool hasFullscreenToolbar() const;
64 void onButtonPress(const ZLToolbar::AbstractButtonItem &button);
65 virtual void addToolbarItem(ZLToolbar::ItemPtr item) = 0;
66 // TODO: change to pure virtual
setToolbarItemState(ZLToolbar::ItemPtr,bool,bool)67 virtual void setToolbarItemState(ZLToolbar::ItemPtr /*item*/, bool /*visible*/, bool /*enabled*/) {};
68 virtual void setToggleButtonState(const ZLToolbar::ToggleButtonItem &toggleButton) = 0;
69
70 virtual void refresh();
71 virtual void processAllEvents() = 0;
72
73 private:
74 void refreshToolbar(ToolbarType type);
75
76 protected:
77 // TODO: change to pure virtual
present()78 virtual void present() {}
79
80 virtual void close() = 0;
81
82 virtual void setCaption(const std::string &caption) = 0;
83
84 virtual void grabAllKeys(bool grab) = 0;
85
86 virtual void setFullscreen(bool fullscreen) = 0;
87 virtual bool isFullscreen() const = 0;
88
89 // TODO: change to pure virtual (?)
setHyperlinkCursor(bool)90 virtual void setHyperlinkCursor(bool) {}
91
92 void setVisualParameter(const std::string &id, const std::string &value);
93 void setParameterValueList(const std::string &id, const std::vector<std::string> &values);
94 const std::string &visualParameter(const std::string &id);
95
96 protected:
97 class VisualParameter {
98
99 public:
100 virtual ~VisualParameter();
101
102 const std::string &value() const;
103 void setValue(const std::string &value);
104 virtual void setValueList(const std::vector<std::string> &values) = 0;
105
106 protected:
107 virtual std::string internalValue() const = 0;
108 virtual void internalSetValue(const std::string &value) = 0;
109 void restoreOldValue();
110
111 private:
112 mutable std::string myValue;
113 };
114
115 protected:
116 void addVisualParameter(const std::string &id, shared_ptr<VisualParameter> parameter);
117
118 private:
119 ZLApplication *myApplication;
120 bool myToggleButtonLock;
121 std::map<std::string,shared_ptr<VisualParameter> > myParameterMap;
122
123 friend class ZLApplication;
124 };
125
~ZLApplicationWindow()126 inline ZLApplicationWindow::~ZLApplicationWindow() {}
application()127 inline ZLApplication &ZLApplicationWindow::application() const { return *myApplication; }
128
129 #endif /* __ZLAPPLICATIONWINDOW_H__ */
130