]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
d80cd92a | 2 | // Name: generic/scrolwin.cpp |
fa3541bd | 3 | // Purpose: wxGenericScrolledWindow implementation |
c801d85f | 4 | // Author: Julian Smart |
566d84a7 RL |
5 | // Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement. |
6 | // Ron Lee on 10.4.02: virtual size / auto scrollbars et al. | |
c801d85f KB |
7 | // Created: 01/02/97 |
8 | // RCS-ID: $Id$ | |
1e6feb95 | 9 | // Copyright: (c) wxWindows team |
a58a12e9 | 10 | // Licence: wxWindows license |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
d80cd92a VZ |
13 | // ============================================================================ |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
c801d85f | 21 | #ifdef __GNUG__ |
3a8c693a | 22 | #pragma implementation "genscrolwin.h" |
c801d85f KB |
23 | #endif |
24 | ||
bcd055ae JJ |
25 | #ifdef __VMS |
26 | #define XtDisplay XTDISPLAY | |
27 | #endif | |
28 | ||
c801d85f KB |
29 | // For compilers that support precompilation, includes "wx.h". |
30 | #include "wx/wxprec.h" | |
31 | ||
c801d85f | 32 | #ifdef __BORLANDC__ |
d80cd92a | 33 | #pragma hdrstop |
c801d85f KB |
34 | #endif |
35 | ||
3a8c693a VZ |
36 | #if !defined(__WXGTK__) || defined(__WXUNIVERSAL__) |
37 | ||
d80cd92a VZ |
38 | #include "wx/utils.h" |
39 | #include "wx/dcclient.h" | |
40 | ||
1e6feb95 | 41 | #include "wx/scrolwin.h" |
053f9cc1 | 42 | #include "wx/panel.h" |
1e6feb95 | 43 | #include "wx/timer.h" |
95d60b24 | 44 | #include "wx/sizer.h" |
c801d85f | 45 | |
48d1144b | 46 | #ifdef __WXMSW__ |
1e6feb95 | 47 | #include <windows.h> // for DLGC_WANTARROWS |
48d1144b JS |
48 | #endif |
49 | ||
a91b47e8 JS |
50 | #ifdef __WXMOTIF__ |
51 | // For wxRETAINED implementation | |
338dd992 JJ |
52 | #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++ |
53 | //This code switches off the compiler warnings | |
54 | # pragma message disable nosimpint | |
55 | #endif | |
a91b47e8 | 56 | #include <Xm/Xm.h> |
338dd992 JJ |
57 | #ifdef __VMS__ |
58 | # pragma message enable nosimpint | |
59 | #endif | |
a91b47e8 JS |
60 | #endif |
61 | ||
fa3541bd | 62 | IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow) |
fa3541bd | 63 | |
d80cd92a | 64 | // ---------------------------------------------------------------------------- |
1e6feb95 VZ |
65 | // wxScrollHelperEvtHandler: intercept the events from the window and forward |
66 | // them to wxScrollHelper | |
d80cd92a VZ |
67 | // ---------------------------------------------------------------------------- |
68 | ||
349efbaa | 69 | class WXDLLEXPORT wxScrollHelperEvtHandler : public wxEvtHandler |
1e6feb95 VZ |
70 | { |
71 | public: | |
72 | wxScrollHelperEvtHandler(wxScrollHelper *scrollHelper) | |
73 | { | |
74 | m_scrollHelper = scrollHelper; | |
75 | } | |
d80cd92a | 76 | |
1e6feb95 VZ |
77 | virtual bool ProcessEvent(wxEvent& event); |
78 | ||
349efbaa VZ |
79 | void ResetDrawnFlag() { m_hasDrawnWindow = FALSE; } |
80 | ||
1e6feb95 VZ |
81 | private: |
82 | wxScrollHelper *m_scrollHelper; | |
349efbaa VZ |
83 | |
84 | bool m_hasDrawnWindow; | |
1e6feb95 VZ |
85 | }; |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // wxAutoScrollTimer: the timer used to generate a stream of scroll events when | |
89 | // a captured mouse is held outside the window | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | class wxAutoScrollTimer : public wxTimer | |
93 | { | |
94 | public: | |
95 | wxAutoScrollTimer(wxWindow *winToScroll, wxScrollHelper *scroll, | |
96 | wxEventType eventTypeToSend, | |
97 | int pos, int orient); | |
98 | ||
99 | virtual void Notify(); | |
100 | ||
101 | private: | |
102 | wxWindow *m_win; | |
103 | wxScrollHelper *m_scrollHelper; | |
104 | wxEventType m_eventType; | |
105 | int m_pos, | |
106 | m_orient; | |
107 | }; | |
d80cd92a VZ |
108 | |
109 | // ============================================================================ | |
110 | // implementation | |
111 | // ============================================================================ | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 114 | // wxAutoScrollTimer |
d80cd92a VZ |
115 | // ---------------------------------------------------------------------------- |
116 | ||
1e6feb95 VZ |
117 | wxAutoScrollTimer::wxAutoScrollTimer(wxWindow *winToScroll, |
118 | wxScrollHelper *scroll, | |
119 | wxEventType eventTypeToSend, | |
120 | int pos, int orient) | |
c801d85f | 121 | { |
1e6feb95 VZ |
122 | m_win = winToScroll; |
123 | m_scrollHelper = scroll; | |
124 | m_eventType = eventTypeToSend; | |
125 | m_pos = pos; | |
126 | m_orient = orient; | |
c801d85f KB |
127 | } |
128 | ||
1e6feb95 | 129 | void wxAutoScrollTimer::Notify() |
c801d85f | 130 | { |
1e6feb95 VZ |
131 | // only do all this as long as the window is capturing the mouse |
132 | if ( wxWindow::GetCapture() != m_win ) | |
133 | { | |
134 | Stop(); | |
135 | } | |
136 | else // we still capture the mouse, continue generating events | |
137 | { | |
138 | // first scroll the window if we are allowed to do it | |
139 | wxScrollWinEvent event1(m_eventType, m_pos, m_orient); | |
140 | event1.SetEventObject(m_win); | |
141 | if ( m_scrollHelper->SendAutoScrollEvents(event1) && | |
142 | m_win->GetEventHandler()->ProcessEvent(event1) ) | |
143 | { | |
144 | // and then send a pseudo mouse-move event to refresh the selection | |
145 | wxMouseEvent event2(wxEVT_MOTION); | |
146 | wxGetMousePosition(&event2.m_x, &event2.m_y); | |
147 | ||
148 | // the mouse event coordinates should be client, not screen as | |
149 | // returned by wxGetMousePosition | |
150 | wxWindow *parentTop = m_win; | |
151 | while ( parentTop->GetParent() ) | |
152 | parentTop = parentTop->GetParent(); | |
153 | wxPoint ptOrig = parentTop->GetPosition(); | |
154 | event2.m_x -= ptOrig.x; | |
155 | event2.m_y -= ptOrig.y; | |
156 | ||
157 | event2.SetEventObject(m_win); | |
158 | ||
159 | // FIXME: we don't fill in the other members - ok? | |
160 | ||
161 | m_win->GetEventHandler()->ProcessEvent(event2); | |
162 | } | |
163 | else // can't scroll further, stop | |
164 | { | |
165 | Stop(); | |
166 | } | |
167 | } | |
168 | } | |
169 | ||
170 | // ---------------------------------------------------------------------------- | |
171 | // wxScrollHelperEvtHandler | |
172 | // ---------------------------------------------------------------------------- | |
173 | ||
174 | bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) | |
175 | { | |
9a268018 | 176 | wxEventType evType = event.GetEventType(); |
2feed004 | 177 | |
349efbaa VZ |
178 | // the explanation of wxEVT_PAINT processing hack: for historic reasons |
179 | // there are 2 ways to process this event in classes deriving from | |
180 | // wxScrolledWindow. The user code may | |
181 | // | |
182 | // 1. override wxScrolledWindow::OnDraw(dc) | |
183 | // 2. define its own OnPaint() handler | |
184 | // | |
185 | // In addition, in wxUniversal wxWindow defines OnPaint() itself and | |
186 | // always processes the draw event, so we can't just try the window | |
187 | // OnPaint() first and call our HandleOnPaint() if it doesn't process it | |
188 | // (the latter would never be called in wxUniversal). | |
189 | // | |
190 | // So the solution is to have a flag telling us whether the user code drew | |
191 | // anything in the window. We set it to true here but reset it to false in | |
192 | // wxScrolledWindow::OnPaint() handler (which wouldn't be called if the | |
193 | // user code defined OnPaint() in the derived class) | |
194 | m_hasDrawnWindow = TRUE; | |
195 | ||
ff186591 VZ |
196 | // pass it on to the real handler |
197 | bool processed = wxEvtHandler::ProcessEvent(event); | |
198 | ||
199 | // always process the size events ourselves, even if the user code handles | |
200 | // them as well, as we need to AdjustScrollbars() | |
201 | // | |
202 | // NB: it is important to do it after processing the event in the normal | |
203 | // way as HandleOnSize() may generate a wxEVT_SIZE itself if the | |
204 | // scrollbar[s] (dis)appear and it should be seen by the user code | |
205 | // after this one | |
206 | if ( evType == wxEVT_SIZE ) | |
207 | { | |
208 | m_scrollHelper->HandleOnSize((wxSizeEvent &)event); | |
209 | ||
210 | return TRUE; | |
211 | } | |
212 | ||
213 | if ( processed ) | |
349efbaa VZ |
214 | { |
215 | // normally, nothing more to do here - except if it was a paint event | |
216 | // which wasn't really processed, then we'll try to call our | |
217 | // OnDraw() below (from HandleOnPaint) | |
993cfa87 | 218 | if ( m_hasDrawnWindow ) |
349efbaa VZ |
219 | { |
220 | return TRUE; | |
221 | } | |
222 | } | |
2feed004 | 223 | |
1e6feb95 VZ |
224 | // reset the skipped flag to FALSE as it might have been set to TRUE in |
225 | // ProcessEvent() above | |
226 | event.Skip(FALSE); | |
227 | ||
e421922f VZ |
228 | if ( evType == wxEVT_PAINT ) |
229 | { | |
230 | m_scrollHelper->HandleOnPaint((wxPaintEvent &)event); | |
231 | return TRUE; | |
232 | } | |
1e6feb95 | 233 | |
e421922f VZ |
234 | if ( evType == wxEVT_SCROLLWIN_TOP || |
235 | evType == wxEVT_SCROLLWIN_BOTTOM || | |
236 | evType == wxEVT_SCROLLWIN_LINEUP || | |
237 | evType == wxEVT_SCROLLWIN_LINEDOWN || | |
238 | evType == wxEVT_SCROLLWIN_PAGEUP || | |
239 | evType == wxEVT_SCROLLWIN_PAGEDOWN || | |
240 | evType == wxEVT_SCROLLWIN_THUMBTRACK || | |
241 | evType == wxEVT_SCROLLWIN_THUMBRELEASE ) | |
242 | { | |
243 | m_scrollHelper->HandleOnScroll((wxScrollWinEvent &)event); | |
1e6feb95 | 244 | return !event.GetSkipped(); |
e421922f | 245 | } |
1e6feb95 | 246 | |
e421922f VZ |
247 | if ( evType == wxEVT_ENTER_WINDOW ) |
248 | { | |
249 | m_scrollHelper->HandleOnMouseEnter((wxMouseEvent &)event); | |
250 | } | |
251 | else if ( evType == wxEVT_LEAVE_WINDOW ) | |
252 | { | |
253 | m_scrollHelper->HandleOnMouseLeave((wxMouseEvent &)event); | |
254 | } | |
255 | #if wxUSE_MOUSEWHEEL | |
256 | else if ( evType == wxEVT_MOUSEWHEEL ) | |
257 | { | |
258 | m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event); | |
259 | } | |
260 | #endif // wxUSE_MOUSEWHEEL | |
e421922f VZ |
261 | else if ( evType == wxEVT_CHAR ) |
262 | { | |
263 | m_scrollHelper->HandleOnChar((wxKeyEvent &)event); | |
264 | return !event.GetSkipped(); | |
1e6feb95 VZ |
265 | } |
266 | ||
267 | return FALSE; | |
268 | } | |
269 | ||
270 | // ---------------------------------------------------------------------------- | |
271 | // wxScrollHelper construction | |
272 | // ---------------------------------------------------------------------------- | |
273 | ||
274 | wxScrollHelper::wxScrollHelper(wxWindow *win) | |
275 | { | |
276 | m_xScrollPixelsPerLine = | |
277 | m_yScrollPixelsPerLine = | |
278 | m_xScrollPosition = | |
279 | m_yScrollPosition = | |
280 | m_xScrollLines = | |
281 | m_yScrollLines = | |
282 | m_xScrollLinesPerPage = | |
139adb6a | 283 | m_yScrollLinesPerPage = 0; |
1e6feb95 VZ |
284 | |
285 | m_xScrollingEnabled = | |
286 | m_yScrollingEnabled = TRUE; | |
287 | ||
288 | m_scaleX = | |
139adb6a | 289 | m_scaleY = 1.0; |
24ce4c18 | 290 | #if wxUSE_MOUSEWHEEL |
d2c52078 | 291 | m_wheelRotation = 0; |
24ce4c18 | 292 | #endif |
a58a12e9 | 293 | |
1e6feb95 VZ |
294 | m_win = |
295 | m_targetWindow = (wxWindow *)NULL; | |
139adb6a | 296 | |
1e6feb95 | 297 | m_timerAutoScroll = (wxTimer *)NULL; |
d7da9756 | 298 | |
349efbaa VZ |
299 | m_handler = NULL; |
300 | ||
1e6feb95 VZ |
301 | if ( win ) |
302 | SetWindow(win); | |
303 | } | |
d7da9756 | 304 | |
1e6feb95 | 305 | wxScrollHelper::~wxScrollHelper() |
d80cd92a | 306 | { |
1e6feb95 VZ |
307 | StopAutoScrolling(); |
308 | ||
349efbaa | 309 | DeleteEvtHandler(); |
d80cd92a VZ |
310 | } |
311 | ||
312 | // ---------------------------------------------------------------------------- | |
313 | // setting scrolling parameters | |
314 | // ---------------------------------------------------------------------------- | |
315 | ||
1e6feb95 VZ |
316 | void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, |
317 | int pixelsPerUnitY, | |
318 | int noUnitsX, | |
319 | int noUnitsY, | |
320 | int xPos, | |
321 | int yPos, | |
322 | bool noRefresh) | |
c801d85f | 323 | { |
b0486e0d SN |
324 | int xpos, ypos; |
325 | ||
326 | CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos); | |
139adb6a RR |
327 | bool do_refresh = |
328 | ( | |
c801d85f | 329 | (noUnitsX != 0 && m_xScrollLines == 0) || |
566d84a7 | 330 | (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX * noUnitsX) || |
b0486e0d | 331 | |
c801d85f | 332 | (noUnitsY != 0 && m_yScrollLines == 0) || |
566d84a7 | 333 | (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY * noUnitsY) || |
c801d85f | 334 | (xPos != m_xScrollPosition) || |
b0486e0d | 335 | (yPos != m_yScrollPosition) |
139adb6a | 336 | ); |
a58a12e9 | 337 | |
139adb6a RR |
338 | m_xScrollPixelsPerLine = pixelsPerUnitX; |
339 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
340 | m_xScrollPosition = xPos; | |
341 | m_yScrollPosition = yPos; | |
a91b47e8 | 342 | |
2b5f62a0 VZ |
343 | // For better backward compatibility we set persisting limits |
344 | // here not just the size. It makes SetScrollbars 'sticky' | |
345 | // emulating the old non-autoscroll behaviour. | |
346 | ||
566d84a7 | 347 | m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); |
a58a12e9 | 348 | |
2b5f62a0 VZ |
349 | // The above should arguably be deprecated, this however we still need. |
350 | ||
351 | m_targetWindow->SetVirtualSize( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); | |
dc429f89 | 352 | |
a58a12e9 | 353 | if (do_refresh && !noRefresh) |
1e6feb95 | 354 | m_targetWindow->Refresh(TRUE, GetRect()); |
a58a12e9 | 355 | |
03d1ae17 JS |
356 | // TODO: check if we can use AdjustScrollbars always. |
357 | #ifdef __WXUNIVERSAL__ | |
358 | AdjustScrollbars(); | |
359 | #else | |
360 | // This is also done by AdjustScrollbars, above | |
7c74e7fe | 361 | #ifdef __WXMAC__ |
d80cd92a | 362 | m_targetWindow->MacUpdateImmediately() ; |
c801d85f | 363 | #endif |
03d1ae17 | 364 | #endif |
c801d85f KB |
365 | } |
366 | ||
d80cd92a | 367 | // ---------------------------------------------------------------------------- |
af4088f1 | 368 | // [target] window handling |
d80cd92a | 369 | // ---------------------------------------------------------------------------- |
ecab4dba | 370 | |
349efbaa | 371 | void wxScrollHelper::DeleteEvtHandler() |
ecab4dba | 372 | { |
248d771c VZ |
373 | // search for m_handler in the handler list |
374 | if ( m_win && m_handler ) | |
349efbaa | 375 | { |
74f6bbf9 | 376 | if ( m_win->RemoveEventHandler(m_handler) ) |
248d771c | 377 | { |
74f6bbf9 | 378 | delete m_handler; |
248d771c | 379 | } |
74f6bbf9 VZ |
380 | //else: something is very wrong, so better [maybe] leak memory than |
381 | // risk a crash because of double deletion | |
248d771c | 382 | |
74f6bbf9 | 383 | m_handler = NULL; |
349efbaa VZ |
384 | } |
385 | } | |
386 | ||
387 | void wxScrollHelper::SetWindow(wxWindow *win) | |
388 | { | |
389 | wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") ); | |
390 | ||
391 | m_win = win; | |
392 | ||
af4088f1 VZ |
393 | // by default, the associated window is also the target window |
394 | DoSetTargetWindow(win); | |
349efbaa VZ |
395 | } |
396 | ||
af4088f1 | 397 | void wxScrollHelper::DoSetTargetWindow(wxWindow *target) |
349efbaa | 398 | { |
ecab4dba | 399 | m_targetWindow = target; |
349efbaa VZ |
400 | |
401 | // install the event handler which will intercept the events we're | |
af4088f1 VZ |
402 | // interested in (but only do it for our real window, not the target window |
403 | // which we scroll - we don't need to hijack its events) | |
404 | if ( m_targetWindow == m_win ) | |
13ff9344 | 405 | { |
248d771c VZ |
406 | // if we already have a handler, delete it first |
407 | DeleteEvtHandler(); | |
408 | ||
13ff9344 JS |
409 | m_handler = new wxScrollHelperEvtHandler(this); |
410 | m_targetWindow->PushEventHandler(m_handler); | |
411 | } | |
349efbaa VZ |
412 | } |
413 | ||
af4088f1 | 414 | void wxScrollHelper::SetTargetWindow(wxWindow *target) |
349efbaa VZ |
415 | { |
416 | wxCHECK_RET( target, wxT("target window must not be NULL") ); | |
417 | ||
418 | if ( target == m_targetWindow ) | |
419 | return; | |
420 | ||
af4088f1 | 421 | DoSetTargetWindow(target); |
ecab4dba RR |
422 | } |
423 | ||
1e6feb95 | 424 | wxWindow *wxScrollHelper::GetTargetWindow() const |
ecab4dba RR |
425 | { |
426 | return m_targetWindow; | |
427 | } | |
428 | ||
d80cd92a VZ |
429 | // ---------------------------------------------------------------------------- |
430 | // scrolling implementation itself | |
431 | // ---------------------------------------------------------------------------- | |
432 | ||
1e6feb95 | 433 | void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event) |
c801d85f | 434 | { |
139adb6a | 435 | int nScrollInc = CalcScrollInc(event); |
1e6feb95 | 436 | if ( nScrollInc == 0 ) |
139adb6a | 437 | { |
1e6feb95 VZ |
438 | // can't scroll further |
439 | event.Skip(); | |
440 | ||
441 | return; | |
139adb6a | 442 | } |
c801d85f | 443 | |
1e6feb95 | 444 | int orient = event.GetOrientation(); |
139adb6a RR |
445 | if (orient == wxHORIZONTAL) |
446 | { | |
447 | m_xScrollPosition += nScrollInc; | |
5f3286d1 | 448 | m_win->SetScrollPos(wxHORIZONTAL, m_xScrollPosition); |
139adb6a | 449 | } |
c801d85f | 450 | else |
139adb6a RR |
451 | { |
452 | m_yScrollPosition += nScrollInc; | |
5f3286d1 | 453 | m_win->SetScrollPos(wxVERTICAL, m_yScrollPosition); |
139adb6a | 454 | } |
a58a12e9 | 455 | |
1e6feb95 VZ |
456 | bool needsRefresh = FALSE; |
457 | int dx = 0, | |
458 | dy = 0; | |
139adb6a RR |
459 | if (orient == wxHORIZONTAL) |
460 | { | |
1e6feb95 VZ |
461 | if ( m_xScrollingEnabled ) |
462 | { | |
463 | dx = -m_xScrollPixelsPerLine * nScrollInc; | |
464 | } | |
139adb6a | 465 | else |
1e6feb95 VZ |
466 | { |
467 | needsRefresh = TRUE; | |
468 | } | |
139adb6a | 469 | } |
c801d85f | 470 | else |
139adb6a | 471 | { |
1e6feb95 VZ |
472 | if ( m_yScrollingEnabled ) |
473 | { | |
474 | dy = -m_yScrollPixelsPerLine * nScrollInc; | |
475 | } | |
139adb6a | 476 | else |
1e6feb95 VZ |
477 | { |
478 | needsRefresh = TRUE; | |
479 | } | |
480 | } | |
481 | ||
482 | if ( needsRefresh ) | |
483 | { | |
484 | m_targetWindow->Refresh(TRUE, GetRect()); | |
485 | } | |
486 | else | |
487 | { | |
488 | m_targetWindow->ScrollWindow(dx, dy, GetRect()); | |
3d2b9c20 | 489 | } |
1e6feb95 | 490 | |
7c74e7fe | 491 | #ifdef __WXMAC__ |
d80cd92a | 492 | m_targetWindow->MacUpdateImmediately() ; |
7c74e7fe | 493 | #endif |
c801d85f KB |
494 | } |
495 | ||
1e6feb95 | 496 | int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event) |
c801d85f | 497 | { |
ecab4dba RR |
498 | int pos = event.GetPosition(); |
499 | int orient = event.GetOrientation(); | |
c801d85f | 500 | |
ecab4dba | 501 | int nScrollInc = 0; |
1a8caf94 | 502 | if (event.GetEventType() == wxEVT_SCROLLWIN_TOP) |
c801d85f | 503 | { |
ecab4dba RR |
504 | if (orient == wxHORIZONTAL) |
505 | nScrollInc = - m_xScrollPosition; | |
506 | else | |
507 | nScrollInc = - m_yScrollPosition; | |
1a8caf94 RR |
508 | } else |
509 | if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM) | |
510 | { | |
ecab4dba RR |
511 | if (orient == wxHORIZONTAL) |
512 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
513 | else | |
514 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
1a8caf94 RR |
515 | } else |
516 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP) | |
517 | { | |
ecab4dba | 518 | nScrollInc = -1; |
1a8caf94 RR |
519 | } else |
520 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN) | |
521 | { | |
ecab4dba | 522 | nScrollInc = 1; |
1a8caf94 RR |
523 | } else |
524 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP) | |
525 | { | |
ecab4dba RR |
526 | if (orient == wxHORIZONTAL) |
527 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
528 | else | |
529 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
530 | } else |
531 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN) | |
532 | { | |
ecab4dba RR |
533 | if (orient == wxHORIZONTAL) |
534 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
535 | else | |
536 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
537 | } else |
538 | if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) || | |
539 | (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE)) | |
540 | { | |
ecab4dba RR |
541 | if (orient == wxHORIZONTAL) |
542 | nScrollInc = pos - m_xScrollPosition; | |
543 | else | |
544 | nScrollInc = pos - m_yScrollPosition; | |
c801d85f | 545 | } |
88150e60 | 546 | |
ecab4dba RR |
547 | if (orient == wxHORIZONTAL) |
548 | { | |
a58a12e9 | 549 | if (m_xScrollPixelsPerLine > 0) |
ecab4dba RR |
550 | { |
551 | int w, h; | |
1e6feb95 | 552 | GetTargetSize(&w, &h); |
ecab4dba RR |
553 | |
554 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
555 | int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
556 | if (noPositions < 0) | |
d80cd92a | 557 | noPositions = 0; |
ecab4dba RR |
558 | |
559 | if ( (m_xScrollPosition + nScrollInc) < 0 ) | |
d80cd92a | 560 | nScrollInc = -m_xScrollPosition; // As -ve as we can go |
ecab4dba | 561 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 562 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go |
ecab4dba RR |
563 | } |
564 | else | |
1e6feb95 | 565 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 VZ |
566 | } |
567 | else | |
ecab4dba | 568 | { |
a58a12e9 | 569 | if (m_yScrollPixelsPerLine > 0) |
d80cd92a | 570 | { |
ecab4dba | 571 | int w, h; |
1e6feb95 | 572 | GetTargetSize(&w, &h); |
a58a12e9 | 573 | |
ecab4dba RR |
574 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; |
575 | int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
576 | if (noPositions < 0) | |
d80cd92a | 577 | noPositions = 0; |
a58a12e9 | 578 | |
ecab4dba | 579 | if ( (m_yScrollPosition + nScrollInc) < 0 ) |
d80cd92a | 580 | nScrollInc = -m_yScrollPosition; // As -ve as we can go |
ecab4dba | 581 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 582 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go |
ecab4dba RR |
583 | } |
584 | else | |
1e6feb95 | 585 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 | 586 | } |
9d9355c6 | 587 | |
ecab4dba | 588 | return nScrollInc; |
c801d85f KB |
589 | } |
590 | ||
591 | // Adjust the scrollbars - new version. | |
1e6feb95 | 592 | void wxScrollHelper::AdjustScrollbars() |
c801d85f | 593 | { |
aeb313f3 SC |
594 | #ifdef __WXMAC__ |
595 | m_targetWindow->MacUpdateImmediately(); | |
596 | #endif | |
597 | ||
566d84a7 RL |
598 | int w = 0, h = 0; |
599 | int oldw, oldh; | |
a58a12e9 | 600 | |
27d029c7 RR |
601 | int oldXScroll = m_xScrollPosition; |
602 | int oldYScroll = m_yScrollPosition; | |
c801d85f | 603 | |
566d84a7 RL |
604 | do { |
605 | GetTargetSize(&w, 0); | |
c801d85f | 606 | |
566d84a7 RL |
607 | if (m_xScrollPixelsPerLine == 0) |
608 | { | |
609 | m_xScrollLines = 0; | |
610 | m_xScrollPosition = 0; | |
611 | m_win->SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE); | |
612 | } | |
613 | else | |
614 | { | |
615 | m_xScrollLines = m_targetWindow->GetVirtualSize().GetWidth() / m_xScrollPixelsPerLine; | |
616 | ||
617 | // Calculate page size i.e. number of scroll units you get on the | |
618 | // current client window | |
619 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
620 | if (noPagePositions < 1) noPagePositions = 1; | |
621 | if ( noPagePositions > m_xScrollLines ) | |
622 | noPagePositions = m_xScrollLines; | |
623 | ||
624 | // Correct position if greater than extent of canvas minus | |
625 | // the visible portion of it or if below zero | |
626 | m_xScrollPosition = wxMin( m_xScrollLines - noPagePositions, m_xScrollPosition); | |
627 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
628 | ||
629 | m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); | |
630 | // The amount by which we scroll when paging | |
631 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
632 | } | |
c801d85f | 633 | |
566d84a7 | 634 | GetTargetSize(0, &h); |
a58a12e9 | 635 | |
566d84a7 RL |
636 | if (m_yScrollPixelsPerLine == 0) |
637 | { | |
638 | m_yScrollLines = 0; | |
639 | m_yScrollPosition = 0; | |
640 | m_win->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); | |
641 | } | |
642 | else | |
643 | { | |
644 | m_yScrollLines = m_targetWindow->GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine; | |
645 | ||
646 | // Calculate page size i.e. number of scroll units you get on the | |
647 | // current client window | |
648 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
649 | if (noPagePositions < 1) noPagePositions = 1; | |
650 | if ( noPagePositions > m_yScrollLines ) | |
651 | noPagePositions = m_yScrollLines; | |
652 | ||
653 | // Correct position if greater than extent of canvas minus | |
654 | // the visible portion of it or if below zero | |
655 | m_yScrollPosition = wxMin( m_yScrollLines - noPagePositions, m_yScrollPosition ); | |
656 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
657 | ||
658 | m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines); | |
659 | // The amount by which we scroll when paging | |
660 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
661 | } | |
c801d85f | 662 | |
566d84a7 | 663 | // If a scrollbar (dis)appeared as a result of this, adjust them again. |
139adb6a | 664 | |
566d84a7 RL |
665 | oldw = w; |
666 | oldh = h; | |
667 | ||
668 | GetTargetSize( &w, &h ); | |
669 | } while ( w != oldw && h != oldh ); | |
670 | ||
671 | #ifdef __WXMOTIF__ | |
672 | // Sorry, some Motif-specific code to implement a backing pixmap | |
673 | // for the wxRETAINED style. Implementing a backing store can't | |
674 | // be entirely generic because it relies on the wxWindowDC implementation | |
675 | // to duplicate X drawing calls for the backing pixmap. | |
676 | ||
677 | if ( m_targetWindow->GetWindowStyle() & wxRETAINED ) | |
139adb6a | 678 | { |
566d84a7 RL |
679 | Display* dpy = XtDisplay((Widget)m_targetWindow->GetMainWidget()); |
680 | ||
681 | int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine; | |
682 | int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine; | |
683 | if (m_targetWindow->GetBackingPixmap() && | |
684 | !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) && | |
685 | (m_targetWindow->GetPixmapHeight() == totalPixelHeight))) | |
686 | { | |
687 | XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap()); | |
688 | m_targetWindow->SetBackingPixmap((WXPixmap) 0); | |
689 | } | |
690 | ||
691 | if (!m_targetWindow->GetBackingPixmap() && | |
9b66c26a | 692 | (m_xScrollLines != 0) && (m_yScrollLines != 0)) |
566d84a7 RL |
693 | { |
694 | int depth = wxDisplayDepth(); | |
695 | m_targetWindow->SetPixmapWidth(totalPixelWidth); | |
696 | m_targetWindow->SetPixmapHeight(totalPixelHeight); | |
697 | m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)), | |
698 | m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth)); | |
699 | } | |
700 | ||
139adb6a | 701 | } |
566d84a7 | 702 | #endif // Motif |
a58a12e9 | 703 | |
27d029c7 RR |
704 | if (oldXScroll != m_xScrollPosition) |
705 | { | |
706 | if (m_xScrollingEnabled) | |
566d84a7 | 707 | m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll - m_xScrollPosition), 0, |
1e6feb95 | 708 | GetRect() ); |
27d029c7 | 709 | else |
1e6feb95 | 710 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 711 | } |
a58a12e9 | 712 | |
27d029c7 RR |
713 | if (oldYScroll != m_yScrollPosition) |
714 | { | |
715 | if (m_yScrollingEnabled) | |
1e6feb95 VZ |
716 | m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), |
717 | GetRect() ); | |
27d029c7 | 718 | else |
1e6feb95 | 719 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 720 | } |
aeb313f3 SC |
721 | |
722 | #ifdef __WXMAC__ | |
723 | m_targetWindow->MacUpdateImmediately(); | |
724 | #endif | |
c801d85f KB |
725 | } |
726 | ||
1e6feb95 | 727 | void wxScrollHelper::DoPrepareDC(wxDC& dc) |
c801d85f | 728 | { |
1e6feb95 VZ |
729 | wxPoint pt = dc.GetDeviceOrigin(); |
730 | dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine, | |
731 | pt.y - m_yScrollPosition * m_yScrollPixelsPerLine ); | |
139adb6a | 732 | dc.SetUserScale( m_scaleX, m_scaleY ); |
c801d85f KB |
733 | } |
734 | ||
566d84a7 RL |
735 | void wxScrollHelper::SetScrollRate( int xstep, int ystep ) |
736 | { | |
737 | int old_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
738 | int old_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
739 | ||
740 | m_xScrollPixelsPerLine = xstep; | |
741 | m_yScrollPixelsPerLine = ystep; | |
742 | ||
743 | int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
744 | int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
745 | ||
746 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); | |
747 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); | |
748 | m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); | |
749 | ||
750 | AdjustScrollbars(); | |
751 | } | |
752 | ||
1e6feb95 | 753 | void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const |
c801d85f | 754 | { |
a0bc2c1d VZ |
755 | if ( x_unit ) |
756 | *x_unit = m_xScrollPixelsPerLine; | |
757 | if ( y_unit ) | |
758 | *y_unit = m_yScrollPixelsPerLine; | |
c801d85f KB |
759 | } |
760 | ||
1e6feb95 | 761 | int wxScrollHelper::GetScrollPageSize(int orient) const |
c801d85f KB |
762 | { |
763 | if ( orient == wxHORIZONTAL ) | |
764 | return m_xScrollLinesPerPage; | |
765 | else | |
766 | return m_yScrollLinesPerPage; | |
767 | } | |
768 | ||
1e6feb95 | 769 | void wxScrollHelper::SetScrollPageSize(int orient, int pageSize) |
c801d85f KB |
770 | { |
771 | if ( orient == wxHORIZONTAL ) | |
772 | m_xScrollLinesPerPage = pageSize; | |
773 | else | |
774 | m_yScrollLinesPerPage = pageSize; | |
775 | } | |
776 | ||
777 | /* | |
778 | * Scroll to given position (scroll position, not pixel position) | |
779 | */ | |
1e6feb95 | 780 | void wxScrollHelper::Scroll( int x_pos, int y_pos ) |
c801d85f | 781 | { |
8b089c5e JS |
782 | if (!m_targetWindow) |
783 | return; | |
784 | ||
a58a12e9 | 785 | if (((x_pos == -1) || (x_pos == m_xScrollPosition)) && |
139adb6a | 786 | ((y_pos == -1) || (y_pos == m_yScrollPosition))) return; |
a58a12e9 | 787 | |
aeb313f3 SC |
788 | #ifdef __WXMAC__ |
789 | m_targetWindow->MacUpdateImmediately(); | |
790 | #endif | |
791 | ||
139adb6a | 792 | int w, h; |
1e6feb95 | 793 | GetTargetSize(&w, &h); |
c801d85f | 794 | |
8775b357 | 795 | if ((x_pos != -1) && (m_xScrollPixelsPerLine)) |
c801d85f | 796 | { |
ed673c6a | 797 | int old_x = m_xScrollPosition; |
139adb6a | 798 | m_xScrollPosition = x_pos; |
a58a12e9 | 799 | |
3d2b9c20 RR |
800 | // Calculate page size i.e. number of scroll units you get on the |
801 | // current client window | |
ecab4dba | 802 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
803 | if (noPagePositions < 1) noPagePositions = 1; |
804 | ||
805 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 806 | // the visible portion of it or if below zero |
139adb6a RR |
807 | m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition ); |
808 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
a58a12e9 | 809 | |
f6bcfd97 | 810 | if (old_x != m_xScrollPosition) { |
5f3286d1 | 811 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); |
1e6feb95 VZ |
812 | m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0, |
813 | GetRect() ); | |
f6bcfd97 | 814 | } |
c801d85f | 815 | } |
8775b357 | 816 | if ((y_pos != -1) && (m_yScrollPixelsPerLine)) |
c801d85f | 817 | { |
ed673c6a | 818 | int old_y = m_yScrollPosition; |
139adb6a | 819 | m_yScrollPosition = y_pos; |
a58a12e9 | 820 | |
3d2b9c20 RR |
821 | // Calculate page size i.e. number of scroll units you get on the |
822 | // current client window | |
ecab4dba | 823 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
824 | if (noPagePositions < 1) noPagePositions = 1; |
825 | ||
826 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 827 | // the visible portion of it or if below zero |
139adb6a RR |
828 | m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); |
829 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
d2c52078 | 830 | |
f6bcfd97 | 831 | if (old_y != m_yScrollPosition) { |
5f3286d1 | 832 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); |
1e6feb95 VZ |
833 | m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine, |
834 | GetRect() ); | |
f6bcfd97 | 835 | } |
c801d85f | 836 | } |
a58a12e9 | 837 | |
7c74e7fe | 838 | #ifdef __WXMAC__ |
3d2b9c20 | 839 | m_targetWindow->MacUpdateImmediately(); |
7c74e7fe | 840 | #endif |
aeb313f3 | 841 | |
c801d85f KB |
842 | } |
843 | ||
1e6feb95 | 844 | void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll) |
c801d85f | 845 | { |
139adb6a RR |
846 | m_xScrollingEnabled = x_scroll; |
847 | m_yScrollingEnabled = y_scroll; | |
c801d85f KB |
848 | } |
849 | ||
c801d85f | 850 | // Where the current view starts from |
1e6feb95 | 851 | void wxScrollHelper::GetViewStart (int *x, int *y) const |
c801d85f | 852 | { |
a0bc2c1d VZ |
853 | if ( x ) |
854 | *x = m_xScrollPosition; | |
855 | if ( y ) | |
856 | *y = m_yScrollPosition; | |
c801d85f KB |
857 | } |
858 | ||
8c2f3797 | 859 | void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 860 | { |
a0bc2c1d VZ |
861 | if ( xx ) |
862 | *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; | |
863 | if ( yy ) | |
864 | *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f KB |
865 | } |
866 | ||
8c2f3797 | 867 | void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 868 | { |
a0bc2c1d VZ |
869 | if ( xx ) |
870 | *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine; | |
871 | if ( yy ) | |
872 | *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f | 873 | } |
d80cd92a VZ |
874 | |
875 | // ---------------------------------------------------------------------------- | |
876 | // event handlers | |
877 | // ---------------------------------------------------------------------------- | |
878 | ||
879 | // Default OnSize resets scrollbars, if any | |
1e6feb95 | 880 | void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event)) |
d80cd92a | 881 | { |
2b5f62a0 VZ |
882 | if( m_win->GetAutoLayout() ) |
883 | { | |
884 | if ( m_targetWindow != m_win ) | |
885 | m_targetWindow->FitInside(); | |
566d84a7 | 886 | |
2b5f62a0 | 887 | m_win->FitInside(); |
dc429f89 | 888 | |
566d84a7 | 889 | #if wxUSE_CONSTRAINTS |
566d84a7 RL |
890 | m_win->Layout(); |
891 | #endif | |
2b5f62a0 VZ |
892 | } |
893 | else | |
894 | AdjustScrollbars(); | |
d80cd92a VZ |
895 | } |
896 | ||
897 | // This calls OnDraw, having adjusted the origin according to the current | |
898 | // scroll position | |
1e6feb95 | 899 | void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event)) |
d80cd92a | 900 | { |
af4088f1 VZ |
901 | // don't use m_targetWindow here, this is always called for ourselves |
902 | wxPaintDC dc(m_win); | |
1e6feb95 | 903 | DoPrepareDC(dc); |
d80cd92a VZ |
904 | |
905 | OnDraw(dc); | |
906 | } | |
907 | ||
438e3558 VZ |
908 | // kbd handling: notice that we use OnChar() and not OnKeyDown() for |
909 | // compatibility here - if we used OnKeyDown(), the programs which process | |
910 | // arrows themselves in their OnChar() would never get the message and like | |
911 | // this they always have the priority | |
1e6feb95 | 912 | void wxScrollHelper::HandleOnChar(wxKeyEvent& event) |
d80cd92a VZ |
913 | { |
914 | int stx, sty, // view origin | |
915 | szx, szy, // view size (total) | |
916 | clix, cliy; // view size (on screen) | |
917 | ||
1e6feb95 VZ |
918 | GetViewStart(&stx, &sty); |
919 | GetTargetSize(&clix, &cliy); | |
566d84a7 | 920 | m_targetWindow->GetVirtualSize(&szx, &szy); |
56dade3c RL |
921 | |
922 | if( m_xScrollPixelsPerLine ) | |
923 | { | |
924 | clix /= m_xScrollPixelsPerLine; | |
d7da9756 | 925 | szx /= m_xScrollPixelsPerLine; |
56dade3c RL |
926 | } |
927 | else | |
928 | { | |
929 | clix = 0; | |
d7da9756 | 930 | szx = -1; |
56dade3c RL |
931 | } |
932 | if( m_yScrollPixelsPerLine ) | |
933 | { | |
934 | cliy /= m_yScrollPixelsPerLine; | |
935 | szy /= m_yScrollPixelsPerLine; | |
936 | } | |
937 | else | |
938 | { | |
939 | cliy = 0; | |
d7da9756 | 940 | szy = -1; |
56dade3c | 941 | } |
d80cd92a | 942 | |
39c869a6 VZ |
943 | int xScrollOld = m_xScrollPosition, |
944 | yScrollOld = m_yScrollPosition; | |
945 | ||
ecb01792 | 946 | int dsty; |
d80cd92a VZ |
947 | switch ( event.KeyCode() ) |
948 | { | |
949 | case WXK_PAGEUP: | |
950 | case WXK_PRIOR: | |
ecb01792 RL |
951 | dsty = sty - (5 * cliy / 6); |
952 | Scroll(-1, (dsty == -1) ? 0 : dsty); | |
d80cd92a VZ |
953 | break; |
954 | ||
955 | case WXK_PAGEDOWN: | |
956 | case WXK_NEXT: | |
957 | Scroll(-1, sty + (5 * cliy / 6)); | |
958 | break; | |
959 | ||
d80cd92a VZ |
960 | case WXK_HOME: |
961 | Scroll(0, event.ControlDown() ? 0 : -1); | |
962 | break; | |
963 | ||
964 | case WXK_END: | |
4acd108c | 965 | Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1); |
d80cd92a VZ |
966 | break; |
967 | ||
968 | case WXK_UP: | |
969 | Scroll(-1, sty - 1); | |
970 | break; | |
971 | ||
972 | case WXK_DOWN: | |
973 | Scroll(-1, sty + 1); | |
974 | break; | |
975 | ||
976 | case WXK_LEFT: | |
977 | Scroll(stx - 1, -1); | |
978 | break; | |
979 | ||
980 | case WXK_RIGHT: | |
981 | Scroll(stx + 1, -1); | |
982 | break; | |
983 | ||
984 | default: | |
985 | // not for us | |
986 | event.Skip(); | |
987 | } | |
39c869a6 VZ |
988 | |
989 | if ( m_xScrollPosition != xScrollOld ) | |
990 | { | |
991 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition, | |
992 | wxHORIZONTAL); | |
993 | event.SetEventObject(m_win); | |
994 | m_win->GetEventHandler()->ProcessEvent(event); | |
995 | } | |
996 | ||
997 | if ( m_yScrollPosition != yScrollOld ) | |
998 | { | |
999 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition, | |
1000 | wxVERTICAL); | |
1001 | event.SetEventObject(m_win); | |
1002 | m_win->GetEventHandler()->ProcessEvent(event); | |
1003 | } | |
d80cd92a | 1004 | } |
d2c52078 | 1005 | |
1e6feb95 VZ |
1006 | // ---------------------------------------------------------------------------- |
1007 | // autoscroll stuff: these functions deal with sending fake scroll events when | |
1008 | // a captured mouse is being held outside the window | |
1009 | // ---------------------------------------------------------------------------- | |
1010 | ||
1011 | bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const | |
1012 | { | |
1013 | // only send the event if the window is scrollable in this direction | |
1014 | wxWindow *win = (wxWindow *)event.GetEventObject(); | |
1015 | return win->HasScrollbar(event.GetOrientation()); | |
1016 | } | |
1017 | ||
1018 | void wxScrollHelper::StopAutoScrolling() | |
1019 | { | |
1020 | if ( m_timerAutoScroll ) | |
1021 | { | |
1022 | delete m_timerAutoScroll; | |
1023 | m_timerAutoScroll = (wxTimer *)NULL; | |
1024 | } | |
1025 | } | |
d2c52078 | 1026 | |
1e6feb95 | 1027 | void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event) |
d2c52078 | 1028 | { |
1e6feb95 VZ |
1029 | StopAutoScrolling(); |
1030 | ||
1031 | event.Skip(); | |
1032 | } | |
d2c52078 | 1033 | |
1e6feb95 VZ |
1034 | void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event) |
1035 | { | |
1036 | // don't prevent the usual processing of the event from taking place | |
1037 | event.Skip(); | |
1038 | ||
1039 | // when a captured mouse leave a scrolled window we start generate | |
1040 | // scrolling events to allow, for example, extending selection beyond the | |
1041 | // visible area in some controls | |
1042 | if ( wxWindow::GetCapture() == m_targetWindow ) | |
1043 | { | |
1044 | // where is the mouse leaving? | |
1045 | int pos, orient; | |
1046 | wxPoint pt = event.GetPosition(); | |
1047 | if ( pt.x < 0 ) | |
1048 | { | |
1049 | orient = wxHORIZONTAL; | |
1050 | pos = 0; | |
1051 | } | |
1052 | else if ( pt.y < 0 ) | |
1053 | { | |
1054 | orient = wxVERTICAL; | |
1055 | pos = 0; | |
1056 | } | |
1057 | else // we're lower or to the right of the window | |
1058 | { | |
1059 | wxSize size = m_targetWindow->GetClientSize(); | |
1060 | if ( pt.x > size.x ) | |
1061 | { | |
1062 | orient = wxHORIZONTAL; | |
1063 | pos = m_xScrollLines; | |
1064 | } | |
1065 | else if ( pt.y > size.y ) | |
1066 | { | |
1067 | orient = wxVERTICAL; | |
1068 | pos = m_yScrollLines; | |
1069 | } | |
1070 | else // this should be impossible | |
1071 | { | |
1072 | // but seems to happen sometimes under wxMSW - maybe it's a bug | |
1073 | // there but for now just ignore it | |
1074 | ||
1075 | //wxFAIL_MSG( _T("can't understand where has mouse gone") ); | |
1076 | ||
1077 | return; | |
1078 | } | |
1079 | } | |
1080 | ||
1081 | // only start the auto scroll timer if the window can be scrolled in | |
1082 | // this direction | |
1083 | if ( !m_targetWindow->HasScrollbar(orient) ) | |
1084 | return; | |
1085 | ||
1086 | delete m_timerAutoScroll; | |
1087 | m_timerAutoScroll = new wxAutoScrollTimer | |
1088 | ( | |
1089 | m_targetWindow, this, | |
1090 | pos == 0 ? wxEVT_SCROLLWIN_LINEUP | |
1091 | : wxEVT_SCROLLWIN_LINEDOWN, | |
1092 | pos, | |
1093 | orient | |
1094 | ); | |
1095 | m_timerAutoScroll->Start(50); // FIXME: make configurable | |
1096 | } | |
1097 | } | |
1098 | ||
e421922f VZ |
1099 | #if wxUSE_MOUSEWHEEL |
1100 | ||
1e6feb95 VZ |
1101 | void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event) |
1102 | { | |
d2c52078 | 1103 | m_wheelRotation += event.GetWheelRotation(); |
1e6feb95 | 1104 | int lines = m_wheelRotation / event.GetWheelDelta(); |
d2c52078 RD |
1105 | m_wheelRotation -= lines * event.GetWheelDelta(); |
1106 | ||
1e6feb95 VZ |
1107 | if (lines != 0) |
1108 | { | |
1e6feb95 | 1109 | |
b6b85bdc JS |
1110 | wxScrollWinEvent newEvent; |
1111 | ||
ac6f6ffc | 1112 | newEvent.SetPosition(0); |
b6b85bdc JS |
1113 | newEvent.SetOrientation(wxVERTICAL); |
1114 | newEvent.m_eventObject = m_win; | |
b6b85bdc | 1115 | |
9b9337da | 1116 | if (event.IsPageScroll()) |
4b056ef5 RD |
1117 | { |
1118 | if (lines > 0) | |
1119 | newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1120 | else | |
1121 | newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1122 | ||
b6b85bdc | 1123 | m_win->GetEventHandler()->ProcessEvent(newEvent); |
4b056ef5 RD |
1124 | } |
1125 | else | |
1126 | { | |
1127 | lines *= event.GetLinesPerAction(); | |
1128 | if (lines > 0) | |
1129 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1130 | else | |
1131 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
b6b85bdc | 1132 | |
4b056ef5 RD |
1133 | int times = abs(lines); |
1134 | for (; times > 0; times--) | |
1135 | m_win->GetEventHandler()->ProcessEvent(newEvent); | |
1136 | } | |
d2c52078 RD |
1137 | } |
1138 | } | |
1139 | ||
e421922f VZ |
1140 | #endif // wxUSE_MOUSEWHEEL |
1141 | ||
1e6feb95 VZ |
1142 | // ---------------------------------------------------------------------------- |
1143 | // wxGenericScrolledWindow implementation | |
1144 | // ---------------------------------------------------------------------------- | |
1145 | ||
1146 | IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel) | |
1147 | ||
349efbaa VZ |
1148 | BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel) |
1149 | EVT_PAINT(wxGenericScrolledWindow::OnPaint) | |
1150 | END_EVENT_TABLE() | |
1151 | ||
1e6feb95 VZ |
1152 | bool wxGenericScrolledWindow::Create(wxWindow *parent, |
1153 | wxWindowID id, | |
1154 | const wxPoint& pos, | |
1155 | const wxSize& size, | |
1156 | long style, | |
1157 | const wxString& name) | |
1158 | { | |
1159 | m_targetWindow = this; | |
1160 | ||
1161 | bool ok = wxPanel::Create(parent, id, pos, size, style, name); | |
1162 | ||
1e6feb95 VZ |
1163 | return ok; |
1164 | } | |
1165 | ||
1166 | wxGenericScrolledWindow::~wxGenericScrolledWindow() | |
1167 | { | |
1168 | } | |
d2c52078 | 1169 | |
30486297 RD |
1170 | bool wxGenericScrolledWindow::Layout() |
1171 | { | |
566d84a7 | 1172 | if (GetSizer() && m_targetWindow == this) |
30486297 | 1173 | { |
566d84a7 RL |
1174 | // If we're the scroll target, take into account the |
1175 | // virtual size and scrolled position of the window. | |
1176 | ||
30486297 RD |
1177 | int x, y, w, h; |
1178 | CalcScrolledPosition(0,0, &x,&y); | |
1179 | GetVirtualSize(&w, &h); | |
1180 | GetSizer()->SetDimension(x, y, w, h); | |
1181 | return TRUE; | |
1182 | } | |
7152f0c6 VZ |
1183 | |
1184 | // fall back to default for LayoutConstraints | |
1185 | return wxPanel::Layout(); | |
30486297 RD |
1186 | } |
1187 | ||
2b5f62a0 VZ |
1188 | void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y) |
1189 | { | |
1190 | wxPanel::DoSetVirtualSize( x, y ); | |
1191 | AdjustScrollbars(); | |
1192 | ||
1193 | #if wxUSE_CONSTRAINTS | |
1194 | if (GetAutoLayout()) | |
1195 | Layout(); | |
1196 | #endif | |
1197 | } | |
1198 | ||
349efbaa VZ |
1199 | void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event) |
1200 | { | |
1201 | // the user code didn't really draw the window if we got here, so set this | |
1202 | // flag to try to call OnDraw() later | |
1203 | m_handler->ResetDrawnFlag(); | |
1204 | ||
1205 | event.Skip(); | |
1206 | } | |
1207 | ||
0cf5b099 VZ |
1208 | #ifdef __WXMSW__ |
1209 | long | |
1210 | wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg, | |
1211 | WXWPARAM wParam, | |
1212 | WXLPARAM lParam) | |
1213 | { | |
1214 | long rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam); | |
1215 | ||
1216 | // we need to process arrows ourselves for scrolling | |
1217 | if ( nMsg == WM_GETDLGCODE ) | |
1218 | { | |
1219 | rc |= DLGC_WANTARROWS; | |
1220 | } | |
1221 | ||
1222 | return rc; | |
1223 | } | |
1224 | ||
1225 | #endif // __WXMSW__ | |
1226 | ||
1e6feb95 | 1227 | #if WXWIN_COMPATIBILITY |
349efbaa | 1228 | |
1e6feb95 VZ |
1229 | void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const |
1230 | { | |
1231 | *x_page = GetScrollPageSize(wxHORIZONTAL); | |
1232 | *y_page = GetScrollPageSize(wxVERTICAL); | |
1233 | } | |
d2c52078 | 1234 | |
1e6feb95 VZ |
1235 | void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const |
1236 | { | |
1237 | if ( xx ) | |
1238 | *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine); | |
1239 | if ( yy ) | |
1240 | *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine); | |
1241 | } | |
349efbaa | 1242 | |
1e6feb95 | 1243 | #endif // WXWIN_COMPATIBILITY |
d2c52078 | 1244 | |
3a8c693a VZ |
1245 | #endif // !wxGTK |
1246 | ||
566d84a7 | 1247 | // vi:sts=4:sw=4:et |