implemented subclassing in XRC

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2001-12-29 16:13:43 +00:00
parent 4f89dbc48e
commit daa85ee3af
4 changed files with 122 additions and 48 deletions

View File

@ -80,19 +80,26 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
WX_DECLARE_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
#endif
enum wxXmlResourceFlags
{
wxXRC_USE_LOCALE = 1,
wxXRC_NO_SUBCLASSING = 2
};
// This class holds XML resources from one or more .xml files
// (or derived forms, either binary or zipped -- see manual for
// details).
class WXXMLDLLEXPORT wxXmlResource : public wxObject
{
public:
// Ctor. If use_locale is TRUE, translatable strings are
// translated via _(). You can disable it by passing use_locale=FALSE
// (for example if you provide resource file for each locale)
wxXmlResource(bool use_locale = TRUE);
wxXmlResource(const wxString& filemask, bool use_locale = TRUE);
// Ctor.
// Flags: wxXRC_USE_LOCALE
// translatable strings will be translated via _()
// wxXRC_NO_SUBCLASSING
// subclass property of object nodes will be ignored
// (useful for previews in XRC editors)
wxXmlResource(int flags = wxXRC_USE_LOCALE);
wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
~wxXmlResource();
// Loads resources from XML files that match given filemask.
@ -176,12 +183,12 @@ protected:
// Creates resource from info in given node:
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL);
bool GetUseLocale() { return m_useLocale; }
int GetFlags() { return m_flags; }
private:
long m_version;
bool m_useLocale;
int m_flags;
wxList m_handlers;
wxXmlResourceDataRecords m_data;
#if wxUSE_FILESYSTEM
@ -348,9 +355,21 @@ protected:
#endif
};
#define ADD_STYLE(style) AddStyle(wxT(#style), style)
// Programmer-friendly macros for writing XRC handlers:
#define XRC_ADD_STYLE(style) AddStyle(wxT(#style), style)
#define ADD_STYLE XRC_ADD_STYLE /* deprecated, don't use!! */
#define XRC_MAKE_INSTANCE(variable, classname) \
classname *variable = NULL; \
if (m_instance) \
variable = wxStaticCast(m_instance, classname); \
if (!variable) \
variable = new classname;
// FIXME -- remove this $%^#$%#$@# as soon as Ron checks his changes in!!
void wxXmlInitResourceModule();
#endif // _WX_XMLRES_H_

View File

@ -40,16 +40,16 @@
WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
wxXmlResource::wxXmlResource(bool use_locale)
wxXmlResource::wxXmlResource(int flags)
{
m_handlers.DeleteContents(TRUE);
m_useLocale = use_locale;
m_flags = flags;
m_version = -1;
}
wxXmlResource::wxXmlResource(const wxString& filemask, bool use_locale)
wxXmlResource::wxXmlResource(const wxString& filemask, int flags)
{
m_useLocale = use_locale;
m_flags = flags;
m_version = -1;
m_handlers.DeleteContents(TRUE);
Load(filemask);
@ -421,10 +421,28 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent
wxObject *myParent = m_parent, *myInstance = m_instance;
wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow;
m_instance = instance;
if (!m_instance && node->HasProp(wxT("subclass")) &&
!(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
{
wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);
wxClassInfo* classInfo = wxClassInfo::FindClass(subclass);
if (classInfo)
m_instance = classInfo->CreateObject();
if (!m_instance)
{
wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
subclass.c_str(), node->GetPropVal(wxT("name"), wxEmptyString).c_str());
}
m_instance = classInfo->CreateObject();
}
m_node = node;
m_class = node->GetPropVal(wxT("class"), wxEmptyString);
m_parent = parent;
m_instance = instance;
m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);
m_instanceAsWindow = wxDynamicCast(m_instance, wxWindow);
@ -449,15 +467,15 @@ void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
void wxXmlResourceHandler::AddWindowStyles()
{
ADD_STYLE(wxSIMPLE_BORDER);
ADD_STYLE(wxSUNKEN_BORDER);
ADD_STYLE(wxDOUBLE_BORDER);
ADD_STYLE(wxRAISED_BORDER);
ADD_STYLE(wxSTATIC_BORDER);
ADD_STYLE(wxNO_BORDER);
ADD_STYLE(wxTRANSPARENT_WINDOW);
ADD_STYLE(wxWANTS_CHARS);
ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
XRC_ADD_STYLE(wxSIMPLE_BORDER);
XRC_ADD_STYLE(wxSUNKEN_BORDER);
XRC_ADD_STYLE(wxDOUBLE_BORDER);
XRC_ADD_STYLE(wxRAISED_BORDER);
XRC_ADD_STYLE(wxSTATIC_BORDER);
XRC_ADD_STYLE(wxNO_BORDER);
XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);
XRC_ADD_STYLE(wxWANTS_CHARS);
XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
}
@ -499,7 +517,7 @@ wxString wxXmlResourceHandler::GetText(const wxString& param)
const wxChar *dt;
wxChar amp_char;
if (m_resource->GetUseLocale())
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
str1 = wxGetTranslation(GetParamValue(param));
else
str1 = GetParamValue(param);

View File

@ -80,19 +80,26 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
WX_DECLARE_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
#endif
enum wxXmlResourceFlags
{
wxXRC_USE_LOCALE = 1,
wxXRC_NO_SUBCLASSING = 2
};
// This class holds XML resources from one or more .xml files
// (or derived forms, either binary or zipped -- see manual for
// details).
class WXXMLDLLEXPORT wxXmlResource : public wxObject
{
public:
// Ctor. If use_locale is TRUE, translatable strings are
// translated via _(). You can disable it by passing use_locale=FALSE
// (for example if you provide resource file for each locale)
wxXmlResource(bool use_locale = TRUE);
wxXmlResource(const wxString& filemask, bool use_locale = TRUE);
// Ctor.
// Flags: wxXRC_USE_LOCALE
// translatable strings will be translated via _()
// wxXRC_NO_SUBCLASSING
// subclass property of object nodes will be ignored
// (useful for previews in XRC editors)
wxXmlResource(int flags = wxXRC_USE_LOCALE);
wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
~wxXmlResource();
// Loads resources from XML files that match given filemask.
@ -176,12 +183,12 @@ protected:
// Creates resource from info in given node:
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL);
bool GetUseLocale() { return m_useLocale; }
int GetFlags() { return m_flags; }
private:
long m_version;
bool m_useLocale;
int m_flags;
wxList m_handlers;
wxXmlResourceDataRecords m_data;
#if wxUSE_FILESYSTEM
@ -348,9 +355,21 @@ protected:
#endif
};
#define ADD_STYLE(style) AddStyle(wxT(#style), style)
// Programmer-friendly macros for writing XRC handlers:
#define XRC_ADD_STYLE(style) AddStyle(wxT(#style), style)
#define ADD_STYLE XRC_ADD_STYLE /* deprecated, don't use!! */
#define XRC_MAKE_INSTANCE(variable, classname) \
classname *variable = NULL; \
if (m_instance) \
variable = wxStaticCast(m_instance, classname); \
if (!variable) \
variable = new classname;
// FIXME -- remove this $%^#$%#$@# as soon as Ron checks his changes in!!
void wxXmlInitResourceModule();
#endif // _WX_XMLRES_H_

View File

@ -40,16 +40,16 @@
WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
wxXmlResource::wxXmlResource(bool use_locale)
wxXmlResource::wxXmlResource(int flags)
{
m_handlers.DeleteContents(TRUE);
m_useLocale = use_locale;
m_flags = flags;
m_version = -1;
}
wxXmlResource::wxXmlResource(const wxString& filemask, bool use_locale)
wxXmlResource::wxXmlResource(const wxString& filemask, int flags)
{
m_useLocale = use_locale;
m_flags = flags;
m_version = -1;
m_handlers.DeleteContents(TRUE);
Load(filemask);
@ -421,10 +421,28 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent
wxObject *myParent = m_parent, *myInstance = m_instance;
wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow;
m_instance = instance;
if (!m_instance && node->HasProp(wxT("subclass")) &&
!(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
{
wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);
wxClassInfo* classInfo = wxClassInfo::FindClass(subclass);
if (classInfo)
m_instance = classInfo->CreateObject();
if (!m_instance)
{
wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
subclass.c_str(), node->GetPropVal(wxT("name"), wxEmptyString).c_str());
}
m_instance = classInfo->CreateObject();
}
m_node = node;
m_class = node->GetPropVal(wxT("class"), wxEmptyString);
m_parent = parent;
m_instance = instance;
m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);
m_instanceAsWindow = wxDynamicCast(m_instance, wxWindow);
@ -449,15 +467,15 @@ void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
void wxXmlResourceHandler::AddWindowStyles()
{
ADD_STYLE(wxSIMPLE_BORDER);
ADD_STYLE(wxSUNKEN_BORDER);
ADD_STYLE(wxDOUBLE_BORDER);
ADD_STYLE(wxRAISED_BORDER);
ADD_STYLE(wxSTATIC_BORDER);
ADD_STYLE(wxNO_BORDER);
ADD_STYLE(wxTRANSPARENT_WINDOW);
ADD_STYLE(wxWANTS_CHARS);
ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
XRC_ADD_STYLE(wxSIMPLE_BORDER);
XRC_ADD_STYLE(wxSUNKEN_BORDER);
XRC_ADD_STYLE(wxDOUBLE_BORDER);
XRC_ADD_STYLE(wxRAISED_BORDER);
XRC_ADD_STYLE(wxSTATIC_BORDER);
XRC_ADD_STYLE(wxNO_BORDER);
XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);
XRC_ADD_STYLE(wxWANTS_CHARS);
XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
}
@ -499,7 +517,7 @@ wxString wxXmlResourceHandler::GetText(const wxString& param)
const wxChar *dt;
wxChar amp_char;
if (m_resource->GetUseLocale())
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
str1 = wxGetTranslation(GetParamValue(param));
else
str1 = GetParamValue(param);