2008-12-03 16:53:10 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/headercol.h
|
|
|
|
// Purpose: declaration of wxHeaderColumn class
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2008-12-02
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_HEADERCOL_H_
|
|
|
|
#define _WX_HEADERCOL_H_
|
|
|
|
|
|
|
|
#include "wx/bitmap.h"
|
|
|
|
|
2009-01-10 19:57:08 -05:00
|
|
|
#if wxUSE_HEADERCTRL
|
|
|
|
|
2008-12-03 16:53:10 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// special value for column width meaning unspecified/default
|
2010-10-30 11:57:41 -04:00
|
|
|
wxCOL_WIDTH_DEFAULT = -1,
|
|
|
|
|
|
|
|
// size the column automatically to fit all values
|
|
|
|
wxCOL_WIDTH_AUTOSIZE = -2
|
2008-12-03 16:53:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// bit masks for the various column attributes
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2008-12-11 08:05:48 -05:00
|
|
|
// wxHeaderColumn: interface for a column in a header of controls such as
|
|
|
|
// wxListCtrl, wxDataViewCtrl or wxGrid
|
2008-12-03 16:53:10 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxHeaderColumn
|
2008-12-03 16:53:10 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors and dtor
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
Derived classes must provide ctors with the following signatures
|
|
|
|
(notice that they shouldn't be explicit to allow passing strings/bitmaps
|
|
|
|
directly to methods such wxHeaderCtrl::AppendColumn()):
|
|
|
|
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);
|
|
|
|
*/
|
|
|
|
|
2008-12-07 11:03:50 -05:00
|
|
|
// virtual dtor for the base class to avoid gcc warnings even though we
|
|
|
|
// don't normally delete the objects of this class via a pointer to
|
2008-12-11 08:05:48 -05:00
|
|
|
// wxHeaderColumn so it's not necessary, strictly speaking
|
|
|
|
virtual ~wxHeaderColumn() { }
|
2008-12-07 11:03:50 -05:00
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
// getters for various attributes
|
|
|
|
// ------------------------------
|
2008-12-03 16:53:10 -05:00
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
// notice that wxHeaderColumn only provides getters as this is all the
|
|
|
|
// wxHeaderCtrl needs, various derived class must also provide some way to
|
|
|
|
// change these attributes but this can be done either at the column level
|
|
|
|
// (in which case they should inherit from wxSettableHeaderColumn) or via
|
|
|
|
// the methods of the main control in which case you don't need setters in
|
|
|
|
// the column class at all
|
2008-12-03 16:53:10 -05:00
|
|
|
|
|
|
|
// title is the string shown for this column
|
|
|
|
virtual wxString GetTitle() const = 0;
|
|
|
|
|
|
|
|
// bitmap shown (instead of text) in the column header
|
|
|
|
virtual wxBitmap GetBitmap() const = 0; \
|
|
|
|
|
|
|
|
// width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
|
|
|
|
// unspecified/default
|
|
|
|
virtual int GetWidth() const = 0;
|
|
|
|
|
|
|
|
// minimal width can be set for resizeable columns to forbid resizing them
|
|
|
|
// below the specified size (set to 0 to remove)
|
|
|
|
virtual int GetMinWidth() const = 0;
|
|
|
|
|
|
|
|
// alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
|
|
|
|
virtual wxAlignment GetAlignment() const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// flags manipulations:
|
|
|
|
// --------------------
|
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
// notice that while we make GetFlags() pure virtual here and implement the
|
|
|
|
// individual flags access in terms of it, for some derived classes it is
|
|
|
|
// more natural to implement access to each flag individually, in which
|
|
|
|
// case they can use our GetFromIndividualFlags() helper below to implement
|
|
|
|
// GetFlags()
|
2008-12-03 16:53:10 -05:00
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
// retrieve all column flags at once: combination of wxCOL_XXX values above
|
2008-12-03 16:53:10 -05:00
|
|
|
virtual int GetFlags() const = 0;
|
|
|
|
|
|
|
|
bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
|
|
|
|
|
|
|
|
|
|
|
|
// wxCOL_RESIZABLE
|
|
|
|
virtual bool IsResizeable() const
|
|
|
|
{ return HasFlag(wxCOL_RESIZABLE); }
|
|
|
|
|
|
|
|
// wxCOL_SORTABLE
|
|
|
|
virtual bool IsSortable() const
|
|
|
|
{ return HasFlag(wxCOL_SORTABLE); }
|
|
|
|
|
|
|
|
// wxCOL_REORDERABLE
|
|
|
|
virtual bool IsReorderable() const
|
|
|
|
{ return HasFlag(wxCOL_REORDERABLE); }
|
|
|
|
|
|
|
|
// wxCOL_HIDDEN
|
|
|
|
virtual bool IsHidden() const
|
|
|
|
{ return HasFlag(wxCOL_HIDDEN); }
|
2008-12-05 16:49:34 -05:00
|
|
|
bool IsShown() const
|
|
|
|
{ return !IsHidden(); }
|
2008-12-03 16:53:10 -05:00
|
|
|
|
2008-12-07 09:47:55 -05:00
|
|
|
|
|
|
|
// sorting
|
|
|
|
// -------
|
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
// return true if the column is the one currently used for sorting
|
2008-12-07 09:47:55 -05:00
|
|
|
virtual bool IsSortKey() const = 0;
|
|
|
|
|
2008-12-03 16:53:10 -05:00
|
|
|
// for sortable columns indicate whether we should sort in ascending or
|
2008-12-07 09:47:55 -05:00
|
|
|
// descending order (this should only be taken into account if IsSortKey())
|
2008-12-11 08:05:48 -05:00
|
|
|
virtual bool IsSortOrderAscending() const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// helper for the class overriding IsXXX()
|
|
|
|
int GetFromIndividualFlags() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxSettableHeaderColumn: column which allows to change its fields too
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-12-11 08:27:03 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn
|
2008-12-11 08:05:48 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void SetTitle(const wxString& title) = 0;
|
|
|
|
virtual void SetBitmap(const wxBitmap& bitmap) = 0;
|
|
|
|
virtual void SetWidth(int width) = 0;
|
|
|
|
virtual void SetMinWidth(int minWidth) = 0;
|
|
|
|
virtual void SetAlignment(wxAlignment align) = 0;
|
|
|
|
|
|
|
|
// see comment for wxHeaderColumn::GetFlags() about the relationship
|
|
|
|
// between SetFlags() and Set{Sortable,Reorderable,...}
|
|
|
|
|
|
|
|
// change, set, clear, toggle or test for any individual flag
|
|
|
|
virtual void SetFlags(int flags) = 0;
|
|
|
|
void ChangeFlag(int flag, bool set);
|
|
|
|
void SetFlag(int flag);
|
|
|
|
void ClearFlag(int flag);
|
|
|
|
void ToggleFlag(int flag);
|
|
|
|
|
|
|
|
virtual void SetResizeable(bool resizeable)
|
|
|
|
{ ChangeFlag(wxCOL_RESIZABLE, resizeable); }
|
|
|
|
virtual void SetSortable(bool sortable)
|
|
|
|
{ ChangeFlag(wxCOL_SORTABLE, sortable); }
|
|
|
|
virtual void SetReorderable(bool reorderable)
|
|
|
|
{ ChangeFlag(wxCOL_REORDERABLE, reorderable); }
|
|
|
|
virtual void SetHidden(bool hidden)
|
|
|
|
{ ChangeFlag(wxCOL_HIDDEN, hidden); }
|
|
|
|
|
|
|
|
virtual void SetAsSortKey(bool sort = true) = 0;
|
|
|
|
void UnsetAsSortKey() { SetAsSortKey(false); }
|
|
|
|
|
2008-12-03 16:53:10 -05:00
|
|
|
virtual void SetSortOrder(bool ascending) = 0;
|
|
|
|
void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
|
|
|
|
|
|
|
|
protected:
|
2008-12-11 08:05:48 -05:00
|
|
|
// helper for the class overriding individual SetXXX() methods instead of
|
|
|
|
// overriding SetFlags()
|
2008-12-03 16:53:10 -05:00
|
|
|
void SetIndividualFlags(int flags);
|
|
|
|
};
|
|
|
|
|
2008-12-07 09:47:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-12-11 08:05:48 -05:00
|
|
|
// wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
|
2008-12-07 09:47:55 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-12-03 16:53:10 -05:00
|
|
|
|
2008-12-11 08:05:48 -05:00
|
|
|
class wxHeaderColumnSimple : public wxSettableHeaderColumn
|
2008-12-07 09:47:55 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
2009-01-10 19:57:08 -05:00
|
|
|
|
|
|
|
#endif // wxUSE_HEADERCTRL
|
|
|
|
|
2008-12-03 16:53:10 -05:00
|
|
|
#endif // _WX_HEADERCOL_H_
|
|
|
|
|