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 <doc.hxx>
21 : #include <pamtyp.hxx>
22 :
23 :
24 0 : sal_Bool SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
25 : const SwPaM *pRegion, sal_Bool bInReadOnly )
26 : {
27 0 : sal_Bool bFound = sal_False;
28 0 : const bool bSrchForward = (fnMove == fnMoveForward);
29 0 : SwPaM* pPam = MakeRegion( fnMove, pRegion );
30 :
31 : // if at beginning/end then move it out of the node
32 0 : if( bSrchForward
33 0 : ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetCntntNode()->Len()
34 0 : : !pPam->GetPoint()->nContent.GetIndex() )
35 : {
36 0 : if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, sal_False ))
37 : {
38 0 : delete pPam;
39 0 : return sal_False;
40 : }
41 0 : SwCntntNode *pNd = pPam->GetPoint()->nNode.GetNode().GetCntntNode();
42 0 : xub_StrLen nTmpPos = bSrchForward ? 0 : pNd->Len();
43 0 : pPam->GetPoint()->nContent.Assign( pNd, nTmpPos );
44 : }
45 :
46 0 : sal_Bool bFirst = sal_True;
47 : SwCntntNode* pNode;
48 0 : while( !bFound &&
49 0 : 0 != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly )))
50 : {
51 0 : if( 0 != ( bFound = (pNode->GetFmtColl() == &rFmt) ))
52 : {
53 : // if a FormatCollection is found then it is definitely a SwCntntNode
54 :
55 : // FORWARD: SPoint at the end, GetMark at the beginning of the node
56 : // BACKWARD: SPoint at the beginning, GetMark at the end of the node
57 : // always: incl. start and incl. end
58 0 : *GetPoint() = *pPam->GetPoint();
59 0 : SetMark();
60 0 : pNode->MakeEndIndex( &GetPoint()->nContent );
61 0 : GetMark()->nContent = 0;
62 :
63 : // if backward search, switch point and mark
64 0 : if( !bSrchForward )
65 0 : Exchange();
66 0 : break;
67 : }
68 : }
69 0 : delete pPam;
70 0 : return bFound;
71 : }
72 :
73 :
74 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|