Menu

[r13158]: / trunk / src / sdk / editor_hooks.cpp  Maximize  Restore  History

Download this file

161 lines (138 with data), 6.1 kB

  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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include "cbeditor.h"
#include "cbplugin.h"
#endif
#include "editor_hooks.h"
#ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
//put these include directive after #include "editor_hooks.h", as the macro may
//defined in the header file
#include <cxxabi.h> // demangle C++ names
#include <cstdlib> // free the memory created by abi::__cxa_demangle
#endif // EDITOR_HOOK_PERFORMANCE_MEASURE
#include "wx/wxscintilla.h"
#include <map>
#ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
// this function is only used in performance hook
static wxString GetScintillaEventName(wxEventType type)
{
wxString name;
if (type == wxEVT_SCI_CHANGE) name = _T("wxEVT_SCI_CHANGE");
else if (type == wxEVT_SCI_STYLENEEDED) name = _T("wxEVT_SCI_STYLENEEDED");
else if (type == wxEVT_SCI_CHARADDED) name = _T("wxEVT_SCI_CHARADDED");
else if (type == wxEVT_SCI_SAVEPOINTREACHED) name = _T("wxEVT_SCI_SAVEPOINTREACHED");
else if (type == wxEVT_SCI_SAVEPOINTLEFT) name = _T("wxEVT_SCI_SAVEPOINTLEFT");
else if (type == wxEVT_SCI_ROMODIFYATTEMPT) name = _T("wxEVT_SCI_ROMODIFYATTEMPT");
else if (type == wxEVT_SCI_KEY) name = _T("wxEVT_SCI_KEY");
else if (type == wxEVT_SCI_DOUBLECLICK) name = _T("wxEVT_SCI_DOUBLECLICK");
else if (type == wxEVT_SCI_UPDATEUI) name = _T("wxEVT_SCI_UPDATEUI");
else if (type == wxEVT_SCI_MODIFIED) name = _T("wxEVT_SCI_MODIFIED");
else if (type == wxEVT_SCI_MACRORECORD) name = _T("wxEVT_SCI_MACRORECORD");
else if (type == wxEVT_SCI_MARGINCLICK) name = _T("wxEVT_SCI_MARGINCLICK");
else if (type == wxEVT_SCI_NEEDSHOWN) name = _T("wxEVT_SCI_NEEDSHOWN");
else if (type == wxEVT_SCI_PAINTED) name = _T("wxEVT_SCI_PAINTED");
else if (type == wxEVT_SCI_USERLISTSELECTION) name = _T("wxEVT_SCI_USERLISTSELECTION");
else if (type == wxEVT_SCI_URIDROPPED) name = _T("wxEVT_SCI_URIDROPPED");
else if (type == wxEVT_SCI_DWELLSTART) name = _T("wxEVT_SCI_DWELLSTART");
else if (type == wxEVT_SCI_DWELLEND) name = _T("wxEVT_SCI_DWELLEND");
else if (type == wxEVT_SCI_START_DRAG) name = _T("wxEVT_SCI_START_DRAG");
else if (type == wxEVT_SCI_DRAG_OVER) name = _T("wxEVT_SCI_DRAG_OVER");
else if (type == wxEVT_SCI_DO_DROP) name = _T("wxEVT_SCI_DO_DROP");
else if (type == wxEVT_SCI_ZOOM) name = _T("wxEVT_SCI_ZOOM");
else if (type == wxEVT_SCI_HOTSPOT_CLICK) name = _T("wxEVT_SCI_HOTSPOT_CLICK");
else if (type == wxEVT_SCI_HOTSPOT_DCLICK) name = _T("wxEVT_SCI_HOTSPOT_DCLICK");
else if (type == wxEVT_SCI_CALLTIP_CLICK) name = _T("wxEVT_SCI_CALLTIP_CLICK");
else if (type == wxEVT_SCI_AUTOCOMP_SELECTION) name = _T("wxEVT_SCI_AUTOCOMP_SELECTION");
else if (type == wxEVT_SCI_INDICATOR_CLICK) name = _T("wxEVT_SCI_INDICATOR_CLICK");
else if (type == wxEVT_SCI_INDICATOR_RELEASE) name = _T("wxEVT_SCI_INDICATOR_RELEASE");
else name = _T("unknown wxEVT_SCI_EVENT");
return name;
}
#endif // EDITOR_HOOK_PERFORMANCE_MEASURE
namespace EditorHooks
{
typedef std::map<int, HookFunctorBase*> HookFunctorsMap;
static HookFunctorsMap s_HookFunctorsMap;
static int s_UniqueID = 0;
}
int EditorHooks::RegisterHook(EditorHooks::HookFunctorBase* functor)
{
for (HookFunctorsMap::iterator it = s_HookFunctorsMap.begin(); it != s_HookFunctorsMap.end(); ++it)
{
if (it->second == functor)
return it->first;
}
s_HookFunctorsMap[s_UniqueID] = functor;
return s_UniqueID++;
}
EditorHooks::HookFunctorBase* EditorHooks::UnregisterHook(int id, bool deleteHook)
{
HookFunctorsMap::iterator it = s_HookFunctorsMap.find(id);
if (it != s_HookFunctorsMap.end())
{
EditorHooks::HookFunctorBase* functor = it->second;
s_HookFunctorsMap.erase(it);
if (deleteHook)
{
delete functor;
return nullptr;
}
return functor;
}
return nullptr;
}
bool EditorHooks::HasRegisteredHooks()
{
return s_HookFunctorsMap.size() != 0;
}
void EditorHooks::CallHooks(cbEditor* editor, wxScintillaEvent& event)
{
for (HookFunctorsMap::iterator it = s_HookFunctorsMap.begin(); it != s_HookFunctorsMap.end(); ++it)
{
EditorHooks::HookFunctorBase* functor = it->second;
if (functor)
{
#ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
wxStopWatch sw;
#endif // EDITOR_HOOK_PERFORMANCE_MEASURE
functor->Call(editor, event);
#ifdef EDITOR_HOOK_PERFORMANCE_MEASURE
if(sw.Time() < 10) // only print a handler run longer than 10 ms
continue;
const char *p = functor->GetTypeName();
int status;
char *realname;
realname = abi::__cxa_demangle(p, nullptr, nullptr, &status);
wxString txt;
// if the demangled C++ function name success, then realname is not nullptr
if (realname != nullptr)
{
txt = wxString::FromUTF8(realname);
free(realname);
}
else
txt = wxString::FromUTF8(p); // show the mangled(original) name
wxEventType type = event.GetEventType();
txt << GetScintillaEventName(type);
Manager::Get()->GetLogManager()->DebugLog(wxString::Format("%s take %ld ms", txt, sw.Time()));
#endif // EDITOR_HOOK_PERFORMANCE_MEASURE
}
}
}
namespace EditorHooks
{
cbSmartIndentEditorHookFunctor::cbSmartIndentEditorHookFunctor(cbSmartIndentPlugin *plugin):
m_plugin(plugin){}
void cbSmartIndentEditorHookFunctor::Call(cbEditor *editor, wxScintillaEvent &event) const
{
m_plugin->OnEditorHook(editor, event);
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.