]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/univ/spinbutt.h | |
3 | // Purpose: universal version of wxSpinButton | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 21.01.01 | |
442b35b5 | 7 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 8 | // Licence: wxWindows licence |
1e6feb95 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_UNIV_SPINBUTT_H_ | |
12 | #define _WX_UNIV_SPINBUTT_H_ | |
13 | ||
1e6feb95 VZ |
14 | #include "wx/univ/scrarrow.h" |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // wxSpinButton | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // actions supported by this control | |
9a83f860 VZ |
21 | #define wxACTION_SPIN_INC wxT("inc") |
22 | #define wxACTION_SPIN_DEC wxT("dec") | |
1e6feb95 | 23 | |
53a2db12 | 24 | class WXDLLIMPEXP_CORE wxSpinButton : public wxSpinButtonBase, |
1e6feb95 VZ |
25 | public wxControlWithArrows |
26 | { | |
27 | public: | |
28 | wxSpinButton(); | |
29 | wxSpinButton(wxWindow *parent, | |
a290fa5a | 30 | wxWindowID id = wxID_ANY, |
1e6feb95 VZ |
31 | const wxPoint& pos = wxDefaultPosition, |
32 | const wxSize& size = wxDefaultSize, | |
33 | long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, | |
34 | const wxString& name = wxSPIN_BUTTON_NAME); | |
35 | ||
36 | bool Create(wxWindow *parent, | |
a290fa5a | 37 | wxWindowID id = wxID_ANY, |
1e6feb95 VZ |
38 | const wxPoint& pos = wxDefaultPosition, |
39 | const wxSize& size = wxDefaultSize, | |
40 | long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, | |
41 | const wxString& name = wxSPIN_BUTTON_NAME); | |
42 | ||
43 | // implement wxSpinButtonBase methods | |
44 | virtual int GetValue() const; | |
45 | virtual void SetValue(int val); | |
46 | virtual void SetRange(int minVal, int maxVal); | |
47 | ||
48 | // implement wxControlWithArrows methods | |
49 | virtual wxRenderer *GetRenderer() const { return m_renderer; } | |
50 | virtual wxWindow *GetWindow() { return this; } | |
51 | virtual bool IsVertical() const { return wxSpinButtonBase::IsVertical(); } | |
52 | virtual int GetArrowState(wxScrollArrows::Arrow arrow) const; | |
53 | virtual void SetArrowFlag(wxScrollArrows::Arrow arrow, int flag, bool set); | |
54 | virtual bool OnArrow(wxScrollArrows::Arrow arrow); | |
6236b8b4 | 55 | virtual wxScrollArrows::Arrow HitTestArrow(const wxPoint& pt) const; |
1e6feb95 VZ |
56 | |
57 | // for wxStdSpinButtonInputHandler | |
58 | const wxScrollArrows& GetArrows() { return m_arrows; } | |
59 | ||
6f02a879 VZ |
60 | virtual bool PerformAction(const wxControlAction& action, |
61 | long numArg = 0, | |
62 | const wxString& strArg = wxEmptyString); | |
63 | ||
9467bdb7 VZ |
64 | static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef); |
65 | virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef) | |
66 | { | |
67 | return GetStdInputHandler(handlerDef); | |
68 | } | |
69 | ||
1e6feb95 VZ |
70 | protected: |
71 | virtual wxSize DoGetBestClientSize() const; | |
72 | virtual void DoDraw(wxControlRenderer *renderer); | |
73 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
74 | ||
1e6feb95 VZ |
75 | // the common part of all ctors |
76 | void Init(); | |
77 | ||
78 | // normalize the value to fit into min..max range | |
79 | int NormalizeValue(int value) const; | |
80 | ||
a290fa5a | 81 | // change the value by +1/-1 and send the event, return true if value was |
1e6feb95 VZ |
82 | // changed |
83 | bool ChangeValue(int inc); | |
84 | ||
85 | // get the rectangles for our 2 arrows | |
86 | void CalcArrowRects(wxRect *rect1, wxRect *rect2) const; | |
87 | ||
88 | // the current controls value | |
89 | int m_value; | |
90 | ||
91 | private: | |
92 | // the object which manages our arrows | |
93 | wxScrollArrows m_arrows; | |
94 | ||
95 | // the state (combination of wxCONTROL_XXX flags) of the arrows | |
96 | int m_arrowsState[wxScrollArrows::Arrow_Max]; | |
97 | ||
98 | DECLARE_DYNAMIC_CLASS(wxSpinButton) | |
99 | }; | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // wxStdSpinButtonInputHandler: manages clicks on them (use arrows like | |
103 | // wxStdScrollBarInputHandler) and processes keyboard events too | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
53a2db12 | 106 | class WXDLLIMPEXP_CORE wxStdSpinButtonInputHandler : public wxStdInputHandler |
1e6feb95 VZ |
107 | { |
108 | public: | |
109 | wxStdSpinButtonInputHandler(wxInputHandler *inphand); | |
110 | ||
23645bfa | 111 | virtual bool HandleKey(wxInputConsumer *consumer, |
1e6feb95 VZ |
112 | const wxKeyEvent& event, |
113 | bool pressed); | |
23645bfa | 114 | virtual bool HandleMouse(wxInputConsumer *consumer, |
1e6feb95 | 115 | const wxMouseEvent& event); |
23645bfa | 116 | virtual bool HandleMouseMove(wxInputConsumer *consumer, |
1e6feb95 VZ |
117 | const wxMouseEvent& event); |
118 | }; | |
119 | ||
120 | #endif // _WX_UNIV_SPINBUTT_H_ | |
121 |