]> git.saurik.com Git - wxWidgets.git/blame - src/mac/spinbutt.cpp
DEBUG => __WXDEBUG__
[wxWidgets.git] / src / mac / spinbutt.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "spinbutt.h"
14#endif
15
16#include "wx/spinbutt.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5
SC
18
19#if !USE_SHARED_LIBRARY
20IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
21#endif
22
23wxSpinButton::wxSpinButton()
24{
25 m_min = 0;
26 m_max = 100;
27}
28
29bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
30 long style, const wxString& name)
31{
e9576ca5
SC
32 m_min = 0;
33 m_max = 100;
34
519cb848
SC
35 if (!parent)
36 return FALSE;
37
38 Rect bounds ;
39 Str255 title ;
40
41 MacPreControlCreate( parent , id , "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
42
43 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
44 kControlLittleArrowsProc , (long) this ) ;
45
46 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
47
48 MacPostControlCreate() ;
e9576ca5 49
519cb848 50 return TRUE;
e9576ca5
SC
51}
52
53wxSpinButton::~wxSpinButton()
54{
55}
56
57// Attributes
58////////////////////////////////////////////////////////////////////////////
59
60int wxSpinButton::GetValue() const
61{
519cb848 62 return m_value;
e9576ca5
SC
63}
64
65void wxSpinButton::SetValue(int val)
66{
519cb848
SC
67 m_value = val ;
68 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
69
70 event.SetPosition(m_value);
71 event.SetEventObject( this );
72 GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
73}
74
75void wxSpinButton::SetRange(int minVal, int maxVal)
76{
77 m_min = minVal;
78 m_max = maxVal;
e9576ca5
SC
79}
80
81// Spin event
82IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
83
84wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
85 wxScrollEvent(commandType, id)
86{
87}
88
519cb848
SC
89void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
90{
91 if ( m_macControl == NULL )
92 return ;
93
94 wxEventType scrollEvent = wxEVT_NULL;
95 int nScrollInc;
96
97 switch( controlpart )
98 {
99 case kControlUpButtonPart :
100 nScrollInc = 1;
101 scrollEvent = wxEVT_SCROLL_LINEUP;
102 break ;
103 case kControlDownButtonPart :
104 nScrollInc = -1;
105 scrollEvent = wxEVT_SCROLL_LINEDOWN;
106 break ;
107 }
108
109 m_value = m_value + nScrollInc;
110
111 if (m_value < m_min)
112 {
113 if ( m_windowStyle & wxSP_WRAP )
114 m_value = m_max;
115 else
116 m_value = m_min;
117 }
118
119 if (m_value > m_max)
120 {
121 if ( m_windowStyle & wxSP_WRAP )
122 m_value = m_min;
123 else
124 m_value = m_max;
125 }
126
127 wxScrollEvent event(scrollEvent, m_windowId);
128
129 event.SetPosition(m_value);
130 event.SetEventObject( this );
131 GetEventHandler()->ProcessEvent(event);
132}
133
134