xref: /aoo41x/main/svl/source/items/visitem.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 <svl/visitem.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <tools/stream.hxx>
29 
30 //============================================================================
31 //
32 //  class SfxVisibilityItem
33 //
34 //============================================================================
35 
36 DBG_NAME(SfxVisibilityItem)
37 
38 //============================================================================
39 TYPEINIT1_AUTOFACTORY(SfxVisibilityItem, SfxPoolItem);
40 
41 //============================================================================
SfxVisibilityItem(sal_uInt16 which,SvStream & rStream)42 SfxVisibilityItem::SfxVisibilityItem(sal_uInt16 which, SvStream & rStream):
43 	SfxPoolItem(which)
44 {
45 	DBG_CTOR(SfxVisibilityItem, 0);
46 	sal_Bool bValue = 0;
47 	rStream >> bValue;
48 	m_nValue.bVisible = bValue;
49 }
50 
51 //============================================================================
52 // virtual
operator ==(const SfxPoolItem & rItem) const53 int SfxVisibilityItem::operator ==(const SfxPoolItem & rItem) const
54 {
55 	DBG_CHKTHIS(SfxVisibilityItem, 0);
56 	DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type");
57 	return m_nValue.bVisible == SAL_STATIC_CAST(const SfxVisibilityItem *, &rItem)->
58 	                    m_nValue.bVisible;
59 }
60 
61 //============================================================================
62 // virtual
Compare(const SfxPoolItem & rWith) const63 int SfxVisibilityItem::Compare(const SfxPoolItem & rWith) const
64 {
65 	DBG_ASSERT(rWith.ISA(SfxVisibilityItem), "SfxVisibilityItem::Compare(): Bad type");
66 	return m_nValue.bVisible == static_cast< SfxVisibilityItem const * >(&rWith)->m_nValue.bVisible ?
67 		       0 : m_nValue.bVisible ? -1 : 1;
68 }
69 
70 //============================================================================
71 // virtual
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const72 SfxItemPresentation SfxVisibilityItem::GetPresentation(SfxItemPresentation,
73 												  SfxMapUnit, SfxMapUnit,
74 												  XubString & rText,
75                                                   const IntlWrapper *) const
76 {
77 	rText = GetValueTextByVal(m_nValue.bVisible);
78 	return SFX_ITEM_PRESENTATION_NAMELESS;
79 }
80 
81 
82 //============================================================================
83 // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const84 sal_Bool SfxVisibilityItem::QueryValue(com::sun::star::uno::Any& rVal,sal_uInt8) const
85 {
86 	rVal <<= m_nValue;
87 	return sal_True;
88 }
89 
90 //============================================================================
91 // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)92 sal_Bool SfxVisibilityItem::PutValue(const com::sun::star::uno::Any& rVal,sal_uInt8)
93 {
94 	if (rVal >>= m_nValue)
95 		return sal_True;
96 
97 	DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" );
98 	return sal_False;
99 }
100 
101 //============================================================================
102 // virtual
Create(SvStream & rStream,sal_uInt16) const103 SfxPoolItem * SfxVisibilityItem::Create(SvStream & rStream, sal_uInt16) const
104 {
105 	DBG_CHKTHIS(SfxVisibilityItem, 0);
106 	return new SfxVisibilityItem(Which(), rStream);
107 }
108 
109 //============================================================================
110 // virtual
Store(SvStream & rStream,sal_uInt16) const111 SvStream & SfxVisibilityItem::Store(SvStream & rStream, sal_uInt16) const
112 {
113 	DBG_CHKTHIS(SfxVisibilityItem, 0);
114 	rStream << m_nValue.bVisible;
115 	return rStream;
116 }
117 
118 //============================================================================
119 // virtual
Clone(SfxItemPool *) const120 SfxPoolItem * SfxVisibilityItem::Clone(SfxItemPool *) const
121 {
122 	DBG_CHKTHIS(SfxVisibilityItem, 0);
123 	return new SfxVisibilityItem(*this);
124 }
125 
126 //============================================================================
127 // virtual
GetValueCount() const128 sal_uInt16 SfxVisibilityItem::GetValueCount() const
129 {
130 	return 2;
131 }
132 
133 //============================================================================
134 // virtual
GetValueTextByVal(sal_Bool bTheValue) const135 UniString SfxVisibilityItem::GetValueTextByVal(sal_Bool bTheValue) const
136 {
137 	return
138 		bTheValue ?
139 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_True")) :
140 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_False"));
141 }
142