Use wxCompositeWindow for generic wxDataViewCtrl implementation
This makes several methods that didn't have any effect before work correctly, including SetToolTip(), whose effect is now shown in the sample, but also SetCursor() and SetLayoutDirection(). Some methods would now actually work too well: SetForegroundColour() and SetBackgroundColour() implementations in wxCompositeWindow apply to all sub-windows, but in wxDataViewCtrl they are only supposed to affect the items, but not the header, so we need to override them to prevent the base class version from being used. It is still preferable to explicitly disable these two methods and inherit all the other ones (including any possibly added in the future) from wxCompositeWindow to implementing all the methods manually in wxDataViewCtrl itself.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
|
#include "wx/compositewin.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/scrolwin.h"
|
||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
@@ -180,7 +181,8 @@ private:
|
|||||||
// wxDataViewCtrl
|
// wxDataViewCtrl
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDataViewCtrl : public wxDataViewCtrlBase,
|
class WXDLLIMPEXP_CORE wxDataViewCtrl
|
||||||
|
: public wxCompositeWindow<wxDataViewCtrlBase>,
|
||||||
public wxScrollHelper
|
public wxScrollHelper
|
||||||
{
|
{
|
||||||
friend class wxDataViewMainWindow;
|
friend class wxDataViewMainWindow;
|
||||||
@@ -192,6 +194,8 @@ class WXDLLIMPEXP_CORE wxDataViewCtrl : public wxDataViewCtrlBase,
|
|||||||
friend class wxDataViewCtrlAccessible;
|
friend class wxDataViewCtrlAccessible;
|
||||||
#endif // wxUSE_ACCESSIBILITY
|
#endif // wxUSE_ACCESSIBILITY
|
||||||
|
|
||||||
|
typedef wxCompositeWindow<wxDataViewCtrlBase> BaseType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxDataViewCtrl() : wxScrollHelper(this)
|
wxDataViewCtrl() : wxScrollHelper(this)
|
||||||
{
|
{
|
||||||
@@ -264,6 +268,8 @@ public:
|
|||||||
virtual void SetFocus() wxOVERRIDE;
|
virtual void SetFocus() wxOVERRIDE;
|
||||||
|
|
||||||
virtual bool SetFont(const wxFont & font) wxOVERRIDE;
|
virtual bool SetFont(const wxFont & font) wxOVERRIDE;
|
||||||
|
virtual bool SetForegroundColour(const wxColour& colour) wxOVERRIDE;
|
||||||
|
virtual bool SetBackgroundColour(const wxColour& colour) wxOVERRIDE;
|
||||||
|
|
||||||
#if wxUSE_ACCESSIBILITY
|
#if wxUSE_ACCESSIBILITY
|
||||||
virtual bool Show(bool show = true) wxOVERRIDE;
|
virtual bool Show(bool show = true) wxOVERRIDE;
|
||||||
@@ -361,6 +367,9 @@ public: // utility functions not part of the API
|
|||||||
#endif // wxUSE_ACCESSIBILITY
|
#endif // wxUSE_ACCESSIBILITY
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Implement pure virtual method inherited from wxCompositeWindow.
|
||||||
|
virtual wxWindowList GetCompositeWindowParts() const wxOVERRIDE;
|
||||||
|
|
||||||
virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE;
|
virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE;
|
||||||
virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE;
|
virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE;
|
||||||
|
|
||||||
|
@@ -617,9 +617,6 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
wxSizer *firstPanelSz = new wxBoxSizer( wxVERTICAL );
|
wxSizer *firstPanelSz = new wxBoxSizer( wxVERTICAL );
|
||||||
m_ctrl[Page_Music]->SetMinSize(wxSize(-1, 200));
|
m_ctrl[Page_Music]->SetMinSize(wxSize(-1, 200));
|
||||||
firstPanelSz->Add(m_ctrl[Page_Music], 1, wxGROW|wxALL, 5);
|
firstPanelSz->Add(m_ctrl[Page_Music], 1, wxGROW|wxALL, 5);
|
||||||
firstPanelSz->Add(
|
|
||||||
new wxStaticText(firstPanel, wxID_ANY, "Most of the cells above are editable!"),
|
|
||||||
0, wxGROW|wxALL, 5);
|
|
||||||
firstPanelSz->Add(button_sizer);
|
firstPanelSz->Add(button_sizer);
|
||||||
firstPanelSz->Add(sizerCurrent);
|
firstPanelSz->Add(sizerCurrent);
|
||||||
firstPanel->SetSizerAndFit(firstPanelSz);
|
firstPanel->SetSizerAndFit(firstPanelSz);
|
||||||
@@ -837,6 +834,8 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
|||||||
|
|
||||||
// select initially the ninth symphony:
|
// select initially the ninth symphony:
|
||||||
m_ctrl[Page_Music]->Select(m_music_model->GetNinthItem());
|
m_ctrl[Page_Music]->Select(m_music_model->GetNinthItem());
|
||||||
|
|
||||||
|
m_ctrl[Page_Music]->SetToolTip("You may edit most of the cells here!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -5584,6 +5584,14 @@ bool wxDataViewCtrl::Create(wxWindow *parent,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxWindowList wxDataViewCtrl::GetCompositeWindowParts() const
|
||||||
|
{
|
||||||
|
wxWindowList parts;
|
||||||
|
parts.push_back(m_headerArea); // It's ok to add it even if it's null.
|
||||||
|
parts.push_back(m_clientArea);
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
wxBorder wxDataViewCtrl::GetDefaultBorder() const
|
wxBorder wxDataViewCtrl::GetDefaultBorder() const
|
||||||
{
|
{
|
||||||
return wxBORDER_THEME;
|
return wxBORDER_THEME;
|
||||||
@@ -5679,15 +5687,11 @@ void wxDataViewCtrl::SetFocus()
|
|||||||
|
|
||||||
bool wxDataViewCtrl::SetFont(const wxFont & font)
|
bool wxDataViewCtrl::SetFont(const wxFont & font)
|
||||||
{
|
{
|
||||||
if (!wxControl::SetFont(font))
|
if (!BaseType::SetFont(font))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_headerArea)
|
|
||||||
m_headerArea->SetFont(font);
|
|
||||||
|
|
||||||
if (m_clientArea)
|
if (m_clientArea)
|
||||||
{
|
{
|
||||||
m_clientArea->SetFont(font);
|
|
||||||
m_clientArea->SetRowHeight(m_clientArea->GetDefaultRowHeight());
|
m_clientArea->SetRowHeight(m_clientArea->GetDefaultRowHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5700,6 +5704,35 @@ bool wxDataViewCtrl::SetFont(const wxFont & font)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxDataViewCtrl::SetForegroundColour(const wxColour& colour)
|
||||||
|
{
|
||||||
|
// Previous versions of this class, not using wxCompositeWindow, as well as
|
||||||
|
// the native versions of this control, don't change the header foreground
|
||||||
|
// when this method is called and this could be more desirable in practice,
|
||||||
|
// as well we being more compatible, so skip calling the base class version
|
||||||
|
// that would change it as well and change only the main items area colour
|
||||||
|
// here too.
|
||||||
|
if ( !wxDataViewCtrlBase::SetForegroundColour(colour) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( m_clientArea )
|
||||||
|
m_clientArea->SetForegroundColour(colour);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewCtrl::SetBackgroundColour(const wxColour& colour)
|
||||||
|
{
|
||||||
|
// See SetForegroundColour() above.
|
||||||
|
if ( !wxDataViewCtrlBase::SetBackgroundColour(colour) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( m_clientArea )
|
||||||
|
m_clientArea->SetBackgroundColour(colour);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_ACCESSIBILITY
|
#if wxUSE_ACCESSIBILITY
|
||||||
bool wxDataViewCtrl::Show(bool show)
|
bool wxDataViewCtrl::Show(bool show)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user