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