]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/spinbutt.cpp
Got rid of some wierd VisualAge debug nonsense that had appeared in this after the...
[wxWidgets.git] / src / mac / carbon / 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"
03e11df5 14#pragma implementation "spinbuttbase.h"
e9576ca5
SC
15#endif
16
17#include "wx/spinbutt.h"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
e7549107
SC
20// ============================================================================
21// implementation
22// ============================================================================
23
24// ----------------------------------------------------------------------------
25// wxWin macros
26// ----------------------------------------------------------------------------
27
2f1ae414 28#if !USE_SHARED_LIBRARY
e7549107
SC
29 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
2f1ae414 31#endif
e9576ca5 32
03e11df5
GD
33wxSpinButton::wxSpinButton()
34 : wxSpinButtonBase()
35{
36}
37
e9576ca5
SC
38bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
39 long style, const wxString& name)
40{
e9576ca5
SC
41 m_min = 0;
42 m_max = 100;
43
519cb848
SC
44 if (!parent)
45 return FALSE;
46
47 Rect bounds ;
48 Str255 title ;
49
50 MacPreControlCreate( parent , id , "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
51
52 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
53 kControlLittleArrowsProc , (long) this ) ;
54
55 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
56
57 MacPostControlCreate() ;
e9576ca5 58
519cb848 59 return TRUE;
e9576ca5
SC
60}
61
62wxSpinButton::~wxSpinButton()
63{
64}
65
66// Attributes
67////////////////////////////////////////////////////////////////////////////
68
03e11df5
GD
69int wxSpinButton::GetMin() const
70{
71 return m_min;
72}
73
74int wxSpinButton::GetMax() const
75{
76 return m_max;
77}
78
e9576ca5
SC
79int wxSpinButton::GetValue() const
80{
519cb848 81 return m_value;
e9576ca5
SC
82}
83
84void wxSpinButton::SetValue(int val)
85{
519cb848
SC
86 m_value = val ;
87 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
88
89 event.SetPosition(m_value);
90 event.SetEventObject( this );
91 GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
92}
93
94void wxSpinButton::SetRange(int minVal, int maxVal)
95{
96 m_min = minVal;
97 m_max = maxVal;
e9576ca5
SC
98}
99
519cb848
SC
100void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
101{
102 if ( m_macControl == NULL )
103 return ;
104
105 wxEventType scrollEvent = wxEVT_NULL;
03e11df5 106 int nScrollInc = 0;
519cb848
SC
107
108 switch( controlpart )
109 {
110 case kControlUpButtonPart :
111 nScrollInc = 1;
112 scrollEvent = wxEVT_SCROLL_LINEUP;
113 break ;
114 case kControlDownButtonPart :
115 nScrollInc = -1;
116 scrollEvent = wxEVT_SCROLL_LINEDOWN;
117 break ;
118 }
119
120 m_value = m_value + nScrollInc;
121
122 if (m_value < m_min)
123 {
124 if ( m_windowStyle & wxSP_WRAP )
125 m_value = m_max;
126 else
127 m_value = m_min;
128 }
129
130 if (m_value > m_max)
131 {
132 if ( m_windowStyle & wxSP_WRAP )
133 m_value = m_min;
134 else
135 m_value = m_max;
136 }
137
138 wxScrollEvent event(scrollEvent, m_windowId);
139
140 event.SetPosition(m_value);
141 event.SetEventObject( this );
142 GetEventHandler()->ProcessEvent(event);
143}
144
51abe921
SC
145// ----------------------------------------------------------------------------
146// size calculation
147// ----------------------------------------------------------------------------
148
37e2cb08 149wxSize wxSpinButton::DoGetBestSize() const
51abe921
SC
150{
151 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
152 {
153 // vertical control
154 return wxSize(16,
155 2*16);
156 }
157 else
158 {
159 // horizontal control
160 return wxSize(2*16,
161 16);
162 }
163}
519cb848 164