]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
Finished MingW32 makefiles
[wxWidgets.git] / src / msw / spinbutt.cpp
CommitLineData
2bda0e17
KB
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
a23fd0e1 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
a23fd0e1 13 #pragma implementation "spinbutt.h"
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
a23fd0e1 20 #pragma hdrstop
2bda0e17
KB
21#endif
22
23#ifndef WX_PRECOMP
a23fd0e1 24 #include "wx/wx.h"
2bda0e17
KB
25#endif
26
57c208c5
JS
27// Can't resolve reference to CreateUpDownControl in
28// TWIN32, but could probably use normal CreateWindow instead.
29
30#if defined(__WIN95__) && !defined(__TWIN32__)
2bda0e17
KB
31
32#include "wx/spinbutt.h"
33#include "wx/msw/private.h"
34
57c208c5 35#if !defined(__GNUWIN32__) || defined(__TWIN32__)
a23fd0e1 36 #include <commctrl.h>
2bda0e17
KB
37#endif
38
39#if !USE_SHARED_LIBRARY
a23fd0e1 40 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
2bda0e17
KB
41#endif
42
a23fd0e1 43wxSpinButton::wxSpinButton()
2bda0e17 44{
a23fd0e1
VZ
45 m_min = 0;
46 m_max = 100;
2bda0e17
KB
47}
48
debe6624
JS
49bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
50 long style, const wxString& name)
2bda0e17
KB
51{
52 wxSystemSettings settings;
fd71308f
JS
53 m_backgroundColour = parent->GetBackgroundColour() ;
54 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17
KB
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 )
a23fd0e1 84 wstyle |= UDS_HORZ;
2bda0e17 85 if ( m_windowStyle & wxSP_ARROW_KEYS )
a23fd0e1 86 wstyle |= UDS_ARROWKEYS;
2bda0e17 87 if ( m_windowStyle & wxSP_WRAP )
a23fd0e1 88 wstyle |= UDS_WRAP;
2bda0e17
KB
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,
a23fd0e1 97 m_min, m_max, m_min);
2bda0e17
KB
98
99 m_hWnd = (WXHWND) hWndListControl;
100 if (parent) parent->AddChild(this);
101
102 // TODO: have this for all controls.
103 if ( !m_hWnd )
a23fd0e1 104 return FALSE;
2bda0e17
KB
105
106 SubclassWin((WXHWND) m_hWnd);
107
108 return TRUE;
109}
110
a23fd0e1 111wxSpinButton::~wxSpinButton()
2bda0e17
KB
112{
113}
114
115// Attributes
116////////////////////////////////////////////////////////////////////////////
117
a23fd0e1 118int wxSpinButton::GetValue() const
2bda0e17 119{
d1d7cdff 120 return LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
121}
122
debe6624 123void wxSpinButton::SetValue(int val)
2bda0e17 124{
d1d7cdff 125 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
2bda0e17
KB
126}
127
debe6624 128void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 129{
a23fd0e1
VZ
130 m_min = minVal;
131 m_max = maxVal;
d1d7cdff 132 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
3d7e30a4 133 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
2bda0e17
KB
134}
135
a23fd0e1
VZ
136bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
137 WXWORD pos, WXHWND control)
2bda0e17 138{
a23fd0e1
VZ
139 if ( !control )
140 return FALSE;
141
7798a18e 142 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17 143 event.SetPosition(pos);
a23fd0e1
VZ
144 event.SetOrientation(orientation);
145 event.SetEventObject(this);
2bda0e17 146
a23fd0e1
VZ
147 switch ( wParam )
148 {
149 case SB_TOP:
150 event.m_eventType = wxEVT_SCROLL_TOP;
151 break;
2bda0e17 152
a23fd0e1
VZ
153 case SB_BOTTOM:
154 event.m_eventType = wxEVT_SCROLL_BOTTOM;
155 break;
2bda0e17 156
a23fd0e1
VZ
157 case SB_LINEUP:
158 event.m_eventType = wxEVT_SCROLL_LINEUP;
159 break;
2bda0e17 160
a23fd0e1
VZ
161 case SB_LINEDOWN:
162 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
163 break;
2bda0e17 164
a23fd0e1
VZ
165 case SB_PAGEUP:
166 event.m_eventType = wxEVT_SCROLL_PAGEUP;
167 break;
2bda0e17 168
a23fd0e1
VZ
169 case SB_PAGEDOWN:
170 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
171 break;
2bda0e17
KB
172
173 case SB_THUMBTRACK:
174 case SB_THUMBPOSITION:
a23fd0e1
VZ
175 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
176 break;
2bda0e17 177
a23fd0e1
VZ
178 default:
179 return FALSE;
180 }
2bda0e17 181
a23fd0e1 182 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
183}
184
debe6624 185bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 186{
a23fd0e1
VZ
187 // No command messages
188 return FALSE;
2bda0e17
KB
189}
190
191// Spin event
192IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
193
a23fd0e1
VZ
194wxSpinEvent::wxSpinEvent(wxEventType commandType, int id)
195 : wxScrollEvent(commandType, id)
2bda0e17
KB
196{
197}
198
a23fd0e1 199#endif // __WIN95__