wxWidgets: wxAppTraits Class Reference

| Version: 3.2.5

Public Member Functions | List of all members
wxAppTraits Class Referenceabstract
Class List by Category » Application and System configuration

`#include <wx/apptrait.h>`

## Detailed Description

The wxAppTraits class defines various configurable aspects of a wxApp.

You can access it using wxApp::GetTraits() function and you can create your own wxAppTraits overriding the wxApp::CreateTraits() function.

Note that wxAppTraits is an abstract class since it contains many pure virtual functions. In fact, by default, wxWidgets creates a `wxConsoleAppTraits` object for console applications (i.e. those applications linked against wxBase library only - see the Library List page) and a `wxGUIAppTraits` object for GUI applications. Both these classes are derived by wxAppTraits and represent concrete implementation of the wxAppTraits interface.

##

Library: wxBase
Category: Application and System configuration

See also
  wxApp Overview, wxApp

## Public Member Functions
virtual wxConfigBase * | CreateConfig ()
| Called by wxWidgets to create the default configuration object for the application. More...
virtual wxEventLoopBase * | CreateEventLoop ()=0
| Used by wxWidgets to create the main event loop used by wxApp::OnRun(). More...
virtual wxFontMapper * | CreateFontMapper ()=0
| Creates the global font mapper object used for encodings/charset mapping. More...
virtual wxLog * | CreateLogTarget ()=0
| Creates a wxLog class for the application to use for logging errors. More...
virtual wxMessageOutput * | CreateMessageOutput ()=0
| Creates the global object used for printing out messages. More...
virtual wxRendererNative * | CreateRenderer ()=0
| Returns the renderer to use for drawing the generic controls (return value may be NULL in which case the default renderer for the current platform is used); this is used in GUI mode only and always returns NULL in console. More...
virtual wxString | GetDesktopEnvironment () const =0
| Returns the name of the desktop environment currently running on a Unix desktop. More...
virtual wxStandardPaths & | GetStandardPaths ()
| Returns the wxStandardPaths object for the application. More...
virtual wxPortId | GetToolkitVersion (int *major=NULL, int *minor=NULL, int *micro=NULL) const =0
| Returns the wxWidgets port ID used by the running program and eventually fills the given pointers with the values of the major, minor, and micro digits of the native toolkit currently used. More...
virtual bool | HasStderr ()=0
| Returns true if `fprintf(stderr)` goes somewhere, false otherwise. More...
virtual bool | IsUsingUniversalWidgets () const =0
| Returns true if the library was built as wxUniversal. More...
virtual bool | ShowAssertDialog (const wxString &msg)=0
| Shows the assert dialog with the specified message in GUI mode or just prints the string to stderr in console mode. More...
virtual bool | SafeMessageBox (const wxString &text, const wxString &title)=0
| Shows a message box with the given text and title if possible. More...
virtual wxString | GetAssertStackTrace ()
| Helper function mostly useful for derived classes ShowAssertDialog() implementation. More...

## Member Function Documentation

## ◆ CreateConfig()

virtual wxConfigBase* wxAppTraits::CreateConfig | ( |  | ) |
| virtual

Called by wxWidgets to create the default configuration object for the application.

The default version creates a registry-based wxRegConfig class under MSW and wxFileConfig under all other platforms.

The wxApp::GetAppName and wxApp::GetVendorName methods are used to determine the registry key or file name.

## ◆ CreateEventLoop()

virtual wxEventLoopBase* wxAppTraits::CreateEventLoop | ( |  | ) |
| pure virtual

Used by wxWidgets to create the main event loop used by wxApp::OnRun().

The default implementation of this method in wxGUIAppTraits returns the usual platform-specific GUI event loop. The version in wxConsoleAppTraits returns a console-specific event loop which can be used to handle timer and socket events in console programs under Unix and MSW or NULL under the other platforms where console event loops are not supported yet.

## ◆ CreateFontMapper()

virtual wxFontMapper* wxAppTraits::CreateFontMapper | ( |  | ) |
| pure virtual

Creates the global font mapper object used for encodings/charset mapping.

## ◆ CreateLogTarget()

virtual wxLog* wxAppTraits::CreateLogTarget | ( |  | ) |
| pure virtual

Creates a wxLog class for the application to use for logging errors.

The default implementation returns a new wxLogGui class.

See also
  wxLog

## ◆ CreateMessageOutput()

virtual wxMessageOutput* wxAppTraits::CreateMessageOutput | ( |  | ) |
| pure virtual

Creates the global object used for printing out messages.

## ◆ CreateRenderer()

virtual wxRendererNative* wxAppTraits::CreateRenderer | ( |  | ) |
| pure virtual

Returns the renderer to use for drawing the generic controls (return value may be NULL in which case the default renderer for the current platform is used); this is used in GUI mode only and always returns NULL in console.

Note
  the returned pointer needs to be deleted by the caller.

## ◆ GetAssertStackTrace()

virtual wxString wxAppTraits::GetAssertStackTrace | ( |  | ) |
| virtual

Helper function mostly useful for derived classes ShowAssertDialog() implementation.

Returns the stack frame as a plain (and possibly empty) wxString.

This function is only available when `wxUSE_STACKWALKER` is 1.

Since
  3.1.5

## ◆ GetDesktopEnvironment()

virtual wxString wxAppTraits::GetDesktopEnvironment | ( |  | ) | const
| pure virtual

Returns the name of the desktop environment currently running on a Unix desktop.

It returns an empty string for platforms other than wxGTK, or if the desktop environment could not be determined.

## ◆ GetStandardPaths()

virtual wxStandardPaths& wxAppTraits::GetStandardPaths | ( |  | ) |
| virtual

Returns the wxStandardPaths object for the application.

It's normally the same for wxBase and wxGUI except in the case of wxMac and wxCocoa.

Note
  The returned reference is to a `wxStandardPathsBase` class but you can consider it to be equivalent to wxStandardPaths (which is documented).

## ◆ GetToolkitVersion()

virtual wxPortId wxAppTraits::GetToolkitVersion | ( | int * | major = `NULL`,
|  | int * | minor = `NULL`,
|  | int * | micro = `NULL`
| ) |  | const
| pure virtual

Returns the wxWidgets port ID used by the running program and eventually fills the given pointers with the values of the major, minor, and micro digits of the native toolkit currently used.

The version numbers returned are thus detected at run-time and not compile-time (except when this is not possible e.g. wxMotif).

E.g. if your program is using wxGTK port this function will return wxPORT_GTK and put in given pointers the versions of the GTK library in use. See wxPlatformInfo for more details.

If a micro version is not available it will have a value of 0.

## ◆ HasStderr()

virtual bool wxAppTraits::HasStderr | ( |  | ) |
| pure virtual

Returns true if `fprintf(stderr)` goes somewhere, false otherwise.

## ◆ IsUsingUniversalWidgets()

virtual bool wxAppTraits::IsUsingUniversalWidgets | ( |  | ) | const
| pure virtual

Returns true if the library was built as wxUniversal.

Always returns false for wxBase-only apps.

## ◆ SafeMessageBox()

virtual bool wxAppTraits::SafeMessageBox | ( | const wxString & | text,
|  | const wxString & | title
| ) |  |
| pure virtual

Shows a message box with the given text and title if possible.

In some ports, e.g. wxMSW, a message box will always be shown, while in the other ones it will be only done if the GUI is available (e.g. X11 display was successfully opened for X11-based ports) and the function simply returns false without doing anything otherwise.

This function is safe in the sense that it can always be called, even before creating wxApp, similarly to wxSafeShowMessage() which is implemented by calling this function and then logging the message to standard error stream if it returned false.

Since
  3.1.5

Parameters

  text | The text to show to the user.
  title | The title of the message box shown to the user.

Returns
  true if the message box was shown or false otherwise.

## ◆ ShowAssertDialog()

virtual bool wxAppTraits::ShowAssertDialog | ( | const wxString & | msg | ) |
| pure virtual

Shows the assert dialog with the specified message in GUI mode or just prints the string to stderr in console mode.

Returns true to suppress subsequent asserts, false to continue as before.