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