// headers
// ----------------------------------------------------------------------------
-#ifdef __VMS
-#define XtDisplay XTDISPLAY
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/utils.h"
#include "wx/panel.h"
#include "wx/dcclient.h"
- #if wxUSE_TIMER
- #include "wx/timer.h"
- #endif
+ #include "wx/timer.h"
#include "wx/sizer.h"
+ #include "wx/settings.h"
#endif
#ifdef __WXMAC__
return true;
}
+ if ( evType == wxEVT_CHILD_FOCUS )
+ {
+ m_scrollHelper->HandleOnChildFocus((wxChildFocusEvent &)event);
+ return true;
+ }
+
// reset the skipped flag (which might have been set to true in
// ProcessEvent() above) to be able to test it below
bool wasSkipped = event.GetSkipped();
m_scrollHelper->HandleOnMouseLeave((wxMouseEvent &)event);
}
#if wxUSE_MOUSEWHEEL
+ // Use GTK's own scroll wheel handling in GtkScrolledWindow
+#ifndef __WXGTK20__
else if ( evType == wxEVT_MOUSEWHEEL )
{
m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
+ return true;
}
+#endif
#endif // wxUSE_MOUSEWHEEL
else if ( evType == wxEVT_CHAR )
{
return m_targetWindow;
}
-#ifdef __WXMAC__
-static bool wxScrolledWindowHasChildren(wxWindow* win)
-{
- wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
- while ( node )
- {
- wxWindow* child = node->GetData();
- if ( !child->IsKindOf(CLASSINFO(wxScrollBar)) )
- return true;
-
- node = node->GetNext();
- }
- return false;
-}
-#endif
-
// ----------------------------------------------------------------------------
// scrolling implementation itself
// ----------------------------------------------------------------------------
return clientSize;
}
-// return the window best size from the given best virtual size
-wxSize
-wxScrollHelper::ScrollGetWindowSizeForVirtualSize(const wxSize& size) const
-{
- // Only use the content to set the window size in the direction
- // where there's no scrolling; otherwise we're going to get a huge
- // window in the direction in which scrolling is enabled
- int ppuX, ppuY;
- GetScrollPixelsPerUnit(&ppuX, &ppuY);
-
- wxSize minSize = m_win->GetMinSize();
- if ( !minSize.IsFullySpecified() )
- minSize = m_win->GetSize();
-
- wxSize best(size);
- if (ppuX > 0)
- best.x = minSize.x;
- if (ppuY > 0)
- best.y = minSize.y;
-
- return best;
-}
-
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
if ( m_xScrollPosition != xScrollOld )
{
- wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
+ wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
wxHORIZONTAL);
- event.SetEventObject(m_win);
- m_win->GetEventHandler()->ProcessEvent(event);
+ evt.SetEventObject(m_win);
+ m_win->GetEventHandler()->ProcessEvent(evt);
}
if ( m_yScrollPosition != yScrollOld )
{
- wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition,
+ wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition,
wxVERTICAL);
- event.SetEventObject(m_win);
- m_win->GetEventHandler()->ProcessEvent(event);
+ evt.SetEventObject(m_win);
+ m_win->GetEventHandler()->ProcessEvent(evt);
}
}
#endif // wxUSE_MOUSEWHEEL
+void wxScrollHelper::HandleOnChildFocus(wxChildFocusEvent& event)
+{
+ // this event should be processed by all windows in parenthood chain,
+ // e.g. so that nested wxScrolledWindows work correctly
+ event.Skip();
+
+ // find the immediate child under which the window receiving focus is:
+ wxWindow *win = event.GetWindow();
+
+ if ( win == m_targetWindow )
+ return; // nothing to do
+
+ while ( win->GetParent() != m_targetWindow )
+ {
+ win = win->GetParent();
+ if ( !win )
+ return; // event is not from a child of the target window
+ }
+
+ // if the child is not fully visible, try to scroll it into view:
+ int stepx, stepy;
+ GetScrollPixelsPerUnit(&stepx, &stepy);
+
+ // NB: we don't call CalcScrolledPosition() on win->GetPosition() here,
+ // because children' positions are already scrolled
+ wxRect winrect(win->GetPosition(), win->GetSize());
+ wxSize view(m_targetWindow->GetClientSize());
+
+ int startx, starty;
+ GetViewStart(&startx, &starty);
+
+ // first in vertical direction:
+ if ( stepy > 0 )
+ {
+ int diff = 0;
+
+ if ( winrect.GetTop() < 0 )
+ {
+ diff = winrect.GetTop();
+ }
+ else if ( winrect.GetBottom() > view.y )
+ {
+ diff = winrect.GetBottom() - view.y + 1;
+ // round up to next scroll step if we can't get exact position,
+ // so that the window is fully visible:
+ diff += stepy - 1;
+ }
+
+ starty = (starty * stepy + diff) / stepy;
+ }
+
+ // then horizontal:
+ if ( stepx > 0 )
+ {
+ int diff = 0;
+
+ if ( winrect.GetLeft() < 0 )
+ {
+ diff = winrect.GetLeft();
+ }
+ else if ( winrect.GetRight() > view.x )
+ {
+ diff = winrect.GetRight() - view.x + 1;
+ // round up to next scroll step if we can't get exact position,
+ // so that the window is fully visible:
+ diff += stepx - 1;
+ }
+
+ startx = (startx * stepx + diff) / stepx;
+ }
+
+ Scroll(startx, starty);
+}
+
// ----------------------------------------------------------------------------
// wxScrolledWindow implementation
// ----------------------------------------------------------------------------
event.Skip();
}
+wxSize wxScrolledWindow::DoGetBestSize() const
+{
+ // NB: We don't do this in WX_FORWARD_TO_SCROLL_HELPER, because not
+ // all scrollable windows should behave like this, only those that
+ // contain children controls within scrollable area
+ // (i.e., wxScrolledWindow) and other some scrollable windows may
+ // have different DoGetBestSize() implementation (e.g. wxTreeCtrl).
+
+ wxSize best = wxPanel::DoGetBestSize();
+
+ if ( GetAutoLayout() )
+ {
+ // Only use the content to set the window size in the direction
+ // where there's no scrolling; otherwise we're going to get a huge
+ // window in the direction in which scrolling is enabled
+ int ppuX, ppuY;
+ GetScrollPixelsPerUnit(&ppuX, &ppuY);
+
+ // NB: This code used to use *current* size if min size wasn't
+ // specified, presumably to get some reasonable (i.e., larger than
+ // minimal) size. But that's a wrong thing to do in GetBestSize(),
+ // so we use minimal size as specified. If the app needs some
+ // minimal size for its scrolled window, it should set it and put
+ // the window into sizer as expandable so that it can use all space
+ // available to it.
+ //
+ // See also http://svn.wxwidgets.org/viewvc/wx?view=rev&revision=45864
+
+ wxSize minSize = GetMinSize();
+
+ if ( ppuX > 0 )
+ best.x = minSize.x + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+
+ if ( ppuY > 0 )
+ best.y = minSize.y + wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
+ }
+
+ return best;
+}
+
#ifdef __WXMSW__
WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam,