diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-05-20 18:53:39 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-05-21 11:19:05 +0200 |
commit | b516387cda854c93af29d270816b8acdb86d4d36 (patch) | |
tree | 438d661a5edb3d1fdae10fb9671013368436e8c9 /sd/source/ui/table/tablefunction.cxx | |
parent | c0f402da0f3ae8318103fc269e98c25617e83111 (diff) |
Make Impress Insert Table dialog async
Change-Id: If8b48cfe983819387c066d3bd81a42dad8947489
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94591
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94612
Tested-by: Jenkins
Diffstat (limited to 'sd/source/ui/table/tablefunction.cxx')
-rw-r--r-- | sd/source/ui/table/tablefunction.cxx | 196 |
1 files changed, 107 insertions, 89 deletions
diff --git a/sd/source/ui/table/tablefunction.cxx b/sd/source/ui/table/tablefunction.cxx index 2a031e525d32..1f49f5fc2fff 100644 --- a/sd/source/ui/table/tablefunction.cxx +++ b/sd/source/ui/table/tablefunction.cxx @@ -84,6 +84,98 @@ static void apply_table_style( SdrTableObj* pObj, SdrModel const * pModel, const } } +static void InsertTableImpl(DrawViewShell* pShell, + ::sd::View* pView, + sal_Int32 nColumns, + sal_Int32 nRows, + const OUString& sTableStyle) +{ + ::tools::Rectangle aRect; + + SdrObject* pPickObj = pView->GetEmptyPresentationObject( PresObjKind::Table ); + if( pPickObj ) + { + aRect = pPickObj->GetLogicRect(); + aRect.setHeight( 200 ); + } + else + { + Size aSize( 14100, 2000 ); + + Point aPos; + ::tools::Rectangle aWinRect(aPos, pShell->GetActiveWindow()->GetOutputSizePixel()); + aWinRect = pShell->GetActiveWindow()->PixelToLogic(aWinRect); + + // make sure that the default size of the table fits on the paper and is inside the viewing area. + // if zoomed in close, don't make the table bigger than the viewing window. + Size aMaxSize = pShell->getCurrentPage()->GetSize(); + + if (comphelper::LibreOfficeKit::isActive()) + { + // aWinRect is nonsensical in the LOK case + aWinRect = ::tools::Rectangle(aPos, aMaxSize); + } + else + { + if( aMaxSize.Height() > aWinRect.getHeight() ) + aMaxSize.setHeight( aWinRect.getHeight() ); + if( aMaxSize.Width() > aWinRect.getWidth() ) + aMaxSize.setWidth( aWinRect.getWidth() ); + } + + if( aSize.Width() > aMaxSize.getWidth() ) + aSize.setWidth( aMaxSize.getWidth() ); + + // adjust height based on # of rows. + if( nRows > 0 ) + { + aSize.setHeight( aSize.Height() * nRows ); + if( aSize.Height() > aMaxSize.getHeight() ) + aSize.setHeight( aMaxSize.getHeight() ); + } + + aPos = aWinRect.Center(); + aPos.AdjustX( -(aSize.Width() / 2) ); + aPos.AdjustY( -(aSize.Height() / 2) ); + aRect = ::tools::Rectangle(aPos, aSize); + } + + sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( + *pShell->GetDoc(), // TTTT should be reference + aRect, + nColumns, + nRows); + pObj->NbcSetStyleSheet( pShell->GetDoc()->GetDefaultStyleSheet(), true ); + apply_table_style( pObj, pShell->GetDoc(), sTableStyle ); + SdrPageView* pPV = pView->GetSdrPageView(); + + // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode, + // so to be on the safe side call SdrEndTextEdit here + SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj); + + if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode()) + { + pView->SdrEndTextEdit(); + } + + // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj + if( pPickObj ) + { + SdPage* pPage = static_cast< SdPage* >(pPickObj->getSdrPageFromSdrObject()); + if(pPage && pPage->IsPresObj(pPickObj)) + { + pObj->SetUserCall( pPickObj->GetUserCall() ); + pPage->InsertPresObj( pObj, PresObjKind::Table ); + } + } + + pShell->GetParentWindow()->GrabFocus(); + if( pPickObj ) + pView->ReplaceObjectAtView(pPickObj, *pPV, pObj ); + else + pView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER); +} + void DrawViewShell::FuTable(SfxRequest& rReq) { switch( rReq.GetSlot() ) @@ -93,6 +185,8 @@ void DrawViewShell::FuTable(SfxRequest& rReq) sal_Int32 nColumns = 0; sal_Int32 nRows = 0; OUString sTableStyle; + DrawViewShell* pShell = this; + ::sd::View* pView = mpView; const SfxUInt16Item* pCols = rReq.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_COLUMN); const SfxUInt16Item* pRows = rReq.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ROW); @@ -110,100 +204,24 @@ void DrawViewShell::FuTable(SfxRequest& rReq) if( (nColumns == 0) || (nRows == 0) ) { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<SvxAbstractNewTableDialog> pDlg( pFact->CreateSvxNewTableDialog(rReq.GetFrameWeld()) ); - - if( pDlg->Execute() != RET_OK ) - break; - - nColumns = pDlg->getColumns(); - nRows = pDlg->getRows(); - } - - ::tools::Rectangle aRect; - - SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PresObjKind::Table ); - if( pPickObj ) - { - aRect = pPickObj->GetLogicRect(); - aRect.setHeight( 200 ); + std::shared_ptr<SvxAbstractNewTableDialog> pDlg( pFact->CreateSvxNewTableDialog(rReq.GetFrameWeld()) ); + + weld::DialogController::runAsync(pDlg->getDialogController(), + [pDlg, pShell, pView, sTableStyle] (sal_Int32 nResult) { + if (nResult == RET_OK) + { + sal_Int32 nColumnsIn = pDlg->getColumns(); + sal_Int32 nRowsIn = pDlg->getRows(); + + InsertTableImpl(pShell, pView, nColumnsIn, nRowsIn, sTableStyle); + } + }); } else { - Size aSize( 14100, 2000 ); - - Point aPos; - ::tools::Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel()); - aWinRect = GetActiveWindow()->PixelToLogic(aWinRect); - - // make sure that the default size of the table fits on the paper and is inside the viewing area. - // if zoomed in close, don't make the table bigger than the viewing window. - Size aMaxSize = getCurrentPage()->GetSize(); - - if (comphelper::LibreOfficeKit::isActive()) - { - // aWinRect is nonsensical in the LOK case - aWinRect = ::tools::Rectangle(aPos, aMaxSize); - } - else - { - if( aMaxSize.Height() > aWinRect.getHeight() ) - aMaxSize.setHeight( aWinRect.getHeight() ); - if( aMaxSize.Width() > aWinRect.getWidth() ) - aMaxSize.setWidth( aWinRect.getWidth() ); - } - - if( aSize.Width() > aMaxSize.getWidth() ) - aSize.setWidth( aMaxSize.getWidth() ); - - // adjust height based on # of rows. - if( nRows > 0 ) - { - aSize.setHeight( aSize.Height() * nRows ); - if( aSize.Height() > aMaxSize.getHeight() ) - aSize.setHeight( aMaxSize.getHeight() ); - } - - aPos = aWinRect.Center(); - aPos.AdjustX( -(aSize.Width() / 2) ); - aPos.AdjustY( -(aSize.Height() / 2) ); - aRect = ::tools::Rectangle(aPos, aSize); - } - - sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( - *GetDoc(), // TTTT should be reference - aRect, - nColumns, - nRows); - pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), true ); - apply_table_style( pObj, GetDoc(), sTableStyle ); - SdrPageView* pPV = mpView->GetSdrPageView(); - - // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode, - // so to be on the safe side call SdrEndTextEdit here - SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj); - - if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode()) - { - mpView->SdrEndTextEdit(); - } - - // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj - if( pPickObj ) - { - SdPage* pPage = static_cast< SdPage* >(pPickObj->getSdrPageFromSdrObject()); - if(pPage && pPage->IsPresObj(pPickObj)) - { - pObj->SetUserCall( pPickObj->GetUserCall() ); - pPage->InsertPresObj( pObj, PresObjKind::Table ); - } + InsertTableImpl(pShell, pView, nColumns, nRows, sTableStyle); } - GetParentWindow()->GrabFocus(); - if( pPickObj ) - mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj ); - else - mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER); - rReq.Ignore(); SfxViewShell* pViewShell = GetViewShell(); OSL_ASSERT (pViewShell!=nullptr); |