Merge branch 'generic-dvc-composite'
Use wxCompositeWindow for generic wxDVC implementation. See https://github.com/wxWidgets/wxWidgets/pull/2382
This commit is contained in:
@@ -218,11 +218,17 @@ private:
|
|||||||
win = win->GetParent();
|
win = win->GetParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
child->Bind(wxEVT_CHAR, &wxCompositeWindow::OnChar, this);
|
// Make all keyboard events occurring in sub-windows appear as coming
|
||||||
|
// from the main window itself.
|
||||||
|
child->Bind(wxEVT_KEY_DOWN, &wxCompositeWindow::OnKeyEvent, this);
|
||||||
|
child->Bind(wxEVT_CHAR, &wxCompositeWindow::OnKeyEvent, this);
|
||||||
|
child->Bind(wxEVT_KEY_UP, &wxCompositeWindow::OnKeyEvent, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnChar(wxKeyEvent& event)
|
void OnKeyEvent(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
|
wxEventObjectOriginSetter setThis(event, this, this->GetId());
|
||||||
|
|
||||||
if ( !this->ProcessWindowEvent(event) )
|
if ( !this->ProcessWindowEvent(event) )
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
@@ -1197,6 +1197,35 @@ private:
|
|||||||
wxDECLARE_NO_COPY_CLASS(wxPropagateOnce);
|
wxDECLARE_NO_COPY_CLASS(wxPropagateOnce);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper class changing the event object to make the event appear as coming
|
||||||
|
// from a different source: this is somewhat of a hack, but avoids copying the
|
||||||
|
// events just to change their event object field.
|
||||||
|
class wxEventObjectOriginSetter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxEventObjectOriginSetter(wxEvent& event, wxObject* source, int winid = 0)
|
||||||
|
: m_event(event),
|
||||||
|
m_sourceOrig(event.GetEventObject()),
|
||||||
|
m_idOrig(event.GetId())
|
||||||
|
{
|
||||||
|
m_event.SetEventObject(source);
|
||||||
|
m_event.SetId(winid);
|
||||||
|
}
|
||||||
|
|
||||||
|
~wxEventObjectOriginSetter()
|
||||||
|
{
|
||||||
|
m_event.SetId(m_idOrig);
|
||||||
|
m_event.SetEventObject(m_sourceOrig);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxEvent& m_event;
|
||||||
|
wxObject* const m_sourceOrig;
|
||||||
|
const int m_idOrig;
|
||||||
|
|
||||||
|
wxDECLARE_NO_COPY_CLASS(wxEventObjectOriginSetter);
|
||||||
|
};
|
||||||
|
|
||||||
// A helper object used to temporarily make wxEvent::ShouldProcessOnlyIn()
|
// A helper object used to temporarily make wxEvent::ShouldProcessOnlyIn()
|
||||||
// return true for the handler passed to its ctor.
|
// return true for the handler passed to its ctor.
|
||||||
class wxEventProcessInHandlerOnly
|
class wxEventProcessInHandlerOnly
|
||||||
|
@@ -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,8 +181,9 @@ private:
|
|||||||
// wxDataViewCtrl
|
// wxDataViewCtrl
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDataViewCtrl : public wxDataViewCtrlBase,
|
class WXDLLIMPEXP_CORE wxDataViewCtrl
|
||||||
public wxScrollHelper
|
: public wxCompositeWindow<wxDataViewCtrlBase>,
|
||||||
|
public wxScrollHelper
|
||||||
{
|
{
|
||||||
friend class wxDataViewMainWindow;
|
friend class wxDataViewMainWindow;
|
||||||
friend class wxDataViewHeaderWindowBase;
|
friend class wxDataViewHeaderWindowBase;
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
@@ -423,7 +423,7 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase,
|
|||||||
if ( !EnableUITests() )
|
if ( !EnableUITests() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EventCounter keyEvents(m_dvc->GetMainWindow(), wxEVT_KEY_DOWN);
|
EventCounter keyEvents(m_dvc, wxEVT_KEY_DOWN);
|
||||||
|
|
||||||
m_dvc->SetFocus();
|
m_dvc->SetFocus();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user