]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
removed some unneeded bit of test code
[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 #ifdef __GNUG__
13 #pragma implementation "spinbutt.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 // Can't resolve reference to CreateUpDownControl in
28 // TWIN32, but could probably use normal CreateWindow instead.
29
30 #if defined(__WIN95__) && !defined(__TWIN32__)
31
32 #include "wx/spinbutt.h"
33 #include "wx/msw/private.h"
34
35 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
36 #include <commctrl.h>
37 #endif
38
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
41 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
42 #endif
43
44 bool wxSpinButton::Create(wxWindow *parent,
45 wxWindowID id,
46 const wxPoint& pos,
47 const wxSize& size,
48 long style,
49 const wxString& name)
50 {
51 wxSystemSettings settings;
52 m_backgroundColour = parent->GetBackgroundColour() ;
53 m_foregroundColour = parent->GetForegroundColour() ;
54
55 SetName(name);
56
57 int x = pos.x;
58 int y = pos.y;
59 int width = size.x;
60 int height = size.y;
61
62 m_windowStyle = style;
63
64 SetParent(parent);
65
66 if (width <= 0)
67 width = 100;
68 if (height <= 0)
69 height = 30;
70 if (x < 0)
71 x = 0;
72 if (y < 0)
73 y = 0;
74
75 InitBase();
76
77 m_windowId = (id == -1) ? NewControlId() : id;
78
79 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
80
81 if ( m_windowStyle & wxSP_HORIZONTAL )
82 wstyle |= UDS_HORZ;
83 if ( m_windowStyle & wxSP_ARROW_KEYS )
84 wstyle |= UDS_ARROWKEYS;
85 if ( m_windowStyle & wxSP_WRAP )
86 wstyle |= UDS_WRAP;
87
88 // Create the ListView control.
89 HWND hWndListControl = CreateUpDownControl(wstyle,
90 x, y, width, height,
91 (HWND) parent->GetHWND(),
92 m_windowId,
93 wxGetInstance(),
94 0,
95 m_min, m_max, m_min);
96
97 m_hWnd = (WXHWND) hWndListControl;
98 if (parent) parent->AddChild(this);
99
100 // TODO: have this for all controls.
101 if ( !m_hWnd )
102 return FALSE;
103
104 SubclassWin((WXHWND) m_hWnd);
105
106 return TRUE;
107 }
108
109 wxSpinButton::~wxSpinButton()
110 {
111 }
112
113 // Attributes
114 ////////////////////////////////////////////////////////////////////////////
115
116 int wxSpinButton::GetValue() const
117 {
118 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
119 }
120
121 void wxSpinButton::SetValue(int val)
122 {
123 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
124 }
125
126 void wxSpinButton::SetRange(int minVal, int maxVal)
127 {
128 wxSpinButtonBase::SetRange(minVal, maxVal);
129 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
130 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
131 }
132
133 bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
134 WXWORD pos, WXHWND control)
135 {
136 wxCHECK_MSG( control, FALSE, _T("scrolling what?") )
137
138 if ( wParam != SB_THUMBPOSITION )
139 {
140 // probable SB_ENDSCROLL - we don't react to it
141 return FALSE;
142 }
143
144 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
145 event.SetPosition((short)pos); // cast is important for negative values!
146 event.SetEventObject(this);
147
148 return GetEventHandler()->ProcessEvent(event);
149 }
150
151 bool wxSpinButton::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
152 {
153 #ifndef __GNUWIN32__
154 #ifdef __BORLANDC__
155 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
156 #elif defined(__VISUALC__) && (__VISUALC__ == 1010)
157 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
158 #else
159 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
160 #endif
161
162 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
163 : wxEVT_SCROLL_LINEDOWN,
164 m_windowId);
165 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
166 event.SetEventObject(this);
167
168 bool processed = GetEventHandler()->ProcessEvent(event);
169
170 *result = event.IsAllowed() ? 0 : 1;
171
172 return processed;
173 #else
174 return FALSE;
175 #endif
176 }
177
178 bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
179 {
180 // No command messages
181 return FALSE;
182 }
183
184 #endif // __WIN95__