Oh, thanks for the review, it is a copy-paste error, it definitely should be std::unique_ptr.
.../contrib/wxSmithAui/wxAuiManager/wxsAuiManager.cpp | 19 ++++++++++++++++---
.../contrib/wxSmithAui/wxAuiToolBar/wxsAuiToolBar.cpp | 13 ++++++++++++-
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/plugins/contrib/wxSmithAui/wxAuiManager/wxsAuiManager.cpp b/src/plugins/contrib/wxSmithAui/wxAuiManager/wxsAuiManager.cpp
index bbd3d967..5a66636c 100644
--- a/src/plugins/contrib/wxSmithAui/wxAuiManager/wxsAuiManager.cpp
+++ b/src/plugins/contrib/wxSmithAui/wxAuiManager/wxsAuiManager.cpp
@@ -27,6 +27,16 @@
using namespace wxsFlags;
+struct TempFrameDeleter
+{
+ void operator()(wxFrame* frame)
+ {
+ frame->Destroy();
+ }
+};
+
+using TempFrameUniquePtr = std::unique_ptr<wxFrame, TempFrameDeleter>;
+
namespace
{
#include "../images/wxsAuiManager16.xpm"
@@ -640,8 +650,8 @@ bool wxsAuiManager::OnCanAddToParent(wxsParent* Parent,bool ShowMessage)
wxMessageBox(_("wxAuiManager can't be added to a sizer. Add panels first."));
return false;
}
-
- if ( !wxDynamicCast(Parent->BuildPreview(new wxFrame(0,-1,wxEmptyString),0),wxWindow) )
+ TempFrameUniquePtr tempFrame(new wxFrame(nullptr, wxID_ANY, wxEmptyString));
+ if ( !wxDynamicCast(Parent->BuildPreview(tempFrame.get(),0),wxWindow) )
{
if ( ShowMessage )
wxMessageBox(_("wxAuiManager can only be added to a wxWindow descendant."));
@@ -651,6 +661,8 @@ bool wxsAuiManager::OnCanAddToParent(wxsParent* Parent,bool ShowMessage)
return wxsParent::OnCanAddToParent(Parent,ShowMessage);
}
+
+
void wxsAuiManager::OnAddChildQPP(wxsItem* Child,wxsAdvQPP* QPP)
{
wxsParent::OnAddChildQPP(Child,QPP);
@@ -665,7 +677,8 @@ void wxsAuiManager::OnAddChildQPP(wxsItem* Child,wxsAdvQPP* QPP)
if ( ChildExtra->m_FirstAdd )
{
ChildExtra->m_FirstAdd = false;
- if ( wxDynamicCast(Child->BuildPreview(new wxFrame(0,-1,wxEmptyString),0),wxAuiToolBar) )
+ TempFrameUniquePtr tempFrame(new wxFrame(nullptr, wxID_ANY, wxEmptyString));
+ if ( wxDynamicCast(Child->BuildPreview(tempFrame.get(),0),wxAuiToolBar) )
{
ChildExtra->m_StandardPane = wxsAuiPaneInfoExtra::ToolbarPane;
ChildExtra->m_DockableFlags = wxsAuiDockableProperty::Dockable;
diff --git a/src/plugins/contrib/wxSmithAui/wxAuiToolBar/wxsAuiToolBar.cpp b/src/plugins/contrib/wxSmithAui/wxAuiToolBar/wxsAuiToolBar.cpp
index 66b67edc..3870d1cb 100644
--- a/src/plugins/contrib/wxSmithAui/wxAuiToolBar/wxsAuiToolBar.cpp
+++ b/src/plugins/contrib/wxSmithAui/wxAuiToolBar/wxsAuiToolBar.cpp
@@ -32,6 +32,16 @@
using namespace wxsFlags;
+struct TempFrameDeleter
+{
+ void operator()(wxFrame* frame)
+ {
+ frame->Destroy();
+ }
+};
+
+using TempFrameUniquePtr = std::unique_ptr<wxFrame, TempFrameDeleter>;
+
//(*Headers(wxsAuiToolBarParentQP)
#include <wx/checkbox.h>
#include <wx/sizer.h>
@@ -126,7 +136,8 @@ wxsAuiToolBar::~wxsAuiToolBar()
bool wxsAuiToolBar::OnCanAddChild(wxsItem* Item,bool ShowMessage)
{
- bool IsControl = wxDynamicCast(Item->BuildPreview(new wxFrame(0,-1,wxEmptyString),0),wxControl);
+ TempFrameUniquePtr tempFrame(new wxFrame(nullptr, wxID_ANY, wxEmptyString));
+ bool IsControl = wxDynamicCast(Item->BuildPreview(tempFrame.get(),0),wxControl);
bool IsAuiToolBarItem = Item->GetClassName().Contains(_T("wxAuiToolBar"));
if ( !IsControl && !IsAuiToolBarItem )
{
I don't think add the same part in two cpp file is a good idea.
std::unique_ptr<wxFrame, std::function<void(wxFrame*)>> tempFrame(new wxFrame(nullptr, wxID_ANY, wxEmptyString),
[&](wxFrame* frame){ frame->Destroy(); }); // deleter