]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: scrolbar.cpp | |
3 | // Purpose: wxScrollBar | |
409c9842 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
409c9842 | 6 | // Created: 10/15/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
409c9842 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/defs.h" | |
17 | #include "wx/utils.h" | |
0e320a79 DW |
18 | #endif |
19 | ||
20 | #include "wx/scrolbar.h" | |
409c9842 | 21 | #include "wx/os2/private.h" |
0e320a79 DW |
22 | |
23 | #if !USE_SHARED_LIBRARY | |
24 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) | |
25 | ||
409c9842 DW |
26 | BEGIN_EVENT_TABLE(wxScrollBar, wxControl) |
27 | #if WXWIN_COMPATIBILITY | |
28 | EVT_SCROLL(wxScrollBar::OnScroll) | |
29 | #endif | |
30 | END_EVENT_TABLE() | |
31 | ||
0e320a79 DW |
32 | #endif |
33 | ||
34 | // Scrollbar | |
35 | bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, | |
36 | const wxPoint& pos, | |
37 | const wxSize& size, long style, | |
5d4b632b DW |
38 | #if wxUSE_VALIDATORS |
39 | # if defined(__VISAGECPP__) | |
40 | const wxValidator* validator, | |
41 | # else | |
0e320a79 | 42 | const wxValidator& validator, |
5d4b632b DW |
43 | # endif |
44 | #endif | |
0e320a79 DW |
45 | const wxString& name) |
46 | { | |
47 | if (!parent) | |
48 | return FALSE; | |
49 | parent->AddChild(this); | |
50 | SetName(name); | |
5d4b632b | 51 | #if wxUSE_VALIDATORS |
409c9842 | 52 | SetValidator(validator); |
5d4b632b | 53 | #endif |
04701dd9 | 54 | |
409c9842 DW |
55 | SetBackgroundColour(parent->GetBackgroundColour()) ; |
56 | SetForegroundColour(parent->GetForegroundColour()) ; | |
0e320a79 DW |
57 | m_windowStyle = style; |
58 | ||
59 | if ( id == -1 ) | |
409c9842 | 60 | m_windowId = (int)NewControlId(); |
0e320a79 | 61 | else |
409c9842 DW |
62 | m_windowId = id; |
63 | ||
64 | int x = pos.x; | |
65 | int y = pos.y; | |
66 | int width = size.x; | |
67 | int height = size.y; | |
68 | ||
69 | if (width == -1) | |
70 | { | |
71 | if (style & wxHORIZONTAL) | |
72 | width = 140; | |
73 | else | |
74 | width = 14; | |
75 | } | |
76 | if (height == -1) | |
77 | { | |
78 | if (style & wxVERTICAL) | |
79 | height = 140; | |
80 | else | |
81 | height = 14; | |
82 | } | |
0e320a79 DW |
83 | |
84 | // TODO create scrollbar | |
409c9842 DW |
85 | |
86 | m_pageSize = 1; | |
87 | m_viewSize = 1; | |
88 | m_objectSize = 1; | |
89 | ||
90 | SetFont(parent->GetFont()); | |
91 | ||
92 | m_hWnd = 0; // TODO: (WXHWND)scroll_bar; | |
93 | ||
04701dd9 DW |
94 | HWND scroll_bar = 0; // temporary |
95 | ||
409c9842 DW |
96 | // Subclass again for purposes of dialog editing mode |
97 | SubclassWin((WXHWND) scroll_bar); | |
98 | ||
99 | SetSize(x, y, width, height); | |
100 | ||
0e320a79 DW |
101 | return TRUE; |
102 | } | |
103 | ||
104 | wxScrollBar::~wxScrollBar() | |
105 | { | |
106 | } | |
107 | ||
409c9842 DW |
108 | bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam, |
109 | WXWORD pos, WXHWND control) | |
110 | { | |
111 | // TODO: | |
112 | /* | |
113 | int position = ::GetScrollPos((HWND) control, SB_CTL); | |
114 | int minPos, maxPos; | |
115 | ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos); | |
116 | ||
117 | #if defined(__WIN95__) | |
118 | // A page size greater than one has the effect of reducing the effective | |
119 | // range, therefore the range has already been boosted artificially - so | |
120 | // reduce it again. | |
121 | if ( m_pageSize > 1 ) | |
122 | maxPos -= (m_pageSize - 1); | |
123 | #endif // __WIN95__ | |
124 | ||
125 | wxEventType scrollEvent = wxEVT_NULL; | |
126 | ||
127 | int nScrollInc; | |
128 | switch ( wParam ) | |
129 | { | |
130 | case SB_TOP: | |
131 | nScrollInc = maxPos - position; | |
132 | scrollEvent = wxEVT_SCROLL_TOP; | |
133 | break; | |
134 | ||
135 | case SB_BOTTOM: | |
136 | nScrollInc = - position; | |
137 | scrollEvent = wxEVT_SCROLL_BOTTOM; | |
138 | break; | |
139 | ||
140 | case SB_LINEUP: | |
141 | nScrollInc = -1; | |
142 | scrollEvent = wxEVT_SCROLL_LINEUP; | |
143 | break; | |
144 | ||
145 | case SB_LINEDOWN: | |
146 | nScrollInc = 1; | |
147 | scrollEvent = wxEVT_SCROLL_LINEDOWN; | |
148 | break; | |
149 | ||
150 | case SB_PAGEUP: | |
151 | nScrollInc = -GetPageSize(); | |
152 | scrollEvent = wxEVT_SCROLL_PAGEUP; | |
153 | break; | |
154 | ||
155 | case SB_PAGEDOWN: | |
156 | nScrollInc = GetPageSize(); | |
157 | scrollEvent = wxEVT_SCROLL_PAGEDOWN; | |
158 | break; | |
159 | ||
160 | case SB_THUMBTRACK: | |
161 | case SB_THUMBPOSITION: | |
162 | nScrollInc = pos - position; | |
163 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; | |
164 | break; | |
165 | ||
166 | default: | |
167 | nScrollInc = 0; | |
168 | } | |
169 | ||
170 | if ( nScrollInc == 0 ) | |
171 | { | |
172 | // no event to process, so don't process it | |
173 | return FALSE; | |
174 | } | |
175 | ||
176 | int new_pos = position + nScrollInc; | |
177 | ||
178 | if (new_pos < 0) | |
179 | new_pos = 0; | |
180 | if (new_pos > maxPos) | |
181 | new_pos = maxPos; | |
182 | ||
183 | SetThumbPosition(new_pos); | |
184 | wxScrollEvent event(scrollEvent, m_windowId); | |
185 | event.SetPosition(new_pos); | |
186 | event.SetEventObject( this ); | |
187 | ||
188 | return GetEventHandler()->ProcessEvent(event); | |
189 | */ | |
190 | return FALSE; | |
191 | } | |
192 | ||
0e320a79 DW |
193 | void wxScrollBar::SetThumbPosition(int viewStart) |
194 | { | |
195 | // TODO | |
196 | } | |
197 | ||
198 | int wxScrollBar::GetThumbPosition() const | |
199 | { | |
200 | // TODO | |
201 | return 0; | |
202 | } | |
203 | ||
204 | void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, | |
205 | bool refresh) | |
206 | { | |
207 | m_viewSize = pageSize; | |
208 | m_pageSize = thumbSize; | |
209 | m_objectSize = range; | |
210 | ||
211 | // TODO | |
212 | } | |
213 | ||
409c9842 DW |
214 | #if WXWIN_COMPATIBILITY |
215 | void wxScrollBar::SetPageSize(int pageLength) | |
216 | { | |
217 | m_pageSize = pageLength; | |
218 | ||
219 | // TODO: | |
220 | } | |
221 | ||
222 | void wxScrollBar::SetObjectLength(int objectLength) | |
223 | { | |
224 | m_objectSize = objectLength; | |
225 | ||
226 | // The range (number of scroll steps) is the | |
227 | // object length minus the view size. | |
228 | int range = wxMax((objectLength - m_viewSize), 0) ; | |
229 | ||
230 | // TODO: | |
231 | } | |
232 | ||
233 | void wxScrollBar::SetViewLength(int viewLength) | |
234 | { | |
235 | m_viewSize = viewLength; | |
236 | } | |
237 | ||
238 | void wxScrollBar::GetValues(int *viewStart, int *viewLength, int *objectLength, | |
239 | int *pageLength) const | |
240 | { | |
241 | // TODO: | |
242 | /* | |
243 | *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL); | |
244 | *viewLength = m_viewSize; | |
245 | *objectLength = m_objectSize; | |
246 | *pageLength = m_pageSize; | |
247 | */ | |
248 | } | |
249 | #endif | |
250 | ||
251 | WXHBRUSH wxScrollBar::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, | |
252 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
253 | { | |
254 | return 0; | |
255 | } | |
0e320a79 DW |
256 | |
257 | void wxScrollBar::Command(wxCommandEvent& event) | |
258 | { | |
259 | SetThumbPosition(event.m_commandInt); | |
260 | ProcessCommand(event); | |
261 | } | |
262 | ||
409c9842 DW |
263 | #if WXWIN_COMPATIBILITY |
264 | // Backward compatibility | |
265 | void wxScrollBar::OnScroll(wxScrollEvent& event) | |
266 | { | |
267 | // TODO: | |
268 | /* | |
269 | wxEventType oldEvent = event.GetEventType(); | |
270 | event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED ); | |
271 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
272 | { | |
273 | event.SetEventType( oldEvent ); | |
274 | if (!GetParent()->GetEventHandler()->ProcessEvent(event)) | |
275 | event.Skip(); | |
276 | } | |
277 | */ | |
278 | } | |
279 | #endif |