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:
97
103 explicit Application(int& argc, char** argv = 0);
104
107 virtual ~Application();
108
114 ApplicationImpl* impl();
115
122
129
133
139 const Screen& screen() const;
140
146 Screen& screen();
147
151
157 void setCursor(const Cursor* cursor = 0);
158
161 const Style& style() const;
162
168 void setStyle(const Style& s);
169
173
178 void setStyleOptions(const StyleOptions& options);
179
184 void loadImage(const System::Path& path, Gfx::Image& image);
185
190 void setScaleFactor(double scale);
191
194 double scaleFactor() const;
195
202
210
216
223
231
238 void nextEvent();
239
242 void commitEvent(const Event& ev);
243
250 void processEvent(const Event& ev);
251
255
262
268 void sendKeyEvent(const KeyEvent& ev);
269
275 void sendMouseEvent(const MouseEvent& ev);
276
283 Widget* capture() const;
284
285 public:
288 void addFonts(const Pt::System::Path& dir);
289
294 bool addFont(const Pt::System::Path& path);
295
300 bool removeFont(const Pt::System::Path& path);
301
306 const std::vector<Pt::System::Path>& fontFiles() const;
307
310 std::string defaultFont() const;
311
314 void setDefaultFont(const std::string& family);
315
318 std::vector<std::string> fontFamilies() const;
319
322 std::vector<Gfx::FontFace> fontFaces(const std::string& family) const;
323
324 protected:
325 void onSetPointer(Widget& widget, bool isPointer);
326
327 void onRequestCapture(Widget& target, bool capture);
328
329 void onShowPopup(Popup& w, bool transient);
330
331 bool isAnchoredTo(Popup& w, Window& top) const;
332
333 bool isPopupOf(Popup& w, Window& top) const;
334
335 void onClosePopups(const Gfx::PointF& screenPos);
336
337 private:
338 void registerWidget(Widget& widget);
339
340 void unregisterWidget(Widget& widget);
341
342 private:
343 void onDispatchMouseEvent(const MouseEvent& ev);
344
345 void onProcessMouseEvent(const MouseEvent& ev);
346
347
348 void onDispatchTouchEvent(const TouchEvent& ev);
349
350 void onProcessTouchEvent(const TouchEvent& ev);
351
352
353 void onDetectScroll(Widget* widget, const Gfx::PointF& screenPos,
354 bool isPress, bool isPressed);
355
356
357 void onDispatchScrollEvent(const ScrollEvent& ev);
358
359 void onProcessScrollEvent(const ScrollEvent& ev);
360
361
362 void onDispatchEnterEvent(const EnterEvent& ev);
363
364 void onProcessEnterEvent(const EnterEvent& ev);
365
366
367 void onDispatchLeaveEvent(const LeaveEvent& ev);
368
369 void onProcessLeaveEvent(const LeaveEvent& ev);
370
371
372 void onDispatchKeyEvent(const KeyEvent& ev);
373
374 void onProcessKeyEvent(const KeyEvent& ev);
375
376
377 void onDispatchInvalidateEvent(const InvalidateEvent& ev);
378
379 void onProcessInvalidateEvent(const InvalidateEvent& ev);
380
381
382 void onDispatchLayoutEvent(const LayoutEvent& ev);
383
384 void onProcessLayoutEvent(const LayoutEvent& ev);
385
386
387 void onDispatchRescaleEvent(const RescaleEvent& ev);
388
389 void onProcessRescaleEvent(const RescaleEvent& ev);
390
391
392 void onDispatchPaintEvent(const PaintEvent& ev);
393
394 void onProcessPaintEvent(const PaintEvent& ev);
395
396
397 void onDispatchMoveEvent(const MoveEvent& ev);
398
399 void onProcessMoveEvent(const MoveEvent& ev);
400
401
402 void onDispatchResizeEvent(const ResizeEvent& ev);
403
404 void onProcessResizeEvent(const ResizeEvent& ev);
405
406
407 void onDispatchActivateEvent(const ActivateEvent& ev);
408
409 void onProcessActivateEvent(const ActivateEvent& ev);
410
411
412 void onDispatchEnableEvent(const EnableEvent& ev);
413
414 void onProcessEnableEvent(const EnableEvent& ev);
415
416
417 void onDispatchShowEvent(const ShowEvent& ev);
418
419 void onProcessShowEvent(const ShowEvent& ev);
420
421
422 void onDispatchCloseEvent(const CloseEvent& ev);
423
424 void onProcessCloseEvent(const CloseEvent& ev);
425
426
427 void onDispatchFocusEvent(const FocusEvent& ev);
428
429 void onProcessFocusEvent(const FocusEvent& ev);
430
431
432 void onDispatchWindowStateEvent(const WindowStateEvent& ev);
433
434 void onProcessWindowStateEvent(const WindowStateEvent& ev);
435
436 private:
437 void initRuntime();
438
439 private:
440 typedef std::map<Pt::uint64_t, Widget*> WidgetMap;
441
442 ApplicationImpl* _impl;
443 GraphicsBackend* _graphicsBackend;
444 Pt::Signal<const Pt::Event&> _eventReceived;
445 Screen* _mainScreen;
446 Pt::uint64_t _lastId;
447 WidgetMap _widgets;
448
449 Style _style;
450 StyleOptions _styleOptions;
451
452 DefaultInputMethod* _defaultInputMethod;
453 InputMethod* _inputMethod;
454
455 std::list<Popup*> _popups;
456 std::list<Widget*> _capture;
457
458 Gfx::PointF _scrollFrom;
459 bool _onScroll;
460 Gfx::PngReader _iconReader;
461 double _scaling;
462};
463
464} // namespace
465
466} // namespace
467
468#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.
Application(int &argc, char **argv=0)
Creates the Forms runtime from argc and argv.
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.
Application()
Creates the Forms runtime and its primary screen.
const GraphicsBackend & graphicsBackend() const
Returns the graphics backend used by Forms.
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