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