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