Update ooo320-m1
[ooovba.git] / svtools / source / items1 / whiter.cxx
bloba74a9e42532f802fbbb5087421ab9424c8a8bc5a
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: whiter.cxx,v $
10 * $Revision: 1.7 $
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_svtools.hxx"
33 // INCLUDE ---------------------------------------------------------------
34 #ifndef GCC
35 #endif
37 #include "whiter.hxx"
38 #include <svtools/itemset.hxx>
40 DBG_NAME(SfxWhichIter)
42 // -----------------------------------------------------------------------
44 SfxWhichIter::SfxWhichIter( const SfxItemSet& rSet, USHORT nFromWh, USHORT nToWh ):
45 pRanges(rSet.GetRanges()),
46 pStart(rSet.GetRanges()),
47 nOfst(0), nFrom(nFromWh), nTo(nToWh)
49 DBG_CTOR(SfxWhichIter, 0);
50 if ( nFrom > 0 )
51 FirstWhich();
54 // -----------------------------------------------------------------------
56 SfxWhichIter::~SfxWhichIter()
58 DBG_DTOR(SfxWhichIter, 0);
61 // -----------------------------------------------------------------------
63 USHORT SfxWhichIter::NextWhich()
65 DBG_CHKTHIS(SfxWhichIter, 0);
66 while ( 0 != *pRanges )
68 const USHORT nLastWhich = *pRanges + nOfst;
69 ++nOfst;
70 if (*(pRanges+1) == nLastWhich)
72 pRanges += 2;
73 nOfst = 0;
75 USHORT nWhich = *pRanges + nOfst;
76 if ( 0 == nWhich || ( nWhich >= nFrom && nWhich <= nTo ) )
77 return nWhich;
79 return 0;
82 // -----------------------------------------------------------------------
84 USHORT SfxWhichIter::PrevWhich()
86 DBG_CHKTHIS(SfxWhichIter, 0);
87 while ( pRanges != pStart || 0 != nOfst )
89 if(nOfst)
90 --nOfst;
91 else {
92 pRanges -= 2;
93 nOfst = *(pRanges+1) - (*pRanges);
95 USHORT nWhich = *pRanges + nOfst;
96 if ( nWhich >= nFrom && nWhich <= nTo )
97 return nWhich;
99 return 0;
102 // -----------------------------------------------------------------------
104 USHORT SfxWhichIter::FirstWhich()
106 DBG_CHKTHIS(SfxWhichIter, 0);
107 pRanges = pStart;
108 nOfst = 0;
109 if ( *pRanges >= nFrom && *pRanges <= nTo )
110 return *pRanges;
111 return NextWhich();
114 // -----------------------------------------------------------------------
116 USHORT SfxWhichIter::LastWhich()
118 DBG_CHKTHIS(SfxWhichIter, 0);
119 while(*pRanges)
120 ++pRanges;
121 nOfst = 0;
122 USHORT nWhich = *(pRanges-1);
123 if ( nWhich >= nFrom && nWhich <= nTo )
124 return nWhich;
125 return PrevWhich();