]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/classic/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 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
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 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) | |
27 | ||
28 | BEGIN_EVENT_TABLE(wxScrollBar, wxControl) | |
29 | END_EVENT_TABLE() | |
30 | ||
31 | extern ControlActionUPP wxMacLiveScrollbarActionUPP ; | |
32 | ||
33 | // Scrollbar | |
34 | bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, | |
35 | const wxPoint& pos, | |
36 | const wxSize& size, long style, | |
37 | const wxValidator& validator, | |
38 | const wxString& name) | |
39 | { | |
40 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) | |
41 | return false; | |
42 | ||
43 | Rect bounds ; | |
44 | Str255 title ; | |
45 | ||
46 | MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; | |
47 | ||
48 | m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) , | |
49 | &bounds , title , false , 0 , 0 , 100, | |
50 | kControlScrollBarLiveProc , (long) this) ; | |
51 | ||
52 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; | |
53 | ||
54 | ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ; | |
55 | ||
56 | MacPostControlCreate() ; | |
57 | ||
58 | return true; | |
59 | } | |
60 | ||
61 | wxScrollBar::~wxScrollBar() | |
62 | { | |
63 | } | |
64 | ||
65 | void wxScrollBar::SetThumbPosition(int viewStart) | |
66 | { | |
67 | ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ; | |
68 | } | |
69 | ||
70 | int wxScrollBar::GetThumbPosition() const | |
71 | { | |
72 | return ::GetControl32BitValue( (ControlHandle) m_macControl ) ; | |
73 | } | |
74 | ||
75 | void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, | |
76 | bool refresh) | |
77 | { | |
78 | m_pageSize = pageSize; | |
79 | m_viewSize = thumbSize; | |
80 | m_objectSize = range; | |
81 | ||
82 | int range1 = wxMax((m_objectSize - m_viewSize), 0) ; | |
83 | ||
84 | SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ; | |
85 | SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ; | |
86 | SetControl32BitValue( (ControlHandle) m_macControl , position ) ; | |
87 | ||
88 | if ( UMAGetAppearanceVersion() >= 0x0110 ) | |
89 | { | |
90 | if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress ) | |
91 | { | |
92 | SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ; | |
93 | } | |
94 | } | |
95 | if ( refresh ) | |
96 | MacRedrawControl() ; | |
97 | } | |
98 | ||
99 | ||
100 | void wxScrollBar::Command(wxCommandEvent& event) | |
101 | { | |
102 | SetThumbPosition(event.GetInt()); | |
103 | ProcessCommand(event); | |
104 | } | |
105 | ||
106 | void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) | |
107 | { | |
108 | if ( (ControlHandle) m_macControl == NULL ) | |
109 | return ; | |
110 | ||
111 | int position = GetControl32BitValue( (ControlHandle) m_macControl) ; | |
112 | int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ; | |
113 | int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ; | |
114 | ||
115 | wxEventType scrollEvent = wxEVT_NULL; | |
116 | int nScrollInc = 0; | |
117 | ||
118 | // all events have already been reported during mouse down, except for THUMBRELEASE | |
119 | if ( !mouseStillDown && controlpart !=kControlIndicatorPart ) | |
120 | return ; | |
121 | ||
122 | switch( controlpart ) | |
123 | { | |
124 | case kControlUpButtonPart : | |
125 | nScrollInc = -1; | |
126 | scrollEvent = wxEVT_SCROLL_LINEUP; | |
127 | break ; | |
128 | case kControlDownButtonPart : | |
129 | nScrollInc = 1; | |
130 | scrollEvent = wxEVT_SCROLL_LINEDOWN; | |
131 | break ; | |
132 | case kControlPageUpPart : | |
133 | nScrollInc = -m_pageSize; | |
134 | scrollEvent = wxEVT_SCROLL_PAGEUP; | |
135 | break ; | |
136 | case kControlPageDownPart : | |
137 | nScrollInc = m_pageSize; | |
138 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; | |
139 | break ; | |
140 | case kControlIndicatorPart : | |
141 | nScrollInc = 0 ; | |
142 | if ( mouseStillDown ) | |
143 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
144 | else | |
145 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; | |
146 | break ; | |
147 | default : | |
148 | wxFAIL_MSG(wxT("illegal scrollbar selector")); | |
149 | break ; | |
150 | } | |
151 | ||
152 | int new_pos = position + nScrollInc; | |
153 | ||
154 | if (new_pos < minPos) | |
155 | new_pos = minPos; | |
156 | if (new_pos > maxPos) | |
157 | new_pos = maxPos; | |
158 | if ( nScrollInc ) | |
159 | SetThumbPosition(new_pos); | |
160 | ||
161 | wxScrollEvent event(scrollEvent, m_windowId); | |
162 | if ( m_windowStyle & wxHORIZONTAL ) | |
163 | { | |
164 | event.SetOrientation( wxHORIZONTAL ) ; | |
165 | } | |
166 | else | |
167 | { | |
168 | event.SetOrientation( wxVERTICAL ) ; | |
169 | } | |
170 | event.SetPosition(new_pos); | |
171 | event.SetEventObject( this ); | |
172 | wxWindow* window = GetParent() ; | |
173 | if (window && window->MacIsWindowScrollbar(this) ) | |
174 | { | |
175 | // this is hardcoded | |
176 | window->MacOnScroll(event); | |
177 | } | |
178 | else | |
179 | GetEventHandler()->ProcessEvent(event); | |
180 | } |