Application.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,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_Application_h
31 #define Pt_Forms_Application_h
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Screen.h>
35 #include <Pt/Forms/Style.h>
36 #include <Pt/Forms/StyleOptions.h>
37 #include <Pt/Forms/GraphicsBackend.h>
38 #include <Pt/Forms/PlatinumStyle.h>
39 #include <Pt/Forms/InputMethod.h>
40 #include <Pt/Forms/Icon.h>
41 #include <Pt/Gfx/Font.h>
42 #include <Pt/Gfx/FontFace.h>
43 #include <Pt/Gfx/PngReader.h>
44 #include <Pt/System/Application.h>
45 #include <Pt/System/Path.h>
46 
47 #include <list>
48 #include <vector>
49 
50 namespace Pt {
51 
52 namespace Forms {
53 
54 class Cursor;
55 class Popup;
56 
67 class PT_FORMS_API Application : public Pt::System::Application
68 {
69  friend class Widget;
70  friend class Popup;
71  friend class Screen;
72 
73  public:
74  Application(int argc = 0, char** argv = 0);
75 
76  virtual ~Application();
77 
78  ApplicationImpl* impl();
79 
80  GraphicsBackend& graphicsBackend();
81 
82  const GraphicsBackend& graphicsBackend() const;
83 
84  static Application& instance();
85 
86  const Screen& screen() const;
87 
88  Screen& screen();
89 
90  Pt::Timespan inactivityTime() const;
91 
92  void setCursor(const Cursor* cursor = 0);
93 
96  const Style& style() const;
97 
100  void setStyle(const Style& s);
101 
104  const StyleOptions& styleOptions() const;
105 
108  void setStyleOptions(const StyleOptions& options);
109 
110  void loadImage(const System::Path& path, Gfx::Image& image);
111 
112  void setScaleFactor(double scale);
113 
114  double scaleFactor() const;
115 
116  InputMethod& inputMethod();
117 
118  void setInputMethod(InputMethod& im);
119 
120  void removeInputMethod(InputMethod& im);
121 
122  Pt::uint64_t makeId();
123 
124  Widget* findWidget(Pt::uint64_t id);
125 
126  // TODO: this might be the same as loop().waitNext()
127  void nextEvent();
128 
129  void commitEvent(const Event& ev);
130 
131  void processEvent(const Event& ev);
132 
133  Pt::Signal<const Pt::Event&>& eventReceived();
134 
135  void invalidate();
136 
139  void sendKeyEvent(const KeyEvent& ev);
140 
143  void sendMouseEvent(const MouseEvent& ev);
144 
145  Widget* capture() const;
146 
147  public:
148  void addFonts(const Pt::System::Path& dir);
149 
150  bool addFont(const Pt::System::Path& path);
151 
152  bool removeFont(const Pt::System::Path& path);
153 
154  const std::vector<Pt::System::Path>& fontFiles() const;
155 
156  std::string defaultFont() const;
157 
158  void setDefaultFont(const std::string& family);
159 
160  std::vector<std::string> fontFamilies() const;
161 
162  std::vector<Gfx::FontFace> fontFaces(const std::string& family) const;
163 
164  protected:
165  void onSetPointer(Widget& widget, bool isPointer);
166 
167  void onRequestCapture(Widget& target, bool capture);
168 
169  void onShowPopup(Popup& w, bool transient);
170 
171  bool isAnchoredTo(Popup& w, Window& top) const;
172 
173  bool isPopupOf(Popup& w, Window& top) const;
174 
175  void onClosePopups(const Gfx::PointF& screenPos);
176 
177  private:
178  void registerWidget(Widget& widget);
179 
180  void unregisterWidget(Widget& widget);
181 
182  private:
183  void onDispatchMouseEvent(const MouseEvent& ev);
184 
185  void onProcessMouseEvent(const MouseEvent& ev);
186 
187 
188  void onDispatchTouchEvent(const TouchEvent& ev);
189 
190  void onProcessTouchEvent(const TouchEvent& ev);
191 
192 
193  void onDetectScroll(Widget* widget, const Gfx::PointF& screenPos,
194  bool isPress, bool isPressed);
195 
196 
197  void onDispatchScrollEvent(const ScrollEvent& ev);
198 
199  void onProcessScrollEvent(const ScrollEvent& ev);
200 
201 
202  void onDispatchEnterEvent(const EnterEvent& ev);
203 
204  void onProcessEnterEvent(const EnterEvent& ev);
205 
206 
207  void onDispatchLeaveEvent(const LeaveEvent& ev);
208 
209  void onProcessLeaveEvent(const LeaveEvent& ev);
210 
211 
212  void onDispatchKeyEvent(const KeyEvent& ev);
213 
214  void onProcessKeyEvent(const KeyEvent& ev);
215 
216 
217  void onDispatchInvalidateEvent(const InvalidateEvent& ev);
218 
219  void onProcessInvalidateEvent(const InvalidateEvent& ev);
220 
221 
222  void onDispatchLayoutEvent(const LayoutEvent& ev);
223 
224  void onProcessLayoutEvent(const LayoutEvent& ev);
225 
226 
227  void onDispatchRescaleEvent(const RescaleEvent& ev);
228 
229  void onProcessRescaleEvent(const RescaleEvent& ev);
230 
231 
232  void onDispatchPaintEvent(const PaintEvent& ev);
233 
234  void onProcessPaintEvent(const PaintEvent& ev);
235 
236 
237  void onDispatchMoveEvent(const MoveEvent& ev);
238 
239  void onProcessMoveEvent(const MoveEvent& ev);
240 
241 
242  void onDispatchResizeEvent(const ResizeEvent& ev);
243 
244  void onProcessResizeEvent(const ResizeEvent& ev);
245 
246 
247  void onDispatchActivateEvent(const ActivateEvent& ev);
248 
249  void onProcessActivateEvent(const ActivateEvent& ev);
250 
251 
252  void onDispatchEnableEvent(const EnableEvent& ev);
253 
254  void onProcessEnableEvent(const EnableEvent& ev);
255 
256 
257  void onDispatchShowEvent(const ShowEvent& ev);
258 
259  void onProcessShowEvent(const ShowEvent& ev);
260 
261 
262  void onDispatchCloseEvent(const CloseEvent& ev);
263 
264  void onProcessCloseEvent(const CloseEvent& ev);
265 
266 
267  void onDispatchFocusEvent(const FocusEvent& ev);
268 
269  void onProcessFocusEvent(const FocusEvent& ev);
270 
271 
272  void onDispatchWindowStateEvent(const WindowStateEvent& ev);
273 
274  void onProcessWindowStateEvent(const WindowStateEvent& ev);
275 
276  private:
277  typedef std::map<Pt::uint64_t, Widget*> WidgetMap;
278 
279  ApplicationImpl* _impl;
280  GraphicsBackend* _graphicsBackend;
281  Pt::Signal<const Pt::Event&> _eventReceived;
282  Screen* _mainScreen;
283  Pt::uint64_t _lastId;
284  WidgetMap _widgets;
285 
286  Style _style;
287  StyleOptions _styleOptions;
288 
289  DefaultInputMethod* _defaultInputMethod;
290  InputMethod* _inputMethod;
291 
292  std::list<Popup*> _popups;
293  std::list<Widget*> _capture;
294 
295  Gfx::PointF _scrollFrom;
296  bool _onScroll;
297  Gfx::PngReader _iconReader;
298  double _scaling;
299 };
300 
301 } // namespace
302 
303 } // namespace
304 
305 #endif
Core module.
Definition: Allocator.h:33
const StyleOptions & styleOptions() const
Returns the current style options.
Base class for all event types.
Definition: Event.h:50
void setStyleOptions(const StyleOptions &options)
Replaces the style options for all widgets.
void sendMouseEvent(const MouseEvent &ev)
Emulates a mouse event.
Multicast Signal to call multiple slots.
Definition: Signal.h:190
Reader for PNG images.
Definition: PngReader.h:42
Window base class.
Definition: Window.h:74
const Style & style() const
Returns the current style.
Common base for objects that participate in the Forms runtime.
Definition: Widget.h:73
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Main element of a Pt::Forms graphical user interface.
Definition: Application.h:68
Style for widgets.
Definition: Style.h:155
void setStyle(const Style &s)
Sets the global style for all widgets.
Screen of a display.
Definition: Screen.h:64
Represents time spans in microsecond resolution.
Definition: Timespan.h:63
Represents a path in the file-system.
Definition: Path.h:48
Basic image.
Definition: Image.h:52
Style options container.
Definition: StyleOptions.h:535
Graphics backend interface used by platform integration.
Definition: GraphicsBackend.h:49
Console applications without a GUI.
Definition: Application.h:55
void sendKeyEvent(const KeyEvent &ev)
Emulates a key event.
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Api-Types.h:62