xref: /aoo42x/main/svl/source/items/whiter.cxx (revision 40df464e)
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_svl.hxx"
26 // INCLUDE ---------------------------------------------------------------
27 
28 #include <svl/whiter.hxx>
29 #include <svl/itemset.hxx>
30 
DBG_NAME(SfxWhichIter)31 DBG_NAME(SfxWhichIter)
32 
33 // -----------------------------------------------------------------------
34 
35 SfxWhichIter::SfxWhichIter( const SfxItemSet& rSet, sal_uInt16 nFromWh, sal_uInt16 nToWh ):
36 	pRanges(rSet.GetRanges()),
37 	pStart(rSet.GetRanges()),
38 	nOfst(0), nFrom(nFromWh), nTo(nToWh)
39 {
40 	DBG_CTOR(SfxWhichIter, 0);
41 	if ( nFrom > 0 )
42 		FirstWhich();
43 }
44 
45 // -----------------------------------------------------------------------
46 
~SfxWhichIter()47 SfxWhichIter::~SfxWhichIter()
48 {
49 	DBG_DTOR(SfxWhichIter, 0);
50 }
51 
52 // -----------------------------------------------------------------------
53 
NextWhich()54 sal_uInt16 SfxWhichIter::NextWhich()
55 {
56 	DBG_CHKTHIS(SfxWhichIter, 0);
57 	while ( 0 != *pRanges )
58 	{
59 		const sal_uInt16 nLastWhich = *pRanges + nOfst;
60 		++nOfst;
61 		if (*(pRanges+1) == nLastWhich)
62 		{
63 			pRanges += 2;
64 			nOfst = 0;
65 		}
66 		sal_uInt16 nWhich = *pRanges + nOfst;
67 		if ( 0 == nWhich || ( nWhich >= nFrom && nWhich <= nTo ) )
68 			return nWhich;
69 	}
70 	return 0;
71 }
72 
73 // -----------------------------------------------------------------------
74 
PrevWhich()75 sal_uInt16  SfxWhichIter::PrevWhich()
76 {
77 	DBG_CHKTHIS(SfxWhichIter, 0);
78 	while ( pRanges != pStart || 0 != nOfst )
79 	{
80 		if(nOfst)
81 			--nOfst;
82 		else {
83 			pRanges -= 2;
84 			nOfst = *(pRanges+1) - (*pRanges);
85 		}
86 		sal_uInt16 nWhich = *pRanges + nOfst;
87 		if ( nWhich >= nFrom && nWhich <= nTo )
88 			return nWhich;
89 	}
90 	return 0;
91 }
92 
93 // -----------------------------------------------------------------------
94 
FirstWhich()95 sal_uInt16 SfxWhichIter::FirstWhich()
96 {
97 	DBG_CHKTHIS(SfxWhichIter, 0);
98 	pRanges = pStart;
99 	nOfst = 0;
100 	if ( *pRanges >= nFrom && *pRanges <= nTo )
101 		return *pRanges;
102 	return NextWhich();
103 }
104 
105 // -----------------------------------------------------------------------
106 
LastWhich()107 sal_uInt16 SfxWhichIter::LastWhich()
108 {
109 	DBG_CHKTHIS(SfxWhichIter, 0);
110 	while(*pRanges)
111 		++pRanges;
112 	nOfst = 0;
113 	sal_uInt16 nWhich = *(pRanges-1);
114 	if ( nWhich >= nFrom && nWhich <= nTo )
115 		return nWhich;
116 	return PrevWhich();
117 }
118 
119