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