]> git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
compilation fix
[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 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 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 if ( !control )
137 return FALSE;
138
139 wxSpinEvent event(wxEVT_NULL, m_windowId);
140 event.SetPosition(pos);
141 event.SetOrientation(orientation);
142 event.SetEventObject(this);
143
144 switch ( wParam )
145 {
146 case SB_TOP:
147 event.m_eventType = wxEVT_SCROLL_TOP;
148 break;
149
150 case SB_BOTTOM:
151 event.m_eventType = wxEVT_SCROLL_BOTTOM;
152 break;
153
154 case SB_LINEUP:
155 event.m_eventType = wxEVT_SCROLL_LINEUP;
156 break;
157
158 case SB_LINEDOWN:
159 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
160 break;
161
162 case SB_PAGEUP:
163 event.m_eventType = wxEVT_SCROLL_PAGEUP;
164 break;
165
166 case SB_PAGEDOWN:
167 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
168 break;
169
170 case SB_THUMBTRACK:
171 case SB_THUMBPOSITION:
172 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
173 break;
174
175 default:
176 return FALSE;
177 }
178
179 return GetEventHandler()->ProcessEvent(event);
180 }
181
182 bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
183 {
184 // No command messages
185 return FALSE;
186 }
187
188 #endif // __WIN95__