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_svx.hxx" 30 #include <tools/stream.hxx> 31 32 #include <svx/viewlayoutitem.hxx> 33 #include <com/sun/star/uno/Sequence.hxx> 34 #include <com/sun/star/beans/PropertyValue.hpp> 35 36 // ----------------------------------------------------------------------- 37 38 TYPEINIT1_FACTORY(SvxViewLayoutItem,SfxUInt16Item, new SvxViewLayoutItem); 39 40 #define VIEWLAYOUT_PARAM_COLUMNS "Columns" 41 #define VIEWLAYOUT_PARAM_BOOKMODE "BookMode" 42 #define VIEWLAYOUT_PARAMS 2 43 44 // ----------------------------------------------------------------------- 45 46 SvxViewLayoutItem::SvxViewLayoutItem 47 ( 48 sal_uInt16 nColumns, 49 bool bBookMode, 50 sal_uInt16 _nWhich 51 ) 52 : SfxUInt16Item( _nWhich, nColumns ), 53 mbBookMode( bBookMode ) 54 { 55 } 56 57 // ----------------------------------------------------------------------- 58 59 SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem& rOrig ) 60 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ), 61 mbBookMode( rOrig.IsBookMode() ) 62 { 63 } 64 65 // ----------------------------------------------------------------------- 66 67 SvxViewLayoutItem::~SvxViewLayoutItem() 68 { 69 } 70 71 // ----------------------------------------------------------------------- 72 73 SfxPoolItem* SvxViewLayoutItem::Clone( SfxItemPool * /*pPool*/ ) const 74 { 75 return new SvxViewLayoutItem( *this ); 76 } 77 78 // ----------------------------------------------------------------------- 79 80 SfxPoolItem* SvxViewLayoutItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const 81 { 82 /* sal_uInt16 nValue; 83 sal_uInt16 nValSet; 84 sal_Int8 nType; 85 rStrm >> nValue >> nValSet >> nType; 86 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() ); 87 pNew->SetValueSet( nValSet ); 88 return pNew;*/ 89 return 0; 90 } 91 92 // ----------------------------------------------------------------------- 93 94 SvStream& SvxViewLayoutItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const 95 { 96 /* rStrm << (sal_uInt16)GetValue() 97 << nValueSet 98 << (sal_Int8)eType;*/ 99 return rStrm; 100 } 101 102 // ----------------------------------------------------------------------- 103 104 int SvxViewLayoutItem::operator==( const SfxPoolItem& rAttr ) const 105 { 106 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 107 108 SvxViewLayoutItem& rItem = (SvxViewLayoutItem&)rAttr; 109 110 return ( GetValue() == rItem.GetValue() && 111 mbBookMode == rItem.IsBookMode() ); 112 } 113 114 sal_Bool SvxViewLayoutItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const 115 { 116 nMemberId &= ~CONVERT_TWIPS; 117 switch ( nMemberId ) 118 { 119 case 0 : 120 { 121 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( VIEWLAYOUT_PARAMS ); 122 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_COLUMNS )); 123 aSeq[0].Value <<= sal_Int32( GetValue() ); 124 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_BOOKMODE )); 125 aSeq[1].Value <<= sal_Bool( mbBookMode ); 126 rVal <<= aSeq; 127 } 128 break; 129 130 case MID_VIEWLAYOUT_COLUMNS : rVal <<= (sal_Int32) GetValue(); break; 131 case MID_VIEWLAYOUT_BOOKMODE: rVal <<= (sal_Bool) mbBookMode; break; 132 default: 133 DBG_ERROR("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!"); 134 return sal_False; 135 } 136 137 return sal_True; 138 } 139 140 sal_Bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) 141 { 142 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 143 nMemberId &= ~CONVERT_TWIPS; 144 switch ( nMemberId ) 145 { 146 case 0 : 147 { 148 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq; 149 if (( rVal >>= aSeq ) && ( aSeq.getLength() == VIEWLAYOUT_PARAMS )) 150 { 151 sal_Int32 nColumns( 0 ); 152 sal_Bool bBookMode = sal_False; 153 sal_Bool bAllConverted( sal_True ); 154 sal_Int16 nConvertedCount( 0 ); 155 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) 156 { 157 if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_COLUMNS )) 158 { 159 bAllConverted &= ( aSeq[i].Value >>= nColumns ); 160 ++nConvertedCount; 161 } 162 else if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_BOOKMODE )) 163 { 164 bAllConverted &= ( aSeq[i].Value >>= bBookMode ); 165 ++nConvertedCount; 166 } 167 } 168 169 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS ) 170 { 171 SetValue( (sal_uInt16)nColumns ); 172 mbBookMode = bBookMode; 173 return sal_True; 174 } 175 } 176 177 return sal_False; 178 } 179 180 case MID_VIEWLAYOUT_COLUMNS: 181 { 182 sal_Int32 nVal = 0; 183 if ( rVal >>= nVal ) 184 { 185 SetValue( (sal_uInt16)nVal ); 186 return sal_True; 187 } 188 else 189 return sal_False; 190 } 191 192 case MID_VIEWLAYOUT_BOOKMODE: 193 { 194 sal_Bool bBookMode = sal_False; 195 if ( rVal >>= bBookMode ) 196 { 197 mbBookMode = bBookMode; 198 return sal_True; 199 } 200 else 201 return sal_False; 202 } 203 204 default: 205 DBG_ERROR("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!"); 206 return sal_False; 207 } 208 209 return sal_True; 210 } 211 212