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:
@@ -138,6 +138,11 @@ public:
|
|||||||
// Loads bitmap or icon resource from file:
|
// Loads bitmap or icon resource from file:
|
||||||
wxBitmap LoadBitmap(const wxString& name);
|
wxBitmap LoadBitmap(const wxString& name);
|
||||||
wxIcon LoadIcon(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
|
// Returns numeric ID that is equivalent to string id used in XML
|
||||||
// resource. To be used in event tables
|
// resource. To be used in event tables
|
||||||
|
@@ -22,36 +22,65 @@
|
|||||||
#include "wx/xml/xh_unkwn.h"
|
#include "wx/xml/xh_unkwn.h"
|
||||||
#include "wx/window.h"
|
#include "wx/window.h"
|
||||||
#include "wx/log.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()
|
wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
|
||||||
: wxXmlResourceHandler()
|
: wxXmlResourceHandler()
|
||||||
{
|
{
|
||||||
AddWindowStyles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxObject *wxUnknownWidgetXmlHandler::DoCreateResource()
|
wxObject *wxUnknownWidgetXmlHandler::DoCreateResource()
|
||||||
{
|
{
|
||||||
long id = GetLong(wxT("id"), -1);
|
wxPanel *panel =
|
||||||
wxString name = GetParamValue(wxT("name"));
|
new wxUnknownControlContainer(m_parentAsWindow,
|
||||||
|
GetName(), GetID(),
|
||||||
wxWindow *wnd = NULL;
|
GetPosition(), GetSize());
|
||||||
|
SetupWindow(panel);
|
||||||
if (id != -1)
|
return panel;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode *node)
|
bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode *node)
|
||||||
|
@@ -195,6 +195,19 @@ wxIcon wxXmlResource::LoadIcon(const wxString& name)
|
|||||||
return rt;
|
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)
|
void wxXmlResource::ProcessPlatformProperty(wxXmlNode *node)
|
||||||
@@ -882,8 +895,6 @@ void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode *
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------- XMLID implementation -----------------------------
|
// --------------- XMLID implementation -----------------------------
|
||||||
|
|
||||||
#define XMLID_TABLE_SIZE 1024
|
#define XMLID_TABLE_SIZE 1024
|
||||||
|
Reference in New Issue
Block a user