1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/uiaction.h 3 // Purpose: wxUIActionSimulator interface 4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin 5 // Created: 2010-03-06 6 // Copyright: (c) 2010 Kevin Ollivier 7 // (c) 2010 Steven Lamerton 8 // (c) 2010-2016 Vadim Zeitlin 9 // Licence: wxWindows licence 10 ///////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_UIACTIONSIMULATOR_H_ 13 #define _WX_UIACTIONSIMULATOR_H_ 14 15 #include "wx/defs.h" 16 17 #if wxUSE_UIACTIONSIMULATOR 18 19 #include "wx/mousestate.h" // for wxMOUSE_BTN_XXX constants 20 21 class WXDLLIMPEXP_CORE wxUIActionSimulator 22 { 23 public: 24 wxUIActionSimulator(); 25 ~wxUIActionSimulator(); 26 27 28 // Mouse simulation 29 // ---------------- 30 31 // Low level methods 32 bool MouseMove(long x, long y); MouseMove(const wxPoint & point)33 bool MouseMove(const wxPoint& point) { return MouseMove(point.x, point.y); } 34 35 bool MouseDown(int button = wxMOUSE_BTN_LEFT); 36 bool MouseUp(int button = wxMOUSE_BTN_LEFT); 37 38 // Higher level interface, use it if possible instead 39 bool MouseClick(int button = wxMOUSE_BTN_LEFT); 40 bool MouseDblClick(int button = wxMOUSE_BTN_LEFT); 41 bool MouseDragDrop(long x1, long y1, long x2, long y2, 42 int button = wxMOUSE_BTN_LEFT); 43 bool MouseDragDrop(const wxPoint& p1, const wxPoint& p2, 44 int button = wxMOUSE_BTN_LEFT) 45 { return MouseDragDrop(p1.x, p1.y, p2.x, p2.y, button); } 46 47 // Keyboard simulation 48 // ------------------- 49 50 // Low level methods for generating key presses and releases 51 bool KeyDown(int keycode, int modifiers = wxMOD_NONE) 52 { return Key(keycode, modifiers, true); } 53 54 bool KeyUp(int keycode, int modifiers = wxMOD_NONE) 55 { return Key(keycode, modifiers, false); } 56 57 // Higher level methods for generating both the key press and release for a 58 // single key or for all characters in the ASCII string "text" which can currently 59 // contain letters, digits and characters for the definition of numbers [+-., ]. 60 bool Char(int keycode, int modifiers = wxMOD_NONE); 61 62 bool Text(const char *text); 63 64 // Select the item with the given text in the currently focused control. 65 bool Select(const wxString& text); 66 67 private: 68 // This is the common part of Key{Down,Up}() methods: while we keep them 69 // separate at public API level for consistency with Mouse{Down,Up}(), at 70 // implementation level it makes more sense to have them in a single 71 // function. 72 // 73 // It calls DoModifiers() to simulate pressing the modifier keys if 74 // necessary and then DoKey() for the key itself. 75 bool Key(int keycode, int modifiers, bool isDown); 76 77 // Call DoKey() for all modifier keys whose bits are set in the parameter. 78 void SimulateModifiers(int modifier, bool isDown); 79 80 81 82 // This pointer is allocated in the ctor and points to the 83 // platform-specific implementation. 84 class wxUIActionSimulatorImpl* const m_impl; 85 86 wxDECLARE_NO_COPY_CLASS(wxUIActionSimulator); 87 }; 88 89 #endif // wxUSE_UIACTIONSIMULATOR 90 91 #endif // _WX_UIACTIONSIMULATOR_H_ 92