]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/scrolbar.cpp
added native alignement support
[wxWidgets.git] / src / mac / carbon / 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 m_macIsUserPane = FALSE ;
44
45 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
46 return FALSE;
47
48 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
49 m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()) ,
50 &bounds , "\p" , true , 0 , 0 , 100,
51 kControlScrollBarLiveProc , (long) this) ;
52
53 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
54
55 ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ;
56
57 MacPostControlCreate(pos,size) ;
58
59 return TRUE;
60 }
61
62 wxScrollBar::~wxScrollBar()
63 {
64 }
65
66 void wxScrollBar::SetThumbPosition(int viewStart)
67 {
68 ::SetControl32BitValue( (ControlRef) m_macControl , viewStart ) ;
69 }
70
71 int wxScrollBar::GetThumbPosition() const
72 {
73 return ::GetControl32BitValue( (ControlRef) 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( (ControlRef) m_macControl , range1 ) ;
86 SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ;
87 SetControl32BitValue( (ControlRef) m_macControl , position ) ;
88
89 if ( UMAGetAppearanceVersion() >= 0x0110 )
90 {
91 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
92 {
93 SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ;
94 }
95 }
96 if ( refresh )
97 MacRedrawControl() ;
98 }
99
100
101 void wxScrollBar::Command(wxCommandEvent& event)
102 {
103 SetThumbPosition(event.m_commandInt);
104 ProcessCommand(event);
105 }
106
107 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
108 {
109 if ( (ControlRef) m_macControl == NULL )
110 return ;
111
112 int position = GetControl32BitValue( (ControlRef) m_macControl) ;
113 int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ;
114 int maxPos = GetControl32BitMaximum( (ControlRef) 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 }
182