]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/scrolbar.cpp
fixed wxOverlay to handle wxWindowDC/wxClientDC in the same way wxMac does
[wxWidgets.git] / src / mac / classic / scrolbar.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
18f3decb 2// Name: src/mac/classic/scrolbar.cpp
2646f485
SC
3// Purpose: wxScrollBar
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
18f3decb 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
18f3decb
WS
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
2646f485 17
851dee09
WS
18#include "wx/scrolbar.h"
19
2646f485
SC
20#ifndef WX_PRECOMP
21 #include "wx/intl.h"
22 #include "wx/log.h"
23#endif // WX_PRECOMP
24
2646f485
SC
25#include "wx/mac/uma.h"
26
2646f485
SC
27IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
28
29BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
30END_EVENT_TABLE()
31
2646f485
SC
32extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
33
34// Scrollbar
35bool 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) )
18f3decb 42 return false;
2646f485
SC
43
44 Rect bounds ;
45 Str255 title ;
46
47 MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
48
6bc3b8e9 49 m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) ,
18f3decb 50 &bounds , title , false , 0 , 0 , 100,
2646f485
SC
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
18f3decb 59 return true;
2646f485
SC
60}
61
62wxScrollBar::~wxScrollBar()
63{
64}
65
66void wxScrollBar::SetThumbPosition(int viewStart)
67{
68 ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
69}
70
71int wxScrollBar::GetThumbPosition() const
72{
73 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
74}
75
76void 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
101void wxScrollBar::Command(wxCommandEvent& event)
102{
687706f5 103 SetThumbPosition(event.GetInt());
2646f485
SC
104 ProcessCommand(event);
105}
106
18f3decb 107void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown )
2646f485
SC
108{
109 if ( (ControlHandle) m_macControl == NULL )
110 return ;
18f3decb 111
2646f485
SC
112 int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
113 int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
114 int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
18f3decb 115
2646f485
SC
116 wxEventType scrollEvent = wxEVT_NULL;
117 int nScrollInc = 0;
18f3decb 118
2646f485
SC
119 // all events have already been reported during mouse down, except for THUMBRELEASE
120 if ( !mouseStillDown && controlpart !=kControlIndicatorPart )
121 return ;
18f3decb 122
2646f485
SC
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 }
18f3decb 152
2646f485 153 int new_pos = position + nScrollInc;
18f3decb 154
2646f485
SC
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);
18f3decb 161
2646f485
SC
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}