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
This commit is contained in:
parent
b5c2a33438
commit
1c60f64458
@ -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"));
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1230,32 +1230,50 @@ 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);
|
||||
wxBitmap stockArt(wxArtProvider::GetBitmap(art_id, art_client, size));
|
||||
if ( stockArt.Ok() )
|
||||
return stockArt;
|
||||
}
|
||||
}
|
||||
|
||||
/* ...or load the bitmap from file: */
|
||||
wxString name = GetParamValue(param);
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user