]> git.saurik.com Git - wxWidgets.git/blob - src/mac/scrolbar.cpp
Quick VA fix
[wxWidgets.git] / src / mac / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "scrolbar.h"
14 #endif
15
16 #include "wx/scrolbar.h"
17 #include "wx/mac/uma.h"
18
19 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
20
21 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
22 END_EVENT_TABLE()
23
24
25 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
26
27 // Scrollbar
28 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 if (!parent)
35 return FALSE;
36
37 Rect bounds ;
38 Str255 title ;
39
40 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
41
42 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
43 kControlScrollBarLiveProc , (long) this ) ;
44
45 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
46
47 ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
48
49 MacPostControlCreate() ;
50
51 return TRUE;
52 }
53
54 wxScrollBar::~wxScrollBar()
55 {
56 }
57
58 void wxScrollBar::SetThumbPosition(int viewStart)
59 {
60 ::SetControlValue( m_macControl , viewStart ) ;
61 }
62
63 int wxScrollBar::GetThumbPosition() const
64 {
65 return ::GetControlValue( m_macControl ) ;
66 }
67
68 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
69 bool refresh)
70 {
71 m_viewSize = pageSize;
72 m_pageSize = thumbSize;
73 m_objectSize = range;
74
75 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
76
77 SetControlMaximum( m_macControl , range1 ) ;
78 SetControlMinimum( m_macControl , 0 ) ;
79 SetControlValue( m_macControl , position ) ;
80
81 if ( UMAGetAppearanceVersion() >= 0x0110 )
82 {
83 #if UMA_USE_8_6
84 SetControlViewSize( m_macControl , m_pageSize ) ;
85 #endif
86 }
87 Refresh() ;
88 }
89
90
91 void wxScrollBar::Command(wxCommandEvent& event)
92 {
93 SetThumbPosition(event.m_commandInt);
94 ProcessCommand(event);
95 }
96
97 void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
98 {
99 if ( m_macControl == NULL )
100 return ;
101
102 int position = GetControlValue( m_macControl) ;
103 int minPos = GetControlMinimum( m_macControl) ;
104 int maxPos = GetControlMaximum( m_macControl) ;
105
106 wxEventType scrollEvent = wxEVT_NULL;
107 int nScrollInc;
108
109 switch( controlpart )
110 {
111 case kControlUpButtonPart :
112 nScrollInc = -1;
113 scrollEvent = wxEVT_SCROLL_LINEUP;
114 break ;
115 case kControlDownButtonPart :
116 nScrollInc = 1;
117 scrollEvent = wxEVT_SCROLL_LINEDOWN;
118 break ;
119 case kControlPageUpPart :
120 nScrollInc = -m_pageSize;
121 scrollEvent = wxEVT_SCROLL_PAGEUP;
122 break ;
123 case kControlPageDownPart :
124 nScrollInc = m_pageSize;
125 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
126 break ;
127 case kControlIndicatorPart :
128 nScrollInc = 0 ;
129 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
130 break ;
131 }
132
133 int new_pos = position + nScrollInc;
134
135 if (new_pos < 0)
136 new_pos = 0;
137 if (new_pos > maxPos)
138 new_pos = maxPos;
139 if ( nScrollInc )
140 SetThumbPosition(new_pos);
141
142 wxScrollEvent event(scrollEvent, m_windowId);
143 if ( m_windowStyle & wxHORIZONTAL )
144 {
145 event.SetOrientation( wxHORIZONTAL ) ;
146 }
147 else
148 {
149 event.SetOrientation( wxVERTICAL ) ;
150 }
151 event.SetPosition(new_pos);
152 event.SetEventObject( this );
153 wxWindow* window = GetParent() ;
154 if (window && window->MacIsWindowScrollbar(this) )
155 {
156 // this is hardcoded
157 window->MacOnScroll(event);
158 }
159 else
160 GetEventHandler()->ProcessEvent(event);
161 }
162