1 /* 2 * This file is part of wxSmith plugin for Code::Blocks Studio 3 * Copyright (C) 2006-2007 Bartlomiej Swiecki 4 * 5 * wxSmith is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * wxSmith is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * $Revision: 10874 $ 19 * $Id: wxsevents.h 10874 2016-07-16 20:00:28Z jenslody $ 20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/wxwidgets/wxsevents.h $ 21 */ 22 23 #ifndef WXSEVENTS_H 24 #define WXSEVENTS_H 25 26 #include <wx/arrstr.h> 27 #include <tinyxml.h> 28 #include <wx/arrstr.h> 29 30 #include "wxscodercontext.h" 31 32 // Forward declarations 33 class wxsItem; 34 35 /** \brief Structure describing one event */ 36 struct wxsEventDesc 37 { 38 enum EntryType 39 { 40 Id, ///< \brief Event using one identifier 41 IdRange, ///< \brief Event using range of identifiers 42 NoId, ///< \brief Event without id (can be used for root element only) 43 Category, ///< \brief Not really entry, but starts new category 44 EndOfList ///< \brief End of list of events 45 }; 46 47 EntryType ET; ///< \brief Type of entry 48 wxString Entry; ///< \brief Name of entry inside event table 49 wxString Type; ///< \brief Macro of event type used inside event table 50 wxString ArgType; ///< \brief Name of type of argument passed to event-processing function 51 wxString NewFuncNameBase; ///< \brief Base for new function name, it will be created as "On" + VarName + NewFuncName 52 }; 53 54 /** \brief Beginning definition of events array (source file) */ 55 #define WXS_EV_BEGIN(name) \ 56 static wxsEventDesc name[] = { 57 58 /** \brief Adding new event into list (entry without id, will be connected to widget using wxsEvtHandler::Connect function) */ 59 #define WXS_EV(entry,type,arg,funcbase) \ 60 { wxsEventDesc::NoId, _T(#entry), _T(#type), _T(#arg), _T(#funcbase) } , 61 62 /** \brief Adding new event into list (entry with id, standard one) */ 63 #define WXS_EVI(entry,type,arg,funcbase) \ 64 { wxsEventDesc::Id, _T(#entry), _T(#type), _T(#arg), _T(#funcbase) } , 65 66 /** \brief Adding new event into list (entry using range of ids, currently not supported by wxSmith, but may be in future) */ 67 #define WXS_EV2I(entry,type,arg,funcbase) \ 68 { wxsEventDesc::IdRange, _T(#entry), _T(#type), _T(#arg), _T(#funcbase) } , 69 70 /** \brief Beginning new category */ 71 #define WXS_EV_CATEGORY(name) \ 72 { wxsEventDesc::Category, name, _T(""), _T(""), _T("") }, 73 74 /** \brief Ending creation of list */ 75 #define WXS_EV_END() \ 76 { wxsEventDesc::EndOfList, _T(""), _T(""), _T(""), _T("") } }; 77 78 /** \brief Adding all default paint events */ 79 #define WXS_EV_PAINT() \ 80 WXS_EV_CATEGORY(_("Paint events")) \ 81 WXS_EV(EVT_PAINT,wxEVT_PAINT,wxPaintEvent,Paint) \ 82 WXS_EV(EVT_ERASE_BACKGROUND,wxEVT_ERASE_BACKGROUND,wxEraseEvent,EraseBackground) \ 83 84 /** \brief Adding all keyboard events */ 85 #define WXS_EV_KEYBOARD() \ 86 WXS_EV_CATEGORY(_("Keyboard events")) \ 87 WXS_EV(EVT_KEY_DOWN,wxEVT_KEY_DOWN,wxKeyEvent,KeyDown) \ 88 WXS_EV(EVT_KEY_UP,wxEVT_KEY_UP,wxKeyEvent,KeyUp) \ 89 WXS_EV(EVT_CHAR,wxEVT_CHAR,wxKeyEvent,Char) \ 90 WXS_EV(EVT_SET_FOCUS,wxEVT_SET_FOCUS,wxFocusEvent,SetFocus) \ 91 WXS_EV(EVT_KILL_FOCUS,wxEVT_KILL_FOCUS,wxFocusEvent,KillFocus) 92 93 #define WXS_EV_MOUSE() \ 94 WXS_EV_CATEGORY(_T("Mouse events")) \ 95 WXS_EV(EVT_LEFT_DOWN,wxEVT_LEFT_DOWN,wxMouseEvent,LeftDown) \ 96 WXS_EV(EVT_LEFT_UP,wxEVT_LEFT_UP,wxMouseEvent,LeftUp) \ 97 WXS_EV(EVT_LEFT_DCLICK,wxEVT_LEFT_DCLICK,wxMouseEvent,LeftDClick) \ 98 WXS_EV(EVT_MIDDLE_DOWN,wxEVT_MIDDLE_DOWN,wxMouseEvent,MiddleDown) \ 99 WXS_EV(EVT_MIDDLE_UP,wxEVT_MIDDLE_UP,wxMouseEvent,MiddleUp) \ 100 WXS_EV(EVT_MIDDLE_DCLICK,wxEVT_MIDDLE_DCLICK,wxMouseEvent,MiddleDClick) \ 101 WXS_EV(EVT_RIGHT_DOWN,wxEVT_RIGHT_DOWN,wxMouseEvent,RightDown) \ 102 WXS_EV(EVT_RIGHT_UP,wxEVT_RIGHT_UP,wxMouseEvent,RightUp) \ 103 WXS_EV(EVT_RIGHT_DCLICK,wxEVT_RIGHT_DCLICK,wxMouseEvent,RightDClick) \ 104 WXS_EV(EVT_MOTION,wxEVT_MOTION,wxMouseEvent,MouseMove) \ 105 WXS_EV(EVT_ENTER_WINDOW,wxEVT_ENTER_WINDOW,wxMouseEvent,MouseEnter) \ 106 WXS_EV(EVT_LEAVE_WINDOW,wxEVT_LEAVE_WINDOW,wxMouseEvent,MouseLeave) \ 107 WXS_EV(EVT_MOUSEWHEEL,wxEVT_MOUSEWHEEL,wxMouseEvent,MouseWheel) \ 108 WXS_EV(EVT_SET_CURSOR,wxEVT_SET_CURSOR,wxSetCursorEvent,SetCursor) \ 109 110 111 /** \brief Adding all size-related events */ 112 #define WXS_EV_SIZE() \ 113 WXS_EV(EVT_SIZE,wxEVT_SIZE,wxSizeEvent,Resize) 114 115 116 /** \brief Adding all default events */ 117 #define WXS_EV_DEFAULTS() \ 118 WXS_EV_PAINT() \ 119 WXS_EV_KEYBOARD() \ 120 WXS_EV_MOUSE() \ 121 WXS_EV_SIZE() 122 123 /** \brief Class managing events used by item 124 * 125 * This class manages event used by widget (but it's not responsible for editing 126 * them). 127 * 128 * After building new wxsEvents class, SetEventArray() should be called to 129 * connect class with specified set of events 130 * 131 */ 132 class wxsEvents 133 { 134 public: 135 136 /** \brief Ctor */ 137 wxsEvents(const wxsEventDesc* Events,wxsItem* Item); 138 139 /** \brief Getting number of events */ GetCount()140 inline int GetCount() { return m_Count; } 141 142 /** \brief Getting event description */ GetDesc(int Index)143 inline const wxsEventDesc* GetDesc(int Index) { return &m_EventArray[Index]; } 144 145 /** \brief Getting event handler name */ GetHandler(int Index)146 inline const wxString& GetHandler(int Index) { return m_Functions[Index]; } 147 148 /** \brief Setting event handler name */ SetHandler(int Index,const wxString & Name)149 inline void SetHandler(int Index,const wxString& Name) { m_Functions[Index] = Name; } 150 151 /** \brief Function generating code which binds events with main resource class 152 * 153 * Connecting events is done through wxsEvtHandler::Connect function. 154 * Event table is not used because not all events could be processed. 155 */ 156 void GenerateBindingCode(wxsCoderContext* Context,const wxString& IdString,const wxString& VarNameString); 157 158 /** \brief Function loading associated function names from Xml node. */ 159 void XmlLoadFunctions(TiXmlElement* Element); 160 161 /** \brief Function adding handlers to given Xml element */ 162 void XmlSaveFunctions(TiXmlElement* Element); 163 164 private: 165 166 wxsItem* m_Item; ///< Item whose events are managed 167 const wxsEventDesc* m_EventArray; ///< Array of events fetched from item 168 wxArrayString m_Functions; ///< Array of function names used for each entry item 169 int m_Count; ///< Number of events 170 }; 171 172 #endif 173