Code::Blocks  SVN r11506
editor_hooks.h
Go to the documentation of this file.
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 EDITOR_HOOKS_H
7 #define EDITOR_HOOKS_H
8 
9 #include "settings.h"
10 
11 //uncomment the below line if you want to do the hook performance measure
12 //#define EDITOR_HOOK_PERFORMANCE_MEASURE
13 
14 #ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
15  #include <typeinfo> // typeid
16 #endif // EDITOR_HOOK_PERFORMANCE_MEASURE
17 
18 class cbEditor;
20 class wxScintillaEvent;
21 
23 namespace EditorHooks
24 {
27  {
28  public:
29  virtual ~HookFunctorBase(){}
30  virtual void Call(cbEditor*, wxScintillaEvent&) const = 0;
31 
32 #ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
33  virtual const char* GetTypeName() const = 0;
34 #endif // EDITOR_HOOK_PERFORMANCE_MEASURE
35 
36  };
37 
52  template<class T> class HookFunctor : public HookFunctorBase
53  {
54  public:
55  typedef void (T::*Func)(cbEditor*, wxScintillaEvent&);
56  HookFunctor(T* obj, Func func) : m_pObj(obj), m_pFunc(func)
57  { ; }
58  void Call(cbEditor* editor, wxScintillaEvent& event) const override
59  {
60  if (m_pObj && m_pFunc)
61  (m_pObj->*m_pFunc)(editor, event);
62  }
63 
64 #ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
65 
66  virtual const char* GetTypeName() const
67  {
68  return typeid(m_pFunc).name();
69  }
70 #endif // EDITOR_HOOK_PERFORMANCE_MEASURE
71 
72  protected:
73  T* m_pObj;
74  Func m_pFunc;
75  };
76 
81  extern DLLIMPORT int RegisterHook(HookFunctorBase* functor);
88  extern DLLIMPORT HookFunctorBase* UnregisterHook(int id, bool deleteHook = true);
92  extern DLLIMPORT bool HasRegisteredHooks();
98  extern DLLIMPORT void CallHooks(cbEditor* editor, wxScintillaEvent& event);
99 
104  {
105  public:
114  void Call(cbEditor* editor, wxScintillaEvent& event) const override;
115 
116 #ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
117  virtual const char* GetTypeName() const
118  {
119  return typeid(m_plugin).name();
120  }
121 #endif // EDITOR_HOOK_PERFORMANCE_MEASURE
122 
123  private:
125  };
126 }
127 
128 #endif // EDITOR_HOOKS_H
Provides static functions to add hooks to the editor modification operations.
Definition: editor_hooks.h:23
DLLIMPORT bool HasRegisteredHooks()
Are there any hooks registered?
#define DLLIMPORT
Definition: settings.h:16
const SQChar * GetTypeName(const SQObjectPtr &obj1)
Definition: sqobject.cpp:43
HookFunctor(T *obj, Func func)
Definition: editor_hooks.h:56
Functor class for use as a editor modification operations hook.
Definition: editor_hooks.h:52
Abstract base hook functor interface.
Definition: editor_hooks.h:26
A file editor.
Definition: cbeditor.h:43
void Call(cbEditor *editor, wxScintillaEvent &event) const override
Definition: editor_hooks.h:58
DLLIMPORT HookFunctorBase * UnregisterHook(int id, bool deleteHook=true)
Unregister a previously registered project loading/saving hook.
Provides a HookFunctor which redirects the Call() of a cbSmartIndentPlugin so only the interface of c...
Definition: editor_hooks.h:103
DLLIMPORT void CallHooks(cbEditor *editor, wxScintillaEvent &event)
Call all registered hooks using the supplied parameters.
DLLIMPORT int RegisterHook(HookFunctorBase *functor)
Register a project loading/saving hook.