~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/manager.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 
3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 
4
 */
 
5
 
 
6
#ifndef MANAGER_H
 
7
#define MANAGER_H
 
8
 
 
9
#include <map>
 
10
#include <vector>
 
11
 
 
12
#ifndef WX_PRECOMP
 
13
#   ifdef __WXMSW__
 
14
#       include <wx/msw/wrapwin.h>  // Needed to prevent Yield define bug.
 
15
#   endif
 
16
#endif
 
17
#include <wx/event.h>
 
18
#include <wx/cmdline.h>
 
19
#include "settings.h"
 
20
#include "sdk_events.h"
 
21
#include "cbfunctor.h"
 
22
 
 
23
// forward decls
 
24
class wxFrame;
 
25
class wxWindow;
 
26
class ProjectManager;
 
27
class EditorManager;
 
28
class LogManager;
 
29
class PluginManager;
 
30
class ToolsManager;
 
31
class MacrosManager;
 
32
class PersonalityManager;
 
33
class wxMenu;
 
34
class wxMenuBar;
 
35
class wxToolBar;
 
36
class UserVariableManager;
 
37
class ScriptingManager;
 
38
class ConfigManager;
 
39
class FileManager;
 
40
 
 
41
 
 
42
class DLLIMPORT Manager
 
43
{
 
44
    void OnMenu(wxCommandEvent& event);
 
45
    wxFrame* m_pAppWindow;
 
46
    static bool appShuttingDown;
 
47
    static bool blockYields;
 
48
    static bool isBatch;
 
49
    static wxCmdLineParser m_CmdLineParser;
 
50
 
 
51
    Manager();
 
52
    ~Manager();
 
53
 
 
54
public:
 
55
    static void SetBatchBuild(bool is_batch);
 
56
    static bool IsBatchBuild(){ return isBatch; }
 
57
    /// Blocks/unblocks Manager::Yield(). Be carefull when using it. Actually, do *not* use it ;)
 
58
    static void BlockYields(bool block);
 
59
    /// Whenever you need to call wxYield(), call Manager::Yield(). It's safer.
 
60
    static void Yield();
 
61
    static void ProcessPendingEvents();
 
62
    static void Shutdown();
 
63
 
 
64
    bool ProcessEvent(CodeBlocksEvent& event);
 
65
    bool ProcessEvent(CodeBlocksDockEvent& event);
 
66
    bool ProcessEvent(CodeBlocksLayoutEvent& event);
 
67
    bool ProcessEvent(CodeBlocksLogEvent& event);
 
68
 
 
69
 
 
70
    /** Use Manager::Get() to get a pointer to its instance
 
71
     * Manager::Get() is guaranteed to never return an invalid pointer.
 
72
     */
 
73
    static Manager* Get();
 
74
    /** Never, EVER, call this function! It is the last function called on shutdown.... */
 
75
    static void Free();
 
76
 
 
77
    wxFrame* GetAppFrame() const;
 
78
    wxWindow* GetAppWindow() const;
 
79
 
 
80
    static bool IsAppShuttingDown();
 
81
    static bool isappShuttingDown(){return Manager::IsAppShuttingDown();};
 
82
 
 
83
    /** Functions returning pointers to the respective sub-manager instances.
 
84
     * During application startup as well as during runtime, these functions will always return a valid pointer.
 
85
     * During application shutdown, these functions will continue to return a valid pointer until the requested manager shuts down.
 
86
     * From that point, the below functions will return null. If there is any chance that your code might execute
 
87
     * during application shutdown, you MUST check for a null pointer.
 
88
     * The one notable exception to this rule is ConfigManager, which has the same lifetime as Manager itself.
 
89
     *
 
90
     * The order of destruction is:
 
91
     * ----------------------------
 
92
     *   ToolsManager,       TemplateManager, PluginManager,
 
93
         *   ScriptingManager,   ProjectManager,  EditorManager,
 
94
         *   PersonalityManager, MacrosManager,   UserVariableManager,
 
95
         *   LogManager
 
96
         *   The ConfigManager is destroyed immediately before the applicaton terminates, so it can be
 
97
         *   considered being omnipresent.
 
98
     *
 
99
     * For plugin developers, this means that most managers (except for the ones you probably don't use anyway)
 
100
     * will be available throughout the entire lifetime of your plugins.
 
101
     */
 
102
 
 
103
    ProjectManager* GetProjectManager() const;
 
104
    EditorManager* GetEditorManager() const;
 
105
    LogManager* GetLogManager() const;
 
106
    PluginManager* GetPluginManager() const;
 
107
    ToolsManager* GetToolsManager() const;
 
108
    MacrosManager* GetMacrosManager() const;
 
109
    PersonalityManager* GetPersonalityManager() const;
 
110
    UserVariableManager* GetUserVariableManager() const;
 
111
    ScriptingManager* GetScriptingManager() const;
 
112
    ConfigManager* GetConfigManager(const wxString& name_space) const;
 
113
    FileManager* GetFileManager() const;
 
114
 
 
115
 
 
116
 
 
117
    /////// XML Resource functions ///////
 
118
    /// Inits XML Resource system
 
119
    static void Initxrc(bool force=false);
 
120
    /// Loads XRC file(s) using data_path
 
121
    static void Loadxrc(wxString relpath);
 
122
    static bool LoadResource(const wxString& file);
 
123
 
 
124
    /// Loads Menubar from XRC
 
125
    static wxMenuBar* LoadMenuBar(wxString resid,bool createonfailure=false);
 
126
    /// Loads Menu from XRC
 
127
    static wxMenu* LoadMenu(wxString menu_id,bool createonfailure=false);
 
128
    /// Loads ToolBar from XRC
 
129
    static wxToolBar *LoadToolBar(wxFrame *parent,wxString resid,bool defaultsmall=true);
 
130
    /// Loads ToolBarAddOn from XRC into existing Toolbar
 
131
 
 
132
    // Do not use this, use Get()
 
133
    static Manager* Get(wxFrame* appWindow);
 
134
 
 
135
    static void AddonToolBar(wxToolBar* toolBar,wxString resid);
 
136
    static bool isToolBar16x16(wxToolBar* toolBar);
 
137
 
 
138
    static wxCmdLineParser* GetCmdLineParser();
 
139
 
 
140
        // event sinks
 
141
        void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksEvent>* functor);
 
142
        void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksDockEvent>* functor);
 
143
        void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksLayoutEvent>* functor);
 
144
        void RegisterEventSink(wxEventType eventType, IEventFunctorBase<CodeBlocksLogEvent>* functor);
 
145
        void RemoveAllEventSinksFor(void* owner);
 
146
 
 
147
private:
 
148
        // event sinks
 
149
        typedef std::vector< IEventFunctorBase<CodeBlocksEvent>* > EventSinksArray;
 
150
        typedef std::map< wxEventType, EventSinksArray > EventSinksMap;
 
151
        typedef std::vector< IEventFunctorBase<CodeBlocksDockEvent>* > DockEventSinksArray;
 
152
        typedef std::map< wxEventType, DockEventSinksArray > DockEventSinksMap;
 
153
        typedef std::vector< IEventFunctorBase<CodeBlocksLayoutEvent>* > LayoutEventSinksArray;
 
154
        typedef std::map< wxEventType, LayoutEventSinksArray > LayoutEventSinksMap;
 
155
        typedef std::vector< IEventFunctorBase<CodeBlocksLogEvent>* > LogEventSinksArray;
 
156
        typedef std::map< wxEventType, LogEventSinksArray > LogEventSinksMap;
 
157
 
 
158
        EventSinksMap m_EventSinks;
 
159
        DockEventSinksMap m_DockEventSinks;
 
160
        LayoutEventSinksMap m_LayoutEventSinks;
 
161
        LogEventSinksMap m_LogEventSinks;
 
162
};
 
163
 
 
164
template <class MgrT> class Mgr
 
165
{
 
166
    static MgrT *instance;
 
167
    static bool isShutdown;
 
168
    explicit Mgr(const Mgr<MgrT>&){};
 
169
    Mgr<MgrT>& operator=(Mgr<MgrT> const&){};
 
170
 
 
171
protected:
 
172
 
 
173
    Mgr(){assert(Mgr<MgrT>::instance == 0);}
 
174
    virtual ~Mgr(){Mgr<MgrT>::instance = 0;}
 
175
 
 
176
public:
 
177
 
 
178
    static inline bool Valid(){return instance;}
 
179
 
 
180
    static inline MgrT* Get()
 
181
    {
 
182
        if(instance == 0 && isShutdown == false)
 
183
            instance = new MgrT();
 
184
 
 
185
        return instance;
 
186
    }
 
187
 
 
188
    static void Free()
 
189
    {
 
190
        isShutdown = true;
 
191
        delete instance;
 
192
        instance = 0;
 
193
    }
 
194
};
 
195
 
 
196
#endif // MANAGER_H
 
197