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#include <wrtsh.hxx>
34
35bool SwCursorShell::CallCursorShellFN( FNCursorShell fnCursor )
36{
37 if (SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(this))
38 pWrtSh->addCurrentPosition();
39
40 SwCallLink aLk( *this ); // watch Cursor-Moves
41 bool bRet = (this->*fnCursor)();
42 if( bRet )
45 return bRet;
46}
47
48bool SwCursorShell::CallCursorFN( FNCursor fnCursor )
49{
50 if (SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(this))
51 pWrtSh->addCurrentPosition();
52
53 SwCallLink aLk( *this ); // watch Cursor-Moves
54 SwCursor* pCursor = getShellCursor( true );
55 bool bRet = (pCursor->*fnCursor)();
56 if( bRet )
59 return bRet;
60}
61
63{
64 // jump from content to footnote
65 bool bRet = false;
66 SwTextNode* pTextNd = GetPoint()->GetNode().GetTextNode();
67
68 SwTextAttr *const pFootnote( pTextNd
69 ? pTextNd->GetTextAttrForCharAt(
70 GetPoint()->GetContentIndex(), RES_TXTATR_FTN)
71 : nullptr);
72 if (pFootnote)
73 {
74 SwCursorSaveState aSaveState( *this );
75 GetPoint()->Assign( *static_cast<SwTextFootnote*>(pFootnote)->GetStartNode() );
76
78 GetPoint(),
79 true, !IsReadOnlyAvailable() );
80 if( pCNd )
81 {
84 }
85 }
86 return bRet;
87}
88
90{
92 if( !bRet )
93 {
94 SwTextNode* pTextNd = GetCursor_() ?
95 GetCursor_()->GetPoint()->GetNode().GetTextNode() : nullptr;
96 if( pTextNd )
97 {
98 std::pair<Point, bool> const tmp(GetCursor_()->GetSttPos(), true);
99 const SwFrame *pFrame = pTextNd->getLayoutFrame( GetLayout(),
100 GetCursor_()->Start(), &tmp);
101 const SwFootnoteBossFrame* pFootnoteBoss;
102 bool bSkip = pFrame && pFrame->IsInFootnote();
103 while( pFrame )
104 {
105 pFootnoteBoss = pFrame->FindFootnoteBossFrame();
106 if (!pFootnoteBoss)
107 break;
108 pFrame = pFootnoteBoss->FindFootnoteCont();
109 if( pFrame )
110 {
111 if( bSkip )
112 bSkip = false;
113 else
114 {
115 const SwContentFrame* pCnt = static_cast<const SwLayoutFrame*>
116 (pFrame)->ContainsContent();
117 if( pCnt )
118 {
119 SwTextFrame const*const pTF(
120 static_cast<const SwTextFrame*>(pCnt));
121 *GetCursor_()->GetPoint() =
122 pTF->MapViewToModelPos(pTF->GetOffset());
125 bRet = true;
126 break;
127 }
128 }
129 }
130 if( pFootnoteBoss->GetNext() && !pFootnoteBoss->IsPageFrame() )
131 pFrame = pFootnoteBoss->GetNext();
132 else
133 pFrame = pFootnoteBoss->GetUpper();
134 }
135 }
136 }
137 return bRet;
138}
139
141{
142 // jump from footnote to anchor
143 const SwNode* pSttNd = GetPointNode().FindFootnoteStartNode();
144 if( pSttNd )
145 {
146 // search in all footnotes in document for this StartIndex
147 const SwFootnoteIdxs& rFootnoteArr = pSttNd->GetDoc().GetFootnoteIdxs();
148 for( size_t n = 0; n < rFootnoteArr.size(); ++n )
149 {
150 const SwTextFootnote* pTextFootnote = rFootnoteArr[ n ];
151 if( nullptr != pTextFootnote->GetStartNode() &&
152 pSttNd == &pTextFootnote->GetStartNode()->GetNode() )
153 {
154 SwCursorSaveState aSaveState( *this );
155
156 SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
157 GetPoint()->Assign( rTNd, pTextFootnote->GetStart() );
158
161 }
162 }
163 }
164 return false;
165}
166
168{
169 if (SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(this))
170 pWrtSh->addCurrentPosition();
171
172 // jump from footnote to anchor
173 SwCallLink aLk( *this ); // watch Cursor-Moves
175 if( bRet )
176 {
177 // special treatment for table header row
181 }
182 return bRet;
183}
184
185static bool CmpLE( const SwTextFootnote& rFootnote, SwNodeOffset nNd, sal_Int32 nCnt )
186{
187 const SwNodeOffset nTNd = rFootnote.GetTextNode().GetIndex();
188 return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() <= nCnt );
189}
190
191static bool CmpL( const SwTextFootnote& rFootnote, SwNodeOffset nNd, sal_Int32 nCnt )
192{
193 const SwNodeOffset nTNd = rFootnote.GetTextNode().GetIndex();
194 return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() < nCnt );
195}
196
198{
199 const SwFootnoteIdxs& rFootnoteArr = GetDoc().GetFootnoteIdxs();
200 const SwTextFootnote* pTextFootnote = nullptr;
201 size_t nPos = 0;
202
203 if( rFootnoteArr.empty() )
204 {
205 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
206 return false;
207 }
208
209 if( rFootnoteArr.SeekEntry( GetPoint()->GetNode(), &nPos ))
210 {
211 // there is a footnote with this index, so search also for the next one
212 if( nPos < rFootnoteArr.size() )
213 {
214 SwNodeOffset nNdPos = GetPoint()->GetNodeIndex();
215 const sal_Int32 nCntPos = GetPoint()->GetContentIndex();
216
217 pTextFootnote = rFootnoteArr[ nPos ];
218 // search forwards
219 if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
220 {
221 pTextFootnote = nullptr;
222 for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
223 {
224 pTextFootnote = rFootnoteArr[ nPos ];
225 if( !CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
226 break; // found
227 pTextFootnote = nullptr;
228 }
229 }
230 else if( nPos )
231 {
232 // search backwards
233 pTextFootnote = nullptr;
234 while( nPos )
235 {
236 pTextFootnote = rFootnoteArr[ --nPos ];
237 if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
238 {
239 pTextFootnote = rFootnoteArr[ ++nPos ];
240 break; // found
241 }
242 }
243 }
244 }
245 }
246 else if( nPos < rFootnoteArr.size() )
247 pTextFootnote = rFootnoteArr[ nPos ];
248
249 if (pTextFootnote == nullptr)
250 {
251 pTextFootnote = rFootnoteArr[ 0 ];
252 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
253 }
254 else
255 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
256
257 bool bRet = nullptr != pTextFootnote;
258 if( bRet )
259 {
260 SwCursorSaveState aSaveState( *this );
261
262 SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
263 GetPoint()->Assign( rTNd, pTextFootnote->GetStart() );
264 bRet = !IsSelOvr();
265 }
266 return bRet;
267}
268
270{
271 const SwFootnoteIdxs& rFootnoteArr = GetDoc().GetFootnoteIdxs();
272 const SwTextFootnote* pTextFootnote = nullptr;
273 size_t nPos = 0;
274
275 if( rFootnoteArr.empty() )
276 {
277 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
278 return false;
279 }
280
281 if( rFootnoteArr.SeekEntry( GetPoint()->GetNode(), &nPos ) )
282 {
283 // there is a footnote with this index, so search also for the next one
284 SwNodeOffset nNdPos = GetPoint()->GetNodeIndex();
285 const sal_Int32 nCntPos = GetPoint()->GetContentIndex();
286
287 pTextFootnote = rFootnoteArr[ nPos ];
288 // search forwards
289 if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
290 {
291 for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
292 {
293 pTextFootnote = rFootnoteArr[ nPos ];
294 if( !CmpL( *pTextFootnote, nNdPos, nCntPos ) )
295 {
296 pTextFootnote = rFootnoteArr[ nPos-1 ];
297 break;
298 }
299 }
300 }
301 else if( nPos )
302 {
303 // search backwards
304 pTextFootnote = nullptr;
305 while( nPos )
306 {
307 pTextFootnote = rFootnoteArr[ --nPos ];
308 if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
309 break; // found
310 pTextFootnote = nullptr;
311 }
312 }
313 else
314 pTextFootnote = nullptr;
315 }
316 else if( nPos )
317 pTextFootnote = rFootnoteArr[ nPos-1 ];
318
319 if( pTextFootnote == nullptr )
320 {
321 pTextFootnote = rFootnoteArr[ rFootnoteArr.size() - 1 ];
322 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
323 }
324 else
325 SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
326
327 bool bRet = nullptr != pTextFootnote;
328 if( bRet )
329 {
330 SwCursorSaveState aSaveState( *this );
331
332 SwTextNode& rTNd = const_cast<SwTextNode&>(pTextFootnote->GetTextNode());
333 GetPoint()->Assign( rTNd, pTextFootnote->GetStart() );
334 bRet = !IsSelOvr();
335 }
336 return bRet;
337}
338
340{
342}
343
345{
347}
348
351{
352 CurrShell aCurr( this );
353 const SwFrame* pFrame = GetCurrFrame();
354 do {
355 pFrame = pFrame->GetUpper();
356 } while( pFrame && !pFrame->IsFlyFrame() );
357
358 if( !pFrame ) // no FlyFrame
359 return;
360
361 SwCallLink aLk( *this ); // watch Cursor-Moves
362 SwCursorSaveState aSaveState( *m_pCurrentCursor );
363
364 // jump in BodyFrame closest to FlyFrame
365 SwRect aTmpRect( m_aCharRect );
366 if( !pFrame->getFrameArea().Contains( aTmpRect ))
367 aTmpRect = pFrame->getFrameArea();
368 Point aPt( aTmpRect.Left(), aTmpRect.Top() +
369 ( aTmpRect.Bottom() - aTmpRect.Top() ) / 2 );
370 aPt.setX(aPt.getX() > (pFrame->getFrameArea().Left() + (pFrame->getFrameArea().SSize().Width() / 2 ))
371 ? pFrame->getFrameArea().Right()
372 : pFrame->getFrameArea().Left());
373
374 const SwPageFrame* pPageFrame = pFrame->FindPageFrame();
375 const SwContentFrame* pFndFrame = pPageFrame->GetContentPos( aPt, false, true );
377
379 if( bRet )
382}
383
384/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setX(tools::Long nX)
constexpr tools::Long getX() const
static void SetSearchLabel(const SearchLabel &rSL)
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
A helper class to save cursor state (position).
Definition: swcrsr.hxx:233
SAL_DLLPRIVATE void UpdateCursor(sal_uInt16 eFlags=SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE, bool bIdleEnd=false)
Definition: crsrsh.cxx:1876
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:339
SwShellCursor * GetCursor_()
Definition: crsrsh.hxx:343
SAL_DLLPRIVATE bool CallCursorFN(FNCursor)
Definition: trvlfnfl.cxx:48
bool GotoFootnoteAnchor()
jump from footnote to anchor
Definition: trvlfnfl.cxx:167
void GotoFlyAnchor()
jump from the frame to the anchor
Definition: trvlfnfl.cxx:350
bool GotoFootnoteText()
jump from content to footnote
Definition: trvlfnfl.cxx:89
SwContentFrame * GetCurrFrame(const bool bCalcFrame=true) const
Get current frame in which the cursor is positioned.
Definition: crsrsh.cxx:2771
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:344
SwShellCursor * getShellCursor(bool bBlock)
Delivers the current shell cursor.
Definition: crsrsh.cxx:3356
SwRect m_aCharRect
Char-SRectangle on which the cursor is located.
Definition: crsrsh.hxx:175
@ READONLY
make visible in spite of Readonly
Definition: crsrsh.hxx:166
@ CHKRANGE
check overlapping PaMs
Definition: crsrsh.hxx:165
@ SCROLLWIN
scroll window
Definition: crsrsh.hxx:164
SAL_DLLPRIVATE bool CallCursorShellFN(FNCursorShell)
Definition: trvlfnfl.cxx:35
SwShellCursor * m_pCurrentCursor
current cursor
Definition: crsrsh.hxx:186
virtual bool IsSelOvr(SwCursorSelOverFlags eFlags=SwCursorSelOverFlags::CheckNodeSection|SwCursorSelOverFlags::Toggle|SwCursorSelOverFlags::ChangePos)
Definition: swcrsr.cxx:222
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:269
bool GotoFootnoteText()
Definition: trvlfnfl.cxx:62
bool IsInProtectTable(bool bMove=false, bool bChgCursor=true)
Definition: swcrsr.cxx:557
bool GotoFootnoteAnchor()
Definition: trvlfnfl.cxx:140
virtual bool IsReadOnlyAvailable() const
Definition: swcrsr.cxx:150
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:197
SwNodes & GetNodes()
Definition: doc.hxx:422
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:649
SwFootnoteContFrame * FindFootnoteCont()
Definition: ftnfrm.cxx:1038
SwTextFootnote * SeekEntry(const SwNode &rNd, size_t *pPos=nullptr) const
Definition: ftnidx.cxx:408
const SwRect & getFrameArea() const
Definition: frame.hxx:179
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwFrame * GetNext()
Definition: frame.hxx:682
bool IsPageFrame() const
Definition: frame.hxx:1184
bool IsInFootnote() const
Definition: frame.hxx:955
virtual bool GetModelPositionForViewPoint(SwPosition *, Point &, SwCursorMoveState *=nullptr, bool bTestBackground=false) const
Definition: unusedf.cxx:47
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
bool IsFlyFrame() const
Definition: frame.hxx:1216
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
SwFootnoteBossFrame * FindFootnoteBossFrame(bool bFootnotes=false)
Definition: findfrm.cxx:491
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
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 GetModelPositionForView...
Definition: trvlfrm.cxx:1183
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwDoc & GetDoc()
Definition: node.hxx:233
const SwStartNode * FindFootnoteStartNode() const
Definition: node.hxx:222
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:1948
SwNode & GetPointNode() const
Definition: pam.hxx:275
SwDoc & GetDoc() const
Definition: pam.hxx:291
const SwPosition * GetPoint() const
Definition: pam.hxx:253
A page of the document layout.
Definition: pagefrm.hxx:60
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
void Right(const tools::Long nRight)
Definition: swrect.hxx:202
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
void SSize(const Size &rNew)
Definition: swrect.hxx:180
bool Contains(const Point &rPOINT) const
Definition: swrect.hxx:356
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
const Point & GetPtPos() const
Definition: viscrs.hxx:165
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
SwTextAttr subclass for footnotes and endnotes.
Definition: txtftn.hxx:34
const SwNodeIndex * GetStartNode() const
Definition: txtftn.hxx:43
const SwTextNode & GetTextNode() const
Definition: txtftn.hxx:72
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1333
TextFrameIndex GetOffset() const
Definition: txtfrm.hxx:453
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
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:3155
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
bool empty() const
size_type size() const
static SwNode * GetStartNode(SwOutlineNodes const *pOutlNds, int nOutlineLevel, SwOutlineNodes::size_type *nOutl)
Definition: docglbl.cxx:89
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
sal_Int64 n
sal_uInt16 nPos
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:1043
SwNode & GetNode() const
Definition: pam.hxx:81
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
static bool CmpLE(const SwTextFootnote &rFootnote, SwNodeOffset nNd, sal_Int32 nCnt)
Definition: trvlfnfl.cxx:185
static bool CmpL(const SwTextFootnote &rFootnote, SwNodeOffset nNd, sal_Int32 nCnt)
Definition: trvlfnfl.cxx:191