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