added <bitmap> and <icon> resources
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8390 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
38
contrib/include/wx/xml/xh_bmp.h
Normal file
38
contrib/include/wx/xml/xh_bmp.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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_
|
@@ -57,8 +57,11 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
|
||||
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.
|
||||
@@ -106,6 +109,10 @@ class WXDLLEXPORT wxXmlResource : public wxObject
|
||||
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
|
||||
@@ -125,8 +132,11 @@ class WXDLLEXPORT wxXmlResource : public wxObject
|
||||
// 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
|
||||
@@ -156,7 +166,6 @@ extern wxXmlResource *wxTheXmlResource;
|
||||
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.
|
||||
@@ -226,8 +235,8 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
// 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
|
||||
@@ -236,7 +245,7 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
// 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
|
||||
@@ -263,6 +272,9 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
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);
|
||||
|
||||
|
60
contrib/src/xml/xh_bmp.cpp
Normal file
60
contrib/src/xml/xh_bmp.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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");
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#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"
|
||||
@@ -37,13 +38,15 @@
|
||||
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);
|
||||
}
|
||||
@@ -176,6 +179,28 @@ bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString&
|
||||
|
||||
|
||||
|
||||
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;
|
||||
@@ -458,7 +483,11 @@ wxString wxXmlResourceHandler::GetText(const wxString& param)
|
||||
}
|
||||
else str2 << *dt;
|
||||
}
|
||||
return str2;
|
||||
|
||||
if (m_Resource->GetUseLocale())
|
||||
return wxGetTranslation(str2);
|
||||
else
|
||||
return str2;
|
||||
}
|
||||
|
||||
|
||||
@@ -615,7 +644,10 @@ wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node)
|
||||
|
||||
wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
|
||||
{
|
||||
return GetNodeContent(GetParamNode(param));
|
||||
if (param.IsEmpty())
|
||||
return GetNodeContent(m_Node);
|
||||
else
|
||||
return GetNodeContent(GetParamNode(param));
|
||||
}
|
||||
|
||||
|
||||
@@ -695,9 +727,59 @@ wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaul
|
||||
|
||||
|
||||
|
||||
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")));
|
||||
@@ -715,6 +797,8 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
|
||||
if (HasParam(_T("tooltip")))
|
||||
wnd->SetToolTip(GetText(_T("tooltip")));
|
||||
#endif
|
||||
if (HasParam(_T("font")))
|
||||
wnd->SetFont(GetFont());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user