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/Pixmap.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
54namespace Pt {
55
56namespace Forms {
57
58class WindowFrame;
59class WindowManager;
61class PaintEvent;
62
98class PT_FORMS_API Window : public Form
99{
100 friend class WindowManager;
101 friend class WindowFrame;
102
103 public:
106 typedef Form Base;
107
111
115
116 public:
123 explicit Window(WindowManager* parent = 0,
125
128 virtual ~Window();
129
130 public:
137 void setParent(WindowManager& parent);
138
143 void unparent();
144
147 WindowManager* windowManager();
148
151 const WindowManager* windowManager() const;
152
157 WindowFrame* frame();
158
161 const WindowFrame* frame() const;
162
163 public:
168 void getBitmap(Gfx::Bitmap& bitmap) const;
169
176 void getBitmap(Gfx::Bitmap& bitmap, const Gfx::RectF& rect) const;
177
178 public:
185
192 void autoSize(const SizePolicy& policy);
193
196 void autoSize();
197
198 public:
201 Type type() const;
202
205 const Gfx::Image& icon() const;
206
211 void setIcon(const Gfx::Image& icon);
212
215 const std::string& title() const;
216
221 void setTitle( const std::string& title );
222
225 bool isAbove() const;
226
231 void setAbove(bool above);
232
235 bool isActive() const;
236
237
238 // TODO: setFullScreen()
239
243
249
258 void showModal();
259
262 bool isClosed() const;
263
269 void close();
270
274
279 bool acceptsInput() const;
280
281 public:
284 const Gfx::Brush& background() const;
285
289
290 //
291 // Form
292 //
293 protected:
296 virtual Gfx::SizeF onProcessMeasure();
297
300 virtual void onProcessLayout(const Gfx::RectF& rect);
301
304 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
305
308 virtual void onLayout(const Gfx::RectF& rect);
309
310 //
311 // Widget
312 //
313 protected:
319 virtual void onConnect(Screen& screen);
320
323 virtual void onDisconnect();
324
330 virtual Widget* onHitTest(const Gfx::PointF& point);
331
334 virtual Gfx::PointF onToParent(const Gfx::PointF& pos) const;
335
338 virtual Gfx::PointF onFromParent(const Gfx::PointF& pos) const;
339
342 virtual void onProcessEvent(const Pt::Event& ev);
343
346 virtual void onRequestRepaint(const Gfx::RectF& rect);
347
350 virtual void onRequestEnable(bool enabled);
351
354 virtual void onRequestActivate(bool active);
355
360 virtual void onRequestShow(bool shown);
361
366 virtual void onRequestMove(const Gfx::PointF& pos);
367
370 virtual void onRequestResize(const Gfx::SizeF& size);
371
374 virtual void onSetSizeLimits(const Gfx::SizeF& minSize,
375 const Gfx::SizeF& maxSize);
376
377 //
378 // invalidation
379 //
380 protected:
383 virtual void onInvalidateEvent(const InvalidateEvent& ev);
384
387 virtual void onInvalidate();
388
389 //
390 // painting
391 //
392 protected:
395 virtual void onProcessPaintEvent(const PaintEvent& event);
396
399 virtual void onPaint(PaintContext& context, const Gfx::RectF& rect);
400
401 //
402 // scaling
403 //
404 protected:
407 virtual void onProcessRescaleEvent(const RescaleEvent& ev);
408
411 virtual void onRescaleEvent(const RescaleEvent& ev);
412
415 virtual void onRescale(double scaling);
416
417 //
418 // geometry
419 //
420 protected:
423 virtual void onProcessMoveEvent(const MoveEvent& ev);
424
427 virtual void onMoveEvent(const MoveEvent& ev);
428
431 virtual void onProcessResizeEvent(const ResizeEvent& ev);
432
435 virtual void onResizeEvent(const ResizeEvent& ev);
436
437 //
438 // visibility
439 //
440 protected:
443 virtual void onProcessShowEvent(const ShowEvent& ev);
444
447 virtual void onShowEvent(const ShowEvent& event);
448
451 virtual void onShow(bool visible);
452
453 //
454 // enabling
455 //
456 protected:
459 virtual void onProcessEnableEvent(const EnableEvent& ev);
460
463 virtual void onEnableEvent(const EnableEvent& ev);
464
467 virtual void onEnable(bool enabled);
468
469 //
470 // activation
471 //
472 protected:
475 virtual void onProcessActivateEvent(const ActivateEvent& event);
476
479 virtual void onActivateEvent(const ActivateEvent& event);
480
481 //
482 // window state
483 //
484 protected:
487 virtual void onProcessWindowStateEvent(const WindowStateEvent& event);
488
491 virtual void onWindowStateEvent(const WindowStateEvent& event);
492
493 //
494 // closing
495 //
496 protected:
499 virtual void onProcessCloseEvent(const CloseEvent& event);
500
503 virtual void onCloseEvent(const CloseEvent& ev);
504
505 //
506 // input
507 //
508 protected:
511 virtual void onProcessMouseEvent(const MouseEvent& event);
512
515 virtual void onProcessTouchEvent(const TouchEvent& event);
516
519 virtual void onProcessScrollEvent(const ScrollEvent& event);
520
523 virtual void onProcessEnterEvent(const EnterEvent& event);
524
527 virtual void onProcessLeaveEvent(const LeaveEvent& event);
528
531 virtual void onProcessKeyEvent(const KeyEvent& event);
532
533 //
534 // Responder
535 //
536 protected:
539 virtual bool onMouseEvent(const MouseEvent& ev);
540
543 virtual bool onTouchEvent( const TouchEvent& ev );
544
547 virtual bool onScrollEvent(const ScrollEvent& ev);
548
551 virtual bool onKeyEvent(const KeyEvent& ev);
552
555 virtual bool onEnterEvent(const EnterEvent& ev);
556
559 virtual bool onLeaveEvent(const LeaveEvent& ev);
560
561 //
562 // Implementation
563 //
564 private:
565 bool isAutoSizeActive(const Gfx::SizeF& s);
566
567 private:
568 WindowFrame* _frame;
569 WindowManager* _wm;
570
571 bool _show;
572 bool _isActive;
573 bool _enabled;
574 bool _isClosed;
575
576 Pt::Signal<> _closed;
577
578 Gfx::PointF _requestedPosition;
579 Gfx::SizeF _requestedSize;
580
581 SizePolicy _autoSizePolicy;
582 bool _autoSize;
583 Gfx::SizeF _lastAutoSize;
584 bool _autoCenter;
585
586 Type _type;
587 std::string _title;
588 Gfx::Image _icon;
589 State _state;
590 bool _isAbove;
591
592 AutoPtr<Gfx::Brush> _background;
593 Gfx::Brush _backgroundBrush;
594};
595
596} // namespace
597
598} // namespace
599
600#endif // include guard
Policy based Auto pointer.
Definition SmartPtr.h:291
Base class for typed events.
Definition Event.h:66
Reports that a widget became active or inactive.
Definition ActivateEvent.h:49
Reports that a widget is closing.
Definition CloseEvent.h:50
Pointer entered a widget.
Definition EnterEvent.h:49
Form()
Creates a form without a content control.
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
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Reports a dirty rectangle that a widget must paint.
Definition PaintEvent.h:48
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
Common type of every visual Forms object.
Definition Widget.h:105
Widget * parent()
Returns the non-owning parent, or 0 when unparented.
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.
Host that attaches windows to a screen or workspace.
Definition WindowManager.h:68
Reports that a window's presentation state changed.
Definition WindowStateEvent.h:50
Presentation state of a window.
Definition WindowType.h:112
Frame style of a window.
Definition WindowType.h:53
@ Default
Uses the default decorated frame.
Definition WindowType.h:61
virtual bool onMouseEvent(const MouseEvent &ev)
Handles a mouse event and returns whether it was consumed.
void autoCenter()
Centers the window in its manager's available area.
const WindowManager * windowManager() const
Returns the current non-owning window manager, or null.
virtual void onProcessShowEvent(const ShowEvent &ev)
Processes a visibility event through the standard form path.
virtual void onProcessActivateEvent(const ActivateEvent &event)
Dispatches event to onActivateEvent().
WindowManager * windowManager()
Returns the current non-owning window manager, or null.
virtual void onRequestMove(const Gfx::PointF &pos)
Records and forwards a normal-state move request to pos.
virtual void onProcessRescaleEvent(const RescaleEvent &ev)
Processes a scale event through the standard form path.
virtual void onProcessEnterEvent(const EnterEvent &event)
Routes the pointer-entry event.
virtual void onRequestShow(bool shown)
Stores the visibility request shown and presents the window.
virtual void onMoveEvent(const MoveEvent &ev)
Updates move state without repainting the window surface.
virtual void onDisconnect()
Disconnects the window form from its screen.
virtual void onRescaleEvent(const RescaleEvent &ev)
Handles a scale event after standard form processing.
virtual void onRequestResize(const Gfx::SizeF &size)
Records and forwards a normal-state resize request to size.
virtual bool onTouchEvent(const TouchEvent &ev)
Handles a touch event and returns whether it was consumed.
void getBitmap(Gfx::Bitmap &bitmap) const
Copies the complete window content into bitmap.
void autoSize(const SizePolicy &policy)
Enables automatic sizing with policy.
virtual void onEnableEvent(const EnableEvent &ev)
Handles an enabled event through the standard form path.
virtual void onWindowStateEvent(const WindowStateEvent &event)
Updates the window state from event.
Window(WindowManager *parent=0, WindowType type=WindowType::Default)
Creates a detached, enabled window of type.
bool isActive() const
Returns the current locally stored activation state.
Form Base
Defines the base form type.
Definition Window.h:106
const std::string & title() const
Returns the window title.
const Gfx::Image & icon() const
Returns the window icon.
void setState(const WindowState &state)
Sets the requested window state to state.
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Fills rect with the current window background.
WindowType Type
Defines the window frame type.
Definition Window.h:110
WindowState state() const
Returns the requested window state.
virtual bool onEnterEvent(const EnterEvent &ev)
Restores the default cursor, handles the event, and returns consumption.
void setIcon(const Gfx::Image &icon)
Sets the window icon to a copy of icon.
virtual void onProcessTouchEvent(const TouchEvent &event)
Routes event when the window accepts input.
WindowState State
Defines the window presentation state type.
Definition Window.h:114
virtual void onResizeEvent(const ResizeEvent &ev)
Updates resize state and the requested window size.
const Gfx::Brush & background() const
Returns the background override or the application background.
void close()
Requests that the current frame close the window.
void setAbove(bool above)
Changes the manager-relative stacking preference to above.
virtual void onProcessKeyEvent(const KeyEvent &event)
Routes event when the window accepts input.
virtual void onProcessResizeEvent(const ResizeEvent &ev)
Processes a resize event through the standard form path.
virtual void onLayout(const Gfx::RectF &rect)
Lays out the content in rect.
virtual void onConnect(Screen &screen)
Connects the window and applies its stored frame configuration.
virtual void onProcessMoveEvent(const MoveEvent &ev)
Processes a move event through the standard form path.
virtual void onProcessLayout(const Gfx::RectF &rect)
Applies automatic sizing and performs the standard layout.
virtual void onProcessEvent(const Pt::Event &ev)
Dispatches event through the standard form event path.
bool isAbove() const
Returns whether the window requests manager-relative stacking.
Signal & closed()
Returns the signal sent after the close transition completes.
virtual Gfx::PointF onFromParent(const Gfx::PointF &pos) const
Converts parent coordinates pos to window coordinates.
virtual void onCloseEvent(const CloseEvent &ev)
Hides, detaches, closes, and sends closed().
void getBitmap(Gfx::Bitmap &bitmap, const Gfx::RectF &rect) const
Copies a window content rectangle into bitmap.
virtual void onShowEvent(const ShowEvent &event)
Processes event and invalidates the window.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the content with policy.
virtual Gfx::SizeF onProcessMeasure()
Updates automatic sizing and performs the standard measurement.
virtual void onProcessLeaveEvent(const LeaveEvent &event)
Routes the pointer-leave event.
void setBackground(const Gfx::Brush &background)
Copies background as the window background and invalidates it.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Handles a pointer-leave event and returns whether it was consumed.
virtual void onInvalidateEvent(const InvalidateEvent &ev)
Processes an invalidation event through the standard form path.
virtual void onRequestActivate(bool active)
Stores and forwards the activation request active.
void unparent()
Detaches the window from its current manager.
virtual bool onKeyEvent(const KeyEvent &ev)
Handles a key event and returns whether it was consumed.
void setTitle(const std::string &title)
Sets the window title to title.
virtual void onSetSizeLimits(const Gfx::SizeF &minSize, const Gfx::SizeF &maxSize)
Applies and forwards the size limits to the current frame.
virtual void onProcessWindowStateEvent(const WindowStateEvent &event)
Dispatches event to onWindowStateEvent().
virtual void onProcessScrollEvent(const ScrollEvent &event)
Routes event when the window accepts input.
void setParent(WindowManager &parent)
Attaches the window to parent.
virtual void onRequestRepaint(const Gfx::RectF &rect)
Requests repainting rect from the current frame.
virtual void onProcessPaintEvent(const PaintEvent &event)
Paints a visible, non-empty dirty region from event.
virtual void onActivateEvent(const ActivateEvent &event)
Updates the active state from event.
virtual bool onScrollEvent(const ScrollEvent &ev)
Handles a scroll event and returns whether it was consumed.
bool isClosed() const
Returns whether a close event has completed the close transition.
const WindowFrame * frame() const
Returns the internal frame that presents the window, or null.
virtual void onProcessCloseEvent(const CloseEvent &event)
Dispatches event to onCloseEvent().
virtual void onRescale(double scaling)
Updates scaling and realigns normal-state window geometry.
virtual void onProcessEnableEvent(const EnableEvent &ev)
Processes an enabled event without enabling against a disable request.
Type type() const
Returns the type selected when the window was created.
virtual void onShow(bool visible)
Updates the visible state to visible.
virtual ~Window()
Detaches the window from its manager and releases its frame.
void showModal()
Runs the window as a modal dialog until it closes.
virtual void onInvalidate()
Updates the cached background and repaints the complete window.
virtual void onProcessMouseEvent(const MouseEvent &event)
Routes event when the window accepts input.
virtual void onEnable(bool enabled)
Updates the enabled state to enabled and invalidates the window.
virtual void onRequestEnable(bool enabled)
Stores and forwards the enabled request enabled.
void autoSize()
Enables automatic sizing with preferred width and height.
virtual Gfx::PointF onToParent(const Gfx::PointF &pos) const
Converts window coordinates pos to parent coordinates.
virtual Widget * onHitTest(const Gfx::PointF &point)
Finds the deepest visible widget at point.
bool acceptsInput() const
Returns whether the window accepts pointer, touch, scroll, and keyboard input.
WindowFrame * frame()
Returns the internal frame that presents the window, or null.
Off-screen image that can be painted.
Definition Bitmap.h:71
Fill color, gradient or texture.
Definition Brush.h:151
Multicast Signal to call multiple slots.
Definition Signal.h:190
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33