New code for inserting unknown controls into resources

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
This commit is contained in:
Václav Slavík
2001-05-20 22:18:28 +00:00
parent bdfeadcac5
commit e6c3f404b8
3 changed files with 68 additions and 23 deletions

View File

@@ -139,6 +139,11 @@ public:
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
// Macro XMLID is provided for convenience

View File

@@ -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)

View 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