extract (and expand and clean up and document) the header window implementation used inside the generic wxDataViewCtrl in a separate wxHeaderCtrl class which could be reused in (generic) wxListCtrl and, most importantly, wxGrid later

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-03 21:53:10 +00:00
parent 878770b854
commit 56873923f3
51 changed files with 3043 additions and 477 deletions

View File

@@ -1540,7 +1540,7 @@ enum wxDataViewColumnFlags
@library{wxadv}
@category{dvc}
*/
class wxDataViewColumn : public wxObject
class wxDataViewColumn : public wxHeaderColumn
{
public:
//@{
@@ -1561,16 +1561,6 @@ public:
int flags = wxDATAVIEW_COL_RESIZABLE);
//@}
/**
Destructor.
*/
virtual ~wxDataViewColumn();
/**
Returns the bitmap in the header of the column, if any.
*/
const wxBitmap& GetBitmap() const;
/**
Returns the index of the column of the model, which this
wxDataViewColumn is displaying.
@@ -1588,68 +1578,6 @@ public:
@see wxDataViewRenderer.
*/
wxDataViewRenderer* GetRenderer() const;
/**
Returns @true if the column is reorderable.
*/
virtual bool IsReorderable() const;
/**
Returns @true if the column is sortable.
@see SetSortable()
*/
virtual bool IsSortable() const;
/**
Returns the width of the column.
*/
virtual int GetWidth() const;
/**
Returns @true, if the sort order is ascending.
@see SetSortOrder()
*/
virtual bool IsSortOrderAscending() const;
/**
Set the alignment of the column header.
*/
virtual void SetAlignment(wxAlignment align);
/**
Set the bitmap of the column header.
*/
virtual void SetBitmap(const wxBitmap& bitmap);
/**
Indicate wether the column can be reordered by the user using the mouse.
This is typically implemented visually by dragging the header button around.
*/
virtual void SetReorderable(bool reorderable);
/**
Indicate the sort order if the implementation of the wxDataViewCtrl supports
it, most commonly by showing a little arrow.
*/
virtual void SetSortOrder(bool ascending);
/**
Indicate that the column is sortable.
This does not show any sorting indicate yet, but it does make the column
header clickable. Call SetSortOrder() afterwards to actually make the sort
indicator appear.
If @a sortable is @false, the column header is no longer clickable and
the sort indicator (little arrow) will disappear.
*/
virtual void SetSortable(bool sortable);
/**
Set the title of the column header to @a title.
*/
virtual void SetTitle(const wxString& title);
};

336
interface/wx/headercol.h Normal file
View File

@@ -0,0 +1,336 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/headercol.h
// Purpose: interface of wxHeaderColumn
// Author: Vadim Zeitlin
// Created: 2008-12-01
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
/**
Special value used for column width meaning unspecified or default.
*/
enum { wxCOL_WIDTH_DEFAULT = -1 };
/**
Bit flags used as wxHeaderColumn flags.
*/
enum
{
/// Column can be resized (included in default flags).
wxCOL_RESIZABLE = 1,
/// Column can be clicked to toggle the sort order by its contents.
wxCOL_SORTABLE = 2,
/// Column can be dragged to change its order (included in default).
wxCOL_REORDERABLE = 4,
/// Column is not shown at all.
wxCOL_HIDDEN = 8,
/// Default flags for wxHeaderColumn ctor.
wxCOL_DEFAULT_FLAGS = wxCOL_RESIZABLE | wxCOL_REORDERABLE
};
/**
@class wxHeaderColumn
Represents a column header in controls displaying tabular data such as
wxHeaderCtrl, wxDataViewCtrl or wxGrid.
@library{wxcore}
@category{ctrl}
@see wxHeaderCtrl
*/
class wxHeaderColumn
{
public:
//@{
/**
Constructor for a column header.
The first constructor creates a header showing the given text @a title
while the second one creates one showing the specified @a bitmap image.
*/
wxHeaderColumn(const wxString& title,
int width = wxCOL_WIDTH_DEFAULT,
wxAlignment align = wxALIGN_NOT,
int flags = wxCOL_DEFAULT_FLAGS);
wxHeaderColumn(const wxBitmap &bitmap,
int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxCOL_DEFAULT_FLAGS);
//@}
/**
Set the text to display in the column header.
*/
virtual void SetTitle(const wxString& title);
/**
Get the text shown in the column header.
*/
virtual wxString GetTitle() const;
/**
Set the bitmap to be displayed in the column header.
Notice that the bitmaps displayed in different columns of the same
control must all be of the same size.
*/
virtual void SetBitmap(const wxBitmap& bitmap);
/**
Returns the bitmap in the header of the column, if any.
If the column has no associated bitmap, wxNullBitmap is returned.
*/
virtual wxBitmap GetBitmap() const; \
/**
Set the column width.
@param width
The column width in pixels or the special wxCOL_WIDTH_DEFAULT value
meaning to use default width.
*/
virtual void SetWidth(int width);
/**
Returns the current width of the column.
@return
Width of the column in pixels, never wxCOL_WIDTH_DEFAULT.
*/
virtual int GetWidth() const;
/**
Set the minimal column width.
This method can be used with resizeable columns (i.e. those for which
wxCOL_RESIZABLE flag is set in GetFlags() or, alternatively,
IsResizeable() returns @true) to prevent the user from making them
narrower than the given width.
@param minWidth
The minimal column width in pixels, may be 0 to remove any
previously set restrictions.
*/
virtual void SetMinWidth(int minWidth);
/**
Return the minimal column width.
@return
The value previously set by SetMinWidth() or 0 by default.
*/
virtual int GetMinWidth() const;
/**
Set the alignment of the column header.
@param align
The text alignment in horizontal direction only or wxALIGN_NOT to
use the default alignment, The possible values here are
wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT with
wxALIGN_CENTRE_HORIZONTAL being also supported as synonym for
wxALIGN_CENTRE for consistency (but notice that GetAlignment()
never returns it).
*/
virtual void SetAlignment(wxAlignment align);
/**
Returns the current column alignment.
@return
One of wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT.
*/
virtual wxAlignment GetAlignment() const;
// not documented because I'm not sure if it should be in the public API at
// all
#if 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 data);
virtual wxUIntPtr GetClientData() const;
#endif
/**
Set the column flags.
This method allows to set all flags at once, see also generic
ChangeFlag(), SetFlag(), ClearFlag() and ToggleFlag() methods below as
well as specific SetResizeable(), SetSortable(), SetReorderable() and
SetHidden() ones.
@param flags
Combination of wxCOL_RESIZABLE, wxCOL_SORTABLE, wxCOL_REORDERABLE
and wxCOL_HIDDEN bit flags.
*/
virtual void SetFlags(int flags);
/**
Set or clear the given flag.
@param flag
The flag to set or clear.
@param set
If @true, set the flag, i.e. equivalent to calling SetFlag(),
otherwise clear it, as ClearFlag().
@see SetFlags()
*/
void ChangeFlag(int flag, bool set);
/**
Set the specified flag for the column.
@see SetFlags()
*/
void SetFlag(int flag);
/**
Clear the specified flag for the column.
@see SetFlags()
*/
void ClearFlag(int flag);
/**
Toggle the specified flag for the column.
If the flag is currently set, equivalent to ClearFlag(), otherwise --
to SetFlag().
@see SetFlags()
*/
void ToggleFlag(int flag);
/**
Get the column flags.
This method retrieves all the flags at once, you can also use HasFlag()
to test for any individual flag or IsResizeable(), IsSortable(),
IsReorderable() and IsHidden() to test for particular flags.
@see SetFlags()
*/
virtual int GetFlags() const;
/**
Return @true if the specified flag is currently set for this column.
*/
bool HasFlag(int flag) const;
/**
Call this to enable or disable interactive resizing of the column by
the user.
By default, the columns are resizeable.
Equivalent to ChangeFlag(wxCOL_RESIZABLE, resizeable).
*/
virtual void SetResizeable(bool resizeable);
/**
Return true if the column can be resized by the user.
Equivalent to HasFlag(wxCOL_RESIZABLE).
*/
virtual bool IsResizeable() const;
/**
Allow clicking the column to sort the control contents by the field in
this column.
By default, the columns are not sortable so you need to explicitly call
this function to allow sorting by the field corresponding to this
column.
Equivalent to ChangeFlag(wxCOL_SORTABLE, sortable).
*/
virtual void SetSortable(bool sortable);
/**
Returns @true if the column can be clicked by user to sort the control
contents by the field in this column.
This corresponds to wxCOL_SORTABLE flag which is off by default.
@see SetSortable()
*/
virtual bool IsSortable() const;
/**
Allow changing the column order by dragging it.
Equivalent to ChangeFlag(wxCOL_REORDERABLE, reorderable).
*/
virtual void SetReorderable(bool reorderable);
/**
Returns @true if the column can be dragged by user to change its order.
This corresponds to wxCOL_REORDERABLE flag which is on by default.
@see SetReorderable()
*/
virtual bool IsReorderable() const;
/**
Hide or show the column.
By default all columns are shown but some of them can be completely
hidden from view by calling this function.
Equivalent to ChangeFlag(wxCOL_HIDDEN, hidden).
*/
virtual void SetHidden(bool hidden);
/**
Returns @true if the column is currently hidden.
This corresponds to wxCOL_HIDDEN flag which is off by default.
*/
virtual bool IsHidden() const;
/**
Sets the sort order for this column.
This only makes sense for sortable columns and is only taken into
account by the control in which this column is inserted, this function
just stores the sort order in the wxHeaderColumn object.
@param ascending
If @true, sort in ascending order, otherwise in descending order.
*/
virtual void SetSortOrder(bool ascending);
/**
Inverses the sort order.
This function is typically called when the user clicks on a column used
for sorting to change sort order from ascending to descending or vice
versa.
@see SetSortOrder(), IsSortOrderAscending()
*/
void ToggleSortOrder();
/**
Returns @true, if the sort order is ascending.
@see SetSortOrder()
*/
virtual bool IsSortOrderAscending() const;
};

187
interface/wx/headerctrl.h Normal file
View File

@@ -0,0 +1,187 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/headerctrl.h
// Purpose: interface of wxHeaderCtrl
// Author: Vadim Zeitlin
// Created: 2008-12-01
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
/**
@class wxHeaderCtrl
wxHeaderCtrl is the control containing the column headings which is usually
used for display of tabular data.
It is used as part of wxGrid and (will be used in the near future) in
in wxDataViewCtrl and report view of wxListCtrl but can be also used
independently.
In addition to labeling the columns, the control has the following
features:
- Column reordering support, either by explicitly configuring the
columns order and calling SetColumnsOrder() or by dragging the
columns interactively (if enabled).
- Display of the icons in the header: this is often used to display a
sort or reverse sort indicator when the column header is clicked.
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.
This control is implemented using the native header control under MSW
systems and a generic implementation elsewhere.
@beginStyleTable
@style{wxHD_DRAGDROP}
If this style is specified (it is by default), the user can reorder
the control columns by dragging them.
@style{wxHD_DEFAULT_STYLE}
Symbolic name for the default control style, currently equal to @c
wxHD_DRAGDROP.
@endStyleTable
@beginEventTable{wxHeaderEvent}
@event{EVT_HEADER_CLICK(id, func)}
A column heading was clicked.
@endEventTable
@library{wxcore}
@category{ctrl}
@see wxGrid, wxListCtrl, wxDataViewCtrl
@section headerctrl_improvements Future Improvements
Some features are supported by the native MSW control and so could be
easily implemented in this version of wxHeaderCtrl but need to be
implemented in the generic version as well to be really useful. Please let
us know if you need or, better, plan to work on implementing, any of them:
- Displaying bitmaps instead of or together with the text
- Custom drawn headers
- Filters associated with a column.
*/
class wxHeaderCtrl
{
public:
/**
Default constructor not creating the underlying window.
You must use Create() after creating the object using this constructor.
*/
wxHeaderCtrl();
/**
Constructor creating the window.
Please see Create() for the parameters documentation.
*/
wxHeaderCtrl(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxHeaderCtrlNameStr);
/**
Create the header control window.
@param parent
The parent window. The header control should be typically
positioned along the top edge of this window.
@param winid
Id of the control or @c wxID_ANY if you don't care.
@param pos
The initial position of the control.
@param size
The initial size of the control (usually not very useful as this
control will typically be resized to have the same width as the
associated data display control).
@param style
The control style, @c wxHD_DEFAULT_STYLE by default. Notice that
the default style allows the user to reorder the columns by
dragging them and you need to explicitly turn this feature off by
using @code wxHD_DEFAULT_STYLE & ~wxHD_DRAGDROP @endcode if this is
undesirable.
@param name
The name of the control.
*/
bool Create(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxHeaderCtrlNameStr);
/**
Return the number of columns in the control.
@see IsEmpty()
*/
unsigned int GetColumnCount() const;
/**
Return whether the control has any columns.
@see GetColumnCount()
*/
bool IsEmpty() const;
/**
Insert the column at the given position.
@param col
The column to insert. Notice that because of the existence of
implicit conversion from wxString to wxHeaderColumn a string
can be passed directly here.
@param idx
The position of the new column, from 0 to GetColumnCount(). Using
GetColumnCount() means to append the column to the end.
@see AppendColumn()
*/
void InsertColumn(const wxHeaderColumn& col, unsigned int idx);
/**
Append the column to the end of the control.
@see InsertColumn()
*/
void AppendColumn(const wxHeaderColumn& col);
/**
Delete the column at the given position.
@see InsertColumn(), AppendColumn()
*/
void DeleteColumn(unsigned int idx);
/**
Update the column sort indicator.
The sort indicator, if shown, is typically an arrow pointing upwards or
downwards depending on whether the control contents is sorted in
ascending or descending order.
@param idx
The column to set the sort indicator for.
@param sortOrder
If @true or @false show the sort indicator corresponding to
ascending or descending sort order respectively, if @c -1 remove
the currently shown sort indicator.
*/
virtual void ShowSortIndicator(unsigned int idx, int sortOrder);
/**
Remove the sort indicator from the given column.
This is the same as calling ShowSortIndicator() with @c -1 argument.
@param idx
The column to remove sort indicator for.
*/
void RemoveSortIndicator(unsigned int idx);
};