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 <svx/viewlayoutitem.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
22 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <osl/diagnose.h>
27 SfxPoolItem
* SvxViewLayoutItem::CreateDefault() { return new SvxViewLayoutItem
; }
29 #define VIEWLAYOUT_PARAM_COLUMNS "Columns"
30 #define VIEWLAYOUT_PARAM_BOOKMODE "BookMode"
31 #define VIEWLAYOUT_PARAMS 2
34 SvxViewLayoutItem::SvxViewLayoutItem
40 : SfxUInt16Item( _nWhich
, nColumns
),
41 mbBookMode( bBookMode
)
46 SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem
& rOrig
)
47 : SfxUInt16Item( rOrig
),
48 mbBookMode( rOrig
.IsBookMode() )
53 SvxViewLayoutItem::~SvxViewLayoutItem()
57 SvxViewLayoutItem
* SvxViewLayoutItem::Clone( SfxItemPool
* /*pPool*/ ) const
59 return new SvxViewLayoutItem( *this );
62 bool SvxViewLayoutItem::operator==( const SfxPoolItem
& rAttr
) const
64 assert(SfxPoolItem::operator==(rAttr
));
66 const SvxViewLayoutItem
& rItem
= static_cast<const SvxViewLayoutItem
&>(rAttr
);
68 return ( GetValue() == rItem
.GetValue() &&
69 mbBookMode
== rItem
.IsBookMode() );
72 bool SvxViewLayoutItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
74 nMemberId
&= ~CONVERT_TWIPS
;
79 css::uno::Sequence
< css::beans::PropertyValue
> aSeq( VIEWLAYOUT_PARAMS
);
80 aSeq
[0].Name
= VIEWLAYOUT_PARAM_COLUMNS
;
81 aSeq
[0].Value
<<= sal_Int32( GetValue() );
82 aSeq
[1].Name
= VIEWLAYOUT_PARAM_BOOKMODE
;
83 aSeq
[1].Value
<<= mbBookMode
;
88 case MID_VIEWLAYOUT_COLUMNS
: rVal
<<= static_cast<sal_Int32
>(GetValue()); break;
89 case MID_VIEWLAYOUT_BOOKMODE
: rVal
<<= mbBookMode
; break;
91 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
98 bool SvxViewLayoutItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
100 nMemberId
&= ~CONVERT_TWIPS
;
105 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
;
106 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == VIEWLAYOUT_PARAMS
))
108 sal_Int32
nColumns( 0 );
109 bool bBookMode
= false;
110 bool bAllConverted( true );
111 sal_Int16
nConvertedCount( 0 );
112 for ( const auto& rProp
: std::as_const(aSeq
) )
114 if ( rProp
.Name
== VIEWLAYOUT_PARAM_COLUMNS
)
116 bAllConverted
&= ( rProp
.Value
>>= nColumns
);
119 else if ( rProp
.Name
== VIEWLAYOUT_PARAM_BOOKMODE
)
121 bAllConverted
&= ( rProp
.Value
>>= bBookMode
);
126 if ( bAllConverted
&& nConvertedCount
== VIEWLAYOUT_PARAMS
)
128 SetValue( static_cast<sal_uInt16
>(nColumns
) );
129 mbBookMode
= bBookMode
;
137 case MID_VIEWLAYOUT_COLUMNS
:
142 SetValue( static_cast<sal_uInt16
>(nVal
) );
149 case MID_VIEWLAYOUT_BOOKMODE
:
151 bool bBookMode
= false;
152 if ( rVal
>>= bBookMode
)
154 mbBookMode
= bBookMode
;
162 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */