add Show/HideColumn() methods

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57132 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-05 21:50:30 +00:00
parent 78fd3d12bc
commit a000920547
4 changed files with 78 additions and 3 deletions

View File

@@ -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_

View File

@@ -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

View File

@@ -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.

View File

@@ -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)"));
}
}