]> git.saurik.com Git - wxWidgets.git/blob - src/mac/scrolbar.cpp
Use the wxStaticBox::GetBordersForSizer method to get border information
[wxWidgets.git] / src / mac / 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 (!parent)
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()) , &bounds , title , true , 0 , 0 , 100,
52 kControlScrollBarLiveProc , (long) this ) ;
53
54 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
55
56 ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
57
58 MacPostControlCreate() ;
59
60 return TRUE;
61 }
62
63 wxScrollBar::~wxScrollBar()
64 {
65 }
66
67 void wxScrollBar::SetThumbPosition(int viewStart)
68 {
69 ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
70 }
71
72 int wxScrollBar::GetThumbPosition() const
73 {
74 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
75 }
76
77 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
78 bool refresh)
79 {
80 m_pageSize = pageSize;
81 m_viewSize = thumbSize;
82 m_objectSize = range;
83
84 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
85
86 SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ;
87 SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
88 SetControl32BitValue( (ControlHandle) m_macControl , position ) ;
89
90 if ( UMAGetAppearanceVersion() >= 0x0110 )
91 {
92 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
93 {
94 SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ;
95 }
96 }
97 if ( refresh )
98 MacRedrawControl() ;
99 }
100
101
102 void wxScrollBar::Command(wxCommandEvent& event)
103 {
104 SetThumbPosition(event.m_commandInt);
105 ProcessCommand(event);
106 }
107
108 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
109 {
110 if ( (ControlHandle) m_macControl == NULL )
111 return ;
112
113 int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
114 int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
115 int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
116
117 wxEventType scrollEvent = wxEVT_NULL;
118 int nScrollInc;
119
120 switch( controlpart )
121 {
122 case kControlUpButtonPart :
123 nScrollInc = -1;
124 scrollEvent = wxEVT_SCROLL_LINEUP;
125 break ;
126 case kControlDownButtonPart :
127 nScrollInc = 1;
128 scrollEvent = wxEVT_SCROLL_LINEDOWN;
129 break ;
130 case kControlPageUpPart :
131 nScrollInc = -m_pageSize;
132 scrollEvent = wxEVT_SCROLL_PAGEUP;
133 break ;
134 case kControlPageDownPart :
135 nScrollInc = m_pageSize;
136 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
137 break ;
138 case kControlIndicatorPart :
139 nScrollInc = 0 ;
140 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
141 break ;
142 default :
143 wxFAIL_MSG(wxT("illegal scrollbar selector"));
144 break ;
145 }
146
147 int new_pos = position + nScrollInc;
148
149 if (new_pos < minPos)
150 new_pos = minPos;
151 if (new_pos > maxPos)
152 new_pos = maxPos;
153 if ( nScrollInc )
154 SetThumbPosition(new_pos);
155
156 wxScrollEvent event(scrollEvent, m_windowId);
157 if ( m_windowStyle & wxHORIZONTAL )
158 {
159 event.SetOrientation( wxHORIZONTAL ) ;
160 }
161 else
162 {
163 event.SetOrientation( wxVERTICAL ) ;
164 }
165 event.SetPosition(new_pos);
166 event.SetEventObject( this );
167 wxWindow* window = GetParent() ;
168 if (window && window->MacIsWindowScrollbar(this) )
169 {
170 // this is hardcoded
171 window->MacOnScroll(event);
172 }
173 else
174 GetEventHandler()->ProcessEvent(event);
175 }
176