]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
Documented help API extension and fixed gsocket compilation.
[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)
31528cd3 41 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
2bda0e17
KB
42#endif
43
31528cd3
VZ
44bool wxSpinButton::Create(wxWindow *parent,
45 wxWindowID id,
46 const wxPoint& pos,
47 const wxSize& size,
48 long style,
49 const wxString& name)
2bda0e17
KB
50{
51 wxSystemSettings settings;
fd71308f
JS
52 m_backgroundColour = parent->GetBackgroundColour() ;
53 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17
KB
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
31528cd3 75 InitBase();
2bda0e17
KB
76
77 m_windowId = (id == -1) ? NewControlId() : id;
78
79 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
31528cd3 80
2bda0e17 81 if ( m_windowStyle & wxSP_HORIZONTAL )
a23fd0e1 82 wstyle |= UDS_HORZ;
2bda0e17 83 if ( m_windowStyle & wxSP_ARROW_KEYS )
a23fd0e1 84 wstyle |= UDS_ARROWKEYS;
2bda0e17 85 if ( m_windowStyle & wxSP_WRAP )
a23fd0e1 86 wstyle |= UDS_WRAP;
2bda0e17
KB
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,
a23fd0e1 95 m_min, m_max, m_min);
2bda0e17
KB
96
97 m_hWnd = (WXHWND) hWndListControl;
98 if (parent) parent->AddChild(this);
99
100 // TODO: have this for all controls.
101 if ( !m_hWnd )
a23fd0e1 102 return FALSE;
31528cd3 103
2bda0e17
KB
104 SubclassWin((WXHWND) m_hWnd);
105
106 return TRUE;
107}
108
a23fd0e1 109wxSpinButton::~wxSpinButton()
2bda0e17
KB
110{
111}
112
113// Attributes
114////////////////////////////////////////////////////////////////////////////
115
a23fd0e1 116int wxSpinButton::GetValue() const
2bda0e17 117{
d1d7cdff 118 return LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
119}
120
debe6624 121void wxSpinButton::SetValue(int val)
2bda0e17 122{
d1d7cdff 123 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
2bda0e17
KB
124}
125
debe6624 126void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 127{
31528cd3 128 wxSpinButtonBase::SetRange(minVal, maxVal);
d1d7cdff 129 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
3d7e30a4 130 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
2bda0e17
KB
131}
132
a23fd0e1
VZ
133bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
134 WXWORD pos, WXHWND control)
2bda0e17 135{
a23fd0e1
VZ
136 if ( !control )
137 return FALSE;
138
7798a18e 139 wxSpinEvent event(wxEVT_NULL, m_windowId);
2bda0e17 140 event.SetPosition(pos);
a23fd0e1
VZ
141 event.SetOrientation(orientation);
142 event.SetEventObject(this);
2bda0e17 143
a23fd0e1
VZ
144 switch ( wParam )
145 {
146 case SB_TOP:
147 event.m_eventType = wxEVT_SCROLL_TOP;
148 break;
2bda0e17 149
a23fd0e1
VZ
150 case SB_BOTTOM:
151 event.m_eventType = wxEVT_SCROLL_BOTTOM;
152 break;
2bda0e17 153
a23fd0e1
VZ
154 case SB_LINEUP:
155 event.m_eventType = wxEVT_SCROLL_LINEUP;
156 break;
2bda0e17 157
a23fd0e1
VZ
158 case SB_LINEDOWN:
159 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
160 break;
2bda0e17 161
a23fd0e1
VZ
162 case SB_PAGEUP:
163 event.m_eventType = wxEVT_SCROLL_PAGEUP;
164 break;
2bda0e17 165
a23fd0e1
VZ
166 case SB_PAGEDOWN:
167 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
168 break;
2bda0e17
KB
169
170 case SB_THUMBTRACK:
171 case SB_THUMBPOSITION:
a23fd0e1
VZ
172 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
173 break;
2bda0e17 174
a23fd0e1
VZ
175 default:
176 return FALSE;
177 }
2bda0e17 178
a23fd0e1 179 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
180}
181
debe6624 182bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 183{
a23fd0e1
VZ
184 // No command messages
185 return FALSE;
2bda0e17
KB
186}
187
a23fd0e1 188#endif // __WIN95__