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 
70 class PT_FORMS_API Form : public View
71 {
72  friend class Control;
73 
74  typedef View Base;
75 
76  protected:
77  Form();
78 
79  public:
80  virtual ~Form();
81 
82  public:
83  Control* content();
84 
85  const Control* content() const;
86 
87  void setContent(Control* control);
88 
89 
90  //Gfx::PaintSurface& surface();
91 
92  //const Gfx::PaintSurface& surface() const;
93 
94  //void setSurface(Gfx::PaintSurface* surface, const Gfx::PointF& pos);
95 
96  //
97  // layouting
98  //
99  public:
100  Gfx::SizeF measure(const SizePolicy& policy);
101 
102  void relayout();
103 
104  protected:
105  virtual void onRequestRelayout();
106 
107  virtual void onProcessLayoutEvent(const LayoutEvent& ev);
108 
109  virtual Gfx::SizeF onProcessMeasure();
110 
111  virtual void onProcessLayout(const Gfx::RectF& rect);
112 
113  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
114 
115  virtual void onLayout(const Gfx::RectF& rect);
116 
117  //
118  // focus handling
119  //
120  public:
121  Control* focusControl();
122 
123  void focusNext();
124 
125  void focusPrev();
126 
127  protected:
128  virtual void onAddElement(Control& control);
129 
130  virtual void onRemoveElement(Control& control);
131 
132  virtual void onSetFocusPolicy(Control& control, FocusPolicy policy);
133 
134  virtual void onSetFocusIndex(Control& control, unsigned index);
135 
136  virtual void onSetFocus(Control& control);
137 
138  virtual void onSetShortcut(Control& control, const std::vector<Key>& keys);
139 
140  virtual void onSetMnemonic(Control& control, const std::vector<Char>& chs);
141 
142  //
143  // View
144  //
145  protected:
146  virtual void onSetSurface(PaintSurface* surface, const Gfx::PointF& pos);
147 
148  virtual void onAttach(Control& control);
149 
150  virtual void onDetach(Control& control);
151 
152  virtual void onInit(Control& control);
153 
154  virtual void onRelease(Control& control);
155 
156  virtual Gfx::PointF onToControl(const Control& control,
157  const Gfx::PointF& pos) const;
158 
159  virtual Gfx::PointF onFromControl(const Control& control,
160  const Gfx::PointF& pos) const;
161 
162  protected:
163  virtual void onRepaintRequest(Control& control, const Gfx::RectF& rect);
164 
165  virtual void onRelayoutRequest(Control& control);
166 
167  virtual void onEnableRequest(Control& control, bool isEnable);
168 
169  virtual void onActivateRequest(Control& control, bool active);
170 
171  virtual void onShowRequest(Control& control, bool isShown);
172 
173  virtual void onMoveRequest(Control& control, const Gfx::PointF& pos);
174 
175  virtual void onResizeRequest(Control& control, const Gfx::SizeF& size);
176 
177  virtual void onRaiseRequest(Control& control);
178 
179  //
180  // Widget
181  //
182  protected:
183  virtual void onConnect(Screen& screen);
184 
185  virtual void onDisconnect();
186 
187 
188  virtual Widget* onHitTest(const Gfx::PointF& pos);
189 
190  virtual void onRequestCapture(bool capture);
191 
192  virtual void onRequestResize(const Gfx::SizeF& s);
193 
194 
195  protected:
196  virtual void onProcessEvent(const Pt::Event& ev);
197 
198  //
199  // invalidation
200  //
201  protected:
202  virtual void onInvalidateEvent(const InvalidateEvent& ev);
203 
204  virtual void onInvalidate();
205 
206  //
207  // painting
208  //
209  protected:
210  virtual void onProcessPaintEvent(const PaintEvent& ev);
211 
212  virtual void onPaintEvent(const PaintEvent& ev);
213 
214  //
215  // scaling
216  //
217  protected:
218  virtual void onProcessRescaleEvent(const RescaleEvent& ev);
219 
220  virtual void onRescaleEvent(const RescaleEvent& ev);
221 
222  virtual void onRescale(double scaling);
223 
224  //
225  // enabling
226  //
227  protected:
228  virtual void onProcessEnableEvent(const EnableEvent& ev);
229 
230  virtual void onEnableEvent(const EnableEvent& ev);
231 
232  virtual void onEnable(bool e);
233 
234  //
235  // visibility
236  //
237  protected:
238  virtual void onProcessShowEvent(const ShowEvent& ev);
239 
240  virtual void onShowEvent(const ShowEvent& ev);
241 
242  virtual void onShow(bool visible);
243 
244  //
245  // geometry
246  //
247  protected:
248  virtual void onProcessMoveEvent(const MoveEvent& ev);
249 
250  virtual void onMoveEvent(const MoveEvent& ev);
251 
252  virtual void onProcessResizeEvent(const ResizeEvent& ev);
253 
254  virtual void onResizeEvent(const ResizeEvent& ev);
255  //
256  // input
257  //
258  protected:
259  virtual void onProcessMouseEvent(const MouseEvent& ev);
260 
261  virtual void onProcessTouchEvent(const TouchEvent& ev);
262 
263  virtual void onProcessScrollEvent(const ScrollEvent& sev);
264 
265  virtual void onProcessEnterEvent(const EnterEvent& ev);
266 
267  virtual void onProcessLeaveEvent(const LeaveEvent& ev);
268 
269  virtual void onProcessKeyEvent(const KeyEvent& ev);
270 
271  //
272  // Responder
273  //
274  protected:
275  virtual bool onMouseEvent(const MouseEvent& ev);
276 
277  virtual bool onTouchEvent(const TouchEvent& ev);
278 
279  virtual bool onScrollEvent(const ScrollEvent& ev);
280 
281  virtual bool onEnterEvent(const EnterEvent& ev);
282 
283  virtual bool onLeaveEvent(const LeaveEvent& ev);
284 
285  virtual bool onKeyEvent(const KeyEvent& ev);
286 
287  private:
288  template <typename Iter>
289  void moveFocus(Iter begin, Iter end);
290 
291  protected:
292  const std::map<Key, Control*>& shortcuts() const
293  {
294  return _shortcuts;
295  }
296 
297  const std::map<Pt::Char, Control*>& mnemonics() const
298  {
299  return _mnemonics;
300  }
301 
302  private:
303  Control* _mainControl;
304 
305  int _layouts;
306 
307  Control* _active;
308 
309  std::vector<Control*> _focusList;
310  Control* _focusControl;
311  std::map<Key, Control*> _shortcuts;
312  std::map<Pt::Char, Control*> _mnemonics;
313 
314 };
315 
316 } // namespace
317 
318 } // namespace
319 
320 #endif // include guard
Core module.
Definition: Allocator.h:33
Base class for all event types.
Definition: Event.h:50
Paint surface.
Definition: PaintSurface.h:44
Common base for objects that participate in the Forms runtime.
Definition: Widget.h:73
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
A view that can be attached as application content.
Definition: Control.h:84
Screen of a display.
Definition: Screen.h:64
A widget that connects controls to a paint surface.
Definition: View.h:66
Rect with floating-point coordinates.
Definition: Rect.h:47
A view that hosts one content control and manages its form state.
Definition: Form.h:71