generic implementation of wxHeaderCtrl API so far

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-05 22:44:54 +00:00
parent d8fc3398ac
commit b63f9a3330
5 changed files with 432 additions and 3 deletions

View File

@@ -0,0 +1,85 @@
///////////////////////////////////////////////////////////////////////////////
// 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

@@ -0,0 +1,103 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/headerctrlg.h
// Purpose: Generic wxHeaderCtrl implementation
// Author: Vadim Zeitlin
// Created: 2008-12-01
// RCS-ID: $Id$
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_HEADERCTRLG_H_
#define _WX_GENERIC_HEADERCTRLG_H_
#include "wx/event.h"
#include "wx/vector.h"
// ----------------------------------------------------------------------------
// wxHeaderCtrl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxHeaderCtrl : public wxHeaderCtrlBase
{
public:
wxHeaderCtrl()
{
Init();
}
wxHeaderCtrl(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHD_DEFAULT_STYLE,
const wxString& name = wxHeaderCtrlNameStr)
{
Init();
Create(parent, id, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHD_DEFAULT_STYLE,
const wxString& name = wxHeaderCtrlNameStr);
virtual ~wxHeaderCtrl();
private:
// implement base class pure virtuals
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 DoScrollHorz(int dx);
// override wxWindow methods which must be implemented by a new control
virtual wxSize DoGetBestSize() const;
// common part of all ctors
void Init();
// event handlers
void OnPaint(wxPaintEvent& event);
void OnMouse(wxMouseEvent& event);
// return the horizontal start position of the given column
int GetColStart(unsigned int idx) const;
// refresh the given column [only]
void RefreshCol(unsigned int idx);
// 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;
// the horizontal scroll offset
int m_scrollOffset;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxHeaderCtrl)
};
#endif // _WX_GENERIC_HEADERCTRLG_H_

View File

@@ -165,7 +165,7 @@ protected:
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/headercol.h"
#elif 0 // TODO
#else
#define wxHAS_GENERIC_HEADERCOL
#include "wx/generic/headercolg.h"
#endif

View File

@@ -160,7 +160,7 @@ private:
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/headerctrl.h"
#elif 0 // TODO
#else
#define wxHAS_GENERIC_HEADERCTRL
#include "wx/generic/headerctrlg.h"
#endif // platform