]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/spinctrl.h
The rounded corners look really dumb at this size.
[wxWidgets.git] / include / wx / msw / spinctrl.h
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
11 #ifndef _WX_MSW_SPINCTRL_H_
12 #define _WX_MSW_SPINCTRL_H_
13
14 #include "wx/spinbutt.h" // the base class
15
16 #if wxUSE_SPINCTRL
17
18 #include "wx/dynarray.h"
19
20 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
21 WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl *, wxArraySpins);
22
23 // ----------------------------------------------------------------------------
24 // Under Win32, wxSpinCtrl is a wxSpinButton with a buddy (as MSDN docs call
25 // it) text window whose contents is automatically updated when the spin
26 // control is clicked.
27 // ----------------------------------------------------------------------------
28
29 class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinButton
30 {
31 public:
32 wxSpinCtrl() { Init(); }
33
34 wxSpinCtrl(wxWindow *parent,
35 wxWindowID id = wxID_ANY,
36 const wxString& value = wxEmptyString,
37 const wxPoint& pos = wxDefaultPosition,
38 const wxSize& size = wxDefaultSize,
39 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
40 int min = 0, int max = 100, int initial = 0,
41 const wxString& name = wxT("wxSpinCtrl"))
42 {
43 Init();
44
45 Create(parent, id, value, pos, size, style, min, max, initial, name);
46 }
47
48 bool Create(wxWindow *parent,
49 wxWindowID id = wxID_ANY,
50 const wxString& value = wxEmptyString,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
54 int min = 0, int max = 100, int initial = 0,
55 const wxString& name = wxT("wxSpinCtrl"));
56
57 // a wxTextCtrl-like method (but we can't have GetValue returning wxString
58 // because the base class already has one returning int!)
59 void SetValue(const wxString& text);
60
61 // another wxTextCtrl-like method
62 void SetSelection(long from, long to);
63
64 // wxSpinCtrlBase methods
65 virtual int GetBase() const;
66 virtual bool SetBase(int base);
67
68
69 // implementation only from now on
70 // -------------------------------
71
72 virtual ~wxSpinCtrl();
73
74 virtual void SetValue(int val);
75 virtual int GetValue() const;
76 virtual void SetRange(int minVal, int maxVal);
77 virtual bool SetFont(const wxFont &font);
78 virtual void SetFocus();
79
80 virtual bool Enable(bool enable = true);
81 virtual bool Show(bool show = true);
82
83 virtual bool Reparent(wxWindowBase *newParent);
84
85 // wxSpinButton doesn't accept focus, but we do
86 virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
87
88 // we're like wxTextCtrl and not (default) wxButton
89 virtual wxVisualAttributes GetDefaultAttributes() const
90 {
91 return GetClassDefaultAttributes(GetWindowVariant());
92 }
93
94 static wxVisualAttributes
95 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
96 {
97 return GetCompositeControlsDefaultAttributes(variant);
98 }
99
100 // for internal use only
101
102 // get the subclassed window proc of the buddy text
103 WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
104
105 // return the spinctrl object whose buddy is the given window or NULL
106 static wxSpinCtrl *GetSpinForTextCtrl(WXHWND hwndBuddy);
107
108 // process a WM_COMMAND generated by the buddy text control
109 bool ProcessTextCommand(WXWORD cmd, WXWORD id);
110
111 // recognize buddy window as part of this control at wx level
112 virtual bool ContainsHWND(WXHWND hWnd) const { return hWnd == m_hwndBuddy; }
113
114 protected:
115 virtual void DoGetPosition(int *x, int *y) const;
116 virtual void DoMoveWindow(int x, int y, int width, int height);
117 virtual wxSize DoGetBestSize() const;
118 virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
119 virtual void DoGetSize(int *width, int *height) const;
120 virtual void DoGetClientSize(int *x, int *y) const;
121 #if wxUSE_TOOLTIPS
122 virtual void DoSetToolTip( wxToolTip *tip );
123 #endif // wxUSE_TOOLTIPS
124
125 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
126 virtual bool MSWOnScroll(int orientation, WXWORD wParam,
127 WXWORD pos, WXHWND control);
128
129 // handle processing of special keys
130 void OnChar(wxKeyEvent& event);
131 void OnSetFocus(wxFocusEvent& event);
132 void OnKillFocus(wxFocusEvent& event);
133
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
138 virtual void NormalizeValue();
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
145 // the data for the "buddy" text ctrl
146 WXHWND m_hwndBuddy;
147 WXFARPROC m_wndProcBuddy;
148
149 // Block text update event after SetValue()
150 bool m_blockEvent;
151
152 private:
153 // Common part of all ctors.
154 void Init();
155
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
162 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
163 DECLARE_EVENT_TABLE()
164 wxDECLARE_NO_COPY_CLASS(wxSpinCtrl);
165 };
166
167 #endif // wxUSE_SPINCTRL
168
169 #endif // _WX_MSW_SPINCTRL_H_
170
171