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.
This commit is contained in:
Vadim Zeitlin
2022-02-20 01:44:48 +00:00
parent f4e3b69dd2
commit 652d37ea61
4 changed files with 27 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -219,6 +219,7 @@
<border>5</border>
<object class="wxBitmapButton" name="controls_bitmapbutton">
<bitmap>controls.xpm</bitmap>
<current>custclas.xpm</current>
</object>
</object>
<object class="sizeritem">

View File

@@ -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;
}