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* pDoc = GetDoc();
38  if( !pDoc->IsInDtor() )
39  {
40  assert(!m_aNotifier.HasListeners());
41  }
42 
43  // delete the whole ring
44  while( GetNext() != this )
45  {
46  Ring* pNxt = GetNextInRing();
47  pNxt->MoveTo(nullptr); // remove from chain
48  delete pNxt; // and delete
49  }
50 }
51 
53 {
54  return true;
55 }
56 
57 const SwContentFrame*
59 {
60  return nullptr; // not for uno cursor
61 }
62 
64 {
65  // not for uno cursor
66 }
67 
69 {
71  {
72  SwDoc* pDoc = GetDoc();
73  SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
74  SwNodeIndex& rPtIdx = GetPoint()->nNode;
75  SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
76  *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
77  if( pOldSttNd != pNewSttNd )
78  {
79  bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
80  bool bValidPos = false;
81 
82  // search the correct surrounded start node - which the index
83  // can't leave.
84  while( pOldSttNd->IsSectionNode() )
85  pOldSttNd = pOldSttNd->StartOfSectionNode();
86 
87  // is the new index inside this surrounded section?
88  if( rPtIdx > *pOldSttNd &&
89  rPtIdx < pOldSttNd->EndOfSectionIndex() )
90  {
91  // check if it a valid move inside this section
92  // (only over SwSection's !)
93  const SwStartNode* pInvalidNode;
94  do {
95  pInvalidNode = nullptr;
96  pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
97 
98  const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
99  if( pSttNd->EndOfSectionIndex() >
100  pEndNd->EndOfSectionIndex() )
101  {
102  pEndNd = pNewSttNd;
103  pSttNd = pOldSttNd;
104  }
105 
106  while( pSttNd->GetIndex() > pEndNd->GetIndex() )
107  {
108  if( !pSttNd->IsSectionNode() )
109  pInvalidNode = pSttNd;
110  pSttNd = pSttNd->StartOfSectionNode();
111  }
112  if( pInvalidNode )
113  {
114  if( bMoveDown )
115  {
116  rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
117 
118  if( !rPtIdx.GetNode().IsContentNode() &&
119  ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
120  rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
121  break;
122  }
123  else
124  {
125  rPtIdx.Assign( *pInvalidNode, -1 );
126 
127  if( !rPtIdx.GetNode().IsContentNode() &&
128  ( !SwNodes::GoPrevSection( &rPtIdx ) ||
129  rPtIdx < *pOldSttNd ) )
130  break;
131  }
132  }
133  else
134  bValidPos = true;
135  } while ( pInvalidNode );
136  }
137 
138  if( bValidPos )
139  {
140  SwContentNode* pCNd = GetContentNode();
141  GetPoint()->nContent.Assign( pCNd, (pCNd && !bMoveDown) ? pCNd->Len() : 0);
142  }
143  else
144  {
145  rPtIdx = GetSavePos()->nNode;
146  GetPoint()->nContent.Assign( GetContentNode(), GetSavePos()->nContent );
147  return true;
148  }
149  }
150  }
151  return SwCursor::IsSelOvr( eFlags );
152 }
153 
155  : SwCursor(rPos, nullptr)
156  , SwUnoCursor(rPos)
157  , SwTableCursor(rPos)
158  , m_aTableSel(rPos, nullptr)
159 {
160  SetRemainInSection(false);
161 }
162 
164 {
165  while (m_aTableSel.GetNext() != &m_aTableSel)
166  delete m_aTableSel.GetNext();
167 }
168 
170 {
171  bool bRet = SwUnoCursor::IsSelOvr( eFlags );
172  if( !bRet )
173  {
174  const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
175  bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
176  FindTableNode() && (!HasMark() ||
177  pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
178  }
179  return bRet;
180 }
181 
183 {
184  const SwContentNode* pCNd;
185  bool bMakeTableCursors = true;
186  if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
187  nullptr != ( pCNd = GetContentNode() ) && pCNd->getLayoutFrame( pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
188  nullptr != ( pCNd = GetContentNode(false) ) && pCNd->getLayoutFrame( pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) )
189  bMakeTableCursors = GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout()->MakeTableCursors( *this );
190 
191  if ( !bMakeTableCursors )
192  {
193  SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
194  while (!rTmpBoxes.empty())
195  {
196  DeleteBox(0);
197  }
198  }
199 
200  if( IsChgd() )
201  {
203  if (!GetSelectedBoxesCount())
204  {
205  const SwTableBox* pBox;
206  const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
207  const SwTableNode* pTableNd = pBoxNd ? pBoxNd->FindTableNode() : nullptr;
208  if( pTableNd && nullptr != ( pBox = pTableNd->GetTable().GetTableBox( pBoxNd->GetIndex() )) )
209  InsertBox( *pBox );
210  }
211  }
212 }
213 
214 /* 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:1181
bool HasListeners() const
sal_uLong GetIndex() const
Definition: node.hxx:282
void InsertBox(const SwTableBox &rTableBox)
Definition: swcrsr.cxx:2431
SwCursorSelOverFlags
Definition: swcrsr.hxx:47
SwUnoTableCursor(const SwPosition &rPos)
Definition: unocrsr.cxx:154
const SwSelBoxes & GetSelectedBoxes() const
Definition: swcrsr.hxx:278
virtual ~SwUnoCursor() override
Definition: unocrsr.cxx:35
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:1343
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:1148
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos)
Definition: swcrsr.cxx:220
Definition: doc.hxx:186
static SwContentNode * GoPrevSection(SwNodeIndex *, bool bSkipHidden=true, bool bSkipProtect=true)
Definition: nodes.cxx:1952
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwCursor * MakeBoxSels(SwCursor *pCurrentCursor)
Definition: swcrsr.cxx:2332
SwCursor m_aTableSel
Definition: unocrsr.hxx:83
virtual bool IsReadOnlyAvailable() const override
Definition: unocrsr.cxx:52
void MakeBoxSels()
Definition: unocrsr.cxx:182
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:28
SwIndex nContent
Definition: pam.hxx:38
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
const SwTable & GetTable() const
Definition: node.hxx:497
virtual ~SwUnoTableCursor() override
Definition: unocrsr.cxx:163
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos) override
Definition: unocrsr.cxx:169
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:26
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:68
sal_uLong nNode
Definition: swcrsr.hxx:242
virtual const SwContentFrame * DoSetBidiLevelLeftRight(bool &io_rbLeft, bool bVisualAllowed, bool bInsertCursor) override
Definition: unocrsr.cxx:58
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:1857
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
virtual void DoSetBidiLevelUpDown() override
Definition: unocrsr.cxx:63
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwNodes & GetNodes()
Definition: doc.hxx:405
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:350
Ring()
Creates a new item in a ring container all by itself.
Definition: ring.hxx:73
bool IsInDtor() const
Definition: doc.hxx:400
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:1900
void DeleteBox(size_t nPos)
Definition: swcrsr.cxx:2438
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