wxAppConsole Class Reference
[Application and Process Management]

#include <wx/app.h>

Inheritance diagram for wxAppConsole:

wxEvtHandler wxObject wxApp

List of all members.


Detailed Description

This class is essential for writing console-only or hybrid apps without having to define wxUSE_GUI=0.

Todo:
MORE INFO
Library:  wxBase

Category:  Application and Process Management

See also:
wxApp Overview

Public Member Functions

virtual ~wxAppConsole ()
virtual bool Dispatch ()
virtual void ExitMainLoop ()
virtual int FilterEvent (wxEvent &event)
wxString GetAppDisplayName () const
wxString GetAppName () const
wxString GetClassName () const
wxAppTraitsGetTraits ()
const wxStringGetVendorDisplayName () const
const wxStringGetVendorName () const
virtual void HandleEvent (wxEvtHandler *handler, wxEventFunction func, wxEvent &event) const
virtual void MacNewFile ()
virtual void MacOpenFile (const wxString &fileName)
virtual void MacOpenURL (const wxString &url)
virtual void MacPrintFile (const wxString &fileName)
virtual void MacReopenApp ()
virtual int MainLoop ()
virtual void OnAssertFailure (const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg)
virtual bool OnCmdLineError (wxCmdLineParser &parser)
virtual bool OnCmdLineHelp (wxCmdLineParser &parser)
virtual bool OnCmdLineParsed (wxCmdLineParser &parser)
virtual bool OnExceptionInMainLoop ()
virtual int OnExit ()
virtual void OnFatalException ()
virtual bool OnInit ()
virtual void OnInitCmdLine (wxCmdLineParser &parser)
virtual int OnRun ()
virtual void OnUnhandledException ()
virtual bool Pending ()
void SetAppDisplayName (const wxString &name)
void SetAppName (const wxString &name)
void SetClassName (const wxString &name)
void SetVendorDisplayName (const wxString &name)
void SetVendorName (const wxString &name)
virtual bool Yield (bool onlyIfNeeded=false)

Static Public Member Functions

static wxAppConsoleGetInstance ()
static bool IsMainLoopRunning ()
static void SetInstance (wxAppConsole *app)

Public Attributes

int argc
wxChar ** argv

Protected Member Functions

virtual wxAppTraitsCreateTraits ()

Constructor & Destructor Documentation

virtual wxAppConsole::~wxAppConsole (  )  [virtual]

Destructor.


Member Function Documentation

virtual wxAppTraits* wxAppConsole::CreateTraits (  )  [protected, virtual]

Creates the wxAppTraits object when GetTraits() needs it for the first time.

See also:
wxAppTraits

virtual bool wxAppConsole::Dispatch (  )  [virtual]

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.

        while (app.Pending())
            Dispatch();

Returns:
false if the event loop should stop and true otherwise.
See also:
Pending()

virtual void wxAppConsole::ExitMainLoop (  )  [virtual]

Call this to explicitly exit the main message (event) loop. You should normally exit the main loop (and the application) by deleting the top window.

virtual int wxAppConsole::FilterEvent ( wxEvent event  )  [virtual]

This function is called before processing any event and allows the application to preempt the processing of some events.

If this method returns -1 the event is processed normally, otherwise either true or false should be returned and the event processing stops immediately 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).

wxString wxAppConsole::GetAppDisplayName (  )  const

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 application name as returned by GetAppName() capitalized using wxString::Capitalize().

Since:
2.9.0

wxString wxAppConsole::GetAppName (  )  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 also:
GetAppDisplayName()

wxString wxAppConsole::GetClassName (  )  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 also:
SetClassName()

static wxAppConsole* wxAppConsole::GetInstance (  )  [static]

Returns the one and only global application object. Usually wxTheApp is used instead.

See also:
SetInstance()

wxAppTraits* wxAppConsole::GetTraits (  ) 

Returns a pointer to the wxAppTraits object for the application. If you want to customize the wxAppTraits object, you must override the CreateTraits() function.

const wxString& wxAppConsole::GetVendorDisplayName (  )  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 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 GetVendorName().

Since:
2.9.0

const wxString& wxAppConsole::GetVendorName (  )  const

Returns the application's vendor name.

virtual void wxAppConsole::HandleEvent ( wxEvtHandler handler,
wxEventFunction  func,
wxEvent event 
) const [virtual]

This function simply invokes the given method func of the specified event handler handler with the event as parameter. It exists solely to allow to catch the C++ exceptions which could be thrown by all event 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.

static bool wxAppConsole::IsMainLoopRunning (  )  [static]

Returns true if the main event loop is currently running, i.e. if the application is inside OnRun().

This can be useful to test whether events can be dispatched. For example, if this function returns false, non-blocking sockets cannot be used because the events from them would never be processed.

virtual void wxAppConsole::MacNewFile (  )  [virtual]

Called in response of an "open-application" Apple event. Override this to create a new document in your app.

Availability:  only available for the wxMac port.

virtual void wxAppConsole::MacOpenFile ( const wxString fileName  )  [virtual]

Called in response of an "open-document" Apple event.

You need to override this method in order to open a document file after the user double clicked on it or if the document file was dropped on either the running application or the application icon in Finder.

Availability:  only available for the wxMac port.

virtual void wxAppConsole::MacOpenURL ( const wxString url  )  [virtual]

Called in response of a "get-url" Apple event.

Availability:  only available for the wxMac port.

virtual void wxAppConsole::MacPrintFile ( const wxString fileName  )  [virtual]

Called in response of a "print-document" Apple event.

Availability:  only available for the wxMac port.

virtual void wxAppConsole::MacReopenApp (  )  [virtual]

Called in response of a "reopen-application" Apple event.

Availability:  only available for the wxMac port.

virtual int wxAppConsole::MainLoop (  )  [virtual]

Called by wxWidgets on creation of the application. Override this if you wish to provide your own (environment-dependent) main loop.

Returns:
0 under X, and the wParam of the WM_QUIT message under Windows.

virtual void wxAppConsole::OnAssertFailure ( const wxChar *  file,
int  line,
const wxChar *  func,
const wxChar *  cond,
const wxChar *  msg 
) [virtual]

This function is called when an assert failure occurs, i.e. the condition specified in wxASSERT() macro evaluated to false.

It is only called in debug mode (when __WXDEBUG__ is defined) as 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.

Parameters:
file the name of the source file where the assert occurred
line the line number in this file where the assert occurred
func the name of the function where the assert occurred, may be empty if the compiler doesn't support C99 __FUNCTION__
cond the condition of the failed assert in text form
msg the message specified as argument to wxASSERT_MSG or wxFAIL_MSG, will be NULL if just wxASSERT or wxFAIL was used

virtual bool wxAppConsole::OnCmdLineError ( wxCmdLineParser parser  )  [virtual]

Called when command line parsing fails (i.e. an incorrect command line option was specified by the user). The default behaviour is to show the program usage text and abort the program.

Return true to continue normal execution or false to return false from OnInit() thus terminating the program.

See also:
OnInitCmdLine()

virtual bool wxAppConsole::OnCmdLineHelp ( wxCmdLineParser parser  )  [virtual]

Called when the help option (--help) was specified on the command line. The default behaviour is to show the program usage text and abort the program.

Return true to continue normal execution or false to return false from OnInit() thus terminating the program.

See also:
OnInitCmdLine()

virtual bool wxAppConsole::OnCmdLineParsed ( wxCmdLineParser parser  )  [virtual]

Called after the command line had been successfully parsed. You may override this method to test for the values of the various parameters which could be set from the command line.

Don't forget to call the base class version unless you want to suppress 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 also:
OnInitCmdLine()

virtual bool wxAppConsole::OnExceptionInMainLoop (  )  [virtual]

This function is called if an unhandled exception occurs inside the main application event loop. It can return true to ignore the exception and to continue running the loop or false to exit the loop and terminate the program. In the latter case it can also use C++ throw keyword to rethrow the current exception.

The default behaviour of this function is the latter in all ports except under Windows where a dialog is shown to the user which allows him to choose between the different options. You may override this function in your class to do something more appropriate.

Finally note that if the exception is rethrown from here, it can be caught in OnUnhandledException().

virtual int wxAppConsole::OnExit (  )  [virtual]

Override this member function for any processing which needs to be done as the application is about to exit. OnExit is called after destroying all application windows and controls, but before wxWidgets cleanup. Note that it is not called at all if OnInit() failed.

The return value of this function is currently ignored, return the same value as returned by the base class method if you override it.

virtual void wxAppConsole::OnFatalException (  )  [virtual]

This function may be called if something fatal happens: an unhandled exception under Win32 or a a fatal signal under Unix, for example. However, this will not happen by default: you have to explicitly call wxHandleFatalExceptions() to enable this.

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 also:
wxHandleFatalExceptions()

virtual bool wxAppConsole::OnInit (  )  [virtual]

This must be provided by the application, and will usually create the application's main window, optionally calling SetTopWindow().

You may use OnExit() to clean up anything initialized here, provided that the function returns true.

Notice that if you want to to use the command line processing provided by wxWidgets you have to call the base class version in the derived class OnInit().

Return true to continue processing, false to exit the application immediately.

virtual void wxAppConsole::OnInitCmdLine ( wxCmdLineParser parser  )  [virtual]

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.

virtual int wxAppConsole::OnRun (  )  [virtual]

This virtual function is where the execution of a program written in wxWidgets starts. The default implementation just enters the main loop and starts handling the events until it terminates, either because ExitMainLoop() has been explicitly called or because the last frame has been deleted and GetExitOnFrameDelete() flag is true (this is the default).

The return value of this function becomes the exit code of the program, so it should return 0 in case of successful termination.

virtual void wxAppConsole::OnUnhandledException (  )  [virtual]

This function is called when an unhandled C++ exception occurs inside OnRun() (the exceptions which occur during the program startup and shutdown might not be caught at all). Notice that by now the main event loop has been terminated and the program will exit, if you want to prevent this from happening (i.e. continue running after catching an exception) you need to override OnExceptionInMainLoop().

The default implementation shows information about the exception in debug build but does nothing in the release build.

virtual bool wxAppConsole::Pending (  )  [virtual]

Returns true if unprocessed events are in the window system event queue.

See also:
Dispatch()

void wxAppConsole::SetAppDisplayName ( const wxString name  ) 

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 display name and name.

Notice that if this function is called, the name is used as is, without any capitalization as done by default by GetAppDisplayName().

void wxAppConsole::SetAppName ( const wxString name  ) 

Sets the name of the application. This name should be used for file names, configuration file entries and other internal strings. For the user-visible strings, such as the window titles, the application display name set by SetAppDisplayName() is used instead.

By default the application name is set to the name of its executable file.

See also:
GetAppName()

void wxAppConsole::SetClassName ( 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 also:
GetClassName()

static void wxAppConsole::SetInstance ( wxAppConsole app  )  [static]

Allows external code to modify global wxTheApp, but you should really know what you're doing if you call it.

Parameters:
app Replacement for the global application object.
See also:
GetInstance()

Reimplemented in wxApp.

void wxAppConsole::SetVendorDisplayName ( const wxString name  ) 

Set the vendor name to be used in the user-visible places. See GetVendorDisplayName() for more about the differences between the display name and name.

void wxAppConsole::SetVendorName ( const wxString name  ) 

Sets the name of application's vendor. The name will be used in registry access. A default name is set by wxWidgets.

See also:
GetVendorName()

virtual bool wxAppConsole::Yield ( bool  onlyIfNeeded = false  )  [virtual]

Yields control to pending messages in the windowing system.

This can be useful, for example, when a time-consuming process writes to a text window. Without an occasional yield, the text window will not be updated properly, and on systems with cooperative multitasking, such as Windows 3.1 other processes will not respond.

Caution should be exercised, however, since yielding may allow the user to perform actions which are not compatible with the current task. Disabling menu items or whole menus during processing can avoid unwanted reentrance of code: see wxSafeYield for a better function.

Note that Yield() will not flush the message logs. This is intentional as calling Yield() is usually done to quickly update the screen and popping up a message box dialog may be undesirable. If you do wish to flush the log messages immediately (otherwise it will be done during the next idle loop iteration), call wxLog::FlushActive.

Calling Yield() recursively is normally an error and an assert failure is raised in debug build if such situation is detected. However if the onlyIfNeeded parameter is true, the method will just silently return false instead.


Member Data Documentation

Number of command line arguments (after environment-specific processing).

Command line arguments (after environment-specific processing).

Under Windows and Linux/Unix, you should parse the command line arguments and check for files to be opened when starting your application. Under OS X, you need to override MacOpenFile() since command line arguments are used differently there.

You may use the wxCmdLineParser to parse command line arguments.



wxWidgets logo

[ top ]