Application Class Reference

#include <Pt/Forms/Application.h>

Provides the runtime root of a Forms user interface. More...

Inherits Application.

Public Member Functions

 Application (int argc=0, char **argv=0)
 Creates the Forms runtime and its primary screen.
virtual ~Application ()
 Destroys the Forms runtime and the services it owns.
ApplicationImpl * impl ()
 Returns the platform-specific Forms implementation.
GraphicsBackendgraphicsBackend ()
 Returns the graphics backend used by Forms.
const GraphicsBackendgraphicsBackend () const
 Returns the graphics backend used by Forms.
const Screen & screen () const
 Returns the primary screen.
Screen & screen ()
 Returns the primary screen.
Pt::Timespan inactivityTime () const
 Returns the time since the last platform user activity.
void setCursor (const Cursor *cursor=0)
 Sets the platform cursor.
const Stylestyle () const
 Returns the current style.
void setStyle (const Style &s)
 Sets the global style for all widgets.
const StyleOptionsstyleOptions () const
 Returns the current style options.
void setStyleOptions (const StyleOptions &options)
 Replaces the style options for all widgets.
void loadImage (const System::Path &path, Gfx::Image &image)
 Loads a PNG file into image.
void setScaleFactor (double scale)
 Sets the Forms scaling factor.
double scaleFactor () const
 Returns the current Forms scaling factor.
InputMethodinputMethod ()
 Returns the active input method.
void setInputMethod (InputMethod &im)
 Installs im as the active input method.
void removeInputMethod (InputMethod &im)
 Removes im when it is the active input method.
Pt::uint64_t makeId ()
 Creates an ID for an internal Forms widget.
Widget * findWidget (Pt::uint64_t id)
 Finds the live widget with id.
void nextEvent ()
 Processes the next platform event.
void commitEvent (const Event &ev)
 Queues ev on the application event loop.
void processEvent (const Event &ev)
 Processes ev immediately through Forms event dispatch.
Pt::Signal< const Pt::Event & > & eventReceived ()
 Notifies of events passed to processEvent().
void invalidate ()
 Invalidates every registered widget.
void sendKeyEvent (const KeyEvent &ev)
 Emulates a platform key event.
void sendMouseEvent (const MouseEvent &ev)
 Emulates a platform mouse event.
Widget * capture () const
 Returns the active pointer-capture target.
void addFonts (const Pt::System::Path &dir)
 Adds the font files found in dir.
bool addFont (const Pt::System::Path &path)
 Adds the font at path.
bool removeFont (const Pt::System::Path &path)
 Removes the font at path.
const std::vector< Pt::System::Path > & fontFiles () const
 Returns the paths of the registered font files.
std::string defaultFont () const
 Returns the default font family used by the graphics backend.
void setDefaultFont (const std::string &family)
 Sets the default font family used by the graphics backend.
std::vector< std::string > fontFamilies () const
 Returns the available font family names.
std::vector< Gfx::FontFacefontFaces (const std::string &family) const
 Returns the available faces in family.
EventLoop & loop ()
 Returns the event loop.
void run ()
 Starts the contained event loop.
void exit ()
 Exits from the contained event loop.
bool ignoreSystemSignal (int sig)
 Ignores a system signal.
bool catchSystemSignal (int sig)
 Catch a system signal.
bool raiseSystemSignal (int sig)
 Raise a system signal.
Signal< int > & systemSignal ()
 Notifies when a system signal was caught.
int & argc () const
 Number of command line arguments.
char ** argv () const
 Command line arguments.
void setArgs (int &argc, char **argv)
 Set command line arguments.
template<typename T>
Arg< T > getArg (const char *name)
 Returns the value of a long option.
template<typename T>
Arg< T > getArg (const char *name, const T &def)
 Returns the value of a long option.
template<typename T>
Arg< T > getArg (const char name)
 Returns the value of a short option.
template<typename T>
Arg< T > getArg (const char name, const T &def)
 Returns the value of a short option.

Static Public Member Functions

static Applicationinstance ()
 Returns the Forms application instance.
static void chdir (const Path &path)
 Changes the current directory.
static Path cwd ()
 Returns the current directory.
static Path rootdir ()
 Returns the system root path.
static Path tmpdir ()
 Returns the systems tmp directory.
static void setEnvVar (const std::string &name, const std::string &value)
 Set environment variable.
static void unsetEnvVar (const std::string &name)
 Unset environment variable.
static std::string getEnvVar (const std::string &name)
 Get environment variable.
static unsigned long usedMemory ()
 Returns the amount of used memory.

Detailed Description

Application provides the Forms runtime. It is not a Widget. Construct one before any widget, show the visual hierarchy, then enter the inherited event loop with Pt::System::Application::run().

The application owns its platform implementation, graphics backend, and primary Screen. It does not own the windows or controls that use those services. Widgets remove themselves from their visual parent when they are destroyed. Each widget receives an ID while the application exists; findWidget() resolves that ID only while the widget remains alive.

Platform events enter the inherited event loop and are routed through the Forms event dispatcher to their target widget or the primary screen. The same dispatcher handles layout, invalidation, repainting, scaling, and window changes. It permits the visual hierarchy to coalesce deferred work. Applications normally request changes through widget APIs. Use processEvent() only when deliberately supplying Forms events.

The application provides shared styles, style options, input methods, fonts, and scaling. Use setStyle() and setStyleOptions() to change the global theme. Those methods reset shared renderer facets and invalidate registered widgets. Widgets rebuild in onInvalidate(). setScaleFactor() sends a rescale event through the primary screen. Configure shared services before showing the user interface when possible. impl() and graphicsBackend() support Forms backend implementations; ordinary applications use the higher-level Forms APIs.

Member Function Documentation

◆ impl()

ApplicationImpl * impl ( )

This is an implementation API for Forms backends. The application owns the returned object.

◆ graphicsBackend() [1/2]

GraphicsBackend & graphicsBackend ( )

This is an implementation API for Forms backends. The application owns the returned backend.

◆ graphicsBackend() [2/2]

const GraphicsBackend & graphicsBackend ( ) const

This is an implementation API for Forms backends. The application owns the returned backend.

◆ screen() [1/2]

const Screen & screen ( ) const

The application owns the returned screen. Use its window manager for top-level windows.

◆ screen() [2/2]

Screen & screen ( )

The application owns the returned screen. Use its window manager for top-level windows.

◆ setCursor()

void setCursor ( const Cursor * cursor = 0)

Pass 0 to restore the platform default cursor. The caller retains ownership of cursor.

◆ setStyle()

void setStyle ( const Style & s)

Resets the style with the current StyleOptions and invalidates all registered widgets.

◆ setStyleOptions()

void setStyleOptions ( const StyleOptions & options)

Resets the current style and invalidates all registered widgets.

◆ loadImage()

void loadImage ( const System::Path & path,
Gfx::Image & image )

Resets image when path does not exist.

◆ setScaleFactor()

void setScaleFactor ( double scale)

Immediately sends a RescaleEvent through the primary screen.

◆ inputMethod()

InputMethod & inputMethod ( )

The application always provides its default input method when no custom method is installed.

◆ setInputMethod()

void setInputMethod ( InputMethod & im)

Removes the previously active method and registers im with this application. The caller retains ownership of im and must keep it alive until it is removed.

◆ removeInputMethod()

void removeInputMethod ( InputMethod & im)

Restores the application-owned default input method.

◆ makeId()

Pt::uint64_t makeId ( )

The ID is unique within this application while the application is alive.

◆ findWidget()

Widget * findWidget ( Pt::uint64_t id)

Returns 0 when no registered widget has id. The returned widget is not owned by the application and remains valid only while the widget remains alive.

◆ nextEvent()

void nextEvent ( )

Use this only when implementing a manual Forms event loop.

TODO: this might be the same as loop().waitNext()

◆ processEvent()

void processEvent ( const Event & ev)

This supports Forms backends, tests, and deliberate event injection. Applications normally request state changes through widget APIs instead.

◆ invalidate()

void invalidate ( )

Use this for application-wide visual changes such as a style update.

◆ sendKeyEvent()

void sendKeyEvent ( const KeyEvent & ev)

This supports tests and automation, not ordinary widget event delivery.

◆ sendMouseEvent()

void sendMouseEvent ( const MouseEvent & ev)

This supports tests and automation, not ordinary widget event delivery.

◆ capture()

Widget * capture ( ) const

Returns the most recently capturing widget, otherwise the most recently shown transient popup, or 0 when neither exists. The returned widget is not owned by the application.

◆ addFont()

bool addFont ( const Pt::System::Path & path)

Returns true when the font was added.

◆ removeFont()

bool removeFont ( const Pt::System::Path & path)

Returns true when the font was removed.

◆ fontFiles()

const std::vector< Pt::System::Path > & fontFiles ( ) const

The returned collection is owned by the font subsystem.

◆ rootdir()

Path rootdir ( )
staticinherited

Returns "/" (root) on Linux, "c:\" on Windows

◆ tmpdir()

Path tmpdir ( )
staticinherited

Returns the value of the environment variable named TEMP or TMP. If neither one is set, "/tmp" is returned on POSIX systems or a path to the current directory.

◆ setEnvVar()

void setEnvVar ( const std::string & name,
const std::string & value )
staticinherited
Exceptions
SystemError

◆ unsetEnvVar()

void unsetEnvVar ( const std::string & name)
staticinherited
Exceptions
SystemError

◆ getEnvVar()

std::string getEnvVar ( const std::string & name)
staticinherited
Exceptions
SystemError