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