Add possibility to create "Close" bitmap button from XRC
This requires refactoring NewCloseButton() in order to extract CreateCloseButton() from it, as XRC relies on being able to use two-step creation which was previously impossible for this kind of buttons. CreateCloseButton() is rather unusual, as it has to be declared in the derived, platform-specific class, in order to be able to call its Create(), but is defined only once in common, platform-independent, code. However the only alternative seems to be to have a static function, e.g. InitCloseButton(), which wouldn't be very pretty neither. Closes https://github.com/wxWidgets/wxWidgets/pull/2118
This commit is contained in:
@@ -769,6 +769,11 @@ Refer to the section @ref xrc_wxtoolbar for more details.
|
|||||||
@hdr3col{property, type, description}
|
@hdr3col{property, type, description}
|
||||||
@row3col{default, @ref overview_xrcformat_type_bool,
|
@row3col{default, @ref overview_xrcformat_type_bool,
|
||||||
Should this button be the default button in dialog (default: 0)?}
|
Should this button be the default button in dialog (default: 0)?}
|
||||||
|
@row3col{close, @ref overview_xrcformat_type_bool,
|
||||||
|
If set, this is a special "Close" button using system-defined appearance,
|
||||||
|
see wxBitmapButton::NewCloseButton(). If this property is set, @c bitmap
|
||||||
|
and @c style are ignored and shouldn't be used. Available since wxWidgets
|
||||||
|
3.1.5.}
|
||||||
@row3col{bitmap, @ref overview_xrcformat_type_bitmap,
|
@row3col{bitmap, @ref overview_xrcformat_type_bitmap,
|
||||||
Bitmap to show on the button (default: none).}
|
Bitmap to show on the button (default: none).}
|
||||||
@row3col{selected, @ref overview_xrcformat_type_bitmap,
|
@row3col{selected, @ref overview_xrcformat_type_bitmap,
|
||||||
|
@@ -65,11 +65,25 @@ public:
|
|||||||
validator, name);
|
validator, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Derived classes also need to declare, but not define, as it's done in
|
||||||
|
common code in bmpbtncmn.cpp, the following function:
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
|
which is used used by NewCloseButton(), and, as Create(), must be
|
||||||
|
called on default-constructed wxBitmapButton object.
|
||||||
|
*/
|
||||||
|
|
||||||
// Special creation function for a standard "Close" bitmap. It allows to
|
// Special creation function for a standard "Close" bitmap. It allows to
|
||||||
// simply create a close button with the image appropriate for the current
|
// simply create a close button with the image appropriate for the current
|
||||||
// platform.
|
// platform.
|
||||||
static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
|
static wxBitmapButton*
|
||||||
|
NewCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
// set/get the margins around the button
|
// set/get the margins around the button
|
||||||
virtual void SetMargins(int x, int y)
|
virtual void SetMargins(int x, int y)
|
||||||
|
@@ -39,6 +39,9 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
private:
|
private:
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxBitmapButton);
|
wxDECLARE_DYNAMIC_CLASS(wxBitmapButton);
|
||||||
};
|
};
|
||||||
|
@@ -42,6 +42,10 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
void SetLabel( const wxString &label );
|
void SetLabel( const wxString &label );
|
||||||
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); }
|
||||||
|
|
||||||
|
@@ -35,6 +35,9 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
// Implementation
|
// Implementation
|
||||||
virtual void ChangeBackgroundColour();
|
virtual void ChangeBackgroundColour();
|
||||||
|
|
||||||
|
@@ -41,6 +41,9 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
protected:
|
protected:
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxBitmapButton);
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxBitmapButton);
|
||||||
|
@@ -37,6 +37,9 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
||||||
|
@@ -30,6 +30,11 @@ public:
|
|||||||
long style = 0,
|
long style = 0,
|
||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxBitmapButton);
|
wxDECLARE_DYNAMIC_CLASS(wxBitmapButton);
|
||||||
|
|
||||||
|
@@ -37,6 +37,11 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
const wxString& name = wxASCII_STR(wxButtonNameStr));
|
||||||
|
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
|
|
||||||
virtual void SetMargins(int x, int y) wxOVERRIDE
|
virtual void SetMargins(int x, int y) wxOVERRIDE
|
||||||
{
|
{
|
||||||
SetBitmapMargins(x, y);
|
SetBitmapMargins(x, y);
|
||||||
|
@@ -99,6 +99,24 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxButtonNameStr);
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creation function for two-step creation of "Close" button.
|
||||||
|
|
||||||
|
It is usually not necessary to use this function directly as
|
||||||
|
NewCloseButton() is more convenient, but, if required, it can be called
|
||||||
|
on a default-constructed wxBitmapButton object to achieve the same
|
||||||
|
effect.
|
||||||
|
|
||||||
|
@param parent The button parent window, must be non-@NULL.
|
||||||
|
@param winid The identifier for the new button.
|
||||||
|
@param name The name for the new button.
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
*/
|
||||||
|
bool CreateCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper function creating a standard-looking "Close" button.
|
Helper function creating a standard-looking "Close" button.
|
||||||
|
|
||||||
@@ -109,10 +127,13 @@ public:
|
|||||||
|
|
||||||
@param parent The button parent window, must be non-@NULL.
|
@param parent The button parent window, must be non-@NULL.
|
||||||
@param winid The identifier for the new button.
|
@param winid The identifier for the new button.
|
||||||
|
@param name The name for the new button (available since wxWidgets 3.1.5)
|
||||||
@return The new button.
|
@return The new button.
|
||||||
|
|
||||||
@since 2.9.5
|
@since 2.9.5
|
||||||
*/
|
*/
|
||||||
static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
|
static wxBitmapButton* NewCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name = wxString());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -686,6 +686,7 @@ wxBitmapButton =
|
|||||||
stdObjectNodeAttributes &
|
stdObjectNodeAttributes &
|
||||||
stdWindowProperties &
|
stdWindowProperties &
|
||||||
[xrc:p="o"] element default {_, t_bool }* &
|
[xrc:p="o"] element default {_, t_bool }* &
|
||||||
|
[xrc:p="o"] element close {_, t_bool }* &
|
||||||
[xrc:p="important"] element bitmap {_, t_bitmap }* &
|
[xrc:p="important"] element bitmap {_, t_bitmap }* &
|
||||||
[xrc:p="o"] element selected {_, t_bitmap }* &
|
[xrc:p="o"] element selected {_, t_bitmap }* &
|
||||||
[xrc:p="o"] element focus {_, t_bitmap }* &
|
[xrc:p="o"] element focus {_, t_bitmap }* &
|
||||||
|
@@ -114,11 +114,12 @@ GetCloseButtonBitmap(wxWindow *win,
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
/* static */
|
bool
|
||||||
wxBitmapButton*
|
wxBitmapButton::CreateCloseButton(wxWindow* parent,
|
||||||
wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid)
|
wxWindowID winid,
|
||||||
|
const wxString& name)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( parent, NULL, wxS("Must have a valid parent") );
|
wxCHECK_MSG( parent, false, wxS("Must have a valid parent") );
|
||||||
|
|
||||||
const wxColour colBg = parent->GetBackgroundColour();
|
const wxColour colBg = parent->GetBackgroundColour();
|
||||||
|
|
||||||
@@ -129,26 +130,34 @@ wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid)
|
|||||||
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
|
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
|
||||||
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
|
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
|
||||||
|
|
||||||
wxBitmapButton* const button = new wxBitmapButton
|
if ( !Create(parent, winid, bmp,
|
||||||
(
|
wxDefaultPosition, wxDefaultSize,
|
||||||
parent,
|
wxBORDER_NONE, wxDefaultValidator, name) )
|
||||||
winid,
|
return false;
|
||||||
bmp,
|
|
||||||
wxDefaultPosition,
|
|
||||||
wxDefaultSize,
|
|
||||||
wxBORDER_NONE
|
|
||||||
);
|
|
||||||
|
|
||||||
#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
|
#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
|
||||||
button->SetBitmapPressed(
|
SetBitmapPressed(
|
||||||
GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED));
|
GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED));
|
||||||
|
|
||||||
button->SetBitmapCurrent(
|
SetBitmapCurrent(
|
||||||
GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT));
|
GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT));
|
||||||
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
|
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
|
||||||
|
|
||||||
// The button should blend with its parent background.
|
// The button should blend with its parent background.
|
||||||
button->SetBackgroundColour(colBg);
|
SetBackgroundColour(colBg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxBitmapButton*
|
||||||
|
wxBitmapButtonBase::NewCloseButton(wxWindow* parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& name)
|
||||||
|
{
|
||||||
|
wxBitmapButton* const button = new wxBitmapButton();
|
||||||
|
|
||||||
|
button->CreateCloseButton(parent, winid, name);
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,14 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource()
|
|||||||
{
|
{
|
||||||
XRC_MAKE_INSTANCE(button, wxBitmapButton)
|
XRC_MAKE_INSTANCE(button, wxBitmapButton)
|
||||||
|
|
||||||
|
if ( GetBool("close", 0) )
|
||||||
|
{
|
||||||
|
button->CreateCloseButton(m_parentAsWindow,
|
||||||
|
GetID(),
|
||||||
|
GetName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
button->Create(m_parentAsWindow,
|
button->Create(m_parentAsWindow,
|
||||||
GetID(),
|
GetID(),
|
||||||
GetBitmap(wxT("bitmap"), wxART_BUTTON),
|
GetBitmap(wxT("bitmap"), wxART_BUTTON),
|
||||||
@@ -44,6 +52,8 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource()
|
|||||||
GetStyle(wxT("style")),
|
GetStyle(wxT("style")),
|
||||||
wxDefaultValidator,
|
wxDefaultValidator,
|
||||||
GetName());
|
GetName());
|
||||||
|
}
|
||||||
|
|
||||||
if (GetBool(wxT("default"), 0))
|
if (GetBool(wxT("default"), 0))
|
||||||
button->SetDefault();
|
button->SetDefault();
|
||||||
SetupWindow(button);
|
SetupWindow(button);
|
||||||
|
Reference in New Issue
Block a user