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