Branch data Line data Source code
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 <svx/svdmodel.hxx>
21 : : #include <svx/svdpage.hxx>
22 : : #include <crsrsh.hxx>
23 : : #include <doc.hxx>
24 : : #include <pagefrm.hxx>
25 : : #include <cntfrm.hxx>
26 : : #include <ftnfrm.hxx>
27 : : #include <viewimp.hxx>
28 : : #include <swcrsr.hxx>
29 : : #include <dflyobj.hxx>
30 : : #include <ndtxt.hxx>
31 : : #include <flyfrm.hxx>
32 : : #include <txtfrm.hxx>
33 : : #include <txtftn.hxx>
34 : : #include <ftnidx.hxx>
35 : : #include <viscrs.hxx>
36 : : #include <callnk.hxx>
37 : :
38 : 0 : sal_Bool SwCrsrShell::CallCrsrFN( FNCrsr fnCrsr )
39 : : {
40 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves
41 [ # # ][ # # ]: 0 : SwCursor* pCrsr = getShellCrsr( true );
42 [ # # ][ # # ]: 0 : sal_Bool bRet = (pCrsr->*fnCrsr)();
43 [ # # ]: 0 : if( bRet )
44 : : UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
45 [ # # ]: 0 : SwCrsrShell::READONLY );
46 [ # # ]: 0 : return bRet;
47 : : }
48 : :
49 : 0 : sal_Bool SwCursor::GotoFtnTxt()
50 : : {
51 : : // jump from content to footnote
52 : 0 : sal_Bool bRet = sal_False;
53 : 0 : SwTxtNode* pTxtNd = GetPoint()->nNode.GetNode().GetTxtNode();
54 : :
55 : : SwTxtAttr *const pFtn( (pTxtNd)
56 : : ? pTxtNd->GetTxtAttrForCharAt(
57 : 0 : GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN)
58 [ # # ]: 0 : : 0);
59 [ # # ]: 0 : if (pFtn)
60 : : {
61 [ # # ]: 0 : SwCrsrSaveState aSaveState( *this );
62 [ # # ]: 0 : GetPoint()->nNode = *((SwTxtFtn*)pFtn)->GetStartNode();
63 : :
64 [ # # ]: 0 : SwCntntNode* pCNd = GetDoc()->GetNodes().GoNextSection(
65 : 0 : &GetPoint()->nNode,
66 [ # # ][ # # ]: 0 : sal_True, !IsReadOnlyAvailable() );
67 [ # # ]: 0 : if( pCNd )
68 : : {
69 [ # # ][ # # ]: 0 : GetPoint()->nContent.Assign( pCNd, 0 );
70 : : bRet = !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
71 [ # # ]: 0 : nsSwCursorSelOverFlags::SELOVER_TOGGLE );
72 [ # # ]: 0 : }
73 : : }
74 : 0 : return bRet;
75 : : }
76 : :
77 : 0 : sal_Bool SwCrsrShell::GotoFtnTxt()
78 : : {
79 : 0 : sal_Bool bRet = CallCrsrFN( &SwCursor::GotoFtnTxt );
80 [ # # ]: 0 : if( !bRet )
81 : : {
82 : 0 : SwTxtNode* pTxtNd = _GetCrsr() ?
83 [ # # ]: 0 : _GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode() : NULL;
84 [ # # ]: 0 : if( pTxtNd )
85 : : {
86 : 0 : const SwFrm *pFrm = pTxtNd->getLayoutFrm( GetLayout(), &_GetCrsr()->GetSttPos(),
87 : 0 : _GetCrsr()->Start() );
88 : : const SwFtnBossFrm* pFtnBoss;
89 [ # # ][ # # ]: 0 : sal_Bool bSkip = pFrm && pFrm->IsInFtn();
90 [ # # ][ # # ]: 0 : while( pFrm && 0 != ( pFtnBoss = pFrm->FindFtnBossFrm() ) )
[ # # ]
91 : : {
92 [ # # ]: 0 : if( 0 != ( pFrm = pFtnBoss->FindFtnCont() ) )
93 : : {
94 [ # # ]: 0 : if( bSkip )
95 : 0 : bSkip = sal_False;
96 : : else
97 : : {
98 : : const SwCntntFrm* pCnt = static_cast<const SwLayoutFrm*>
99 : 0 : (pFrm)->ContainsCntnt();
100 [ # # ]: 0 : if( pCnt )
101 : : {
102 : 0 : const SwCntntNode* pNode = pCnt->GetNode();
103 : 0 : _GetCrsr()->GetPoint()->nNode = *pNode;
104 : 0 : _GetCrsr()->GetPoint()->nContent.Assign(
105 : : const_cast<SwCntntNode*>(pNode),
106 [ # # ]: 0 : static_cast<const SwTxtFrm*>(pCnt)->GetOfst() );
107 : : UpdateCrsr( SwCrsrShell::SCROLLWIN |
108 : 0 : SwCrsrShell::CHKRANGE | SwCrsrShell::READONLY );
109 : 0 : bRet = sal_True;
110 : 0 : break;
111 : : }
112 : : }
113 : : }
114 [ # # ][ # # ]: 0 : if( pFtnBoss->GetNext() && !pFtnBoss->IsPageFrm() )
[ # # ]
115 : 0 : pFrm = pFtnBoss->GetNext();
116 : : else
117 : 0 : pFrm = pFtnBoss->GetUpper();
118 : : }
119 : : }
120 : : }
121 : 0 : return bRet;
122 : : }
123 : :
124 : :
125 : 0 : sal_Bool SwCursor::GotoFtnAnchor()
126 : : {
127 : : // jump from footnote to anchor
128 : 0 : const SwNode* pSttNd = GetNode()->FindFootnoteStartNode();
129 [ # # ]: 0 : if( pSttNd )
130 : : {
131 : : // search in all footnotes in document for this StartIndex
132 : : const SwTxtFtn* pTxtFtn;
133 : 0 : const SwFtnIdxs& rFtnArr = pSttNd->GetDoc()->GetFtnIdxs();
134 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rFtnArr.size(); ++n )
135 [ # # # # ]: 0 : if( 0 != ( pTxtFtn = rFtnArr[ n ])->GetStartNode() &&
[ # # ]
136 : 0 : pSttNd == &pTxtFtn->GetStartNode()->GetNode() )
137 : : {
138 [ # # ]: 0 : SwCrsrSaveState aSaveState( *this );
139 : :
140 : 0 : SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
141 : :
142 [ # # ]: 0 : GetPoint()->nNode = rTNd;
143 [ # # ]: 0 : GetPoint()->nContent.Assign( &rTNd, *pTxtFtn->GetStart() );
144 : :
145 : : return !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
146 [ # # ][ # # ]: 0 : nsSwCursorSelOverFlags::SELOVER_TOGGLE );
147 : : }
148 : : }
149 : 0 : return sal_False;
150 : : }
151 : :
152 : 0 : sal_Bool SwCrsrShell::GotoFtnAnchor()
153 : : {
154 : : // jump from footnote to anchor
155 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves
156 [ # # ]: 0 : sal_Bool bRet = pCurCrsr->GotoFtnAnchor();
157 [ # # ]: 0 : if( bRet )
158 : : {
159 : : // special treatment for table header row
160 : 0 : pCurCrsr->GetPtPos() = Point();
161 : : UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
162 [ # # ]: 0 : SwCrsrShell::READONLY );
163 : : }
164 [ # # ]: 0 : return bRet;
165 : : }
166 : :
167 : 0 : inline sal_Bool CmpLE( const SwTxtFtn& rFtn, sal_uLong nNd, xub_StrLen nCnt )
168 : : {
169 : 0 : sal_uLong nTNd = rFtn.GetTxtNode().GetIndex();
170 [ # # ][ # # ]: 0 : return nTNd < nNd || ( nTNd == nNd && *rFtn.GetStart() <= nCnt );
[ # # ]
171 : : }
172 : 0 : inline sal_Bool CmpL( const SwTxtFtn& rFtn, sal_uLong nNd, xub_StrLen nCnt )
173 : : {
174 : 0 : sal_uLong nTNd = rFtn.GetTxtNode().GetIndex();
175 [ # # ][ # # ]: 0 : return nTNd < nNd || ( nTNd == nNd && *rFtn.GetStart() < nCnt );
[ # # ]
176 : : }
177 : :
178 : 0 : sal_Bool SwCursor::GotoNextFtnAnchor()
179 : : {
180 : 0 : const SwFtnIdxs& rFtnArr = GetDoc()->GetFtnIdxs();
181 : 0 : const SwTxtFtn* pTxtFtn = 0;
182 : : sal_uInt16 nPos;
183 : :
184 [ # # ][ # # ]: 0 : if( rFtnArr.SeekEntry( GetPoint()->nNode, &nPos ))
185 : : {
186 : : // there is a footnote with this index, so search also for the next one
187 [ # # ]: 0 : if( nPos < rFtnArr.size() )
188 : : {
189 : 0 : sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
190 : 0 : xub_StrLen nCntPos = GetPoint()->nContent.GetIndex();
191 : :
192 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos ];
193 : : // search forwards
194 [ # # ]: 0 : if( CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
195 : : {
196 : 0 : pTxtFtn = 0;
197 [ # # ]: 0 : for( ++nPos; nPos < rFtnArr.size(); ++nPos )
198 : : {
199 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos ];
200 [ # # ]: 0 : if( !CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
201 : 0 : break; // found
202 : 0 : pTxtFtn = 0;
203 : : }
204 : : }
205 [ # # ]: 0 : else if( nPos )
206 : : {
207 : : // search backwards
208 : 0 : pTxtFtn = 0;
209 [ # # ]: 0 : while( nPos )
210 : : {
211 [ # # ]: 0 : pTxtFtn = rFtnArr[ --nPos ];
212 [ # # ]: 0 : if( CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
213 : : {
214 [ # # ]: 0 : pTxtFtn = rFtnArr[ ++nPos ];
215 : 0 : break; // found
216 : : }
217 : : }
218 : : }
219 : : }
220 : : }
221 [ # # ]: 0 : else if( nPos < rFtnArr.size() )
222 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos ];
223 : :
224 : 0 : sal_Bool bRet = 0 != pTxtFtn;
225 [ # # ]: 0 : if( bRet )
226 : : {
227 [ # # ]: 0 : SwCrsrSaveState aSaveState( *this );
228 : :
229 : 0 : SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
230 [ # # ]: 0 : GetPoint()->nNode = rTNd;
231 [ # # ]: 0 : GetPoint()->nContent.Assign( &rTNd, *pTxtFtn->GetStart() );
232 [ # # ][ # # ]: 0 : bRet = !IsSelOvr();
233 : : }
234 : 0 : return bRet;
235 : : }
236 : :
237 : 0 : sal_Bool SwCursor::GotoPrevFtnAnchor()
238 : : {
239 : 0 : const SwFtnIdxs& rFtnArr = GetDoc()->GetFtnIdxs();
240 : 0 : const SwTxtFtn* pTxtFtn = 0;
241 : : sal_uInt16 nPos;
242 : :
243 [ # # ][ # # ]: 0 : if( rFtnArr.SeekEntry( GetPoint()->nNode, &nPos ) )
244 : : {
245 : : // there is a footnote with this index, so search also for the next one
246 : 0 : sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
247 : 0 : xub_StrLen nCntPos = GetPoint()->nContent.GetIndex();
248 : :
249 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos ];
250 : : // search forwards
251 [ # # ]: 0 : if( CmpL( *pTxtFtn, nNdPos, nCntPos ))
252 : : {
253 [ # # ]: 0 : for( ++nPos; nPos < rFtnArr.size(); ++nPos )
254 : : {
255 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos ];
256 [ # # ]: 0 : if( !CmpL( *pTxtFtn, nNdPos, nCntPos ) )
257 : : {
258 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos-1 ];
259 : 0 : break;
260 : : }
261 : : }
262 : : }
263 [ # # ]: 0 : else if( nPos )
264 : : {
265 : : // search backwards
266 : 0 : pTxtFtn = 0;
267 [ # # ]: 0 : while( nPos )
268 : : {
269 [ # # ]: 0 : pTxtFtn = rFtnArr[ --nPos ];
270 [ # # ]: 0 : if( CmpL( *pTxtFtn, nNdPos, nCntPos ))
271 : 0 : break; // found
272 : 0 : pTxtFtn = 0;
273 : : }
274 : : }
275 : : else
276 : 0 : pTxtFtn = 0;
277 : : }
278 [ # # ]: 0 : else if( nPos )
279 [ # # ]: 0 : pTxtFtn = rFtnArr[ nPos-1 ];
280 : :
281 : 0 : sal_Bool bRet = 0 != pTxtFtn;
282 [ # # ]: 0 : if( bRet )
283 : : {
284 [ # # ]: 0 : SwCrsrSaveState aSaveState( *this );
285 : :
286 : 0 : SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
287 [ # # ]: 0 : GetPoint()->nNode = rTNd;
288 [ # # ]: 0 : GetPoint()->nContent.Assign( &rTNd, *pTxtFtn->GetStart() );
289 [ # # ][ # # ]: 0 : bRet = !IsSelOvr();
290 : : }
291 : 0 : return bRet;
292 : : }
293 : :
294 : 0 : sal_Bool SwCrsrShell::GotoNextFtnAnchor()
295 : : {
296 : 0 : return CallCrsrFN( &SwCursor::GotoNextFtnAnchor );
297 : : }
298 : :
299 : 0 : sal_Bool SwCrsrShell::GotoPrevFtnAnchor()
300 : : {
301 : 0 : return CallCrsrFN( &SwCursor::GotoPrevFtnAnchor );
302 : : }
303 : :
304 : : /// jump from border to anchor
305 : 0 : sal_Bool SwCrsrShell::GotoFlyAnchor()
306 : : {
307 [ # # ]: 0 : SET_CURR_SHELL( this );
308 [ # # ]: 0 : const SwFrm* pFrm = GetCurrFrm();
309 [ # # ]: 0 : do {
[ # # # # ]
310 : 0 : pFrm = pFrm->GetUpper();
311 : 0 : } while( pFrm && !pFrm->IsFlyFrm() );
312 : :
313 [ # # ]: 0 : if( !pFrm ) // no FlyFrame
314 : 0 : return sal_False;
315 : :
316 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves
317 [ # # ]: 0 : SwCrsrSaveState aSaveState( *pCurCrsr );
318 : :
319 : : // jump in BodyFrame closest to FlyFrame
320 : 0 : SwRect aTmpRect( aCharRect );
321 [ # # ][ # # ]: 0 : if( !pFrm->Frm().IsInside( aTmpRect ))
322 : 0 : aTmpRect = pFrm->Frm();
323 : 0 : Point aPt( aTmpRect.Left(), aTmpRect.Top() +
324 : 0 : ( aTmpRect.Bottom() - aTmpRect.Top() ) / 2 );
325 : 0 : aPt.X() = aPt.X() > (pFrm->Frm().Left() + (pFrm->Frm().SSize().Width() / 2 ))
326 : 0 : ? pFrm->Frm().Right()
327 [ # # ]: 0 : : pFrm->Frm().Left();
328 : :
329 [ # # ]: 0 : const SwPageFrm* pPageFrm = pFrm->FindPageFrm();
330 [ # # ]: 0 : const SwCntntFrm* pFndFrm = pPageFrm->GetCntntPos( aPt, sal_False, sal_True );
331 [ # # ]: 0 : pFndFrm->GetCrsrOfst( pCurCrsr->GetPoint(), aPt );
332 : :
333 [ # # ][ # # ]: 0 : sal_Bool bRet = !pCurCrsr->IsInProtectTable() && !pCurCrsr->IsSelOvr();
[ # # ][ # # ]
334 [ # # ]: 0 : if( bRet )
335 : : UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
336 [ # # ]: 0 : SwCrsrShell::READONLY );
337 [ # # ][ # # ]: 0 : return bRet;
[ # # ]
338 : : }
339 : :
340 : :
341 : :
342 : :
343 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|