]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/scrolbar.cpp
fixed unused variable warning
[wxWidgets.git] / src / mac / classic / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "scrolbar.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/scrolbar.h"
24 #include "wx/mac/uma.h"
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
28
29 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
30 END_EVENT_TABLE()
31
32 #endif
33
34 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
35
36 // Scrollbar
37 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
38 const wxPoint& pos,
39 const wxSize& size, long style,
40 const wxValidator& validator,
41 const wxString& name)
42 {
43 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
44 return FALSE;
45
46 Rect bounds ;
47 Str255 title ;
48
49 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
50
51 m_macControl = ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) ,
52 &bounds , title , false , 0 , 0 , 100,
53 kControlScrollBarLiveProc , (long) this) ;
54
55 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
56
57 ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
58
59 MacPostControlCreate() ;
60
61 return TRUE;
62 }
63
64 wxScrollBar::~wxScrollBar()
65 {
66 }
67
68 void wxScrollBar::SetThumbPosition(int viewStart)
69 {
70 ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
71 }
72
73 int wxScrollBar::GetThumbPosition() const
74 {
75 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
76 }
77
78 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
79 bool refresh)
80 {
81 m_pageSize = pageSize;
82 m_viewSize = thumbSize;
83 m_objectSize = range;
84
85 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
86
87 SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ;
88 SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
89 SetControl32BitValue( (ControlHandle) m_macControl , position ) ;
90
91 if ( UMAGetAppearanceVersion() >= 0x0110 )
92 {
93 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
94 {
95 SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ;
96 }
97 }
98 if ( refresh )
99 MacRedrawControl() ;
100 }
101
102
103 void wxScrollBar::Command(wxCommandEvent& event)
104 {
105 SetThumbPosition(event.m_commandInt);
106 ProcessCommand(event);
107 }
108
109 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
110 {
111 if ( (ControlHandle) m_macControl == NULL )
112 return ;
113
114 int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
115 int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
116 int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
117
118 wxEventType scrollEvent = wxEVT_NULL;
119 int nScrollInc = 0;
120
121 // all events have already been reported during mouse down, except for THUMBRELEASE
122 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
123 return ;
124
125 switch( controlpart )
126 {
127 case kControlUpButtonPart :
128 nScrollInc = -1;
129 scrollEvent = wxEVT_SCROLL_LINEUP;
130 break ;
131 case kControlDownButtonPart :
132 nScrollInc = 1;
133 scrollEvent = wxEVT_SCROLL_LINEDOWN;
134 break ;
135 case kControlPageUpPart :
136 nScrollInc = -m_pageSize;
137 scrollEvent = wxEVT_SCROLL_PAGEUP;
138 break ;
139 case kControlPageDownPart :
140 nScrollInc = m_pageSize;
141 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
142 break ;
143 case kControlIndicatorPart :
144 nScrollInc = 0 ;
145 if ( mouseStillDown )
146 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
147 else
148 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
149 break ;
150 default :
151 wxFAIL_MSG(wxT("illegal scrollbar selector"));
152 break ;
153 }
154
155 int new_pos = position + nScrollInc;
156
157 if (new_pos < minPos)
158 new_pos = minPos;
159 if (new_pos > maxPos)
160 new_pos = maxPos;
161 if ( nScrollInc )
162 SetThumbPosition(new_pos);
163
164 wxScrollEvent event(scrollEvent, m_windowId);
165 if ( m_windowStyle & wxHORIZONTAL )
166 {
167 event.SetOrientation( wxHORIZONTAL ) ;
168 }
169 else
170 {
171 event.SetOrientation( wxVERTICAL ) ;
172 }
173 event.SetPosition(new_pos);
174 event.SetEventObject( this );
175 wxWindow* window = GetParent() ;
176 if (window && window->MacIsWindowScrollbar(this) )
177 {
178 // this is hardcoded
179 window->MacOnScroll(event);
180 }
181 else
182 GetEventHandler()->ProcessEvent(event);
183 }
184