]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1. minor fixes in wxDynLib
[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__)
36 #include <commctrl.h>
37 #endif
38
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
41 #endif
42
43 wxSpinButton::wxSpinButton()
44 {
45 m_min = 0;
46 m_max = 100;
47 }
48
49 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
50 long style, const wxString& name)
51 {
52 wxSystemSettings settings;
53 m_backgroundColour = parent->GetBackgroundColour() ;
54 m_foregroundColour = parent->GetForegroundColour() ;
55
56 SetName(name);
57
58 int x = pos.x;
59 int y = pos.y;
60 int width = size.x;
61 int height = size.y;
62
63 m_windowStyle = style;
64
65 SetParent(parent);
66
67 if (width <= 0)
68 width = 100;
69 if (height <= 0)
70 height = 30;
71 if (x < 0)
72 x = 0;
73 if (y < 0)
74 y = 0;
75
76 m_min = 0;
77 m_max = 100;
78
79 m_windowId = (id == -1) ? NewControlId() : id;
80
81 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
82
83 if ( m_windowStyle & wxSP_HORIZONTAL )
84 wstyle |= UDS_HORZ;
85 if ( m_windowStyle & wxSP_ARROW_KEYS )
86 wstyle |= UDS_ARROWKEYS;
87 if ( m_windowStyle & wxSP_WRAP )
88 wstyle |= UDS_WRAP;
89
90 // Create the ListView control.
91 HWND hWndListControl = CreateUpDownControl(wstyle,
92 x, y, width, height,
93 (HWND) parent->GetHWND(),
94 m_windowId,
95 wxGetInstance(),
96 0,
97 m_min, m_max, m_min);
98
99 m_hWnd = (WXHWND) hWndListControl;
100 if (parent) parent->AddChild(this);
101
102 // TODO: have this for all controls.
103 if ( !m_hWnd )
104 return FALSE;
105
106 SubclassWin((WXHWND) m_hWnd);
107
108 return TRUE;
109 }
110
111 wxSpinButton::~wxSpinButton()
112 {
113 }
114
115 // Attributes
116 ////////////////////////////////////////////////////////////////////////////
117
118 int wxSpinButton::GetValue() const
119 {
120 return LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
121 }
122
123 void wxSpinButton::SetValue(int val)
124 {
125 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
126 }
127
128 void wxSpinButton::SetRange(int minVal, int maxVal)
129 {
130 m_min = minVal;
131 m_max = maxVal;
132 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
133 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
134 }
135
136 bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
137 WXWORD pos, WXHWND control)
138 {
139 if ( !control )
140 return FALSE;
141
142 wxSpinEvent event(wxEVT_NULL, m_windowId);
143 event.SetPosition(pos);
144 event.SetOrientation(orientation);
145 event.SetEventObject(this);
146
147 switch ( wParam )
148 {
149 case SB_TOP:
150 event.m_eventType = wxEVT_SCROLL_TOP;
151 break;
152
153 case SB_BOTTOM:
154 event.m_eventType = wxEVT_SCROLL_BOTTOM;
155 break;
156
157 case SB_LINEUP:
158 event.m_eventType = wxEVT_SCROLL_LINEUP;
159 break;
160
161 case SB_LINEDOWN:
162 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
163 break;
164
165 case SB_PAGEUP:
166 event.m_eventType = wxEVT_SCROLL_PAGEUP;
167 break;
168
169 case SB_PAGEDOWN:
170 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
171 break;
172
173 case SB_THUMBTRACK:
174 case SB_THUMBPOSITION:
175 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
176 break;
177
178 default:
179 return FALSE;
180 }
181
182 return GetEventHandler()->ProcessEvent(event);
183 }
184
185 bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
186 {
187 // No command messages
188 return FALSE;
189 }
190
191 // Spin event
192 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
193
194 wxSpinEvent::wxSpinEvent(wxEventType commandType, int id)
195 : wxScrollEvent(commandType, id)
196 {
197 }
198
199 #endif // __WIN95__