LibreOffice Module sw (master) 1
unocrsr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <unocrsr.hxx>
21#include <doc.hxx>
23#include <swtable.hxx>
24#include <rootfrm.hxx>
25
27
29 : SwCursor( rPos, nullptr )
30 , m_bRemainInSection(true)
31 , m_bSkipOverHiddenSections(false)
32 , m_bSkipOverProtectSections(false)
33{}
34
36{
37 SwDoc& rDoc = GetDoc();
38 if( !rDoc.IsInDtor() )
39 {
40 assert(!m_aNotifier.HasListeners());
41 }
42
43 // delete the whole ring
44 while( GetNext() != this )
45 {
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
50 }
51 // coverity[deref_arg] - GetNext() is not a use after free at this point
52}
53
55{
56 return true;
57}
58
59const SwContentFrame*
61{
62 return nullptr; // not for uno cursor
63}
64
66{
67 // not for uno cursor
68}
69
71{
73 {
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 )
80 {
81 bool bMoveDown = GetSavePos()->nNode < rPtPos.GetNodeIndex();
82 bool bValidPos = false;
83
84 // search the correct surrounded start node - which the index
85 // can't leave.
86 while( pOldSttNd->IsSectionNode() )
87 pOldSttNd = pOldSttNd->StartOfSectionNode();
88
89 // is the new index inside this surrounded section?
90 if( rPtPos.GetNode() > *pOldSttNd &&
91 rPtPos.GetNode() < *pOldSttNd->EndOfSectionNode() )
92 {
93 // check if it a valid move inside this section
94 // (only over SwSection's !)
95 const SwStartNode* pInvalidNode;
96 do {
97 pInvalidNode = nullptr;
98 pNewSttNd = rPtPos.GetNode().StartOfSectionNode();
99
100 const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
101 if( pSttNd->EndOfSectionIndex() >
102 pEndNd->EndOfSectionIndex() )
103 {
104 pEndNd = pNewSttNd;
105 pSttNd = pOldSttNd;
106 }
107
108 while( pSttNd->GetIndex() > pEndNd->GetIndex() )
109 {
110 if( !pSttNd->IsSectionNode() )
111 pInvalidNode = pSttNd;
112 pSttNd = pSttNd->StartOfSectionNode();
113 }
114 if( pInvalidNode )
115 {
116 if( bMoveDown )
117 {
118 rPtPos.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
119
120 if( !rPtPos.GetNode().IsContentNode() &&
121 ( !rDoc.GetNodes().GoNextSection( &rPtPos ) ||
122 rPtPos.GetNode() > *pOldSttNd->EndOfSectionNode() ) )
123 break;
124 }
125 else
126 {
127 rPtPos.Assign( *pInvalidNode, -1 );
128
129 if( !rPtPos.GetNode().IsContentNode() &&
130 ( !SwNodes::GoPrevSection( &rPtPos ) ||
131 rPtPos.GetNode() < *pOldSttNd ) )
132 break;
133 }
134 }
135 else
136 bValidPos = true;
137 } while ( pInvalidNode );
138 }
139
140 if( bValidPos )
141 {
143 GetPoint()->SetContent( (pCNd && !bMoveDown) ? pCNd->Len() : 0);
144 }
145 else
146 {
147 rPtPos.Assign( GetSavePos()->nNode );
148 GetPoint()->SetContent( GetSavePos()->nContent );
149 return true;
150 }
151 }
152 }
153 return SwCursor::IsSelOvr( eFlags );
154}
155
157 : SwCursor(rPos, nullptr)
158 , SwUnoCursor(rPos)
159 , SwTableCursor(rPos)
160 , m_aTableSel(rPos, nullptr)
161{
162 SetRemainInSection(false);
163}
164
166{
167 while (m_aTableSel.GetNext() != &m_aTableSel)
168 delete m_aTableSel.GetNext();
169}
170
172{
173 bool bRet = SwUnoCursor::IsSelOvr( eFlags );
174 if( !bRet )
175 {
176 const SwTableNode* pTNd = GetPoint()->GetNode().FindTableNode();
177 bRet = !(pTNd == GetDoc().GetNodes()[ GetSavePos()->nNode ]->
178 FindTableNode() && (!HasMark() ||
179 pTNd == GetMark()->GetNode().FindTableNode() ));
180 }
181 return bRet;
182}
183
185{
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 );
192
193 if ( !bMakeTableCursors )
194 {
195 SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
196 while (!rTmpBoxes.empty())
197 {
198 DeleteBox(0);
199 }
200 }
201
202 if( IsChgd() )
203 {
206 {
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() )) )
211 InsertBox( *pBox );
212 }
213 }
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SwRootFrame * GetCurrentLayout() const =0
bool HasListeners() const
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:58
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1230
virtual sal_Int32 Len() const
Definition: node.cxx:1263
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos)
Definition: swcrsr.cxx:222
SwCursor * GetNext()
Definition: swcrsr.hxx:219
const SwCursor_SavePos * GetSavePos() const
Definition: swcrsr.hxx:313
Definition: doc.hxx:194
bool IsInDtor() const
Definition: doc.hxx:412
SwNodes & GetNodes()
Definition: doc.hxx:417
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:411
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:136
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodeOffset GetIndex() const
Definition: node.hxx:312
const SwStartNode * FindTableBoxStartNode() const
Definition: node.hxx:218
bool IsContentNode() const
Definition: node.hxx:677
SwDoc & GetDoc()
Definition: node.hxx:233
bool IsSectionNode() const
Definition: node.hxx:693
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:726
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:731
SwContentNode * GoNextSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true) const
Go to next content-node that is not protected or hidden (Both set FALSE ==> GoNext/GoPrevious!...
Definition: nodes.cxx:1943
static SwContentNode * GoPrevSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true)
Definition: nodes.cxx:2059
const SwPosition * GetMark() const
Definition: pam.hxx:263
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:287
SwContentNode * GetMarkContentNode() const
Definition: pam.hxx:288
SwDoc & GetDoc() const
Definition: pam.hxx:299
const SwPosition * GetPoint() const
Definition: pam.hxx:261
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:259
bool MakeTableCursors(SwTableCursor &)
Calculates the cells included from the current selection.
Definition: trvlfrm.cxx:1871
Starts a section of nodes in the document model.
Definition: node.hxx:348
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:426
void DeleteBox(size_t nPos)
Definition: swcrsr.cxx:2512
SwCursor * MakeBoxSels(SwCursor *pCurrentCursor)
Definition: swcrsr.cxx:2403
bool IsChgd() const
Definition: swcrsr.hxx:298
const SwSelBoxes & GetSelectedBoxes() const
Definition: swcrsr.hxx:280
size_t GetSelectedBoxesCount() const
Definition: swcrsr.hxx:279
void InsertBox(const SwTableBox &rTableBox)
Definition: swcrsr.cxx:2505
const SwTable & GetTable() const
Definition: node.hxx:542
const SwTableBox * GetTableBox(const OUString &rName, const bool bPerformValidCheck=false) const
Definition: swtable.cxx:1340
virtual bool IsReadOnlyAvailable() const override
Definition: unocrsr.cxx:54
virtual const SwContentFrame * DoSetBidiLevelLeftRight(bool &io_rbLeft, bool bVisualAllowed, bool bInsertCursor) override
Definition: unocrsr.cxx:60
void SetRemainInSection(bool bFlag)
Definition: unocrsr.hxx:66
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos) override
Definition: unocrsr.cxx:70
virtual ~SwUnoCursor() override
Definition: unocrsr.cxx:35
virtual void DoSetBidiLevelUpDown() override
Definition: unocrsr.cxx:65
SfxBroadcaster m_aNotifier
Definition: unocrsr.hxx:44
bool m_bRemainInSection
Definition: unocrsr.hxx:39
SwUnoCursor(const SwPosition &rPos)
Definition: unocrsr.cxx:28
SwCursor m_aTableSel
Definition: unocrsr.hxx:84
SwUnoTableCursor(const SwPosition &rPos)
Definition: unocrsr.cxx:156
void MakeBoxSels()
Definition: unocrsr.cxx:184
virtual ~SwUnoTableCursor() override
Definition: unocrsr.cxx:165
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos) override
Definition: unocrsr.cxx:171
bool empty() const
Ring()
Creates a new item in a ring container all by itself.
Definition: ring.hxx:73
SwPaM * GetNextInRing()
Definition: ring.hxx:84
SwNodeOffset nNode
Definition: swcrsr.hxx:244
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:266
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:77
virtual ~UnoCursorHint() override
Definition: unocrsr.cxx:26
SwCursorSelOverFlags
Definition: swcrsr.hxx:50