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