merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / crsr / findfmt.cxx
blob30794c5209f78d10ed82ec390c560e5c77727c3a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: findfmt.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <doc.hxx>
36 #include <pamtyp.hxx>
39 BOOL SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
40 const SwPaM *pRegion, BOOL bInReadOnly )
42 BOOL bFound = FALSE;
43 BOOL bSrchForward = fnMove == fnMoveForward;
44 SwPaM* pPam = MakeRegion( fnMove, pRegion );
46 // Wenn am Anfang/Ende, aus dem Node moven
47 if( bSrchForward
48 ? pPam->GetPoint()->nContent.GetIndex() == pPam->GetCntntNode()->Len()
49 : !pPam->GetPoint()->nContent.GetIndex() )
51 if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, FALSE ))
53 delete pPam;
54 return FALSE;
56 SwCntntNode *pNd = pPam->GetPoint()->nNode.GetNode().GetCntntNode();
57 xub_StrLen nTmpPos = bSrchForward ? 0 : pNd->Len();
58 pPam->GetPoint()->nContent.Assign( pNd, nTmpPos );
61 BOOL bFirst = TRUE;
62 SwCntntNode* pNode;
63 while( !bFound &&
64 0 != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly )))
66 if( 0 != ( bFound = pNode->GetFmtColl() == &rFmt ))
68 // wurde die FormatCollection gefunden, dann handelt es sich auf
69 // jedenfall um einen SwCntntNode !!
71 // FORWARD: SPoint an das Ende, GetMark zum Anfanf vom Node
72 // BACKWARD: SPoint zum Anfang, GetMark an das Ende vom Node
73 // und immer nach der Logik: inkl. Start, exkl. End !!!
74 *GetPoint() = *pPam->GetPoint();
75 SetMark();
76 pNode->MakeEndIndex( &GetPoint()->nContent );
77 GetMark()->nContent = 0;
78 if( !bSrchForward ) // rueckwaerts Suche?
79 Exchange(); // SPoint und GetMark tauschen
80 break;
83 delete pPam;
84 return bFound;