xref: /aoo42x/main/svl/source/items/flagitem.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 
27 #include <svl/flagitem.hxx>
28 #include <svl/poolitem.hxx>
29 #include <tools/stream.hxx>
30 
31 // STATIC DATA -----------------------------------------------------------
32 
33 DBG_NAME(SfxFlagItem)
34 
35 sal_uInt16 nSfxFlagVal[16] =
36 {
37 	0x0001, 0x0002, 0x0004, 0x0008,
38 	0x0010, 0x0020, 0x0040, 0x0080,
39 	0x0100, 0x0200, 0x0400, 0x0800,
40 	0x1000, 0x2000, 0x4000, 0x8000
41 };
42 
43 
44 // -----------------------------------------------------------------------
45 
46 TYPEINIT1(SfxFlagItem, SfxPoolItem);
47 
48 // -----------------------------------------------------------------------
49 
SfxFlagItem(sal_uInt16 nW,sal_uInt16 nV)50 SfxFlagItem::SfxFlagItem( sal_uInt16 nW, sal_uInt16 nV ) :
51 	SfxPoolItem( nW ),
52 	nVal(nV)
53 {
54 	DBG_CTOR(SfxFlagItem, 0);
55 }
56 
57 // -----------------------------------------------------------------------
58 
SfxFlagItem(sal_uInt16 nW,SvStream & rStream)59 SfxFlagItem::SfxFlagItem( sal_uInt16 nW, SvStream &rStream) :
60 	SfxPoolItem( nW )
61 {
62 	DBG_CTOR(SfxFlagItem, 0);
63 	rStream >> nVal;
64 }
65 
66 // -----------------------------------------------------------------------
67 
SfxFlagItem(const SfxFlagItem & rItem)68 SfxFlagItem::SfxFlagItem( const SfxFlagItem& rItem ) :
69 	SfxPoolItem( rItem ),
70 	nVal( rItem.nVal )
71 {
72 	DBG_CTOR(SfxFlagItem, 0);
73 }
74 
75 // -----------------------------------------------------------------------
76 
Store(SvStream & rStream,sal_uInt16) const77 SvStream& SfxFlagItem::Store(SvStream &rStream, sal_uInt16) const
78 {
79 	DBG_CHKTHIS(SfxFlagItem, 0);
80 	rStream << nVal;
81 	return rStream;
82 }
83 
84 // -----------------------------------------------------------------------
85 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const86 SfxItemPresentation SfxFlagItem::GetPresentation
87 (
88 	SfxItemPresentation 	/*ePresentation*/,
89 	SfxMapUnit				/*eCoreMetric*/,
90 	SfxMapUnit				/*ePresentationMetric*/,
91 	XubString& 				rText,
92     const IntlWrapper *
93 )	const
94 {
95 	DBG_CHKTHIS(SfxFlagItem, 0);
96 	rText.Erase();
97 	for ( sal_uInt8 nFlag = 0; nFlag < GetFlagCount(); ++nFlag )
98 		rText += XubString::CreateFromInt32( GetFlag(nFlag) );
99 	return SFX_ITEM_PRESENTATION_NAMELESS;
100 }
101 
102 // -----------------------------------------------------------------------
103 
GetFlagText(sal_uInt8) const104 XubString SfxFlagItem::GetFlagText( sal_uInt8 ) const
105 {
106 	DBG_CHKTHIS(SfxFlagItem, 0);
107 	DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" );
108 	return XubString();
109 }
110 
111 // -----------------------------------------------------------------------
112 
GetFlagCount() const113 sal_uInt8 SfxFlagItem::GetFlagCount() const
114 {
115 	DBG_CHKTHIS(SfxFlagItem, 0);
116 	DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" );
117 	return 0;
118 }
119 
120 // -----------------------------------------------------------------------
121 
Create(SvStream &,sal_uInt16) const122 SfxPoolItem* SfxFlagItem::Create(SvStream &, sal_uInt16) const
123 {
124 	DBG_CHKTHIS(SfxFlagItem, 0);
125 	DBG_WARNING( "calling Create() on SfxFlagItem -- overload!" );
126 	return 0;
127 }
128 
129 // -----------------------------------------------------------------------
130 
operator ==(const SfxPoolItem & rItem) const131 int SfxFlagItem::operator==( const SfxPoolItem& rItem ) const
132 {
133 	DBG_CHKTHIS(SfxFlagItem, 0);
134 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
135 	return (((SfxFlagItem&)rItem).nVal == nVal);
136 }
137 
138 // -----------------------------------------------------------------------
139 
SetFlag(sal_uInt8 nFlag,int bVal)140 void SfxFlagItem::SetFlag( sal_uInt8 nFlag, int bVal )
141 {
142 	if ( bVal )
143 		nVal |= nSfxFlagVal[nFlag];
144 	else
145 		nVal &= ~nSfxFlagVal[nFlag];
146 }
147 
148 // -----------------------------------------------------------------------
149 
Clone(SfxItemPool *) const150 SfxPoolItem* SfxFlagItem::Clone(SfxItemPool *) const
151 {
152 	DBG_CHKTHIS(SfxFlagItem, 0);
153 	return new SfxFlagItem( *this );
154 }
155 
156 
157 
158 
159 
160