From 1c60f644581df7bfc4b44d9ad68ee94ff728ceb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 29 Mar 2009 21:25:23 +0000 Subject: [PATCH] set icons bundle, not single icon, for frames loaded from XRC git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59931 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/xrc/xmlres.h | 5 ++ interface/wx/xrc/xmlres.h | 13 ++++++ src/xrc/xh_dlg.cpp | 2 +- src/xrc/xh_frame.cpp | 2 +- src/xrc/xh_mdi.cpp | 2 +- src/xrc/xh_propdlg.cpp | 3 +- src/xrc/xmlres.cpp | 98 ++++++++++++++++++++++++++++++++------- 7 files changed, 104 insertions(+), 21 deletions(-) diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 0f0b69aa92..3ec28e0da7 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -33,6 +33,7 @@ class WXDLLIMPEXP_FWD_BASE wxFileName; +class WXDLLIMPEXP_FWD_CORE wxIconBundle; class WXDLLIMPEXP_FWD_CORE wxMenu; class WXDLLIMPEXP_FWD_CORE wxMenuBar; class WXDLLIMPEXP_FWD_CORE wxDialog; @@ -508,6 +509,10 @@ protected: const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); + // Gets an icon bundle. + wxIconBundle GetIconBundle(const wxString& param, + const wxArtClient& defaultArtClient = wxART_OTHER); + #if wxUSE_ANIMATIONCTRL // Gets an animation. wxAnimation GetAnimation(const wxString& param = wxT("animation")); diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index 5bd3bce792..c07f44c017 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -532,6 +532,19 @@ protected: const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); + /** + Returns an icon bundle. + + @note + Bundles can be loaded either with stock IDs or from files that contain + more than one image (e.g. Windows icon files). If a file contains only + single image, a bundle with only one icon will be created. + + @since 2.9.0 + */ + wxIconBundle GetIconBundle(const wxString& param, + const wxArtClient& defaultArtClient = wxART_OTHER); + /** Gets the integer value from the parameter. */ diff --git a/src/xrc/xh_dlg.cpp b/src/xrc/xh_dlg.cpp index cd50f4a96c..268d60f4f1 100644 --- a/src/xrc/xh_dlg.cpp +++ b/src/xrc/xh_dlg.cpp @@ -73,7 +73,7 @@ wxObject *wxDialogXmlHandler::DoCreateResource() if (HasParam(wxT("pos"))) dlg->Move(GetPosition()); if (HasParam(wxT("icon"))) - dlg->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON)); + dlg->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON)); SetupWindow(dlg); diff --git a/src/xrc/xh_frame.cpp b/src/xrc/xh_frame.cpp index 892a9e38aa..b575f8bd8b 100644 --- a/src/xrc/xh_frame.cpp +++ b/src/xrc/xh_frame.cpp @@ -79,7 +79,7 @@ wxObject *wxFrameXmlHandler::DoCreateResource() if (HasParam(wxT("pos"))) frame->Move(GetPosition()); if (HasParam(wxT("icon"))) - frame->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON)); + frame->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON)); SetupWindow(frame); diff --git a/src/xrc/xh_mdi.cpp b/src/xrc/xh_mdi.cpp index f6fea842dd..50a7ed1cb7 100644 --- a/src/xrc/xh_mdi.cpp +++ b/src/xrc/xh_mdi.cpp @@ -117,7 +117,7 @@ wxObject *wxMdiXmlHandler::DoCreateResource() { wxFrame* f = wxDynamicCast(frame, wxFrame); if (f) - f->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON)); + f->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON)); } SetupWindow(frame); diff --git a/src/xrc/xh_propdlg.cpp b/src/xrc/xh_propdlg.cpp index 0dd4f168f8..8a7b102e93 100644 --- a/src/xrc/xh_propdlg.cpp +++ b/src/xrc/xh_propdlg.cpp @@ -113,7 +113,8 @@ wxObject *wxPropertySheetDialogXmlHandler::DoCreateResource() GetStyle(), GetName()); - if (HasParam(wxT("icon"))) dlg->SetIcon(GetIcon(wxT("icon"), wxART_FRAME_ICON)); + if (HasParam(wxT("icon"))) + dlg->SetIcons(GetIconBundle(wxT("icon"), wxART_FRAME_ICON)); SetupWindow(dlg); diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 075489d9e7..d16bc62363 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1230,31 +1230,49 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param, const wxColour& return clr; } +namespace +{ + +// if 'param' has stock_id/stock_client, extracts them and returns true +bool GetStockArtAttrs(const wxXmlNode *paramNode, + const wxString& defaultArtClient, + wxString& art_id, wxString& art_client) +{ + if ( paramNode ) + { + art_id = paramNode->GetAttribute("stock_id", ""); + + if ( !art_id.empty() ) + { + art_id = wxART_MAKE_ART_ID_FROM_STR(art_id); + + art_client = paramNode->GetAttribute("stock_client", ""); + if ( art_client.empty() ) + art_client = defaultArtClient; + else + art_client = wxART_MAKE_CLIENT_ID_FROM_STR(art_client); + return true; + } + } + + return false; +} + +} // anonymous namespace wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, const wxArtClient& defaultArtClient, wxSize size) { /* If the bitmap is specified as stock item, query wxArtProvider for it: */ - wxXmlNode *bmpNode = GetParamNode(param); - if ( bmpNode ) + wxString art_id, art_client; + if ( GetStockArtAttrs(GetParamNode(param), defaultArtClient, + art_id, art_client) ) { - wxString sid = bmpNode->GetAttribute(wxT("stock_id"), wxEmptyString); - if ( !sid.empty() ) - { - wxString scl = bmpNode->GetAttribute(wxT("stock_client"), wxEmptyString); - if (scl.empty()) - scl = defaultArtClient; - else - scl = wxART_MAKE_CLIENT_ID_FROM_STR(scl); - - wxBitmap stockArt = - wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid), - scl, size); - if ( stockArt.Ok() ) - return stockArt; - } + wxBitmap stockArt(wxArtProvider::GetBitmap(art_id, art_client, size)); + if ( stockArt.Ok() ) + return stockArt; } /* ...or load the bitmap from file: */ @@ -1300,6 +1318,52 @@ wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, return icon; } +wxIconBundle wxXmlResourceHandler::GetIconBundle(const wxString& param, + const wxArtClient& defaultArtClient) +{ + wxString art_id, art_client; + if ( GetStockArtAttrs(GetParamNode(param), defaultArtClient, + art_id, art_client) ) + { + wxIconBundle stockArt(wxArtProvider::GetIconBundle(art_id, art_client)); + if ( stockArt.IsOk() ) + return stockArt; + } + + const wxString name = GetParamValue(param); + if ( name.empty() ) + return wxNullIconBundle; + +#if wxUSE_FILESYSTEM + wxFSFile *fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE); + if ( fsfile == NULL ) + { + ReportParamError + ( + param, + wxString::Format("cannot open icon resource \"%s\"", name) + ); + return wxNullIconBundle; + } + + wxIconBundle bundle(*(fsfile->GetStream())); + delete fsfile; +#else + wxIconBundle bundle(name); +#endif + + if ( !bundle.IsOk() ) + { + ReportParamError + ( + param, + wxString::Format("cannot create icon from \"%s\"", name) + ); + return wxNullIconBundle; + } + + return bundle; +} wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param) -- 2.45.2