Window.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27  02110-1301 USA
28 */
29 
30 #ifndef PT_FORMS_WINDOW_H
31 #define PT_FORMS_WINDOW_H
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Form.h>
35 #include <Pt/Forms/PixmapSurface.h>
36 #include <Pt/Forms/WindowType.h>
37 #include <Pt/Forms/SizePolicy.h>
38 #include <Pt/Forms/ActivateEvent.h>
39 #include <Pt/Forms/CloseEvent.h>
40 #include <Pt/Forms/ResizeEvent.h>
41 #include <Pt/Forms/KeyEvent.h>
42 #include <Pt/Forms/MouseEvent.h>
43 #include <Pt/Forms/TouchEvent.h>
44 #include <Pt/Forms/ScrollEvent.h>
45 #include <Pt/Forms/MoveEvent.h>
46 #include <Pt/Forms/EnterEvent.h>
47 #include <Pt/Forms/LeaveEvent.h>
48 #include <Pt/Forms/ShowEvent.h>
49 #include <Pt/Forms/EnableEvent.h>
50 #include <Pt/Forms/InvalidateEvent.h>
51 #include <Pt/Gfx/Image.h>
52 #include <Pt/Signal.h>
53 
54 namespace Pt {
55 
56 namespace Forms {
57 
58 class WindowFrame;
59 class WindowManager;
60 class WindowStateEvent;
61 class PaintEvent;
62 
65 class PT_FORMS_API Window : public Form
66 {
67  friend class WindowManager;
68  friend class WindowFrame;
69 
70  public:
71  typedef Form Base;
72  typedef WindowType Type;
73  typedef WindowState State;
74 
75  public:
76  explicit Window(WindowManager* parent = 0,
77  WindowType type = WindowType::Default);
78 
79  virtual ~Window();
80 
81  public:
82  void setParent(WindowManager& parent);
83 
84  void unparent();
85 
86  WindowManager* windowManager();
87 
88  const WindowManager* windowManager() const;
89 
90  WindowFrame* frame();
91 
92  const WindowFrame* frame() const;
93 
94  public:
95  void getBitmap(Gfx::Bitmap& bitmap) const;
96 
97  public:
98  void autoCenter();
99 
100 
101  void autoSize(const SizePolicy& policy);
102 
103  void autoSize();
104 
105  public:
106  Type type() const;
107 
108 
109  const Gfx::Image& icon() const;
110 
111  void setIcon(const Gfx::Image& i);
112 
113  const std::string& title() const;
114 
115  void setTitle( const std::string& t );
116 
117 
118  bool isAbove() const;
119 
120  void setAbove(bool top);
121 
122 
123  bool isActive() const;
124 
125 
126  // TODO: setFullScreen()
127 
128  WindowState state() const;
129 
130  void setState(const WindowState& s);
131 
132 
133  void showModal();
134 
135 
136  bool isClosed() const;
137 
138  void close();
139 
140  Signal<>& closed();
141 
142 
143  bool acceptsInput() const;
144 
145  public:
146  const Gfx::Brush& background() const;
147 
148  void setBackground(const Gfx::Brush& b);
149 
150  //
151  // Form
152  //
153  protected:
154  virtual Gfx::SizeF onProcessMeasure();
155 
156  virtual void onProcessLayout(const Gfx::RectF& rect);
157 
158  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
159 
160  virtual void onLayout(const Gfx::RectF& rect);
161 
162  //
163  // Widget
164  //
165  protected:
166  virtual void onConnect(Screen& screen);
167 
168  virtual void onDisconnect();
169 
170 
171  virtual Widget* onHitTest(const Gfx::PointF& p);
172 
173  virtual Gfx::PointF onToParent(const Gfx::PointF& pos) const;
174 
175  virtual Gfx::PointF onFromParent(const Gfx::PointF& pos) const;
176 
177 
178  virtual void onProcessEvent(const Pt::Event& ev);
179 
180  virtual void onRequestRepaint(const Gfx::RectF& rect);
181 
182  virtual void onRequestEnable(bool isEnable);
183 
184  virtual void onRequestActivate(bool active);
185 
186  virtual void onRequestShow(bool isShown);
187 
188  virtual void onRequestMove(const Gfx::PointF& pos);
189 
190  virtual void onRequestResize(const Gfx::SizeF& s);
191 
192  virtual void onSetSizeLimits(const Gfx::SizeF& minSize,
193  const Gfx::SizeF& maxSize);
194 
195  //
196  // invalidation
197  //
198  protected:
199  virtual void onInvalidateEvent(const InvalidateEvent& ev);
200 
201  virtual void onInvalidate();
202 
203  //
204  // painting
205  //
206  protected:
207  virtual void onProcessPaintEvent(const PaintEvent& ev);
208 
209  virtual void onPaintEvent(const PaintEvent& ev);
210 
211  //
212  // scaling
213  //
214  protected:
215  virtual void onProcessRescaleEvent(const RescaleEvent& ev);
216 
217  virtual void onRescaleEvent(const RescaleEvent& ev);
218 
219  virtual void onRescale(double scaling);
220 
221  //
222  // geometry
223  //
224  protected:
225  virtual void onProcessMoveEvent(const MoveEvent& ev);
226 
227  virtual void onMoveEvent(const MoveEvent& ev);
228 
229  virtual void onProcessResizeEvent(const ResizeEvent& ev);
230 
231  virtual void onResizeEvent(const ResizeEvent& ev);
232 
233  //
234  // visibility
235  //
236  protected:
237  virtual void onProcessShowEvent(const ShowEvent& ev);
238 
239  virtual void onShowEvent(const ShowEvent& ev);
240 
241  virtual void onShow(bool visible);
242 
243  //
244  // enabling
245  //
246  protected:
247  virtual void onProcessEnableEvent(const EnableEvent& ev);
248 
249  virtual void onEnableEvent(const EnableEvent& ev);
250 
251  virtual void onEnable(bool e);
252 
253  //
254  // activation
255  //
256  protected:
257  virtual void onProcessActivateEvent(const ActivateEvent& ev);
258 
259  virtual void onActivateEvent(const ActivateEvent& ev);
260 
261  //
262  // window state
263  //
264  protected:
265  virtual void onProcessWindowStateEvent(const WindowStateEvent& ev);
266 
267  virtual void onWindowStateEvent(const WindowStateEvent& ev);
268 
269  //
270  // closing
271  //
272  protected:
273  virtual void onProcessCloseEvent(const CloseEvent& ev);
274 
275  virtual void onCloseEvent(const CloseEvent& ev);
276 
277  //
278  // input
279  //
280  protected:
281  virtual void onProcessMouseEvent(const MouseEvent& ev);
282 
283  virtual void onProcessTouchEvent(const TouchEvent& ev);
284 
285  virtual void onProcessScrollEvent(const ScrollEvent& ev);
286 
287  virtual void onProcessEnterEvent(const EnterEvent& ev);
288 
289  virtual void onProcessLeaveEvent(const LeaveEvent& ev);
290 
291  virtual void onProcessKeyEvent(const KeyEvent& ev);
292 
293  //
294  // Responder
295  //
296  protected:
297  virtual bool onMouseEvent(const MouseEvent& ev);
298 
299  virtual bool onTouchEvent( const TouchEvent& ev );
300 
301  virtual bool onScrollEvent(const ScrollEvent& ev);
302 
303  virtual bool onKeyEvent(const KeyEvent& ev);
304 
305  virtual bool onEnterEvent(const EnterEvent& ev);
306 
307  virtual bool onLeaveEvent(const LeaveEvent& ev);
308 
309  //
310  // Implementation
311  //
312  private:
313  bool isAutoSizeActive(const Gfx::SizeF& s);
314 
315  private:
316  WindowFrame* _frame;
317  WindowManager* _wm;
318 
319  bool _show;
320  bool _isActive;
321  bool _enabled;
322  bool _isClosed;
323 
324  Pt::Signal<> _closed;
325 
326  Gfx::PointF _requestedPosition;
327  Gfx::SizeF _requestedSize;
328 
329  SizePolicy _autoSizePolicy;
330  bool _autoSize;
331  Gfx::SizeF _lastAutoSize;
332  bool _autoCenter;
333 
334  Type _type;
335  std::string _title;
336  Gfx::Image _icon;
337  State _state;
338  bool _isAbove;
339 
340  AutoPtr<Gfx::Brush> _background;
341  Gfx::Brush _backgroundBrush;
342 };
343 
344 } // namespace
345 
346 } // namespace
347 
348 #endif // include guard
Window base class.
Definition: Window.h:65
Rect with floating-point coordinates.
Definition: Rect.h:44
Basic image.
Definition: Api.h:81
Base class for all event types.
Definition: Event.h:49
Image drawing surface.
Definition: Bitmap.h:54
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Screen of a display.
Definition: Screen.h:54
Size with floating-point width and height.
Definition: Size.h:44
Point with floating-point X and Y coordinates.
Definition: Point.h:44