]> git.saurik.com Git - wxWidgets.git/blob - src/mac/spinbutt.cpp
fixed menu accelerators
[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 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
21 #endif
22
23 wxSpinButton::wxSpinButton()
24 {
25 m_min = 0;
26 m_max = 100;
27 }
28
29 bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
30 long style, const wxString& name)
31 {
32 m_min = 0;
33 m_max = 100;
34
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() ;
49
50 return TRUE;
51 }
52
53 wxSpinButton::~wxSpinButton()
54 {
55 }
56
57 // Attributes
58 ////////////////////////////////////////////////////////////////////////////
59
60 int wxSpinButton::GetValue() const
61 {
62 return m_value;
63 }
64
65 void wxSpinButton::SetValue(int val)
66 {
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);
73 }
74
75 void wxSpinButton::SetRange(int minVal, int maxVal)
76 {
77 m_min = minVal;
78 m_max = maxVal;
79 }
80
81 // Spin event
82 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent)
83
84 wxSpinEvent::wxSpinEvent(wxEventType commandType, int id):
85 wxScrollEvent(commandType, id)
86 {
87 }
88
89 void 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