]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/spinctrl.h
When handling accelerators in wxWebView make sure that we do not block right-alt...
[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 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_SPINCTRL_H_
13 #define _WX_MSW_SPINCTRL_H_
14
15 #include "wx/spinbutt.h" // the base class
16
17 #if wxUSE_SPINCTRL
18
19 #include "wx/dynarray.h"
20
21 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
22 WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl *, wxArraySpins);
23
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
30 class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinButton
31 {
32 public:
33 wxSpinCtrl() { Init(); }
34
35 wxSpinCtrl(wxWindow *parent,
36 wxWindowID id = wxID_ANY,
37 const wxString& value = wxEmptyString,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
41 int min = 0, int max = 100, int initial = 0,
42 const wxString& name = wxT("wxSpinCtrl"))
43 {
44 Init();
45
46 Create(parent, id, value, pos, size, style, min, max, initial, name);
47 }
48
49 bool Create(wxWindow *parent,
50 wxWindowID id = wxID_ANY,
51 const wxString& value = wxEmptyString,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
54 long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
55 int min = 0, int max = 100, int initial = 0,
56 const wxString& name = wxT("wxSpinCtrl"));
57
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
62 // another wxTextCtrl-like method
63 void SetSelection(long from, long to);
64
65 // wxSpinCtrlBase methods
66 virtual int GetBase() const;
67 virtual bool SetBase(int base);
68
69
70 // implementation only from now on
71 // -------------------------------
72
73 virtual ~wxSpinCtrl();
74
75 virtual void SetValue(int val);
76 virtual int GetValue() const;
77 virtual void SetRange(int minVal, int maxVal);
78 virtual bool SetFont(const wxFont &font);
79 virtual void SetFocus();
80
81 virtual bool Enable(bool enable = true);
82 virtual bool Show(bool show = true);
83
84 virtual bool Reparent(wxWindowBase *newParent);
85
86 // wxSpinButton doesn't accept focus, but we do
87 virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
88
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
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);
111
112 // recognize buddy window as part of this control at wx level
113 virtual bool ContainsHWND(WXHWND hWnd) const { return hWnd == m_hwndBuddy; }
114
115 protected:
116 virtual void DoGetPosition(int *x, int *y) const;
117 virtual void DoMoveWindow(int x, int y, int width, int height);
118 virtual wxSize DoGetBestSize() const;
119 virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
120 virtual void DoGetSize(int *width, int *height) const;
121 virtual void DoGetClientSize(int *x, int *y) const;
122 #if wxUSE_TOOLTIPS
123 virtual void DoSetToolTip( wxToolTip *tip );
124 #endif // wxUSE_TOOLTIPS
125
126 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
127 virtual bool MSWOnScroll(int orientation, WXWORD wParam,
128 WXWORD pos, WXHWND control);
129
130 // handle processing of special keys
131 void OnChar(wxKeyEvent& event);
132 void OnSetFocus(wxFocusEvent& event);
133 void OnKillFocus(wxFocusEvent& event);
134
135 // generate spin control update event with the given value
136 void SendSpinUpdate(int value);
137
138 // called to ensure that the value is in the correct range
139 virtual void NormalizeValue();
140
141
142 // the value of the control before the latest change (which might not have
143 // changed anything in fact -- this is why we need this field)
144 int m_oldValue;
145
146 // the data for the "buddy" text ctrl
147 WXHWND m_hwndBuddy;
148 WXFARPROC m_wndProcBuddy;
149
150 // Block text update event after SetValue()
151 bool m_blockEvent;
152
153 private:
154 // Common part of all ctors.
155 void Init();
156
157 // Adjust the text control style depending on whether we need to enter only
158 // digits or may need to enter something else (e.g. "-" sign, "x"
159 // hexadecimal prefix, ...) in it.
160 void UpdateBuddyStyle();
161
162
163 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
164 DECLARE_EVENT_TABLE()
165 wxDECLARE_NO_COPY_CLASS(wxSpinCtrl);
166 };
167
168 #endif // wxUSE_SPINCTRL
169
170 #endif // _WX_MSW_SPINCTRL_H_
171
172