LibreOffice Module sw (master)  1
trvlfnfl.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 <crsrsh.hxx>
21 #include <doc.hxx>
22 #include <pagefrm.hxx>
23 #include <cntfrm.hxx>
24 #include <ftnfrm.hxx>
25 #include <swcrsr.hxx>
26 #include <ndtxt.hxx>
27 #include <txtfrm.hxx>
28 #include <txtftn.hxx>
29 #include <ftnidx.hxx>
30 #include <viscrs.hxx>
31 #include "callnk.hxx"
32 #include <svx/srchdlg.hxx>
33 
34 bool SwCursorShell::CallCursorShellFN( FNCursorShell fnCursor )
35 {
36  SwCallLink aLk( *this ); // watch Cursor-Moves
37  bool bRet = (this->*fnCursor)();
38  if( bRet )
41  return bRet;
42 }
43 
44 bool SwCursorShell::CallCursorFN( FNCursor fnCursor )
45 {
46  SwCallLink aLk( *this ); // watch Cursor-Moves
47  SwCursor* pCursor = getShellCursor( true );
48  bool bRet = (pCursor->*fnCursor)();
49  if( bRet )
52  return bRet;
53 }
54 
56 {
57  // jump from content to footnote
58  bool bRet = false;
59  SwTextNode* pTextNd = GetPoint()->nNode.GetNode().GetTextNode();
60 
61  SwTextAttr *const pFootnote( pTextNd
62  ? pTextNd->GetTextAttrForCharAt(
63  GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN)
64  : nullptr);
65  if (pFootnote)
66  {
67  SwCursorSaveState aSaveState( *this );
68  GetPoint()->nNode = *static_cast<SwTextFootnote*>(pFootnote)->GetStartNode();
69 
71  &GetPoint()->nNode,
72  true, !IsReadOnlyAvailable() );
73  if( pCNd )
74  {
75  GetPoint()->nContent.Assign( pCNd, 0 );
78  }
79  }
80  return bRet;
81 }
82 
84 {
86  if( !bRet )
87  {
88  SwTextNode* pTextNd = GetCursor_() ?
89  GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode() : nullptr;
90  if( pTextNd )
91  {
92  std::pair<Point, bool> const tmp(GetCursor_()->GetSttPos(), true);
93  const SwFrame *pFrame = pTextNd->getLayoutFrame( GetLayout(),
94  GetCursor_()->Start(), &tmp);
95  const SwFootnoteBossFrame* pFootnoteBoss;
96  bool bSkip = pFrame && pFrame->IsInFootnote();
97  while( pFrame && nullptr != ( pFootnoteBoss = pFrame->FindFootnoteBossFrame() ) )
98  {
99  if( nullptr != ( pFrame = pFootnoteBoss->FindFootnoteCont() ) )
100  {
101  if( bSkip )
102  bSkip = false;
103  else
104  {
105  const SwContentFrame* pCnt = static_cast<const SwLayoutFrame*>
106  (pFrame)->ContainsContent();
107  if( pCnt )
108  {
109  SwTextFrame const*const pTF(
110  static_cast<const SwTextFrame*>(pCnt));
111  *GetCursor_()->GetPoint() =
112  pTF->MapViewToModelPos(pTF->GetOfst());
115  bRet = true;
116  break;
117  }
118  }
119  }
120  if( pFootnoteBoss->GetNext() && !pFootnoteBoss->IsPageFrame() )
121  pFrame = pFootnoteBoss->GetNext();
122  else
123  pFrame = pFootnoteBoss->GetUpper();
124  }
125  }
126  }
127  return bRet;
128 }
129 
131 {
132  // jump from footnote to anchor
133  const SwNode* pSttNd = GetNode().FindFootnoteStartNode();
134  if( pSttNd )
135  {
136  // search in all footnotes in document for this StartIndex
137  const SwTextFootnote* pTextFootnote;
138  const SwFootnoteIdxs& rFootnoteArr = pSttNd->GetDoc()->GetFootnoteIdxs();
139  for( size_t n = 0; n < rFootnoteArr.size(); ++n )
140  if( nullptr != ( pTextFootnote = rFootnoteArr[ n ])->GetStartNode() &&
141  pSttNd == &pTextFootnote->GetStartNode()->GetNode() )
142  {
143  SwCursorSaveState aSaveState( *this );
144 
145  SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
146  GetPoint()->nNode = rTNd;
147  GetPoint()->nContent.Assign( &rTNd, pTextFootnote->GetStart() );
148 
151  }
152  }
153  return false;
154 }
155 
157 {
158  // jump from footnote to anchor
159  SwCallLink aLk( *this ); // watch Cursor-Moves
160  bool bRet = m_pCurrentCursor->GotoFootnoteAnchor();
161  if( bRet )
162  {
163  // special treatment for table header row
167  }
168  return bRet;
169 }
170 
171 static bool CmpLE( const SwTextFootnote& rFootnote, sal_uLong nNd, sal_Int32 nCnt )
172 {
173  const sal_uLong nTNd = rFootnote.GetTextNode().GetIndex();
174  return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() <= nCnt );
175 }
176 
177 static bool CmpL( const SwTextFootnote& rFootnote, sal_uLong nNd, sal_Int32 nCnt )
178 {
179  const sal_uLong nTNd = rFootnote.GetTextNode().GetIndex();
180  return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() < nCnt );
181 }
182 
184 {
185  const SwFootnoteIdxs& rFootnoteArr = GetDoc()->GetFootnoteIdxs();
186  const SwTextFootnote* pTextFootnote = nullptr;
187  size_t nPos = 0;
188 
189  if( rFootnoteArr.empty() )
190  {
191  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
192  return false;
193  }
194 
195  if( rFootnoteArr.SeekEntry( GetPoint()->nNode, &nPos ))
196  {
197  // there is a footnote with this index, so search also for the next one
198  if( nPos < rFootnoteArr.size() )
199  {
200  sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
201  const sal_Int32 nCntPos = GetPoint()->nContent.GetIndex();
202 
203  pTextFootnote = rFootnoteArr[ nPos ];
204  // search forwards
205  if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
206  {
207  pTextFootnote = nullptr;
208  for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
209  {
210  pTextFootnote = rFootnoteArr[ nPos ];
211  if( !CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
212  break; // found
213  pTextFootnote = nullptr;
214  }
215  }
216  else if( nPos )
217  {
218  // search backwards
219  pTextFootnote = nullptr;
220  while( nPos )
221  {
222  pTextFootnote = rFootnoteArr[ --nPos ];
223  if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
224  {
225  pTextFootnote = rFootnoteArr[ ++nPos ];
226  break; // found
227  }
228  }
229  }
230  }
231  }
232  else if( nPos < rFootnoteArr.size() )
233  pTextFootnote = rFootnoteArr[ nPos ];
234 
235  if (pTextFootnote == nullptr)
236  {
237  pTextFootnote = rFootnoteArr[ 0 ];
238  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
239  }
240  else
241  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
242 
243  bool bRet = nullptr != pTextFootnote;
244  if( bRet )
245  {
246  SwCursorSaveState aSaveState( *this );
247 
248  SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
249  GetPoint()->nNode = rTNd;
250  GetPoint()->nContent.Assign( &rTNd, pTextFootnote->GetStart() );
251  bRet = !IsSelOvr();
252  }
253  return bRet;
254 }
255 
257 {
258  const SwFootnoteIdxs& rFootnoteArr = GetDoc()->GetFootnoteIdxs();
259  const SwTextFootnote* pTextFootnote = nullptr;
260  size_t nPos = 0;
261 
262  if( rFootnoteArr.empty() )
263  {
264  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
265  return false;
266  }
267 
268  if( rFootnoteArr.SeekEntry( GetPoint()->nNode, &nPos ) )
269  {
270  // there is a footnote with this index, so search also for the next one
271  sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
272  const sal_Int32 nCntPos = GetPoint()->nContent.GetIndex();
273 
274  pTextFootnote = rFootnoteArr[ nPos ];
275  // search forwards
276  if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
277  {
278  for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
279  {
280  pTextFootnote = rFootnoteArr[ nPos ];
281  if( !CmpL( *pTextFootnote, nNdPos, nCntPos ) )
282  {
283  pTextFootnote = rFootnoteArr[ nPos-1 ];
284  break;
285  }
286  }
287  }
288  else if( nPos )
289  {
290  // search backwards
291  pTextFootnote = nullptr;
292  while( nPos )
293  {
294  pTextFootnote = rFootnoteArr[ --nPos ];
295  if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
296  break; // found
297  pTextFootnote = nullptr;
298  }
299  }
300  else
301  pTextFootnote = nullptr;
302  }
303  else if( nPos )
304  pTextFootnote = rFootnoteArr[ nPos-1 ];
305 
306  if( pTextFootnote == nullptr )
307  {
308  pTextFootnote = rFootnoteArr[ rFootnoteArr.size() - 1 ];
309  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
310  }
311  else
312  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
313 
314  bool bRet = nullptr != pTextFootnote;
315  if( bRet )
316  {
317  SwCursorSaveState aSaveState( *this );
318 
319  SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
320  GetPoint()->nNode = rTNd;
321  GetPoint()->nContent.Assign( &rTNd, pTextFootnote->GetStart() );
322  bRet = !IsSelOvr();
323  }
324  return bRet;
325 }
326 
328 {
330 }
331 
333 {
335 }
336 
339 {
340  SET_CURR_SHELL( this );
341  const SwFrame* pFrame = GetCurrFrame();
342  do {
343  pFrame = pFrame->GetUpper();
344  } while( pFrame && !pFrame->IsFlyFrame() );
345 
346  if( !pFrame ) // no FlyFrame
347  return;
348 
349  SwCallLink aLk( *this ); // watch Cursor-Moves
350  SwCursorSaveState aSaveState( *m_pCurrentCursor );
351 
352  // jump in BodyFrame closest to FlyFrame
353  SwRect aTmpRect( m_aCharRect );
354  if( !pFrame->getFrameArea().IsInside( aTmpRect ))
355  aTmpRect = pFrame->getFrameArea();
356  Point aPt( aTmpRect.Left(), aTmpRect.Top() +
357  ( aTmpRect.Bottom() - aTmpRect.Top() ) / 2 );
358  aPt.setX(aPt.getX() > (pFrame->getFrameArea().Left() + (pFrame->getFrameArea().SSize().Width() / 2 ))
359  ? pFrame->getFrameArea().Right()
360  : pFrame->getFrameArea().Left());
361 
362  const SwPageFrame* pPageFrame = pFrame->FindPageFrame();
363  const SwContentFrame* pFndFrame = pPageFrame->GetContentPos( aPt, false, true );
364  pFndFrame->GetCursorOfst( m_pCurrentCursor->GetPoint(), aPt );
365 
367  if( bRet )
370 }
371 
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
sal_uLong GetIndex() const
Definition: node.hxx:282
SAL_DLLPRIVATE void UpdateCursor(sal_uInt16 eFlags=SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE, bool bIdleEnd=false)
Definition: crsrsh.cxx:1551
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
SwShellCursor * m_pCurrentCursor
current cursor
Definition: crsrsh.hxx:179
bool IsInProtectTable(bool bMove=false, bool bChgCursor=true)
Definition: swcrsr.cxx:545
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:327
check overlapping PaMs
Definition: crsrsh.hxx:158
SwNodeIndex nNode
Definition: pam.hxx:37
bool IsInFootnote() const
Definition: frame.hxx:925
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:2999
sal_uIntPtr sal_uLong
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:216
TextFrameIndex GetOfst() const
Definition: txtfrm.hxx:426
SwNode & GetNode() const
Definition: ndindex.hxx:118
bool GotoFootnoteAnchor()
jump from footnote to anchor
Definition: trvlfnfl.cxx:156
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:183
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3059
bool IsFlyFrame() const
Definition: frame.hxx:1186
void Top(const long nTop)
Definition: swrect.hxx:202
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:175
void setX(long nX)
SwFootnoteContFrame * FindFootnoteCont()
Definition: ftnfrm.cxx:964
bool GotoFootnoteText()
jump from content to footnote
Definition: trvlfnfl.cxx:83
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
static bool CmpL(const SwTextFootnote &rFootnote, sal_uLong nNd, sal_Int32 nCnt)
Definition: trvlfnfl.cxx:177
void Right(const long nRight)
Definition: swrect.hxx:198
size_type size() const
SwShellCursor * GetCursor_()
Definition: crsrsh.hxx:331
long getX() const
static SwNodePtr GetStartNode(SwOutlineNodes const *pOutlNds, int nOutlineLevel, SwOutlineNodes::size_type *nOutl)
Definition: docglbl.cxx:90
SwTextFootnote * SeekEntry(const SwNodeIndex &rIdx, size_t *pPos=nullptr) const
Definition: ftnidx.cxx:409
A helper class to save cursor state (position).
Definition: swcrsr.hxx:230
const SwPosition * GetPoint() const
Definition: pam.hxx:207
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
#define RES_TXTATR_FTN
Definition: hintids.hxx:152
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
SwDoc * GetDoc()
Definition: node.hxx:702
bool GotoFootnoteText()
Definition: trvlfnfl.cxx:55
SwDoc * GetDoc() const
Definition: pam.hxx:243
SwLayoutFrame * GetUpper()
Definition: frame.hxx:656
SwFootnoteBossFrame * FindFootnoteBossFrame(bool bFootnotes=false)
Definition: findfrm.cxx:435
#define SET_CURR_SHELL(shell)
Definition: swtypes.hxx:101
bool empty() const
void SSize(const Size &rNew)
Definition: swrect.hxx:176
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:256
static bool CmpLE(const SwTextFootnote &rFootnote, sal_uLong nNd, sal_Int32 nCnt)
Definition: trvlfnfl.cxx:171
A page of the document layout.
Definition: pagefrm.hxx:40
virtual bool GetCursorOfst(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const
Definition: unusedf.cxx:46
static void SetSearchLabel(const SearchLabel &rSL)
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:332
virtual bool IsReadOnlyAvailable() const
Definition: swcrsr.cxx:144
void Left(const long nLeft)
Definition: swrect.hxx:193
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void Bottom(const long nBottom)
Definition: swrect.hxx:207
SwContentFrame * GetCurrFrame(const bool bCalcFrame=true) const
Get current frame in which the cursor is positioned.
Definition: crsrsh.cxx:2426
sal_Int32 GetIndex() const
Definition: index.hxx:95
bool IsInside(const Point &rPOINT) const
Definition: swrect.cxx:107
SwNodes & GetNodes()
Definition: doc.hxx:402
bool IsPageFrame() const
Definition: frame.hxx:1154
const Point & GetPtPos() const
Definition: viscrs.hxx:140
scroll window
Definition: crsrsh.hxx:157
SAL_DLLPRIVATE bool CallCursorShellFN(FNCursorShell)
Definition: trvlfnfl.cxx:34
SwNodeIndex * GetStartNode() const
Definition: txtftn.hxx:41
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:627
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
make visible in spite of Readonly
Definition: crsrsh.hxx:159
void GotoFlyAnchor()
jump from the frame to the anchor
Definition: trvlfnfl.cxx:338
bool GotoFootnoteAnchor()
Definition: trvlfnfl.cxx:130
SwRect m_aCharRect
Char-SRectangle on which the cursor is located.
Definition: crsrsh.hxx:168
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
sal_Int32 nPos
const SwContentFrame * GetContentPos(Point &rPoint, const bool bDontLeave, const bool bBodyOnly=false, SwCursorMoveState *pCMS=nullptr, const bool bDefaultExpand=true) const
Finds the closest Content for the SPoint Is used for Pages, Flys and Cells if GetCursorOfst failed...
Definition: trvlfrm.cxx:1180
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1245
SAL_DLLPRIVATE bool CallCursorFN(FNCursor)
Definition: trvlfnfl.cxx:44
const SwTextNode & GetTextNode() const
Definition: txtftn.hxx:69
const SwStartNode * FindFootnoteStartNode() const
Definition: node.hxx:200
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843
SwFrame * GetNext()
Definition: frame.hxx:654
Base class of the Writer document model elements.
Definition: node.hxx:79