summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-01-13 12:10:43 +0000
committerJan Holesovsky <kendy@collabora.com>2018-01-15 17:40:11 +0100
commitd0f4f27465da113748ca63103692c45da64af6f5 (patch)
tree7f0d3c2038b080dd98127e298402ae0144b21758
parentaceaaaa85fd824611349e637f37b9644b6fe62cb (diff)
lokdialog: Allow closing the Format Cell dialogs in any order.
Includes also lots of infrastructural changes, making the conversion of the rest of the dialogs much easier. StartExecuteAsync should be used in-place of StartExecuteModal and the latter removed from the code-base incrementally. More common code from Dialog::Execute should be moved to ImplStartExecuteModal in a next step, as this is used more widely. Change-Id: Idb2c1ec790e38f582438471a0419a56cdcf1439d Reviewed-on: https://gerrit.libreoffice.org/47817 Reviewed-by: Jan Holesovsky <kendy@collabora.com> Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r--include/sfx2/tabdlg.hxx1
-rw-r--r--include/vcl/abstdlg.hxx18
-rw-r--r--include/vcl/dialog.hxx17
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.hxx5
-rw-r--r--sc/source/ui/view/tabvwsha.cxx34
-rw-r--r--sfx2/source/control/request.cxx17
-rw-r--r--sfx2/source/dialog/tabdlg.cxx37
-rw-r--r--vcl/source/window/abstdlg.cxx6
-rw-r--r--vcl/source/window/dialog.cxx99
-rw-r--r--vcl/source/window/window.cxx5
10 files changed, 178 insertions, 61 deletions
diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx
index efed3fff4d35..a758d4544291 100644
--- a/include/sfx2/tabdlg.hxx
+++ b/include/sfx2/tabdlg.hxx
@@ -190,6 +190,7 @@ public:
short Execute() override;
void StartExecuteModal( const Link<Dialog&,void>& rEndDialogHdl ) override;
+ bool StartExecuteAsync( VclAbstractDialog::AsyncContext &rCtx ) override;
void Start();
const SfxItemSet* GetExampleSet() const { return m_pExampleSet; }
diff --git a/include/vcl/abstdlg.hxx b/include/vcl/abstdlg.hxx
index c173326706c8..55260f51aef3 100644
--- a/include/vcl/abstdlg.hxx
+++ b/include/vcl/abstdlg.hxx
@@ -24,6 +24,7 @@
#include <vcl/dllapi.h>
#include <vcl/vclreferencebase.hxx>
#include <vector>
+#include <functional>
namespace vcl { class Window; }
class Dialog;
@@ -41,6 +42,23 @@ protected:
public:
virtual short Execute() = 0;
+ struct AsyncContext {
+ VclPtr<VclReferenceBase> mxOwner;
+ std::function<void(sal_Int32)> maEndDialogFn;
+ bool isSet() { return !!maEndDialogFn; }
+ };
+
+ bool StartExecuteAsync(const std::function<void(sal_Int32)> &rEndDialogFn, VclPtr<VclReferenceBase> xOwner)
+ {
+ AsyncContext aCtx;
+ aCtx.mxOwner = xOwner;
+ aCtx.maEndDialogFn = rEndDialogFn;
+ return StartExecuteAsync(aCtx);
+ }
+
+ /// Commence execution of a modal dialog.
+ virtual bool StartExecuteAsync(AsyncContext &);
+
// Screenshot interface
virtual std::vector<OString> getAllPageUIXMLDescriptions() const;
virtual bool selectPageByUIXMLDescription(const OString& rUIXMLDescription);
diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx
index 706cd762db94..aa837f741c2c 100644
--- a/include/vcl/dialog.hxx
+++ b/include/vcl/dialog.hxx
@@ -25,6 +25,7 @@
#include <vcl/syswin.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/IDialogRenderable.hxx>
+#include <vcl/abstdlg.hxx>
struct DialogImpl;
class VclBox;
@@ -37,6 +38,7 @@ public:
private:
VclPtr<Dialog> mpPrevExecuteDlg;
+ VclPtr<Dialog> mpNextExecuteDlg;
std::unique_ptr<DialogImpl> mpDialogImpl;
long mnMousePositioned;
bool mbInExecute;
@@ -48,6 +50,7 @@ private:
VclPtr<VclButtonBox> mpActionArea;
VclPtr<VclBox> mpContentArea;
+ SAL_DLLPRIVATE void RemoveFromDlgList();
SAL_DLLPRIVATE void ImplInitDialogData();
SAL_DLLPRIVATE void ImplInitSettings();
@@ -124,6 +127,20 @@ private:
static void ImplEndExecuteModal();
public:
+ // FIXME: Need to remove old StartExecuteModal in favour of this one.
+ /// Returns true of the dialog successfully starts
+ bool StartExecuteAsync(const std::function<void(sal_Int32)> &rEndDialogFn,
+ VclPtr<VclReferenceBase> xOwner = VclPtr<VclReferenceBase>())
+ {
+ VclAbstractDialog::AsyncContext aCtx;
+ aCtx.mxOwner = xOwner;
+ aCtx.maEndDialogFn = rEndDialogFn;
+ return StartExecuteAsync(aCtx);
+ }
+
+ /// Commence execution of a modal dialog, disposes owner on failure
+ virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx);
+
// Dialog::Execute replacement API
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index b069c779efb2..ef6e0a6a1057 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -65,6 +65,7 @@ public: \
{} \
virtual ~Class() override; \
virtual short Execute() override ; \
+ virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) override; \
std::vector<OString> getAllPageUIXMLDescriptions() const override; \
bool selectPageByUIXMLDescription(const OString& rUIXMLDescription) override; \
virtual Bitmap createScreenshot() const override; \
@@ -88,6 +89,10 @@ short Class::Execute() \
{ \
return pDlg->Execute(); \
} \
+bool Class::StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx)\
+{ \
+ return pDlg->StartExecuteAsync( rCtx ); \
+} \
std::vector<OString> Class::getAllPageUIXMLDescriptions() const \
{ \
return pDlg->getAllPageUIXMLDescriptions(); \
diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index 5946a6054b8f..4753de415735 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -481,8 +481,8 @@ void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OString &rName
const ScPatternAttr* pOldAttrs = GetSelectionPattern();
- std::unique_ptr<SfxItemSet> pOldSet(new SfxItemSet(pOldAttrs->GetItemSet()));
- std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem;
+ std::shared_ptr<SfxItemSet> pOldSet(new SfxItemSet(pOldAttrs->GetItemSet()));
+ std::shared_ptr<SvxNumberInfoItem> pNumberInfoItem;
pOldSet->MergeRange(SID_ATTR_BORDER_STYLES, SID_ATTR_BORDER_DEFAULT_WIDTH);
@@ -540,28 +540,30 @@ void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OString &rName
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
- ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScAttrDlg(GetDialogParent(), pOldSet.get()));
+ VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScAttrDlg(GetDialogParent(), pOldSet.get()));
if (!rName.isEmpty())
pDlg->SetCurPageId(rName);
- short nResult = pDlg->Execute();
- bInFormatDialog = false;
- if ( nResult == RET_OK )
- {
- const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
+ std::shared_ptr<SfxRequest> pRequest(new SfxRequest(rReq));
+ pDlg->StartExecuteAsync([=](sal_Int32 nResult){
+ bInFormatDialog = false;
- const SfxPoolItem* pItem=nullptr;
- if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,true,&pItem)==SfxItemState::SET)
- {
+ if ( nResult == RET_OK )
+ {
+ const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
- UpdateNumberFormatter(static_cast<const SvxNumberInfoItem&>(*pItem));
- }
+ const SfxPoolItem* pItem=nullptr;
+ if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,true,&pItem)==SfxItemState::SET)
+ {
+ UpdateNumberFormatter(static_cast<const SvxNumberInfoItem&>(*pItem));
+ }
- ApplyAttributes(pOutSet, pOldSet.get());
+ ApplyAttributes(pOutSet, pOldSet.get());
- rReq.Done( *pOutSet );
- }
+ pRequest->Done(pOutSet);
+ }
+ }, pDlg);
}
bool ScTabViewShell::IsRefInputMode() const
diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx
index 2c8f1ea69cb4..751e2f30108a 100644
--- a/sfx2/source/control/request.cxx
+++ b/sfx2/source/control/request.cxx
@@ -152,6 +152,23 @@ SfxRequest::SfxRequest
pImpl->SetPool( pArgs->GetPool() );
else
pImpl->SetPool( rOrig.pImpl->pPool );
+
+ // setup macro recording if it was in the original SfxRequest
+ if (rOrig.pImpl->pViewFrame && rOrig.pImpl->xRecorder.is())
+ {
+ nSlot = rOrig.nSlot;
+ pImpl->pViewFrame = rOrig.pImpl->pViewFrame;
+ if (pImpl->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl(nSlot, &pImpl->pShell, &pImpl->pSlot, true, true))
+ {
+ pImpl->SetPool( &pImpl->pShell->GetPool() );
+ pImpl->xRecorder = SfxRequest::GetMacroRecorder(pImpl->pViewFrame);
+ pImpl->aTarget = pImpl->pShell->GetName();
+ }
+ else
+ {
+ SAL_WARN("sfx", "Recording unsupported slot: " << pImpl->pPool->GetSlotId(nSlot));
+ }
+ }
}
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index 13033266ba47..c2228856465b 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -520,22 +520,19 @@ short SfxTabDialog::Execute()
return RET_CANCEL;
Start_Impl();
- SfxViewShell* pViewShell = SfxViewShell::Current();
- if (comphelper::LibreOfficeKit::isActive() && pViewShell && !GetLOKNotifier())
- {
- SetLOKNotifier(pViewShell);
- const Size aSize = GetOptimalSize();
- std::vector<vcl::LOKPayloadItem> aItems;
- aItems.emplace_back("type", "dialog");
- aItems.emplace_back("size", aSize.toString());
- if (!GetText().isEmpty())
- aItems.emplace_back("title", GetText().toUtf8());
- pViewShell->notifyWindow(GetLOKWindowId(), "created", aItems);
- }
-
return TabDialog::Execute();
}
+bool SfxTabDialog::StartExecuteAsync( VclAbstractDialog::AsyncContext &rCtx )
+{
+ if ( !m_pTabCtrl->GetPageCount() )
+ {
+ rCtx.mxOwner.disposeAndClear();
+ return false;
+ }
+ Start_Impl();
+ return TabDialog::StartExecuteAsync( rCtx );
+}
void SfxTabDialog::StartExecuteModal( const Link<Dialog&,void>& rEndDialogHdl )
{
@@ -592,6 +589,20 @@ void SfxTabDialog::Start_Impl()
m_pTabCtrl->SetCurPageId( nActPage );
ActivatePageHdl( m_pTabCtrl );
+
+ SfxViewShell* pViewShell = SfxViewShell::Current();
+
+ if (comphelper::LibreOfficeKit::isActive() && pViewShell && !GetLOKNotifier())
+ {
+ SetLOKNotifier(pViewShell);
+ const Size aSize = GetOptimalSize();
+ std::vector<vcl::LOKPayloadItem> aItems;
+ aItems.emplace_back("type", "dialog");
+ aItems.emplace_back("size", aSize.toString());
+ if (!GetText().isEmpty())
+ aItems.emplace_back("title", GetText().toUtf8());
+ pViewShell->notifyWindow(GetLOKWindowId(), "created", aItems);
+ }
}
void SfxTabDialog::AddTabPage( sal_uInt16 nId, const OUString &rRiderText )
diff --git a/vcl/source/window/abstdlg.cxx b/vcl/source/window/abstdlg.cxx
index 807e75ead2d0..8ce6fd4221d6 100644
--- a/vcl/source/window/abstdlg.cxx
+++ b/vcl/source/window/abstdlg.cxx
@@ -58,6 +58,12 @@ VclAbstractDialog::~VclAbstractDialog()
{
}
+bool VclAbstractDialog::StartExecuteAsync(AsyncContext &)
+{
+ assert(false);
+ return false;
+}
+
std::vector<OString> VclAbstractDialog::getAllPageUIXMLDescriptions() const
{
// default has no pages
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index d1ce491d490a..1fe977961d74 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -38,6 +38,7 @@
#include "window.h"
+#include <vcl/abstdlg.hxx>
#include <vcl/builder.hxx>
#include <vcl/layout.hxx>
#include <vcl/svapp.hxx>
@@ -346,7 +347,7 @@ struct DialogImpl
{
long mnResult;
bool mbStartedModal;
- Link<Dialog&,void> maEndDialogHdl;
+ VclAbstractDialog::AsyncContext maEndCtx;
DialogImpl() : mnResult( -1 ), mbStartedModal( false ) {}
};
@@ -355,6 +356,7 @@ void Dialog::ImplInitDialogData()
{
mpWindowImpl->mbDialog = true;
mpPrevExecuteDlg = nullptr;
+ mpNextExecuteDlg = nullptr;
mbInExecute = false;
mbInClose = false;
mbModalMode = false;
@@ -584,7 +586,9 @@ Dialog::~Dialog()
void Dialog::dispose()
{
mpDialogImpl.reset();
+ RemoveFromDlgList();
mpPrevExecuteDlg.clear();
+ mpNextExecuteDlg.clear();
mpActionArea.clear();
mpContentArea.clear();
@@ -779,7 +783,9 @@ bool Dialog::Close()
bool Dialog::ImplStartExecuteModal()
{
- if ( mbInExecute )
+ setDeferredProperties();
+
+ if ( mbInExecute || mpDialogImpl->maEndCtx.isSet() )
{
#ifdef DBG_UTIL
OStringBuffer aErrorStr;
@@ -827,6 +833,8 @@ bool Dialog::ImplStartExecuteModal()
// link all dialogs which are being executed
mpPrevExecuteDlg = pSVData->maWinData.mpLastExecuteDlg;
+ if (mpPrevExecuteDlg)
+ mpPrevExecuteDlg->mpNextExecuteDlg = this;
pSVData->maWinData.mpLastExecuteDlg = this;
// stop capturing, in order to have control over the dialog
@@ -842,7 +850,9 @@ bool Dialog::ImplStartExecuteModal()
GetParent()->CompatNotify( aNEvt );
}
mbInExecute = true;
- SetModalInputMode( true );
+ // no real modality in LibreOfficeKit
+ if (!comphelper::LibreOfficeKit::isActive())
+ SetModalInputMode(true);
// FIXME: no layouting, workaround some clipping issues
ImplAdjustNWFSizes();
@@ -850,6 +860,14 @@ bool Dialog::ImplStartExecuteModal()
Show();
pSVData->maAppData.mnModalMode++;
+
+ css::uno::Reference< css::uno::XComponentContext > xContext(
+ comphelper::getProcessComponentContext() );
+ css::uno::Reference<css::frame::XGlobalEventBroadcaster> xEventBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
+ css::document::DocumentEvent aObject;
+ aObject.EventName = "DialogExecute";
+ xEventBroadcaster->documentEventOccured(aObject);
+
return true;
}
@@ -910,21 +928,11 @@ Bitmap Dialog::createScreenshot()
short Dialog::Execute()
{
#if HAVE_FEATURE_DESKTOP
-
- setDeferredProperties();
+ VclPtr<vcl::Window> xWindow = this;
if ( !ImplStartExecuteModal() )
return 0;
- VclPtr<vcl::Window> xWindow = this;
-
- css::uno::Reference< css::uno::XComponentContext > xContext(
- comphelper::getProcessComponentContext() );
- css::uno::Reference<css::frame::XGlobalEventBroadcaster> xEventBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
- css::document::DocumentEvent aObject;
- aObject.EventName = "DialogExecute";
- xEventBroadcaster->documentEventOccured(aObject);
-
// Yield util EndDialog is called or dialog gets destroyed
// (the latter should not happen, but better safe than sorry
while ( !xWindow->IsDisposed() && mbInExecute )
@@ -961,11 +969,44 @@ short Dialog::Execute()
// virtual
void Dialog::StartExecuteModal( const Link<Dialog&,void>& rEndDialogHdl )
{
+ VclAbstractDialog::AsyncContext aCtx;
+ VclPtr<Dialog> ref(this);
+ aCtx.maEndDialogFn = [ref,rEndDialogHdl](sal_Int32){ rEndDialogHdl.Call(*ref.get()); };
+ StartExecuteAsync(aCtx);
+}
+
+// virtual
+bool Dialog::StartExecuteAsync( VclAbstractDialog::AsyncContext &rCtx )
+{
if ( !ImplStartExecuteModal() )
- return;
+ {
+ rCtx.mxOwner.disposeAndClear();
+ return false;
+ }
- mpDialogImpl->maEndDialogHdl = rEndDialogHdl;
+ mpDialogImpl->maEndCtx = rCtx;
mpDialogImpl->mbStartedModal = true;
+
+ return true;
+}
+
+void Dialog::RemoveFromDlgList()
+{
+ // remove dialog from the list of dialogs which are being executed
+ ImplSVData* pSVData = ImplGetSVData();
+ if (pSVData->maWinData.mpLastExecuteDlg == this)
+ {
+ if (mpPrevExecuteDlg)
+ pSVData->maWinData.mpLastExecuteDlg = mpPrevExecuteDlg;
+ else
+ pSVData->maWinData.mpLastExecuteDlg = mpNextExecuteDlg;
+ }
+ if (mpPrevExecuteDlg)
+ mpPrevExecuteDlg->mpNextExecuteDlg = mpNextExecuteDlg;
+ if (mpNextExecuteDlg)
+ mpNextExecuteDlg->mpPrevExecuteDlg = mpPrevExecuteDlg;
+ mpPrevExecuteDlg.clear();
+ mpNextExecuteDlg.clear();
}
void Dialog::EndDialog( long nResult )
@@ -974,24 +1015,14 @@ void Dialog::EndDialog( long nResult )
{
SetModalInputMode( false );
- // remove dialog from the list of dialogs which are being executed
- ImplSVData* pSVData = ImplGetSVData();
- Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
- while ( pExeDlg )
- {
- if ( pExeDlg == this )
- {
- pSVData->maWinData.mpLastExecuteDlg = mpPrevExecuteDlg;
- break;
- }
- pExeDlg = pExeDlg->mpPrevExecuteDlg;
- }
+ RemoveFromDlgList();
+
// set focus to previous modal dialogue if it is modal for
// the same frame parent (or NULL)
if( mpPrevExecuteDlg )
{
vcl::Window* pFrameParent = ImplGetFrameWindow()->ImplGetParent();
- vcl::Window* pPrevFrameParent = mpPrevExecuteDlg->ImplGetFrameWindow()->ImplGetParent();
+ vcl::Window* pPrevFrameParent = mpPrevExecuteDlg->ImplGetFrameWindow()? mpPrevExecuteDlg->ImplGetFrameWindow()->ImplGetParent(): nullptr;
if( ( !pFrameParent && !pPrevFrameParent ) ||
( pFrameParent && pPrevFrameParent && pFrameParent->ImplGetFrame() == pPrevFrameParent->ImplGetFrame() )
)
@@ -1000,6 +1031,7 @@ void Dialog::EndDialog( long nResult )
}
}
mpPrevExecuteDlg = nullptr;
+ mpNextExecuteDlg = nullptr;
Hide();
if ( GetParent() )
@@ -1013,16 +1045,19 @@ void Dialog::EndDialog( long nResult )
if ( mpDialogImpl->mbStartedModal )
{
ImplEndExecuteModal();
- if (mpDialogImpl->maEndDialogHdl.IsSet())
+ if (mpDialogImpl->maEndCtx.isSet())
{
- mpDialogImpl->maEndDialogHdl.Call( *this );
- mpDialogImpl->maEndDialogHdl = Link<Dialog&,void>();
+ mpDialogImpl->maEndCtx.maEndDialogFn(nResult);
+ mpDialogImpl->maEndCtx.maEndDialogFn = nullptr;
}
mpDialogImpl->mbStartedModal = false;
mpDialogImpl->mnResult = -1;
}
mbInExecute = false;
}
+
+ // Destroy ourselves (if we have a context with VclPtr owner)
+ mpDialogImpl->maEndCtx.mxOwner.disposeAndClear();
}
long Dialog::GetResult() const
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 77f6c28d168e..430dbe3ac2cf 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -2517,6 +2517,8 @@ bool Window::IsCallHandlersOnInputDisabled() const
void Window::EnableInput( bool bEnable, bool bChild )
{
+ if (!mpWindowImpl)
+ return;
bool bNotify = (bEnable != mpWindowImpl->mbInputDisabled);
if ( mpWindowImpl->mpBorderWindow )
@@ -2580,6 +2582,9 @@ void Window::EnableInput( bool bEnable, bool bChild )
void Window::EnableInput( bool bEnable, const vcl::Window* pExcludeWindow )
{
+ if (!mpWindowImpl)
+ return;
+
EnableInput( bEnable );
// pExecuteWindow is the first Overlap-Frame --> if this