]>
Commit | Line | Data |
---|---|---|
f6bcfd97 | 1 | //////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/msw/spinctrl.h |
b782f2e0 VZ |
3 | // Purpose: wxSpinCtrl class declaration for Win32 |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 22.07.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
65571936 | 9 | // Licence: wxWindows licence |
b782f2e0 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_MSW_SPINCTRL_H_ | |
13 | #define _WX_MSW_SPINCTRL_H_ | |
14 | ||
b782f2e0 VZ |
15 | #include "wx/spinbutt.h" // the base class |
16 | ||
0e871ad0 WS |
17 | #if wxUSE_SPINCTRL |
18 | ||
6fe19057 | 19 | #include "wx/dynarray.h" |
d77254fc | 20 | |
b5dbe15d | 21 | class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; |
d5d29b8a | 22 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl *, wxArraySpins); |
6fe19057 | 23 | |
b782f2e0 VZ |
24 | // ---------------------------------------------------------------------------- |
25 | // Under Win32, wxSpinCtrl is a wxSpinButton with a buddy (as MSDN docs call | |
26 | // it) text window whose contents is automatically updated when the spin | |
27 | // control is clicked. | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
53a2db12 | 30 | class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinButton |
b782f2e0 VZ |
31 | { |
32 | public: | |
bcdeea5a | 33 | wxSpinCtrl() { Init(); } |
b782f2e0 VZ |
34 | |
35 | wxSpinCtrl(wxWindow *parent, | |
57f4f925 | 36 | wxWindowID id = wxID_ANY, |
678cd6de | 37 | const wxString& value = wxEmptyString, |
b782f2e0 VZ |
38 | const wxPoint& pos = wxDefaultPosition, |
39 | const wxSize& size = wxDefaultSize, | |
f1ddb476 | 40 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, |
b782f2e0 | 41 | int min = 0, int max = 100, int initial = 0, |
9a83f860 | 42 | const wxString& name = wxT("wxSpinCtrl")) |
b782f2e0 | 43 | { |
bcdeea5a VZ |
44 | Init(); |
45 | ||
678cd6de | 46 | Create(parent, id, value, pos, size, style, min, max, initial, name); |
b782f2e0 VZ |
47 | } |
48 | ||
49 | bool Create(wxWindow *parent, | |
57f4f925 | 50 | wxWindowID id = wxID_ANY, |
678cd6de | 51 | const wxString& value = wxEmptyString, |
b782f2e0 VZ |
52 | const wxPoint& pos = wxDefaultPosition, |
53 | const wxSize& size = wxDefaultSize, | |
f1ddb476 | 54 | long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, |
b782f2e0 | 55 | int min = 0, int max = 100, int initial = 0, |
9a83f860 | 56 | const wxString& name = wxT("wxSpinCtrl")); |
b782f2e0 | 57 | |
678cd6de VZ |
58 | // a wxTextCtrl-like method (but we can't have GetValue returning wxString |
59 | // because the base class already has one returning int!) | |
60 | void SetValue(const wxString& text); | |
61 | ||
07901ec9 VZ |
62 | // another wxTextCtrl-like method |
63 | void SetSelection(long from, long to); | |
64 | ||
9e565667 VZ |
65 | // wxSpinCtrlBase methods |
66 | virtual int GetBase() const; | |
67 | virtual bool SetBase(int base); | |
68 | ||
69 | ||
882a8f40 VZ |
70 | // implementation only from now on |
71 | // ------------------------------- | |
72 | ||
f6bcfd97 BP |
73 | virtual ~wxSpinCtrl(); |
74 | ||
eeea41ab | 75 | virtual void SetValue(int val); |
b44d69ba | 76 | virtual int GetValue() const; |
345ff9c6 | 77 | virtual void SetRange(int minVal, int maxVal); |
baccb514 | 78 | virtual bool SetFont(const wxFont &font); |
b44d69ba | 79 | virtual void SetFocus(); |
baccb514 | 80 | |
57f4f925 WS |
81 | virtual bool Enable(bool enable = true); |
82 | virtual bool Show(bool show = true); | |
882a8f40 | 83 | |
03d4194d VZ |
84 | virtual bool Reparent(wxWindowBase *newParent); |
85 | ||
f6bcfd97 BP |
86 | // wxSpinButton doesn't accept focus, but we do |
87 | virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); } | |
88 | ||
ddc4214a VZ |
89 | // we're like wxTextCtrl and not (default) wxButton |
90 | virtual wxVisualAttributes GetDefaultAttributes() const | |
91 | { | |
92 | return GetClassDefaultAttributes(GetWindowVariant()); | |
93 | } | |
94 | ||
95 | static wxVisualAttributes | |
96 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL) | |
97 | { | |
98 | return GetCompositeControlsDefaultAttributes(variant); | |
99 | } | |
100 | ||
6fe19057 VZ |
101 | // for internal use only |
102 | ||
103 | // get the subclassed window proc of the buddy text | |
104 | WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; } | |
105 | ||
106 | // return the spinctrl object whose buddy is the given window or NULL | |
107 | static wxSpinCtrl *GetSpinForTextCtrl(WXHWND hwndBuddy); | |
108 | ||
109 | // process a WM_COMMAND generated by the buddy text control | |
110 | bool ProcessTextCommand(WXWORD cmd, WXWORD id); | |
8614c467 | 111 | |
ea283460 VZ |
112 | // recognize buddy window as part of this control at wx level |
113 | virtual bool ContainsHWND(WXHWND hWnd) const { return hWnd == m_hwndBuddy; } | |
114 | ||
b782f2e0 | 115 | protected: |
f6bcfd97 | 116 | virtual void DoGetPosition(int *x, int *y) const; |
baccb514 | 117 | virtual void DoMoveWindow(int x, int y, int width, int height); |
f68586e5 | 118 | virtual wxSize DoGetBestSize() const; |
f6bcfd97 | 119 | virtual void DoGetSize(int *width, int *height) const; |
b7527dde | 120 | virtual void DoGetClientSize(int *x, int *y) const; |
74124ea9 VZ |
121 | #if wxUSE_TOOLTIPS |
122 | virtual void DoSetToolTip( wxToolTip *tip ); | |
123 | #endif // wxUSE_TOOLTIPS | |
b782f2e0 | 124 | |
177e38e6 RR |
125 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); |
126 | virtual bool MSWOnScroll(int orientation, WXWORD wParam, | |
127 | WXWORD pos, WXHWND control); | |
9750fc42 | 128 | |
d40e9e06 | 129 | // handle processing of special keys |
e08d628d | 130 | void OnChar(wxKeyEvent& event); |
c5c04fab | 131 | void OnSetFocus(wxFocusEvent& event); |
4c81b431 | 132 | void OnKillFocus(wxFocusEvent& event); |
e08d628d | 133 | |
d40e9e06 VZ |
134 | // generate spin control update event with the given value |
135 | void SendSpinUpdate(int value); | |
136 | ||
137 | // called to ensure that the value is in the correct range | |
1e8dba5e | 138 | virtual void NormalizeValue(); |
d40e9e06 VZ |
139 | |
140 | ||
141 | // the value of the control before the latest change (which might not have | |
142 | // changed anything in fact -- this is why we need this field) | |
143 | int m_oldValue; | |
144 | ||
f6bcfd97 BP |
145 | // the data for the "buddy" text ctrl |
146 | WXHWND m_hwndBuddy; | |
6fe19057 VZ |
147 | WXFARPROC m_wndProcBuddy; |
148 | ||
03647350 | 149 | // Block text update event after SetValue() |
ea6cbf48 RR |
150 | bool m_blockEvent; |
151 | ||
9750fc42 | 152 | private: |
bcdeea5a VZ |
153 | // Common part of all ctors. |
154 | void Init(); | |
155 | ||
9e565667 VZ |
156 | // Adjust the text control style depending on whether we need to enter only |
157 | // digits or may need to enter something else (e.g. "-" sign, "x" | |
158 | // hexadecimal prefix, ...) in it. | |
159 | void UpdateBuddyStyle(); | |
160 | ||
161 | ||
b782f2e0 | 162 | DECLARE_DYNAMIC_CLASS(wxSpinCtrl) |
9750fc42 | 163 | DECLARE_EVENT_TABLE() |
c0c133e1 | 164 | wxDECLARE_NO_COPY_CLASS(wxSpinCtrl); |
b782f2e0 VZ |
165 | }; |
166 | ||
0e871ad0 WS |
167 | #endif // wxUSE_SPINCTRL |
168 | ||
b782f2e0 VZ |
169 | #endif // _WX_MSW_SPINCTRL_H_ |
170 | ||
171 |