1 /* 2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 3 * Distributed under the MIT License 4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 5 */ 6 7 #ifndef MYGUI_WIDGET_INPUT_H_ 8 #define MYGUI_WIDGET_INPUT_H_ 9 10 #include "MyGUI_Prerequest.h" 11 #include "MyGUI_Macros.h" 12 #include "MyGUI_WidgetDefines.h" 13 #include "MyGUI_WidgetToolTip.h" 14 #include "MyGUI_MouseButton.h" 15 #include "MyGUI_KeyCode.h" 16 #include "MyGUI_MaskPickInfo.h" 17 #include "MyGUI_Delegate.h" 18 #include "MyGUI_EventPair.h" 19 20 namespace MyGUI 21 { 22 23 /** 24 General information about creating delegate for event : 25 @example "Delegate usage" 26 @code 27 void anyFunc(...) { } // global function 28 29 class AnyClass 30 { 31 public: 32 static void anyStaticMethod(...) { } // static class method 33 void anyMethod(...) { } // class method 34 }; 35 36 AnyClass anyObject; // class instance 37 @endcode 38 39 delegate creating: 40 @code 41 eventAny = MyGUI::newDelegate(anyFunc); 42 eventAny = MyGUI::newDelegate(AnyClass::anyStaticMethod); 43 eventAny = MyGUI::newDelegate(&anyObject, &AnyClass::anyMethod); 44 @endcode 45 */ 46 47 // делегаты для событий виджета 48 typedef delegates::CMultiDelegate1<Widget*> EventHandle_WidgetVoid; 49 typedef delegates::CMultiDelegate2<Widget*, Widget*> EventHandle_WidgetWidget; 50 typedef delegates::CMultiDelegate2<Widget*, bool> EventHandle_WidgetBool; 51 typedef delegates::CMultiDelegate2<Widget*, int> EventHandle_WidgetInt; 52 typedef delegates::CMultiDelegate2<Widget*, size_t> EventHandle_WidgetSizeT; 53 typedef delegates::CMultiDelegate3<Widget*, int, int> EventHandle_WidgetIntInt; 54 typedef delegates::CMultiDelegate4<Widget*, int, int, MouseButton> EventHandle_WidgetIntIntButton; 55 typedef delegates::CMultiDelegate2<Widget*, KeyCode> EventHandle_WidgetKeyCode; 56 typedef delegates::CMultiDelegate3<Widget*, KeyCode, Char> EventHandle_WidgetKeyCodeChar; 57 typedef delegates::CMultiDelegate2<Widget*, const ToolTipInfo& > EventHandle_WidgetToolTip; 58 59 class MYGUI_EXPORT WidgetInput 60 { 61 public: 62 WidgetInput(); 63 virtual ~WidgetInput() = default; 64 65 /** Set need tool tip mode flag. Enable this if you need tool tip events for widget */ 66 void setNeedToolTip(bool _value); 67 /** Get need tool tip mode flag */ 68 bool getNeedToolTip() const; 69 70 /** Set mouse pointer for this widget */ 71 void setPointer(const std::string& _value); 72 /** Get mouse pointer name for this widget */ 73 const std::string& getPointer() const; 74 75 /** Set need key focus flag */ 76 void setNeedKeyFocus(bool _value); 77 /** Is need key focus 78 If disable this widget won't be reacting on keyboard at all.\n 79 Enabled (true) by default. 80 */ 81 bool getNeedKeyFocus() const; 82 83 /** Set need mouse focus flag */ 84 void setNeedMouseFocus(bool _value); 85 /** Is need mouse focus 86 If disable this widget won't be reacting on mouse at all.\n 87 Enabled (true) by default. 88 */ 89 bool getNeedMouseFocus() const; 90 91 /** Set inherits mode flag 92 This mode makes all child widgets pickable even if widget don't 93 need mouse focus (was set setNeedMouseFocus(false) ).\n 94 Disabled (false) by default. 95 */ 96 void setInheritsPick(bool _value); 97 /** Get inherits mode flag */ 98 bool getInheritsPick() const; 99 100 /** Set picking mask for widget */ 101 void setMaskPick(const std::string& _filename); 102 /** Set picking mask for widget */ 103 void setMaskPick(const MaskPickInfo& _info); 104 105 bool isMaskPickInside(const IntPoint& _point, const IntCoord& _coord) const; 106 107 bool getRootMouseFocus() const; 108 bool getRootKeyFocus() const; 109 110 /** Event : Widget lost mouse focus.\n 111 signature : void method(MyGUI::Widget* _sender, MyGUI::Widget* _new)\n 112 @param _sender widget that called this event 113 @param _new widget with mouse focus or nullptr 114 */ 115 EventHandle_WidgetWidget eventMouseLostFocus; 116 117 /** Event : Widget got mouse focus.\n 118 signature : void method(MyGUI::Widget* _sender, MyGUI::Widget* _old)\n 119 @param _sender widget that called this event 120 @param _old widget with mouse focus or nullptr 121 */ 122 EventHandle_WidgetWidget eventMouseSetFocus; 123 124 /** Event : Widget mouse move with captured widget.\n 125 signature : void method(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)\n 126 @param _sender widget that called this event 127 @param _left - pointer position 128 @param _top - pointer position 129 */ 130 EventPairAddParameter<EventHandle_WidgetIntInt, EventHandle_WidgetIntIntButton> eventMouseDrag; 131 132 /** Event : Mouse move over widget.\n 133 signature : void method(MyGUI::Widget* _sender, int _left, int _top)\n 134 @param _sender widget that called this event 135 @param _left - pointer position 136 @param _top - pointer position 137 */ 138 EventHandle_WidgetIntInt eventMouseMove; 139 140 /** Event : Mouse wheel over widget.\n 141 signature : void method(MyGUI::Widget* _sender, int _rel)\n 142 @param _sender widget that called this event 143 @param _rel relative wheel position 144 */ 145 EventHandle_WidgetInt eventMouseWheel; 146 147 /** Event : Mouse button pressed.\n 148 signature : void method(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)\n 149 @param _sender widget that called this event 150 @param _left - pointer position 151 @param _top - pointer position 152 @param _id Mouse button id 153 */ 154 EventHandle_WidgetIntIntButton eventMouseButtonPressed; 155 156 /** Event : Mouse button released.\n 157 signature : void method(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)\n 158 @param _sender widget that called this event 159 @param _left - pointer position 160 @param _top - pointer position 161 @param _id Mouse button id 162 */ 163 EventHandle_WidgetIntIntButton eventMouseButtonReleased; 164 165 /** Event : Mouse button pressed and released.\n 166 signature : void method(MyGUI::Widget* _sender) 167 @param _sender widget that called this event 168 */ 169 EventHandle_WidgetVoid eventMouseButtonClick; 170 171 /** Event : Mouse button double click.\n 172 signature : void method(MyGUI::Widget* _sender) 173 @param _sender widget that called this event 174 */ 175 EventHandle_WidgetVoid eventMouseButtonDoubleClick; 176 177 /** Event : Widget lost keyboard focus.\n 178 signature : void method(MyGUI::Widget* _sender, MyGUI::Widget* _new)\n 179 @param _sender widget that called this event 180 @param _new widget with keyboard focus or nullptr 181 */ 182 EventHandle_WidgetWidget eventKeyLostFocus; 183 184 /** Event : Widget got keyboard focus.\n 185 signature : void method(MyGUI::Widget* _sender, MyGUI::Widget* _old)\n 186 @param _sender widget that called this event 187 @param _old widget with keyboard focus or nullptr 188 */ 189 EventHandle_WidgetWidget eventKeySetFocus; 190 191 /** Event : Key pressed.\n 192 signature : void method(MyGUI::Widget* _sender, MyGUI::KeyCode _key, MyGUI::Char _char)\n 193 @param _sender widget that called this event 194 @param _key code 195 @param _char of pressed symbol (for multilanguage applications) 196 */ 197 EventHandle_WidgetKeyCodeChar eventKeyButtonPressed; 198 199 /** Event : Key released.\n 200 signature : void method(MyGUI::Widget* _sender, MyGUI::KeyCode _key)\n 201 @param _sender widget that called this event 202 @param _key code 203 */ 204 EventHandle_WidgetKeyCode eventKeyButtonReleased; 205 206 /** Event : Root widget changed mouse focus.\n 207 info : this event sends only to root widget\n 208 signature : void method(MyGUI::Widget* _sender, bool _focus); 209 @param _sender widget that called this event 210 @param _focus Is widget got mouse focus. 211 */ 212 EventHandle_WidgetBool eventRootMouseChangeFocus; 213 214 /** Event : Root widget changed keyboard focus.\n 215 info : this event sends only to root widget\n 216 signature : void method(MyGUI::Widget* _sender, bool _focus); 217 @param _sender widget that called this event 218 @param _focus Is widget got keyboard focus. 219 */ 220 EventHandle_WidgetBool eventRootKeyChangeFocus; 221 222 /** Event : Event about changing tooltip state.\n 223 signature : void method(MyGUI::Widget* _sender, const MyGUI::ToolTipInfo& _info); 224 @param _sender widget that called this event 225 @param _info about tooltip 226 */ 227 EventHandle_WidgetToolTip eventToolTip; 228 229 /*internal:*/ 230 void _riseMouseLostFocus(Widget* _new); 231 void _riseMouseSetFocus(Widget* _old); 232 void _riseMouseDrag(int _left, int _top, MouseButton _id); 233 void _riseMouseMove(int _left, int _top); 234 void _riseMouseWheel(int _rel); 235 void _riseMouseButtonPressed(int _left, int _top, MouseButton _id); 236 void _riseMouseButtonReleased(int _left, int _top, MouseButton _id); 237 void _riseMouseButtonClick(); 238 void _riseMouseButtonDoubleClick(); 239 void _riseKeyLostFocus(Widget* _new); 240 void _riseKeySetFocus(Widget* _old); 241 void _riseKeyButtonPressed(KeyCode _key, Char _char); 242 void _riseKeyButtonReleased(KeyCode _key); 243 void _riseMouseChangeRootFocus(bool _focus); 244 void _riseKeyChangeRootFocus(bool _focus); 245 246 void _setRootMouseFocus(bool _value); 247 void _setRootKeyFocus(bool _value); 248 249 protected: 250 virtual void onMouseLostFocus(Widget* _new); 251 virtual void onMouseSetFocus(Widget* _old); 252 virtual void onMouseDrag(int _left, int _top, MouseButton _id); 253 virtual void onMouseMove(int _left, int _top); 254 virtual void onMouseWheel(int _rel); 255 virtual void onMouseButtonPressed(int _left, int _top, MouseButton _id); 256 virtual void onMouseButtonReleased(int _left, int _top, MouseButton _id); 257 virtual void onMouseButtonClick(); 258 virtual void onMouseButtonDoubleClick(); 259 virtual void onKeyLostFocus(Widget* _new); 260 virtual void onKeySetFocus(Widget* _old); 261 virtual void onKeyButtonPressed(KeyCode _key, Char _char); 262 virtual void onKeyButtonReleased(KeyCode _key); 263 virtual void onMouseChangeRootFocus(bool _focus); 264 virtual void onKeyChangeRootFocus(bool _focus); 265 266 private: 267 std::string mPointer; 268 MaskPickInfo mOwnMaskPickInfo; 269 270 bool mNeedToolTip; 271 bool mInheritsPick; 272 bool mNeedKeyFocus; 273 bool mNeedMouseFocus; 274 275 bool mRootMouseFocus; 276 bool mRootKeyFocus; 277 }; 278 279 } // namespace MyGUI 280 281 #endif // MYGUI_WIDGET_INPUT_H_ 282