X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9b7e022676582feadfcce349d66a52be88121ac7..7bd30a12ade503fd135c686ecc98a6f6d5fecbeb:/include/wx/uiaction.h diff --git a/include/wx/uiaction.h b/include/wx/uiaction.h index a11bb347eb..7736620675 100644 --- a/include/wx/uiaction.h +++ b/include/wx/uiaction.h @@ -1,11 +1,13 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: include/wx/uiaction.cpp +// Name: wx/uiaction.h // Purpose: wxUIActionSimulator interface -// Author: Kevin Ollivier +// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin // Modified by: // Created: 2010-03-06 -// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Kevin Ollivier +// (c) 2010 Steven Lamerton +// (c) 2010 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -16,39 +18,70 @@ #if wxUSE_UIACTIONSIMULATOR -#include "wx/event.h" -#include "wx/dynarray.h" +#include "wx/mousestate.h" // for wxMOUSE_BTN_XXX constants class WXDLLIMPEXP_CORE wxUIActionSimulator { public: - wxUIActionSimulator(); - ~wxUIActionSimulator(); + wxUIActionSimulator() { } - // Mouse related - bool MouseMove(long x, long y); - bool MouseDown(int button = wxMOUSE_BTN_LEFT); - bool MouseUp(int button = wxMOUSE_BTN_LEFT); - bool MouseClick(int button = wxMOUSE_BTN_LEFT); - bool MouseDblClick(int button = wxMOUSE_BTN_LEFT); - bool MouseDragDrop(long x1, long y1, long x2, long y2, int button = wxMOUSE_BTN_LEFT); - // Keyboard related: + // Default dtor, copy ctor and assignment operator are ok (even though the + // last two don't make much sense for this class). - bool KeyDown(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false) - { return Key(keycode, true, shiftDown, cmdDown, altDown); } - bool KeyUp(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false) - { return Key(keycode, false, shiftDown, cmdDown, altDown); } + // Mouse simulation + // ---------------- - bool Char(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false); + // Low level methods + bool MouseMove(long x, long y); + bool MouseMove(const wxPoint& point) { return MouseMove(point.x, point.y); } -protected: - // Implementation-wise, since key events take more code to set up on GTK and Mac, it makes - // sense to handle both key down and key up in one method. However, I wanted the API for pressing - // and releasing the mouse and keyboard to be consistent, and I don't really like using a bool - // for pressed state, so I'm leaving this as an implementation detail. - bool Key(int keycode, bool isDown=true, bool shiftDown=false, bool cmdDown=false, bool altDown=false); + bool MouseDown(int button = wxMOUSE_BTN_LEFT); + bool MouseUp(int button = wxMOUSE_BTN_LEFT); + + // Higher level interface, use it if possible instead + bool MouseClick(int button = wxMOUSE_BTN_LEFT); + bool MouseDblClick(int button = wxMOUSE_BTN_LEFT); + bool MouseDragDrop(long x1, long y1, long x2, long y2, + int button = wxMOUSE_BTN_LEFT); + + + // Keyboard simulation + // ------------------- + + // Low level methods for generating key presses and releases + bool KeyDown(int keycode, int modifiers = wxMOD_NONE) + { return Key(keycode, modifiers, true); } + + bool KeyUp(int keycode, int modifiers = wxMOD_NONE) + { return Key(keycode, modifiers, false); } + + // Higher level methods for generating both the key press and release for a + // single key or for all characters in the ASCII string "text" which can + // currently contain letters only (no digits, no punctuation). + bool Char(int keycode, int modifiers = wxMOD_NONE); + + bool Text(const char *text); + +private: + // This is the common part of Key{Down,Up}() methods: while we keep them + // separate at public API level for consistency with Mouse{Down,Up}(), at + // implementation level it makes more sense to have them in a single + // function. + // + // It calls DoModifiers() to simulate pressing the modifier keys if + // necessary and then DoKey() for the key itself. + bool Key(int keycode, int modifiers, bool isDown); + + // Call DoKey() for all modifier keys whose bits are set in the parameter. + void SimulateModifiers(int modifier, bool isDown); + + + // The low-level port-specific function which really generates the key + // presses. It should generate exactly one key event with the given + // parameters. + bool DoKey(int keycode, int modifiers, bool isDown); }; #endif // wxUSE_UIACTIONSIMULATOR