Update ooo320-m1
[ooovba.git] / svx / source / items / viewlayoutitem.cxx
blobe1e92d05ffd36c497542cda0e432315c08ec7983
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewlayoutitem.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/stream.hxx>
35 #include <svx/viewlayoutitem.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/beans/PropertyValue.hpp>
39 // -----------------------------------------------------------------------
41 TYPEINIT1_FACTORY(SvxViewLayoutItem,SfxUInt16Item, new SvxViewLayoutItem);
43 #define VIEWLAYOUT_PARAM_COLUMNS "Columns"
44 #define VIEWLAYOUT_PARAM_BOOKMODE "BookMode"
45 #define VIEWLAYOUT_PARAMS 2
47 // -----------------------------------------------------------------------
49 SvxViewLayoutItem::SvxViewLayoutItem
51 USHORT nColumns,
52 bool bBookMode,
53 sal_uInt16 _nWhich
55 : SfxUInt16Item( _nWhich, nColumns ),
56 mbBookMode( bBookMode )
60 // -----------------------------------------------------------------------
62 SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem& rOrig )
63 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
64 mbBookMode( rOrig.IsBookMode() )
68 // -----------------------------------------------------------------------
70 SvxViewLayoutItem::~SvxViewLayoutItem()
74 // -----------------------------------------------------------------------
76 SfxPoolItem* SvxViewLayoutItem::Clone( SfxItemPool * /*pPool*/ ) const
78 return new SvxViewLayoutItem( *this );
81 // -----------------------------------------------------------------------
83 SfxPoolItem* SvxViewLayoutItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
85 /* sal_uInt16 nValue;
86 sal_uInt16 nValSet;
87 sal_Int8 nType;
88 rStrm >> nValue >> nValSet >> nType;
89 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
90 pNew->SetValueSet( nValSet );
91 return pNew;*/
92 return 0;
95 // -----------------------------------------------------------------------
97 SvStream& SvxViewLayoutItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
99 /* rStrm << (sal_uInt16)GetValue()
100 << nValueSet
101 << (sal_Int8)eType;*/
102 return rStrm;
105 // -----------------------------------------------------------------------
107 int SvxViewLayoutItem::operator==( const SfxPoolItem& rAttr ) const
109 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
111 SvxViewLayoutItem& rItem = (SvxViewLayoutItem&)rAttr;
113 return ( GetValue() == rItem.GetValue() &&
114 mbBookMode == rItem.IsBookMode() );
117 sal_Bool SvxViewLayoutItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
119 nMemberId &= ~CONVERT_TWIPS;
120 switch ( nMemberId )
122 case 0 :
124 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( VIEWLAYOUT_PARAMS );
125 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_COLUMNS ));
126 aSeq[0].Value <<= sal_Int32( GetValue() );
127 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_BOOKMODE ));
128 aSeq[1].Value <<= sal_Bool( mbBookMode );
129 rVal <<= aSeq;
131 break;
133 case MID_VIEWLAYOUT_COLUMNS : rVal <<= (sal_Int32) GetValue(); break;
134 case MID_VIEWLAYOUT_BOOKMODE: rVal <<= (sal_Bool) mbBookMode; break;
135 default:
136 DBG_ERROR("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
137 return sal_False;
140 return sal_True;
143 sal_Bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
145 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
146 nMemberId &= ~CONVERT_TWIPS;
147 switch ( nMemberId )
149 case 0 :
151 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
152 if (( rVal >>= aSeq ) && ( aSeq.getLength() == VIEWLAYOUT_PARAMS ))
154 sal_Int32 nColumns( 0 );
155 sal_Bool bBookMode = sal_False;
156 sal_Bool bAllConverted( sal_True );
157 sal_Int16 nConvertedCount( 0 );
158 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
160 if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_COLUMNS ))
162 bAllConverted &= ( aSeq[i].Value >>= nColumns );
163 ++nConvertedCount;
165 else if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_BOOKMODE ))
167 bAllConverted &= ( aSeq[i].Value >>= bBookMode );
168 ++nConvertedCount;
172 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
174 SetValue( (UINT16)nColumns );
175 mbBookMode = bBookMode;
176 return sal_True;
180 return sal_False;
183 case MID_VIEWLAYOUT_COLUMNS:
185 sal_Int32 nVal = 0;
186 if ( rVal >>= nVal )
188 SetValue( (UINT16)nVal );
189 return sal_True;
191 else
192 return sal_False;
195 case MID_VIEWLAYOUT_BOOKMODE:
197 sal_Bool bBookMode = sal_False;
198 if ( rVal >>= bBookMode )
200 mbBookMode = bBookMode;
201 return sal_True;
203 else
204 return sal_False;
207 default:
208 DBG_ERROR("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
209 return sal_False;
212 return sal_True;