diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-01-26 16:35:10 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-03-09 09:55:04 +0100 |
commit | 878e8fe7ffeada3d6154fe4750079deb38e1ce94 (patch) | |
tree | 54b9c53745581ded7a0b1b5ef7a9788b589742a2 | |
parent | 067b22aeff5ff256be393dc2aa14acdf0300427a (diff) |
fontwork: insert in the center of LOK view
Change-Id: Iabde4ee927546b0e396c4fbd6d0099fa82240166
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109968
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112163
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | include/sfx2/viewsh.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/tabvwsh.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsh4.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/inc/ViewShellBase.hxx | 4 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 11 | ||||
-rw-r--r-- | svx/source/tbxctrls/fontworkgallery.cxx | 49 | ||||
-rw-r--r-- | sw/inc/view.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view.cxx | 9 | ||||
-rw-r--r-- | sw/source/uibase/uiview/viewdraw.cxx | 14 |
10 files changed, 83 insertions, 17 deletions
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index a25da48c39d4..8742820dde51 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -382,6 +382,8 @@ public: bool isLOKTablet() const { return maLOKDeviceFormFactor == LOKDeviceFormFactor::TABLET; } /// Check if the lok client is running on a mobile device. bool isLOKMobilePhone() const { return maLOKDeviceFormFactor == LOKDeviceFormFactor::MOBILE; } + + virtual tools::Rectangle getLOKVisibleArea() const { return tools::Rectangle(); } }; diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx index 351c9e2cbeee..94f8e14ebb91 100644 --- a/sc/source/ui/inc/tabvwsh.hxx +++ b/sc/source/ui/inc/tabvwsh.hxx @@ -399,6 +399,8 @@ public: void InitFormEditData(); void ClearFormEditData(); ScFormEditData* GetFormEditData() { return mpFormEditData.get(); } + + virtual tools::Rectangle getLOKVisibleArea() const override; }; #endif diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index cb13072d0edc..0707b7038409 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -1855,4 +1855,9 @@ ScNavigatorSettings* ScTabViewShell::GetNavigatorSettings() return pNavSettings.get(); } +tools::Rectangle ScTabViewShell::getLOKVisibleArea() const +{ + return GetViewData().getLOKVisibleArea(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/inc/ViewShellBase.hxx b/sd/source/ui/inc/ViewShellBase.hxx index d80e6113fdd3..f61cab75661b 100644 --- a/sd/source/ui/inc/ViewShellBase.hxx +++ b/sd/source/ui/inc/ViewShellBase.hxx @@ -217,6 +217,9 @@ public: /// See SfxViewShell::NotifyCursor(). void NotifyCursor(SfxViewShell* pViewShell) const override; + void setLOKVisibleArea(const ::tools::Rectangle& rArea) { maLOKVisibleArea = rArea; } + virtual ::tools::Rectangle getLOKVisibleArea() const override { return maLOKVisibleArea; } + protected: virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override; @@ -228,6 +231,7 @@ private: std::unique_ptr<Implementation> mpImpl; DrawDocShell* mpDocShell; SdDrawDocument* mpDocument; + ::tools::Rectangle maLOKVisibleArea; /** Determine from the properties of the document shell the initial type of the view shell in the center pane. We use this method to avoid diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index 7856e46aa33f..747ce4e585cb 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -255,6 +255,8 @@ public: virtual void setGraphicSelection(int nType, int nX, int nY) override; /// @see lok::Document::resetSelection(). virtual void resetSelection() override; + /// @see vcl::ITiledRenderable::setClientVisibleArea(). + virtual void setClientVisibleArea(const tools::Rectangle& rRectangle) override; /// @see vcl::ITiledRenderable::setClipboard(). virtual void setClipboard(const css::uno::Reference<css::datatransfer::clipboard::XClipboard>& xClipboard) override; /// @see vcl::ITiledRenderable::isMimeTypeSupported(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 411af888513f..62b35a5cbfe9 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2607,6 +2607,17 @@ void SdXImpressDocument::resetSelection() pSdrView->UnmarkAll(); } +void SdXImpressDocument::setClientVisibleArea(const ::tools::Rectangle& rRectangle) +{ + SolarMutexGuard aGuard; + + DrawViewShell* pViewShell = GetViewShell(); + if (!pViewShell) + return; + + pViewShell->GetViewShellBase().setLOKVisibleArea(rRectangle); +} + void SdXImpressDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard) { SolarMutexGuard aGuard; diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx index bfcde08d09c8..7acaac50b15c 100644 --- a/svx/source/tbxctrls/fontworkgallery.cxx +++ b/svx/source/tbxctrls/fontworkgallery.cxx @@ -20,16 +20,19 @@ #include <com/sun/star/text/WritingMode.hpp> +#include <comphelper/lok.hxx> + #include <vcl/toolbox.hxx> #include <vcl/virdev.hxx> +#include <sfx2/viewsh.hxx> + #include <svl/itempool.hxx> #include <svtools/toolbarmenu.hxx> #include <svtools/popupwindowcontroller.hxx> #include <svx/fmmodel.hxx> -#include <svx/dialmgr.hxx> #include <svx/strings.hrc> #include <svx/svdpage.hxx> #include <svx/svdobj.hxx> @@ -38,6 +41,8 @@ #include <svx/gallery.hxx> #include <svx/fontworkgallery.hxx> +#include <tools/UnitConversion.hxx> + #include <algorithm> #include <memory> @@ -193,17 +198,41 @@ void FontWorkGalleryDialog::insertSelectedFontwork() // pNewObject->SetPage(nullptr); tools::Rectangle aObjRect( pNewObject->GetLogicRect() ); - tools::Rectangle aVisArea = pOutDev->PixelToLogic(tools::Rectangle(Point(0,0), pOutDev->GetOutputSizePixel())); - Point aPagePos = aVisArea.Center(); - bool bIsInsertedObjectSmallerThanVisibleArea = - aVisArea.GetSize().getHeight() > aObjRect.GetSize().getHeight() && - aVisArea.GetSize().getWidth() > aObjRect.GetSize().getWidth(); - if (bIsInsertedObjectSmallerThanVisibleArea) + Point aPagePos; + Size aFontworkSize = aObjRect.GetSize(); + + if (comphelper::LibreOfficeKit::isActive()) { - aPagePos.AdjustX( -(aObjRect.GetWidth() / 2) ); - aPagePos.AdjustY( -(aObjRect.GetHeight() / 2) ); + SfxViewShell* pViewShell = SfxViewShell::Current(); + + aPagePos = pViewShell->getLOKVisibleArea().Center(); + + aPagePos.setX(convertTwipToMm100(aPagePos.X())); + aPagePos.setY(convertTwipToMm100(aPagePos.Y())); + + sal_Int32 nLOKViewWidth = 0.8 * convertTwipToMm100(pViewShell->getLOKVisibleArea().getWidth()); + if (aFontworkSize.getWidth() > nLOKViewWidth) + { + double fScale = static_cast<double>(aFontworkSize.getWidth()) / nLOKViewWidth; + aFontworkSize.setWidth(aFontworkSize.getWidth() / fScale); + aFontworkSize.setHeight(aFontworkSize.getHeight() / fScale); + } } - tools::Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize()); + else + { + Size aSize = pOutDev->GetOutputSizePixel(); + tools::Rectangle aPixelVisRect(Point(0,0), aSize); + tools::Rectangle aVisArea = pOutDev->PixelToLogic(aPixelVisRect); + + aPagePos = aVisArea.Center(); + } + + if (aPagePos.getX() > aFontworkSize.getWidth() / 2) + aPagePos.AdjustX( -(aFontworkSize.getWidth() / 2) ); + if (aPagePos.getY() > aFontworkSize.getHeight() / 2) + aPagePos.AdjustY( -(aFontworkSize.getHeight() / 2) ); + + tools::Rectangle aNewObjectRectangle(aPagePos, aFontworkSize); pNewObject->SetLogicRect(aNewObjectRectangle); if (bUseSpecialCalcMode) diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx index e71a75423b88..f51a80aea1a3 100644 --- a/sw/inc/view.hxx +++ b/sw/inc/view.hxx @@ -674,6 +674,8 @@ public: void SetOldFrameCat(const OUString& sStr); const OUString& GetOldDrwCat(); void SetOldDrwCat(const OUString& sStr); + + virtual tools::Rectangle getLOKVisibleArea() const override; }; inline tools::Long SwView::GetXScroll() const diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 33a7344107c0..2a2ff5a563b6 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -1862,6 +1862,15 @@ void SwView::AddTransferable(SwTransferable& rTransferable) GetViewImpl()->AddTransferable(rTransferable); } +tools::Rectangle SwView::getLOKVisibleArea() const +{ + SwViewShell* pVwSh = GetWrtShellPtr(); + if (pVwSh) + return pVwSh->getLOKVisibleArea(); + else + return tools::Rectangle(); +} + namespace sw { void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb) diff --git a/sw/source/uibase/uiview/viewdraw.cxx b/sw/source/uibase/uiview/viewdraw.cxx index f27000acbd71..680d7ba788e7 100644 --- a/sw/source/uibase/uiview/viewdraw.cxx +++ b/sw/source/uibase/uiview/viewdraw.cxx @@ -159,10 +159,9 @@ void SwView::ExecDraw(SfxRequest& rReq) if ( pObj ) { Size aDocSize( m_pWrtShell->GetDocSize() ); - const SwRect& rVisArea = m_pWrtShell->VisArea(); + const SwRect& rVisArea = comphelper::LibreOfficeKit::isActive() ? + m_pWrtShell->getLOKVisibleArea() : m_pWrtShell->VisArea(); Point aPos( rVisArea.Center() ); - Size aSize; - Size aPrefSize( pObj->GetSnapRect().GetSize() ); if( rVisArea.Width() > aDocSize.Width()) aPos.setX( aDocSize.Width() / 2 + rVisArea.Left() ); @@ -170,10 +169,11 @@ void SwView::ExecDraw(SfxRequest& rReq) if(rVisArea.Height() > aDocSize.Height()) aPos.setY( aDocSize.Height() / 2 + rVisArea.Top() ); - if( aPrefSize.Width() && aPrefSize.Height() ) - aSize = rWin2.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip)); - else - aSize = Size( 2835, 2835 ); + tools::Rectangle aObjRect( pObj->GetLogicRect() ); + if (aPos.getX() > aObjRect.GetWidth() / 2) + aPos.AdjustX( -(aObjRect.GetWidth() / 2) ); + if (aPos.getY() > aObjRect.GetHeight() / 2) + aPos.AdjustY( -(aObjRect.GetHeight() / 2) ); m_pWrtShell->EnterStdMode(); m_pWrtShell->SwFEShell::InsertDrawObj( *pObj, aPos ); |