Form.h
1 /* Copyright (C) 2022 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301 USA
27 */
28 
29 #ifndef PT_FORMS_FORM_H
30 #define PT_FORMS_FORM_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/Widget.h>
34 #include <Pt/Forms/Control.h>
35 #include <Pt/Gfx/Point.h>
36 #include <Pt/Gfx/Size.h>
37 #include <Pt/Gfx/Rect.h>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
44 // TODO: move base functionality to Widget API
45 //
46 // where to align
47 // when is invalidate, relayout, repaint called
48 // some onXYZRequested handlers in Widget
49 //
51 
52 //
53 // TODO:
54 // - alignment for move/resize of window
55 // - WindowImpl for native and framework windows
56 // - set Decorator on Window to translate positions
57 //
58 
59 class PT_FORMS_API Form : public View
60 {
61  friend class Control;
62 
63  typedef View Base;
64 
65  protected:
66  Form();
67 
68  public:
69  virtual ~Form();
70 
71  public:
72  Control* content();
73 
74  const Control* content() const;
75 
76  void setContent(Control* control);
77 
78 
79  //Gfx::PaintSurface& surface();
80 
81  //const Gfx::PaintSurface& surface() const;
82 
83  //void setSurface(Gfx::PaintSurface* surface, const Gfx::PointF& pos);
84 
85  //
86  // layouting
87  //
88  public:
89  Gfx::SizeF measure(const SizePolicy& policy);
90 
91  void relayout();
92 
93  protected:
94  virtual void onRequestRelayout();
95 
96  virtual void onProcessLayoutEvent(const LayoutEvent& ev);
97 
98  virtual Gfx::SizeF onProcessMeasure();
99 
100  virtual void onProcessLayout(const Gfx::RectF& rect);
101 
102  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
103 
104  virtual void onLayout(const Gfx::RectF& rect);
105 
106  //
107  // focus handling
108  //
109  public:
110  Control* focusControl();
111 
112  void focusNext();
113 
114  void focusPrev();
115 
116  protected:
117  virtual void onAddElement(Control& control);
118 
119  virtual void onRemoveElement(Control& control);
120 
121  virtual void onSetFocusPolicy(Control& control, FocusPolicy policy);
122 
123  virtual void onSetFocusIndex(Control& control, unsigned index);
124 
125  virtual void onSetFocus(Control& control);
126 
127  virtual void onSetShortcut(Control& control, const std::vector<Key>& keys);
128 
129  virtual void onSetMnemonic(Control& control, const std::vector<Char>& chs);
130 
131  //
132  // View
133  //
134  protected:
135  virtual void onSetSurface(PaintSurface* surface, const Gfx::PointF& pos);
136 
137  virtual void onAttach(Control& control);
138 
139  virtual void onDetach(Control& control);
140 
141  virtual void onInit(Control& control);
142 
143  virtual void onRelease(Control& control);
144 
145  virtual Gfx::PointF onToControl(const Control& control,
146  const Gfx::PointF& pos) const;
147 
148  virtual Gfx::PointF onFromControl(const Control& control,
149  const Gfx::PointF& pos) const;
150 
151  protected:
152  virtual void onRepaintRequest(Control& control, const Gfx::RectF& rect);
153 
154  virtual void onRelayoutRequest(Control& control);
155 
156  virtual void onEnableRequest(Control& control, bool isEnable);
157 
158  virtual void onActivateRequest(Control& control, bool active);
159 
160  virtual void onShowRequest(Control& control, bool isShown);
161 
162  virtual void onMoveRequest(Control& control, const Gfx::PointF& pos);
163 
164  virtual void onResizeRequest(Control& control, const Gfx::SizeF& size);
165 
166  virtual void onRaiseRequest(Control& control);
167 
168  //
169  // Widget
170  //
171  protected:
172  virtual void onConnect(Screen& screen);
173 
174  virtual void onDisconnect();
175 
176 
177  virtual Widget* onHitTest(const Gfx::PointF& pos);
178 
179  virtual void onRequestCapture(bool capture);
180 
181  virtual void onRequestResize(const Gfx::SizeF& s);
182 
183 
184  protected:
185  virtual void onProcessEvent(const Pt::Event& ev);
186 
187  //
188  // invalidation
189  //
190  protected:
191  virtual void onInvalidateEvent(const InvalidateEvent& ev);
192 
193  virtual void onInvalidate();
194 
195  //
196  // painting
197  //
198  protected:
199  virtual void onProcessPaintEvent(const PaintEvent& ev);
200 
201  virtual void onPaintEvent(const PaintEvent& ev);
202 
203  //
204  // scaling
205  //
206  protected:
207  virtual void onProcessRescaleEvent(const RescaleEvent& ev);
208 
209  virtual void onRescaleEvent(const RescaleEvent& ev);
210 
211  virtual void onRescale(double scaling);
212 
213  //
214  // enabling
215  //
216  protected:
217  virtual void onProcessEnableEvent(const EnableEvent& ev);
218 
219  virtual void onEnableEvent(const EnableEvent& ev);
220 
221  virtual void onEnable(bool e);
222 
223  //
224  // visibility
225  //
226  protected:
227  virtual void onProcessShowEvent(const ShowEvent& ev);
228 
229  virtual void onShowEvent(const ShowEvent& ev);
230 
231  virtual void onShow(bool visible);
232 
233  //
234  // geometry
235  //
236  protected:
237  virtual void onProcessMoveEvent(const MoveEvent& ev);
238 
239  virtual void onMoveEvent(const MoveEvent& ev);
240 
241  virtual void onProcessResizeEvent(const ResizeEvent& ev);
242 
243  virtual void onResizeEvent(const ResizeEvent& ev);
244  //
245  // input
246  //
247  protected:
248  virtual void onProcessMouseEvent(const MouseEvent& ev);
249 
250  virtual void onProcessTouchEvent(const TouchEvent& ev);
251 
252  virtual void onProcessScrollEvent(const ScrollEvent& sev);
253 
254  virtual void onProcessEnterEvent(const EnterEvent& ev);
255 
256  virtual void onProcessLeaveEvent(const LeaveEvent& ev);
257 
258  virtual void onProcessKeyEvent(const KeyEvent& ev);
259 
260  //
261  // Responder
262  //
263  protected:
264  virtual bool onMouseEvent(const MouseEvent& ev);
265 
266  virtual bool onTouchEvent(const TouchEvent& ev);
267 
268  virtual bool onScrollEvent(const ScrollEvent& ev);
269 
270  virtual bool onEnterEvent(const EnterEvent& ev);
271 
272  virtual bool onLeaveEvent(const LeaveEvent& ev);
273 
274  virtual bool onKeyEvent(const KeyEvent& ev);
275 
276  private:
277  template <typename Iter>
278  void moveFocus(Iter begin, Iter end);
279 
280  protected:
281  const std::map<Key, Control*>& shortcuts() const
282  {
283  return _shortcuts;
284  }
285 
286  const std::map<Pt::Char, Control*>& mnemonics() const
287  {
288  return _mnemonics;
289  }
290 
291  private:
292  Control* _mainControl;
293 
294  int _layouts;
295 
296  Control* _active;
297 
298  std::vector<Control*> _focusList;
299  Control* _focusControl;
300  std::map<Key, Control*> _shortcuts;
301  std::map<Pt::Char, Control*> _mnemonics;
302 
303 };
304 
305 } // namespace
306 
307 } // namespace
308 
309 #endif // include guard
Base class for all event types.
Definition: Event.h:49