From f24f65791310a4e0d1690f244658b837036aa270 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2008 22:11:27 +0000 Subject: [PATCH] emulate scrolling in wxMSW header control; document the need to call ScrollWindow() when using it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57133 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/headerctrl.h | 5 +++++ interface/wx/headerctrl.h | 4 +++- src/msw/headerctrl.cpp | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/headerctrl.h b/include/wx/msw/headerctrl.h index 130de040a8..8a2c388417 100644 --- a/include/wx/msw/headerctrl.h +++ b/include/wx/msw/headerctrl.h @@ -46,6 +46,11 @@ public: virtual ~wxHeaderCtrl(); + + // this method is only overridden in order to synchronize the control with + // the main window when it is scrolled + virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); + private: // implement base class pure virtuals virtual unsigned int DoGetCount() const; diff --git a/interface/wx/headerctrl.h b/interface/wx/headerctrl.h index fa5537a4f8..4d311c62d5 100644 --- a/interface/wx/headerctrl.h +++ b/interface/wx/headerctrl.h @@ -29,7 +29,9 @@ Notice that this control itself doesn't do anything other than displaying the column headers. In particular column reordering and sorting must still be supported by the associated control displaying the real data under the - header. + header. Also remember to call ScrollWindow() method of the control if the + associated data display window has a horizontal scrollbar, otherwise the + headers wouldn't align with the data when the window is scrolled. This control is implemented using the native header control under MSW systems and a generic implementation elsewhere. diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index 9390925fec..6330b225e1 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -86,6 +86,29 @@ wxHeaderCtrl::~wxHeaderCtrl() delete m_imageList; } +// ---------------------------------------------------------------------------- +// wxHeaderCtrl scrolling +// ---------------------------------------------------------------------------- + +// as the native control doesn't support offsetting its contents, we use a hack +// here to make it appear correctly when the parent is scrolled: instead of +// scrolling or repainting we simply move the control window itself +void wxHeaderCtrl::ScrollWindow(int dx, + int WXUNUSED_UNLESS_DEBUG(dy), + const wxRect * WXUNUSED_UNLESS_DEBUG(rect)) +{ + // this doesn't make sense at all + wxASSERT_MSG( !dy, "header window can't be scrolled vertically" ); + + // this would actually be nice to support for "frozen" headers + wxASSERT_MSG( !rect, "header window can't be scrolled partially" ); + + // offset the window by the scroll increment to the left and increment its + // width to still extend to the right boundary to compensate for it (notice + // that dx is negative when scrolling to the right) + SetSize(GetPosition().x + dx, -1, GetSize().x - dx, -1, wxSIZE_USE_EXISTING); +} + // ---------------------------------------------------------------------------- // wxHeaderCtrl geometry calculation // ---------------------------------------------------------------------------- -- 2.47.2