]> git.saurik.com Git - wxWidgets.git/blame - interface/module.h
GetSocketManager() has no GUI-specific version under Darwin finally
[wxWidgets.git] / interface / module.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: module.h
e54c96f1 3// Purpose: interface of wxModule
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxModule
11 @wxheader{module.h}
7c913512 12
23324ae1
FM
13 The module system is a very simple mechanism to allow applications (and parts
14 of wxWidgets itself) to define initialization and cleanup functions that are
15 automatically called on wxWidgets startup and exit.
7c913512 16
23324ae1 17 To define a new kind of module, derive a class from wxModule, override the
7c913512 18 wxModule::OnInit and wxModule::OnExit
23324ae1
FM
19 functions, and add the DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS to
20 header and implementation files (which can be the same file). On
21 initialization, wxWidgets will find all classes derived from wxModule, create
22 an instance of each, and call each OnInit function. On exit, wxWidgets will
23 call the OnExit function for each module instance.
7c913512 24
23324ae1 25 Note that your module class does not have to be in a header file.
7c913512 26
23324ae1 27 For example:
7c913512 28
23324ae1
FM
29 @code
30 // A module to allow DDE initialization/cleanup
31 // without calling these functions from app.cpp or from
32 // the user's application.
33 class wxDDEModule: public wxModule
34 {
35 public:
36 wxDDEModule() { }
37 virtual bool OnInit() { wxDDEInitialize(); return @true; };
38 virtual void OnExit() { wxDDECleanUp(); };
7c913512 39
23324ae1
FM
40 private:
41 DECLARE_DYNAMIC_CLASS(wxDDEModule)
42 };
7c913512 43
23324ae1 44 IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule)
7c913512 45
23324ae1
FM
46 // Another module which uses DDE in its OnInit()
47 class MyModule: public wxModule
48 {
49 public:
50 MyModule() { AddDependency(CLASSINFO(wxDDEModule)); }
51 virtual bool OnInit() { ... code using DDE ... }
52 virtual void OnExit() { ... }
7c913512 53
23324ae1
FM
54 private:
55 DECLARE_DYNAMIC_CLASS(MyModule)
56 };
7c913512 57
23324ae1 58 IMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule)
7c913512 59
23324ae1
FM
60 // Another module which uses DDE in its OnInit()
61 // but uses a named dependency
62 class MyModule2: public wxModule
63 {
64 public:
65 MyModule2() { AddDependency("wxDDEModule"); }
66 virtual bool OnInit() { ... code using DDE ... }
67 virtual void OnExit() { ... }
7c913512 68
23324ae1
FM
69 private:
70 DECLARE_DYNAMIC_CLASS(MyModule2)
71 };
7c913512 72
23324ae1
FM
73 IMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
74 @endcode
7c913512 75
23324ae1
FM
76 @library{wxbase}
77 @category{FIXME}
78*/
79class wxModule : public wxObject
80{
81public:
82 /**
83 Constructs a wxModule object.
84 */
85 wxModule();
86
87 /**
88 Destructor.
89 */
90 ~wxModule();
91
92 //@{
93 /**
4cc4bfaf 94 Call this function from the constructor of the derived class. @a dep must be
e54c96f1 95 the CLASSINFO() of a wxModule-derived class and the
23324ae1
FM
96 corresponding module will be loaded before and unloaded after
97 this module.
23324ae1
FM
98 The second version of this function allows a dependency to be added by
99 name without access to the class info. This is useful when a module is
100 declared entirely in a source file and there is no header for the declaration
e54c96f1 101 of the module needed by CLASSINFO(), however errors are
23324ae1 102 not detected until run-time, instead of compile-time, then.
23324ae1 103 Note that circular dependencies are detected and result in a fatal error.
3c4f71cc 104
7c913512 105 @param dep
4cc4bfaf 106 The class information object for the dependent module.
7c913512 107 @param classname
4cc4bfaf 108 The class name of the dependent module.
23324ae1 109 */
4cc4bfaf
FM
110 void AddDependency(wxClassInfo* dep);
111 void AddDependency(const char* classname);
23324ae1
FM
112 //@}
113
114 /**
115 Provide this function with appropriate cleanup for your module.
116 */
117 virtual void OnExit();
118
119 /**
120 Provide this function with appropriate initialization for your module. If the
121 function
122 returns @false, wxWidgets will exit immediately.
123 */
124 virtual bool OnInit();
125};
e54c96f1 126