2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: module.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxModule
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxModule
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The module system is a very simple mechanism to allow applications (and parts
|
|
|
|
of wxWidgets itself) to define initialization and cleanup functions that are
|
|
|
|
automatically called on wxWidgets startup and exit.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
To define a new kind of module, derive a class from wxModule, override the
|
2008-10-11 13:10:48 +00:00
|
|
|
wxModule::OnInit and wxModule::OnExit functions, and add the
|
2010-06-09 13:55:48 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation
|
2008-10-11 13:10:48 +00:00
|
|
|
files (which can be the same file).
|
|
|
|
On initialization, wxWidgets will find all classes derived from wxModule, create
|
|
|
|
an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets
|
|
|
|
will call the wxModule::OnExit function for each module instance.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Note that your module class does not have to be in a header file.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
For example:
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@code
|
2008-10-11 13:10:48 +00:00
|
|
|
// A module to allow DDE initialization/cleanup
|
2008-03-08 13:52:38 +00:00
|
|
|
// without calling these functions from app.cpp or from
|
|
|
|
// the user's application.
|
|
|
|
class wxDDEModule: public wxModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDDEModule() { }
|
2008-07-02 14:45:57 +00:00
|
|
|
virtual bool OnInit() { wxDDEInitialize(); return true; };
|
2008-03-08 13:52:38 +00:00
|
|
|
virtual void OnExit() { wxDDECleanUp(); };
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
private:
|
2010-06-09 13:55:48 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2010-06-09 13:55:48 +00:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule);
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
// Another module which uses DDE in its OnInit()
|
|
|
|
class MyModule: public wxModule
|
|
|
|
{
|
|
|
|
public:
|
2010-06-09 13:55:48 +00:00
|
|
|
MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
|
2008-03-08 13:52:38 +00:00
|
|
|
virtual bool OnInit() { ... code using DDE ... }
|
|
|
|
virtual void OnExit() { ... }
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
private:
|
2010-06-09 13:55:48 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(MyModule);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2010-06-09 13:55:48 +00:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule);
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
// Another module which uses DDE in its OnInit()
|
|
|
|
// but uses a named dependency
|
|
|
|
class MyModule2: public wxModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyModule2() { AddDependency("wxDDEModule"); }
|
|
|
|
virtual bool OnInit() { ... code using DDE ... }
|
|
|
|
virtual void OnExit() { ... }
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
private:
|
2010-06-09 13:55:48 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(MyModule2)
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2010-06-09 13:55:48 +00:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
|
2008-03-08 13:52:38 +00:00
|
|
|
@endcode
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2009-02-20 11:34:52 +00:00
|
|
|
@category{appmanagement}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxModule : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructs a wxModule object.
|
|
|
|
*/
|
|
|
|
wxModule();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxModule();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-10-29 18:55:57 +00:00
|
|
|
/**
|
|
|
|
Provide this function with appropriate cleanup for your module.
|
|
|
|
*/
|
|
|
|
virtual void OnExit() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Provide this function with appropriate initialization for your module.
|
|
|
|
If the function returns @false, wxWidgets will exit immediately.
|
|
|
|
*/
|
|
|
|
virtual bool OnInit() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Call this function from the constructor of the derived class.
|
|
|
|
|
2010-06-09 13:55:48 +00:00
|
|
|
@a dep must be the wxCLASSINFO() of a wxModule-derived class and the
|
2008-10-11 13:10:48 +00:00
|
|
|
corresponding module will be loaded before and unloaded after this module.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param dep
|
2008-03-09 12:33:59 +00:00
|
|
|
The class information object for the dependent module.
|
2008-10-11 13:10:48 +00:00
|
|
|
*/
|
|
|
|
void AddDependency(wxClassInfo* dep);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Call this function from the constructor of the derived class.
|
|
|
|
|
|
|
|
This overload allows a dependency to be added by name without access to
|
|
|
|
the class info.
|
|
|
|
|
|
|
|
This is useful when a module is declared entirely in a source file and
|
2010-06-09 13:55:48 +00:00
|
|
|
there is no header for the declaration of the module needed by wxCLASSINFO(),
|
2008-10-11 13:10:48 +00:00
|
|
|
however errors are not detected until run-time, instead of compile-time, then.
|
|
|
|
Note that circular dependencies are detected and result in a fatal error.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param classname
|
2008-03-09 12:33:59 +00:00
|
|
|
The class name of the dependent module.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void AddDependency(const char* classname);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|