diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index dff65c1122..4fbf46b86c 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -769,6 +769,11 @@ Refer to the section @ref xrc_wxtoolbar for more details. @hdr3col{property, type, description} @row3col{default, @ref overview_xrcformat_type_bool, 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, Bitmap to show on the button (default: none).} @row3col{selected, @ref overview_xrcformat_type_bitmap, diff --git a/include/wx/bmpbuttn.h b/include/wx/bmpbuttn.h index 4bf85e0b53..91a00a742d 100644 --- a/include/wx/bmpbuttn.h +++ b/include/wx/bmpbuttn.h @@ -65,11 +65,25 @@ public: 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 // simply create a close button with the image appropriate for the current // 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 virtual void SetMargins(int x, int y) diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index 1748c5e5e1..46d8836a84 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -39,6 +39,9 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); private: wxDECLARE_DYNAMIC_CLASS(wxBitmapButton); }; diff --git a/include/wx/gtk1/bmpbuttn.h b/include/wx/gtk1/bmpbuttn.h index 5627930a05..9d81994eb0 100644 --- a/include/wx/gtk1/bmpbuttn.h +++ b/include/wx/gtk1/bmpbuttn.h @@ -42,6 +42,10 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); + void SetLabel( const wxString &label ); virtual void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel(bitmap); } diff --git a/include/wx/motif/bmpbuttn.h b/include/wx/motif/bmpbuttn.h index ec6ae884fc..16ccf4869e 100644 --- a/include/wx/motif/bmpbuttn.h +++ b/include/wx/motif/bmpbuttn.h @@ -35,6 +35,9 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); // Implementation virtual void ChangeBackgroundColour(); diff --git a/include/wx/msw/bmpbuttn.h b/include/wx/msw/bmpbuttn.h index 983db43b85..a083428948 100644 --- a/include/wx/msw/bmpbuttn.h +++ b/include/wx/msw/bmpbuttn.h @@ -41,6 +41,9 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); protected: wxDECLARE_EVENT_TABLE(); wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxBitmapButton); diff --git a/include/wx/osx/bmpbuttn.h b/include/wx/osx/bmpbuttn.h index 8d060516f9..7ea895ffe3 100644 --- a/include/wx/osx/bmpbuttn.h +++ b/include/wx/osx/bmpbuttn.h @@ -37,6 +37,9 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); protected: virtual wxSize DoGetBestSize() const wxOVERRIDE; diff --git a/include/wx/qt/bmpbuttn.h b/include/wx/qt/bmpbuttn.h index 27f5a353a9..15baae446a 100644 --- a/include/wx/qt/bmpbuttn.h +++ b/include/wx/qt/bmpbuttn.h @@ -30,6 +30,11 @@ public: long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); + protected: wxDECLARE_DYNAMIC_CLASS(wxBitmapButton); diff --git a/include/wx/univ/bmpbuttn.h b/include/wx/univ/bmpbuttn.h index 6c37b78193..685302d432 100644 --- a/include/wx/univ/bmpbuttn.h +++ b/include/wx/univ/bmpbuttn.h @@ -37,6 +37,11 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxASCII_STR(wxButtonNameStr)); + bool CreateCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); + + virtual void SetMargins(int x, int y) wxOVERRIDE { SetBitmapMargins(x, y); diff --git a/interface/wx/bmpbuttn.h b/interface/wx/bmpbuttn.h index be1657cabb..d4c4abdd41 100644 --- a/interface/wx/bmpbuttn.h +++ b/interface/wx/bmpbuttn.h @@ -99,6 +99,24 @@ public: const wxValidator& validator = wxDefaultValidator, 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. @@ -109,10 +127,13 @@ public: @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 (available since wxWidgets 3.1.5) @return The new button. @since 2.9.5 */ - static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid); + static wxBitmapButton* NewCloseButton(wxWindow* parent, + wxWindowID winid, + const wxString& name = wxString()); }; diff --git a/misc/schema/xrc_schema.rnc b/misc/schema/xrc_schema.rnc index 6a1ca469e0..b601d54e36 100644 --- a/misc/schema/xrc_schema.rnc +++ b/misc/schema/xrc_schema.rnc @@ -686,6 +686,7 @@ wxBitmapButton = stdObjectNodeAttributes & stdWindowProperties & [xrc:p="o"] element default {_, t_bool }* & + [xrc:p="o"] element close {_, t_bool }* & [xrc:p="important"] element bitmap {_, t_bitmap }* & [xrc:p="o"] element selected {_, t_bitmap }* & [xrc:p="o"] element focus {_, t_bitmap }* & diff --git a/src/common/bmpbtncmn.cpp b/src/common/bmpbtncmn.cpp index 0eb20d269c..3e8b9cab68 100644 --- a/src/common/bmpbtncmn.cpp +++ b/src/common/bmpbtncmn.cpp @@ -114,11 +114,12 @@ GetCloseButtonBitmap(wxWindow *win, } // anonymous namespace -/* static */ -wxBitmapButton* -wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid) +bool +wxBitmapButton::CreateCloseButton(wxWindow* parent, + 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(); @@ -129,26 +130,34 @@ wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid) wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON); #endif // wxHAS_DRAW_TITLE_BAR_BITMAP - wxBitmapButton* const button = new wxBitmapButton - ( - parent, - winid, - bmp, - wxDefaultPosition, - wxDefaultSize, - wxBORDER_NONE - ); + if ( !Create(parent, winid, bmp, + wxDefaultPosition, wxDefaultSize, + wxBORDER_NONE, wxDefaultValidator, name) ) + return false; #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP - button->SetBitmapPressed( + SetBitmapPressed( GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED)); - button->SetBitmapCurrent( + SetBitmapCurrent( GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT)); #endif // wxHAS_DRAW_TITLE_BAR_BITMAP // 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; } diff --git a/src/xrc/xh_bmpbt.cpp b/src/xrc/xh_bmpbt.cpp index f3d725b8fa..822fb2b235 100644 --- a/src/xrc/xh_bmpbt.cpp +++ b/src/xrc/xh_bmpbt.cpp @@ -37,13 +37,23 @@ wxObject *wxBitmapButtonXmlHandler::DoCreateResource() { XRC_MAKE_INSTANCE(button, wxBitmapButton) - button->Create(m_parentAsWindow, - GetID(), - GetBitmap(wxT("bitmap"), wxART_BUTTON), - GetPosition(), GetSize(), - GetStyle(wxT("style")), - wxDefaultValidator, - GetName()); + if ( GetBool("close", 0) ) + { + button->CreateCloseButton(m_parentAsWindow, + GetID(), + GetName()); + } + else + { + button->Create(m_parentAsWindow, + GetID(), + GetBitmap(wxT("bitmap"), wxART_BUTTON), + GetPosition(), GetSize(), + GetStyle(wxT("style")), + wxDefaultValidator, + GetName()); + } + if (GetBool(wxT("default"), 0)) button->SetDefault(); SetupWindow(button);