1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unocrsr.hxx>
22 #include <IDocumentLayoutAccess.hxx>
23 #include <swtable.hxx>
24 #include <rootfrm.hxx>
26 sw::UnoCursorHint::~UnoCursorHint() {}
28 SwUnoCursor::SwUnoCursor( const SwPosition
&rPos
)
29 : SwCursor( rPos
, nullptr )
30 , m_bRemainInSection(true)
31 , m_bSkipOverHiddenSections(false)
32 , m_bSkipOverProtectSections(false)
35 SwUnoCursor::~SwUnoCursor()
37 SwDoc
& rDoc
= GetDoc();
38 if( !rDoc
.IsInDtor() )
40 assert(!m_aNotifier
.HasListeners());
43 // delete the whole ring
44 while( GetNext() != this )
46 Ring
* pNxt
= GetNextInRing();
47 // coverity[deref_arg] - the delete moves a new entry into GetNext()
48 pNxt
->MoveTo(nullptr); // remove from chain
49 delete pNxt
; // and delete
51 // coverity[deref_arg] - GetNext() is not a use after free at this point
54 bool SwUnoCursor::IsReadOnlyAvailable() const
60 SwUnoCursor::DoSetBidiLevelLeftRight( bool &, bool, bool )
62 return nullptr; // not for uno cursor
65 void SwUnoCursor::DoSetBidiLevelUpDown()
70 bool SwUnoCursor::IsSelOvr( SwCursorSelOverFlags eFlags
)
72 if (m_bRemainInSection
)
74 SwDoc
& rDoc
= GetDoc();
75 SwNodeIndex
aOldIdx( *rDoc
.GetNodes()[ GetSavePos()->nNode
] );
76 SwPosition
& rPtPos
= *GetPoint();
77 SwStartNode
*pOldSttNd
= aOldIdx
.GetNode().StartOfSectionNode(),
78 *pNewSttNd
= rPtPos
.GetNode().StartOfSectionNode();
79 if( pOldSttNd
!= pNewSttNd
)
81 bool bMoveDown
= GetSavePos()->nNode
< rPtPos
.GetNodeIndex();
82 bool bValidPos
= false;
84 // search the correct surrounded start node - which the index
86 while( pOldSttNd
->IsSectionNode() )
87 pOldSttNd
= pOldSttNd
->StartOfSectionNode();
89 // is the new index inside this surrounded section?
90 if( rPtPos
.GetNode() > *pOldSttNd
&&
91 rPtPos
.GetNode() < *pOldSttNd
->EndOfSectionNode() )
93 // check if it a valid move inside this section
94 // (only over SwSection's !)
95 const SwStartNode
* pInvalidNode
;
97 pInvalidNode
= nullptr;
98 pNewSttNd
= rPtPos
.GetNode().StartOfSectionNode();
100 const SwStartNode
*pSttNd
= pNewSttNd
, *pEndNd
= pOldSttNd
;
101 if( pSttNd
->EndOfSectionIndex() >
102 pEndNd
->EndOfSectionIndex() )
108 while( pSttNd
->GetIndex() > pEndNd
->GetIndex() )
110 if( !pSttNd
->IsSectionNode() )
111 pInvalidNode
= pSttNd
;
112 pSttNd
= pSttNd
->StartOfSectionNode();
118 rPtPos
.Assign( *pInvalidNode
->EndOfSectionNode(), 1 );
120 if( !rPtPos
.GetNode().IsContentNode() &&
121 ( !rDoc
.GetNodes().GoNextSection( &rPtPos
) ||
122 rPtPos
.GetNode() > *pOldSttNd
->EndOfSectionNode() ) )
127 rPtPos
.Assign( *pInvalidNode
, -1 );
129 if( !rPtPos
.GetNode().IsContentNode() &&
130 ( !SwNodes::GoPrevSection( &rPtPos
) ||
131 rPtPos
.GetNode() < *pOldSttNd
) )
137 } while ( pInvalidNode
);
142 SwContentNode
* pCNd
= GetPointContentNode();
143 GetPoint()->SetContent( (pCNd
&& !bMoveDown
) ? pCNd
->Len() : 0);
147 rPtPos
.Assign( GetSavePos()->nNode
);
148 GetPoint()->SetContent( GetSavePos()->nContent
);
153 return SwCursor::IsSelOvr( eFlags
);
156 SwUnoTableCursor::SwUnoTableCursor(const SwPosition
& rPos
)
157 : SwCursor(rPos
, nullptr)
159 , SwTableCursor(rPos
)
160 , m_aTableSel(rPos
, nullptr)
162 SetRemainInSection(false);
165 SwUnoTableCursor::~SwUnoTableCursor()
167 while (m_aTableSel
.GetNext() != &m_aTableSel
)
168 delete m_aTableSel
.GetNext();
171 bool SwUnoTableCursor::IsSelOvr( SwCursorSelOverFlags eFlags
)
173 bool bRet
= SwUnoCursor::IsSelOvr( eFlags
);
176 const SwTableNode
* pTNd
= GetPoint()->GetNode().FindTableNode();
177 bRet
= !(pTNd
== GetDoc().GetNodes()[ GetSavePos()->nNode
]->
178 FindTableNode() && (!HasMark() ||
179 pTNd
== GetMark()->GetNode().FindTableNode() ));
184 void SwUnoTableCursor::MakeBoxSels()
186 const SwContentNode
* pCNd
;
187 bool bMakeTableCursors
= true;
188 if( GetPoint()->GetNodeIndex() && GetMark()->GetNodeIndex() &&
189 nullptr != ( pCNd
= GetPointContentNode() ) && pCNd
->getLayoutFrame( pCNd
->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) &&
190 nullptr != ( pCNd
= GetMarkContentNode() ) && pCNd
->getLayoutFrame( pCNd
->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) )
191 bMakeTableCursors
= GetDoc().getIDocumentLayoutAccess().GetCurrentLayout()->MakeTableCursors( *this );
193 if ( !bMakeTableCursors
)
195 SwSelBoxes
const& rTmpBoxes
= GetSelectedBoxes();
196 while (!rTmpBoxes
.empty())
204 SwTableCursor::MakeBoxSels( &m_aTableSel
);
205 if (!GetSelectedBoxesCount())
207 const SwTableBox
* pBox
;
208 const SwNode
* pBoxNd
= GetPoint()->GetNode().FindTableBoxStartNode();
209 const SwTableNode
* pTableNd
= pBoxNd
? pBoxNd
->FindTableNode() : nullptr;
210 if( pTableNd
&& nullptr != ( pBox
= pTableNd
->GetTable().GetTableBox( pBoxNd
->GetIndex() )) )
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */