File: module.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (130 lines) | stat: -rw-r--r-- 4,075 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/////////////////////////////////////////////////////////////////////////////
// Name:        module.h
// Purpose:     interface of wxModule
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @class wxModule

    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.

    To define a new kind of module, derive a class from wxModule, override the
    wxModule::OnInit and wxModule::OnExit functions, and add the
    wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation
    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.

    Note that your module class does not have to be in a header file.

    For example:

    @code
        // A module to allow DDE initialization/cleanup
      // without calling these functions from app.cpp or from
      // the user's application.
      class wxDDEModule: public wxModule
      {
      public:
          wxDDEModule() { }
          virtual bool OnInit() { wxDDEInitialize(); return true; };
          virtual void OnExit() { wxDDECleanUp(); };

      private:
          wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
      };

      wxIMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule);

      // Another module which uses DDE in its OnInit()
      class MyModule: public wxModule
      {
      public:
          MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
          virtual bool OnInit() { ... code using DDE ... }
          virtual void OnExit() { ... }

      private:
          wxDECLARE_DYNAMIC_CLASS(MyModule);
      };

      wxIMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule);

      // 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() { ... }

      private:
          wxDECLARE_DYNAMIC_CLASS(MyModule2)
      };

      wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)
    @endcode

    @library{wxbase}
    @category{appmanagement}
*/
class wxModule : public wxObject
{
public:
    /**
        Constructs a wxModule object.
    */
    wxModule();

    /**
        Destructor.
    */
    virtual ~wxModule();

    /**
        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:

    /**
        Call this function from the constructor of the derived class.

        @a dep must be the wxCLASSINFO() of a wxModule-derived class and the
        corresponding module will be loaded before and unloaded after this module.

        @param dep
            The class information object for the dependent module.
    */
    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
        there is no header for the declaration of the module needed by wxCLASSINFO(),
        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.

        @param classname
            The class name of the dependent module.
    */
    void AddDependency(const char* classname);
};