// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
+
/**
- @class wxApp
+ @class wxAppConsole
@wxheader{app.h}
- The wxApp class represents the application itself. It is used to:
-
- @li set and get application-wide properties;
- @li implement the windowing system message or event loop;
- @li initiate application processing via wxApp::OnInit;
- @li allow default processing of events not handled by other
- objects in the application.
-
- You should use the macro IMPLEMENT_APP(appClass) in your application
- implementation file to tell wxWidgets how to create an instance of your
- application class.
+ This class is essential for writing console-only or hybrid apps without
+ having to define wxUSE_GUI=0.
- Use DECLARE_APP(appClass) in a header file if you want the wxGetApp function
- (which returns a reference to your application object) to be visible to other
- files.
+ @todo MORE INFO
@library{wxbase}
@category{appmanagement}
@see @ref overview_app
*/
-class wxApp : public wxEvtHandler
+class wxAppConsole : public wxEvtHandler
{
-public:
+protected:
/**
- Constructor. Called implicitly with a definition of a wxApp object.
- */
- wxApp();
+ Creates the wxAppTraits object when GetTraits() needs it for the first time.
- /**
- Destructor. Will be called implicitly on program exit if the wxApp
- object is created on the stack.
+ @see wxAppTraits
*/
- ~wxApp();
+ virtual wxAppTraits* CreateTraits();
+
+public:
/**
- Creates a wxLog class for the application to use for logging errors.
- The default implementation returns a new wxLogGui class.
-
- @see wxLog
+ Constructor.
*/
- virtual wxLog* CreateLogTarget();
+ wxAppConsole();
/**
- Creates the wxAppTraits object when GetTraits() needs it for the first time.
-
- @see wxAppTraits
+ Destructor.
*/
- virtual wxAppTraits* CreateTraits();
+ virtual ~wxAppConsole();
/**
Dispatches the next event in the windowing system event queue.
+ Blocks until an event appears if there are none currently
+ (use Pending() if this is not wanted).
+
This can be used for programming event loops, e.g.
@code
while (app.Pending())
Dispatch();
@endcode
-
+
+ @return @false if the event loop should stop and @true otherwise.
+
@see Pending()
*/
- virtual void Dispatch();
+ virtual bool Dispatch();
/**
Call this to explicitly exit the main message (event) loop.
considering that the event had been already processed (for the former return
value) or that it is not going to be processed at all (for the latter one).
*/
- int FilterEvent(wxEvent& event);
+ virtual int FilterEvent(wxEvent& event);
/**
- Returns the user-readable application name.
-
+ Returns the user-readable application name.
+
The difference between this string and the one returned by GetAppName() is that
this one is meant to be shown to the user and so should be used for the window
titles, page headers and so on while the other one should be only used internally,
e.g. for the file names or configuration file keys.
By default, returns the same string as GetAppName().
-
+
@wxsince{2.9.0}
*/
wxString GetAppDisplayName() const;
/**
Returns the application name.
-
+
@remarks wxWidgets sets this to a reasonable default before calling
OnInit(), but the application can reset it at will.
-
+
@see GetAppDisplayName()
*/
wxString GetAppName() const;
/**
Gets the class name of the application. The class name may be used in a
platform specific manner to refer to the application.
-
+
@see SetClassName()
*/
wxString GetClassName() const;
- /**
- Returns @true if the application will exit when the top-level window is
- deleted, @false otherwise.
-
- @see SetExitOnFrameDelete(), @ref overview_app_shutdown
- */
- bool GetExitOnFrameDelete() const;
-
/**
Returns the one and only global application object.
Usually ::wxTheApp is usead instead.
-
+
@see SetInstance()
*/
static wxAppConsole* GetInstance();
- /**
- Returns a pointer to the top window.
-
- @remarks If the top window hasn't been set using SetTopWindow(),
- this function will find the first top-level window
- (frame or dialog) and return that.
-
- @see SetTopWindow()
- */
- virtual wxWindow* GetTopWindow() const;
-
/**
Returns a pointer to the wxAppTraits object for the application.
If you want to customize the wxAppTraits object, you must override the
*/
wxAppTraits* GetTraits();
- /**
- Returns @true if the application will use the best visual on systems that support
- different visuals, @false otherwise.
-
- @see SetUseBestVisual()
- */
- bool GetUseBestVisual() const;
-
/**
Returns the user-readable vendor name. The difference between this string
and the one returned by GetVendorName() is that this one is meant to be shown
configuration file keys.
By default, returns the same string as GetVendorName().
-
+
@wxsince{2.9.0}
*/
- wxString GetVendorDisplayName() const;
+ const wxString& GetVendorDisplayName() const;
/**
Returns the application's vendor name.
*/
- wxString GetVendorName() const;
+ const wxString& GetVendorName() const;
/**
This function simply invokes the given method @a func of the specified
handlers in the application in one place: if you want to do this, override
this function in your wxApp-derived class and add try/catch clause(s) to it.
*/
- virtual void HandleEvent(wxEvtHandler handler,
+ virtual void HandleEvent(wxEvtHandler* handler,
wxEventFunction func,
wxEvent& event) const;
- /**
- 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.
- */
- bool IsActive() const;
-
/**
Returns @true if the main event loop is currently running, i.e. if the
application is inside OnRun().
Mac specific. Called in response of an "open-application" Apple event.
Override this to create a new document in your app.
*/
- void MacNewFile();
+ virtual void MacNewFile();
/**
Mac specific. Called in response of an "open-document" Apple event.
user double clicked on it or if the document file was dropped on either the
running application or the application icon in Finder.
*/
- void MacOpenFile(const wxString& fileName);
+ virtual void MacOpenFile(const wxString& fileName);
/**
Mac specific. Called in response of a "get-url" Apple event.
*/
- void MacOpenURL(const wxString& url);
+ virtual void MacOpenURL(const wxString& url);
/**
Mac specific. Called in response of a "print-document" Apple event.
*/
- void MacPrintFile(const wxString& fileName);
+ virtual void MacPrintFile(const wxString& fileName);
/**
Mac specific. Called in response of a "reopen-application" Apple event.
*/
- void MacReopenApp();
+ virtual void MacReopenApp();
/**
Called by wxWidgets on creation of the application. Override this if you wish
to provide your own (environment-dependent) main loop.
-
+
@returns Returns 0 under X, and the wParam of the WM_QUIT message under
Windows.
*/
asserts are not left in the release code at all.
The base class version shows the default assert failure dialog box proposing to
the user to stop the program, continue or ignore all subsequent asserts.
-
+
@param file
the name of the source file where the assert occurred
@param line
the message specified as argument to wxASSERT_MSG or wxFAIL_MSG, will
be @NULL if just wxASSERT or wxFAIL was used
*/
- void OnAssertFailure(const wxChar file, int line,
- const wxChar func,
- const wxChar cond,
- const wxChar msg);
+ virtual void OnAssertFailure(const wxChar *file,
+ int line,
+ const wxChar *func,
+ const wxChar *cond,
+ const wxChar *msg);
/**
Called when command line parsing fails (i.e. an incorrect command line option
Return @true to continue normal execution or @false to return
@false from OnInit() thus terminating the program.
-
+
@see OnInitCmdLine()
*/
- bool OnCmdLineError(wxCmdLineParser& parser);
+ virtual bool OnCmdLineError(wxCmdLineParser& parser);
/**
Called when the help option (@c --help) was specified on the command line.
Return @true to continue normal execution or @false to return
@false from OnInit() thus terminating the program.
-
+
@see OnInitCmdLine()
*/
- bool OnCmdLineHelp(wxCmdLineParser& parser);
+ virtual bool OnCmdLineHelp(wxCmdLineParser& parser);
/**
Called after the command line had been successfully parsed. You may override
processing of the standard command line options.
Return @true to continue normal execution or @false to return @false from
OnInit() thus terminating the program.
-
+
@see OnInitCmdLine()
*/
- bool OnCmdLineParsed(wxCmdLineParser& parser);
+ virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
/**
This function is called if an unhandled exception occurs inside the main
Generally speaking, this function should only show a message to the user and
return. You may attempt to save unsaved data but this is not guaranteed to
work and, in fact, probably won't.
-
+
@see wxHandleFatalExceptions()
*/
- void OnFatalException();
+ virtual void OnFatalException();
/**
This must be provided by the application, and will usually create the
Return @true to continue processing, @false to exit the application
immediately.
*/
- bool OnInit();
+ virtual bool OnInit();
/**
Called from OnInit() and may be used to initialize the parser with the
command line options for this application. The base class versions adds
support for a few standard options only.
*/
- void OnInitCmdLine(wxCmdLineParser& parser);
+ virtual void OnInitCmdLine(wxCmdLineParser& parser);
/**
This virtual function is where the execution of a program written in wxWidgets
/**
Returns @true if unprocessed events are in the window system event queue.
-
+
@see Dispatch()
*/
virtual bool Pending();
- /**
- 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:
-
- @code
- // Provide wxWidgets message loop compatibility
- BOOL CTheApp::PreTranslateMessage(MSG *msg)
- {
- if (wxTheApp && wxTheApp->ProcessMessage((WXMSW *)msg))
- return true;
- else
- return CWinApp::PreTranslateMessage(msg);
- }
- @endcode
- */
- bool ProcessMessage(WXMSG* msg);
-
- /**
- Sends idle events to a window and its children.
- Please note that this function is internal to wxWidgets and shouldn't be used
- by user code.
-
- @remarks These functions poll the top-level windows, and their children,
- for idle event processing. If @true is returned, more OnIdle
- processing is requested by one or more window.
-
- @see wxIdleEvent
- */
- bool SendIdleEvents(wxWindow* win, wxIdleEvent& event);
-
/**
Set the application name to be used in the user-visible places such as window
titles. See GetAppDisplayName() for more about the differences between the
SetAppDisplayName() is used instead.
By default the application name is set to the name of its executable file.
-
+
@see GetAppName()
*/
void SetAppName(const wxString& name);
/**
Sets the class name of the application. This may be used in a platform specific
manner to refer to the application.
-
+
@see GetClassName()
*/
void SetClassName(const wxString& name);
- /**
- Allows the programmer to specify whether the application will exit when the
- top-level frame is deleted.
-
- @param flag
- If @true (the default), the application will exit when the top-level frame
- is deleted. If @false, the application will continue to run.
-
- @see GetExitOnFrameDelete(), @ref overview_app_shutdown
- */
- void SetExitOnFrameDelete(bool flag);
-
/**
Allows external code to modify global ::wxTheApp, but you should really
know what you're doing if you call it.
-
+
@param app
Replacement for the global application object.
-
+
@see GetInstance()
*/
static void SetInstance(wxAppConsole* app);
- /**
- Allows runtime switching of the UI environment theme.
-
- Currently implemented for wxGTK2-only.
- Return @true if theme was successfully changed.
-
- @param theme
- The name of the new theme or an absolute path to a gtkrc-theme-file
- */
- bool SetNativeTheme(const wxString& theme);
-
- /**
- 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 in its top-level window
- list, when it needs to use the top window.
-
- @param window
- The new top window.
-
- @see GetTopWindow(), OnInit()
- */
- void SetTopWindow(wxWindow* window);
-
- /**
- 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.
-
- @param flag
- If @true, the app will use the best visual.
- @param forceTrueColour
- If @true then the application will try to force using a TrueColour
- visual and abort the app if none is found.
- */
- void SetUseBestVisual(bool flag, bool forceTrueColour = false);
-
/**
Set the vendor name to be used in the user-visible places.
See GetVendorDisplayName() for more about the differences between the
/**
Sets the name of application's vendor. The name will be used
in registry access. A default name is set by wxWidgets.
-
+
@see GetVendorName()
*/
void SetVendorName(const wxString& name);
@a onlyIfNeeded parameter is @true, the method will just silently
return @false instead.
*/
- bool Yield(bool onlyIfNeeded = false);
+ virtual bool Yield(bool onlyIfNeeded = false);
/**
Number of command line arguments (after environment-specific processing).
-// ============================================================================
-// Global functions/macros
-// ============================================================================
/**
- The global pointer to the singleton wxApp object.
+ @class wxApp
+ @wxheader{app.h}
- @see wxApp::GetInstance()
+ The wxApp class represents the application itself. It is used to:
+
+ @li set and get application-wide properties;
+ @li implement the windowing system message or event loop;
+ @li initiate application processing via wxApp::OnInit;
+ @li allow default processing of events not handled by other
+ objects in the application.
+
+ You should use the macro IMPLEMENT_APP(appClass) in your application
+ implementation file to tell wxWidgets how to create an instance of your
+ application class.
+
+ Use DECLARE_APP(appClass) in a header file if you want the wxGetApp function
+ (which returns a reference to your application object) to be visible to other
+ files.
+
+ @library{wxbase}
+ @category{appmanagement}
+
+ @see @ref overview_app
*/
-wxApp *wxTheApp;
+class wxApp : public wxAppConsole
+{
+public:
+ /**
+ Constructor. Called implicitly with a definition of a wxApp object.
+ */
+ wxApp();
+
+ /**
+ Destructor. Will be called implicitly on program exit if the wxApp
+ object is created on the stack.
+ */
+ virtual ~wxApp();
+
+ /**
+ Returns @true if the application will exit when the top-level frame is deleted.
+ @see SetExitOnFrameDelete()
+ */
+ bool GetExitOnFrameDelete() const;
+
+ /**
+ Returns @true if the application will use the best visual on systems that support
+ different visuals, @false otherwise.
+
+ @see SetUseBestVisual()
+ */
+ bool GetUseBestVisual() const;
+
+ /**
+ Returns a pointer to the top window.
+
+ @remarks If the top window hasn't been set using SetTopWindow(),
+ this function will find the first top-level window
+ (frame or dialog) and return that.
+
+ @see SetTopWindow()
+ */
+ virtual wxWindow* GetTopWindow() const;
+
+ /**
+ 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 bool IsActive() const;
+
+ /**
+ 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:
+
+ @code
+ // Provide wxWidgets message loop compatibility
+ BOOL CTheApp::PreTranslateMessage(MSG *msg)
+ {
+ if (wxTheApp && wxTheApp->ProcessMessage((WXMSW *)msg))
+ return true;
+ else
+ return CWinApp::PreTranslateMessage(msg);
+ }
+ @endcode
+ */
+ bool ProcessMessage(WXMSG* msg);
+
+ /**
+ Sends idle events to a window and its children.
+ Please note that this function is internal to wxWidgets and shouldn't be used
+ by user code.
+
+ @remarks These functions poll the top-level windows, and their children,
+ for idle event processing. If @true is returned, more OnIdle
+ processing is requested by one or more window.
+
+ @see wxIdleEvent
+ */
+ virtual bool SendIdleEvents(wxWindow* win, wxIdleEvent& event);
+
+ /**
+ Allows the programmer to specify whether the application will exit when the
+ top-level frame is deleted.
+
+ @param flag
+ If @true (the default), the application will exit when the top-level frame
+ is deleted. If @false, the application will continue to run.
+
+ @see GetExitOnFrameDelete(), @ref overview_app_shutdown
+ */
+ void SetExitOnFrameDelete(bool flag);
+
+ /**
+ Allows external code to modify global ::wxTheApp, but you should really
+ know what you're doing if you call it.
+
+ @param app
+ Replacement for the global application object.
+
+ @see GetInstance()
+ */
+ static void SetInstance(wxAppConsole* app);
+
+ /**
+ Allows runtime switching of the UI environment theme.
+
+ Currently implemented for wxGTK2-only.
+ Return @true if theme was successfully changed.
+
+ @param theme
+ The name of the new theme or an absolute path to a gtkrc-theme-file
+ */
+ virtual bool SetNativeTheme(const wxString& theme);
+
+ /**
+ 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 in its top-level window
+ list, when it needs to use the top window.
+
+ @param window
+ The new top window.
+
+ @see GetTopWindow(), OnInit()
+ */
+ void SetTopWindow(wxWindow* window);
+
+ /**
+ 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.
+
+ @param flag
+ If @true, the app will use the best visual.
+ @param forceTrueColour
+ If @true then the application will try to force using a TrueColour
+ visual and abort the app if none is found.
+ */
+ void SetUseBestVisual(bool flag, bool forceTrueColour = false);
+};
+
+
+
+// ============================================================================
+// Global functions/macros
+// ============================================================================
/** @ingroup group_funcmacro_rtti */
+/**
+ The global pointer to the singleton wxApp object.
+
+ @see wxApp::GetInstance()
+*/
+wxApp *wxTheApp;
+
+
+
/** @ingroup group_funcmacro_appinitterm */
//@{
/**
- This function doesn't exist in wxWidgets but it is created by using
- the IMPLEMENT_APP() macro.
+ This function doesn't exist in wxWidgets but it is created by using the
+ IMPLEMENT_APP() macro.
Thus, before using it anywhere but in the same module where this macro is
used, you must make it available using DECLARE_APP().
The advantage of using this function compared to directly using the global
- wxTheApp pointer is that the latter is of type wxApp* and so wouldn't
- allow you to access the functions specific to your application class but not
- present in wxApp while wxGetApp() returns the object of the right type.
+ ::wxTheApp pointer is that the latter is of type wxApp* and so wouldn't
+ allow you to access the functions specific to your application class but
+ not present in wxApp while wxGetApp() returns the object of the right type.
+
+ @header{wx/app.h}
*/
-wxAppDerivedClass wxGetApp();
+wxAppDerivedClass& wxGetApp();
/**
If @a doIt is @true, the fatal exceptions (also known as general protection
faults under Windows or segmentation violations in the Unix world) will be
caught and passed to wxApp::OnFatalException.
- By default, i.e. before this function is called, they will be handled in the
- normal way which usually just means that the application will be terminated.
- Calling wxHandleFatalExceptions() with @a doIt equal to @false will restore
- this default behaviour.
+ By default, i.e. before this function is called, they will be handled in
+ the normal way which usually just means that the application will be
+ terminated. Calling wxHandleFatalExceptions() with @a doIt equal to @false
+ will restore this default behaviour.
+
+ Notice that this function is only available if @c wxUSE_ON_FATAL_EXCEPTION
+ is 1 and under Windows platform this requires a compiler with support for
+ SEH (structured exception handling) which currently means only Microsoft
+ Visual C++ or a recent Borland C++ version.
- Notice that this function is only available if @c wxUSE_ON_FATAL_EXCEPTION is 1
- and under Windows platform this requires a compiler with support for SEH
- (structured exception handling) which currently means only Microsoft Visual C++
- or a recent Borland C++ version.
+ @header{wx/app.h}
*/
bool wxHandleFatalExceptions(bool doIt = true);
-
/**
This function is used in wxBase only and only if you don't create
wxApp object at all. In this case you must call it from your
This function may be called several times but wxUninitialize() must be
called for each successful call to this function.
+
+ @header{wx/app.h}
*/
bool wxInitialize();
/**
This function is for use in console (wxBase) programs only. It must be called
once for each previous successful call to wxInitialize().
+
+ @header{wx/app.h}
*/
void wxUninitialize();
+/**
+ This function wakes up the (internal and platform dependent) idle system,
+ i.e. it will force the system to send an idle event even if the system
+ currently @e is idle and thus would not send any idle event until after
+ some other event would get sent. This is also useful for sending events
+ between two threads and is used by the corresponding functions
+ wxPostEvent() and wxEvtHandler::AddPendingEvent().
+
+ @header{wx/app.h}
+*/
+void wxWakeUpIdle();
+
/**
Calls wxApp::Yield.
@deprecated
This function is kept only for backwards compatibility. Please use
the wxApp::Yield method instead in any new code.
+
+ @header{wx/app.h}
*/
bool wxYield();
afterwards. If @a win is not @NULL, this window will remain enabled,
allowing the implementation of some limited user interaction.
Returns the result of the call to ::wxYield.
+
+ @header{wx/app.h}
*/
bool wxSafeYield(wxWindow* win = NULL, bool onlyIfNeeded = false);
@note This overload of wxEntry is available under all platforms.
@see wxEntryStart()
+
+ @header{wx/app.h}
*/
int wxEntry(int& argc, wxChar** argv);
// OnExit isn't called by CleanUp so must be called explicitly.
wxTheApp->OnExit();
wxApp::CleanUp();
-
+
return CWinApp::ExitInstance();
}
@endcode
+ @header{wx/app.h}
*/
int wxEntry(HINSTANCE hInstance,
HINSTANCE hPrevInstance = NULL,
Should only be used in an emergency: normally the top-level frame
should be deleted (after deleting all other frames) to terminate the
application. See wxCloseEvent and wxApp.
+
+ @header{wx/app.h}
*/
void wxExit();