]> git.saurik.com Git - wxWidgets.git/commitdiff
New code for inserting unknown controls into resources
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 20 May 2001 22:18:28 +0000 (22:18 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 20 May 2001 22:18:28 +0000 (22:18 +0000)
via <object class='unknown'>. This one even works.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10249 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/include/wx/xml/xmlres.h
contrib/src/xml/xh_unkwn.cpp
contrib/src/xml/xmlres.cpp

index aab2b33d3039d3252b22829829dcb428465f4892..b9cb6aaec687745fbc4438d56657ab4515ddeb66 100644 (file)
@@ -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 <object class="unknown">)
+    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
index 161b700fd2a372035ab6ea8e0828363260f99d6b..e71cc914fcb5d75a035811f4fcd411f2f5a87ab6 100644 (file)
 #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)
index 7a5bd4ee74221d8e92dc89347747a27a1b25356d..0e91f2dbab26cf6541810748651965632ca71a8b 100644 (file)
@@ -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