]> git.saurik.com Git - wxWidgets.git/blob - src/mac/spinbutt.cpp
Commented out palette code for wxGTK
[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 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
29 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
30 #endif
31
32 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
33 long style, const wxString& name)
34 {
35 m_min = 0;
36 m_max = 100;
37
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() ;
52
53 return TRUE;
54 }
55
56 wxSpinButton::~wxSpinButton()
57 {
58 }
59
60 // Attributes
61 ////////////////////////////////////////////////////////////////////////////
62
63 int wxSpinButton::GetValue() const
64 {
65 return m_value;
66 }
67
68 void wxSpinButton::SetValue(int val)
69 {
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);
76 }
77
78 void wxSpinButton::SetRange(int minVal, int maxVal)
79 {
80 m_min = minVal;
81 m_max = maxVal;
82 }
83
84 void 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
129 // ----------------------------------------------------------------------------
130 // size calculation
131 // ----------------------------------------------------------------------------
132
133 wxSize wxSpinButton::DoGetBestSize() const
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 }
148