1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <doc.hxx>
29 #include <pamtyp.hxx>
30
31
Find(const SwFmt & rFmt,SwMoveFn fnMove,const SwPaM * pRegion,sal_Bool bInReadOnly)32 sal_Bool SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
33 const SwPaM *pRegion, sal_Bool bInReadOnly )
34 {
35 sal_Bool bFound = sal_False;
36 sal_Bool bSrchForward = fnMove == fnMoveForward;
37 SwPaM* pPam = MakeRegion( fnMove, pRegion );
38
39 // Wenn am Anfang/Ende, aus dem Node moven
40 if( bSrchForward
41 ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetCntntNode()->Len()
42 : !pPam->GetPoint()->nContent.GetIndex() )
43 {
44 if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, sal_False ))
45 {
46 delete pPam;
47 return sal_False;
48 }
49 SwCntntNode *pNd = pPam->GetPoint()->nNode.GetNode().GetCntntNode();
50 xub_StrLen nTmpPos = bSrchForward ? 0 : pNd->Len();
51 pPam->GetPoint()->nContent.Assign( pNd, nTmpPos );
52 }
53
54 sal_Bool bFirst = sal_True;
55 SwCntntNode* pNode;
56 while( !bFound &&
57 0 != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly )))
58 {
59 if( 0 != ( bFound = pNode->GetFmtColl() == &rFmt ))
60 {
61 // wurde die FormatCollection gefunden, dann handelt es sich auf
62 // jedenfall um einen SwCntntNode !!
63
64 // FORWARD: SPoint an das Ende, GetMark zum Anfanf vom Node
65 // BACKWARD: SPoint zum Anfang, GetMark an das Ende vom Node
66 // und immer nach der Logik: inkl. Start, exkl. End !!!
67 *GetPoint() = *pPam->GetPoint();
68 SetMark();
69 pNode->MakeEndIndex( &GetPoint()->nContent );
70 GetMark()->nContent = 0;
71 if( !bSrchForward ) // rueckwaerts Suche?
72 Exchange(); // SPoint und GetMark tauschen
73 break;
74 }
75 }
76 delete pPam;
77 return bFound;
78 }
79
80
81