1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/stream.hxx>
22 #include <svx/viewlayoutitem.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <osl/diagnose.h>
29 TYPEINIT1_FACTORY(SvxViewLayoutItem
,SfxUInt16Item
, new SvxViewLayoutItem
);
31 #define VIEWLAYOUT_PARAM_COLUMNS "Columns"
32 #define VIEWLAYOUT_PARAM_BOOKMODE "BookMode"
33 #define VIEWLAYOUT_PARAMS 2
37 SvxViewLayoutItem::SvxViewLayoutItem
43 : SfxUInt16Item( _nWhich
, nColumns
),
44 mbBookMode( bBookMode
)
50 SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem
& rOrig
)
51 : SfxUInt16Item( rOrig
.Which(), rOrig
.GetValue() ),
52 mbBookMode( rOrig
.IsBookMode() )
58 SvxViewLayoutItem::~SvxViewLayoutItem()
64 SfxPoolItem
* SvxViewLayoutItem::Clone( SfxItemPool
* /*pPool*/ ) const
66 return new SvxViewLayoutItem( *this );
71 SfxPoolItem
* SvxViewLayoutItem::Create( SvStream
& /*rStrm*/, sal_uInt16
/*nVersion*/ ) const
78 SvStream
& SvxViewLayoutItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
85 bool SvxViewLayoutItem::operator==( const SfxPoolItem
& rAttr
) const
87 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
89 const SvxViewLayoutItem
& rItem
= static_cast<const SvxViewLayoutItem
&>(rAttr
);
91 return ( GetValue() == rItem
.GetValue() &&
92 mbBookMode
== rItem
.IsBookMode() );
95 bool SvxViewLayoutItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
97 nMemberId
&= ~CONVERT_TWIPS
;
102 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq( VIEWLAYOUT_PARAMS
);
103 aSeq
[0].Name
= VIEWLAYOUT_PARAM_COLUMNS
;
104 aSeq
[0].Value
<<= sal_Int32( GetValue() );
105 aSeq
[1].Name
= VIEWLAYOUT_PARAM_BOOKMODE
;
106 aSeq
[1].Value
<<= mbBookMode
;
111 case MID_VIEWLAYOUT_COLUMNS
: rVal
<<= (sal_Int32
) GetValue(); break;
112 case MID_VIEWLAYOUT_BOOKMODE
: rVal
<<= mbBookMode
; break;
114 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
121 bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
123 nMemberId
&= ~CONVERT_TWIPS
;
128 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq
;
129 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == VIEWLAYOUT_PARAMS
))
131 sal_Int32
nColumns( 0 );
132 bool bBookMode
= false;
133 bool bAllConverted( true );
134 sal_Int16
nConvertedCount( 0 );
135 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
137 if ( aSeq
[i
].Name
== VIEWLAYOUT_PARAM_COLUMNS
)
139 bAllConverted
&= ( aSeq
[i
].Value
>>= nColumns
);
142 else if ( aSeq
[i
].Name
== VIEWLAYOUT_PARAM_BOOKMODE
)
144 bAllConverted
&= ( aSeq
[i
].Value
>>= bBookMode
);
149 if ( bAllConverted
&& nConvertedCount
== VIEWLAYOUT_PARAMS
)
151 SetValue( (sal_uInt16
)nColumns
);
152 mbBookMode
= bBookMode
;
160 case MID_VIEWLAYOUT_COLUMNS
:
165 SetValue( (sal_uInt16
)nVal
);
172 case MID_VIEWLAYOUT_BOOKMODE
:
174 bool bBookMode
= false;
175 if ( rVal
>>= bBookMode
)
177 mbBookMode
= bBookMode
;
185 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */