]> git.saurik.com Git - wxWidgets.git/blob - src/mac/scrolbar.cpp
Forgot ! in wxTreeCtrl flag test.
[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 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
21
22 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
23 END_EVENT_TABLE()
24
25 #endif
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 (!parent)
37 return FALSE;
38
39 Rect bounds ;
40 Str255 title ;
41
42 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
43
44 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
45 kControlScrollBarLiveProc , (long) this ) ;
46
47 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
48
49 ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ;
50
51 MacPostControlCreate() ;
52
53 return TRUE;
54 }
55
56 wxScrollBar::~wxScrollBar()
57 {
58 }
59
60 void wxScrollBar::SetThumbPosition(int viewStart)
61 {
62 ::SetControlValue( m_macControl , viewStart ) ;
63 }
64
65 int wxScrollBar::GetThumbPosition() const
66 {
67 return ::GetControlValue( m_macControl ) ;
68 }
69
70 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
71 bool refresh)
72 {
73 m_viewSize = pageSize;
74 m_pageSize = thumbSize;
75 m_objectSize = range;
76
77 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
78
79 SetControlMaximum( m_macControl , range1 ) ;
80 SetControlMinimum( m_macControl , 0 ) ;
81 SetControlValue( m_macControl , position ) ;
82
83 if ( UMAGetAppearanceVersion() >= 0x0110 )
84 {
85 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
86 {
87 SetControlViewSize( m_macControl , m_pageSize ) ;
88 }
89 }
90 Refresh() ;
91 }
92
93
94 void wxScrollBar::Command(wxCommandEvent& event)
95 {
96 SetThumbPosition(event.m_commandInt);
97 ProcessCommand(event);
98 }
99
100 void wxScrollBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
101 {
102 if ( m_macControl == NULL )
103 return ;
104
105 int position = GetControlValue( m_macControl) ;
106 int minPos = GetControlMinimum( m_macControl) ;
107 int maxPos = GetControlMaximum( m_macControl) ;
108
109 wxEventType scrollEvent = wxEVT_NULL;
110 int nScrollInc;
111
112 switch( controlpart )
113 {
114 case kControlUpButtonPart :
115 nScrollInc = -1;
116 scrollEvent = wxEVT_SCROLL_LINEUP;
117 break ;
118 case kControlDownButtonPart :
119 nScrollInc = 1;
120 scrollEvent = wxEVT_SCROLL_LINEDOWN;
121 break ;
122 case kControlPageUpPart :
123 nScrollInc = -m_pageSize;
124 scrollEvent = wxEVT_SCROLL_PAGEUP;
125 break ;
126 case kControlPageDownPart :
127 nScrollInc = m_pageSize;
128 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
129 break ;
130 case kControlIndicatorPart :
131 nScrollInc = 0 ;
132 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
133 break ;
134 }
135
136 int new_pos = position + nScrollInc;
137
138 if (new_pos < 0)
139 new_pos = 0;
140 if (new_pos > maxPos)
141 new_pos = maxPos;
142 if ( nScrollInc )
143 SetThumbPosition(new_pos);
144
145 wxScrollEvent event(scrollEvent, m_windowId);
146 if ( m_windowStyle & wxHORIZONTAL )
147 {
148 event.SetOrientation( wxHORIZONTAL ) ;
149 }
150 else
151 {
152 event.SetOrientation( wxVERTICAL ) ;
153 }
154 event.SetPosition(new_pos);
155 event.SetEventObject( this );
156 wxWindow* window = GetParent() ;
157 if (window && window->MacIsWindowScrollbar(this) )
158 {
159 // this is hardcoded
160 window->MacOnScroll(event);
161 }
162 else
163 GetEventHandler()->ProcessEvent(event);
164 }
165