From dec0c1b5b60d406a0905bc4ede137c474fc021df Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 00:54:00 +0000 Subject: [PATCH 1/7] Don't return wxNullBitmap from XRC GetBitmapBundle() Return an empty bundle directly instead of relying on conversion from invalid bitmap. --- src/xrc/xmlres.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 53dca74238..929b7a0002 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1953,7 +1953,7 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param, if ( !node ) { // this is not an error as bitmap parameter could be optional - return wxNullBitmap; + return wxBitmapBundle(); } /* If the bitmap is specified as stock item, query wxArtProvider for it: */ From 5fcea04d71b65ddff96146ed4d693776e0030cfc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 17:54:52 +0100 Subject: [PATCH 2/7] Take wxBitmapBundle in wxMenuItem::SetBitmap() in all ports Update the remaining ports to take wxBitmapBundle rather than wxBitmap as well to make their API consistent with the tier 1 ports -- even if there is no actual support for choosing the resolution-appropriate bitmap in them yet. --- include/wx/motif/menuitem.h | 6 +++--- include/wx/qt/menuitem.h | 6 +++--- include/wx/univ/menuitem.h | 22 +++++++++++----------- src/qt/menuitem.cpp | 6 +++--- src/univ/menu.cpp | 6 ++---- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/wx/motif/menuitem.h b/include/wx/motif/menuitem.h index 456358a2de..3e539a44d7 100644 --- a/include/wx/motif/menuitem.h +++ b/include/wx/motif/menuitem.h @@ -39,8 +39,8 @@ public: // I'm not sure if this works but it silences the linker in the // menu sample. // JJ - virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } - virtual const wxBitmap& GetBitmap() const { return m_bitmap; } + virtual void SetBitmap(const wxBitmapBundle& bitmap) { m_bitmap = bitmap; } + virtual wxBitmap GetBitmap() const { return GetBitmapFromBundle(m_bitmap); } // implementation from now on void CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu, @@ -59,7 +59,7 @@ private: WXWidget m_buttonWidget; wxMenuBar* m_menuBar; wxMenu* m_topMenu; // Top-level menu e.g. popup-menu - wxBitmap m_bitmap; // Bitmap for menuitem, if any + wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any wxDECLARE_DYNAMIC_CLASS(wxMenuItem); }; diff --git a/include/wx/qt/menuitem.h b/include/wx/qt/menuitem.h index f5219cd1a9..63d59ffce9 100644 --- a/include/wx/qt/menuitem.h +++ b/include/wx/qt/menuitem.h @@ -35,8 +35,8 @@ public: virtual void Check(bool check = true) wxOVERRIDE; virtual bool IsChecked() const wxOVERRIDE; - virtual void SetBitmap(const wxBitmap& bitmap); - virtual const wxBitmap& GetBitmap() const { return m_bitmap; } + virtual void SetBitmap(const wxBitmapBundle& bitmap); + virtual wxBitmap GetBitmap() const { return GetBitmapFromBundle(m_bitmap); } virtual QAction *GetHandle() const; @@ -44,7 +44,7 @@ public: private: // Qt is using an action instead of a menu item. wxQtAction *m_qtAction; - wxBitmap m_bitmap; + wxBitmapBundle m_bitmap; wxDECLARE_DYNAMIC_CLASS( wxMenuItem ); }; diff --git a/include/wx/univ/menuitem.h b/include/wx/univ/menuitem.h index 281c919cc7..d2b3717cd4 100644 --- a/include/wx/univ/menuitem.h +++ b/include/wx/univ/menuitem.h @@ -37,16 +37,16 @@ public: // we add some extra functions which are also available under MSW from // wxOwnerDrawn class - they will be moved to wxMenuItemBase later // hopefully - void SetBitmaps(const wxBitmap& bmpChecked, - const wxBitmap& bmpUnchecked = wxNullBitmap); - void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); } - const wxBitmap& GetBitmap(bool checked = true) const - { return checked ? m_bmpChecked : m_bmpUnchecked; } + void SetBitmaps(const wxBitmapBundle& bmpChecked, + const wxBitmapBundle& bmpUnchecked = wxBitmapBundle()); + void SetBitmap(const wxBitmapBundle& bmp) { SetBitmaps(bmp); } + wxBitmap GetBitmap(bool checked = true) const + { return GetBitmapFromBundle(checked ? m_bmpChecked : m_bmpUnchecked); } - void SetDisabledBitmap( const wxBitmap& bmpDisabled ) + void SetDisabledBitmap( const wxBitmapBundle& bmpDisabled ) { m_bmpDisabled = bmpDisabled; } - const wxBitmap& GetDisabledBitmap() const - { return m_bmpDisabled; } + wxBitmap GetDisabledBitmap() const + { return GetBitmapFromBundle(m_bmpDisabled); } // mark item as belonging to the given radio group void SetAsRadioGroupStart(); @@ -93,9 +93,9 @@ protected: void UpdateAccelInfo(); // the bitmaps (may be invalid, then they're not used) - wxBitmap m_bmpChecked, - m_bmpUnchecked, - m_bmpDisabled; + wxBitmapBundle m_bmpChecked, + m_bmpUnchecked, + m_bmpDisabled; // the positions of the first and last items of the radio group this item // belongs to or -1: start is the radio group start and is valid for all diff --git a/src/qt/menuitem.cpp b/src/qt/menuitem.cpp index 97a85fdb37..f589389a4a 100644 --- a/src/qt/menuitem.cpp +++ b/src/qt/menuitem.cpp @@ -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 diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index 99fe79c716..21718a9ba9 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -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; From 38ad81716311bb90fa260cd5fffdde0b0a7e16c6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 01:02:52 +0000 Subject: [PATCH 3/7] Use GetBitmapBundle() whenever possible in XRC handlers This allows specifying multiple bitmaps and/or SVG in the XRC for the controls which support them. --- src/xrc/xh_animatctrl.cpp | 7 ++++--- src/xrc/xh_aui.cpp | 2 +- src/xrc/xh_auitoolb.cpp | 4 ++-- src/xrc/xh_bannerwindow.cpp | 2 +- src/xrc/xh_menu.cpp | 6 +++--- src/xrc/xh_tglbtn.cpp | 4 ++-- src/xrc/xh_toolb.cpp | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/xrc/xh_animatctrl.cpp b/src/xrc/xh_animatctrl.cpp index aafa6da0a3..8f2f98c228 100644 --- a/src/xrc/xh_animatctrl.cpp +++ b/src/xrc/xh_animatctrl.cpp @@ -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); diff --git a/src/xrc/xh_aui.cpp b/src/xrc/xh_aui.cpp index 141375fefb..d81e618ada 100644 --- a/src/xrc/xh_aui.cpp +++ b/src/xrc/xh_aui.cpp @@ -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 { diff --git a/src/xrc/xh_auitoolb.cpp b/src/xrc/xh_auitoolb.cpp index 6d713637e6..e94a0e37e7 100644 --- a/src/xrc/xh_auitoolb.cpp +++ b/src/xrc/xh_auitoolb.cpp @@ -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")), diff --git a/src/xrc/xh_bannerwindow.cpp b/src/xrc/xh_bannerwindow.cpp index 408e97ac01..56c5cb3a9c 100644 --- a/src/xrc/xh_bannerwindow.cpp +++ b/src/xrc/xh_bannerwindow.cpp @@ -56,7 +56,7 @@ wxObject *wxBannerWindowXmlHandler::DoCreateResource() } } - wxBitmap bitmap = GetBitmap(); + wxBitmapBundle bitmap = GetBitmapBundle(); if ( bitmap.IsOk() ) { if ( colStart.IsOk() || colEnd.IsOk() ) diff --git a/src/xrc/xh_menu.cpp b/src/xrc/xh_menu.cpp index 5d769e9b66..1c7e755645 100644 --- a/src/xrc/xh_menu.cpp +++ b/src/xrc/xh_menu.cpp @@ -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); diff --git a/src/xrc/xh_tglbtn.cpp b/src/xrc/xh_tglbtn.cpp index 45cd2fd8bf..1777bca82e 100644 --- a/src/xrc/xh_tglbtn.cpp +++ b/src/xrc/xh_tglbtn.cpp @@ -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, diff --git a/src/xrc/xh_toolb.cpp b/src/xrc/xh_toolb.cpp index 8348c55433..407c854766 100644 --- a/src/xrc/xh_toolb.cpp +++ b/src/xrc/xh_toolb.cpp @@ -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")) From f077169c865d45b4d3aa73e105ebe79def989a1e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 01:16:57 +0000 Subject: [PATCH 4/7] Refactor wxBitmapButtonXmlHandler before using wxBitmapBundle This replaces 4 calls to GetBitmap() with a single one. Note that we now use SetBitmapPressed() and SetBitmapCurrent(), which take wxBitmapBundle, instead of deprecated SetBitmapSelected() and SetBitmapFocus(), which do not. We also search for the parameter node only once instead of doing it twice in a row if it was found, so the new code is slightly more efficient. --- include/wx/xrc/xh_bmpbt.h | 9 +++++++++ src/xrc/xh_bmpbt.cpp | 28 ++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/wx/xrc/xh_bmpbt.h b/include/wx/xrc/xh_bmpbt.h index 4e016a1ed5..e215f90613 100644 --- a/include/wx/xrc/xh_bmpbt.h +++ b/include/wx/xrc/xh_bmpbt.h @@ -14,6 +14,8 @@ #if wxUSE_XRC && wxUSE_BMPBUTTON +#include "wx/bmpbuttn.h" + class WXDLLIMPEXP_XRC wxBitmapButtonXmlHandler : public wxXmlResourceHandler { wxDECLARE_DYNAMIC_CLASS(wxBitmapButtonXmlHandler); @@ -22,6 +24,13 @@ public: wxBitmapButtonXmlHandler(); virtual wxObject *DoCreateResource() wxOVERRIDE; virtual bool CanHandle(wxXmlNode *node) wxOVERRIDE; + +private: + typedef void (wxBitmapButton::*BitmapSetter)(const wxBitmapBundle&); + + void SetBitmapIfSpecified(wxBitmapButton* button, + BitmapSetter setter, + const char* paramName); }; #endif // wxUSE_XRC && wxUSE_BMPBUTTON diff --git a/src/xrc/xh_bmpbt.cpp b/src/xrc/xh_bmpbt.cpp index 822fb2b235..210c95dae5 100644 --- a/src/xrc/xh_bmpbt.cpp +++ b/src/xrc/xh_bmpbt.cpp @@ -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,18 @@ wxBitmapButtonXmlHandler::wxBitmapButtonXmlHandler() AddWindowStyles(); } +// Function calls the given setter with the contents of the node with the given +// name, if present. +void +wxBitmapButtonXmlHandler::SetBitmapIfSpecified(wxBitmapButton* button, + BitmapSetter setter, + const char* paramName) +{ + wxXmlNode* const node = GetParamNode(paramName); + if ( node ) + (button->*setter)(GetBitmap(node)); +} + wxObject *wxBitmapButtonXmlHandler::DoCreateResource() { XRC_MAKE_INSTANCE(button, wxBitmapButton) @@ -58,14 +66,10 @@ 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, "selected"); + SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapFocus, "focus"); + SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapDisabled, "disabled"); + SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapCurrent, "hover"); return button; } From 34facd225a40d560572a6f9516c557d457182036 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 01:25:47 +0000 Subject: [PATCH 5/7] Add wxXmlResourceHandler::GetBitmapBundle(wxXmlNode) overload Do it for consistency with the existing GetBitmap() overload and also because this can be useful when we need to test for the bitmap bundle presence before using it. Also document both the new overload and the original one, which was mistakenly left undocumented when it was added. --- include/wx/xrc/xmlres.h | 5 +++++ include/wx/xrc/xmlreshandler.h | 9 +++++++++ interface/wx/xrc/xmlres.h | 17 +++++++++++++++++ src/xrc/xmlres.cpp | 29 +++++++++++++++++++++-------- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 85be98a649..ab7004e67e 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -588,6 +588,11 @@ public: const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), wxSize size = wxDefaultSize) wxOVERRIDE; + // Gets a bitmap bundle from the provided node. + wxBitmapBundle GetBitmapBundle(const wxXmlNode* node, + const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), + wxSize size = wxDefaultSize) wxOVERRIDE; + // Gets an icon. wxIcon GetIcon(const wxString& param = wxT("icon"), const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), diff --git a/include/wx/xrc/xmlreshandler.h b/include/wx/xrc/xmlreshandler.h index 531630dd7b..606eedaa09 100644 --- a/include/wx/xrc/xmlreshandler.h +++ b/include/wx/xrc/xmlreshandler.h @@ -93,6 +93,9 @@ public: virtual wxBitmapBundle GetBitmapBundle(const wxString& param = wxT("bitmap"), const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), wxSize size = wxDefaultSize) = 0; + virtual wxBitmapBundle GetBitmapBundle(const wxXmlNode* node, + const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), + wxSize size = wxDefaultSize) = 0; virtual wxIcon GetIcon(const wxString& param = wxT("icon"), const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), wxSize size = wxDefaultSize) = 0; @@ -341,6 +344,12 @@ protected: { return GetImpl()->GetBitmapBundle(param, defaultArtClient, size); } + wxBitmapBundle GetBitmapBundle(const wxXmlNode* node, + const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), + wxSize size = wxDefaultSize) + { + return GetImpl()->GetBitmapBundle(node, defaultArtClient, size); + } wxIcon GetIcon(const wxString& param = wxT("icon"), const wxArtClient& defaultArtClient = wxASCII_STR(wxART_OTHER), wxSize size = wxDefaultSize) diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index 9a87d7db3c..18741f29ad 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -613,6 +613,23 @@ protected: const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); + /** + Gets a bitmap bundle. + + @since 3.1.6 + */ + wxBitmapBundle GetBitmapBundle(const wxString& param = "bitmap", + const wxArtClient& defaultArtClient = wxART_OTHER, + wxSize size = wxDefaultSize); + /** + Gets a bitmap bundle from the provided node. + + @since 3.1.6 + */ + wxBitmapBundle GetBitmapBundle(const wxXmlNode* node, + const wxArtClient& defaultArtClient = wxART_OTHER, + wxSize size = wxDefaultSize); + /** Gets a bool flag (1, t, yes, on, true are @true, everything else is @false). */ diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 929b7a0002..482084c115 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1946,7 +1946,7 @@ 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); @@ -1956,6 +1956,17 @@ wxBitmapBundle wxXmlResourceHandlerImpl::GetBitmapBundle(const wxString& param, 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 From f4e3b69dd2f8b0469b63eb24ba755923610f6369 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 01:27:40 +0000 Subject: [PATCH 6/7] Use wxBitmapBundle in wxBitmapButtonXmlHandler Allow specifying bundles and not just individual bitmaps in XRC for this control. --- src/xrc/xh_bmpbt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xrc/xh_bmpbt.cpp b/src/xrc/xh_bmpbt.cpp index 210c95dae5..fcf84d56ae 100644 --- a/src/xrc/xh_bmpbt.cpp +++ b/src/xrc/xh_bmpbt.cpp @@ -38,7 +38,7 @@ wxBitmapButtonXmlHandler::SetBitmapIfSpecified(wxBitmapButton* button, { wxXmlNode* const node = GetParamNode(paramName); if ( node ) - (button->*setter)(GetBitmap(node)); + (button->*setter)(GetBitmapBundle(node)); } wxObject *wxBitmapButtonXmlHandler::DoCreateResource() @@ -55,7 +55,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, From 652d37ea61cacdc4ce1e09d65776a195d5e300be Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Feb 2022 01:44:48 +0000 Subject: [PATCH 7/7] Add "pressed" and "current" wxBitmapButton XRC properties New names are consistent with the names of the preferred SetBitmapXXX() functions. Document them and show using one of them in the sample. --- docs/doxygen/overviews/xrc_format.h | 12 ++++++++---- include/wx/xrc/xh_bmpbt.h | 3 ++- samples/xrc/rc/controls.xrc | 1 + src/xrc/xh_bmpbt.cpp | 21 ++++++++++++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index fa222b0f34..9d9b9fdb16 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -832,14 +832,18 @@ Refer to the section @ref xrc_wxtoolbar for more details. 3.1.5.} @row3col{bitmap, @ref overview_xrcformat_type_bitmap, Bitmap to show on the button (default: none).} -@row3col{selected, @ref overview_xrcformat_type_bitmap, - Bitmap to show when the button is selected (default: none, same as @c bitmap).} +@row3col{pressed, @ref overview_xrcformat_type_bitmap, + Bitmap to show when the button is pressed (default: none, same as @c bitmap). + This property exists since wxWidgets 3.1.6, but the equivalent (and still + supported) "selected" property can be used in the older versions.} @row3col{focus, @ref overview_xrcformat_type_bitmap, Bitmap to show when the button has focus (default: none, same as @c bitmap).} @row3col{disabled, @ref overview_xrcformat_type_bitmap, Bitmap to show when the button is disabled (default: none, same as @c bitmap).} -@row3col{hover, @ref overview_xrcformat_type_bitmap, - Bitmap to show when mouse cursor hovers above the bitmap (default: none, same as @c bitmap).} +@row3col{current, @ref overview_xrcformat_type_bitmap, + Bitmap to show when mouse cursor hovers above the bitmap (default: none, same as @c bitmap). + This property exists since wxWidgets 3.1.6, but the equivalent (and still + supported) "hover" property can be used in the older versions.} @endTable diff --git a/include/wx/xrc/xh_bmpbt.h b/include/wx/xrc/xh_bmpbt.h index e215f90613..f3e10b5b2d 100644 --- a/include/wx/xrc/xh_bmpbt.h +++ b/include/wx/xrc/xh_bmpbt.h @@ -30,7 +30,8 @@ private: void SetBitmapIfSpecified(wxBitmapButton* button, BitmapSetter setter, - const char* paramName); + const char* paramName, + const char* paramNameAlt = NULL); }; #endif // wxUSE_XRC && wxUSE_BMPBUTTON diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc index 78c96300d5..638f91a167 100644 --- a/samples/xrc/rc/controls.xrc +++ b/samples/xrc/rc/controls.xrc @@ -219,6 +219,7 @@ 5 controls.xpm + custclas.xpm diff --git a/src/xrc/xh_bmpbt.cpp b/src/xrc/xh_bmpbt.cpp index fcf84d56ae..2c72c54695 100644 --- a/src/xrc/xh_bmpbt.cpp +++ b/src/xrc/xh_bmpbt.cpp @@ -31,14 +31,23 @@ wxBitmapButtonXmlHandler::wxBitmapButtonXmlHandler() // 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* paramName, + const char* paramNameAlt) { - wxXmlNode* const node = GetParamNode(paramName); - if ( node ) + 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() @@ -66,10 +75,12 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource() button->SetDefault(); SetupWindow(button); - SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapPressed, "selected"); + SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapPressed, + "pressed", "selected"); SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapFocus, "focus"); SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapDisabled, "disabled"); - SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapCurrent, "hover"); + SetBitmapIfSpecified(button, &wxBitmapButton::SetBitmapCurrent, + "current", "hover"); return button; }