00001 00002 // Name: ax_module.h 00003 // Purpose: AxModule: a self-contained unit of functionality. 00004 // Implement a new module to tell the framework how to e.g. 00005 // scan for files of a particular kind. 00006 // Author: Julian Smart 00007 // Modified by: 00008 // Created: 2009-03-25 00009 // RCS-ID: $Id$ 00010 // Copyright: (c) Julian Smart 00011 // Licence: New BSD License 00013 00014 #ifndef _AX_AXMODULE_H_ 00015 #define _AX_AXMODULE_H_ 00016 00017 #include "wx/config.h" 00018 00019 #include "ax_resource/ax_resource.h" 00020 00021 class AxActivator; 00022 00023 // declare a linked list of modules 00024 class AxModule; 00025 WX_DECLARE_EXPORTED_LIST(AxModule, AxModuleList); 00026 00027 // Priority symbols 00028 #define axHIGHEST_PRIORITY 100 00029 #define axHIGH_PRIORITY 80 00030 #define axMEDIUM_PRIORITY 50 00031 #define axLOW_PRIORITY 20 00032 #define axLOWEST_PRIORITY 0 00033 00034 class AxResourceLibrary; 00035 00049 class AxModule: public wxEvtHandler 00050 { 00051 DECLARE_CLASS(AxModule) 00052 00053 public: 00055 AxModule(); 00056 00058 ~AxModule() {} 00059 00060 // Overridables 00061 00063 virtual bool OnInit() = 0; 00064 00066 virtual bool OnInitUI() = 0; 00067 00070 virtual void OnExit() = 0; 00071 00073 virtual bool LoadConfig(wxConfigBase& WXUNUSED(config)) { return true; } 00074 00076 virtual bool SaveConfig(wxConfigBase& WXUNUSED(config)) { return true; } 00077 00078 // Called just before the frame is closed. Return false vetoes 00079 // the frame/app close. 00080 virtual bool OnCloseMainWindow() { return true; } 00081 00082 // Allows app to search amongst its own objects. Call AxResourceLibrary::AddSearchItem 00083 // for each item. 00084 virtual bool OnSearch(const wxString& WXUNUSED(searchString), int WXUNUSED(flags), AxResourceLibrary* WXUNUSED(library)) { return false; } 00085 00087 virtual bool IsFileSupported(const wxString& WXUNUSED(filename)) { return false; } 00088 00090 virtual AxResource* LoadResource(const wxString& WXUNUSED(filename)) { return false; } 00091 00094 virtual bool AggregateFiles(AxResourceLibrary* WXUNUSED(library), wxArrayString& WXUNUSED(files), bool WXUNUSED(checkIfFileLoaded)) { return false; } 00095 00097 virtual AxActivator* CreateActivator(AxResourceLibrary* WXUNUSED(library), AxResource* WXUNUSED(resource)) { return NULL; } 00098 00100 00101 // Operations 00102 00104 static AxModule* FindModule(wxClassInfo* info); 00105 00106 // Implementation 00107 00108 bool Init(AxResourceLibrary* library) { m_library = library; return OnInit(); } 00109 void Exit() { OnExit(); } 00110 static void RegisterModule(AxModule* module); 00111 static void RegisterModules(); 00112 static bool InitializeModules(AxResourceLibrary* library); 00113 static void CleanUpModules(); 00114 static void UnregisterModule(AxModule* module); 00115 static AxModuleList& GetModules() { return m_modules; } 00116 00117 // Accessors 00118 00120 void SetPriority(int priority) { m_priority = priority; } 00121 int GetPriority() { return m_priority; } 00122 00123 AxResourceLibrary* GetLibrary() const { return m_library; } 00124 void SetLibrary(AxResourceLibrary* library) { m_library = library; } 00125 00126 protected: 00127 static AxModuleList m_modules; 00128 00129 int m_priority; 00130 AxResourceLibrary* m_library; 00131 }; 00132 00133 #endif 00134 // _AX_AXMODULE_H_ 00135