Merge branch 'xrc-use-bmpbundle'
Use wxBitmapBundle in more XRC handlers and other minor XRC-related improvements. See #22144.
This commit is contained in:
@@ -112,14 +112,14 @@ bool wxMenuItem::IsChecked() const
|
||||
}
|
||||
|
||||
|
||||
void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
|
||||
void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap)
|
||||
{
|
||||
if ( m_kind == wxITEM_NORMAL )
|
||||
{
|
||||
m_bitmap = bitmap;
|
||||
if ( !m_bitmap.IsNull() )
|
||||
if ( m_bitmap.IsOk() )
|
||||
{
|
||||
m_qtAction->setIcon( QIcon(*m_bitmap.GetHandle()) );
|
||||
m_qtAction->setIcon( QIcon(*GetBitmapFromBundle(m_bitmap).GetHandle()) );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1550,8 +1550,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
|
||||
m_radioGroup.start = -1;
|
||||
m_isRadioGroupStart = false;
|
||||
|
||||
m_bmpDisabled = wxNullBitmap;
|
||||
|
||||
UpdateAccelInfo();
|
||||
}
|
||||
|
||||
@@ -1615,8 +1613,8 @@ void wxMenuItem::SetCheckable(bool checkable)
|
||||
}
|
||||
}
|
||||
|
||||
void wxMenuItem::SetBitmaps(const wxBitmap& bmpChecked,
|
||||
const wxBitmap& bmpUnchecked)
|
||||
void wxMenuItem::SetBitmaps(const wxBitmapBundle& bmpChecked,
|
||||
const wxBitmapBundle& bmpUnchecked)
|
||||
{
|
||||
m_bmpChecked = bmpChecked;
|
||||
m_bmpUnchecked = bmpUnchecked;
|
||||
|
||||
@@ -61,9 +61,10 @@ wxObject *wxAnimationCtrlXmlHandler::DoCreateResource()
|
||||
if ( animation )
|
||||
ctrl->SetAnimation(*animation);
|
||||
|
||||
// if no inactive-bitmap has been provided, GetBitmap() will return wxNullBitmap
|
||||
// which just tells wxAnimationCtrl to use the default for inactive status
|
||||
ctrl->SetInactiveBitmap(GetBitmap(wxT("inactive-bitmap")));
|
||||
// if no inactive-bitmap has been provided, GetBitmapBundle() will return
|
||||
// an empty bundle, which just tells wxAnimationCtrl to use the default
|
||||
// bitmap for inactive status
|
||||
ctrl->SetInactiveBitmap(GetBitmapBundle(wxT("inactive-bitmap")));
|
||||
|
||||
SetupWindow(ctrl);
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ wxObject *wxAuiXmlHandler::DoCreateResource()
|
||||
m_notebook->AddPage(wnd,
|
||||
GetText(wxS("label")),
|
||||
GetBool(wxS("selected")),
|
||||
GetBitmap(wxS("bitmap"), wxART_OTHER));
|
||||
GetBitmapBundle(wxS("bitmap"), wxART_OTHER));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -111,8 +111,8 @@ wxObject *wxAuiToolBarXmlHandler::DoCreateResource()
|
||||
(
|
||||
GetID(),
|
||||
GetText(wxS("label")),
|
||||
GetBitmap(wxS("bitmap"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmap(wxS("bitmap2"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmapBundle(wxS("bitmap"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmapBundle(wxS("bitmap2"), wxART_TOOLBAR, m_toolSize),
|
||||
kind,
|
||||
GetText(wxS("tooltip")),
|
||||
GetText(wxS("longhelp")),
|
||||
|
||||
@@ -56,7 +56,7 @@ wxObject *wxBannerWindowXmlHandler::DoCreateResource()
|
||||
}
|
||||
}
|
||||
|
||||
wxBitmap bitmap = GetBitmap();
|
||||
wxBitmapBundle bitmap = GetBitmapBundle();
|
||||
if ( bitmap.IsOk() )
|
||||
{
|
||||
if ( colStart.IsOk() || colEnd.IsOk() )
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
|
||||
#include "wx/xrc/xh_bmpbt.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/bmpbuttn.h"
|
||||
#endif
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxBitmapButtonXmlHandler, wxXmlResourceHandler);
|
||||
|
||||
wxBitmapButtonXmlHandler::wxBitmapButtonXmlHandler()
|
||||
@@ -33,6 +29,27 @@ wxBitmapButtonXmlHandler::wxBitmapButtonXmlHandler()
|
||||
AddWindowStyles();
|
||||
}
|
||||
|
||||
// Function calls the given setter with the contents of the node with the given
|
||||
// name, if present.
|
||||
//
|
||||
// If alternative parameter name is specified, it is used too.
|
||||
void
|
||||
wxBitmapButtonXmlHandler::SetBitmapIfSpecified(wxBitmapButton* button,
|
||||
BitmapSetter setter,
|
||||
const char* paramName,
|
||||
const char* paramNameAlt)
|
||||
{
|
||||
if ( wxXmlNode* const node = GetParamNode(paramName) )
|
||||
{
|
||||
(button->*setter)(GetBitmapBundle(node));
|
||||
}
|
||||
else if ( paramNameAlt )
|
||||
{
|
||||
if ( wxXmlNode* const nodeAlt = GetParamNode(paramNameAlt) )
|
||||
(button->*setter)(GetBitmap(nodeAlt));
|
||||
}
|
||||
}
|
||||
|
||||
wxObject *wxBitmapButtonXmlHandler::DoCreateResource()
|
||||
{
|
||||
XRC_MAKE_INSTANCE(button, wxBitmapButton)
|
||||
@@ -47,7 +64,7 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource()
|
||||
{
|
||||
button->Create(m_parentAsWindow,
|
||||
GetID(),
|
||||
GetBitmap(wxT("bitmap"), wxART_BUTTON),
|
||||
GetBitmapBundle(wxT("bitmap"), wxART_BUTTON),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(wxT("style")),
|
||||
wxDefaultValidator,
|
||||
@@ -58,14 +75,12 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource()
|
||||
button->SetDefault();
|
||||
SetupWindow(button);
|
||||
|
||||
if (GetParamNode(wxT("selected")))
|
||||
button->SetBitmapSelected(GetBitmap(wxT("selected")));
|
||||
if (GetParamNode(wxT("focus")))
|
||||
button->SetBitmapFocus(GetBitmap(wxT("focus")));
|
||||
if (GetParamNode(wxT("disabled")))
|
||||
button->SetBitmapDisabled(GetBitmap(wxT("disabled")));
|
||||
if (GetParamNode(wxT("hover")))
|
||||
button->SetBitmapHover(GetBitmap(wxT("hover")));
|
||||
SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapPressed,
|
||||
"pressed", "selected");
|
||||
SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapFocus, "focus");
|
||||
SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapDisabled, "disabled");
|
||||
SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapCurrent,
|
||||
"current", "hover");
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -152,11 +152,11 @@ wxObject *wxMenuXmlHandler::DoCreateResource()
|
||||
// and unchecked bitmaps for menu items
|
||||
#ifdef __WXMSW__
|
||||
if (HasParam(wxT("bitmap2")))
|
||||
mitem->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU),
|
||||
GetBitmap(wxT("bitmap"), wxART_MENU));
|
||||
mitem->SetBitmaps(GetBitmapBundle(wxT("bitmap2"), wxART_MENU),
|
||||
GetBitmapBundle(wxT("bitmap"), wxART_MENU));
|
||||
else
|
||||
#endif // __WXMSW__
|
||||
mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
|
||||
mitem->SetBitmap(GetBitmapBundle(wxT("bitmap"), wxART_MENU));
|
||||
}
|
||||
#endif
|
||||
p_menu->Append(mitem);
|
||||
|
||||
@@ -82,7 +82,7 @@ void wxToggleButtonXmlHandler::DoCreateToggleButton(wxObject *control)
|
||||
#ifdef wxHAVE_BITMAPS_IN_BUTTON
|
||||
if ( GetParamNode("bitmap") )
|
||||
{
|
||||
button->SetBitmap(GetBitmap("bitmap", wxART_BUTTON),
|
||||
button->SetBitmap(GetBitmapBundle("bitmap", wxART_BUTTON),
|
||||
GetDirection("bitmapposition"));
|
||||
}
|
||||
#endif
|
||||
@@ -97,7 +97,7 @@ void wxToggleButtonXmlHandler::DoCreateBitmapToggleButton(wxObject *control)
|
||||
|
||||
button->Create(m_parentAsWindow,
|
||||
GetID(),
|
||||
GetBitmap(wxT("bitmap"), wxART_BUTTON),
|
||||
GetBitmapBundle(wxT("bitmap"), wxART_BUTTON),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
|
||||
@@ -126,8 +126,8 @@ wxObject *wxToolBarXmlHandler::DoCreateResource()
|
||||
(
|
||||
GetID(),
|
||||
GetText(wxT("label")),
|
||||
GetBitmap(wxT("bitmap"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmap(wxT("bitmap2"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmapBundle(wxT("bitmap"), wxART_TOOLBAR, m_toolSize),
|
||||
GetBitmapBundle(wxT("bitmap2"), wxART_TOOLBAR, m_toolSize),
|
||||
kind,
|
||||
GetText(wxT("tooltip")),
|
||||
GetText(wxT("longhelp"))
|
||||
|
||||
@@ -1946,16 +1946,27 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
const wxArtClient& defaultArtClient,
|
||||
wxSize size)
|
||||
{
|
||||
wxASSERT_MSG( !param.empty(), "bitmap parameter name can't be empty" );
|
||||
wxASSERT_MSG( !param.empty(), "bitmap bundle 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 wxBitmapBundle();
|
||||
}
|
||||
|
||||
return GetBitmapBundle(node, defaultArtClient, size);
|
||||
}
|
||||
|
||||
wxBitmapBundle
|
||||
wxXmlResourceHandlerImpl::GetBitmapBundle(const wxXmlNode* node,
|
||||
const wxArtClient& defaultArtClient,
|
||||
wxSize size)
|
||||
{
|
||||
if ( !node )
|
||||
return wxBitmapBundle();
|
||||
|
||||
/* If the bitmap is specified as stock item, query wxArtProvider for it: */
|
||||
wxString art_id, art_client;
|
||||
if ( GetStockArtAttrs(node, defaultArtClient,
|
||||
@@ -1974,7 +1985,7 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
{
|
||||
ReportParamError
|
||||
(
|
||||
param,
|
||||
node->GetName(),
|
||||
"may contain either one SVG file or a list of files separated by ';'"
|
||||
);
|
||||
return bitmapBundle;
|
||||
@@ -1986,21 +1997,23 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
{
|
||||
ReportParamError
|
||||
(
|
||||
param,
|
||||
node->GetName(),
|
||||
"'default_size' attribute required with svg file"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef wxHAS_SVG
|
||||
wxSize svgDefaultSize = ParseStringInPixels(this, param, svgDefaultSizeAttr, wxDefaultSize);
|
||||
wxSize svgDefaultSize = ParseStringInPixels(this, node->GetName(),
|
||||
svgDefaultSizeAttr,
|
||||
wxDefaultSize);
|
||||
#if wxUSE_FILESYSTEM
|
||||
wxFSFile* fsfile = GetCurFileSystem().OpenFile(paramValue, wxFS_READ | wxFS_SEEKABLE);
|
||||
if (fsfile == NULL)
|
||||
{
|
||||
ReportParamError
|
||||
(
|
||||
param,
|
||||
node->GetName(),
|
||||
wxString::Format("cannot open SVG resource \"%s\"", paramValue)
|
||||
);
|
||||
}
|
||||
@@ -2023,7 +2036,7 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
#else // !wxHAS_SVG
|
||||
ReportParamError
|
||||
(
|
||||
param,
|
||||
node->GetName(),
|
||||
"SVG bitmaps are not supported in this build of the library"
|
||||
);
|
||||
#endif // wxHAS_SVG/!wxHAS_SVG
|
||||
@@ -2035,7 +2048,7 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
{
|
||||
ReportParamError
|
||||
(
|
||||
param,
|
||||
node->GetName(),
|
||||
"may contain either one SVG file or a list of files separated by ';'"
|
||||
);
|
||||
return bitmapBundle;
|
||||
@@ -2046,7 +2059,7 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param,
|
||||
wxArrayString paths = wxSplit(paramValue, ';', '\0');
|
||||
for ( wxArrayString::const_iterator i = paths.begin(); i != paths.end(); ++i )
|
||||
{
|
||||
wxBitmap bmpNext = LoadBitmapFromFS(this, *i, size, param);
|
||||
wxBitmap bmpNext = LoadBitmapFromFS(this, *i, size, node->GetName());
|
||||
if ( !bmpNext.IsOk() )
|
||||
{
|
||||
// error in loading wxBitmap, return invalid wxBitmapBundle
|
||||
|
||||
Reference in New Issue
Block a user