| 1 |
#include "events_database.h" |
| 2 |
|
| 3 |
#include "wxgui_helpers.h" |
| 4 |
|
| 5 |
void ConnectDetails::GenerateFunctionName(const wxString& controlName) |
| 6 |
{ |
| 7 |
wxString member = controlName; |
| 8 |
member.StartsWith("m_", &member); |
| 9 |
member.StartsWith("_", &member); |
| 10 |
|
| 11 |
wxString str = m_eventName; |
| 12 |
str.Replace("wxEVT_", ""); |
| 13 |
|
| 14 |
str = wxCrafter::CamelCase(str); |
| 15 |
wxString camelCaseControlName = wxCrafter::CamelCase(member); |
| 16 |
|
| 17 |
m_functionNameAndSignature.Clear(); |
| 18 |
m_functionNameAndSignature << "On" << camelCaseControlName << str << "(" << m_eventClass << "& event)"; |
| 19 |
} |
| 20 |
|
| 21 |
void ConnectDetails::MakeSignatureForName(const wxString& name) |
| 22 |
{ |
| 23 |
wxString tmpname = name; |
| 24 |
tmpname.Trim().Trim(false); |
| 25 |
if(tmpname.IsEmpty()) |
| 26 |
return; |
| 27 |
|
| 28 |
m_functionNameAndSignature.Clear(); |
| 29 |
m_functionNameAndSignature << name << "(" << m_eventClass << "& event)"; |
| 30 |
} |
| 31 |
|
| 32 |
wxString ConnectDetails::GetFunctionDecl() const |
| 33 |
{ |
| 34 |
wxString decl; |
| 35 |
decl << " virtual void " << GetFunctionNameAndSignature() << ";" |
| 36 |
<< "\n"; |
| 37 |
wxCrafter::WrapInIfBlock(GetIfBlock(), decl); |
| 38 |
return decl; |
| 39 |
} |
| 40 |
|
| 41 |
wxString ConnectDetails::GetFunctionImpl(const wxString& classname) const |
| 42 |
{ |
| 43 |
wxString impl; |
| 44 |
impl << "void " << classname << "::" << GetFunctionNameAndSignature(); |
| 45 |
impl << "\n{\n"; |
| 46 |
impl << "}\n"; |
| 47 |
wxCrafter::WrapInIfBlock(GetIfBlock(), impl); |
| 48 |
return impl; |
| 49 |
} |
| 50 |
|
| 51 |
void ConnectDetails::SetFunctionNameAndSignature(const wxString& functionNameAndSignature) |
| 52 |
{ |
| 53 |
// In theory the supplied string should be sane. In practice it might instead be: |
| 54 |
// an import from wxFB, entered by a user who might have typed any daft thing; or |
| 55 |
// an import from XRCed (in which case it would've been empty had we not constructed a fake one) |
| 56 |
if(!functionNameAndSignature.empty()) { |
| 57 |
wxString sig = functionNameAndSignature.AfterFirst('(').BeforeFirst(')'); |
| 58 |
if(sig.empty()) { |
| 59 |
MakeSignatureForName(functionNameAndSignature); |
| 60 |
return; |
| 61 |
} |
| 62 |
// If we reached here, there wasn't a problem |
| 63 |
m_functionNameAndSignature = functionNameAndSignature; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 68 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 |
|
| 70 |
EventsDatabase::EventsDatabase() {} |
| 71 |
|
| 72 |
EventsDatabase::~EventsDatabase() { Clear(); } |
| 73 |
|
| 74 |
void EventsDatabase::Add(const ConnectDetails& ed) |
| 75 |
{ |
| 76 |
m_events.PushBack(ed.GetEventName(), ed); |
| 77 |
m_menuIdToName[ed.GetMenuItemId()] = ed.GetEventName(); |
| 78 |
} |
| 79 |
|
| 80 |
void EventsDatabase::Add(const wxString& eventName, const wxString& className, const wxString& description, |
| 81 |
const wxString& functionNameAndSig /*=""*/, bool noBody /*=false*/) |
| 82 |
{ |
| 83 |
m_events.PushBack(eventName, ConnectDetails(eventName, className, description, noBody, functionNameAndSig)); |
| 84 |
m_menuIdToName[m_events.Item(eventName).GetMenuItemId()] = eventName; |
| 85 |
} |
| 86 |
|
| 87 |
bool EventsDatabase::Exists(int menuId) const { return m_menuIdToName.count(menuId) > 0; } |
| 88 |
|
| 89 |
ConnectDetails EventsDatabase::Item(int menuId) const |
| 90 |
{ |
| 91 |
if(Exists(menuId)) { |
| 92 |
MapMenuIdToName_t::const_iterator iter = m_menuIdToName.find(menuId); |
| 93 |
return m_events.Item(iter->second); |
| 94 |
} |
| 95 |
return ConnectDetails(); |
| 96 |
} |
| 97 |
|
| 98 |
void EventsDatabase::FillCommonEvents() |
| 99 |
{ |
| 100 |
//////////////////////////////////////////////// |
| 101 |
// Create the common events KB |
| 102 |
//////////////////////////////////////////////// |
| 103 |
Clear(); |
| 104 |
|
| 105 |
// Key Events |
| 106 |
m_events.PushBack("wxEVT_KEY_DOWN", ConnectDetails("wxEVT_KEY_DOWN", "wxKeyEvent", |
| 107 |
_("Process a wxEVT_KEY_DOWN event (any key has been pressed)"))); |
| 108 |
m_events.PushBack("wxEVT_KEY_UP", ConnectDetails("wxEVT_KEY_UP", "wxKeyEvent", |
| 109 |
_("Process a wxEVT_KEY_UP event (any key has been released)"))); |
| 110 |
m_events.PushBack("wxEVT_CHAR", ConnectDetails("wxEVT_CHAR", "wxKeyEvent", _("Process a wxEVT_CHAR event"))); |
| 111 |
|
| 112 |
// Menu |
| 113 |
m_events.PushBack( |
| 114 |
"wxEVT_CONTEXT_MENU", |
| 115 |
ConnectDetails("wxEVT_CONTEXT_MENU", "wxContextMenuEvent", |
| 116 |
_("A right click (or other context menu command depending on platform) has been detected"))); |
| 117 |
|
| 118 |
// Mouse Events |
| 119 |
m_events.PushBack("wxEVT_LEFT_DOWN", |
| 120 |
ConnectDetails("wxEVT_LEFT_DOWN", "wxMouseEvent", |
| 121 |
_("Process a wxEVT_LEFT_DOWN event. The handler of this event should normally " |
| 122 |
"call event.Skip() to allow the default processing to take place as otherwise " |
| 123 |
"the window under mouse wouldn't get the focus."))); |
| 124 |
m_events.PushBack("wxEVT_LEFT_UP", |
| 125 |
ConnectDetails("wxEVT_LEFT_UP", "wxMouseEvent", _("Process a wxEVT_LEFT_UP event."))); |
| 126 |
m_events.PushBack("wxEVT_LEFT_DCLICK", |
| 127 |
ConnectDetails("wxEVT_LEFT_DCLICK", "wxMouseEvent", _("Process a wxEVT_LEFT_DCLICK event."))); |
| 128 |
m_events.PushBack("wxEVT_MIDDLE_DOWN", |
| 129 |
ConnectDetails("wxEVT_MIDDLE_DOWN", "wxMouseEvent", _("Process a wxEVT_MIDDLE_DOWN event"))); |
| 130 |
m_events.PushBack("wxEVT_MIDDLE_UP", |
| 131 |
ConnectDetails("wxEVT_MIDDLE_UP", "wxMouseEvent", _("Process a wxEVT_MIDDLE_UP event"))); |
| 132 |
m_events.PushBack("wxEVT_MIDDLE_DCLICK", |
| 133 |
ConnectDetails("wxEVT_MIDDLE_DCLICK", "wxMouseEvent", _("Process a wxEVT_MIDDLE_DCLICK event."))); |
| 134 |
m_events.PushBack("wxEVT_RIGHT_DOWN", |
| 135 |
ConnectDetails("wxEVT_RIGHT_DOWN", "wxMouseEvent", _("Process a wxEVT_RIGHT_DOWN event"))); |
| 136 |
m_events.PushBack("wxEVT_RIGHT_UP", |
| 137 |
ConnectDetails("wxEVT_RIGHT_UP", "wxMouseEvent", _("Process a wxEVT_RIGHT_UP event"))); |
| 138 |
m_events.PushBack("wxEVT_RIGHT_DCLICK", |
| 139 |
ConnectDetails("wxEVT_RIGHT_DCLICK", "wxMouseEvent", _("Process a wxEVT_RIGHT_DCLICK event"))); |
| 140 |
m_events.PushBack("wxEVT_MOTION", |
| 141 |
ConnectDetails("wxEVT_MOTION", "wxMouseEvent", _("Process a wxEVT_MOTION event"))); |
| 142 |
m_events.PushBack("wxEVT_ENTER_WINDOW", |
| 143 |
ConnectDetails("wxEVT_ENTER_WINDOW", "wxMouseEvent", _("Process a wxEVT_ENTER_WINDOW event"))); |
| 144 |
m_events.PushBack("wxEVT_LEAVE_WINDOW", |
| 145 |
ConnectDetails("wxEVT_LEAVE_WINDOW", "wxMouseEvent", _("Process a wxEVT_LEAVE_WINDOW event."))); |
| 146 |
m_events.PushBack("wxEVT_MOUSEWHEEL", |
| 147 |
ConnectDetails("wxEVT_MOUSEWHEEL", "wxMouseEvent", _("Process a wxEVT_MOUSEWHEEL event"))); |
| 148 |
m_events.PushBack( |
| 149 |
"wxEVT_MOUSE_CAPTURE_LOST", |
| 150 |
ConnectDetails("wxEVT_MOUSE_CAPTURE_LOST", "wxMouseCaptureLostEvent", |
| 151 |
wxT("A mouse capture lost event is sent to a window that had obtained mouse capture, which was " |
| 152 |
"subsequently lost due to an \"external\" event (for example, when a dialog box is shown or " |
| 153 |
"if another application captures the mouse)"))); |
| 154 |
|
| 155 |
// Focus |
| 156 |
m_events.PushBack("wxEVT_SET_FOCUS", |
| 157 |
ConnectDetails("wxEVT_SET_FOCUS", "wxFocusEvent", _("Process a wxEVT_SET_FOCUS event"))); |
| 158 |
m_events.PushBack("wxEVT_KILL_FOCUS", |
| 159 |
ConnectDetails("wxEVT_KILL_FOCUS", "wxFocusEvent", _("Process a wxEVT_KILL_FOCUS event"))); |
| 160 |
|
| 161 |
// UI |
| 162 |
m_events.PushBack("wxEVT_PAINT", ConnectDetails("wxEVT_PAINT", "wxPaintEvent", _("Process a wxEVT_PAINT event"))); |
| 163 |
m_events.PushBack("wxEVT_ERASE_BACKGROUND", ConnectDetails("wxEVT_ERASE_BACKGROUND", "wxEraseEvent", |
| 164 |
_("Process a wxEVT_ERASE_BACKGROUND event."))); |
| 165 |
m_events.PushBack("wxEVT_SIZE", ConnectDetails("wxEVT_SIZE", "wxSizeEvent", _("Process a wxEVT_SIZE event"))); |
| 166 |
m_events.PushBack("wxEVT_MOVE", |
| 167 |
ConnectDetails("wxEVT_MOVE", "wxMoveEvent", |
| 168 |
_("Process a wxEVT_MOVE event, which is generated when a window is moved."))); |
| 169 |
m_events.PushBack("wxEVT_UPDATE_UI", |
| 170 |
ConnectDetails("wxEVT_UPDATE_UI", "wxUpdateUIEvent", _("Process a wxEVT_UPDATE_UI event"))); |
| 171 |
|
| 172 |
// Misc |
| 173 |
m_events.PushBack("wxEVT_IDLE", ConnectDetails("wxEVT_IDLE", "wxIdleEvent", _("Process a wxEVT_IDLE event"))); |
| 174 |
|
| 175 |
MapEvents_t::const_iterator iter = m_events.begin(); |
| 176 |
for(; iter != m_events.end(); iter++) { |
| 177 |
m_menuIdToName[iter->second.GetMenuItemId()] = iter->second.GetEventName(); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
wxMenu* EventsDatabase::CreateMenu() const |
| 182 |
{ |
| 183 |
MapEvents_t::const_iterator iter = m_events.begin(); |
| 184 |
wxMenu* menu = new wxMenu; |
| 185 |
for(; iter != m_events.end(); iter++) { |
| 186 |
ConnectDetails cd = iter->second; |
| 187 |
if(cd.GetEventName().IsEmpty()) { |
| 188 |
menu->AppendSeparator(); |
| 189 |
|
| 190 |
} else { |
| 191 |
menu->Append(cd.GetMenuItemId(), cd.GetEventName(), wxEmptyString, wxITEM_CHECK); |
| 192 |
} |
| 193 |
} |
| 194 |
return menu; |
| 195 |
} |
| 196 |
|
| 197 |
void EventsDatabase::Clear() |
| 198 |
{ |
| 199 |
m_events.Clear(); |
| 200 |
m_menuIdToName.clear(); |
| 201 |
} |