/////////////////////////////////////////////////////////////////////////////
-// Name: generic/scrolwin.cpp
-// Purpose: wxGenericScrolledWindow implementation
+// Name: src/generic/scrolwin.cpp
+// Purpose: wxScrolledWindow implementation
// Author: Julian Smart
// Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement.
// Ron Lee on 10.4.02: virtual size / auto scrollbars et al.
#pragma hdrstop
#endif
-#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
+#include "wx/scrolwin.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/utils.h"
+ #include "wx/panel.h"
+#endif
-#include "wx/utils.h"
#include "wx/dcclient.h"
-#include "wx/scrolwin.h"
-#include "wx/panel.h"
#if wxUSE_TIMER
#include "wx/timer.h"
#endif
#endif
#endif
-IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
-
/*
TODO PROPERTIES
style wxHSCROLL | wxVSCROLL
// normally, nothing more to do here - except if it was a paint event
// which wasn't really processed, then we'll try to call our
// OnDraw() below (from HandleOnPaint)
- if ( m_hasDrawnWindow )
+ if ( m_hasDrawnWindow || event.IsCommandEvent() )
{
return true;
}
wxScrollHelper::wxScrollHelper(wxWindow *win)
{
+ wxASSERT_MSG( win, _T("associated window can't be NULL in wxScrollHelper") );
+
m_xScrollPixelsPerLine =
m_yScrollPixelsPerLine =
m_xScrollPosition =
m_handler = NULL;
- if ( win )
- SetWindow(win);
+ m_win = win;
+
+ // by default, the associated window is also the target window
+ DoSetTargetWindow(win);
}
wxScrollHelper::~wxScrollHelper()
}
}
-void wxScrollHelper::SetWindow(wxWindow *win)
-{
- wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") );
-
- m_win = win;
-
- // by default, the associated window is also the target window
- DoSetTargetWindow(win);
-}
-
void wxScrollHelper::DoSetTargetWindow(wxWindow *target)
{
m_targetWindow = target;
do
{
iterationCount ++;
-
+
GetTargetSize(&w, 0);
// scroll lines per page: if 0, no scrolling is needed
if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
- int w, h;
+ int w = 0, h = 0;
GetTargetSize(&w, &h);
if ((x_pos != -1) && (m_xScrollPixelsPerLine))
*yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
}
+// ----------------------------------------------------------------------------
+// geometry
+// ----------------------------------------------------------------------------
+
+bool wxScrollHelper::ScrollLayout()
+{
+ if ( m_win->GetSizer() && m_targetWindow == m_win )
+ {
+ // If we're the scroll target, take into account the
+ // virtual size and scrolled position of the window.
+
+ int x = 0, y = 0, w = 0, h = 0;
+ CalcScrolledPosition(0,0, &x,&y);
+ m_win->GetVirtualSize(&w, &h);
+ m_win->GetSizer()->SetDimension(x, y, w, h);
+ return true;
+ }
+
+ // fall back to default for LayoutConstraints
+ return m_win->wxWindow::Layout();
+}
+
+void wxScrollHelper::ScrollDoSetVirtualSize(int x, int y)
+{
+ m_win->wxWindow::DoSetVirtualSize( x, y );
+ AdjustScrollbars();
+
+ if (m_win->GetAutoLayout())
+ m_win->Layout();
+}
+
+// wxWindow's GetBestVirtualSize returns the actual window size,
+// whereas we want to return the virtual size
+wxSize wxScrollHelper::ScrollGetBestVirtualSize() const
+{
+ wxSize clientSize(m_win->GetClientSize());
+ if ( m_win->GetSizer() )
+ clientSize.IncTo(m_win->GetSizer()->CalcMin());
+
+ 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_targetWindow->GetAutoLayout() )
{
wxSize size = m_targetWindow->GetBestVirtualSize();
-
+
// This will call ::Layout() and ::AdjustScrollbars()
m_win->SetVirtualSize( size );
}
// this they always have the priority
void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
{
- int stx, sty, // view origin
- szx, szy, // view size (total)
- clix, cliy; // view size (on screen)
+ int stx = 0, sty = 0, // view origin
+ szx = 0, szy = 0, // view size (total)
+ clix = 0, cliy = 0; // view size (on screen)
GetViewStart(&stx, &sty);
GetTargetSize(&clix, &cliy);
switch ( event.GetKeyCode() )
{
case WXK_PAGEUP:
- case WXK_PRIOR:
dsty = sty - (5 * cliy / 6);
Scroll(-1, (dsty == -1) ? 0 : dsty);
break;
case WXK_PAGEDOWN:
- case WXK_NEXT:
Scroll(-1, sty + (5 * cliy / 6));
break;
#endif // wxUSE_MOUSEWHEEL
// ----------------------------------------------------------------------------
-// wxGenericScrolledWindow implementation
+// wxScrolledWindow implementation
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
+IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel)
-BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel)
- EVT_PAINT(wxGenericScrolledWindow::OnPaint)
+BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
+ EVT_PAINT(wxScrolledWindow::OnPaint)
END_EVENT_TABLE()
-bool wxGenericScrolledWindow::Create(wxWindow *parent,
+bool wxScrolledWindow::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
return ok;
}
-wxGenericScrolledWindow::~wxGenericScrolledWindow()
-{
-}
-
-bool wxGenericScrolledWindow::Layout()
-{
- if (GetSizer() && m_targetWindow == this)
- {
- // If we're the scroll target, take into account the
- // virtual size and scrolled position of the window.
-
- int x, y, w, h;
- CalcScrolledPosition(0,0, &x,&y);
- GetVirtualSize(&w, &h);
- GetSizer()->SetDimension(x, y, w, h);
- return true;
- }
-
- // fall back to default for LayoutConstraints
- return wxPanel::Layout();
-}
-
-void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y)
+wxScrolledWindow::~wxScrolledWindow()
{
- wxPanel::DoSetVirtualSize( x, y );
- AdjustScrollbars();
-
- if (GetAutoLayout())
- Layout();
}
-// wxWindow's GetBestVirtualSize returns the actual window size,
-// whereas we want to return the virtual size
-wxSize wxGenericScrolledWindow::GetBestVirtualSize() const
-{
- wxSize clientSize( GetClientSize() );
- if (GetSizer())
- {
- wxSize minSize( GetSizer()->CalcMin() );
-
- return wxSize( wxMax( clientSize.x, minSize.x ), wxMax( clientSize.y, minSize.y ) );
- }
- else
- return clientSize;
-}
-
-// return the size best suited for the current window
-// (this isn't a virtual size, this is a sensible size for the window)
-wxSize wxGenericScrolledWindow::DoGetBestSize() const
-{
- wxSize best;
-
- if ( GetSizer() )
- {
- wxSize b = GetSizer()->GetMinSize();
-
- // 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;
- if ( GetMinSize().IsFullySpecified() )
- minSize = GetMinSize();
- else
- minSize = GetSize();
-
- if (ppuX > 0)
- b.x = minSize.x;
- if (ppuY > 0)
- b.y = minSize.y;
- best = b;
- }
- else
- return wxWindow::DoGetBestSize();
-
- // Add any difference between size and client size
- wxSize diff = GetSize() - GetClientSize();
- best.x += wxMax(0, diff.x);
- best.y += wxMax(0, diff.y);
-
- return best;
-}
-
-void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
+void wxScrolledWindow::OnPaint(wxPaintEvent& event)
{
// the user code didn't really draw the window if we got here, so set this
// flag to try to call OnDraw() later
}
#ifdef __WXMSW__
-WXLRESULT
-wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
+WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam,
WXLPARAM lParam)
{
}
#endif // __WXMSW__
-
-#endif // !wxGTK
-
-// vi:sts=4:sw=4:et