Added generic LoadObject methods that can load any classtype from a

resources and return it as a wxObject (Assuming there is a handler for
it.)

Enabled wxFrames and wxDialogs to be loaded using a new instance
rather than only with existing instances.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-08-24 02:26:13 +00:00
parent cdb105516c
commit 92e898b0b4
8 changed files with 120 additions and 52 deletions

View File

@@ -128,6 +128,9 @@ public:
// all controls used within the resource. // all controls used within the resource.
void AddHandler(wxXmlResourceHandler *handler); void AddHandler(wxXmlResourceHandler *handler);
// Add a new handler at the begining of the handler list
void InsertHandler(wxXmlResourceHandler *handler);
// Removes all handlers // Removes all handlers
void ClearHandlers(); void ClearHandlers();
@@ -165,8 +168,20 @@ public:
bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name); bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
// Loads a frame. // Loads a frame.
wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name); bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
// Load an object from the resource specifying both the resource name and
// the classname. This lets you load nonstandard container windows.
wxObject *LoadObject(wxWindow *parent, const wxString& name,
const wxString& classname);
// Load an object from the resource specifying both the resource name and
// the classname. This form lets you finish the creation of an existing
// instance.
bool LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
const wxString& classname);
// Loads a bitmap resource from a file. // Loads a bitmap resource from a file.
wxBitmap LoadBitmap(const wxString& name); wxBitmap LoadBitmap(const wxString& name);

View File

@@ -47,9 +47,7 @@ wxDialogXmlHandler::wxDialogXmlHandler() : wxXmlResourceHandler()
wxObject *wxDialogXmlHandler::DoCreateResource() wxObject *wxDialogXmlHandler::DoCreateResource()
{ {
wxDialog *dlg = wxDynamicCast(m_instance, wxDialog); XRC_MAKE_INSTANCE(dlg, wxDialog);
wxASSERT_MSG(dlg, _("XRC resource: Cannot create dialog without instance."));
dlg->Create(m_parentAsWindow, dlg->Create(m_parentAsWindow,
GetID(), GetID(),

View File

@@ -52,9 +52,7 @@ wxFrameXmlHandler::wxFrameXmlHandler() : wxXmlResourceHandler()
wxObject *wxFrameXmlHandler::DoCreateResource() wxObject *wxFrameXmlHandler::DoCreateResource()
{ {
wxFrame *frame = wxDynamicCast(m_instance, wxFrame); XRC_MAKE_INSTANCE(frame, wxFrame);
wxASSERT_MSG(frame, _("XRC resource: Cannot create dialog without instance."));
frame->Create(m_parentAsWindow, frame->Create(m_parentAsWindow,
GetID(), GetID(),

View File

@@ -132,6 +132,12 @@ void wxXmlResource::AddHandler(wxXmlResourceHandler *handler)
handler->SetParentResource(this); handler->SetParentResource(this);
} }
void wxXmlResource::InsertHandler(wxXmlResourceHandler *handler)
{
m_handlers.Insert(handler);
handler->SetParentResource(this);
}
void wxXmlResource::ClearHandlers() void wxXmlResource::ClearHandlers()
@@ -188,6 +194,11 @@ bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString&
return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL; return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL;
} }
wxFrame *wxXmlResource::LoadFrame(wxWindow* parent, const wxString& name)
{
return (wxFrame*)CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, NULL);
}
bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name) bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name)
{ {
return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL; return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL;
@@ -213,6 +224,18 @@ wxIcon wxXmlResource::LoadIcon(const wxString& name)
return rt; return rt;
} }
wxObject *wxXmlResource::LoadObject(wxWindow *parent, const wxString& name, const wxString& classname)
{
return CreateResFromNode(FindResource(name, classname), parent, NULL);
}
bool wxXmlResource::LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname)
{
return CreateResFromNode(FindResource(name, classname), parent, instance) != NULL;
}
bool wxXmlResource::AttachUnknownControl(const wxString& name, bool wxXmlResource::AttachUnknownControl(const wxString& name,
wxWindow *control, wxWindow *parent) wxWindow *control, wxWindow *parent)
{ {

View File

@@ -128,6 +128,9 @@ public:
// all controls used within the resource. // all controls used within the resource.
void AddHandler(wxXmlResourceHandler *handler); void AddHandler(wxXmlResourceHandler *handler);
// Add a new handler at the begining of the handler list
void InsertHandler(wxXmlResourceHandler *handler);
// Removes all handlers // Removes all handlers
void ClearHandlers(); void ClearHandlers();
@@ -165,8 +168,20 @@ public:
bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name); bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
// Loads a frame. // Loads a frame.
wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name); bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
// Load an object from the resource specifying both the resource name and
// the classname. This lets you load nonstandard container windows.
wxObject *LoadObject(wxWindow *parent, const wxString& name,
const wxString& classname);
// Load an object from the resource specifying both the resource name and
// the classname. This form lets you finish the creation of an existing
// instance.
bool LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
const wxString& classname);
// Loads a bitmap resource from a file. // Loads a bitmap resource from a file.
wxBitmap LoadBitmap(const wxString& name); wxBitmap LoadBitmap(const wxString& name);

View File

@@ -47,9 +47,7 @@ wxDialogXmlHandler::wxDialogXmlHandler() : wxXmlResourceHandler()
wxObject *wxDialogXmlHandler::DoCreateResource() wxObject *wxDialogXmlHandler::DoCreateResource()
{ {
wxDialog *dlg = wxDynamicCast(m_instance, wxDialog); XRC_MAKE_INSTANCE(dlg, wxDialog);
wxASSERT_MSG(dlg, _("XRC resource: Cannot create dialog without instance."));
dlg->Create(m_parentAsWindow, dlg->Create(m_parentAsWindow,
GetID(), GetID(),

View File

@@ -52,9 +52,7 @@ wxFrameXmlHandler::wxFrameXmlHandler() : wxXmlResourceHandler()
wxObject *wxFrameXmlHandler::DoCreateResource() wxObject *wxFrameXmlHandler::DoCreateResource()
{ {
wxFrame *frame = wxDynamicCast(m_instance, wxFrame); XRC_MAKE_INSTANCE(frame, wxFrame);
wxASSERT_MSG(frame, _("XRC resource: Cannot create dialog without instance."));
frame->Create(m_parentAsWindow, frame->Create(m_parentAsWindow,
GetID(), GetID(),

View File

@@ -132,6 +132,12 @@ void wxXmlResource::AddHandler(wxXmlResourceHandler *handler)
handler->SetParentResource(this); handler->SetParentResource(this);
} }
void wxXmlResource::InsertHandler(wxXmlResourceHandler *handler)
{
m_handlers.Insert(handler);
handler->SetParentResource(this);
}
void wxXmlResource::ClearHandlers() void wxXmlResource::ClearHandlers()
@@ -188,6 +194,11 @@ bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString&
return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL; return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL;
} }
wxFrame *wxXmlResource::LoadFrame(wxWindow* parent, const wxString& name)
{
return (wxFrame*)CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, NULL);
}
bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name) bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name)
{ {
return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL; return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL;
@@ -213,6 +224,18 @@ wxIcon wxXmlResource::LoadIcon(const wxString& name)
return rt; return rt;
} }
wxObject *wxXmlResource::LoadObject(wxWindow *parent, const wxString& name, const wxString& classname)
{
return CreateResFromNode(FindResource(name, classname), parent, NULL);
}
bool wxXmlResource::LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname)
{
return CreateResFromNode(FindResource(name, classname), parent, instance) != NULL;
}
bool wxXmlResource::AttachUnknownControl(const wxString& name, bool wxXmlResource::AttachUnknownControl(const wxString& name,
wxWindow *control, wxWindow *parent) wxWindow *control, wxWindow *parent)
{ {