// 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
#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)
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)
-
-
// --------------- XMLID implementation -----------------------------
#define XMLID_TABLE_SIZE 1024