#include <wx/app.h>
The wxApp class represents the application itself when wxUSE_GUI=1
.
In addition to the features provided by wxAppConsole it keeps track of the top window (see SetTopWindow()) and adds support for video modes (see SetVideoMode()).
In general, application-wide settings for GUI-only apps are accessible from wxApp (or from wxSystemSettings or wxSystemOptions classes).
Event macros for events emitted by this class:
wxEVT_ACTIVATE_APP
event. See wxActivateEvent. wxEVT_IDLE
event. See wxIdleEvent. Public Member Functions | |
wxApp () | |
Constructor. More... | |
virtual | ~wxApp () |
Destructor. More... | |
virtual wxVideoMode | GetDisplayMode () const |
Get display mode that is used use. More... | |
bool | GetExitOnFrameDelete () const |
Returns true if the application will exit when the top-level frame is deleted. More... | |
virtual wxLayoutDirection | GetLayoutDirection () const |
Return the layout direction for the current locale or wxLayout_Default if it's unknown. More... | |
bool | GetUseBestVisual () const |
Returns true if the application will use the best visual on systems that support different visuals, false otherwise. More... | |
virtual wxWindow * | GetTopWindow () const |
Returns a pointer to the top window. More... | |
virtual bool | IsActive () const |
Returns true if the application is active, i.e. if one of its windows is currently in the foreground. More... | |
virtual bool | SafeYield (wxWindow *win, bool onlyIfNeeded) |
This function is similar to wxYield(), except that it disables the user input to all program windows before calling wxAppConsole::Yield and re-enables it again afterwards. More... | |
virtual bool | SafeYieldFor (wxWindow *win, long eventsToProcess) |
Works like SafeYield() with onlyIfNeeded == true except that it allows the caller to specify a mask of events to be processed. More... | |
bool | ProcessMessage (WXMSG *msg) |
Windows-only function for processing a message. More... | |
virtual bool | SetDisplayMode (const wxVideoMode &info) |
Set display mode to use. More... | |
void | SetExitOnFrameDelete (bool flag) |
Allows the programmer to specify whether the application will exit when the top-level frame is deleted. More... | |
virtual bool | SetNativeTheme (const wxString &theme) |
Allows runtime switching of the UI environment theme. More... | |
void | SetTopWindow (wxWindow *window) |
Sets the 'top' window. More... | |
void | SetUseBestVisual (bool flag, bool forceTrueColour=false) |
Allows the programmer to specify whether the application will use the best visual on systems that support several visual on the same display. More... | |
Mac-specific functions | |
virtual void | MacNewFile () |
Called in response of an "open-application" Apple event. More... | |
virtual void | MacOpenFiles (const wxArrayString &fileNames) |
Called in response of an openFiles message. More... | |
virtual void | MacOpenFile (const wxString &fileName) |
Called in response of an "open-document" Apple event. More... | |
virtual void | MacOpenURL (const wxString &url) |
Called in response of a "get-url" Apple event. More... | |
virtual void | MacPrintFile (const wxString &fileName) |
Called in response of a "print-document" Apple event. More... | |
virtual void | MacReopenApp () |
Called in response of a "reopen-application" Apple event. More... | |
virtual bool | OSXIsGUIApplication () |
May be overridden to indicate that the application is not a foreground GUI application under OS X. More... | |
Public Member Functions inherited from wxAppConsole | |
virtual | ~wxAppConsole () |
Destructor. More... | |
bool | Yield (bool onlyIfNeeded=false) |
Yields control to pending messages in the event loop. More... | |
void | SetCLocale () |
Sets the C locale to the default locale for the current environment. More... | |
virtual int | MainLoop () |
Called by wxWidgets on creation of the application. More... | |
virtual void | ExitMainLoop () |
Call this to explicitly exit the main message (event) loop. More... | |
virtual int | FilterEvent (wxEvent &event) |
Overridden wxEventFilter method. More... | |
wxEventLoopBase * | GetMainLoop () const |
Returns the main event loop instance, i.e. the event loop which is started by OnRun() and which dispatches all events sent from the native toolkit to the application (except when new event loops are temporarily set-up). More... | |
virtual void | HandleEvent (wxEvtHandler *handler, wxEventFunction func, wxEvent &event) const |
This function simply invokes the given method func of the specified event handler handler with the event as parameter. More... | |
virtual bool | UsesEventLoop () const |
Returns true if the application is using an event loop. More... | |
virtual void | ProcessPendingEvents () |
Process all pending events; it is necessary to call this function to process events posted with wxEvtHandler::QueueEvent or wxEvtHandler::AddPendingEvent. More... | |
void | DeletePendingEvents () |
Deletes the pending events of all wxEvtHandlers of this application. More... | |
bool | HasPendingEvents () const |
Returns true if there are pending events on the internal pending event list. More... | |
void | SuspendProcessingOfPendingEvents () |
Temporary suspends processing of the pending events. More... | |
void | ResumeProcessingOfPendingEvents () |
Resume processing of the pending events previously stopped because of a call to SuspendProcessingOfPendingEvents(). More... | |
void | ScheduleForDestruction (wxObject *object) |
Delayed objects destruction. More... | |
bool | IsScheduledForDestruction (wxObject *object) const |
Check if the object had been scheduled for destruction with ScheduleForDestruction(). More... | |
virtual void | OnAssertFailure (const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg) |
This function is called when an assert failure occurs, i.e. the condition specified in wxASSERT() macro evaluated to false. More... | |
virtual bool | OnCmdLineError (wxCmdLineParser &parser) |
Called when command line parsing fails (i.e. an incorrect command line option was specified by the user). More... | |
virtual bool | OnCmdLineHelp (wxCmdLineParser &parser) |
Called when the help option (–help ) was specified on the command line. More... | |
virtual bool | OnCmdLineParsed (wxCmdLineParser &parser) |
Called after the command line had been successfully parsed. More... | |
virtual void | OnEventLoopEnter (wxEventLoopBase *loop) |
Called by wxEventLoopBase::SetActive(): you can override this function and put here the code which needs an active event loop. More... | |
virtual void | OnEventLoopExit (wxEventLoopBase *loop) |
Called by wxEventLoopBase::OnExit() for each event loop which is exited. More... | |
virtual int | OnExit () |
Override this member function for any processing which needs to be done as the application is about to exit. More... | |
virtual void | OnFatalException () |
This function may be called if something fatal happens: an unhandled exception under Win32 or a fatal signal under Unix, for example. More... | |
virtual bool | OnInit () |
This must be provided by the application, and will usually create the application's main window, optionally calling SetTopWindow(). More... | |
virtual void | OnInitCmdLine (wxCmdLineParser &parser) |
Called from OnInit() and may be used to initialize the parser with the command line options for this application. More... | |
virtual int | OnRun () |
This virtual function is where the execution of a program written in wxWidgets starts. More... | |
virtual bool | OnExceptionInMainLoop () |
This function is called if an unhandled exception occurs inside the main application event loop. More... | |
virtual void | OnUnhandledException () |
This function is called when an unhandled C++ exception occurs in user code called by wxWidgets. More... | |
virtual bool | StoreCurrentException () |
Method to store exceptions not handled by OnExceptionInMainLoop(). More... | |
virtual void | RethrowStoredException () |
Method to rethrow exceptions stored by StoreCurrentException(). More... | |
wxString | GetAppDisplayName () const |
Returns the user-readable application name. More... | |
wxString | GetAppName () const |
Returns the application name. More... | |
wxString | GetClassName () const |
Gets the class name of the application. More... | |
wxAppTraits * | GetTraits () |
Returns a pointer to the wxAppTraits object for the application. More... | |
const wxString & | GetVendorDisplayName () const |
Returns the user-readable vendor name. More... | |
const wxString & | GetVendorName () const |
Returns the application's vendor name. More... | |
void | SetAppDisplayName (const wxString &name) |
Set the application name to be used in the user-visible places such as window titles. More... | |
void | SetAppName (const wxString &name) |
Sets the name of the application. More... | |
void | SetClassName (const wxString &name) |
Sets the class name of the application. More... | |
void | SetVendorDisplayName (const wxString &name) |
Set the vendor name to be used in the user-visible places. More... | |
void | SetVendorName (const wxString &name) |
Sets the name of application's vendor. More... | |
Public Member Functions inherited from wxEvtHandler | |
wxEvtHandler () | |
Constructor. More... | |
virtual | ~wxEvtHandler () |
Destructor. More... | |
virtual void | QueueEvent (wxEvent *event) |
Queue event for a later processing. More... | |
virtual void | AddPendingEvent (const wxEvent &event) |
Post an event to be processed later. More... | |
template<typename T , typename T1 , ... > | |
void | CallAfter (void(T::*method)(T1,...), T1 x1,...) |
Asynchronously call the given method. More... | |
template<typename T > | |
void | CallAfter (const T &functor) |
Asynchronously call the given functor. More... | |
virtual bool | ProcessEvent (wxEvent &event) |
Processes an event, searching event tables and calling zero or more suitable event handler function(s). More... | |
bool | ProcessEventLocally (wxEvent &event) |
Try to process the event in this handler and all those chained to it. More... | |
bool | SafelyProcessEvent (wxEvent &event) |
Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process. More... | |
void | ProcessPendingEvents () |
Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail. More... | |
void | DeletePendingEvents () |
Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent(). More... | |
virtual bool | SearchEventTable (wxEventTable &table, wxEvent &event) |
Searches the event table, executing an event handler function if an appropriate one is found. More... | |
void | Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
Connects the given function dynamically with the event handler, id and event type. More... | |
void | Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More... | |
void | Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More... | |
bool | Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More... | |
bool | Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More... | |
bool | Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL) |
See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info. More... | |
template<typename EventTag , typename Functor > | |
void | Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
Binds the given function, functor or method dynamically with the event. More... | |
template<typename EventTag , typename Class , typename EventArg , typename EventHandler > | |
void | Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More... | |
template<typename EventTag , typename Functor > | |
bool | Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed. More... | |
template<typename EventTag , typename Class , typename EventArg , typename EventHandler > | |
bool | Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL) |
See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info. More... | |
void * | GetClientData () const |
Returns user-supplied client data. More... | |
wxClientData * | GetClientObject () const |
Returns a pointer to the user-supplied client data object. More... | |
void | SetClientData (void *data) |
Sets user-supplied client data. More... | |
void | SetClientObject (wxClientData *data) |
Set the client data object. More... | |
bool | GetEvtHandlerEnabled () const |
Returns true if the event handler is enabled, false otherwise. More... | |
wxEvtHandler * | GetNextHandler () const |
Returns the pointer to the next handler in the chain. More... | |
wxEvtHandler * | GetPreviousHandler () const |
Returns the pointer to the previous handler in the chain. More... | |
void | SetEvtHandlerEnabled (bool enabled) |
Enables or disables the event handler. More... | |
virtual void | SetNextHandler (wxEvtHandler *handler) |
Sets the pointer to the next handler. More... | |
virtual void | SetPreviousHandler (wxEvtHandler *handler) |
Sets the pointer to the previous handler. More... | |
void | Unlink () |
Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted). More... | |
bool | IsUnlinked () const |
Returns true if the next and the previous handler pointers of this event handler instance are NULL. More... | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. More... | |
wxObject (const wxObject &other) | |
Copy ctor. More... | |
virtual | ~wxObject () |
Destructor. More... | |
virtual wxClassInfo * | GetClassInfo () const |
This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More... | |
wxObjectRefData * | GetRefData () const |
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More... | |
bool | IsKindOf (const wxClassInfo *info) const |
Determines whether this class is a subclass of (or the same class as) the given class. More... | |
bool | IsSameAs (const wxObject &obj) const |
Returns true if this object has the same data pointer as obj. More... | |
void | Ref (const wxObject &clone) |
Makes this object refer to the data in clone. More... | |
void | SetRefData (wxObjectRefData *data) |
Sets the wxObject::m_refData pointer. More... | |
void | UnRef () |
Decrements the reference count in the associated data, and if it is zero, deletes the data. More... | |
void | UnShare () |
This is the same of AllocExclusive() but this method is public. More... | |
void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More... | |
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More... | |
Public Member Functions inherited from wxEventFilter | |
wxEventFilter () | |
Default constructor. More... | |
virtual | ~wxEventFilter () |
Destructor. More... | |
Additional Inherited Members | |
Public Types inherited from wxEventFilter | |
enum | { Event_Skip = -1, Event_Ignore = 0, Event_Processed = 1 } |
Possible return values for FilterEvent(). More... | |
Static Public Member Functions inherited from wxAppConsole | |
static void | SetInstance (wxAppConsole *app) |
Allows external code to modify global wxTheApp, but you should really know what you're doing if you call it. More... | |
static wxAppConsole * | GetInstance () |
Returns the one and only global application object. More... | |
static bool | IsMainLoopRunning () |
Returns true if the main event loop is currently running, i.e. if the application is inside OnRun(). More... | |
Static Public Member Functions inherited from wxEvtHandler | |
static void | AddFilter (wxEventFilter *filter) |
Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets. More... | |
static void | RemoveFilter (wxEventFilter *filter) |
Remove a filter previously installed with AddFilter(). More... | |
Public Attributes inherited from wxAppConsole | |
int | argc |
Number of command line arguments (after environment-specific processing). More... | |
wxChar ** | argv |
Command line arguments (after environment-specific processing). More... | |
Protected Member Functions inherited from wxAppConsole | |
virtual wxAppTraits * | CreateTraits () |
Creates the wxAppTraits object when GetTraits() needs it for the first time. More... | |
Protected Member Functions inherited from wxEvtHandler | |
virtual bool | TryBefore (wxEvent &event) |
Method called by ProcessEvent() before examining this object event tables. More... | |
virtual bool | TryAfter (wxEvent &event) |
Method called by ProcessEvent() as last resort. More... | |
Protected Member Functions inherited from wxObject | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. More... | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More... | |
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More... | |
Protected Attributes inherited from wxObject | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. More... | |
wxApp::wxApp | ( | ) |
Constructor.
Called implicitly with a definition of a wxApp object.
|
virtual |
Destructor.
Will be called implicitly on program exit if the wxApp object is created on the stack.
|
virtual |
Get display mode that is used use.
This is only used in framebuffer wxWidgets ports such as wxDFB.
bool wxApp::GetExitOnFrameDelete | ( | ) | const |
Returns true if the application will exit when the top-level frame is deleted.
|
virtual |
Return the layout direction for the current locale or wxLayout_Default
if it's unknown.
|
virtual |
Returns a pointer to the top window.
bool wxApp::GetUseBestVisual | ( | ) | const |
Returns true if the application will use the best visual on systems that support different visuals, false otherwise.
|
virtual |
Returns true if the application is active, i.e. if one of its windows is currently in the foreground.
If this function returns false and you need to attract users attention to the application, you may use wxTopLevelWindow::RequestUserAttention to do it.
|
virtual |
Called in response of an "open-application" Apple event.
Override this to create a new document in your app.
|
virtual |
Called in response of an "open-document" Apple event.
|
virtual |
Called in response of an openFiles message.
You need to override this method in order to open one or more document files after the user double clicked on it or if the files and/or folders were dropped on either the application in the dock or the application icon in Finder.
By default this method calls MacOpenFile for each file/folder.
|
virtual |
Called in response of a "get-url" Apple event.
|
virtual |
Called in response of a "print-document" Apple event.
|
virtual |
Called in response of a "reopen-application" Apple event.
|
virtual |
May be overridden to indicate that the application is not a foreground GUI application under OS X.
This method is called during the application startup and returns true by default. In this case, wxWidgets ensures that the application is ran as a foreground, GUI application so that the user can interact with it normally, even if it is not bundled. If this is undesired, i.e. if the application doesn't need to be brought to the foreground, this method can be overridden to return false.
Notice that overriding it doesn't make any difference for the bundled applications which are always foreground unless LSBackgroundOnly
key is specified in the Info.plist
file.
bool wxApp::ProcessMessage | ( | WXMSG * | msg | ) |
Windows-only function for processing a message.
This function is called from the main message loop, checking for windows that may wish to process it.
The function returns true if the message was processed, false otherwise. If you use wxWidgets with another class library with its own message loop, you should make sure that this function is called to allow wxWidgets to receive messages. For example, to allow co-existence with the Microsoft Foundation Classes, override the PreTranslateMessage function:
|
virtual |
This function is similar to wxYield(), except that it disables the user input to all program windows before calling wxAppConsole::Yield and re-enables it again afterwards.
If win is not NULL, this window will remain enabled, allowing the implementation of some limited user interaction. Returns the result of the call to wxAppConsole::Yield.
|
virtual |
Works like SafeYield() with onlyIfNeeded == true except that it allows the caller to specify a mask of events to be processed.
See wxAppConsole::YieldFor for more info.
|
virtual |
Set display mode to use.
This is only used in framebuffer wxWidgets ports such as wxDFB.
void wxApp::SetExitOnFrameDelete | ( | bool | flag | ) |
Allows the programmer to specify whether the application will exit when the top-level frame is deleted.
flag | If true (the default), the application will exit when the top-level frame is deleted. If false, the application will continue to run. |
|
virtual |
Allows runtime switching of the UI environment theme.
Currently implemented for wxGTK2-only. Return true if theme was successfully changed.
theme | The name of the new theme or an absolute path to a gtkrc-theme-file |
void wxApp::SetTopWindow | ( | wxWindow * | window | ) |
Sets the 'top' window.
You can call this from within OnInit() to let wxWidgets know which is the main window. You don't have to set the top window; it is only a convenience so that (for example) certain dialogs without parents can use a specific window as the top window.
If no top window is specified by the application, wxWidgets just uses the first frame or dialog (or better, any wxTopLevelWindow) in its top-level window list, when it needs to use the top window. If you previously called SetTopWindow() and now you need to restore this automatic behaviour you can call
.
window | The new top window. |
void wxApp::SetUseBestVisual | ( | bool | flag, |
bool | forceTrueColour = false |
||
) |
Allows the programmer to specify whether the application will use the best visual on systems that support several visual on the same display.
This is typically the case under Solaris and IRIX, where the default visual is only 8-bit whereas certain applications are supposed to run in TrueColour mode.
Note that this function has to be called in the constructor of the wxApp instance and won't have any effect when called later on. This function currently only has effect under GTK.
flag | If true, the app will use the best visual. |
forceTrueColour | If true then the application will try to force using a TrueColour visual and abort the app if none is found. |