inpcons.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/inpcons.h
  3. // Purpose: wxInputConsumer: mix-in class for input handling
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 14.08.00
  7. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_INPCONS_H_
  11. #define _WX_UNIV_INPCONS_H_
  12. class WXDLLIMPEXP_FWD_CORE wxInputHandler;
  13. class WXDLLIMPEXP_FWD_CORE wxWindow;
  14. #include "wx/object.h"
  15. #include "wx/event.h"
  16. // ----------------------------------------------------------------------------
  17. // wxControlAction: the action is currently just a string which identifies it,
  18. // later it might become an atom (i.e. an opaque handler to string).
  19. // ----------------------------------------------------------------------------
  20. typedef wxString wxControlAction;
  21. // the list of actions which apply to all controls (other actions are defined
  22. // in the controls headers)
  23. #define wxACTION_NONE wxT("") // no action to perform
  24. // ----------------------------------------------------------------------------
  25. // wxInputConsumer: mix-in class for handling wxControlActions (used by
  26. // wxControl and wxTopLevelWindow).
  27. // ----------------------------------------------------------------------------
  28. class WXDLLIMPEXP_CORE wxInputConsumer
  29. {
  30. public:
  31. wxInputConsumer() { m_inputHandler = NULL; }
  32. virtual ~wxInputConsumer() { }
  33. // get the input handler
  34. wxInputHandler *GetInputHandler() const { return m_inputHandler; }
  35. // perform a control-dependent action: an action may have an optional
  36. // numeric and another (also optional) string argument whose interpretation
  37. // depends on the action
  38. //
  39. // NB: we might use ellipsis in PerformAction() declaration but this
  40. // wouldn't be more efficient than always passing 2 unused parameters
  41. // but would be more difficult. Another solution would be to have
  42. // several overloaded versions but this will expose the problem of
  43. // virtual function hiding we don't have here.
  44. virtual bool PerformAction(const wxControlAction& action,
  45. long numArg = -1l,
  46. const wxString& strArg = wxEmptyString);
  47. // get the window to work with (usually the class wxInputConsumer was mixed into)
  48. virtual wxWindow *GetInputWindow() const = 0;
  49. // this function must be implemented in any classes process input (i.e. not
  50. // static controls) to create the standard input handler for the concrete
  51. // class deriving from this mix-in
  52. //
  53. // the parameter is the default input handler which should receive all
  54. // unprocessed input (i.e. typically handlerDef is passed to
  55. // wxStdInputHandler ctor) or it may be NULL
  56. //
  57. // the returned pointer will not be deleted by caller so it must either
  58. // point to a static object or be deleted on program termination
  59. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef);
  60. protected:
  61. // event handlers
  62. void OnMouse(wxMouseEvent& event);
  63. void OnKeyDown(wxKeyEvent& event);
  64. void OnKeyUp(wxKeyEvent& event);
  65. void OnFocus(wxFocusEvent& event);
  66. void OnActivate(wxActivateEvent& event);
  67. // create input handler by name, fall back to GetStdInputHandler() if
  68. // the current theme doesn't define any specific handler of this type
  69. void CreateInputHandler(const wxString& inphandler);
  70. private:
  71. // the input processor (we never delete it)
  72. wxInputHandler *m_inputHandler;
  73. };
  74. // ----------------------------------------------------------------------------
  75. // macros which must be used by the classes derived from wxInputConsumer mix-in
  76. // ----------------------------------------------------------------------------
  77. // declare the methods to be forwarded
  78. #define WX_DECLARE_INPUT_CONSUMER() \
  79. private: \
  80. void OnMouse(wxMouseEvent& event); \
  81. void OnKeyDown(wxKeyEvent& event); \
  82. void OnKeyUp(wxKeyEvent& event); \
  83. void OnFocus(wxFocusEvent& event); \
  84. public: /* because of docview :-( */ \
  85. void OnActivate(wxActivateEvent& event); \
  86. private:
  87. // implement the event table entries for wxControlContainer
  88. #define WX_EVENT_TABLE_INPUT_CONSUMER(classname) \
  89. EVT_KEY_DOWN(classname::OnKeyDown) \
  90. EVT_KEY_UP(classname::OnKeyUp) \
  91. EVT_MOUSE_EVENTS(classname::OnMouse) \
  92. EVT_SET_FOCUS(classname::OnFocus) \
  93. EVT_KILL_FOCUS(classname::OnFocus) \
  94. EVT_ACTIVATE(classname::OnActivate)
  95. // Forward event handlers to wxInputConsumer
  96. //
  97. // (We can't use them directly, because wxIC has virtual methods, which forces
  98. // the compiler to include (at least) two vtables into wxControl, one for the
  99. // wxWindow-wxControlBase-wxControl branch and one for the wxIC mix-in.
  100. // Consequently, the "this" pointer has different value when in wxControl's
  101. // and wxIC's method, even though the instance stays same. This doesn't matter
  102. // so far as member pointers aren't used, but that's not wxControl's case.
  103. // When we add an event table entry (= use a member pointer) pointing to
  104. // wxIC's OnXXX method, GCC compiles code that executes wxIC::OnXXX with the
  105. // version of "this" that belongs to wxControl, not wxIC! In our particular
  106. // case, the effect is that m_handler is NULL (probably same memory
  107. // area as the_other_vtable's_this->m_refObj) and input handling doesn't work.)
  108. #define WX_FORWARD_TO_INPUT_CONSUMER(classname) \
  109. void classname::OnMouse(wxMouseEvent& event) \
  110. { \
  111. wxInputConsumer::OnMouse(event); \
  112. } \
  113. void classname::OnKeyDown(wxKeyEvent& event) \
  114. { \
  115. wxInputConsumer::OnKeyDown(event); \
  116. } \
  117. void classname::OnKeyUp(wxKeyEvent& event) \
  118. { \
  119. wxInputConsumer::OnKeyUp(event); \
  120. } \
  121. void classname::OnFocus(wxFocusEvent& event) \
  122. { \
  123. wxInputConsumer::OnFocus(event); \
  124. } \
  125. void classname::OnActivate(wxActivateEvent& event) \
  126. { \
  127. wxInputConsumer::OnActivate(event); \
  128. }
  129. #endif // _WX_UNIV_INPCONS_H_