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
39namespace Pt {
40
41namespace 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
90class PT_FORMS_API Form : public View
91{
92 friend class Control;
93
94 typedef View Base;
95
96 protected:
100
101 public:
104 virtual ~Form();
105
106 public:
109 Control* content();
110
113 const Control* content() const;
114
121 void setContent(Control* control);
122
123 //
124 // layouting
125 //
126 public:
132 Gfx::SizeF measure(const SizePolicy& policy);
133
139 void relayout();
140
141 protected:
144 virtual void onRequestRelayout();
145
150 virtual void onProcessLayoutEvent(const LayoutEvent& ev);
151
156 virtual Gfx::SizeF onProcessMeasure();
157
160 virtual void onProcessLayout(const Gfx::RectF& rect);
161
167 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
168
175 virtual void onLayout(const Gfx::RectF& rect);
176
177 //
178 // focus handling
179 //
180 public:
183 Control* focusControl();
184
190 void focusNext();
191
197 void focusPrev();
198
199 protected:
202 virtual void onAddElement(Control& control);
203
206 virtual void onRemoveElement(Control& control);
207
210 virtual void onSetFocusPolicy(Control& control, FocusPolicy policy);
211
214 virtual void onSetFocusIndex(Control& control, unsigned index);
215
220 virtual void onSetFocus(Control& control);
221
224 virtual void onSetShortcut(Control& control, const std::vector<Key>& keys);
225
228 virtual void onSetMnemonic(Control& control, const std::vector<Char>& chs);
229
230 //
231 // View
232 //
233 protected:
236 virtual void onSetSurface(PaintSurface* surface, const Gfx::PointF& pos);
237
240 virtual void onAttach(Control& control);
241
244 virtual void onDetach(Control& control);
245
248 virtual void onInit(Control& control);
249
252 virtual void onRelease(Control& control);
253
256 virtual Gfx::PointF onToControl(const Control& control,
257 const Gfx::PointF& pos) const;
258
261 virtual Gfx::PointF onFromControl(const Control& control,
262 const Gfx::PointF& pos) const;
263
264 protected:
267 virtual void onRepaintRequest(Control& control, const Gfx::RectF& rect);
268
271 virtual void onRelayoutRequest(Control& control);
272
278 virtual void onEnableRequest(Control& control, bool isEnable);
279
285 virtual void onActivateRequest(Control& control, bool active);
286
289 virtual void onShowRequest(Control& control, bool isShown);
290
293 virtual void onMoveRequest(Control& control, const Gfx::PointF& pos);
294
297 virtual void onResizeRequest(Control& control, const Gfx::SizeF& size);
298
304 virtual void onRaiseRequest(Control& control);
305
306 //
307 // Widget
308 //
309 protected:
312 virtual void onConnect(Screen& screen);
313
316 virtual void onDisconnect();
317
318
321 virtual Widget* onHitTest(const Gfx::PointF& pos);
322
325 virtual void onRequestCapture(bool capture);
326
332 virtual void onRequestResize(const Gfx::SizeF& s);
333
334
335 protected:
341 virtual void onProcessEvent(const Pt::Event& ev);
342
343 //
344 // invalidation
345 //
346 protected:
349 virtual void onInvalidateEvent(const InvalidateEvent& ev);
350
353 virtual void onInvalidate();
354
355 //
356 // painting
357 //
358 protected:
364 virtual void onProcessPaintEvent(const PaintEvent& ev);
365
371 virtual void onPaintEvent(const PaintEvent& ev);
372
373 //
374 // scaling
375 //
376 protected:
379 virtual void onProcessRescaleEvent(const RescaleEvent& ev);
380
383 virtual void onRescaleEvent(const RescaleEvent& ev);
384
387 virtual void onRescale(double scaling);
388
389 //
390 // enabling
391 //
392 protected:
395 virtual void onProcessEnableEvent(const EnableEvent& ev);
396
399 virtual void onEnableEvent(const EnableEvent& ev);
400
403 virtual void onEnable(bool e);
404
405 //
406 // visibility
407 //
408 protected:
413 virtual void onProcessShowEvent(const ShowEvent& ev);
414
417 virtual void onShowEvent(const ShowEvent& ev);
418
421 virtual void onShow(bool visible);
422
423 //
424 // geometry
425 //
426 protected:
429 virtual void onProcessMoveEvent(const MoveEvent& ev);
430
433 virtual void onMoveEvent(const MoveEvent& ev);
434
437 virtual void onProcessResizeEvent(const ResizeEvent& ev);
438
441 virtual void onResizeEvent(const ResizeEvent& ev);
442 //
443 // input
444 //
445 protected:
448 virtual void onProcessMouseEvent(const MouseEvent& ev);
449
452 virtual void onProcessTouchEvent(const TouchEvent& ev);
453
456 virtual void onProcessScrollEvent(const ScrollEvent& sev);
457
460 virtual void onProcessEnterEvent(const EnterEvent& ev);
461
464 virtual void onProcessLeaveEvent(const LeaveEvent& ev);
465
472 virtual void onProcessKeyEvent(const KeyEvent& ev);
473
474 //
475 // Responder
476 //
477 protected:
480 virtual bool onMouseEvent(const MouseEvent& ev);
481
484 virtual bool onTouchEvent(const TouchEvent& ev);
485
488 virtual bool onScrollEvent(const ScrollEvent& ev);
489
492 virtual bool onEnterEvent(const EnterEvent& ev);
493
496 virtual bool onLeaveEvent(const LeaveEvent& ev);
497
500 virtual bool onKeyEvent(const KeyEvent& ev);
501
502 private:
503 template <typename Iter>
504 void moveFocus(Iter begin, Iter end);
505
506 protected:
509 const std::map<Key, Control*>& shortcuts() const
510 {
511 return _shortcuts;
512 }
513
516 const std::map<Pt::Char, Control*>& mnemonics() const
517 {
518 return _mnemonics;
519 }
520
521 private:
522 Control* _mainControl;
523
524 int _layouts;
525
526 Control* _active;
527
528 std::vector<Control*> _focusList;
529 Control* _focusControl;
530 std::map<Key, Control*> _shortcuts;
531 std::map<Pt::Char, Control*> _mnemonics;
532
533};
534
535} // namespace
536
537} // namespace
538
539#endif // include guard
Base class for typed events.
Definition Event.h:66
Reusable view used as application content.
Definition Control.h:107
Pointer entered a widget.
Definition EnterEvent.h:49
virtual void onProcessLeaveEvent(const LeaveEvent &ev)
Processes pointer leave with the standard widget responder behavior.
virtual bool onMouseEvent(const MouseEvent &ev)
Does not handle mouse input and continues responder dispatch.
virtual void onProcessShowEvent(const ShowEvent &ev)
Updates visibility of the form itself.
virtual void onSetMnemonic(Control &control, const std::vector< Char > &chs)
Replaces the mnemonic registrations for control with chs.
virtual void onSetFocusIndex(Control &control, unsigned index)
Updates the focus order after control changes its focus index.
virtual void onProcessRescaleEvent(const RescaleEvent &ev)
Updates form scaling and propagates it to the content root.
Control * focusControl()
Returns the focused control, or 0 when no control has focus.
virtual void onMoveEvent(const MoveEvent &ev)
Repaints changed bounds and updates the form position.
virtual void onDisconnect()
Disconnects the form and its content from the screen.
virtual void onRescaleEvent(const RescaleEvent &ev)
Handles a scale-change event for the form.
virtual void onRemoveElement(Control &control)
Removes control from focus traversal, shortcuts, and mnemonics.
virtual bool onTouchEvent(const TouchEvent &ev)
Does not handle touch input and continues responder dispatch.
virtual Gfx::PointF onToControl(const Control &control, const Gfx::PointF &pos) const
Converts form-local pos to coordinates local to control.
virtual void onEnableEvent(const EnableEvent &ev)
Handles an enable event for the form.
virtual void onSetFocus(Control &control)
Gives focus to control and sends the corresponding focus events.
void relayout()
Queues a layout pass while the form is connected.
virtual void onSetShortcut(Control &control, const std::vector< Key > &keys)
Replaces the shortcut registrations for control with keys.
virtual void onProcessScrollEvent(const ScrollEvent &sev)
Routes scrolling to the active control, then the focused control.
virtual void onRequestRelayout()
Queues the layout event for a requested layout pass.
virtual bool onEnterEvent(const EnterEvent &ev)
Installs the current cursor and consumes pointer entry.
virtual void onShowRequest(Control &control, bool isShown)
Delivers a visibility request to control.
virtual void onResizeEvent(const ResizeEvent &ev)
Repaints changed bounds, updates size, and requests relayout.
virtual void onRelayoutRequest(Control &control)
Queues a form layout after a request from control.
virtual void onEnableRequest(Control &control, bool isEnable)
Delivers an effective enable state to control.
virtual void onProcessResizeEvent(const ResizeEvent &ev)
Processes a resize event and schedules relayout when size changes.
virtual Gfx::PointF onFromControl(const Control &control, const Gfx::PointF &pos) const
Converts coordinates local to control into form-local pos.
virtual void onLayout(const Gfx::RectF &rect)
Lays out the content in rect.
virtual void onConnect(Screen &screen)
Connects the form and its content to screen.
virtual void onProcessMoveEvent(const MoveEvent &ev)
Processes a move event with the standard View behavior.
virtual void onRepaintRequest(Control &control, const Gfx::RectF &rect)
Translates a repaint request from control to form coordinates.
virtual void onProcessLayout(const Gfx::RectF &rect)
Applies the result of the default layout pass to rect.
void setContent(Control *control)
Replaces the content root with control.
virtual void onProcessEvent(const Pt::Event &ev)
Dispatches ev through the widget event dispatcher.
virtual void onShowEvent(const ShowEvent &ev)
Handles a visibility event for the form.
virtual void onRequestResize(const Gfx::SizeF &s)
Receives a resize request for the form itself.
virtual void onProcessMouseEvent(const MouseEvent &ev)
Routes mouse input to the content under the pointer when possible.
virtual void onProcessEnterEvent(const EnterEvent &ev)
Processes pointer entry with the standard widget responder behavior.
virtual void onDetach(Control &control)
Handles detachment of control from this form.
const std::map< Key, Control * > & shortcuts() const
Returns the shortcut-to-control registrations for this form.
Definition Form.h:509
virtual void onMoveRequest(Control &control, const Gfx::PointF &pos)
Aligns and commits a move request for control.
Control * content()
Returns the current content control, or 0 when none is attached.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the content for policy.
virtual Gfx::SizeF onProcessMeasure()
Creates the size policy used by the default layout pass.
virtual void onAttach(Control &control)
Handles attachment of control to this form.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Restores the default cursor and consumes pointer leave.
virtual void onInvalidateEvent(const InvalidateEvent &ev)
Handles the final coalesced invalidation event.
virtual void onSetSurface(PaintSurface *surface, const Gfx::PointF &pos)
Assigns the paint surface and translates it to the content root.
virtual void onActivateRequest(Control &control, bool active)
Makes control the active input target when active is true.
virtual void onEnable(bool e)
Performs behavior associated with effective enabled state e.
virtual bool onKeyEvent(const KeyEvent &ev)
Does not handle key input and continues responder dispatch.
virtual void onResizeRequest(Control &control, const Gfx::SizeF &size)
Aligns and commits a resize request for control.
void focusPrev()
Moves focus to the previous eligible control.
Form()
Creates a form without a content control.
virtual void onRequestCapture(bool capture)
Forwards a pointer capture request to the Forms application.
virtual void onProcessLayoutEvent(const LayoutEvent &ev)
Processes a queued layout event.
const Control * content() const
Returns the current content control, or 0 when none is attached.
Gfx::SizeF measure(const SizePolicy &policy)
Measures the preferred content size for policy.
virtual ~Form()
Detaches the current content control.
virtual void onSetFocusPolicy(Control &control, FocusPolicy policy)
Updates focus after control changes to policy.
virtual bool onScrollEvent(const ScrollEvent &ev)
Does not handle scroll input and continues responder dispatch.
virtual void onRaiseRequest(Control &control)
Receives a request to raise control.
virtual void onPaintEvent(const PaintEvent &ev)
Paints the form's own view content.
virtual void onProcessPaintEvent(const PaintEvent &ev)
Paints the form and the intersecting part of its content root.
virtual void onRescale(double scaling)
Updates the form's logical-to-device scaling to scaling.
virtual void onProcessEnableEvent(const EnableEvent &ev)
Updates form enabled state and propagates it to the content root.
const std::map< Pt::Char, Control * > & mnemonics() const
Returns the mnemonic-to-control registrations for this form.
Definition Form.h:516
virtual void onAddElement(Control &control)
Registers control for focus traversal, shortcuts, and mnemonics.
virtual Widget * onHitTest(const Gfx::PointF &pos)
Returns the deepest content widget at form-local pos.
void focusNext()
Moves focus to the next eligible control.
virtual void onInit(Control &control)
Connects control to this form's screen and responder chain.
virtual void onRelease(Control &control)
Disconnects control from this form's screen and responder chain.
virtual void onShow(bool visible)
Performs behavior associated with form visibility visible.
virtual void onProcessKeyEvent(const KeyEvent &ev)
Routes keyboard input through form-level interaction handling.
virtual void onProcessTouchEvent(const TouchEvent &ev)
Routes touch input to the content under the pointer when possible.
virtual void onInvalidate()
Clears invalidation state and requests a layout pass.
Key press or release.
Definition KeyEvent.h:50
Pointer left a widget.
Definition LeaveEvent.h:49
Pointer movement or button change.
Definition MouseEvent.h:134
Reports that a widget moved.
Definition MoveEvent.h:50
Reports a dirty rectangle that a widget must paint.
Definition PaintEvent.h:48
Forms render target for painting.
Definition PaintSurface.h:50
Reports that a widget was resized.
Definition ResizeEvent.h:50
Display root for top-level windows.
Definition Screen.h:83
Scroll or wheel movement.
Definition ScrollEvent.h:51
Reports that a widget was shown or hidden.
Definition ShowEvent.h:48
Constraint used when measuring a control.
Definition SizePolicy.h:48
Touch press, move, or release.
Definition TouchEvent.h:51
PaintSurface & surface()
Returns this view's local paint-surface adapter.
View()
Creates a view for a derived content host.
FocusPolicy
Defines whether a control can receive or retain focus.
Definition View.h:95
Common type of every visual Forms object.
Definition Widget.h:105
const Gfx::Scaling & scaling() const
Returns the current logical-to-device scaling.
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Screen * screen()
Returns the connected screen, or 0 when disconnected.
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33