- Rewrite wxHeaderCtrl to be virtual-like: even if we don't need an infinite

number of columns in it, it turns out that getting column information from
  the associated control is much easier than copying it into the control.
- Provide wxHeaderCtrlSimple derived class which can be used easily if
  callback approach of wxHeaderCtrl is not needed.
- Because of wxHeaderCtrl virtualization, port-specific implementations of
  wxHeaderColumn are not needed any more and were removed.
- Use wxHeaderCtrl in the generic wxDataViewCtrl: this means that column
  events are broken right now in it as they haven't been implemented by
  wxHeaderCtrl yet, this will be fixed a.s.a.p.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-07 14:47:55 +00:00
parent bc0289bf5e
commit e2bfe6731e
30 changed files with 725 additions and 2034 deletions

View File

@@ -508,26 +508,25 @@ enum wxDataViewColumnFlags
wxDATAVIEW_COL_HIDDEN = wxCOL_HIDDEN
};
class WXDLLIMPEXP_ADV wxDataViewColumnBase : public
// native implementations of wxDataViewCtrl have their own implementations of
// wxDataViewColumnBase and so they need to only inherit from
// wxHeaderColumnBase to provide the same interface as the generic port which
// uses the platform native (if any) wxHeaderColumn
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
wxHeaderColumn
#else
wxHeaderColumnBase
#endif
class WXDLLIMPEXP_ADV wxDataViewColumnBase : public wxHeaderColumnBase
{
public:
wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE );
wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE );
// ctor for the text columns: takes ownership of renderer
wxDataViewColumnBase(wxDataViewRenderer *renderer,
unsigned int model_column)
{
Init(renderer, model_column);
}
// ctor for the bitmap columns
wxDataViewColumnBase(const wxBitmap& bitmap,
wxDataViewRenderer *renderer,
unsigned int model_column)
: m_bitmap(bitmap)
{
Init(renderer, model_column);
}
virtual ~wxDataViewColumnBase();
// setters:
@@ -539,23 +538,20 @@ public:
wxDataViewCtrl *GetOwner() const { return m_owner; }
wxDataViewRenderer* GetRenderer() const { return m_renderer; }
#ifndef wxHAS_GENERIC_DATAVIEWCTRL
// implement some of base class pure virtuals (the rest is port-dependent
// and done differently in generic and native versions)
virtual void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
virtual wxBitmap GetBitmap() const { return m_bitmap; }
#endif // !wxHAS_GENERIC_DATAVIEWCTRL
protected:
wxDataViewRenderer *m_renderer;
int m_model_column;
#ifndef wxHAS_GENERIC_DATAVIEWCTRL
wxBitmap m_bitmap;
#endif // !wxHAS_GENERIC_DATAVIEWCTRL
wxDataViewCtrl *m_owner;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
private:
// common part of all ctors
void Init(wxDataViewRenderer *renderer, unsigned int model_column);
};
// ---------------------------------------------------------

View File

@@ -33,7 +33,7 @@ class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
{
public:
wxDataViewRenderer( const wxString &varianttype,
wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewRenderer();
@@ -51,32 +51,32 @@ public:
virtual bool Activate( wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
virtual bool LeftClick( wxPoint WXUNUSED(cursor),
wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
virtual bool RightClick( wxPoint WXUNUSED(cursor),
wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
virtual bool StartDrag( wxPoint WXUNUSED(cursor),
wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
// Create DC on request
virtual wxDC *GetDC();
void SetHasAttr( bool set ) { m_hasAttr = set; }
void SetAttr( const wxDataViewItemAttr &attr ) { m_attr = attr; }
bool GetWantsAttr() { return m_wantsAttr; }
@@ -88,7 +88,7 @@ private:
wxDC *m_dc;
int m_align;
wxDataViewCellMode m_mode;
protected:
bool m_wantsAttr;
bool m_hasAttr;
@@ -137,7 +137,7 @@ public:
virtual bool HasEditorCtrl();
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
protected:
wxString m_text;
@@ -157,7 +157,7 @@ public:
int align = wxDVR_DEFAULT_ALIGNMENT );
bool Render( wxRect cell, wxDC *dc, int state );
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
};
@@ -202,7 +202,7 @@ public:
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
unsigned int col );
wxSize GetSize() const;
@@ -239,32 +239,32 @@ private:
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewIconTextRenderer();
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool HasEditorCtrl() { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
private:
wxDataViewIconText m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
@@ -302,34 +302,79 @@ protected:
class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
{
public:
wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE );
wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE );
wxDataViewColumn(const wxString& title,
wxDataViewRenderer *renderer,
unsigned int model_column,
int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE)
: wxDataViewColumnBase(renderer, model_column),
m_title(title)
{
Init(width, align, flags);
}
// override some methods to notify the owner about changes
virtual void SetFlags(int flags);
virtual void SetWidth(int width);
virtual void SetSortOrder(bool ascending);
wxDataViewColumn(const wxBitmap& bitmap,
wxDataViewRenderer *renderer,
unsigned int model_column,
int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE)
: wxDataViewColumnBase(bitmap, renderer, model_column)
{
Init(width, align, flags);
}
// override this one to return our default width for columns whose width
// was not explicitly set
virtual int GetWidth() const;
// implement wxHeaderColumnBase methods
virtual void SetTitle(const wxString& title) { m_title = title; }
virtual wxString GetTitle() const { return m_title; }
virtual void SetWidth(int width) { m_width = width; }
virtual int GetWidth() const { return m_width; }
virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
virtual int GetMinWidth() const { return m_minWidth; }
virtual void SetAlignment(wxAlignment align) { m_align = align; }
virtual wxAlignment GetAlignment() const { return m_align; }
virtual void SetFlags(int flags) { m_flags = flags; }
virtual int GetFlags() const { return m_flags; }
virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
virtual bool IsSortKey() const { return m_sort; }
virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
virtual bool IsSortOrderAscending() const { return m_sortAscending; }
private:
// common part of all ctors
void Init(int width, wxAlignment align, int flags)
{
m_width = width == wxCOL_WIDTH_DEFAULT ? wxDVC_DEFAULT_WIDTH : width;
m_minWidth = 0;
m_align = align;
m_flags = flags;
m_sort = false;
m_sortAscending = true;
}
// like SetWidth() but does not ask the header window of the
// wxDataViewCtrl to reflect the width-change.
void SetInternalWidth(int width);
wxString m_title;
int m_width,
m_minWidth;
wxAlignment m_align;
int m_flags;
bool m_sort,
m_sortAscending;
friend class wxDataViewHeaderWindowBase;
friend class wxDataViewHeaderWindow;
friend class wxDataViewHeaderWindowMSW;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
};
// ---------------------------------------------------------
@@ -373,7 +418,7 @@ public:
const wxValidator& validator = wxDefaultValidator );
virtual bool AssociateModel( wxDataViewModel *model );
virtual bool AppendColumn( wxDataViewColumn *col );
virtual bool PrependColumn( wxDataViewColumn *col );
virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
@@ -388,7 +433,7 @@ public:
virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
virtual wxDataViewColumn *GetSortingColumn() const;
virtual wxDataViewItem GetSelection() const;
virtual int GetSelections( wxDataViewItemArray & sel ) const;
virtual void SetSelections( const wxDataViewItemArray & sel );
@@ -406,11 +451,11 @@ public:
virtual void Expand( const wxDataViewItem & item );
virtual void Collapse( const wxDataViewItem & item );
virtual void SetFocus();
protected:
virtual int GetSelections( wxArrayInt & sel ) const;
virtual int GetSelections( wxArrayInt & sel ) const;
virtual void SetSelections( const wxArrayInt & sel );
virtual void Select( int row );
virtual void Unselect( int row );

View File

@@ -1,85 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/headercolg.h
// Purpose: Generic wxHeaderColumn implementation
// Author: Vadim Zeitlin
// Created: 2008-12-04
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_HEADERCOLG_H_
#define _WX_GENERIC_HEADERCOLG_H_
// ----------------------------------------------------------------------------
// wxHeaderColumn: trivial generic implementation of wxHeaderColumnBase
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxHeaderColumn : public wxHeaderColumnBase
{
public:
// ctors and dtor
wxHeaderColumn(const wxString& title,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_NOT,
int flags = wxCOL_DEFAULT_FLAGS)
: m_title(title),
m_width(width),
m_align(align),
m_flags(flags)
{
Init();
}
wxHeaderColumn(const wxBitmap& bitmap,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_CENTER,
int flags = wxCOL_DEFAULT_FLAGS)
: m_bitmap(bitmap),
m_width(width),
m_align(align),
m_flags(flags)
{
Init();
}
// implement base class pure virtuals
virtual void SetTitle(const wxString& title) { m_title = title; }
virtual wxString GetTitle() const { return m_title; }
virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
wxBitmap GetBitmap() const { return m_bitmap; }
virtual void SetWidth(int width) { m_width = width; }
virtual int GetWidth() const { return m_width; }
virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
virtual int GetMinWidth() const { return m_minWidth; }
virtual void SetAlignment(wxAlignment align) { m_align = align; }
virtual wxAlignment GetAlignment() const { return m_align; }
virtual void SetFlags(int flags) { m_flags = flags; }
virtual int GetFlags() const { return m_flags; }
virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
virtual bool IsSortOrderAscending() const { return m_sortAscending; }
private:
// common part of all ctors
void Init()
{
m_minWidth = 0;
m_sortAscending = true;
}
wxString m_title;
wxBitmap m_bitmap;
int m_width,
m_minWidth;
wxAlignment m_align;
int m_flags;
bool m_sortAscending;
};
#endif // _WX_GENERIC_HEADERCOLG_H_

View File

@@ -75,19 +75,6 @@ private:
// refresh all the controls starting from (and including) the given one
void RefreshColsAfter(unsigned int idx);
// all our current columns
typedef wxVector<wxHeaderColumn> Columns;
Columns m_cols;
// sorting indicators for the columns: our API is such that it allows using
// multiple columns for sorting, and even if this is not used anywhere in
// practice right now, still support this
//
// the values are interpreted in the same way as ShowSortIndicator()
// sortOrder parameter: true/false for ascending/descending sort if the
// corresponding column is used for sorting or -1 otherwise
wxVector<int> m_sortOrders;
// index of the column under mouse or -1 if none
unsigned int m_hover;

View File

@@ -300,8 +300,6 @@ public:
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE );
virtual ~wxDataViewColumn();
// setters:
@@ -314,6 +312,7 @@ public:
virtual void SetSortable( bool sortable );
virtual void SetSortOrder( bool ascending );
virtual void SetAsSortKey(bool sort = true);
virtual void SetResizeable( bool resizeable );
virtual void SetHidden( bool hidden );
@@ -332,6 +331,8 @@ public:
virtual bool IsSortable() const;
virtual bool IsSortOrderAscending() const;
virtual bool IsSortKey() const = 0;
virtual bool IsResizeable() const;
virtual bool IsHidden() const;

View File

@@ -47,7 +47,7 @@ enum
// wxListCtrl, wxDataViewCtrl or wxGrid
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxHeaderColumnBase : public wxObject
class WXDLLIMPEXP_CORE wxHeaderColumnBase
{
public:
// ctors and dtor
@@ -93,14 +93,6 @@ public:
virtual void SetAlignment(wxAlignment align) = 0;
virtual wxAlignment GetAlignment() const = 0;
// arbitrary client data associated with the column (currently only
// implemented in MSW because it is used in MSW wxDataViewCtrl
// implementation)
virtual void SetClientData(wxUIntPtr WXUNUSED(data))
{ wxFAIL_MSG("not implemented"); }
virtual wxUIntPtr GetClientData() const
{ return 0; }
// flags manipulations:
// --------------------
@@ -151,8 +143,19 @@ public:
bool IsShown() const
{ return !IsHidden(); }
// sorting
// -------
// set this column as the one used to sort the control
virtual void SetAsSortKey(bool sort = true) = 0;
void UnsetAsSortKey() { SetAsSortKey(false); }
// return true if the column is used for sorting
virtual bool IsSortKey() const = 0;
// for sortable columns indicate whether we should sort in ascending or
// descending order
// descending order (this should only be taken into account if IsSortKey())
virtual void SetSortOrder(bool ascending) = 0;
void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
virtual bool IsSortOrderAscending() const = 0;
@@ -163,12 +166,80 @@ protected:
int GetFromIndividualFlags() const;
};
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/headercol.h"
#else
#define wxHAS_GENERIC_HEADERCOL
#include "wx/generic/headercolg.h"
#endif
// ----------------------------------------------------------------------------
// wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumnBase
// ----------------------------------------------------------------------------
class wxHeaderColumnSimple : public wxHeaderColumnBase
{
public:
// ctors and dtor
wxHeaderColumnSimple(const wxString& title,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_NOT,
int flags = wxCOL_DEFAULT_FLAGS)
: m_title(title),
m_width(width),
m_align(align),
m_flags(flags)
{
Init();
}
wxHeaderColumnSimple(const wxBitmap& bitmap,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_CENTER,
int flags = wxCOL_DEFAULT_FLAGS)
: m_bitmap(bitmap),
m_width(width),
m_align(align),
m_flags(flags)
{
Init();
}
// implement base class pure virtuals
virtual void SetTitle(const wxString& title) { m_title = title; }
virtual wxString GetTitle() const { return m_title; }
virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
wxBitmap GetBitmap() const { return m_bitmap; }
virtual void SetWidth(int width) { m_width = width; }
virtual int GetWidth() const { return m_width; }
virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
virtual int GetMinWidth() const { return m_minWidth; }
virtual void SetAlignment(wxAlignment align) { m_align = align; }
virtual wxAlignment GetAlignment() const { return m_align; }
virtual void SetFlags(int flags) { m_flags = flags; }
virtual int GetFlags() const { return m_flags; }
virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
virtual bool IsSortKey() const { return m_sort; }
virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
virtual bool IsSortOrderAscending() const { return m_sortAscending; }
private:
// common part of all ctors
void Init()
{
m_minWidth = 0;
m_sort = false;
m_sortAscending = true;
}
wxString m_title;
wxBitmap m_bitmap;
int m_width,
m_minWidth;
wxAlignment m_align;
int m_flags;
bool m_sort,
m_sortAscending;
};
#endif // _WX_HEADERCOL_H_

View File

@@ -13,6 +13,8 @@
#include "wx/control.h"
#include "wx/vector.h"
#include "wx/headercol.h"
// notice that the classes in this header are defined in the core library even
@@ -34,8 +36,6 @@ enum
extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[];
class WXDLLIMPEXP_FWD_CORE wxHeaderColumn;
// ----------------------------------------------------------------------------
// wxHeaderCtrlBase defines the interface of a header control
// ----------------------------------------------------------------------------
@@ -51,29 +51,111 @@ public:
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
long style = wxHD_DEFAULT_STYLE,
const wxString& name = wxHeaderCtrlNameStr);
bool Create(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
long style = wxHD_DEFAULT_STYLE,
const wxString& name = wxHeaderCtrlNameStr);
*/
// column-related methods
// ----------------------
// set the number of columns in the control
//
// this also calls UpdateColumn() for all columns
void SetColumnCount(unsigned int count) { DoSetCount(count); }
// return the number of columns in the control as set by SetColumnCount()
unsigned int GetColumnCount() const { return DoGetCount(); }
// return whether the control has any columns
bool IsEmpty() const { return DoGetCount() == 0; }
// update the column with the given index
void UpdateColumn(unsigned int idx)
{
wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
DoUpdate(idx);
}
// implementation only from now on
// -------------------------------
// the user doesn't need to TAB to this control
virtual bool AcceptsFocusFromKeyboard() const { return false; }
// this method is only overridden in order to synchronize the control with
// the main window when it is scrolled, the derived class must implement
// DoScrollHorz()
virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
protected:
// this method must be implemented by the derived classes to return the
// information for the given column
virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0;
private:
// methods implementing our public API and defined in platform-specific
// implementations
virtual void DoSetCount(unsigned int count) = 0;
virtual unsigned int DoGetCount() const = 0;
virtual void DoUpdate(unsigned int idx) = 0;
virtual void DoScrollHorz(int dx) = 0;
// this window doesn't look nice with the border so don't use it by default
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
};
// ----------------------------------------------------------------------------
// wxHeaderCtrl: port-specific header control implementation, notice that this
// is still an ABC which is meant to be used as part of another
// control, see wxHeaderCtrlSimple for a standalone version
// ----------------------------------------------------------------------------
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/headerctrl.h"
#else
#define wxHAS_GENERIC_HEADERCTRL
#include "wx/generic/headerctrlg.h"
#endif // platform
// ----------------------------------------------------------------------------
// wxHeaderCtrlSimple: concrete header control which can be used standalone
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxHeaderCtrlSimple : public wxHeaderCtrl
{
public:
// control creation
// ----------------
wxHeaderCtrlSimple() { Init(); }
wxHeaderCtrlSimple(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHD_DEFAULT_STYLE,
const wxString& name = wxHeaderCtrlNameStr)
{
Init();
Create(parent, winid, pos, size, style, name);
}
// managing the columns
// --------------------
// return the number of columns in the control
unsigned int GetColumnCount() const { return DoGetCount(); }
// return whether the control has any columns
bool IsEmpty() const { return GetColumnCount() == 0; }
// insert the column at the given position, using GetColumnCount() as
// position appends it at the end
void InsertColumn(const wxHeaderColumn& col, unsigned int idx)
void InsertColumn(const wxHeaderColumnSimple& col, unsigned int idx)
{
wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" );
@@ -81,7 +163,7 @@ public:
}
// append the column to the end of the control
void AppendColumn(const wxHeaderColumn& col)
void AppendColumn(const wxHeaderColumnSimple& col)
{
DoInsert(col, GetColumnCount());
}
@@ -115,54 +197,43 @@ public:
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
void ShowSortIndicator(unsigned int idx, int sortOrder)
// indicate that the column is used for sorting
void ShowSortIndicator(unsigned int idx, bool ascending = true)
{
wxCHECK_RET( sortOrder == 0 || sortOrder == 1 || sortOrder == -1,
"invalid sort order value" );
wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
DoShowSortIndicator(idx, sortOrder);
DoShowSortIndicator(idx, ascending);
}
// remove the sort indicator from the given column
void RemoveSortIndicator(unsigned int idx)
{
DoShowSortIndicator(idx, -1);
}
// remove the sort indicator completely
void RemoveSortIndicator();
// implementation only from now on
// -------------------------------
// the user doesn't need to TAB to this control
virtual bool AcceptsFocusFromKeyboard() const { return false; }
// this method is only overridden in order to synchronize the control with
// the main window when it is scrolled, the derived class must implement
// DoScrollHorz()
virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
protected:
virtual wxHeaderColumnBase& GetColumn(unsigned int idx);
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;
virtual void DoScrollHorz(int dx) = 0;
// functions implementing our public API
void DoInsert(const wxHeaderColumnSimple& col, unsigned int idx);
void DoDelete(unsigned int idx);
void DoShowColumn(unsigned int idx, bool show);
void DoShowSortIndicator(unsigned int idx, bool ascending);
// this window doesn't look nice with the border so don't use it by default
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
// common part of all ctors
void Init();
// bring the column count in sync with the number of columns we store
void UpdateColumnCount() { SetColumnCount(m_cols.size()); }
// all our current columns
typedef wxVector<wxHeaderColumnSimple> Columns;
Columns m_cols;
// the column currently used for sorting or -1 if none
unsigned int m_sortKey;
DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple)
};
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/headerctrl.h"
#else
#define wxHAS_GENERIC_HEADERCTRL
#include "wx/generic/headerctrlg.h"
#endif // platform
#endif // _WX_HEADERCTRL_H_

View File

@@ -1,77 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/headercol.h
// Purpose: wxHeaderColumn implementation for MSW
// Author: Vadim Zeitlin
// Created: 2008-12-02
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_HEADERCOL_H_
#define _WX_MSW_HEADERCOL_H_
struct wxHDITEM;
// ----------------------------------------------------------------------------
// wxHeaderColumn
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxHeaderColumn : public wxHeaderColumnBase
{
public:
// ctors and dtor
wxHeaderColumn(const wxString& title,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_NOT,
int flags = wxCOL_DEFAULT_FLAGS);
wxHeaderColumn(const wxBitmap &bitmap,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_CENTER,
int flags = wxCOL_DEFAULT_FLAGS);
virtual ~wxHeaderColumn();
// implement base class pure virtuals
virtual void SetTitle(const wxString& title);
virtual wxString GetTitle() const;
virtual void SetBitmap(const wxBitmap& bitmap);
wxBitmap GetBitmap() const;
virtual void SetWidth(int width);
virtual int GetWidth() const;
virtual void SetMinWidth(int minWidth);
virtual int GetMinWidth() const;
virtual void SetAlignment(wxAlignment align);
virtual wxAlignment GetAlignment() const;
virtual void SetClientData(wxUIntPtr data);
virtual wxUIntPtr GetClientData() const;
virtual void SetFlags(int flags);
virtual int GetFlags() const;
virtual void SetSortOrder(bool ascending);
virtual bool IsSortOrderAscending() const;
// MSW-specific implementation helpers
wxHDITEM& GetHDI();
const wxHDITEM& GetHDI() const
{
return const_cast<wxHeaderColumn *>(this)->GetHDI();
}
private:
// initialize m_impl
void Init();
struct wxMSWHeaderColumnImpl *m_impl;
};
#endif // _WX_MSW_HEADERCOL_H_

View File

@@ -49,11 +49,10 @@ public:
private:
// implement base class pure virtuals
virtual void DoSetCount(unsigned int count);
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);
virtual void DoUpdate(unsigned int idx);
virtual void DoScrollHorz(int dx);
// override wxWindow methods which must be implemented by a new control
@@ -65,6 +64,13 @@ private:
// common part of all ctors
void Init();
// wrapper around Header_{Set,Insert}Item(): either appends the item to the
// end or modifies the existing item by copying information from
// GetColumn(idx) to it
enum Operation { Set, Insert };
void DoSetOrInsertItem(Operation oper, unsigned int idx);
// the image list: initially NULL, created on demand
wxImageList *m_imageList;