control.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/control.h
  3. // Purpose: universal wxControl: adds handling of mnemonics
  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_CONTROL_H_
  11. #define _WX_UNIV_CONTROL_H_
  12. class WXDLLIMPEXP_FWD_CORE wxControlRenderer;
  13. class WXDLLIMPEXP_FWD_CORE wxInputHandler;
  14. class WXDLLIMPEXP_FWD_CORE wxRenderer;
  15. // we must include it as most/all control classes derive their handlers from
  16. // it
  17. #include "wx/univ/inphand.h"
  18. #include "wx/univ/inpcons.h"
  19. // ----------------------------------------------------------------------------
  20. // wxControlAction: the action is currently just a string which identifies it,
  21. // later it might become an atom (i.e. an opaque handler to string).
  22. // ----------------------------------------------------------------------------
  23. typedef wxString wxControlAction;
  24. // the list of actions which apply to all controls (other actions are defined
  25. // in the controls headers)
  26. #define wxACTION_NONE wxT("") // no action to perform
  27. // ----------------------------------------------------------------------------
  28. // wxControl: the base class for all GUI controls
  29. // ----------------------------------------------------------------------------
  30. class WXDLLIMPEXP_CORE wxControl : public wxControlBase, public wxInputConsumer
  31. {
  32. public:
  33. wxControl() { Init(); }
  34. wxControl(wxWindow *parent,
  35. wxWindowID id,
  36. const wxPoint& pos = wxDefaultPosition,
  37. const wxSize& size = wxDefaultSize, long style = 0,
  38. const wxValidator& validator = wxDefaultValidator,
  39. const wxString& name = wxControlNameStr)
  40. {
  41. Init();
  42. Create(parent, id, pos, size, style, validator, name);
  43. }
  44. bool Create(wxWindow *parent,
  45. wxWindowID id,
  46. const wxPoint& pos = wxDefaultPosition,
  47. const wxSize& size = wxDefaultSize, long style = 0,
  48. const wxValidator& validator = wxDefaultValidator,
  49. const wxString& name = wxControlNameStr);
  50. // this function will filter out '&' characters and will put the
  51. // accelerator char (the one immediately after '&') into m_chAccel
  52. virtual void SetLabel(const wxString& label);
  53. // return the current label
  54. virtual wxString GetLabel() const { return m_label; }
  55. // wxUniversal-specific methods
  56. // return the index of the accel char in the label or -1 if none
  57. int GetAccelIndex() const { return m_indexAccel; }
  58. // return the accel char itself or 0 if none
  59. wxChar GetAccelChar() const
  60. {
  61. return m_indexAccel == -1 ? wxT('\0') : (wxChar)m_label[m_indexAccel];
  62. }
  63. virtual wxWindow *GetInputWindow() const { return (wxWindow*)this; }
  64. protected:
  65. // common part of all ctors
  66. void Init();
  67. // set m_label and m_indexAccel and refresh the control to show the new
  68. // label (but, unlike SetLabel(), don't call the base class SetLabel() thus
  69. // avoiding to change wxControlBase::m_labelOrig)
  70. void UnivDoSetLabel(const wxString& label);
  71. private:
  72. // label and accel info
  73. wxString m_label;
  74. int m_indexAccel;
  75. DECLARE_DYNAMIC_CLASS(wxControl)
  76. DECLARE_EVENT_TABLE()
  77. WX_DECLARE_INPUT_CONSUMER()
  78. };
  79. #endif // _WX_UNIV_CONTROL_H_