[Libreoffice-commits] core.git: 2 commits - sw/inc sw/source

Luboš Luňák l.lunak at collabora.com
Tue Aug 12 11:23:43 PDT 2014


 sw/inc/swregion.hxx                 |    1 +
 sw/inc/undobj.hxx                   |    2 +-
 sw/source/core/bastyp/swregion.cxx  |    6 ++++++
 sw/source/core/layout/trvlfrm.cxx   |   26 +++++++++++++++++++++++++-
 sw/source/core/undo/undobj.cxx      |   20 ++++++++++++++++----
 sw/source/filter/basflt/shellio.cxx |    3 ++-
 6 files changed, 51 insertions(+), 7 deletions(-)

New commits:
commit 78131b6bfc16d739e28024407de253c84cb68a8a
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Tue Aug 12 20:15:02 2014 +0200

    show fly anchored inside selection as selected too
    
    If part (or whole) document is selected and then the selection
    is e.g. deleted, flys anchored there will be deleted too, so it
    makes sense to show them as part of the selection.
    
    Change-Id: I17bfccebc0cd305c19616159471f0f113c7e71d9

diff --git a/sw/inc/swregion.hxx b/sw/inc/swregion.hxx
index 5602c12..b290e21 100644
--- a/sw/inc/swregion.hxx
+++ b/sw/inc/swregion.hxx
@@ -36,6 +36,7 @@ public:
 
     // For punching from aOrigin.
     void operator-=( const SwRect& rRect );
+    void operator+=( const SwRect& rRect );
 
     // From holes to areas, from areas to holes.
     void Invert();
diff --git a/sw/source/core/bastyp/swregion.cxx b/sw/source/core/bastyp/swregion.cxx
index d7cef15..dcd2eb3 100644
--- a/sw/source/core/bastyp/swregion.cxx
+++ b/sw/source/core/bastyp/swregion.cxx
@@ -45,6 +45,12 @@ inline void SwRegionRects::InsertRect( const SwRect &rRect,
     }
 }
 
+void SwRegionRects::operator+=( const SwRect &rRect )
+{
+    bool f = false;
+    InsertRect( rRect, 0, f );
+}
+
 /** Delete all overlaps of the Rects in array with the given <rRect>
 
     To do so, all existing rectangles have to be either split or deleted.
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index f98aee6..7f63987 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -1973,6 +1973,12 @@ inline void Sub( SwRegionRects& rRegion, const SwRect& rRect )
         rRegion -= rRect;
 }
 
+inline void Add( SwRegionRects& rRegion, const SwRect& rRect )
+{
+    if( rRect.Width() > 1 && rRect.Height() > 1 )
+        rRegion += rRect;
+}
+
 /*
  * The following situations can happen:
  *  1. Start and end lie in one screen-row and in the same node
@@ -1990,6 +1996,7 @@ inline void Sub( SwRegionRects& rRegion, const SwRect& rRect )
  * Exceptions:  - The Fly in which the selection took place (if it took place
  *                 in a Fly)
  *              - The Flys which are underrun by the text
+ *              - The Flys which are anchored to somewhere inside the selection.
  * Functioning: First a SwRegion with a root gets initialized.
  *              Out of the region the inverted sections are cut out. The
  *              section gets compressed and finally inverted and thereby the
@@ -2549,6 +2556,7 @@ void SwRootFrm::CalcFrmRects(SwShellCrsr &rCrsr)
     //   sit in it)
     // - if in the Z-order we have Flys above those in which the StartFrm is
     //   placed
+    // - if they are anchored to inside the selection and thus part of it
     const SwPageFrm *pPage      = pStartFrm->FindPageFrm();
     const SwPageFrm *pEndPage   = pEndFrm->FindPageFrm();
 
@@ -2565,7 +2573,23 @@ void SwRootFrm::CalcFrmRects(SwShellCrsr &rCrsr)
                 const SwFlyFrm* pFly = static_cast<const SwFlyFrm*>(pAnchoredObj);
                 const SwVirtFlyDrawObj* pObj = pFly->GetVirtDrawObj();
                 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
-                if ( !pFly->IsAnLower( pStartFrm ) &&
+                SwPosition anchoredAt = *pAnchoredObj->GetFrmFmt().GetAnchor().GetCntntAnchor();
+                bool inSelection = ( *pStartPos <= anchoredAt && anchoredAt < *pEndPos );
+                if( anchoredAt == *pEndPos )
+                {
+                    const SwNodes& nodes = anchoredAt.GetDoc()->GetNodes();
+                    if( *pEndPos == SwPosition( nodes.GetEndOfContent()))
+                        inSelection = true;
+                    else
+                    {
+                        SwNodeIndex idx( nodes.GetEndOfContent());
+                     if( SwCntntNode* last = nodes.GoPrevious( &idx ))
+                        inSelection = *pEndPos == SwPosition( *last, last->Len());
+                    }
+                }
+                if( inSelection )
+                        Add( aRegion, pFly->Frm() );
+                else if ( !pFly->IsAnLower( pStartFrm ) &&
                     (rSur.GetSurround() != SURROUND_THROUGHT &&
                     !rSur.IsContour()) )
                 {
commit 2903d85d6197829633d7f96c95cd55821c2c20ff
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Tue Aug 12 18:39:02 2014 +0200

    fix deleting an image anchored to last paragraph in document
    
    It only compared nodes instead of SwPositions, thus refusing to delete
    anything anchored at the last content node. Also, select-all makes
    rEnd point to the last content node, after its content. So if
    an anchor-to-char image is anchored at the end of the paragraph,
    it points to this place, too, so that must be checked.
    
    Change-Id: Ie0ba6ed59f47e59492ad88577392884cadb52106

diff --git a/sw/inc/undobj.hxx b/sw/inc/undobj.hxx
index 9c0ff35..a1febc4 100644
--- a/sw/inc/undobj.hxx
+++ b/sw/inc/undobj.hxx
@@ -134,7 +134,7 @@ namespace nsDelCntntType
 
 /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
 bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
-        SwPosition const & rStart, SwPosition const & rEnd,
+        SwPosition const & rStart, SwPosition const & rEnd, const SwDoc* doc,
         DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
 
 // This class has to be inherited into an Undo-object if it saves content
diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx
index 7124511..ff2a30b 100644
--- a/sw/source/core/undo/undobj.cxx
+++ b/sw/source/core/undo/undobj.cxx
@@ -645,7 +645,7 @@ void SwUndoSaveCntnt::DelCntntIndex( const SwPosition& rMark,
                         if( !pHistory )
                             pHistory = new SwHistory;
                         if (IsDestroyFrameAnchoredAtChar(
-                                *pAPos, *pStt, *pEnd, nDelCntntType))
+                                *pAPos, *pStt, *pEnd, pDoc, nDelCntntType))
                         {
                             pHistory->Add( *pFmt, nChainInsPos );
                             n = n >= rSpzArr.size() ? rSpzArr.size() : n+1;
@@ -1145,15 +1145,27 @@ OUString ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString
 }
 
 bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
-        SwPosition const & rStart, SwPosition const & rEnd,
+        SwPosition const & rStart, SwPosition const & rEnd, const SwDoc* doc,
         DelCntntType const nDelCntntType)
 {
-
+    bool inSelection = rAnchorPos < rEnd;
+    if( rAnchorPos == rEnd )
+    {
+        const SwNodes& nodes = doc->GetNodes();
+        if( rEnd == SwPosition( nodes.GetEndOfContent()))
+            inSelection = true;
+        else
+        {
+            SwNodeIndex idx( nodes.GetEndOfContent());
+         if( SwCntntNode* last = nodes.GoPrevious( &idx ))
+            inSelection = rEnd == SwPosition( *last, last->Len());
+        }
+    }
     // Here we identified the objects to destroy:
     // - anchored between start and end of the selection
     // - anchored in start of the selection with "CheckNoContent"
     // - anchored in start of sel. and the selection start at pos 0
-    return  (rAnchorPos.nNode < rEnd.nNode)
+    return  inSelection
          && (   (nsDelCntntType::DELCNT_CHKNOCNTNT & nDelCntntType)
             ||  (rStart.nNode < rAnchorPos.nNode)
             ||  !rStart.nContent.GetIndex()
diff --git a/sw/source/filter/basflt/shellio.cxx b/sw/source/filter/basflt/shellio.cxx
index 6505ccf..8a1bb01 100644
--- a/sw/source/filter/basflt/shellio.cxx
+++ b/sw/source/filter/basflt/shellio.cxx
@@ -237,7 +237,8 @@ sal_uLong SwReader::Read( const Reader& rOptions )
                                     &&  !IsDestroyFrameAnchoredAtChar(
                                               *pFrameAnchor,
                                               *pUndoPam->GetPoint(),
-                                              *pUndoPam->GetMark())
+                                              *pUndoPam->GetMark(),
+                                              pDoc)
                                     )
                                 )
                             )


More information about the Libreoffice-commits mailing list