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 <docary.hxx>
25 #include <rootfrm.hxx>
26 
28 
30  : SwCursor( rPos, nullptr )
31  , m_bRemainInSection(true)
32  , m_bSkipOverHiddenSections(false)
33  , m_bSkipOverProtectSections(false)
34 {}
35 
37 {
38  SwDoc* pDoc = GetDoc();
39  if( !pDoc->IsInDtor() )
40  {
41  assert(!m_aNotifier.HasListeners());
42  }
43 
44  // delete the whole ring
45  while( GetNext() != this )
46  {
47  Ring* pNxt = GetNextInRing();
48  pNxt->MoveTo(nullptr); // remove from chain
49  delete pNxt; // and delete
50  }
51 }
52 
54 {
55  return true;
56 }
57 
58 const SwContentFrame*
60 {
61  return nullptr; // not for uno cursor
62 }
63 
65 {
66  // not for uno cursor
67 }
68 
70 {
72  {
73  SwDoc* pDoc = GetDoc();
74  SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
75  SwNodeIndex& rPtIdx = GetPoint()->nNode;
76  SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
77  *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
78  if( pOldSttNd != pNewSttNd )
79  {
80  bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
81  bool bValidPos = false;
82 
83  // search the correct surrounded start node - which the index
84  // can't leave.
85  while( pOldSttNd->IsSectionNode() )
86  pOldSttNd = pOldSttNd->StartOfSectionNode();
87 
88  // is the new index inside this surrounded section?
89  if( rPtIdx > *pOldSttNd &&
90  rPtIdx < pOldSttNd->EndOfSectionIndex() )
91  {
92  // check if it a valid move inside this section
93  // (only over SwSection's !)
94  const SwStartNode* pInvalidNode;
95  do {
96  pInvalidNode = nullptr;
97  pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
98 
99  const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
100  if( pSttNd->EndOfSectionIndex() >
101  pEndNd->EndOfSectionIndex() )
102  {
103  pEndNd = pNewSttNd;
104  pSttNd = pOldSttNd;
105  }
106 
107  while( pSttNd->GetIndex() > pEndNd->GetIndex() )
108  {
109  if( !pSttNd->IsSectionNode() )
110  pInvalidNode = pSttNd;
111  pSttNd = pSttNd->StartOfSectionNode();
112  }
113  if( pInvalidNode )
114  {
115  if( bMoveDown )
116  {
117  rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
118 
119  if( !rPtIdx.GetNode().IsContentNode() &&
120  ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
121  rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
122  break;
123  }
124  else
125  {
126  rPtIdx.Assign( *pInvalidNode, -1 );
127 
128  if( !rPtIdx.GetNode().IsContentNode() &&
129  ( !SwNodes::GoPrevSection( &rPtIdx ) ||
130  rPtIdx < *pOldSttNd ) )
131  break;
132  }
133  }
134  else
135  bValidPos = true;
136  } while ( pInvalidNode );
137  }
138 
139  if( bValidPos )
140  {
141  SwContentNode* pCNd = GetContentNode();
142  GetPoint()->nContent.Assign( pCNd, (pCNd && !bMoveDown) ? pCNd->Len() : 0);
143  }
144  else
145  {
146  rPtIdx = GetSavePos()->nNode;
147  GetPoint()->nContent.Assign( GetContentNode(), GetSavePos()->nContent );
148  return true;
149  }
150  }
151  }
152  return SwCursor::IsSelOvr( eFlags );
153 }
154 
156  : SwCursor(rPos, nullptr)
157  , SwUnoCursor(rPos)
158  , SwTableCursor(rPos)
159  , m_aTableSel(rPos, nullptr)
160 {
161  SetRemainInSection(false);
162 }
163 
165 {
166  while (m_aTableSel.GetNext() != &m_aTableSel)
167  delete m_aTableSel.GetNext();
168 }
169 
171 {
172  bool bRet = SwUnoCursor::IsSelOvr( eFlags );
173  if( !bRet )
174  {
175  const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
176  bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
177  FindTableNode() && (!HasMark() ||
178  pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
179  }
180  return bRet;
181 }
182 
184 {
185  const SwContentNode* pCNd;
186  bool bMakeTableCursors = true;
187  if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
188  nullptr != ( pCNd = GetContentNode() ) && pCNd->getLayoutFrame( pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
189  nullptr != ( pCNd = GetContentNode(false) ) && pCNd->getLayoutFrame( pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) )
190  bMakeTableCursors = GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout()->MakeTableCursors( *this );
191 
192  if ( !bMakeTableCursors )
193  {
194  SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
195  while (!rTmpBoxes.empty())
196  {
197  DeleteBox(0);
198  }
199  }
200 
201  if( IsChgd() )
202  {
204  if (!GetSelectedBoxesCount())
205  {
206  const SwTableBox* pBox;
207  const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
208  const SwTableNode* pTableNd = pBoxNd ? pBoxNd->FindTableNode() : nullptr;
209  if( pTableNd && nullptr != ( pBox = pTableNd->GetTable().GetTableBox( pBoxNd->GetIndex() )) )
210  InsertBox( *pBox );
211  }
212  }
213 }
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
Starts a section of nodes in the document model.
Definition: node.hxx:303
virtual sal_Int32 Len() const
Definition: node.cxx:1183
bool HasListeners() const
sal_uLong GetIndex() const
Definition: node.hxx:282
void InsertBox(const SwTableBox &rTableBox)
Definition: swcrsr.cxx:2415
SwCursorSelOverFlags
Definition: swcrsr.hxx:47
SwUnoTableCursor(const SwPosition &rPos)
Definition: unocrsr.cxx:155
const SwSelBoxes & GetSelectedBoxes() const
Definition: swcrsr.hxx:278
virtual ~SwUnoCursor() override
Definition: unocrsr.cxx:36
Marks a position in the document model.
Definition: pam.hxx:35
bool IsSectionNode() const
Definition: node.hxx:644
const SwTableBox * GetTableBox(const OUString &rName, const bool bPerformValidCheck=false) const
Definition: swtable.cxx:1344
virtual const SwRootFrame * GetCurrentLayout() const =0
SwNodeIndex nNode
Definition: pam.hxx:37
const SwPosition * GetMark() const
Definition: pam.hxx:209
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1150
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos)
Definition: swcrsr.cxx:216
Definition: doc.hxx:185
static SwContentNode * GoPrevSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true)
Definition: nodes.cxx:1975
SwNode & GetNode() const
Definition: ndindex.hxx:118
SwCursor * MakeBoxSels(SwCursor *pCurrentCursor)
Definition: swcrsr.cxx:2316
SwCursor m_aTableSel
Definition: unocrsr.hxx:83
virtual bool IsReadOnlyAvailable() const override
Definition: unocrsr.cxx:53
void MakeBoxSels()
Definition: unocrsr.cxx:183
SfxBroadcaster m_aNotifier
Definition: unocrsr.hxx:43
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
void SetRemainInSection(bool bFlag)
Definition: unocrsr.hxx:65
SwUnoCursor(const SwPosition &rPos)
Definition: unocrsr.cxx:29
SwIndex nContent
Definition: pam.hxx:38
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
const SwTable & GetTable() const
Definition: node.hxx:497
virtual ~SwUnoTableCursor() override
Definition: unocrsr.cxx:164
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos) override
Definition: unocrsr.cxx:170
SwCursor * GetNext()
Definition: swcrsr.hxx:217
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
virtual ~UnoCursorHint() override
Definition: unocrsr.cxx:27
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
bool IsChgd() const
Definition: swcrsr.hxx:296
SwPaM * GetNextInRing()
Definition: ring.hxx:84
SwDoc * GetDoc()
Definition: node.hxx:702
SwDoc * GetDoc() const
Definition: pam.hxx:243
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos) override
Definition: unocrsr.cxx:69
sal_uLong nNode
Definition: swcrsr.hxx:242
virtual const SwContentFrame * DoSetBidiLevelLeftRight(bool &io_rbLeft, bool bVisualAllowed, bool bInsertCursor) override
Definition: unocrsr.cxx:59
Marks a node in the document model.
Definition: ndindex.hxx:31
bool empty() const
bool MakeTableCursors(SwTableCursor &)
Calculates the cells included from the current selection.
Definition: trvlfrm.cxx:1859
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
virtual void DoSetBidiLevelUpDown() override
Definition: unocrsr.cxx:64
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwNodes & GetNodes()
Definition: doc.hxx:403
size_t GetSelectedBoxesCount() const
Definition: swcrsr.hxx:277
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
const SwStartNode * FindTableBoxStartNode() const
Definition: node.hxx:196
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:351
Ring()
Creates a new item in a ring container all by itself.
Definition: ring.hxx:73
bool IsInDtor() const
Definition: doc.hxx:398
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:1923
void DeleteBox(size_t nPos)
Definition: swcrsr.cxx:2422
bool m_bRemainInSection
Definition: unocrsr.hxx:38
Base class of the Writer document model elements.
Definition: node.hxx:79
const SwCursor_SavePos * GetSavePos() const
Definition: swcrsr.hxx:85