]> git.saurik.com Git - wxWidgets.git/blob - src/mac/scrolbar.cpp
typo fixed
[wxWidgets.git] / src / mac / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
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 "scrolbar.h"
14 #endif
15
16 #include "wx/scrolbar.h"
17 #include "wx/mac/uma.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
21
22 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
23 END_EVENT_TABLE()
24
25 #endif
26
27 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
28
29 // Scrollbar
30 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator,
34 const wxString& name)
35 {
36 if (!parent)
37 return FALSE;
38
39 Rect bounds ;
40 Str255 title ;
41
42 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
43
44 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
45 kControlScrollBarLiveProc , (long) this ) ;
46
47 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
48
49 ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
50
51 MacPostControlCreate() ;
52
53 return TRUE;
54 }
55
56 wxScrollBar::~wxScrollBar()
57 {
58 }
59
60 void wxScrollBar::SetThumbPosition(int viewStart)
61 {
62 ::SetControlValue( m_macControl , viewStart ) ;
63 }
64
65 int wxScrollBar::GetThumbPosition() const
66 {
67 return ::GetControlValue( m_macControl ) ;
68 }
69
70 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
71 bool refresh)
72 {
73 m_viewSize = pageSize;
74 m_pageSize = thumbSize;
75 m_objectSize = range;
76
77 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
78
79 SetControlMaximum( m_macControl , range1 ) ;
80 SetControlMinimum( m_macControl , 0 ) ;
81 SetControlValue( m_macControl , position ) ;
82
83 if ( UMAGetAppearanceVersion() >= 0x0110 )
84 {
85 #if UMA_USE_8_6
86 SetControlViewSize( m_macControl , m_pageSize ) ;
87 #endif
88 }
89 Refresh() ;
90 }
91
92
93 void wxScrollBar::Command(wxCommandEvent& event)
94 {
95 SetThumbPosition(event.m_commandInt);
96 ProcessCommand(event);
97 }
98
99 void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
100 {
101 if ( m_macControl == NULL )
102 return ;
103
104 int position = GetControlValue( m_macControl) ;
105 int minPos = GetControlMinimum( m_macControl) ;
106 int maxPos = GetControlMaximum( m_macControl) ;
107
108 wxEventType scrollEvent = wxEVT_NULL;
109 int nScrollInc;
110
111 switch( controlpart )
112 {
113 case kControlUpButtonPart :
114 nScrollInc = -1;
115 scrollEvent = wxEVT_SCROLL_LINEUP;
116 break ;
117 case kControlDownButtonPart :
118 nScrollInc = 1;
119 scrollEvent = wxEVT_SCROLL_LINEDOWN;
120 break ;
121 case kControlPageUpPart :
122 nScrollInc = -m_pageSize;
123 scrollEvent = wxEVT_SCROLL_PAGEUP;
124 break ;
125 case kControlPageDownPart :
126 nScrollInc = m_pageSize;
127 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
128 break ;
129 case kControlIndicatorPart :
130 nScrollInc = 0 ;
131 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
132 break ;
133 }
134
135 int new_pos = position + nScrollInc;
136
137 if (new_pos < 0)
138 new_pos = 0;
139 if (new_pos > maxPos)
140 new_pos = maxPos;
141 if ( nScrollInc )
142 SetThumbPosition(new_pos);
143
144 wxScrollEvent event(scrollEvent, m_windowId);
145 if ( m_windowStyle & wxHORIZONTAL )
146 {
147 event.SetOrientation( wxHORIZONTAL ) ;
148 }
149 else
150 {
151 event.SetOrientation( wxVERTICAL ) ;
152 }
153 event.SetPosition(new_pos);
154 event.SetEventObject( this );
155 wxWindow* window = GetParent() ;
156 if (window && window->MacIsWindowScrollbar(this) )
157 {
158 // this is hardcoded
159 window->MacOnScroll(event);
160 }
161 else
162 GetEventHandler()->ProcessEvent(event);
163 }
164