xref: /aoo41x/main/svl/source/items/flagitem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include <svl/flagitem.hxx>
32 #include <svl/poolitem.hxx>
33 #include <tools/stream.hxx>
34 
35 // STATIC DATA -----------------------------------------------------------
36 
37 DBG_NAME(SfxFlagItem)
38 
39 sal_uInt16 nSfxFlagVal[16] =
40 {
41 	0x0001, 0x0002, 0x0004, 0x0008,
42 	0x0010, 0x0020, 0x0040, 0x0080,
43 	0x0100, 0x0200, 0x0400, 0x0800,
44 	0x1000, 0x2000, 0x4000, 0x8000
45 };
46 
47 
48 // -----------------------------------------------------------------------
49 
50 TYPEINIT1(SfxFlagItem, SfxPoolItem);
51 
52 // -----------------------------------------------------------------------
53 
54 SfxFlagItem::SfxFlagItem( sal_uInt16 nW, sal_uInt16 nV ) :
55 	SfxPoolItem( nW ),
56 	nVal(nV)
57 {
58 	DBG_CTOR(SfxFlagItem, 0);
59 }
60 
61 // -----------------------------------------------------------------------
62 
63 SfxFlagItem::SfxFlagItem( sal_uInt16 nW, SvStream &rStream) :
64 	SfxPoolItem( nW )
65 {
66 	DBG_CTOR(SfxFlagItem, 0);
67 	rStream >> nVal;
68 }
69 
70 // -----------------------------------------------------------------------
71 
72 SfxFlagItem::SfxFlagItem( const SfxFlagItem& rItem ) :
73 	SfxPoolItem( rItem ),
74 	nVal( rItem.nVal )
75 {
76 	DBG_CTOR(SfxFlagItem, 0);
77 }
78 
79 // -----------------------------------------------------------------------
80 
81 SvStream& SfxFlagItem::Store(SvStream &rStream, sal_uInt16) const
82 {
83 	DBG_CHKTHIS(SfxFlagItem, 0);
84 	rStream << nVal;
85 	return rStream;
86 }
87 
88 // -----------------------------------------------------------------------
89 
90 SfxItemPresentation SfxFlagItem::GetPresentation
91 (
92 	SfxItemPresentation 	/*ePresentation*/,
93 	SfxMapUnit				/*eCoreMetric*/,
94 	SfxMapUnit				/*ePresentationMetric*/,
95 	XubString& 				rText,
96     const IntlWrapper *
97 )	const
98 {
99 	DBG_CHKTHIS(SfxFlagItem, 0);
100 	rText.Erase();
101 	for ( sal_uInt8 nFlag = 0; nFlag < GetFlagCount(); ++nFlag )
102 		rText += XubString::CreateFromInt32( GetFlag(nFlag) );
103 	return SFX_ITEM_PRESENTATION_NAMELESS;
104 }
105 
106 // -----------------------------------------------------------------------
107 
108 XubString SfxFlagItem::GetFlagText( sal_uInt8 ) const
109 {
110 	DBG_CHKTHIS(SfxFlagItem, 0);
111 	DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" );
112 	return XubString();
113 }
114 
115 // -----------------------------------------------------------------------
116 
117 sal_uInt8 SfxFlagItem::GetFlagCount() const
118 {
119 	DBG_CHKTHIS(SfxFlagItem, 0);
120 	DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" );
121 	return 0;
122 }
123 
124 // -----------------------------------------------------------------------
125 
126 SfxPoolItem* SfxFlagItem::Create(SvStream &, sal_uInt16) const
127 {
128 	DBG_CHKTHIS(SfxFlagItem, 0);
129 	DBG_WARNING( "calling Create() on SfxFlagItem -- overload!" );
130 	return 0;
131 }
132 
133 // -----------------------------------------------------------------------
134 
135 int SfxFlagItem::operator==( const SfxPoolItem& rItem ) const
136 {
137 	DBG_CHKTHIS(SfxFlagItem, 0);
138 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
139 	return (((SfxFlagItem&)rItem).nVal == nVal);
140 }
141 
142 // -----------------------------------------------------------------------
143 
144 void SfxFlagItem::SetFlag( sal_uInt8 nFlag, int bVal )
145 {
146 	if ( bVal )
147 		nVal |= nSfxFlagVal[nFlag];
148 	else
149 		nVal &= ~nSfxFlagVal[nFlag];
150 }
151 
152 // -----------------------------------------------------------------------
153 
154 SfxPoolItem* SfxFlagItem::Clone(SfxItemPool *) const
155 {
156 	DBG_CHKTHIS(SfxFlagItem, 0);
157 	return new SfxFlagItem( *this );
158 }
159 
160 
161 
162 
163 
164