Generalized wxScrolledWindow into wxScrolled<T> that can derive from
[wxWidgets.git] / src / generic / scrlwing.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/scrlwing.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Julian Smart
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.
7 // Created: 01/02/97
8 // RCS-ID: $Id$
9 // Copyright: (c) wxWidgets team
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // ============================================================================
14 // declarations
15 // ============================================================================
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #include "wx/scrolwin.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/utils.h"
32 #include "wx/panel.h"
33 #include "wx/dcclient.h"
34 #include "wx/timer.h"
35 #include "wx/sizer.h"
36 #include "wx/settings.h"
37 #endif
38
39 #ifdef __WXMAC__
40 #include "wx/scrolbar.h"
41 #endif
42
43 #include "wx/recguard.h"
44
45 #ifdef __WXMSW__
46 #include <windows.h> // for DLGC_WANTARROWS
47 #include "wx/msw/winundef.h"
48 #endif
49
50 #ifdef __WXMOTIF__
51 // For wxRETAINED implementation
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
56 #include <Xm/Xm.h>
57 #ifdef __VMS__
58 # pragma message enable nosimpint
59 #endif
60 #endif
61
62 /*
63 TODO PROPERTIES
64 style wxHSCROLL | wxVSCROLL
65 */
66
67 // ----------------------------------------------------------------------------
68 // wxScrollHelperEvtHandler: intercept the events from the window and forward
69 // them to wxScrollHelper
70 // ----------------------------------------------------------------------------
71
72 class WXDLLEXPORT wxScrollHelperEvtHandler : public wxEvtHandler
73 {
74 public:
75 wxScrollHelperEvtHandler(wxScrollHelper *scrollHelper)
76 {
77 m_scrollHelper = scrollHelper;
78 }
79
80 virtual bool ProcessEvent(wxEvent& event);
81
82 void ResetDrawnFlag() { m_hasDrawnWindow = false; }
83
84 private:
85 wxScrollHelper *m_scrollHelper;
86
87 bool m_hasDrawnWindow;
88
89 DECLARE_NO_COPY_CLASS(wxScrollHelperEvtHandler)
90 };
91
92 #if wxUSE_TIMER
93 // ----------------------------------------------------------------------------
94 // wxAutoScrollTimer: the timer used to generate a stream of scroll events when
95 // a captured mouse is held outside the window
96 // ----------------------------------------------------------------------------
97
98 class wxAutoScrollTimer : public wxTimer
99 {
100 public:
101 wxAutoScrollTimer(wxWindow *winToScroll, wxScrollHelper *scroll,
102 wxEventType eventTypeToSend,
103 int pos, int orient);
104
105 virtual void Notify();
106
107 private:
108 wxWindow *m_win;
109 wxScrollHelper *m_scrollHelper;
110 wxEventType m_eventType;
111 int m_pos,
112 m_orient;
113
114 DECLARE_NO_COPY_CLASS(wxAutoScrollTimer)
115 };
116
117 // ============================================================================
118 // implementation
119 // ============================================================================
120
121 // ----------------------------------------------------------------------------
122 // wxAutoScrollTimer
123 // ----------------------------------------------------------------------------
124
125 wxAutoScrollTimer::wxAutoScrollTimer(wxWindow *winToScroll,
126 wxScrollHelper *scroll,
127 wxEventType eventTypeToSend,
128 int pos, int orient)
129 {
130 m_win = winToScroll;
131 m_scrollHelper = scroll;
132 m_eventType = eventTypeToSend;
133 m_pos = pos;
134 m_orient = orient;
135 }
136
137 void wxAutoScrollTimer::Notify()
138 {
139 // only do all this as long as the window is capturing the mouse
140 if ( wxWindow::GetCapture() != m_win )
141 {
142 Stop();
143 }
144 else // we still capture the mouse, continue generating events
145 {
146 // first scroll the window if we are allowed to do it
147 wxScrollWinEvent event1(m_eventType, m_pos, m_orient);
148 event1.SetEventObject(m_win);
149 if ( m_scrollHelper->SendAutoScrollEvents(event1) &&
150 m_win->GetEventHandler()->ProcessEvent(event1) )
151 {
152 // and then send a pseudo mouse-move event to refresh the selection
153 wxMouseEvent event2(wxEVT_MOTION);
154 wxGetMousePosition(&event2.m_x, &event2.m_y);
155
156 // the mouse event coordinates should be client, not screen as
157 // returned by wxGetMousePosition
158 wxWindow *parentTop = m_win;
159 while ( parentTop->GetParent() )
160 parentTop = parentTop->GetParent();
161 wxPoint ptOrig = parentTop->GetPosition();
162 event2.m_x -= ptOrig.x;
163 event2.m_y -= ptOrig.y;
164
165 event2.SetEventObject(m_win);
166
167 // FIXME: we don't fill in the other members - ok?
168
169 m_win->GetEventHandler()->ProcessEvent(event2);
170 }
171 else // can't scroll further, stop
172 {
173 Stop();
174 }
175 }
176 }
177 #endif
178
179 // ----------------------------------------------------------------------------
180 // wxScrollHelperEvtHandler
181 // ----------------------------------------------------------------------------
182
183 bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
184 {
185 wxEventType evType = event.GetEventType();
186
187 // the explanation of wxEVT_PAINT processing hack: for historic reasons
188 // there are 2 ways to process this event in classes deriving from
189 // wxScrolledWindow. The user code may
190 //
191 // 1. override wxScrolledWindow::OnDraw(dc)
192 // 2. define its own OnPaint() handler
193 //
194 // In addition, in wxUniversal wxWindow defines OnPaint() itself and
195 // always processes the draw event, so we can't just try the window
196 // OnPaint() first and call our HandleOnPaint() if it doesn't process it
197 // (the latter would never be called in wxUniversal).
198 //
199 // So the solution is to have a flag telling us whether the user code drew
200 // anything in the window. We set it to true here but reset it to false in
201 // wxScrolledWindow::OnPaint() handler (which wouldn't be called if the
202 // user code defined OnPaint() in the derived class)
203 m_hasDrawnWindow = true;
204
205 // pass it on to the real handler
206 bool processed = wxEvtHandler::ProcessEvent(event);
207
208 // always process the size events ourselves, even if the user code handles
209 // them as well, as we need to AdjustScrollbars()
210 //
211 // NB: it is important to do it after processing the event in the normal
212 // way as HandleOnSize() may generate a wxEVT_SIZE itself if the
213 // scrollbar[s] (dis)appear and it should be seen by the user code
214 // after this one
215 if ( evType == wxEVT_SIZE )
216 {
217 m_scrollHelper->HandleOnSize((wxSizeEvent &)event);
218
219 return true;
220 }
221
222 if ( processed )
223 {
224 // normally, nothing more to do here - except if it was a paint event
225 // which wasn't really processed, then we'll try to call our
226 // OnDraw() below (from HandleOnPaint)
227 if ( m_hasDrawnWindow || event.IsCommandEvent() )
228 {
229 return true;
230 }
231 }
232
233 if ( evType == wxEVT_PAINT )
234 {
235 m_scrollHelper->HandleOnPaint((wxPaintEvent &)event);
236 return true;
237 }
238
239 if ( evType == wxEVT_CHILD_FOCUS )
240 {
241 m_scrollHelper->HandleOnChildFocus((wxChildFocusEvent &)event);
242 return true;
243 }
244
245 // reset the skipped flag (which might have been set to true in
246 // ProcessEvent() above) to be able to test it below
247 bool wasSkipped = event.GetSkipped();
248 if ( wasSkipped )
249 event.Skip(false);
250
251 if ( evType == wxEVT_SCROLLWIN_TOP ||
252 evType == wxEVT_SCROLLWIN_BOTTOM ||
253 evType == wxEVT_SCROLLWIN_LINEUP ||
254 evType == wxEVT_SCROLLWIN_LINEDOWN ||
255 evType == wxEVT_SCROLLWIN_PAGEUP ||
256 evType == wxEVT_SCROLLWIN_PAGEDOWN ||
257 evType == wxEVT_SCROLLWIN_THUMBTRACK ||
258 evType == wxEVT_SCROLLWIN_THUMBRELEASE )
259 {
260 m_scrollHelper->HandleOnScroll((wxScrollWinEvent &)event);
261 if ( !event.GetSkipped() )
262 {
263 // it makes sense to indicate that we processed the message as we
264 // did scroll the window (and also notice that wxAutoScrollTimer
265 // relies on our return value to stop scrolling when we are at top
266 // or bottom already)
267 processed = true;
268 wasSkipped = false;
269 }
270 }
271
272 if ( evType == wxEVT_ENTER_WINDOW )
273 {
274 m_scrollHelper->HandleOnMouseEnter((wxMouseEvent &)event);
275 }
276 else if ( evType == wxEVT_LEAVE_WINDOW )
277 {
278 m_scrollHelper->HandleOnMouseLeave((wxMouseEvent &)event);
279 }
280 #if wxUSE_MOUSEWHEEL
281 // Use GTK's own scroll wheel handling in GtkScrolledWindow
282 #ifndef __WXGTK20__
283 else if ( evType == wxEVT_MOUSEWHEEL )
284 {
285 m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
286 return true;
287 }
288 #endif
289 #endif // wxUSE_MOUSEWHEEL
290 else if ( evType == wxEVT_CHAR )
291 {
292 m_scrollHelper->HandleOnChar((wxKeyEvent &)event);
293 if ( !event.GetSkipped() )
294 {
295 processed = true;
296 wasSkipped = false;
297 }
298 }
299
300 if ( processed )
301 event.Skip(wasSkipped);
302
303 return processed;
304 }
305
306 // ----------------------------------------------------------------------------
307 // wxScrollHelper construction
308 // ----------------------------------------------------------------------------
309
310 wxScrollHelper::wxScrollHelper(wxWindow *win)
311 {
312 wxASSERT_MSG( win, _T("associated window can't be NULL in wxScrollHelper") );
313
314 m_xScrollPixelsPerLine =
315 m_yScrollPixelsPerLine =
316 m_xScrollPosition =
317 m_yScrollPosition =
318 m_xScrollLines =
319 m_yScrollLines =
320 m_xScrollLinesPerPage =
321 m_yScrollLinesPerPage = 0;
322
323 m_xScrollingEnabled =
324 m_yScrollingEnabled = true;
325
326 m_scaleX =
327 m_scaleY = 1.0;
328 #if wxUSE_MOUSEWHEEL
329 m_wheelRotation = 0;
330 #endif
331
332 m_win =
333 m_targetWindow = (wxWindow *)NULL;
334
335 m_timerAutoScroll = (wxTimer *)NULL;
336
337 m_handler = NULL;
338
339 m_win = win;
340
341 m_win->SetScrollHelper( this );
342
343 // by default, the associated window is also the target window
344 DoSetTargetWindow(win);
345 }
346
347 wxScrollHelper::~wxScrollHelper()
348 {
349 StopAutoScrolling();
350
351 DeleteEvtHandler();
352 }
353
354 // ----------------------------------------------------------------------------
355 // setting scrolling parameters
356 // ----------------------------------------------------------------------------
357
358 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX,
359 int pixelsPerUnitY,
360 int noUnitsX,
361 int noUnitsY,
362 int xPos,
363 int yPos,
364 bool noRefresh)
365 {
366 int xpos, ypos;
367
368 CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos);
369 bool do_refresh =
370 (
371 (noUnitsX != 0 && m_xScrollLines == 0) ||
372 (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX * noUnitsX) ||
373
374 (noUnitsY != 0 && m_yScrollLines == 0) ||
375 (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY * noUnitsY) ||
376 (xPos != m_xScrollPosition) ||
377 (yPos != m_yScrollPosition)
378 );
379
380 m_xScrollPixelsPerLine = pixelsPerUnitX;
381 m_yScrollPixelsPerLine = pixelsPerUnitY;
382 m_xScrollPosition = xPos;
383 m_yScrollPosition = yPos;
384
385 int w = noUnitsX * pixelsPerUnitX;
386 int h = noUnitsY * pixelsPerUnitY;
387
388 // For better backward compatibility we set persisting limits
389 // here not just the size. It makes SetScrollbars 'sticky'
390 // emulating the old non-autoscroll behaviour.
391 // m_targetWindow->SetVirtualSizeHints( w, h );
392
393 // The above should arguably be deprecated, this however we still need.
394
395 // take care not to set 0 virtual size, 0 means that we don't have any
396 // scrollbars and hence we should use the real size instead of the virtual
397 // one which is indicated by using wxDefaultCoord
398 m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
399 h ? h : wxDefaultCoord);
400
401 if (do_refresh && !noRefresh)
402 m_targetWindow->Refresh(true, GetScrollRect());
403
404 #ifndef __WXUNIVERSAL__
405 // If the target is not the same as the window with the scrollbars,
406 // then we need to update the scrollbars here, since they won't have
407 // been updated by SetVirtualSize().
408 if ( m_targetWindow != m_win )
409 #endif // !__WXUNIVERSAL__
410 {
411 AdjustScrollbars();
412 }
413 #ifndef __WXUNIVERSAL__
414 else
415 {
416 // otherwise this has been done by AdjustScrollbars, above
417 }
418 #endif // !__WXUNIVERSAL__
419 }
420
421 // ----------------------------------------------------------------------------
422 // [target] window handling
423 // ----------------------------------------------------------------------------
424
425 void wxScrollHelper::DeleteEvtHandler()
426 {
427 // search for m_handler in the handler list
428 if ( m_win && m_handler )
429 {
430 if ( m_win->RemoveEventHandler(m_handler) )
431 {
432 delete m_handler;
433 }
434 //else: something is very wrong, so better [maybe] leak memory than
435 // risk a crash because of double deletion
436
437 m_handler = NULL;
438 }
439 }
440
441 void wxScrollHelper::ResetDrawnFlag()
442 {
443 wxCHECK_RET( m_handler, "invalid use of ResetDrawnFlag - no handler?" );
444 m_handler->ResetDrawnFlag();
445 }
446
447 void wxScrollHelper::DoSetTargetWindow(wxWindow *target)
448 {
449 m_targetWindow = target;
450 #ifdef __WXMAC__
451 target->MacSetClipChildren( true ) ;
452 #endif
453
454 // install the event handler which will intercept the events we're
455 // interested in (but only do it for our real window, not the target window
456 // which we scroll - we don't need to hijack its events)
457 if ( m_targetWindow == m_win )
458 {
459 // if we already have a handler, delete it first
460 DeleteEvtHandler();
461
462 m_handler = new wxScrollHelperEvtHandler(this);
463 m_targetWindow->PushEventHandler(m_handler);
464 }
465 }
466
467 void wxScrollHelper::SetTargetWindow(wxWindow *target)
468 {
469 wxCHECK_RET( target, wxT("target window must not be NULL") );
470
471 if ( target == m_targetWindow )
472 return;
473
474 DoSetTargetWindow(target);
475 }
476
477 wxWindow *wxScrollHelper::GetTargetWindow() const
478 {
479 return m_targetWindow;
480 }
481
482 // ----------------------------------------------------------------------------
483 // scrolling implementation itself
484 // ----------------------------------------------------------------------------
485
486 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event)
487 {
488 int nScrollInc = CalcScrollInc(event);
489 if ( nScrollInc == 0 )
490 {
491 // can't scroll further
492 event.Skip();
493
494 return;
495 }
496
497 bool needsRefresh = false;
498 int dx = 0,
499 dy = 0;
500 int orient = event.GetOrientation();
501 if (orient == wxHORIZONTAL)
502 {
503 if ( m_xScrollingEnabled )
504 {
505 dx = -m_xScrollPixelsPerLine * nScrollInc;
506 }
507 else
508 {
509 needsRefresh = true;
510 }
511 }
512 else
513 {
514 if ( m_yScrollingEnabled )
515 {
516 dy = -m_yScrollPixelsPerLine * nScrollInc;
517 }
518 else
519 {
520 needsRefresh = true;
521 }
522 }
523
524 if ( !needsRefresh )
525 {
526 // flush all pending repaints before we change m_{x,y}ScrollPosition, as
527 // otherwise invalidated area could be updated incorrectly later when
528 // ScrollWindow() makes sure they're repainted before scrolling them
529 #ifdef __WXMAC__
530 // wxWindowMac is taking care of making sure the update area is correctly
531 // set up, while not forcing an immediate redraw
532 #else
533 m_targetWindow->Update();
534 #endif
535 }
536
537 if (orient == wxHORIZONTAL)
538 {
539 m_xScrollPosition += nScrollInc;
540 m_win->SetScrollPos(wxHORIZONTAL, m_xScrollPosition);
541 }
542 else
543 {
544 m_yScrollPosition += nScrollInc;
545 m_win->SetScrollPos(wxVERTICAL, m_yScrollPosition);
546 }
547
548 if ( needsRefresh )
549 {
550 m_targetWindow->Refresh(true, GetScrollRect());
551 }
552 else
553 {
554 m_targetWindow->ScrollWindow(dx, dy, GetScrollRect());
555 }
556 }
557
558 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event)
559 {
560 int pos = event.GetPosition();
561 int orient = event.GetOrientation();
562
563 int nScrollInc = 0;
564 if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
565 {
566 if (orient == wxHORIZONTAL)
567 nScrollInc = - m_xScrollPosition;
568 else
569 nScrollInc = - m_yScrollPosition;
570 } else
571 if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
572 {
573 if (orient == wxHORIZONTAL)
574 nScrollInc = m_xScrollLines - m_xScrollPosition;
575 else
576 nScrollInc = m_yScrollLines - m_yScrollPosition;
577 } else
578 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
579 {
580 nScrollInc = -1;
581 } else
582 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
583 {
584 nScrollInc = 1;
585 } else
586 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
587 {
588 if (orient == wxHORIZONTAL)
589 nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
590 else
591 nScrollInc = -GetScrollPageSize(wxVERTICAL);
592 } else
593 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
594 {
595 if (orient == wxHORIZONTAL)
596 nScrollInc = GetScrollPageSize(wxHORIZONTAL);
597 else
598 nScrollInc = GetScrollPageSize(wxVERTICAL);
599 } else
600 if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
601 (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
602 {
603 if (orient == wxHORIZONTAL)
604 nScrollInc = pos - m_xScrollPosition;
605 else
606 nScrollInc = pos - m_yScrollPosition;
607 }
608
609 if (orient == wxHORIZONTAL)
610 {
611 if ( m_xScrollPosition + nScrollInc < 0 )
612 {
613 // As -ve as we can go
614 nScrollInc = -m_xScrollPosition;
615 }
616 else // check for the other bound
617 {
618 const int posMax = m_xScrollLines - m_xScrollLinesPerPage;
619 if ( m_xScrollPosition + nScrollInc > posMax )
620 {
621 // As +ve as we can go
622 nScrollInc = posMax - m_xScrollPosition;
623 }
624 }
625 }
626 else // wxVERTICAL
627 {
628 if ( m_yScrollPosition + nScrollInc < 0 )
629 {
630 // As -ve as we can go
631 nScrollInc = -m_yScrollPosition;
632 }
633 else // check for the other bound
634 {
635 const int posMax = m_yScrollLines - m_yScrollLinesPerPage;
636 if ( m_yScrollPosition + nScrollInc > posMax )
637 {
638 // As +ve as we can go
639 nScrollInc = posMax - m_yScrollPosition;
640 }
641 }
642 }
643
644 return nScrollInc;
645 }
646
647 // Adjust the scrollbars - new version.
648 void wxScrollHelper::AdjustScrollbars()
649 {
650 static wxRecursionGuardFlag s_flagReentrancy;
651 wxRecursionGuard guard(s_flagReentrancy);
652 if ( guard.IsInside() )
653 {
654 // don't reenter AdjustScrollbars() while another call to
655 // AdjustScrollbars() is in progress because this may lead to calling
656 // ScrollWindow() twice and this can really happen under MSW if
657 // SetScrollbar() call below adds or removes the scrollbar which
658 // changes the window size and hence results in another
659 // AdjustScrollbars() call
660 return;
661 }
662
663 int w = 0, h = 0;
664 int oldw, oldh;
665
666 int oldXScroll = m_xScrollPosition;
667 int oldYScroll = m_yScrollPosition;
668
669 // VZ: at least under Windows this loop is useless because when scrollbars
670 // [dis]appear we get a WM_SIZE resulting in another call to
671 // AdjustScrollbars() anyhow. As it doesn't seem to do any harm I leave
672 // it here for now but it would be better to ensure that all ports
673 // generate EVT_SIZE when scrollbars [dis]appear, emulating it if
674 // necessary, and remove it later
675 // JACS: Stop potential infinite loop by limiting number of iterations
676 int iterationCount = 0;
677 const int iterationMax = 5;
678 do
679 {
680 iterationCount ++;
681
682 GetTargetSize(&w, 0);
683
684 // scroll lines per page: if 0, no scrolling is needed
685 int linesPerPage;
686
687 if ( m_xScrollPixelsPerLine == 0 )
688 {
689 // scrolling is disabled
690 m_xScrollLines = 0;
691 m_xScrollPosition = 0;
692 linesPerPage = 0;
693 }
694 else // might need scrolling
695 {
696 // Round up integer division to catch any "leftover" client space.
697 const int wVirt = m_targetWindow->GetVirtualSize().GetWidth();
698 m_xScrollLines = (wVirt + m_xScrollPixelsPerLine - 1) / m_xScrollPixelsPerLine;
699
700 // Calculate page size i.e. number of scroll units you get on the
701 // current client window.
702 linesPerPage = w / m_xScrollPixelsPerLine;
703
704 // Special case. When client and virtual size are very close but
705 // the client is big enough, kill scrollbar.
706 if ((linesPerPage < m_xScrollLines) && (w >= wVirt)) ++linesPerPage;
707
708 if (linesPerPage >= m_xScrollLines)
709 {
710 // we're big enough to not need scrolling
711 linesPerPage =
712 m_xScrollLines =
713 m_xScrollPosition = 0;
714 }
715 else // we do need a scrollbar
716 {
717 if ( linesPerPage < 1 )
718 linesPerPage = 1;
719
720 // Correct position if greater than extent of canvas minus
721 // the visible portion of it or if below zero
722 const int posMax = m_xScrollLines - linesPerPage;
723 if ( m_xScrollPosition > posMax )
724 m_xScrollPosition = posMax;
725 else if ( m_xScrollPosition < 0 )
726 m_xScrollPosition = 0;
727 }
728 }
729
730 m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition,
731 linesPerPage, m_xScrollLines);
732
733 // The amount by which we scroll when paging
734 SetScrollPageSize(wxHORIZONTAL, linesPerPage);
735
736 GetTargetSize(0, &h);
737
738 if ( m_yScrollPixelsPerLine == 0 )
739 {
740 // scrolling is disabled
741 m_yScrollLines = 0;
742 m_yScrollPosition = 0;
743 linesPerPage = 0;
744 }
745 else // might need scrolling
746 {
747 // Round up integer division to catch any "leftover" client space.
748 const int hVirt = m_targetWindow->GetVirtualSize().GetHeight();
749 m_yScrollLines = ( hVirt + m_yScrollPixelsPerLine - 1 ) / m_yScrollPixelsPerLine;
750
751 // Calculate page size i.e. number of scroll units you get on the
752 // current client window.
753 linesPerPage = h / m_yScrollPixelsPerLine;
754
755 // Special case. When client and virtual size are very close but
756 // the client is big enough, kill scrollbar.
757 if ((linesPerPage < m_yScrollLines) && (h >= hVirt)) ++linesPerPage;
758
759 if (linesPerPage >= m_yScrollLines)
760 {
761 // we're big enough to not need scrolling
762 linesPerPage =
763 m_yScrollLines =
764 m_yScrollPosition = 0;
765 }
766 else // we do need a scrollbar
767 {
768 if ( linesPerPage < 1 )
769 linesPerPage = 1;
770
771 // Correct position if greater than extent of canvas minus
772 // the visible portion of it or if below zero
773 const int posMax = m_yScrollLines - linesPerPage;
774 if ( m_yScrollPosition > posMax )
775 m_yScrollPosition = posMax;
776 else if ( m_yScrollPosition < 0 )
777 m_yScrollPosition = 0;
778 }
779 }
780
781 m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition,
782 linesPerPage, m_yScrollLines);
783
784 // The amount by which we scroll when paging
785 SetScrollPageSize(wxVERTICAL, linesPerPage);
786
787
788 // If a scrollbar (dis)appeared as a result of this, adjust them again.
789 oldw = w;
790 oldh = h;
791
792 GetTargetSize( &w, &h );
793 } while ( (w != oldw || h != oldh) && (iterationCount < iterationMax) );
794
795 #ifdef __WXMOTIF__
796 // Sorry, some Motif-specific code to implement a backing pixmap
797 // for the wxRETAINED style. Implementing a backing store can't
798 // be entirely generic because it relies on the wxWindowDC implementation
799 // to duplicate X drawing calls for the backing pixmap.
800
801 if ( m_targetWindow->GetWindowStyle() & wxRETAINED )
802 {
803 Display* dpy = XtDisplay((Widget)m_targetWindow->GetMainWidget());
804
805 int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;
806 int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;
807 if (m_targetWindow->GetBackingPixmap() &&
808 !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) &&
809 (m_targetWindow->GetPixmapHeight() == totalPixelHeight)))
810 {
811 XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap());
812 m_targetWindow->SetBackingPixmap((WXPixmap) 0);
813 }
814
815 if (!m_targetWindow->GetBackingPixmap() &&
816 (m_xScrollLines != 0) && (m_yScrollLines != 0))
817 {
818 int depth = wxDisplayDepth();
819 m_targetWindow->SetPixmapWidth(totalPixelWidth);
820 m_targetWindow->SetPixmapHeight(totalPixelHeight);
821 m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
822 m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth));
823 }
824
825 }
826 #endif // Motif
827
828 if (oldXScroll != m_xScrollPosition)
829 {
830 if (m_xScrollingEnabled)
831 m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll - m_xScrollPosition), 0,
832 GetScrollRect() );
833 else
834 m_targetWindow->Refresh(true, GetScrollRect());
835 }
836
837 if (oldYScroll != m_yScrollPosition)
838 {
839 if (m_yScrollingEnabled)
840 m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition),
841 GetScrollRect() );
842 else
843 m_targetWindow->Refresh(true, GetScrollRect());
844 }
845 }
846
847 void wxScrollHelper::DoPrepareDC(wxDC& dc)
848 {
849 wxPoint pt = dc.GetDeviceOrigin();
850 #ifdef __WXGTK__
851 // It may actually be correct to always query
852 // the m_sign from the DC here, but I leve the
853 // #ifdef GTK for now.
854 if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
855 dc.SetDeviceOrigin( pt.x + m_xScrollPosition * m_xScrollPixelsPerLine,
856 pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
857 else
858 #endif
859 dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
860 pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
861 dc.SetUserScale( m_scaleX, m_scaleY );
862 }
863
864 void wxScrollHelper::SetScrollRate( int xstep, int ystep )
865 {
866 int old_x = m_xScrollPixelsPerLine * m_xScrollPosition;
867 int old_y = m_yScrollPixelsPerLine * m_yScrollPosition;
868
869 m_xScrollPixelsPerLine = xstep;
870 m_yScrollPixelsPerLine = ystep;
871
872 int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
873 int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
874
875 m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
876 m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition );
877 m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
878
879 AdjustScrollbars();
880 }
881
882 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
883 {
884 if ( x_unit )
885 *x_unit = m_xScrollPixelsPerLine;
886 if ( y_unit )
887 *y_unit = m_yScrollPixelsPerLine;
888 }
889
890
891 int wxScrollHelper::GetScrollLines( int orient ) const
892 {
893 if ( orient == wxHORIZONTAL )
894 return m_xScrollLines;
895 else
896 return m_yScrollLines;
897 }
898
899 int wxScrollHelper::GetScrollPageSize(int orient) const
900 {
901 if ( orient == wxHORIZONTAL )
902 return m_xScrollLinesPerPage;
903 else
904 return m_yScrollLinesPerPage;
905 }
906
907 void wxScrollHelper::SetScrollPageSize(int orient, int pageSize)
908 {
909 if ( orient == wxHORIZONTAL )
910 m_xScrollLinesPerPage = pageSize;
911 else
912 m_yScrollLinesPerPage = pageSize;
913 }
914
915 /*
916 * Scroll to given position (scroll position, not pixel position)
917 */
918 void wxScrollHelper::Scroll( int x_pos, int y_pos )
919 {
920 if (!m_targetWindow)
921 return;
922
923 if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
924 ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
925
926 int w = 0, h = 0;
927 GetTargetSize(&w, &h);
928
929 // compute new position:
930 int new_x = m_xScrollPosition;
931 int new_y = m_yScrollPosition;
932
933 if ((x_pos != -1) && (m_xScrollPixelsPerLine))
934 {
935 new_x = x_pos;
936
937 // Calculate page size i.e. number of scroll units you get on the
938 // current client window
939 int noPagePositions = w/m_xScrollPixelsPerLine;
940 if (noPagePositions < 1) noPagePositions = 1;
941
942 // Correct position if greater than extent of canvas minus
943 // the visible portion of it or if below zero
944 new_x = wxMin( m_xScrollLines-noPagePositions, new_x );
945 new_x = wxMax( 0, new_x );
946 }
947 if ((y_pos != -1) && (m_yScrollPixelsPerLine))
948 {
949 new_y = y_pos;
950
951 // Calculate page size i.e. number of scroll units you get on the
952 // current client window
953 int noPagePositions = h/m_yScrollPixelsPerLine;
954 if (noPagePositions < 1) noPagePositions = 1;
955
956 // Correct position if greater than extent of canvas minus
957 // the visible portion of it or if below zero
958 new_y = wxMin( m_yScrollLines-noPagePositions, new_y );
959 new_y = wxMax( 0, new_y );
960 }
961
962 if ( new_x == m_xScrollPosition && new_y == m_yScrollPosition )
963 return; // nothing to do, the position didn't change
964
965 // flush all pending repaints before we change m_{x,y}ScrollPosition, as
966 // otherwise invalidated area could be updated incorrectly later when
967 // ScrollWindow() makes sure they're repainted before scrolling them
968 m_targetWindow->Update();
969
970 // update the position and scroll the window now:
971 if (m_xScrollPosition != new_x)
972 {
973 int old_x = m_xScrollPosition;
974 m_xScrollPosition = new_x;
975 m_win->SetScrollPos( wxHORIZONTAL, new_x );
976 m_targetWindow->ScrollWindow( (old_x-new_x)*m_xScrollPixelsPerLine, 0,
977 GetScrollRect() );
978 }
979
980 if (m_yScrollPosition != new_y)
981 {
982 int old_y = m_yScrollPosition;
983 m_yScrollPosition = new_y;
984 m_win->SetScrollPos( wxVERTICAL, new_y );
985 m_targetWindow->ScrollWindow( 0, (old_y-new_y)*m_yScrollPixelsPerLine,
986 GetScrollRect() );
987 }
988 }
989
990 void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll)
991 {
992 m_xScrollingEnabled = x_scroll;
993 m_yScrollingEnabled = y_scroll;
994 }
995
996 // Where the current view starts from
997 void wxScrollHelper::GetViewStart (int *x, int *y) const
998 {
999 if ( x )
1000 *x = m_xScrollPosition;
1001 if ( y )
1002 *y = m_yScrollPosition;
1003 }
1004
1005 void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const
1006 {
1007 if ( xx )
1008 *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
1009 if ( yy )
1010 *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
1011 }
1012
1013 void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
1014 {
1015 if ( xx )
1016 *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
1017 if ( yy )
1018 *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
1019 }
1020
1021 // ----------------------------------------------------------------------------
1022 // geometry
1023 // ----------------------------------------------------------------------------
1024
1025 bool wxScrollHelper::ScrollLayout()
1026 {
1027 if ( m_win->GetSizer() && m_targetWindow == m_win )
1028 {
1029 // If we're the scroll target, take into account the
1030 // virtual size and scrolled position of the window.
1031
1032 int x = 0, y = 0, w = 0, h = 0;
1033 CalcScrolledPosition(0,0, &x,&y);
1034 m_win->GetVirtualSize(&w, &h);
1035 m_win->GetSizer()->SetDimension(x, y, w, h);
1036 return true;
1037 }
1038
1039 // fall back to default for LayoutConstraints
1040 return m_win->wxWindow::Layout();
1041 }
1042
1043 void wxScrollHelper::ScrollDoSetVirtualSize(int x, int y)
1044 {
1045 m_win->wxWindow::DoSetVirtualSize( x, y );
1046 AdjustScrollbars();
1047
1048 if (m_win->GetAutoLayout())
1049 m_win->Layout();
1050 }
1051
1052 // wxWindow's GetBestVirtualSize returns the actual window size,
1053 // whereas we want to return the virtual size
1054 wxSize wxScrollHelper::ScrollGetBestVirtualSize() const
1055 {
1056 wxSize clientSize(m_win->GetClientSize());
1057 if ( m_win->GetSizer() )
1058 clientSize.IncTo(m_win->GetSizer()->CalcMin());
1059
1060 return clientSize;
1061 }
1062
1063 // ----------------------------------------------------------------------------
1064 // event handlers
1065 // ----------------------------------------------------------------------------
1066
1067 // Default OnSize resets scrollbars, if any
1068 void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event))
1069 {
1070 if ( m_targetWindow->GetAutoLayout() )
1071 {
1072 wxSize size = m_targetWindow->GetBestVirtualSize();
1073
1074 // This will call ::Layout() and ::AdjustScrollbars()
1075 m_win->SetVirtualSize( size );
1076 }
1077 else
1078 {
1079 AdjustScrollbars();
1080 }
1081 }
1082
1083 // This calls OnDraw, having adjusted the origin according to the current
1084 // scroll position
1085 void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event))
1086 {
1087 // don't use m_targetWindow here, this is always called for ourselves
1088 wxPaintDC dc(m_win);
1089 DoPrepareDC(dc);
1090
1091 OnDraw(dc);
1092 }
1093
1094 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
1095 // compatibility here - if we used OnKeyDown(), the programs which process
1096 // arrows themselves in their OnChar() would never get the message and like
1097 // this they always have the priority
1098 void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
1099 {
1100 int stx = 0, sty = 0, // view origin
1101 szx = 0, szy = 0, // view size (total)
1102 clix = 0, cliy = 0; // view size (on screen)
1103
1104 GetViewStart(&stx, &sty);
1105 GetTargetSize(&clix, &cliy);
1106 m_targetWindow->GetVirtualSize(&szx, &szy);
1107
1108 if( m_xScrollPixelsPerLine )
1109 {
1110 clix /= m_xScrollPixelsPerLine;
1111 szx /= m_xScrollPixelsPerLine;
1112 }
1113 else
1114 {
1115 clix = 0;
1116 szx = -1;
1117 }
1118 if( m_yScrollPixelsPerLine )
1119 {
1120 cliy /= m_yScrollPixelsPerLine;
1121 szy /= m_yScrollPixelsPerLine;
1122 }
1123 else
1124 {
1125 cliy = 0;
1126 szy = -1;
1127 }
1128
1129 int xScrollOld = m_xScrollPosition,
1130 yScrollOld = m_yScrollPosition;
1131
1132 int dsty;
1133 switch ( event.GetKeyCode() )
1134 {
1135 case WXK_PAGEUP:
1136 dsty = sty - (5 * cliy / 6);
1137 Scroll(-1, (dsty == -1) ? 0 : dsty);
1138 break;
1139
1140 case WXK_PAGEDOWN:
1141 Scroll(-1, sty + (5 * cliy / 6));
1142 break;
1143
1144 case WXK_HOME:
1145 Scroll(0, event.ControlDown() ? 0 : -1);
1146 break;
1147
1148 case WXK_END:
1149 Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
1150 break;
1151
1152 case WXK_UP:
1153 Scroll(-1, sty - 1);
1154 break;
1155
1156 case WXK_DOWN:
1157 Scroll(-1, sty + 1);
1158 break;
1159
1160 case WXK_LEFT:
1161 Scroll(stx - 1, -1);
1162 break;
1163
1164 case WXK_RIGHT:
1165 Scroll(stx + 1, -1);
1166 break;
1167
1168 default:
1169 // not for us
1170 event.Skip();
1171 }
1172
1173 if ( m_xScrollPosition != xScrollOld )
1174 {
1175 wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
1176 wxHORIZONTAL);
1177 evt.SetEventObject(m_win);
1178 m_win->GetEventHandler()->ProcessEvent(evt);
1179 }
1180
1181 if ( m_yScrollPosition != yScrollOld )
1182 {
1183 wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition,
1184 wxVERTICAL);
1185 evt.SetEventObject(m_win);
1186 m_win->GetEventHandler()->ProcessEvent(evt);
1187 }
1188 }
1189
1190 // ----------------------------------------------------------------------------
1191 // autoscroll stuff: these functions deal with sending fake scroll events when
1192 // a captured mouse is being held outside the window
1193 // ----------------------------------------------------------------------------
1194
1195 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const
1196 {
1197 // only send the event if the window is scrollable in this direction
1198 wxWindow *win = (wxWindow *)event.GetEventObject();
1199 return win->HasScrollbar(event.GetOrientation());
1200 }
1201
1202 void wxScrollHelper::StopAutoScrolling()
1203 {
1204 #if wxUSE_TIMER
1205 if ( m_timerAutoScroll )
1206 {
1207 delete m_timerAutoScroll;
1208 m_timerAutoScroll = (wxTimer *)NULL;
1209 }
1210 #endif
1211 }
1212
1213 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event)
1214 {
1215 StopAutoScrolling();
1216
1217 event.Skip();
1218 }
1219
1220 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event)
1221 {
1222 // don't prevent the usual processing of the event from taking place
1223 event.Skip();
1224
1225 // when a captured mouse leave a scrolled window we start generate
1226 // scrolling events to allow, for example, extending selection beyond the
1227 // visible area in some controls
1228 if ( wxWindow::GetCapture() == m_targetWindow )
1229 {
1230 // where is the mouse leaving?
1231 int pos, orient;
1232 wxPoint pt = event.GetPosition();
1233 if ( pt.x < 0 )
1234 {
1235 orient = wxHORIZONTAL;
1236 pos = 0;
1237 }
1238 else if ( pt.y < 0 )
1239 {
1240 orient = wxVERTICAL;
1241 pos = 0;
1242 }
1243 else // we're lower or to the right of the window
1244 {
1245 wxSize size = m_targetWindow->GetClientSize();
1246 if ( pt.x > size.x )
1247 {
1248 orient = wxHORIZONTAL;
1249 pos = m_xScrollLines;
1250 }
1251 else if ( pt.y > size.y )
1252 {
1253 orient = wxVERTICAL;
1254 pos = m_yScrollLines;
1255 }
1256 else // this should be impossible
1257 {
1258 // but seems to happen sometimes under wxMSW - maybe it's a bug
1259 // there but for now just ignore it
1260
1261 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
1262
1263 return;
1264 }
1265 }
1266
1267 // only start the auto scroll timer if the window can be scrolled in
1268 // this direction
1269 if ( !m_targetWindow->HasScrollbar(orient) )
1270 return;
1271
1272 #if wxUSE_TIMER
1273 delete m_timerAutoScroll;
1274 m_timerAutoScroll = new wxAutoScrollTimer
1275 (
1276 m_targetWindow, this,
1277 pos == 0 ? wxEVT_SCROLLWIN_LINEUP
1278 : wxEVT_SCROLLWIN_LINEDOWN,
1279 pos,
1280 orient
1281 );
1282 m_timerAutoScroll->Start(50); // FIXME: make configurable
1283 #else
1284 wxUnusedVar(pos);
1285 #endif
1286 }
1287 }
1288
1289 #if wxUSE_MOUSEWHEEL
1290
1291 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
1292 {
1293 m_wheelRotation += event.GetWheelRotation();
1294 int lines = m_wheelRotation / event.GetWheelDelta();
1295 m_wheelRotation -= lines * event.GetWheelDelta();
1296
1297 if (lines != 0)
1298 {
1299
1300 wxScrollWinEvent newEvent;
1301
1302 newEvent.SetPosition(0);
1303 newEvent.SetOrientation( event.GetWheelAxis() == 0 ? wxVERTICAL : wxHORIZONTAL);
1304 newEvent.SetEventObject(m_win);
1305
1306 if (event.IsPageScroll())
1307 {
1308 if (lines > 0)
1309 newEvent.SetEventType(wxEVT_SCROLLWIN_PAGEUP);
1310 else
1311 newEvent.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN);
1312
1313 m_win->GetEventHandler()->ProcessEvent(newEvent);
1314 }
1315 else
1316 {
1317 lines *= event.GetLinesPerAction();
1318 if (lines > 0)
1319 newEvent.SetEventType(wxEVT_SCROLLWIN_LINEUP);
1320 else
1321 newEvent.SetEventType(wxEVT_SCROLLWIN_LINEDOWN);
1322
1323 int times = abs(lines);
1324 for (; times > 0; times--)
1325 m_win->GetEventHandler()->ProcessEvent(newEvent);
1326 }
1327 }
1328 }
1329
1330 #endif // wxUSE_MOUSEWHEEL
1331
1332 void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
1333 {
1334 // this event should be processed by all windows in parenthood chain,
1335 // e.g. so that nested wxScrolledWindows work correctly
1336 event.Skip();
1337
1338 // find the immediate child under which the window receiving focus is:
1339 wxWindow *win = event.GetWindow();
1340
1341 if ( win == m_targetWindow )
1342 return; // nothing to do
1343
1344 while ( win->GetParent() != m_targetWindow )
1345 {
1346 win = win->GetParent();
1347 if ( !win )
1348 return; // event is not from a child of the target window
1349 }
1350
1351 // if the child is not fully visible, try to scroll it into view:
1352 int stepx, stepy;
1353 GetScrollPixelsPerUnit(&stepx, &stepy);
1354
1355 // NB: we don't call CalcScrolledPosition() on win->GetPosition() here,
1356 // because children' positions are already scrolled
1357 wxRect winrect(win->GetPosition(), win->GetSize());
1358 wxSize view(m_targetWindow->GetClientSize());
1359
1360 int startx, starty;
1361 GetViewStart(&startx, &starty);
1362
1363 // first in vertical direction:
1364 if ( stepy > 0 )
1365 {
1366 int diff = 0;
1367
1368 if ( winrect.GetTop() < 0 )
1369 {
1370 diff = winrect.GetTop();
1371 }
1372 else if ( winrect.GetBottom() > view.y )
1373 {
1374 diff = winrect.GetBottom() - view.y + 1;
1375 // round up to next scroll step if we can't get exact position,
1376 // so that the window is fully visible:
1377 diff += stepy - 1;
1378 }
1379
1380 starty = (starty * stepy + diff) / stepy;
1381 }
1382
1383 // then horizontal:
1384 if ( stepx > 0 )
1385 {
1386 int diff = 0;
1387
1388 if ( winrect.GetLeft() < 0 )
1389 {
1390 diff = winrect.GetLeft();
1391 }
1392 else if ( winrect.GetRight() > view.x )
1393 {
1394 diff = winrect.GetRight() - view.x + 1;
1395 // round up to next scroll step if we can't get exact position,
1396 // so that the window is fully visible:
1397 diff += stepx - 1;
1398 }
1399
1400 startx = (startx * stepx + diff) / stepx;
1401 }
1402
1403 Scroll(startx, starty);
1404 }
1405
1406 // ----------------------------------------------------------------------------
1407 // wxScrolled<T> and wxScrolledWindow implementation
1408 // ----------------------------------------------------------------------------
1409
1410 wxSize wxScrolledT_Helper::FilterBestSize(const wxWindow *win,
1411 const wxScrollHelperNative *helper,
1412 const wxSize& origBest)
1413 {
1414 // NB: We don't do this in WX_FORWARD_TO_SCROLL_HELPER, because not
1415 // all scrollable windows should behave like this, only those that
1416 // contain children controls within scrollable area
1417 // (i.e., wxScrolledWindow) and other some scrollable windows may
1418 // have different DoGetBestSize() implementation (e.g. wxTreeCtrl).
1419
1420 wxSize best = origBest;
1421
1422 if ( win->GetAutoLayout() )
1423 {
1424 // Only use the content to set the window size in the direction
1425 // where there's no scrolling; otherwise we're going to get a huge
1426 // window in the direction in which scrolling is enabled
1427 int ppuX, ppuY;
1428 helper->GetScrollPixelsPerUnit(&ppuX, &ppuY);
1429
1430 // NB: This code used to use *current* size if min size wasn't
1431 // specified, presumably to get some reasonable (i.e., larger than
1432 // minimal) size. But that's a wrong thing to do in GetBestSize(),
1433 // so we use minimal size as specified. If the app needs some
1434 // minimal size for its scrolled window, it should set it and put
1435 // the window into sizer as expandable so that it can use all space
1436 // available to it.
1437 //
1438 // See also http://svn.wxwidgets.org/viewvc/wx?view=rev&revision=45864
1439
1440 wxSize minSize = win->GetMinSize();
1441
1442 if ( ppuX > 0 )
1443 best.x = minSize.x + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1444
1445 if ( ppuY > 0 )
1446 best.y = minSize.y + wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
1447 }
1448
1449 return best;
1450 }
1451
1452 #ifdef __WXMSW__
1453 WXLRESULT wxScrolledT_Helper::FilterMSWWindowProc(WXLRESULT rc)
1454 {
1455 #ifndef __WXWINCE__
1456 // we need to process arrows ourselves for scrolling
1457 if ( nMsg == WM_GETDLGCODE )
1458 {
1459 rc |= DLGC_WANTARROWS;
1460 }
1461 #endif
1462 return rc;
1463 }
1464 #endif // __WXMSW__
1465
1466 // NB: skipping wxScrolled<T> in wxRTTI information because being a templte,
1467 // it doesn't and can't implement wxRTTI support
1468 IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel)