--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: xh_bmp.h
+// Purpose: XML resource handler for wxBitmap and wxIcon
+// Author: Vaclav Slavik
+// Created: 2000/09/00
+// RCS-ID: $Id$
+// Copyright: (c) 2000 Vaclav Slavik
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_XH_BMP_H_
+#define _WX_XH_BMP_H_
+
+#ifdef __GNUG__
+#pragma interface "xh_bmp.h"
+#endif
+
+#include "wx/xml/xmlres.h"
+
+
+class WXDLLEXPORT wxBitmapXmlHandler : public wxXmlResourceHandler
+{
+ public:
+ wxBitmapXmlHandler();
+ virtual wxObject *DoCreateResource();
+ virtual bool CanHandle(wxXmlNode *node);
+};
+
+class WXDLLEXPORT wxIconXmlHandler : public wxXmlResourceHandler
+{
+ public:
+ wxIconXmlHandler();
+ virtual wxObject *DoCreateResource();
+ virtual bool CanHandle(wxXmlNode *node);
+};
+
+
+#endif // _WX_XH_BMP_H_
class WXDLLEXPORT wxXmlResource : public wxObject
{
public:
- wxXmlResource();
- wxXmlResource(const wxString& filemask);
+ // 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);
~wxXmlResource();
// Loads resources from XML files that match given filemask.
wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
+ // Load bitmap or icon resource from file:
+ wxBitmap LoadBitmap(const wxString& name);
+ wxIcon LoadIcon(const wxString& name);
+
// 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
// Remove nodes with property "platform" that does not
// match current platform
void ProcessPlatformProperty(wxXmlNode *node);
+
+ bool GetUseLocale() { return m_UseLocale; }
private:
+ bool m_UseLocale;
wxList m_Handlers;
wxXmlResourceDataRecords m_Data;
#if wxUSE_FILESYSTEM
wxXmlResource::GetXMLID(_T(str_id))
-
// This macro returns pointer to particular control in dialog
// created using XML resources. You can use it to set/get values from
// controls.
// understood by this handler
void AddStyle(const wxString& name, int value);
- // Add styles common to all wxWindow-derived classes
- void AddWindowStyles();
+ // Add styles common to all wxWindow-derived classes
+ void AddWindowStyles();
// Gets style flags from text in form "flag | flag2| flag3 |..."
// Only understads flags added with AddStyle
// Gets text from param and does some convertions:
// - replaces \n, \r, \t by respective chars (according to C syntax)
// - replaces $ by & and $$ by $ (needed for $File => &File because of XML)
- // - converts encodings if neccessary
+ // - calls wxGetTranslations (unless disabled in wxXmlResource)
wxString GetText(const wxString& param);
// Return XMLID
wxBitmap GetBitmap(const wxString& param = _T("bitmap"), wxSize size = wxDefaultSize);
wxIcon GetIcon(const wxString& param = _T("icon"), wxSize size = wxDefaultSize);
+ // Get font:
+ wxFont GetFont(const wxString& param = _T("font"));
+
// Sets common window options:
void SetupWindow(wxWindow *wnd);
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: xh_bmp.cpp
+// Purpose: XML resource for wxBitmap and wxIcon
+// Author: Vaclav Slavik
+// Created: 2000/09/09
+// RCS-ID: $Id$
+// Copyright: (c) 2000 Vaclav Slavik
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "xh_bmp.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/xml/xh_bmp.h"
+#include "wx/bitmap.h"
+
+
+wxBitmapXmlHandler::wxBitmapXmlHandler()
+: wxXmlResourceHandler()
+{
+}
+
+wxObject *wxBitmapXmlHandler::DoCreateResource()
+{
+ return new wxBitmap(GetBitmap(_T("")));
+}
+
+
+
+bool wxBitmapXmlHandler::CanHandle(wxXmlNode *node)
+{
+ return node->GetName() == _T("bitmap");
+}
+
+
+wxIconXmlHandler::wxIconXmlHandler()
+: wxXmlResourceHandler()
+{
+}
+
+wxObject *wxIconXmlHandler::DoCreateResource()
+{
+ return new wxIcon(GetIcon(_T("")));
+}
+
+
+
+bool wxIconXmlHandler::CanHandle(wxXmlNode *node)
+{
+ return node->GetName() == _T("icon");
+}
+
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/tokenzr.h"
+#include "wx/fontenum.h"
#include "wx/module.h"
#include "wx/bitmap.h"
#include "wx/image.h"
WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
-wxXmlResource::wxXmlResource()
+wxXmlResource::wxXmlResource(bool use_locale = TRUE)
{
m_Handlers.DeleteContents(TRUE);
+ m_UseLocale = use_locale;
}
-wxXmlResource::wxXmlResource(const wxString& filemask)
+wxXmlResource::wxXmlResource(const wxString& filemask, bool use_locale = TRUE)
{
+ m_UseLocale = use_locale;
m_Handlers.DeleteContents(TRUE);
Load(filemask);
}
+wxBitmap wxXmlResource::LoadBitmap(const wxString& name)
+{
+ wxBitmap *bmp = (wxBitmap*)CreateResFromNode(
+ FindResource(name, wxT("bitmap")), NULL, NULL);
+ wxBitmap rt;
+
+ if (bmp) { rt = *bmp; delete bmp; }
+ return rt;
+}
+
+wxIcon wxXmlResource::LoadIcon(const wxString& name)
+{
+ wxIcon *icon = (wxIcon*)CreateResFromNode(
+ FindResource(name, wxT("icon")), NULL, NULL);
+ wxIcon rt;
+
+ if (icon) { rt = *icon; delete icon; }
+ return rt;
+}
+
+
+
void wxXmlResource::ProcessPlatformProperty(wxXmlNode *node)
{
wxString s;
}
else str2 << *dt;
}
- return str2;
+
+ if (m_Resource->GetUseLocale())
+ return wxGetTranslation(str2);
+ else
+ return str2;
}
wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
{
- return GetNodeContent(GetParamNode(param));
+ if (param.IsEmpty())
+ return GetNodeContent(m_Node);
+ else
+ return GetNodeContent(GetParamNode(param));
}
+wxFont wxXmlResourceHandler::GetFont(const wxString& param)
+{
+ wxXmlNode *font_node = GetParamNode(param);
+ if (font_node == NULL)
+ {
+ wxLogError("Cannot find font node '%s'.", param.mb_str());
+ return wxNullFont;
+ }
+
+ wxXmlNode *oldnode = m_Node;
+ m_Node = font_node;
+
+ long size = GetLong(_("size"), 12);
+
+ wxString style = GetParamValue(_("style"));
+ wxString weight = GetParamValue(_("weight"));
+ int istyle = wxNORMAL, iweight = wxNORMAL;
+ if (style == _("italic")) istyle = wxITALIC;
+ else if (style == _("slant")) istyle = wxSLANT;
+ if (weight == _("bold")) iweight = wxBOLD;
+ else if (weight == _("light")) iweight = wxLIGHT;
+
+ bool underlined = GetBool(_("underlined"), FALSE);
+
+ wxString encoding = GetParamValue(_("encoding"));
+ // FIXME - handle encoding
+
+ wxString faces = GetParamValue(_("face"));
+ wxString facename = wxEmptyString;
+ wxFontEnumerator enu;
+ enu.EnumerateFacenames();
+ wxStringTokenizer tk(faces, ",");
+ while (tk.HasMoreTokens())
+ {
+ int index = enu.GetFacenames()->Index(tk.GetNextToken(), FALSE);
+ if (index != wxNOT_FOUND)
+ {
+ facename = (*enu.GetFacenames())[index];
+ break;
+ }
+ }
+
+ m_Node = oldnode;
+
+ wxFont font(size, wxDEFAULT, istyle, iweight, underlined,
+ facename, wxFONTENCODING_DEFAULT);
+ return font;
+}
+
+
void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
{
- //FIXME : add font, cursor
+ //FIXME : add cursor
if (HasParam(_T("exstyle")))
wnd->SetExtraStyle(GetStyle(_T("exstyle")));
if (HasParam(_T("tooltip")))
wnd->SetToolTip(GetText(_T("tooltip")));
#endif
+ if (HasParam(_T("font")))
+ wnd->SetFont(GetFont());
}