1 ////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/spinctrl.h
3 // Purpose: wxSpinCtrl class declaration for Win32
4 // Author: Vadim Zeitlin
7 // Copyright: (c) Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_MSW_SPINCTRL_H_
12 #define _WX_MSW_SPINCTRL_H_
14 #include "wx/spinbutt.h" // the base class
18 #include "wx/dynarray.h"
20 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
21 WX_DEFINE_EXPORTED_ARRAY_PTR(wxSpinCtrl
*, wxArraySpins
);
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 // ----------------------------------------------------------------------------
29 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxSpinButton
32 wxSpinCtrl() { Init(); }
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"))
45 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
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"));
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
);
61 // another wxTextCtrl-like method
62 void SetSelection(long from
, long to
);
64 // wxSpinCtrlBase methods
65 virtual int GetBase() const;
66 virtual bool SetBase(int base
);
69 // implementation only from now on
70 // -------------------------------
72 virtual ~wxSpinCtrl();
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();
80 virtual bool Enable(bool enable
= true);
81 virtual bool Show(bool show
= true);
83 virtual bool Reparent(wxWindowBase
*newParent
);
85 // wxSpinButton doesn't accept focus, but we do
86 virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
88 // we're like wxTextCtrl and not (default) wxButton
89 virtual wxVisualAttributes
GetDefaultAttributes() const
91 return GetClassDefaultAttributes(GetWindowVariant());
94 static wxVisualAttributes
95 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
97 return GetCompositeControlsDefaultAttributes(variant
);
100 // for internal use only
102 // get the subclassed window proc of the buddy text
103 WXFARPROC
GetBuddyWndProc() const { return m_wndProcBuddy
; }
105 // return the spinctrl object whose buddy is the given window or NULL
106 static wxSpinCtrl
*GetSpinForTextCtrl(WXHWND hwndBuddy
);
108 // process a WM_COMMAND generated by the buddy text control
109 bool ProcessTextCommand(WXWORD cmd
, WXWORD id
);
111 // recognize buddy window as part of this control at wx level
112 virtual bool ContainsHWND(WXHWND hWnd
) const { return hWnd
== m_hwndBuddy
; }
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;
122 virtual void DoSetToolTip( wxToolTip
*tip
);
123 #endif // wxUSE_TOOLTIPS
125 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
126 virtual bool MSWOnScroll(int orientation
, WXWORD wParam
,
127 WXWORD pos
, WXHWND control
);
129 // handle processing of special keys
130 void OnChar(wxKeyEvent
& event
);
131 void OnSetFocus(wxFocusEvent
& event
);
132 void OnKillFocus(wxFocusEvent
& event
);
134 // generate spin control update event with the given value
135 void SendSpinUpdate(int value
);
137 // called to ensure that the value is in the correct range
138 virtual void NormalizeValue();
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)
145 // the data for the "buddy" text ctrl
147 WXFARPROC m_wndProcBuddy
;
149 // Block text update event after SetValue()
153 // Common part of all ctors.
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();
162 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
163 DECLARE_EVENT_TABLE()
164 wxDECLARE_NO_COPY_CLASS(wxSpinCtrl
);
167 #endif // wxUSE_SPINCTRL
169 #endif // _WX_MSW_SPINCTRL_H_