refactored wxGTK scrolling: it has now fully-functioning wxScrollHelper and a lot of duplicate code was removed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-10-10 18:24:27 +00:00
parent 87a3ebe978
commit d32e78bd42
7 changed files with 421 additions and 2452 deletions

View File

@@ -19,72 +19,9 @@
#include "wx/window.h" #include "wx/window.h"
#include "wx/panel.h" #include "wx/panel.h"
extern WXDLLEXPORT_DATA(const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGenericScrolledWindow // wxGenericScrolledWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxGenericScrolledWindow : public wxPanel,
public wxScrollHelper
{
public:
wxGenericScrolledWindow() : wxScrollHelper(this) { }
wxGenericScrolledWindow(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
: wxScrollHelper(this)
{
Create(parent, winid, pos, size, style, name);
}
virtual ~wxGenericScrolledWindow();
bool Create(wxWindow *parent,
wxWindowID winid,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
virtual void DoSetVirtualSize(int x, int y);
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
protected:
// this is needed for wxEVT_PAINT processing hack described in
// wxScrollHelperEvtHandler::ProcessEvent()
void OnPaint(wxPaintEvent& event);
// we need to return a special WM_GETDLGCODE value to process just the
// arrows but let the other navigation characters through
#ifdef __WXMSW__
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
#endif // __WXMSW__
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericScrolledWindow)
DECLARE_EVENT_TABLE()
};
#endif // _WX_GENERIC_SCROLLWIN_H_ #endif // _WX_GENERIC_SCROLLWIN_H_

View File

@@ -2,7 +2,7 @@
// Name: wx/gtk/scrolwin.h // Name: wx/gtk/scrolwin.h
// Purpose: wxScrolledWindow class // Purpose: wxScrolledWindow class
// Author: Robert Roebling // Author: Robert Roebling
// Modified by: // Modified by: Vadim Zeitlin (2005-10-10): wxScrolledWindow is now common
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Robert Roebling // Copyright: (c) Robert Roebling
@@ -12,182 +12,43 @@
#ifndef _WX_GTK_SCROLLWIN_H_ #ifndef _WX_GTK_SCROLLWIN_H_
#define _WX_GTK_SCROLLWIN_H_ #define _WX_GTK_SCROLLWIN_H_
// ----------------------------------------------------------------------------
// headers and constants
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/panel.h"
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxScrolledWindow // wxScrolledWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxScrolledWindow : public wxPanel class WXDLLEXPORT wxScrollHelperNative : public wxScrollHelper
{ {
public: public:
wxScrolledWindow() // default ctor doesn't do anything
{ Init(); } wxScrollHelperNative(wxWindow *win) : wxScrollHelper(win) { }
wxScrolledWindow(wxWindow *parent,
wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
{ Create(parent, id, pos, size, style, name); }
void Init();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
// Normally the wxScrolledWindow will scroll itself, but in
// some rare occasions you might want it to scroll another
// window (e.g. a child of it in order to scroll only a portion
// the area between the scrollbars (spreadsheet: only cell area
// will move).
virtual void SetTargetWindow( wxWindow *target, bool pushEventHandler = FALSE );
virtual wxWindow *GetTargetWindow() const;
// Set the scrolled area of the window.
virtual void DoSetVirtualSize( int x, int y );
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
// Length of page in user units
// Default action is to set the virtual size and alter scrollbars
// accordingly.
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY, int noUnitsX, int noUnitsY,
int xPos = 0, int yPos = 0, int xPos = 0, int yPos = 0,
bool noRefresh = FALSE ); bool noRefresh = false);
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
// Enable/disable Windows scrolling in either direction.
// If TRUE, wxWidgets scrolls the canvas and only a bit of
// the canvas is invalidated; no Clear() is necessary.
// If FALSE, the whole canvas is invalidated and a Clear() is
// necessary. Disable for when the scroll increment is used
// to actually scroll a non-constant distance
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start
virtual void GetViewStart(int *x, int *y) const;
// translate between scrolled and unscrolled coordinates
void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcScrolledPosition(x, y, xx, yy); }
wxPoint CalcScrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcUnscrolledPosition(x, y, xx, yy); }
wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
// Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) {}
// Override this function if you don't want to have wxScrolledWindow
// automatically change the origin according to the scroll position.
void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
// Adjust the scrollbars
virtual void AdjustScrollbars(); virtual void AdjustScrollbars();
virtual void Scroll(int x, int y);
// Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
double GetScaleX() const { return m_scaleX; }
double GetScaleY() const { return m_scaleY; }
// implementation from now on
void OnScroll(wxScrollWinEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnChar(wxKeyEvent& event);
void GtkVScroll( float value, unsigned int scroll_type );
void GtkHScroll( float value, unsigned int scroll_type );
void GtkVConnectEvent();
void GtkHConnectEvent();
void GtkVDisconnectEvent();
void GtkHDisconnectEvent();
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
// Overridden from wxWidgets due callback being static
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
virtual void DoPrepareDC(wxDC& dc);
protected: protected:
wxWindow *m_targetWindow; // this does (each) half of AdjustScrollbars() work
int m_xScrollPixelsPerLine; void DoAdjustScrollbar(GtkAdjustment *adj,
int m_yScrollPixelsPerLine; int pixelsPerLine,
bool m_xScrollingEnabled; int winSize,
bool m_yScrollingEnabled; int virtSize,
int *pos,
int *lines,
int *linesPerPage);
// FIXME: these next four members are duplicated in the GtkAdjustment // and this does the same for Scroll()
// members of wxWindow. Can they be safely removed from here? void DoScroll(int orient,
GtkAdjustment *adj,
int m_xScrollPosition; int pos,
int m_yScrollPosition; int pixelsPerLine,
int m_xScrollLinesPerPage; int *posOld);
int m_yScrollLinesPerPage;
double m_scaleY,m_scaleX;
private: private:
DECLARE_EVENT_TABLE() DECLARE_NO_COPY_CLASS(wxScrollHelperNative)
DECLARE_DYNAMIC_CLASS(wxScrolledWindow)
}; };
#endif #endif // _WX_GTK_SCROLLWIN_H_
// _WX_GTK_SCROLLWIN_H_
// vi:sts=4:sw=4:et

View File

@@ -2,7 +2,7 @@
// Name: wx/gtk/scrolwin.h // Name: wx/gtk/scrolwin.h
// Purpose: wxScrolledWindow class // Purpose: wxScrolledWindow class
// Author: Robert Roebling // Author: Robert Roebling
// Modified by: // Modified by: Vadim Zeitlin (2005-10-10): wxScrolledWindow is now common
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Robert Roebling // Copyright: (c) Robert Roebling
@@ -12,182 +12,43 @@
#ifndef _WX_GTK_SCROLLWIN_H_ #ifndef _WX_GTK_SCROLLWIN_H_
#define _WX_GTK_SCROLLWIN_H_ #define _WX_GTK_SCROLLWIN_H_
// ----------------------------------------------------------------------------
// headers and constants
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/panel.h"
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxScrolledWindow // wxScrolledWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxScrolledWindow : public wxPanel class WXDLLEXPORT wxScrollHelperNative : public wxScrollHelper
{ {
public: public:
wxScrolledWindow() // default ctor doesn't do anything
{ Init(); } wxScrollHelperNative(wxWindow *win) : wxScrollHelper(win) { }
wxScrolledWindow(wxWindow *parent,
wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
{ Create(parent, id, pos, size, style, name); }
void Init();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
// Normally the wxScrolledWindow will scroll itself, but in
// some rare occasions you might want it to scroll another
// window (e.g. a child of it in order to scroll only a portion
// the area between the scrollbars (spreadsheet: only cell area
// will move).
virtual void SetTargetWindow( wxWindow *target, bool pushEventHandler = FALSE );
virtual wxWindow *GetTargetWindow() const;
// Set the scrolled area of the window.
virtual void DoSetVirtualSize( int x, int y );
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
// Length of page in user units
// Default action is to set the virtual size and alter scrollbars
// accordingly.
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY, int noUnitsX, int noUnitsY,
int xPos = 0, int yPos = 0, int xPos = 0, int yPos = 0,
bool noRefresh = FALSE ); bool noRefresh = false);
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
// Enable/disable Windows scrolling in either direction.
// If TRUE, wxWidgets scrolls the canvas and only a bit of
// the canvas is invalidated; no Clear() is necessary.
// If FALSE, the whole canvas is invalidated and a Clear() is
// necessary. Disable for when the scroll increment is used
// to actually scroll a non-constant distance
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start
virtual void GetViewStart(int *x, int *y) const;
// translate between scrolled and unscrolled coordinates
void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcScrolledPosition(x, y, xx, yy); }
wxPoint CalcScrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcUnscrolledPosition(x, y, xx, yy); }
wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
// Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) {}
// Override this function if you don't want to have wxScrolledWindow
// automatically change the origin according to the scroll position.
void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
// Adjust the scrollbars
virtual void AdjustScrollbars(); virtual void AdjustScrollbars();
virtual void Scroll(int x, int y);
// Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
double GetScaleX() const { return m_scaleX; }
double GetScaleY() const { return m_scaleY; }
// implementation from now on
void OnScroll(wxScrollWinEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnChar(wxKeyEvent& event);
void GtkVScroll( float value, unsigned int scroll_type );
void GtkHScroll( float value, unsigned int scroll_type );
void GtkVConnectEvent();
void GtkHConnectEvent();
void GtkVDisconnectEvent();
void GtkHDisconnectEvent();
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
// Overridden from wxWidgets due callback being static
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
virtual void DoPrepareDC(wxDC& dc);
protected: protected:
wxWindow *m_targetWindow; // this does (each) half of AdjustScrollbars() work
int m_xScrollPixelsPerLine; void DoAdjustScrollbar(GtkAdjustment *adj,
int m_yScrollPixelsPerLine; int pixelsPerLine,
bool m_xScrollingEnabled; int winSize,
bool m_yScrollingEnabled; int virtSize,
int *pos,
int *lines,
int *linesPerPage);
// FIXME: these next four members are duplicated in the GtkAdjustment // and this does the same for Scroll()
// members of wxWindow. Can they be safely removed from here? void DoScroll(int orient,
GtkAdjustment *adj,
int m_xScrollPosition; int pos,
int m_yScrollPosition; int pixelsPerLine,
int m_xScrollLinesPerPage; int *posOld);
int m_yScrollLinesPerPage;
double m_scaleY,m_scaleX;
private: private:
DECLARE_EVENT_TABLE() DECLARE_NO_COPY_CLASS(wxScrollHelperNative)
DECLARE_DYNAMIC_CLASS(wxScrolledWindow)
}; };
#endif #endif // _WX_GTK_SCROLLWIN_H_
// _WX_GTK_SCROLLWIN_H_
// vi:sts=4:sw=4:et

View File

@@ -17,19 +17,44 @@
class WXDLLEXPORT wxScrollHelperEvtHandler; class WXDLLEXPORT wxScrollHelperEvtHandler;
class WXDLLEXPORT wxTimer; class WXDLLEXPORT wxTimer;
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
// default scrolled window style: scroll in both directions
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxScrollHelper: this class implements the scrolling logic which is used by // The hierarchy of scrolling classes is a bit complicated because we want to
// wxScrolledWindow and wxScrolledControl. It is a mix-in: just derive from it // put as much functionality as possible in a mix-in class not deriving from
// to implement scrolling in your class. // wxWindow so that other classes could derive from the same base class on all
// platforms irrespectively of whether they are native controls (and hence
// don't use our scrolling) or not.
//
// So we have
//
// wxScrollHelper
// |
// |
// \|/
// wxWindow wxScrollHelperNative
// | \ / /
// | \ / /
// | _| |_ /
// | wxScrolledWindow /
// | /
// \|/ /
// wxControl /
// \ /
// \ /
// _| |_
// wxScrolledControl
//
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
class WXDLLEXPORT wxScrollHelper class WXDLLEXPORT wxScrollHelper
{ {
public: public:
// ctor and dtor // ctor must be given the associated window
wxScrollHelper(wxWindow *winToScroll = (wxWindow *)NULL); wxScrollHelper(wxWindow *winToScroll);
void SetWindow(wxWindow *winToScroll);
virtual ~wxScrollHelper(); virtual ~wxScrollHelper();
// configure the scrolling // configure the scrolling
@@ -163,6 +188,13 @@ protected:
*h = size.y; *h = size.y;
} }
// implementations of various wxWindow virtual methods which should be
// forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER())
bool ScrollLayout();
void ScrollDoSetVirtualSize(int x, int y);
wxSize ScrollGetBestVirtualSize() const;
wxSize ScrollGetWindowSizeForVirtualSize(const wxSize& size) const;
// change just the target window (unlike SetWindow which changes m_win as // change just the target window (unlike SetWindow which changes m_win as
// well) // well)
void DoSetTargetWindow(wxWindow *target); void DoSetTargetWindow(wxWindow *target);
@@ -170,6 +202,7 @@ protected:
// delete the event handler we installed // delete the event handler we installed
void DeleteEvtHandler(); void DeleteEvtHandler();
double m_scaleX; double m_scaleX;
double m_scaleY; double m_scaleY;
@@ -201,38 +234,71 @@ protected:
DECLARE_NO_COPY_CLASS(wxScrollHelper) DECLARE_NO_COPY_CLASS(wxScrollHelper)
}; };
// this macro can be used in a wxScrollHelper-derived class to forward wxWindow
// methods to corresponding wxScrollHelper methods
#define WX_FORWARD_TO_SCROLL_HELPER() \
virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); } \
virtual bool Layout() { return ScrollLayout(); } \
virtual void DoSetVirtualSize(int x, int y) \
{ ScrollDoSetVirtualSize(x, y); } \
virtual wxSize GetBestVirtualSize() const \
{ return ScrollGetBestVirtualSize(); } \
virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const \
{ return ScrollGetWindowSizeForVirtualSize(size); }
// include the declaration of wxScrollHelperNative if needed
#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
#include "wx/gtk/scrolwin.h"
#else
typedef wxScrollHelper wxScrollHelperNative;
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxScrolledWindow: a wxWindow which knows how to scroll // wxScrolledWindow: a wxWindow which knows how to scroll
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) class WXDLLEXPORT wxScrolledWindow : public wxPanel,
#include "wx/gtk/scrolwin.h" public wxScrollHelperNative
#else // !wxGTK
#include "wx/generic/scrolwin.h"
class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
{ {
public: public:
wxScrolledWindow() { } wxScrolledWindow() : wxScrollHelperNative(this) { }
wxScrolledWindow(wxWindow *parent, wxScrolledWindow(wxWindow *parent,
wxWindowID winid = wxID_ANY, wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle, long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr) const wxString& name = wxPanelNameStr)
: wxGenericScrolledWindow(parent, winid, pos, size, style, name) : wxScrollHelperNative(this)
{ {
Create(parent, winid, pos, size, style, name);
} }
virtual ~wxScrolledWindow();
bool Create(wxWindow *parent,
wxWindowID winid,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
WX_FORWARD_TO_SCROLL_HELPER()
protected:
// this is needed for wxEVT_PAINT processing hack described in
// wxScrollHelperEvtHandler::ProcessEvent()
void OnPaint(wxPaintEvent& event);
// we need to return a special WM_GETDLGCODE value to process just the
// arrows but let the other navigation characters through
#ifdef __WXMSW__
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
#endif // __WXMSW__
private: private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow) DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
DECLARE_EVENT_TABLE()
}; };
#define wxSCROLLED_WINDOW_IS_GENERIC 1 #endif // _WX_SCROLWIN_H_BASE_
#endif
#endif
// _WX_SCROLWIN_H_BASE_

View File

@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: generic/scrolwin.cpp // Name: generic/scrolwin.cpp
// Purpose: wxGenericScrolledWindow implementation // Purpose: wxScrolledWindow implementation
// Author: Julian Smart // Author: Julian Smart
// Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement. // Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement.
// Ron Lee on 10.4.02: virtual size / auto scrollbars et al. // Ron Lee on 10.4.02: virtual size / auto scrollbars et al.
@@ -29,8 +29,6 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/dcclient.h" #include "wx/dcclient.h"
@@ -59,8 +57,6 @@
#endif #endif
#endif #endif
IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
/* /*
TODO PROPERTIES TODO PROPERTIES
style wxHSCROLL | wxVSCROLL style wxHSCROLL | wxVSCROLL
@@ -284,6 +280,8 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
wxScrollHelper::wxScrollHelper(wxWindow *win) wxScrollHelper::wxScrollHelper(wxWindow *win)
{ {
wxASSERT_MSG( win, _T("associated window can't be NULL in wxScrollHelper") );
m_xScrollPixelsPerLine = m_xScrollPixelsPerLine =
m_yScrollPixelsPerLine = m_yScrollPixelsPerLine =
m_xScrollPosition = m_xScrollPosition =
@@ -309,8 +307,10 @@ wxScrollHelper::wxScrollHelper(wxWindow *win)
m_handler = NULL; m_handler = NULL;
if ( win ) m_win = win;
SetWindow(win);
// by default, the associated window is also the target window
DoSetTargetWindow(win);
} }
wxScrollHelper::~wxScrollHelper() wxScrollHelper::~wxScrollHelper()
@@ -407,16 +407,6 @@ void wxScrollHelper::DeleteEvtHandler()
} }
} }
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) void wxScrollHelper::DoSetTargetWindow(wxWindow *target)
{ {
m_targetWindow = target; m_targetWindow = target;
@@ -956,6 +946,71 @@ void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) co
*yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; *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, y, w, h;
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 // event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1228,16 +1283,16 @@ void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
#endif // wxUSE_MOUSEWHEEL #endif // wxUSE_MOUSEWHEEL
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGenericScrolledWindow implementation // wxScrolledWindow implementation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel) IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel)
BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel) BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
EVT_PAINT(wxGenericScrolledWindow::OnPaint) EVT_PAINT(wxScrolledWindow::OnPaint)
END_EVENT_TABLE() END_EVENT_TABLE()
bool wxGenericScrolledWindow::Create(wxWindow *parent, bool wxScrolledWindow::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
@@ -1254,92 +1309,11 @@ bool wxGenericScrolledWindow::Create(wxWindow *parent,
return ok; return ok;
} }
wxGenericScrolledWindow::~wxGenericScrolledWindow() wxScrolledWindow::~wxScrolledWindow()
{ {
} }
bool wxGenericScrolledWindow::Layout() void wxScrolledWindow::OnPaint(wxPaintEvent& event)
{
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)
{
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)
{ {
// the user code didn't really draw the window if we got here, so set this // the user code didn't really draw the window if we got here, so set this
// flag to try to call OnDraw() later // flag to try to call OnDraw() later
@@ -1349,8 +1323,7 @@ void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
} }
#ifdef __WXMSW__ #ifdef __WXMSW__
WXLRESULT WXLRESULT wxScrolledWindow::MSWWindowProc(WXUINT nMsg,
wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam, WXWPARAM wParam,
WXLPARAM lParam) WXLPARAM lParam)
{ {
@@ -1369,6 +1342,3 @@ wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
#endif // __WXMSW__ #endif // __WXMSW__
#endif // !wxGTK
// vi:sts=4:sw=4:et

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff