]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
value of wxTE_PASSWORD changed to be different from wxCANCEL
[wxWidgets.git] / src / msw / spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: spinbutt.cpp
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "spinbutt.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/wx.h"
33 #endif
34
35 // Can't resolve reference to CreateUpDownControl in
36 // TWIN32, but could probably use normal CreateWindow instead.
37
38 #if wxUSE_SPINBTN
39
40 #if defined(__WIN95__) && !defined(__TWIN32__)
41
42 #include "wx/spinbutt.h"
43 #include "wx/msw/private.h"
44
45 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
46 #include <commctrl.h>
47 #endif
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // wxWin macros
55 // ----------------------------------------------------------------------------
56
57 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
58 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
59
60 // ----------------------------------------------------------------------------
61 // wxSpinButton
62 // ----------------------------------------------------------------------------
63
64 bool wxSpinButton::Create(wxWindow *parent,
65 wxWindowID id,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxString& name)
70 {
71 // basic initialization
72 InitBase();
73
74 m_windowId = (id == -1) ? NewControlId() : id;
75
76 m_backgroundColour = parent->GetBackgroundColour() ;
77 m_foregroundColour = parent->GetForegroundColour() ;
78
79 SetName(name);
80
81 int x = pos.x;
82 int y = pos.y;
83 int width = size.x;
84 int height = size.y;
85
86 m_windowStyle = style;
87
88 SetParent(parent);
89
90 // get the right size for the control
91 if ( width <= 0 || height <= 0 )
92 {
93 wxSize size = DoGetBestSize();
94 if ( width <= 0 )
95 width = size.x;
96 if ( height <= 0 )
97 height = size.y;
98 }
99
100 if ( x < 0 )
101 x = 0;
102 if ( y < 0 )
103 y = 0;
104
105 // translate the styles
106 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
107 UDS_NOTHOUSANDS | // never useful, sometimes harmful
108 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
109
110 if ( m_windowStyle & wxSP_HORIZONTAL )
111 wstyle |= UDS_HORZ;
112 if ( m_windowStyle & wxSP_ARROW_KEYS )
113 wstyle |= UDS_ARROWKEYS;
114 if ( m_windowStyle & wxSP_WRAP )
115 wstyle |= UDS_WRAP;
116
117 // create the UpDown control.
118 m_hWnd = (WXHWND)CreateUpDownControl
119 (
120 wstyle,
121 x, y, width, height,
122 GetHwndOf(parent),
123 m_windowId,
124 wxGetInstance(),
125 NULL, // no buddy
126 m_max, m_min,
127 m_min // initial position
128 );
129
130 if ( !m_hWnd )
131 {
132 wxLogLastError("CreateUpDownControl");
133
134 return FALSE;
135 }
136
137 if ( parent )
138 {
139 parent->AddChild(this);
140 }
141
142 SubclassWin(m_hWnd);
143
144 return TRUE;
145 }
146
147 wxSpinButton::~wxSpinButton()
148 {
149 }
150
151 // ----------------------------------------------------------------------------
152 // size calculation
153 // ----------------------------------------------------------------------------
154
155 wxSize wxSpinButton::DoGetBestSize() const
156 {
157 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
158 {
159 // vertical control
160 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
161 2*GetSystemMetrics(SM_CYVSCROLL));
162 }
163 else
164 {
165 // horizontal control
166 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
167 GetSystemMetrics(SM_CYHSCROLL));
168 }
169 }
170
171 // ----------------------------------------------------------------------------
172 // Attributes
173 // ----------------------------------------------------------------------------
174
175 int wxSpinButton::GetValue() const
176 {
177 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
178 }
179
180 void wxSpinButton::SetValue(int val)
181 {
182 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
183 }
184
185 void wxSpinButton::SetRange(int minVal, int maxVal)
186 {
187 wxSpinButtonBase::SetRange(minVal, maxVal);
188 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
189 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
190 }
191
192 bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
193 WXWORD pos, WXHWND control)
194 {
195 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
196
197 if ( wParam != SB_THUMBPOSITION )
198 {
199 // probable SB_ENDSCROLL - we don't react to it
200 return FALSE;
201 }
202
203 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
204 event.SetPosition((short)pos); // cast is important for negative values!
205 event.SetEventObject(this);
206
207 return GetEventHandler()->ProcessEvent(event);
208 }
209
210 bool wxSpinButton::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
211 {
212 #ifndef __GNUWIN32__
213 #if defined(__BORLANDC__) || defined(__WATCOMC__)
214 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
215 #elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
216 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
217 #else
218 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
219 #endif
220
221 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
222 : wxEVT_SCROLL_LINEDOWN,
223 m_windowId);
224 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
225 event.SetEventObject(this);
226
227 bool processed = GetEventHandler()->ProcessEvent(event);
228
229 *result = event.IsAllowed() ? 0 : 1;
230
231 return processed;
232 #else // GnuWin32
233 return FALSE;
234 #endif
235 }
236
237 bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
238 {
239 // No command messages
240 return FALSE;
241 }
242
243 #endif // __WIN95__
244
245 #endif
246 // wxUSE_SPINCTN
247