spinctrl.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/spinctrl.h
  3. // Purpose: wxSpinCtrl class declaration for Win32
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 22.07.99
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_SPINCTRL_H_
  11. #define _WX_MSW_SPINCTRL_H_
  12. #include "wx/spinbutt.h" // the base class
  13. #if wxUSE_SPINCTRL
  14. #include "wx/dynarray.h"
  15. class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
  16. WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl *, wxArraySpins);
  17. // ----------------------------------------------------------------------------
  18. // Under Win32, wxSpinCtrl is a wxSpinButton with a buddy (as MSDN docs call
  19. // it) text window whose contents is automatically updated when the spin
  20. // control is clicked.
  21. // ----------------------------------------------------------------------------
  22. class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinButton
  23. {
  24. public:
  25. wxSpinCtrl() { Init(); }
  26. wxSpinCtrl(wxWindow *parent,
  27. wxWindowID id = wxID_ANY,
  28. const wxString& value = wxEmptyString,
  29. const wxPoint& pos = wxDefaultPosition,
  30. const wxSize& size = wxDefaultSize,
  31. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  32. int min = 0, int max = 100, int initial = 0,
  33. const wxString& name = wxT("wxSpinCtrl"))
  34. {
  35. Init();
  36. Create(parent, id, value, pos, size, style, min, max, initial, name);
  37. }
  38. bool Create(wxWindow *parent,
  39. wxWindowID id = wxID_ANY,
  40. const wxString& value = wxEmptyString,
  41. const wxPoint& pos = wxDefaultPosition,
  42. const wxSize& size = wxDefaultSize,
  43. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  44. int min = 0, int max = 100, int initial = 0,
  45. const wxString& name = wxT("wxSpinCtrl"));
  46. // a wxTextCtrl-like method (but we can't have GetValue returning wxString
  47. // because the base class already has one returning int!)
  48. void SetValue(const wxString& text);
  49. // another wxTextCtrl-like method
  50. void SetSelection(long from, long to);
  51. // wxSpinCtrlBase methods
  52. virtual int GetBase() const;
  53. virtual bool SetBase(int base);
  54. // implementation only from now on
  55. // -------------------------------
  56. virtual ~wxSpinCtrl();
  57. virtual void SetValue(int val);
  58. virtual int GetValue() const;
  59. virtual void SetRange(int minVal, int maxVal);
  60. virtual bool SetFont(const wxFont &font);
  61. virtual void SetFocus();
  62. virtual bool Enable(bool enable = true);
  63. virtual bool Show(bool show = true);
  64. virtual bool Reparent(wxWindowBase *newParent);
  65. // wxSpinButton doesn't accept focus, but we do
  66. virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
  67. // we're like wxTextCtrl and not (default) wxButton
  68. virtual wxVisualAttributes GetDefaultAttributes() const
  69. {
  70. return GetClassDefaultAttributes(GetWindowVariant());
  71. }
  72. static wxVisualAttributes
  73. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
  74. {
  75. return GetCompositeControlsDefaultAttributes(variant);
  76. }
  77. // for internal use only
  78. // get the subclassed window proc of the buddy text
  79. WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
  80. // return the spinctrl object whose buddy is the given window or NULL
  81. static wxSpinCtrl *GetSpinForTextCtrl(WXHWND hwndBuddy);
  82. // process a WM_COMMAND generated by the buddy text control
  83. bool ProcessTextCommand(WXWORD cmd, WXWORD id);
  84. // recognize buddy window as part of this control at wx level
  85. virtual bool ContainsHWND(WXHWND hWnd) const { return hWnd == m_hwndBuddy; }
  86. protected:
  87. virtual void DoGetPosition(int *x, int *y) const;
  88. virtual void DoMoveWindow(int x, int y, int width, int height);
  89. virtual wxSize DoGetBestSize() const;
  90. virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
  91. virtual void DoGetSize(int *width, int *height) const;
  92. virtual void DoGetClientSize(int *x, int *y) const;
  93. #if wxUSE_TOOLTIPS
  94. virtual void DoSetToolTip( wxToolTip *tip );
  95. #endif // wxUSE_TOOLTIPS
  96. virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  97. virtual bool MSWOnScroll(int orientation, WXWORD wParam,
  98. WXWORD pos, WXHWND control);
  99. // handle processing of special keys
  100. void OnChar(wxKeyEvent& event);
  101. void OnSetFocus(wxFocusEvent& event);
  102. void OnKillFocus(wxFocusEvent& event);
  103. // generate spin control update event with the given value
  104. void SendSpinUpdate(int value);
  105. // called to ensure that the value is in the correct range
  106. virtual void NormalizeValue();
  107. // the value of the control before the latest change (which might not have
  108. // changed anything in fact -- this is why we need this field)
  109. int m_oldValue;
  110. // the data for the "buddy" text ctrl
  111. WXHWND m_hwndBuddy;
  112. WXFARPROC m_wndProcBuddy;
  113. // Block text update event after SetValue()
  114. bool m_blockEvent;
  115. private:
  116. // Common part of all ctors.
  117. void Init();
  118. // Adjust the text control style depending on whether we need to enter only
  119. // digits or may need to enter something else (e.g. "-" sign, "x"
  120. // hexadecimal prefix, ...) in it.
  121. void UpdateBuddyStyle();
  122. DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
  123. DECLARE_EVENT_TABLE()
  124. wxDECLARE_NO_COPY_CLASS(wxSpinCtrl);
  125. };
  126. #endif // wxUSE_SPINCTRL
  127. #endif // _WX_MSW_SPINCTRL_H_