Blob Blame History Raw
From f33f59871bc268dbfef6843a8196fe03d7419874 Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Tue, 13 Oct 2015 15:54:56 +0200
Subject: [PATCH 215/398] editeng: add EditView::GetSelectionRectangles()

This gives sd access to the selection rectangles as well (as opposed
only to the document model positions of selections).

Change-Id: Icb903e91f9e868573403b360bbe839705ddf2916
(cherry picked from commit f7764214f2ab8aff030aaeb29efd693275822761)
---
 editeng/source/editeng/editview.cxx |  5 +++++
 editeng/source/editeng/impedit.cxx  | 22 +++++++++++++++++-----
 editeng/source/editeng/impedit.hxx  |  1 +
 editeng/source/outliner/outlvw.cxx  |  5 +++++
 include/editeng/editview.hxx        |  2 ++
 include/editeng/outliner.hxx        |  1 +
 6 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 049c5a1eb256..66a49ed925de 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -264,6 +264,11 @@ SvtScriptType EditView::GetSelectedScriptType() const
     return pImpEditView->pEditEngine->GetScriptType( pImpEditView->GetEditSelection() );
 }
 
+void EditView::GetSelectionRectangles(std::vector<Rectangle>& rLogicRects) const
+{
+    return pImpEditView->GetSelectionRectangles(rLogicRects);
+}
+
 void EditView::Paint( const Rectangle& rRect, OutputDevice* pTargetDevice )
 {
     pImpEditView->pEditEngine->pImpEditEngine->Paint( pImpEditView, rRect, pTargetDevice );
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index 08d990b2d2ef..f7e2886c0524 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -184,12 +184,10 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
 
     // pRegion: When not NULL, then only calculate Region.
 
+    vcl::Region* pOldRegion = pRegion;
     vcl::Region aRegion;
-    if (isTiledRendering())
-    {
-        assert(!pRegion);
+    if (isTiledRendering() && !pRegion)
         pRegion = &aRegion;
-    }
 
     tools::PolyPolygon* pPolyPoly = NULL;
     if ( pRegion )
@@ -326,7 +324,7 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
     {
         *pRegion = vcl::Region( *pPolyPoly );
 
-        if (isTiledRendering())
+        if (isTiledRendering() && !pOldRegion)
         {
             bool bMm100ToTwip = pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM;
             OString sRectangle;
@@ -380,6 +378,20 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
     }
 }
 
+void ImpEditView::GetSelectionRectangles(std::vector<Rectangle>& rLogicRects)
+{
+    bool bMm100ToTwip = pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM;
+    vcl::Region aRegion;
+    DrawSelection(aEditSelection, &aRegion);
+    aRegion.GetRegionRectangles(rLogicRects);
+
+    for (Rectangle& rRectangle : rLogicRects)
+    {
+        if (bMm100ToTwip)
+            rRectangle = OutputDevice::LogicToLogic(rRectangle, MAP_100TH_MM, MAP_TWIP);
+    }
+}
+
 void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly )
 {
     if ( rDocPosTopLeft.X() != rDocPosBottomRight.X() )
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 4866523f5171..7b24e6e790b7 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -319,6 +319,7 @@ public:
 
     void            DrawSelection() { DrawSelection( aEditSelection ); }
     void            DrawSelection( EditSelection, vcl::Region* pRegion = NULL, OutputDevice* pTargetDevice = NULL );
+    void GetSelectionRectangles(std::vector<Rectangle>& rLogicRects);
 
     vcl::Window*         GetWindow() const           { return pOutWin; }
 
diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx
index 92f967877e24..329b5f3c0ed4 100644
--- a/editeng/source/outliner/outlvw.cxx
+++ b/editeng/source/outliner/outlvw.cxx
@@ -1213,6 +1213,11 @@ void OutlinerView::SetSelection( const ESelection& rSel )
     pEditView->SetSelection( rSel );
 }
 
+void OutlinerView::GetSelectionRectangles(std::vector<Rectangle>& rLogicRects) const
+{
+    pEditView->GetSelectionRectangles(rLogicRects);
+}
+
 void OutlinerView::SetReadOnly( bool bReadOnly )
 {
     pEditView->SetReadOnly( bReadOnly );
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index bb091172c9ba..41146fac63a5 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -114,6 +114,8 @@ public:
     ESelection      GetSelection() const;
     void            SetSelection( const ESelection& rNewSel );
     bool            SelectCurrentWord( sal_Int16 nWordType = ::com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
+    /// Returns the rectangles of the current selection in TWIPs.
+    void GetSelectionRectangles(std::vector<Rectangle>& rLogicRects) const;
 
     bool            IsInsertMode() const;
     void            SetInsertMode( bool bInsert );
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index 5a2dbe9f8cf9..dddb221ec9cc 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -310,6 +310,7 @@ public:
 
     void        SetVisArea( const Rectangle& rRect );
     void        SetSelection( const ESelection& );
+    void GetSelectionRectangles(std::vector<Rectangle>& rLogicRects) const;
 
     void        RemoveAttribs( bool bRemoveParaAttribs = false, sal_uInt16 nWhich = 0, bool bKeepLanguages = false );
     void        RemoveAttribsKeepLanguages( bool bRemoveParaAttribs );
-- 
2.12.0