1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewlayoutitem.cxx,v $
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
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
88 rStrm >> nValue >> nValSet >> nType;
89 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
90 pNew->SetValueSet( nValSet );
95 // -----------------------------------------------------------------------
97 SvStream
& SvxViewLayoutItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
99 /* rStrm << (sal_uInt16)GetValue()
101 << (sal_Int8)eType;*/
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
;
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
);
133 case MID_VIEWLAYOUT_COLUMNS
: rVal
<<= (sal_Int32
) GetValue(); break;
134 case MID_VIEWLAYOUT_BOOKMODE
: rVal
<<= (sal_Bool
) mbBookMode
; break;
136 DBG_ERROR("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
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
;
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
);
165 else if ( aSeq
[i
].Name
.equalsAscii( VIEWLAYOUT_PARAM_BOOKMODE
))
167 bAllConverted
&= ( aSeq
[i
].Value
>>= bBookMode
);
172 if ( bAllConverted
&& nConvertedCount
== VIEWLAYOUT_PARAMS
)
174 SetValue( (UINT16
)nColumns
);
175 mbBookMode
= bBookMode
;
183 case MID_VIEWLAYOUT_COLUMNS
:
188 SetValue( (UINT16
)nVal
);
195 case MID_VIEWLAYOUT_BOOKMODE
:
197 sal_Bool bBookMode
= sal_False
;
198 if ( rVal
>>= bBookMode
)
200 mbBookMode
= bBookMode
;
208 DBG_ERROR("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");