]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: scrolwin.cpp | |
3 | // Purpose: wxScrolledWindow implementation | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
14 | #pragma implementation "scrolwin.h" | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #include "wx/utils.h" | |
21 | #include "wx/dcclient.h" | |
22 | ||
c801d85f KB |
23 | #ifdef __BORLANDC__ |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/generic/scrolwin.h" | |
053f9cc1 | 28 | #include "wx/panel.h" |
c801d85f KB |
29 | |
30 | #if !USE_SHARED_LIBRARY | |
053f9cc1 | 31 | BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel) |
c5b42c87 | 32 | EVT_SCROLLWIN(wxScrolledWindow::OnScroll) |
139adb6a RR |
33 | EVT_SIZE(wxScrolledWindow::OnSize) |
34 | EVT_PAINT(wxScrolledWindow::OnPaint) | |
c801d85f KB |
35 | END_EVENT_TABLE() |
36 | ||
053f9cc1 | 37 | IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel) |
c801d85f KB |
38 | #endif |
39 | ||
48d1144b JS |
40 | #ifdef __WXMSW__ |
41 | #include "windows.h" | |
42 | #endif | |
43 | ||
a91b47e8 JS |
44 | #ifdef __WXMOTIF__ |
45 | // For wxRETAINED implementation | |
338dd992 JJ |
46 | #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++ |
47 | //This code switches off the compiler warnings | |
48 | # pragma message disable nosimpint | |
49 | #endif | |
a91b47e8 | 50 | #include <Xm/Xm.h> |
338dd992 JJ |
51 | #ifdef __VMS__ |
52 | # pragma message enable nosimpint | |
53 | #endif | |
a91b47e8 JS |
54 | #endif |
55 | ||
c5b42c87 | 56 | wxScrolledWindow::wxScrolledWindow() |
c801d85f | 57 | { |
139adb6a RR |
58 | m_xScrollPixelsPerLine = 0; |
59 | m_yScrollPixelsPerLine = 0; | |
60 | m_xScrollingEnabled = TRUE; | |
61 | m_yScrollingEnabled = TRUE; | |
62 | m_xScrollPosition = 0; | |
63 | m_yScrollPosition = 0; | |
64 | m_xScrollLines = 0; | |
65 | m_yScrollLines = 0; | |
66 | m_xScrollLinesPerPage = 0; | |
67 | m_yScrollLinesPerPage = 0; | |
68 | m_scaleX = 1.0; | |
69 | m_scaleY = 1.0; | |
c801d85f KB |
70 | } |
71 | ||
debe6624 | 72 | bool wxScrolledWindow::Create(wxWindow *parent, wxWindowID id, |
c801d85f KB |
73 | const wxPoint& pos, |
74 | const wxSize& size, | |
debe6624 | 75 | long style, |
c801d85f KB |
76 | const wxString& name) |
77 | { | |
139adb6a RR |
78 | m_xScrollPixelsPerLine = 0; |
79 | m_yScrollPixelsPerLine = 0; | |
80 | m_xScrollingEnabled = TRUE; | |
81 | m_yScrollingEnabled = TRUE; | |
82 | m_xScrollPosition = 0; | |
83 | m_yScrollPosition = 0; | |
84 | m_xScrollLines = 0; | |
85 | m_yScrollLines = 0; | |
86 | m_xScrollLinesPerPage = 0; | |
87 | m_yScrollLinesPerPage = 0; | |
88 | m_scaleX = 1.0; | |
89 | m_scaleY = 1.0; | |
ecab4dba RR |
90 | |
91 | m_targetWindow = this; | |
139adb6a | 92 | |
053f9cc1 | 93 | return wxPanel::Create(parent, id, pos, size, style, name); |
c801d85f KB |
94 | } |
95 | ||
96 | /* | |
97 | * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line) | |
98 | * noUnitsX/noUnitsY: : no. units per scrollbar | |
99 | */ | |
debe6624 JS |
100 | void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, |
101 | int noUnitsX, int noUnitsY, | |
102 | int xPos, int yPos, bool noRefresh ) | |
c801d85f | 103 | { |
139adb6a RR |
104 | bool do_refresh = |
105 | ( | |
c801d85f | 106 | (noUnitsX != 0 && m_xScrollLines == 0) || |
ea5c6ca7 | 107 | (noUnitsX < m_xScrollLines) || |
c801d85f | 108 | (noUnitsY != 0 && m_yScrollLines == 0) || |
ea5c6ca7 | 109 | (noUnitsY < m_yScrollLines) || |
c801d85f KB |
110 | (xPos != m_xScrollPosition) || |
111 | (yPos != m_yScrollPosition) || | |
112 | (pixelsPerUnitX != m_xScrollPixelsPerLine) || | |
113 | (pixelsPerUnitY != m_yScrollPixelsPerLine) | |
139adb6a | 114 | ); |
c801d85f | 115 | |
139adb6a RR |
116 | m_xScrollPixelsPerLine = pixelsPerUnitX; |
117 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
118 | m_xScrollPosition = xPos; | |
119 | m_yScrollPosition = yPos; | |
120 | m_xScrollLines = noUnitsX; | |
121 | m_yScrollLines = noUnitsY; | |
a91b47e8 JS |
122 | |
123 | #ifdef __WXMOTIF__ | |
124 | // Sorry, some Motif-specific code to implement a backing pixmap | |
125 | // for the wxRETAINED style. Implementing a backing store can't | |
126 | // be entirely generic because it relies on the wxWindowDC implementation | |
127 | // to duplicate X drawing calls for the backing pixmap. | |
128 | ||
129 | if ((m_windowStyle & wxRETAINED) == wxRETAINED) | |
130 | { | |
131 | Display* dpy = XtDisplay((Widget) GetMainWidget()); | |
132 | ||
133 | int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine; | |
134 | int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine; | |
135 | if (m_backingPixmap && | |
136 | !((m_pixmapWidth == totalPixelWidth) && | |
137 | (m_pixmapHeight == totalPixelHeight))) | |
138 | { | |
139 | XFreePixmap (dpy, (Pixmap) m_backingPixmap); | |
140 | m_backingPixmap = (WXPixmap) 0; | |
141 | } | |
142 | ||
143 | if (!m_backingPixmap && | |
144 | (noUnitsX != 0) && (noUnitsY != 0)) | |
145 | { | |
146 | int depth = wxDisplayDepth(); | |
147 | m_pixmapWidth = totalPixelWidth; | |
148 | m_pixmapHeight = totalPixelHeight; | |
149 | m_backingPixmap = (WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)), | |
150 | m_pixmapWidth, m_pixmapHeight, depth); | |
151 | } | |
152 | ||
153 | } | |
154 | #endif | |
d4c99d6f | 155 | |
139adb6a | 156 | AdjustScrollbars(); |
c801d85f | 157 | |
ea5c6ca7 | 158 | if (do_refresh && !noRefresh) |
ecab4dba | 159 | m_targetWindow->Refresh(); |
c801d85f | 160 | |
2049ba38 | 161 | #ifdef __WXMSW__ |
48d1144b | 162 | // Necessary? |
7c74e7fe SC |
163 | UpdateWindow ((HWND) m_targetWindow->GetHWND()); |
164 | #endif | |
165 | #ifdef __WXMAC__ | |
166 | m_targetWindow->MacUpdateImmediately() ; | |
c801d85f KB |
167 | #endif |
168 | } | |
169 | ||
ecab4dba RR |
170 | wxScrolledWindow::~wxScrolledWindow() |
171 | { | |
172 | } | |
173 | ||
174 | void wxScrolledWindow::SetTargetWindow( wxWindow *target ) | |
175 | { | |
176 | wxASSERT_MSG( target, wxT("target window must not be NULL") ); | |
177 | m_targetWindow = target; | |
178 | } | |
179 | ||
180 | wxWindow *wxScrolledWindow::GetTargetWindow() | |
181 | { | |
182 | return m_targetWindow; | |
183 | } | |
184 | ||
c5b42c87 | 185 | void wxScrolledWindow::OnScroll(wxScrollWinEvent& event) |
c801d85f | 186 | { |
139adb6a | 187 | int orient = event.GetOrientation(); |
c801d85f | 188 | |
139adb6a RR |
189 | int nScrollInc = CalcScrollInc(event); |
190 | if (nScrollInc == 0) return; | |
c801d85f | 191 | |
139adb6a RR |
192 | if (orient == wxHORIZONTAL) |
193 | { | |
194 | int newPos = m_xScrollPosition + nScrollInc; | |
195 | SetScrollPos(wxHORIZONTAL, newPos, TRUE ); | |
196 | } | |
197 | else | |
198 | { | |
199 | int newPos = m_yScrollPosition + nScrollInc; | |
200 | SetScrollPos(wxVERTICAL, newPos, TRUE ); | |
201 | } | |
c801d85f | 202 | |
139adb6a RR |
203 | if (orient == wxHORIZONTAL) |
204 | { | |
205 | m_xScrollPosition += nScrollInc; | |
206 | } | |
c801d85f | 207 | else |
139adb6a RR |
208 | { |
209 | m_yScrollPosition += nScrollInc; | |
210 | } | |
211 | ||
212 | if (orient == wxHORIZONTAL) | |
213 | { | |
214 | if (m_xScrollingEnabled) | |
ecab4dba | 215 | m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL); |
139adb6a | 216 | else |
ecab4dba | 217 | m_targetWindow->Refresh(); |
139adb6a | 218 | } |
c801d85f | 219 | else |
139adb6a RR |
220 | { |
221 | if (m_yScrollingEnabled) | |
ecab4dba | 222 | m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL); |
139adb6a | 223 | else |
ecab4dba | 224 | m_targetWindow->Refresh(); |
c801d85f | 225 | } |
7c74e7fe SC |
226 | #ifdef __WXMAC__ |
227 | m_targetWindow->MacUpdateImmediately() ; | |
228 | #endif | |
c801d85f KB |
229 | } |
230 | ||
c5b42c87 | 231 | int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) |
c801d85f | 232 | { |
ecab4dba RR |
233 | int pos = event.GetPosition(); |
234 | int orient = event.GetOrientation(); | |
c801d85f | 235 | |
ecab4dba RR |
236 | int nScrollInc = 0; |
237 | switch (event.GetEventType()) | |
c801d85f | 238 | { |
ecab4dba RR |
239 | case wxEVT_SCROLLWIN_TOP: |
240 | { | |
241 | if (orient == wxHORIZONTAL) | |
242 | nScrollInc = - m_xScrollPosition; | |
243 | else | |
244 | nScrollInc = - m_yScrollPosition; | |
245 | break; | |
246 | } | |
247 | case wxEVT_SCROLLWIN_BOTTOM: | |
248 | { | |
249 | if (orient == wxHORIZONTAL) | |
250 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
251 | else | |
252 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
253 | break; | |
254 | } | |
255 | case wxEVT_SCROLLWIN_LINEUP: | |
256 | { | |
257 | nScrollInc = -1; | |
258 | break; | |
259 | } | |
260 | case wxEVT_SCROLLWIN_LINEDOWN: | |
261 | { | |
262 | nScrollInc = 1; | |
263 | break; | |
264 | } | |
265 | case wxEVT_SCROLLWIN_PAGEUP: | |
266 | { | |
267 | if (orient == wxHORIZONTAL) | |
268 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
269 | else | |
270 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
271 | break; | |
272 | } | |
273 | case wxEVT_SCROLLWIN_PAGEDOWN: | |
274 | { | |
275 | if (orient == wxHORIZONTAL) | |
276 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
277 | else | |
278 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
279 | break; | |
280 | } | |
281 | case wxEVT_SCROLLWIN_THUMBTRACK: | |
282 | { | |
283 | if (orient == wxHORIZONTAL) | |
284 | nScrollInc = pos - m_xScrollPosition; | |
285 | else | |
286 | nScrollInc = pos - m_yScrollPosition; | |
287 | break; | |
288 | } | |
289 | default: | |
290 | { | |
291 | break; | |
292 | } | |
c801d85f | 293 | } |
88150e60 | 294 | |
ecab4dba RR |
295 | if (orient == wxHORIZONTAL) |
296 | { | |
297 | if (m_xScrollPixelsPerLine > 0) | |
298 | { | |
299 | int w, h; | |
300 | m_targetWindow->GetClientSize(&w, &h); | |
301 | ||
302 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
303 | int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
304 | if (noPositions < 0) | |
305 | noPositions = 0; | |
306 | ||
307 | if ( (m_xScrollPosition + nScrollInc) < 0 ) | |
308 | nScrollInc = -m_xScrollPosition; // As -ve as we can go | |
309 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) | |
310 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go | |
311 | } | |
312 | else | |
313 | m_targetWindow->Refresh(); | |
9d9355c6 VZ |
314 | } |
315 | else | |
ecab4dba RR |
316 | { |
317 | if (m_yScrollPixelsPerLine > 0) | |
318 | { | |
319 | int w, h; | |
320 | m_targetWindow->GetClientSize(&w, &h); | |
9d9355c6 | 321 | |
ecab4dba RR |
322 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; |
323 | int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
324 | if (noPositions < 0) | |
325 | noPositions = 0; | |
9d9355c6 | 326 | |
ecab4dba RR |
327 | if ( (m_yScrollPosition + nScrollInc) < 0 ) |
328 | nScrollInc = -m_yScrollPosition; // As -ve as we can go | |
329 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) | |
330 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go | |
331 | } | |
332 | else | |
333 | m_targetWindow->Refresh(); | |
9d9355c6 | 334 | } |
9d9355c6 | 335 | |
ecab4dba | 336 | return nScrollInc; |
c801d85f KB |
337 | } |
338 | ||
339 | // Adjust the scrollbars - new version. | |
27d029c7 | 340 | void wxScrolledWindow::AdjustScrollbars() |
c801d85f | 341 | { |
139adb6a | 342 | int w, h; |
ecab4dba | 343 | m_targetWindow->GetClientSize(&w, &h); |
27d029c7 RR |
344 | |
345 | int oldXScroll = m_xScrollPosition; | |
346 | int oldYScroll = m_yScrollPosition; | |
c801d85f | 347 | |
139adb6a RR |
348 | if (m_xScrollLines > 0) |
349 | { | |
c801d85f KB |
350 | // Calculate page size i.e. number of scroll units you get on the |
351 | // current client window | |
ecab4dba | 352 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); |
139adb6a | 353 | if (noPagePositions < 1) noPagePositions = 1; |
c801d85f | 354 | |
139adb6a RR |
355 | // Correct position if greater than extent of canvas minus |
356 | // the visible portion of it or if below zero | |
357 | m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition); | |
358 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
c801d85f | 359 | |
139adb6a | 360 | SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); |
88150e60 JS |
361 | // The amount by which we scroll when paging |
362 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
139adb6a RR |
363 | } |
364 | else | |
365 | { | |
366 | m_xScrollPosition = 0; | |
367 | SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE); | |
368 | } | |
369 | ||
370 | if (m_yScrollLines > 0) | |
371 | { | |
c801d85f KB |
372 | // Calculate page size i.e. number of scroll units you get on the |
373 | // current client window | |
ecab4dba | 374 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); |
139adb6a | 375 | if (noPagePositions < 1) noPagePositions = 1; |
c801d85f | 376 | |
139adb6a RR |
377 | // Correct position if greater than extent of canvas minus |
378 | // the visible portion of it or if below zero | |
379 | m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); | |
380 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
381 | ||
382 | SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines); | |
88150e60 JS |
383 | // The amount by which we scroll when paging |
384 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
139adb6a RR |
385 | } |
386 | else | |
387 | { | |
388 | m_yScrollPosition = 0; | |
389 | SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); | |
390 | } | |
27d029c7 RR |
391 | |
392 | if (oldXScroll != m_xScrollPosition) | |
393 | { | |
394 | if (m_xScrollingEnabled) | |
ecab4dba | 395 | m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll-m_xScrollPosition), 0, (const wxRect *) NULL ); |
27d029c7 | 396 | else |
ecab4dba | 397 | m_targetWindow->Refresh(); |
27d029c7 RR |
398 | } |
399 | ||
400 | if (oldYScroll != m_yScrollPosition) | |
401 | { | |
402 | if (m_yScrollingEnabled) | |
ecab4dba | 403 | m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), (const wxRect *) NULL ); |
27d029c7 | 404 | else |
ecab4dba | 405 | m_targetWindow->Refresh(); |
27d029c7 | 406 | } |
c801d85f KB |
407 | } |
408 | ||
409 | // Default OnSize resets scrollbars, if any | |
410 | void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)) | |
411 | { | |
47d67540 | 412 | #if wxUSE_CONSTRAINTS |
139adb6a | 413 | if (GetAutoLayout()) Layout(); |
c801d85f KB |
414 | #endif |
415 | ||
139adb6a | 416 | AdjustScrollbars(); |
c801d85f KB |
417 | } |
418 | ||
419 | // This calls OnDraw, having adjusted the origin according to the current | |
420 | // scroll position | |
421 | void wxScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
422 | { | |
139adb6a RR |
423 | wxPaintDC dc(this); |
424 | PrepareDC(dc); | |
c801d85f | 425 | |
139adb6a | 426 | OnDraw(dc); |
c801d85f KB |
427 | } |
428 | ||
429 | // Override this function if you don't want to have wxScrolledWindow | |
430 | // automatically change the origin according to the scroll position. | |
431 | void wxScrolledWindow::PrepareDC(wxDC& dc) | |
432 | { | |
139adb6a RR |
433 | dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine, |
434 | -m_yScrollPosition * m_yScrollPixelsPerLine ); | |
435 | dc.SetUserScale( m_scaleX, m_scaleY ); | |
c801d85f KB |
436 | } |
437 | ||
438 | #if WXWIN_COMPATIBILITY | |
439 | void wxScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const | |
440 | { | |
441 | *x_page = GetScrollPageSize(wxHORIZONTAL); | |
442 | *y_page = GetScrollPageSize(wxVERTICAL); | |
443 | } | |
a0bc2c1d VZ |
444 | |
445 | void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const | |
446 | { | |
447 | if ( xx ) | |
448 | *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine); | |
449 | if ( yy ) | |
450 | *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine); | |
451 | } | |
452 | #endif // WXWIN_COMPATIBILITY | |
c801d85f KB |
453 | |
454 | void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const | |
455 | { | |
a0bc2c1d VZ |
456 | if ( x_unit ) |
457 | *x_unit = m_xScrollPixelsPerLine; | |
458 | if ( y_unit ) | |
459 | *y_unit = m_yScrollPixelsPerLine; | |
c801d85f KB |
460 | } |
461 | ||
462 | int wxScrolledWindow::GetScrollPageSize(int orient) const | |
463 | { | |
464 | if ( orient == wxHORIZONTAL ) | |
465 | return m_xScrollLinesPerPage; | |
466 | else | |
467 | return m_yScrollLinesPerPage; | |
468 | } | |
469 | ||
470 | void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize) | |
471 | { | |
472 | if ( orient == wxHORIZONTAL ) | |
473 | m_xScrollLinesPerPage = pageSize; | |
474 | else | |
475 | m_yScrollLinesPerPage = pageSize; | |
476 | } | |
477 | ||
478 | /* | |
479 | * Scroll to given position (scroll position, not pixel position) | |
480 | */ | |
139adb6a | 481 | void wxScrolledWindow::Scroll( int x_pos, int y_pos ) |
c801d85f | 482 | { |
139adb6a RR |
483 | if (((x_pos == -1) || (x_pos == m_xScrollPosition)) && |
484 | ((y_pos == -1) || (y_pos == m_yScrollPosition))) return; | |
485 | ||
486 | int w, h; | |
ecab4dba | 487 | m_targetWindow->GetClientSize(&w, &h); |
c801d85f | 488 | |
139adb6a | 489 | if (x_pos != -1) |
c801d85f | 490 | { |
ed673c6a | 491 | int old_x = m_xScrollPosition; |
139adb6a RR |
492 | m_xScrollPosition = x_pos; |
493 | ||
494 | // Calculate page size i.e. number of scroll units you get on the | |
495 | // current client window | |
ecab4dba | 496 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
497 | if (noPagePositions < 1) noPagePositions = 1; |
498 | ||
499 | // Correct position if greater than extent of canvas minus | |
500 | // the visible portion of it or if below zero | |
501 | m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition ); | |
502 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
503 | ||
ecab4dba | 504 | m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE ); |
ed673c6a | 505 | |
ecab4dba | 506 | m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); |
c801d85f | 507 | } |
139adb6a | 508 | if (y_pos != -1) |
c801d85f | 509 | { |
ed673c6a | 510 | int old_y = m_yScrollPosition; |
139adb6a RR |
511 | m_yScrollPosition = y_pos; |
512 | ||
513 | // Calculate page size i.e. number of scroll units you get on the | |
514 | // current client window | |
ecab4dba | 515 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
516 | if (noPagePositions < 1) noPagePositions = 1; |
517 | ||
518 | // Correct position if greater than extent of canvas minus | |
519 | // the visible portion of it or if below zero | |
520 | m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); | |
521 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
522 | ||
ecab4dba | 523 | m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE ); |
ed673c6a | 524 | |
ecab4dba | 525 | m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); |
c801d85f | 526 | } |
139adb6a | 527 | |
139adb6a | 528 | |
2049ba38 | 529 | #ifdef __WXMSW__ |
ed673c6a | 530 | // ::UpdateWindow ((HWND) GetHWND()); |
5e014a0c | 531 | #else |
ed673c6a | 532 | // Refresh(); |
c801d85f | 533 | #endif |
7c74e7fe SC |
534 | #ifdef __WXMAC__ |
535 | m_targetWindow->MacUpdateImmediately() ; | |
536 | #endif | |
c801d85f KB |
537 | } |
538 | ||
debe6624 | 539 | void wxScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll) |
c801d85f | 540 | { |
139adb6a RR |
541 | m_xScrollingEnabled = x_scroll; |
542 | m_yScrollingEnabled = y_scroll; | |
c801d85f KB |
543 | } |
544 | ||
545 | void wxScrolledWindow::GetVirtualSize (int *x, int *y) const | |
546 | { | |
a0bc2c1d VZ |
547 | if ( x ) |
548 | *x = m_xScrollPixelsPerLine * m_xScrollLines; | |
549 | if ( y ) | |
550 | *y = m_yScrollPixelsPerLine * m_yScrollLines; | |
c801d85f KB |
551 | } |
552 | ||
553 | // Where the current view starts from | |
554 | void wxScrolledWindow::ViewStart (int *x, int *y) const | |
555 | { | |
a0bc2c1d VZ |
556 | if ( x ) |
557 | *x = m_xScrollPosition; | |
558 | if ( y ) | |
559 | *y = m_yScrollPosition; | |
c801d85f KB |
560 | } |
561 | ||
debe6624 | 562 | void wxScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 563 | { |
a0bc2c1d VZ |
564 | if ( xx ) |
565 | *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; | |
566 | if ( yy ) | |
567 | *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f KB |
568 | } |
569 | ||
a0bc2c1d | 570 | void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 571 | { |
a0bc2c1d VZ |
572 | if ( xx ) |
573 | *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine; | |
574 | if ( yy ) | |
575 | *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f | 576 | } |