From a000920547e25b92ce1dfa18f73d99dbf780db72 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2008 21:50:30 +0000 Subject: [PATCH] add Show/HideColumn() methods git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57132 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/headerctrl.h | 19 ++++++++++++++++++- include/wx/msw/headerctrl.h | 1 + interface/wx/headerctrl.h | 28 ++++++++++++++++++++++++++++ src/msw/headerctrl.cpp | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index f47df31917..e317eca220 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -101,6 +101,20 @@ public: // modifying columns // ----------------- + // show or hide the column, notice that even when a column is hidden we + // still account for it when using indices + void ShowColumn(unsigned int idx, bool show = true) + { + wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); + + DoShowColumn(idx, show); + } + + void HideColumn(unsigned int idx) + { + ShowColumn(idx, false); + } + // indicate that the column is used for sorting in ascending order if // sortOrder is true, for sorting in descending order if it is false or not // used for sorting at all if it is -1 @@ -109,6 +123,8 @@ public: wxCHECK_RET( sortOrder == 0 || sortOrder == 1 || sortOrder == -1, "invalid sort order value" ); + wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); + DoShowSortIndicator(idx, sortOrder); } @@ -129,6 +145,7 @@ private: virtual unsigned int DoGetCount() const = 0; virtual void DoInsert(const wxHeaderColumn& col, unsigned int idx) = 0; virtual void DoDelete(unsigned int idx) = 0; + virtual void DoShowColumn(unsigned int idx, bool show) = 0; virtual void DoShowSortIndicator(unsigned int idx, int sortOrder) = 0; }; @@ -136,7 +153,7 @@ private: #include "wx/msw/headerctrl.h" #elif 0 // TODO #define wxHAS_GENERIC_HEADERCTRL - #include "wx/generic/headerctrl.h" + #include "wx/generic/headerctrlg.h" #endif // platform #endif // _WX_HEADERCTRL_H_ diff --git a/include/wx/msw/headerctrl.h b/include/wx/msw/headerctrl.h index c1c09fa38d..130de040a8 100644 --- a/include/wx/msw/headerctrl.h +++ b/include/wx/msw/headerctrl.h @@ -51,6 +51,7 @@ private: virtual unsigned int DoGetCount() const; virtual void DoInsert(const wxHeaderColumn& col, unsigned int idx); virtual void DoDelete(unsigned int idx); + virtual void DoShowColumn(unsigned int idx, bool show); virtual void DoShowSortIndicator(unsigned int idx, int sortOrder); // override wxWindow methods which must be implemented by a new control diff --git a/interface/wx/headerctrl.h b/interface/wx/headerctrl.h index 110a2585a1..fa5537a4f8 100644 --- a/interface/wx/headerctrl.h +++ b/interface/wx/headerctrl.h @@ -159,6 +159,34 @@ public: */ void DeleteColumn(unsigned int idx); + /** + Show or hide the column. + + Initially the column is shown by default or hidden if it was added with + wxCOL_HIDDEN flag set. + + When a column is hidden, it doesn't appear at all on the screen but its + index is still taken into account when working with other columns. E.g. + if there are three columns 0, 1 and 2 and the column 1 is hidden you + still need to use index 2 to refer to the last visible column. + + @param idx + The index of the column to show or hide, from 0 to GetColumnCount(). + @param show + Indicates whether the column should be shown (default) or hidden. + */ + void ShowColumn(unsigned int idx, bool show = true); + + /** + Hide the column with the given index. + + This is the same as calling @code ShowColumn(idx, false) @endcode. + + @param idx + The index of the column to show or hide, from 0 to GetColumnCount(). + */ + void HideColumn(unsigned int idx); + /** Update the column sort indicator. diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index 3acf89cd38..9390925fec 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -145,6 +145,12 @@ void wxHeaderCtrl::DoInsert(const wxHeaderColumn& col, unsigned int idx) hdi.iImage = m_imageList->GetImageCount() - 1; } + if ( col.IsHidden() ) + { + hdi.mask |= HDI_WIDTH; + hdi.cxy = 0; + } + if ( Header_InsertItem(GetHwnd(), idx, &hdi) == -1 ) { wxLogLastError(_T("Header_InsertItem")); @@ -163,6 +169,29 @@ void wxHeaderCtrl::DoDelete(unsigned int idx) // wxHeaderCtrl columns attributes // ---------------------------------------------------------------------------- +void wxHeaderCtrl::DoShowColumn(unsigned int idx, bool show) +{ + wxHDITEM hdi; + hdi.mask = HDI_WIDTH; + + if ( !Header_GetItem(GetHwnd(), idx, &hdi) ) + { + wxLogLastError(_T("Header_GetItem(HDI_WIDTH)")); + return; + } + + if ( show ) + hdi.cxy = 80; // FIXME: we don't have the column width here any more + else + hdi.cxy = 0; + + if ( !Header_SetItem(GetHwnd(), idx, &hdi) ) + { + wxLogLastError(_T("Header_SetItem(HDI_WIDTH)")); + return; + } +} + void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx, int sortOrder) { wxHDITEM hdi; @@ -170,7 +199,7 @@ void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx, int sortOrder) if ( !Header_GetItem(GetHwnd(), idx, &hdi) ) { - wxLogLastError(_T("Header_GetItem")); + wxLogLastError(_T("Header_GetItem(HDI_FORMAT)")); return; } @@ -181,7 +210,7 @@ void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx, int sortOrder) if ( !Header_SetItem(GetHwnd(), idx, &hdi) ) { - wxLogLastError(_T("Header_SetItem")); + wxLogLastError(_T("Header_SetItem(HDI_FORMAT)")); } } -- 2.45.2