X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/44108a078fae492eadbef70c1256c3625d95e676..a6982a3882f976f5764c0bac808cc3fd64c9a7f3:/src/xrc/xmlres.cpp diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index e9942ba285..5b21be5d36 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -44,6 +44,7 @@ #include "wx/fontenum.h" #include "wx/fontmap.h" #include "wx/artprov.h" +#include "wx/imaglist.h" #include "wx/dir.h" #include "wx/xml/xml.h" @@ -1333,9 +1334,32 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, const wxArtClient& defaultArtClient, wxSize size) { + // it used to be possible to pass an empty string here to indicate that the + // bitmap name should be read from this node itself but this is not + // supported any more because GetBitmap(m_node) can be used directly + // instead + wxASSERT_MSG( !param.empty(), "bitmap parameter name can't be empty" ); + + const wxXmlNode* const node = GetParamNode(param); + + if ( !node ) + { + // this is not an error as bitmap parameter could be optional + return wxNullBitmap; + } + + return GetBitmap(node, defaultArtClient, size); +} + +wxBitmap wxXmlResourceHandler::GetBitmap(const wxXmlNode* node, + const wxArtClient& defaultArtClient, + wxSize size) +{ + wxCHECK_MSG( node, wxNullBitmap, "bitmap node can't be NULL" ); + /* If the bitmap is specified as stock item, query wxArtProvider for it: */ wxString art_id, art_client; - if ( GetStockArtAttrs(GetParamNode(param), defaultArtClient, + if ( GetStockArtAttrs(node, defaultArtClient, art_id, art_client) ) { wxBitmap stockArt(wxArtProvider::GetBitmap(art_id, art_client, size)); @@ -1344,7 +1368,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, } /* ...or load the bitmap from file: */ - wxString name = GetParamValue(param); + wxString name = GetParamValue(node); if (name.empty()) return wxNullBitmap; #if wxUSE_FILESYSTEM wxFSFile *fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE); @@ -1352,7 +1376,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, { ReportParamError ( - param, + node->GetName(), wxString::Format("cannot open bitmap resource \"%s\"", name) ); return wxNullBitmap; @@ -1367,7 +1391,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, { ReportParamError ( - param, + node->GetName(), wxString::Format("cannot create bitmap from \"%s\"", name) ); return wxNullBitmap; @@ -1380,12 +1404,31 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, const wxArtClient& defaultArtClient, wxSize size) +{ + // see comment in GetBitmap(wxString) overload + wxASSERT_MSG( !param.empty(), "icon parameter name can't be empty" ); + + const wxXmlNode* const node = GetParamNode(param); + + if ( !node ) + { + // this is not an error as icon parameter could be optional + return wxIcon(); + } + + return GetIcon(node, defaultArtClient, size); +} + +wxIcon wxXmlResourceHandler::GetIcon(const wxXmlNode* node, + const wxArtClient& defaultArtClient, + wxSize size) { wxIcon icon; - icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size)); + icon.CopyFromBitmap(GetBitmap(node, defaultArtClient, size)); return icon; } + wxIconBundle wxXmlResourceHandler::GetIconBundle(const wxString& param, const wxArtClient& defaultArtClient) { @@ -1434,6 +1477,46 @@ wxIconBundle wxXmlResourceHandler::GetIconBundle(const wxString& param, } +wxImageList *wxXmlResourceHandler::GetImageList(const wxString& param) +{ + wxXmlNode * const imagelist_node = GetParamNode(param); + if ( !imagelist_node ) + return NULL; + + wxXmlNode * const oldnode = m_node; + m_node = imagelist_node; + + // size + wxSize size = GetSize(); + size.SetDefaults(wxSize(wxSystemSettings::GetMetric(wxSYS_ICON_X), + wxSystemSettings::GetMetric(wxSYS_ICON_Y))); + + // mask: true by default + bool mask = HasParam(wxT("mask")) ? GetBool(wxT("mask"), true) : true; + + // now we have everything we need to create the image list + wxImageList *imagelist = new wxImageList(size.x, size.y, mask); + + // add images + wxString parambitmap = wxT("bitmap"); + if ( HasParam(parambitmap) ) + { + wxXmlNode *n = m_node->GetChildren(); + while (n) + { + if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == parambitmap) + { + // add icon instead of bitmap to keep the bitmap mask + imagelist->Add(GetIcon(n)); + } + n = n->GetNext(); + } + } + + m_node = oldnode; + return imagelist; +} + wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param) { wxCHECK_MSG(m_node, NULL, wxT("You can't access handler data before it was initialized!")); @@ -1464,9 +1547,9 @@ bool wxXmlResourceHandler::IsOfClass(wxXmlNode *node, const wxString& classname) -wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node) +wxString wxXmlResourceHandler::GetNodeContent(const wxXmlNode *node) { - wxXmlNode *n = node; + const wxXmlNode *n = node; if (n == NULL) return wxEmptyString; n = n->GetChildren(); @@ -1490,6 +1573,10 @@ wxString wxXmlResourceHandler::GetParamValue(const wxString& param) return GetNodeContent(GetParamNode(param)); } +wxString wxXmlResourceHandler::GetParamValue(const wxXmlNode* node) +{ + return GetNodeContent(node); +} wxSize wxXmlResourceHandler::GetSize(const wxString& param, @@ -1763,8 +1850,12 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd) wnd->SetExtraStyle(wnd->GetExtraStyle() | GetStyle(wxT("exstyle"))); if (HasParam(wxT("bg"))) wnd->SetBackgroundColour(GetColour(wxT("bg"))); + if (HasParam(wxT("ownbg"))) + wnd->SetOwnBackgroundColour(GetColour(wxT("ownbg"))); if (HasParam(wxT("fg"))) wnd->SetForegroundColour(GetColour(wxT("fg"))); + if (HasParam(wxT("ownfg"))) + wnd->SetOwnForegroundColour(GetColour(wxT("ownfg"))); if (GetBool(wxT("enabled"), 1) == 0) wnd->Enable(false); if (GetBool(wxT("focused"), 0) == 1) @@ -1776,7 +1867,9 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd) wnd->SetToolTip(GetText(wxT("tooltip"))); #endif if (HasParam(wxT("font"))) - wnd->SetFont(GetFont()); + wnd->SetFont(GetFont(wxT("font"))); + if (HasParam(wxT("ownfont"))) + wnd->SetOwnFont(GetFont(wxT("ownfont"))); if (HasParam(wxT("help"))) wnd->SetHelpText(GetText(wxT("help"))); }