From: Václav Slavík Date: Sun, 20 May 2001 22:18:28 +0000 (+0000) Subject: New code for inserting unknown controls into resources X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e6c3f404b8e3f5cf1bf544e9d461619eb761782d New code for inserting unknown controls into resources via . This one even works. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10249 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/contrib/include/wx/xml/xmlres.h b/contrib/include/wx/xml/xmlres.h index aab2b33d30..b9cb6aaec6 100644 --- a/contrib/include/wx/xml/xmlres.h +++ b/contrib/include/wx/xml/xmlres.h @@ -138,6 +138,11 @@ public: // Loads bitmap or icon resource from file: wxBitmap LoadBitmap(const wxString& name); wxIcon LoadIcon(const wxString& name); + + // Attaches unknown control into given panel/window/dialog: + // (unknown controls are used in conjunction with ) + bool AttachUnknownControl(const wxString& name, wxWindow *control, + wxWindow *parent = NULL); // Returns numeric ID that is equivalent to string id used in XML // resource. To be used in event tables diff --git a/contrib/src/xml/xh_unkwn.cpp b/contrib/src/xml/xh_unkwn.cpp index 161b700fd2..e71cc914fc 100644 --- a/contrib/src/xml/xh_unkwn.cpp +++ b/contrib/src/xml/xh_unkwn.cpp @@ -22,36 +22,65 @@ #include "wx/xml/xh_unkwn.h" #include "wx/window.h" #include "wx/log.h" +#include "wx/sizer.h" + + +class wxUnknownControlContainer : public wxPanel +{ +public: + wxUnknownControlContainer(wxWindow *parent, + const wxString& controlName, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize) + : wxPanel(parent, id, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER, + controlName + wxT("_container")), + m_controlName(controlName), m_controlAdded(FALSE) + { + m_bg = GetBackgroundColour(); + SetBackgroundColour(wxColour(255, 0, 255)); + } + + virtual void AddChild(wxWindowBase *child); + +protected: + wxString m_controlName; + bool m_controlAdded; + wxColour m_bg; +}; + +void wxUnknownControlContainer::AddChild(wxWindowBase *child) +{ + wxASSERT_MSG( !m_controlAdded, wxT("Couldn't add two unknown controls to the same container!") ) + + wxPanel::AddChild(child); + + SetBackgroundColour(m_bg); + child->SetName(m_controlName); + m_controlAdded = TRUE; + + wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add((wxWindow*)child, 1, wxEXPAND); + SetSizer(sizer); + SetAutoLayout(TRUE); + Layout(); +} + wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler() : wxXmlResourceHandler() { - AddWindowStyles(); } wxObject *wxUnknownWidgetXmlHandler::DoCreateResource() { - long id = GetLong(wxT("id"), -1); - wxString name = GetParamValue(wxT("name")); - - wxWindow *wnd = NULL; - - if (id != -1) - wnd = m_parentAsWindow->FindWindow(id); - if (wnd == NULL && !name.IsEmpty()) - wnd = m_parentAsWindow->FindWindow(name); - - if (wnd == NULL) - wxLogError(wxT("Cannot find specified window for class 'unknown' (id=%li, name='%s')."), id, name.mb_str()); - else - { - if (wnd->GetParent() != m_parentAsWindow) - wnd->Reparent(m_parentAsWindow); - SetupWindow(wnd); - } - - return wnd; + wxPanel *panel = + new wxUnknownControlContainer(m_parentAsWindow, + GetName(), GetID(), + GetPosition(), GetSize()); + SetupWindow(panel); + return panel; } bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode *node) diff --git a/contrib/src/xml/xmlres.cpp b/contrib/src/xml/xmlres.cpp index 7a5bd4ee74..0e91f2dbab 100644 --- a/contrib/src/xml/xmlres.cpp +++ b/contrib/src/xml/xmlres.cpp @@ -195,6 +195,19 @@ wxIcon wxXmlResource::LoadIcon(const wxString& name) return rt; } +bool wxXmlResource::AttachUnknownControl(const wxString& name, + wxWindow *control, wxWindow *parent) +{ + if (parent == NULL) + parent = control->GetParent(); + wxWindow *container = parent->FindWindow(name + wxT("_container")); + if (!container) + { + wxLogError(_("Cannot find container for unknown control '%s'."), name.c_str()); + return FALSE; + } + return control->Reparent(container); +} void wxXmlResource::ProcessPlatformProperty(wxXmlNode *node) @@ -882,8 +895,6 @@ void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode * - - // --------------- XMLID implementation ----------------------------- #define XMLID_TABLE_SIZE 1024