[Libreoffice-commits] core.git: sd/source

Pranav Kant pranavk at collabora.co.uk
Sat Mar 17 03:19:48 UTC 2018


 sd/source/ui/func/fuinsert.cxx |   21 ++-------------------
 sd/source/ui/inc/View.hxx      |    2 +-
 sd/source/ui/inc/Window.hxx    |    1 +
 sd/source/ui/view/sdview2.cxx  |   13 ++-----------
 sd/source/ui/view/sdwindow.cxx |   20 ++++++++++++++++++++
 5 files changed, 26 insertions(+), 31 deletions(-)

New commits:
commit 1990fc47bb561fcb9f98cbdcb7f986b93a54b876
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Mar 8 21:07:40 2018 +0100

    sd lok: Enable mapmode in case of lok to calculate center
    
    This reverts the solution in 9fee132c18b658c9ea9fb1114c1fefa56b57532a.
    
    Also, calculate center using the new function for chart, image, and text
    shape insertion.
    
    Change-Id: Ie893050b7c875760db0194e7a3f0c2cd3068963b
    Reviewed-on: https://gerrit.libreoffice.org/51343
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>

diff --git a/sd/source/ui/func/fuinsert.cxx b/sd/source/ui/func/fuinsert.cxx
index 7d18f8e6ab4c..397580a029e1 100644
--- a/sd/source/ui/func/fuinsert.cxx
+++ b/sd/source/ui/func/fuinsert.cxx
@@ -69,7 +69,6 @@
 #include <sfx2/opengrf.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <svx/charthelper.hxx>
-#include <comphelper/lok.hxx>
 
 #include <app.hrc>
 #include <sdresid.hxx>
@@ -170,20 +169,7 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq )
                 bSelectionReplaced = true;
             }
 
-            Point aPos;
-            // For LOK, set position to center of the page
-            if (comphelper::LibreOfficeKit::isActive())
-                aPos = ::tools::Rectangle(aPos, mpView->GetSdrPageView()->GetPage()->GetSize()).Center();
-            else
-            {
-                ::tools::Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
-                aPos = aRect.Center();
-                bool bMapModeWasEnabled(mpWindow->IsMapModeEnabled());
-                mpWindow->EnableMapMode(/*true*/);
-                aPos = mpWindow->PixelToLogic(aPos);
-                mpWindow->EnableMapMode(bMapModeWasEnabled);
-            }
-
+            Point aPos = mpWindow->GetVisibleCenter();
             SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, nullptr);
 
             if(pGrafObj && bAsLink )
@@ -380,10 +366,7 @@ void FuInsertOLE::DoExecute( SfxRequest& rReq )
                     aSize = OutputDevice::LogicToLogic(aSize, MapMode(aUnit), MapMode(MapUnit::Map100thMM));
                 }
 
-                Point aPos;
-                ::tools::Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
-                aPos = aWinRect.Center();
-                aPos = mpWindow->PixelToLogic(aPos);
+                Point aPos = mpWindow->GetVisibleCenter();
                 aPos.AdjustX( -(aSize.Width() / 2) );
                 aPos.AdjustY( -(aSize.Height() / 2) );
                 aRect = ::tools::Rectangle(aPos, aSize);
diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx
index 271a8850f707..962b6d43f56e 100644
--- a/sd/source/ui/inc/View.hxx
+++ b/sd/source/ui/inc/View.hxx
@@ -91,7 +91,7 @@ public:
     void                    SelectAll();
     void                    DoCut();
     void                    DoCopy();
-    void                    DoPaste(vcl::Window const * pWindow=nullptr);
+    void                    DoPaste(::sd::Window* pWindow=nullptr);
     virtual void            DoConnect(SdrOle2Obj* pOleObj) override;
     virtual bool            SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr = false);
     void                    StartDrag( const Point& rStartPos, vcl::Window* pWindow );
diff --git a/sd/source/ui/inc/Window.hxx b/sd/source/ui/inc/Window.hxx
index d1aa74a91602..d03890f6f491 100644
--- a/sd/source/ui/inc/Window.hxx
+++ b/sd/source/ui/inc/Window.hxx
@@ -131,6 +131,7 @@ public:
     void    SetVisibleXY(double fX, double fY);
     double  GetVisibleWidth();
     double  GetVisibleHeight();
+    Point   GetVisibleCenter();
     double  GetScrlLineWidth();
     double  GetScrlLineHeight();
     double  GetScrlPageWidth();
diff --git a/sd/source/ui/view/sdview2.cxx b/sd/source/ui/view/sdview2.cxx
index 81aff44869e2..57db0d9bef2d 100644
--- a/sd/source/ui/view/sdview2.cxx
+++ b/sd/source/ui/view/sdview2.cxx
@@ -264,7 +264,7 @@ void View::DoCopy()
     }
 }
 
-void View::DoPaste (vcl::Window const * pWindow)
+void View::DoPaste (::sd::Window* pWindow)
 {
     TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewSh->GetActiveWindow() ) );
     if( !aDataHelper.GetTransferable().is() )
@@ -315,17 +315,8 @@ void View::DoPaste (vcl::Window const * pWindow)
     }
     else
     {
-        Point       aPos;
         sal_Int8    nDnDAction = DND_ACTION_COPY;
-
-        if( pWindow )
-        {
-            if (comphelper::LibreOfficeKit::isActive())
-                aPos = ::tools::Rectangle(aPos, GetSdrPageView()->GetPage()->GetSize()).Center();
-            else
-                aPos = pWindow->PixelToLogic( ::tools::Rectangle( aPos, pWindow->GetOutputSizePixel() ).Center() );
-        }
-
+        Point aPos = pWindow->GetVisibleCenter();
         DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>( mpDocSh->GetViewShell() );
 
         if (pDrViewSh != nullptr)
diff --git a/sd/source/ui/view/sdwindow.cxx b/sd/source/ui/view/sdwindow.cxx
index b81249061b87..2d17fbe5ec3b 100644
--- a/sd/source/ui/view/sdwindow.cxx
+++ b/sd/source/ui/view/sdwindow.cxx
@@ -683,6 +683,26 @@ double Window::GetVisibleHeight()
     return (static_cast<double>(aWinSize.Height()) / maViewSize.Height());
 }
 
+Point Window::GetVisibleCenter()
+{
+    Size aWinSize = PixelToLogic(GetOutputSizePixel());
+    if ( aWinSize.Height() > maViewSize.Height() )
+        aWinSize.setHeight( maViewSize.Height() );
+    if ( aWinSize.Width() > maViewSize.Width() )
+        aWinSize.setWidth( maViewSize.Width() );
+
+    Point aPos;
+    aPos = ::tools::Rectangle(aPos, aWinSize).Center();
+
+    // For LOK
+    bool bMapModeWasEnabled(IsMapModeEnabled());
+    EnableMapMode(/*true*/);
+    aPos = PixelToLogic(aPos);
+    EnableMapMode(bMapModeWasEnabled);
+
+    return aPos;
+}
+
 /**
  * @returns width of a scroll column in proportion to the width of the whole
  * working area.


More information about the Libreoffice-commits mailing list