]> git.saurik.com Git - wxWidgets.git/blame - src/msw/spinbutt.cpp
added some utils (tex2rtf, helpgen, makegen) to make system
[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
b782f2e0
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
a23fd0e1 21 #pragma implementation "spinbutt.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
a23fd0e1 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
a23fd0e1 32 #include "wx/wx.h"
2bda0e17
KB
33#endif
34
57c208c5
JS
35// Can't resolve reference to CreateUpDownControl in
36// TWIN32, but could probably use normal CreateWindow instead.
37
0e528b99
JS
38#if wxUSE_SPINBTN
39
57c208c5 40#if defined(__WIN95__) && !defined(__TWIN32__)
2bda0e17
KB
41
42#include "wx/spinbutt.h"
43#include "wx/msw/private.h"
44
65fd5cb0 45#if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
a23fd0e1 46 #include <commctrl.h>
2bda0e17
KB
47#endif
48
b782f2e0
VZ
49// ============================================================================
50// implementation
51// ============================================================================
52
53// ----------------------------------------------------------------------------
54// wxWin macros
55// ----------------------------------------------------------------------------
56
9750fc42
VZ
57IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
58IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
2bda0e17 59
b782f2e0
VZ
60// ----------------------------------------------------------------------------
61// wxSpinButton
62// ----------------------------------------------------------------------------
63
31528cd3
VZ
64bool wxSpinButton::Create(wxWindow *parent,
65 wxWindowID id,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxString& name)
2bda0e17 70{
b782f2e0
VZ
71 // basic initialization
72 InitBase();
2bda0e17 73
b782f2e0 74 m_windowId = (id == -1) ? NewControlId() : id;
2bda0e17 75
b782f2e0
VZ
76 m_backgroundColour = parent->GetBackgroundColour() ;
77 m_foregroundColour = parent->GetForegroundColour() ;
2bda0e17 78
b782f2e0 79 SetName(name);
2bda0e17 80
b782f2e0
VZ
81 int x = pos.x;
82 int y = pos.y;
83 int width = size.x;
84 int height = size.y;
2bda0e17 85
b782f2e0 86 m_windowStyle = style;
2bda0e17 87
b782f2e0 88 SetParent(parent);
2bda0e17 89
b782f2e0
VZ
90 // get the right size for the control
91 if ( width <= 0 || height <= 0 )
92 {
93 wxSize size = DoGetBestSize();
94 if ( width <= 0 )
95 width = size.x;
96 if ( height <= 0 )
97 height = size.y;
98 }
2bda0e17 99
b782f2e0
VZ
100 if ( x < 0 )
101 x = 0;
102 if ( y < 0 )
103 y = 0;
104
105 // translate the styles
106 DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP |
882a8f40
VZ
107 UDS_NOTHOUSANDS | // never useful, sometimes harmful
108 UDS_SETBUDDYINT; // it doesn't harm if we don't have buddy
b782f2e0
VZ
109
110 if ( m_windowStyle & wxSP_HORIZONTAL )
111 wstyle |= UDS_HORZ;
112 if ( m_windowStyle & wxSP_ARROW_KEYS )
113 wstyle |= UDS_ARROWKEYS;
114 if ( m_windowStyle & wxSP_WRAP )
115 wstyle |= UDS_WRAP;
116
117 // create the UpDown control.
118 m_hWnd = (WXHWND)CreateUpDownControl
119 (
120 wstyle,
121 x, y, width, height,
122 GetHwndOf(parent),
123 m_windowId,
124 wxGetInstance(),
125 NULL, // no buddy
126 m_max, m_min,
127 m_min // initial position
128 );
129
130 if ( !m_hWnd )
131 {
132 wxLogLastError("CreateUpDownControl");
2bda0e17 133
b782f2e0
VZ
134 return FALSE;
135 }
2bda0e17 136
b782f2e0
VZ
137 if ( parent )
138 {
139 parent->AddChild(this);
140 }
31528cd3 141
b782f2e0 142 SubclassWin(m_hWnd);
2bda0e17 143
b782f2e0 144 return TRUE;
2bda0e17
KB
145}
146
a23fd0e1 147wxSpinButton::~wxSpinButton()
2bda0e17
KB
148{
149}
150
b782f2e0
VZ
151// ----------------------------------------------------------------------------
152// size calculation
153// ----------------------------------------------------------------------------
154
f68586e5 155wxSize wxSpinButton::DoGetBestSize() const
b782f2e0
VZ
156{
157 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
158 {
159 // vertical control
160 return wxSize(GetSystemMetrics(SM_CXVSCROLL),
161 2*GetSystemMetrics(SM_CYVSCROLL));
162 }
163 else
164 {
165 // horizontal control
166 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL),
167 GetSystemMetrics(SM_CYHSCROLL));
168 }
169}
170
171// ----------------------------------------------------------------------------
2bda0e17 172// Attributes
b782f2e0 173// ----------------------------------------------------------------------------
2bda0e17 174
a23fd0e1 175int wxSpinButton::GetValue() const
2bda0e17 176{
0655ad29 177 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS, 0, 0));
2bda0e17
KB
178}
179
debe6624 180void wxSpinButton::SetValue(int val)
2bda0e17 181{
d1d7cdff 182 ::SendMessage(GetHwnd(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0));
2bda0e17
KB
183}
184
debe6624 185void wxSpinButton::SetRange(int minVal, int maxVal)
2bda0e17 186{
31528cd3 187 wxSpinButtonBase::SetRange(minVal, maxVal);
d1d7cdff 188 ::SendMessage(GetHwnd(), UDM_SETRANGE, 0,
3d7e30a4 189 (LPARAM) MAKELONG((short)maxVal, (short)minVal));
2bda0e17
KB
190}
191
a23fd0e1
VZ
192bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam,
193 WXWORD pos, WXHWND control)
2bda0e17 194{
223d09f6 195 wxCHECK_MSG( control, FALSE, wxT("scrolling what?") )
2bda0e17 196
0655ad29 197 if ( wParam != SB_THUMBPOSITION )
a23fd0e1 198 {
0655ad29
VZ
199 // probable SB_ENDSCROLL - we don't react to it
200 return FALSE;
201 }
2bda0e17 202
0655ad29
VZ
203 wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
204 event.SetPosition((short)pos); // cast is important for negative values!
205 event.SetEventObject(this);
2bda0e17 206
0655ad29
VZ
207 return GetEventHandler()->ProcessEvent(event);
208}
2bda0e17 209
0655ad29
VZ
210bool wxSpinButton::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
211{
8a4df159 212#ifndef __GNUWIN32__
0cdf89ab 213#if defined(__BORLANDC__) || defined(__WATCOMC__)
83475efc 214 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
6474416b 215#elif defined(__VISUALC__) && (__VISUALC__ >= 1000) && (__VISUALC__ < 1020)
2996bcde 216 LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam;
83475efc 217#else
0655ad29 218 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
83475efc 219#endif
2bda0e17 220
0655ad29
VZ
221 wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
222 : wxEVT_SCROLL_LINEDOWN,
223 m_windowId);
224 event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
225 event.SetEventObject(this);
2bda0e17 226
0655ad29 227 bool processed = GetEventHandler()->ProcessEvent(event);
2bda0e17 228
0655ad29 229 *result = event.IsAllowed() ? 0 : 1;
2bda0e17 230
0655ad29 231 return processed;
b782f2e0 232#else // GnuWin32
8a4df159
RR
233 return FALSE;
234#endif
2bda0e17
KB
235}
236
debe6624 237bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17 238{
a23fd0e1
VZ
239 // No command messages
240 return FALSE;
2bda0e17
KB
241}
242
a23fd0e1 243#endif // __WIN95__
0e528b99
JS
244
245#endif
246 // wxUSE_SPINCTN
247