Kaydet (Commit) b358bb95 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Stephan Bergmann

cannot create a shared_ptr from an existing object

so pass in the shared_ptr we already have (and enforce that we pass in
the right one)

Change-Id: Ic481b5ec17c34ed9cba50586dedb6184505dee24
Reviewed-on: https://gerrit.libreoffice.org/72908
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 3dfcc485
......@@ -403,7 +403,10 @@ private:
public:
virtual int run() = 0;
// Run async without a controller
virtual bool runAsync(const std::function<void(sal_Int32)>& func) = 0;
// @param self - must point to this, to enforce that the dialog was created/held by a shared_ptr
virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
const std::function<void(sal_Int32)>& func)
= 0;
virtual void response(int response) = 0;
virtual void add_button(const OUString& rText, int response, const OString& rHelpId = OString())
= 0;
......
......@@ -38,7 +38,7 @@ namespace
std::shared_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
VclMessageType::Warning, VclButtonsType::Ok,
rString));
xBox->runAsync(func);
xBox->runAsync(xBox, func);
}
}
......
......@@ -1199,10 +1199,13 @@ public:
return m_xDialog->StartExecuteAsync(aCtx);
}
virtual bool runAsync(const std::function<void(sal_Int32)> &rEndDialogFn) override
virtual bool runAsync(std::shared_ptr<Dialog> const & rxSelf, const std::function<void(sal_Int32)> &rEndDialogFn) override
{
assert( rxSelf.get() == this );
VclAbstractDialog::AsyncContext aCtx;
aCtx.mxOwnerSelf.reset(this);
// In order to store a shared_ptr to ourself, we have to have been constructed by make_shared,
// which is that rxSelf enforces.
aCtx.mxOwnerSelf = rxSelf;
aCtx.maEndDialogFn = rEndDialogFn;
return m_xDialog->StartExecuteAsync(aCtx);
}
......
......@@ -3004,7 +3004,7 @@ private:
DialogRunner m_aDialogRun;
std::shared_ptr<weld::DialogController> m_xDialogController;
// Used to keep ourself alive during a runAsync(when doing runAsync without a DialogController)
std::shared_ptr<GtkInstanceDialog> m_xRunAsyncSelf;
std::shared_ptr<weld::Dialog> m_xRunAsyncSelf;
std::function<void(sal_Int32)> m_aFunc;
gulong m_nCloseSignalId;
gulong m_nResponseSignalId;
......@@ -3088,11 +3088,14 @@ public:
return true;
}
virtual bool runAsync(const std::function<void(sal_Int32)>& func) override
virtual bool runAsync(std::shared_ptr<Dialog> const & rxSelf, const std::function<void(sal_Int32)>& func) override
{
assert( rxSelf.get() == this );
assert(!m_nResponseSignalId);
m_xRunAsyncSelf.reset(this);
// In order to store a shared_ptr to ourself, we have to have been constructed by make_shared,
// which is that rxSelf enforces.
m_xRunAsyncSelf = rxSelf;
m_aFunc = func;
show();
......@@ -4630,7 +4633,7 @@ void GtkInstanceDialog::asyncresponse(gint ret)
m_aFunc(GtkToVcl(ret));
m_aFunc = nullptr;
// move the self pointer, otherwise it might be de-allocated by time we try to reset it
std::shared_ptr<GtkInstanceDialog> me = std::move(m_xRunAsyncSelf);
std::shared_ptr<weld::Dialog> me = std::move(m_xRunAsyncSelf);
m_xDialogController.reset();
me.reset();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment