]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
wxMSW::wxTreeCtrl has multiple selection too (somewhat documented)
[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{
0655ad29 118 return (short)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{
0655ad29 136 wxCHECK_MSG( control, FALSE, _T("scrolling what?") )
2bda0e17 137
0655ad29 138 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 139 {
0655ad29
VZ
140 // probable SB_ENDSCROLL - we don't react to it
141 return FALSE;
142 }
2bda0e17 143
0655ad29
VZ
144 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
145 event.SetPosition((short)pos); // cast is important for negative values!
146 event.SetEventObject(this);
2bda0e17 147
0655ad29
VZ
148 return GetEventHandler()->ProcessEvent(event);
149}
2bda0e17 150
0655ad29
VZ
151bool wxSpinButton::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
152{
8a4df159 153#ifndef __GNUWIN32__
0655ad29 154 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
2bda0e17 155
0655ad29
VZ
156 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
157 : wxEVT_SCROLL_LINEDOWN,
158 m_windowId);
159 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
160 event.SetEventObject(this);
2bda0e17 161
0655ad29 162 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 163
0655ad29 164 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 165
0655ad29 166 return processed;
8a4df159
RR
167#else
168 return FALSE;
169#endif
2bda0e17
KB
170}
171
debe6624 172bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 173{
a23fd0e1
VZ
174 // No command messages
175 return FALSE;
2bda0e17
KB
176}
177
a23fd0e1 178#endif // __WIN95__