Add wxCompositeWindow<> and use it in wxDatePickerCtrlGeneric.
wxCompositeWindow<> is a convenient base class for composite windows, i.e. windows consisting of several other wxWindows. Currently it just automatically forwards various attributes setters calls to all of the composite window parts but it could become more useful in the future. Similarly, for now it is only used in wxDatePickerCtrlGeneric but it could (and should) be used for other composite controls later and we probably should even make this class public to allow its use in the client code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3823,6 +3823,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
|
||||
wx/collpane.h \
|
||||
wx/combo.h \
|
||||
wx/combobox.h \
|
||||
wx/compositewin.h \
|
||||
wx/control.h \
|
||||
wx/ctrlsub.h \
|
||||
wx/cursor.h \
|
||||
|
@@ -797,6 +797,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
||||
wx/collpane.h
|
||||
wx/combo.h
|
||||
wx/combobox.h
|
||||
wx/compositewin.h
|
||||
wx/control.h
|
||||
wx/ctrlsub.h
|
||||
wx/cursor.h
|
||||
|
@@ -5965,6 +5965,10 @@ SOURCE=..\..\include\wx\commandlinkbutton.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\wx\compositewin.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\wx\control.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -5068,6 +5068,9 @@
|
||||
<File
|
||||
RelativePath="..\..\include\wx\commandlinkbutton.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\compositewin.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\control.h">
|
||||
</File>
|
||||
|
@@ -6775,6 +6775,10 @@
|
||||
RelativePath="..\..\include\wx\commandlinkbutton.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\compositewin.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\control.h"
|
||||
>
|
||||
|
@@ -6771,6 +6771,10 @@
|
||||
RelativePath="..\..\include\wx\commandlinkbutton.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\compositewin.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\control.h"
|
||||
>
|
||||
|
110
include/wx/compositewin.h
Normal file
110
include/wx/compositewin.h
Normal file
@@ -0,0 +1,110 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/compositewin.h
|
||||
// Purpose: wxCompositeWindow<> declaration
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-01-02
|
||||
// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_COMPOSITEWIN_H_
|
||||
#define _WX_COMPOSITEWIN_H_
|
||||
|
||||
#include "wx/window.h"
|
||||
|
||||
// NB: This is an experimental and, as for now, undocumented class used only by
|
||||
// wxWidgets itself internally. Don't use it in your code until its API is
|
||||
// officially stabilized unless you are ready to change it with the next
|
||||
// wxWidgets release.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxCompositeWindow is a helper for implementing composite windows: to define
|
||||
// a class using subwindows, simply inherit from it specialized with the real
|
||||
// base class name and implement GetCompositeWindowParts() pure virtual method.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// The template parameter W must be a wxWindow-derived class.
|
||||
template <class W>
|
||||
class wxCompositeWindow : public W
|
||||
{
|
||||
public:
|
||||
typedef W BaseWindowClass;
|
||||
|
||||
// Default ctor doesn't do anything.
|
||||
wxCompositeWindow() { }
|
||||
|
||||
// Override all wxWindow methods which must be forwarded to the composite
|
||||
// window parts.
|
||||
|
||||
// Attribute setters group.
|
||||
//
|
||||
// NB: Unfortunately we can't factor out the call for the setter itself
|
||||
// into DoSetForAllParts() because we can't call the function passed to
|
||||
// it non-virtually and we need to do this to avoid infinite recursion,
|
||||
// so we work around this by calling the method of this object itself
|
||||
// manually in each function.
|
||||
virtual bool SetForegroundColour(const wxColour& colour)
|
||||
{
|
||||
if ( !BaseWindowClass::SetForegroundColour(colour) )
|
||||
return false;
|
||||
|
||||
DoSetForAllParts(&wxWindow::SetForegroundColour, colour);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SetBackgroundColour(const wxColour& colour)
|
||||
{
|
||||
if ( !BaseWindowClass::SetBackgroundColour(colour) )
|
||||
return false;
|
||||
|
||||
DoSetForAllParts(&wxWindow::SetBackgroundColour, colour);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SetFont(const wxFont& font)
|
||||
{
|
||||
if ( !BaseWindowClass::SetFont(font) )
|
||||
return false;
|
||||
|
||||
DoSetForAllParts(&wxWindow::SetFont, font);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool SetCursor(const wxCursor& cursor)
|
||||
{
|
||||
if ( !BaseWindowClass::SetCursor(cursor) )
|
||||
return false;
|
||||
|
||||
DoSetForAllParts(&wxWindow::SetCursor, cursor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// Must be implemented by the derived class to return all children to which
|
||||
// the public methods we override should forward to.
|
||||
virtual wxWindowList GetCompositeWindowParts() const = 0;
|
||||
|
||||
template <class T>
|
||||
void DoSetForAllParts(bool (wxWindow::*func)(const T&), const T& arg)
|
||||
{
|
||||
// Simply call the setters for all parts of this composite window.
|
||||
const wxWindowList parts = GetCompositeWindowParts();
|
||||
for ( wxWindowList::const_iterator i = parts.begin();
|
||||
i != parts.end();
|
||||
++i )
|
||||
{
|
||||
wxWindow * const child = *i;
|
||||
|
||||
(child->*func)(arg);
|
||||
}
|
||||
}
|
||||
|
||||
wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow, W);
|
||||
};
|
||||
|
||||
#endif // _WX_COMPOSITEWIN_H_
|
@@ -12,12 +12,15 @@
|
||||
#ifndef _WX_GENERIC_DATECTRL_H_
|
||||
#define _WX_GENERIC_DATECTRL_H_
|
||||
|
||||
#include "wx/compositewin.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxComboCtrl;
|
||||
|
||||
class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl;
|
||||
class WXDLLIMPEXP_FWD_ADV wxCalendarComboPopup;
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDatePickerCtrlGeneric : public wxDatePickerCtrlBase
|
||||
class WXDLLIMPEXP_ADV wxDatePickerCtrlGeneric
|
||||
: public wxCompositeWindow<wxDatePickerCtrlBase>
|
||||
{
|
||||
public:
|
||||
// creating the control
|
||||
@@ -72,6 +75,9 @@ protected:
|
||||
private:
|
||||
void Init();
|
||||
|
||||
// return the list of the windows composing this one
|
||||
virtual wxWindowList GetCompositeWindowParts() const;
|
||||
|
||||
void OnText(wxCommandEvent &event);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnFocus(wxFocusEvent& event);
|
||||
|
@@ -378,6 +378,14 @@ wxSize wxDatePickerCtrlGeneric::DoGetBestSize() const
|
||||
return m_combo->GetBestSize();
|
||||
}
|
||||
|
||||
wxWindowList wxDatePickerCtrlGeneric::GetCompositeWindowParts() const
|
||||
{
|
||||
wxWindowList parts;
|
||||
parts.push_back(m_combo);
|
||||
parts.push_back(m_popup);
|
||||
return parts;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDatePickerCtrlGeneric API
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user