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
50namespace Pt {
51
52namespace Forms {
53
54class Cursor;
55class Popup;
56
87class PT_FORMS_API Application : public Pt::System::Application
88{
89 friend class Widget;
90 friend class Popup;
91 friend class Screen;
92
93 public:
96 Application(int argc = 0, char** argv = 0);
97
100 virtual ~Application();
101
107 ApplicationImpl* impl();
108
115
122
126
132 const Screen& screen() const;
133
139 Screen& screen();
140
144
150 void setCursor(const Cursor* cursor = 0);
151
154 const Style& style() const;
155
161 void setStyle(const Style& s);
162
166
171 void setStyleOptions(const StyleOptions& options);
172
177 void loadImage(const System::Path& path, Gfx::Image& image);
178
183 void setScaleFactor(double scale);
184
187 double scaleFactor() const;
188
195
203
209
216
224
231 void nextEvent();
232
235 void commitEvent(const Event& ev);
236
243 void processEvent(const Event& ev);
244
248
255
261 void sendKeyEvent(const KeyEvent& ev);
262
268 void sendMouseEvent(const MouseEvent& ev);
269
276 Widget* capture() const;
277
278 public:
281 void addFonts(const Pt::System::Path& dir);
282
287 bool addFont(const Pt::System::Path& path);
288
293 bool removeFont(const Pt::System::Path& path);
294
299 const std::vector<Pt::System::Path>& fontFiles() const;
300
303 std::string defaultFont() const;
304
307 void setDefaultFont(const std::string& family);
308
311 std::vector<std::string> fontFamilies() const;
312
315 std::vector<Gfx::FontFace> fontFaces(const std::string& family) const;
316
317 protected:
318 void onSetPointer(Widget& widget, bool isPointer);
319
320 void onRequestCapture(Widget& target, bool capture);
321
322 void onShowPopup(Popup& w, bool transient);
323
324 bool isAnchoredTo(Popup& w, Window& top) const;
325
326 bool isPopupOf(Popup& w, Window& top) const;
327
328 void onClosePopups(const Gfx::PointF& screenPos);
329
330 private:
331 void registerWidget(Widget& widget);
332
333 void unregisterWidget(Widget& widget);
334
335 private:
336 void onDispatchMouseEvent(const MouseEvent& ev);
337
338 void onProcessMouseEvent(const MouseEvent& ev);
339
340
341 void onDispatchTouchEvent(const TouchEvent& ev);
342
343 void onProcessTouchEvent(const TouchEvent& ev);
344
345
346 void onDetectScroll(Widget* widget, const Gfx::PointF& screenPos,
347 bool isPress, bool isPressed);
348
349
350 void onDispatchScrollEvent(const ScrollEvent& ev);
351
352 void onProcessScrollEvent(const ScrollEvent& ev);
353
354
355 void onDispatchEnterEvent(const EnterEvent& ev);
356
357 void onProcessEnterEvent(const EnterEvent& ev);
358
359
360 void onDispatchLeaveEvent(const LeaveEvent& ev);
361
362 void onProcessLeaveEvent(const LeaveEvent& ev);
363
364
365 void onDispatchKeyEvent(const KeyEvent& ev);
366
367 void onProcessKeyEvent(const KeyEvent& ev);
368
369
370 void onDispatchInvalidateEvent(const InvalidateEvent& ev);
371
372 void onProcessInvalidateEvent(const InvalidateEvent& ev);
373
374
375 void onDispatchLayoutEvent(const LayoutEvent& ev);
376
377 void onProcessLayoutEvent(const LayoutEvent& ev);
378
379
380 void onDispatchRescaleEvent(const RescaleEvent& ev);
381
382 void onProcessRescaleEvent(const RescaleEvent& ev);
383
384
385 void onDispatchPaintEvent(const PaintEvent& ev);
386
387 void onProcessPaintEvent(const PaintEvent& ev);
388
389
390 void onDispatchMoveEvent(const MoveEvent& ev);
391
392 void onProcessMoveEvent(const MoveEvent& ev);
393
394
395 void onDispatchResizeEvent(const ResizeEvent& ev);
396
397 void onProcessResizeEvent(const ResizeEvent& ev);
398
399
400 void onDispatchActivateEvent(const ActivateEvent& ev);
401
402 void onProcessActivateEvent(const ActivateEvent& ev);
403
404
405 void onDispatchEnableEvent(const EnableEvent& ev);
406
407 void onProcessEnableEvent(const EnableEvent& ev);
408
409
410 void onDispatchShowEvent(const ShowEvent& ev);
411
412 void onProcessShowEvent(const ShowEvent& ev);
413
414
415 void onDispatchCloseEvent(const CloseEvent& ev);
416
417 void onProcessCloseEvent(const CloseEvent& ev);
418
419
420 void onDispatchFocusEvent(const FocusEvent& ev);
421
422 void onProcessFocusEvent(const FocusEvent& ev);
423
424
425 void onDispatchWindowStateEvent(const WindowStateEvent& ev);
426
427 void onProcessWindowStateEvent(const WindowStateEvent& ev);
428
429 private:
430 typedef std::map<Pt::uint64_t, Widget*> WidgetMap;
431
432 ApplicationImpl* _impl;
433 GraphicsBackend* _graphicsBackend;
434 Pt::Signal<const Pt::Event&> _eventReceived;
435 Screen* _mainScreen;
436 Pt::uint64_t _lastId;
437 WidgetMap _widgets;
438
439 Style _style;
440 StyleOptions _styleOptions;
441
442 DefaultInputMethod* _defaultInputMethod;
443 InputMethod* _inputMethod;
444
445 std::list<Popup*> _popups;
446 std::list<Widget*> _capture;
447
448 Gfx::PointF _scrollFrom;
449 bool _onScroll;
450 Gfx::PngReader _iconReader;
451 double _scaling;
452};
453
454} // namespace
455
456} // namespace
457
458#endif
Base class for typed events.
Definition Event.h:66
Reports that a widget became active or inactive.
Definition ActivateEvent.h:49
std::vector< std::string > fontFamilies() const
Returns the available font family names.
bool removeFont(const Pt::System::Path &path)
Removes the font at path.
void nextEvent()
Processes the next platform event.
InputMethod & inputMethod()
Returns the active input method.
std::string defaultFont() const
Returns the default font family used by the graphics backend.
std::vector< Gfx::FontFace > fontFaces(const std::string &family) const
Returns the available faces in family.
const Screen & screen() const
Returns the primary screen.
void commitEvent(const Event &ev)
Queues ev on the application event loop.
Screen & screen()
Returns the primary screen.
void sendKeyEvent(const KeyEvent &ev)
Emulates a platform key event.
void setDefaultFont(const std::string &family)
Sets the default font family used by the graphics backend.
void setScaleFactor(double scale)
Sets the Forms scaling factor.
Pt::Timespan inactivityTime() const
Returns the time since the last platform user activity.
void loadImage(const System::Path &path, Gfx::Image &image)
Loads a PNG file into image.
bool addFont(const Pt::System::Path &path)
Adds the font at path.
void setInputMethod(InputMethod &im)
Installs im as the active input method.
const std::vector< Pt::System::Path > & fontFiles() const
Returns the paths of the registered font files.
void setCursor(const Cursor *cursor=0)
Sets the platform cursor.
GraphicsBackend & graphicsBackend()
Returns the graphics backend used by Forms.
void addFonts(const Pt::System::Path &dir)
Adds the font files found in dir.
double scaleFactor() const
Returns the current Forms scaling factor.
void invalidate()
Invalidates every registered widget.
Pt::uint64_t makeId()
Creates an ID for an internal Forms widget.
void setStyleOptions(const StyleOptions &options)
Replaces the style options for all widgets.
Widget * capture() const
Returns the active pointer-capture target.
void processEvent(const Event &ev)
Processes ev immediately through Forms event dispatch.
Pt::Signal< const Pt::Event & > & eventReceived()
Notifies of events passed to processEvent().
static Application & instance()
Returns the Forms application instance.
const Style & style() const
Returns the current style.
const StyleOptions & styleOptions() const
Returns the current style options.
void removeInputMethod(InputMethod &im)
Removes im when it is the active input method.
void setStyle(const Style &s)
Sets the global style for all widgets.
virtual ~Application()
Destroys the Forms runtime and the services it owns.
Widget * findWidget(Pt::uint64_t id)
Finds the live widget with id.
void sendMouseEvent(const MouseEvent &ev)
Emulates a platform mouse event.
const GraphicsBackend & graphicsBackend() const
Returns the graphics backend used by Forms.
Application(int argc=0, char **argv=0)
Creates the Forms runtime and its primary screen.
ApplicationImpl * impl()
Returns the platform-specific Forms implementation.
Reports that a widget is closing.
Definition CloseEvent.h:50
Provides the application-owned default input method.
Definition InputMethod.h:129
Pointer entered a widget.
Definition EnterEvent.h:49
Reports that a widget gained or lost focus.
Definition FocusEvent.h:48
Graphics backend used by platform integration.
Definition GraphicsBackend.h:52
Extension for platform or custom text entry.
Definition InputMethod.h:59
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
Represents a borderless transient window.
Definition Popup.h:48
Reports that a widget was resized.
Definition ResizeEvent.h:50
Scroll or wheel movement.
Definition ScrollEvent.h:51
Reports that a widget was shown or hidden.
Definition ShowEvent.h:48
Stores named appearance options.
Definition StyleOptions.h:646
Stores renderer facets for the active theme.
Definition Style.h:203
Touch press, move, or release.
Definition TouchEvent.h:51
Reports that a window's presentation state changed.
Definition WindowStateEvent.h:50
Form presented by a window manager.
Definition Window.h:99
PNG image reader.
Definition PngReader.h:53
Multicast Signal to call multiple slots.
Definition Signal.h:190
Console process root.
Definition Application.h:74
char ** argv() const
Command line arguments.
Definition Application.h:139
int & argc() const
Number of command line arguments.
Definition Application.h:134
Represents a path in the file-system.
Definition Path.h:48
Represents time spans in microsecond resolution.
Definition Timespan.h:63
uint_type uint64_t
Unsigned 64-bit integer type.
Definition Api-Types.h:66
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33