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 <comphelper/propertyvalue.hxx>
25 #include <osl/diagnose.h>
30 SfxPoolItem
* SvxViewLayoutItem::CreateDefault() { return new SvxViewLayoutItem
; }
32 constexpr OUStringLiteral VIEWLAYOUT_PARAM_COLUMNS
= u
"Columns";
33 constexpr OUStringLiteral VIEWLAYOUT_PARAM_BOOKMODE
= u
"BookMode";
34 #define VIEWLAYOUT_PARAMS 2
37 SvxViewLayoutItem::SvxViewLayoutItem
41 TypedWhichId
<SvxViewLayoutItem
> _nWhich
43 : SfxUInt16Item( _nWhich
, nColumns
),
44 mbBookMode( bBookMode
)
49 SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem
& rOrig
)
50 : SfxUInt16Item( rOrig
),
51 mbBookMode( rOrig
.IsBookMode() )
56 SvxViewLayoutItem::~SvxViewLayoutItem()
60 SvxViewLayoutItem
* SvxViewLayoutItem::Clone( SfxItemPool
* /*pPool*/ ) const
62 return new SvxViewLayoutItem( *this );
65 bool SvxViewLayoutItem::operator==( const SfxPoolItem
& rAttr
) const
67 assert(SfxPoolItem::operator==(rAttr
));
69 const SvxViewLayoutItem
& rItem
= static_cast<const SvxViewLayoutItem
&>(rAttr
);
71 return ( GetValue() == rItem
.GetValue() &&
72 mbBookMode
== rItem
.IsBookMode() );
75 bool SvxViewLayoutItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
77 nMemberId
&= ~CONVERT_TWIPS
;
82 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
{
83 comphelper::makePropertyValue(VIEWLAYOUT_PARAM_COLUMNS
, sal_Int32( GetValue() )),
84 comphelper::makePropertyValue(VIEWLAYOUT_PARAM_BOOKMODE
, mbBookMode
)
86 assert(aSeq
.getLength() == VIEWLAYOUT_PARAMS
);
91 case MID_VIEWLAYOUT_COLUMNS
: rVal
<<= static_cast<sal_Int32
>(GetValue()); break;
92 case MID_VIEWLAYOUT_BOOKMODE
: rVal
<<= mbBookMode
; break;
94 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
101 bool SvxViewLayoutItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
103 nMemberId
&= ~CONVERT_TWIPS
;
108 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
;
109 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == VIEWLAYOUT_PARAMS
))
111 sal_Int32
nColumns( 0 );
112 bool bBookMode
= false;
113 bool bAllConverted( true );
114 sal_Int16
nConvertedCount( 0 );
115 for ( const auto& rProp
: std::as_const(aSeq
) )
117 if ( rProp
.Name
== VIEWLAYOUT_PARAM_COLUMNS
)
119 bAllConverted
&= ( rProp
.Value
>>= nColumns
);
122 else if ( rProp
.Name
== VIEWLAYOUT_PARAM_BOOKMODE
)
124 bAllConverted
&= ( rProp
.Value
>>= bBookMode
);
129 if ( bAllConverted
&& nConvertedCount
== VIEWLAYOUT_PARAMS
)
131 SetValue( static_cast<sal_uInt16
>(nColumns
) );
132 mbBookMode
= bBookMode
;
140 case MID_VIEWLAYOUT_COLUMNS
:
145 SetValue( static_cast<sal_uInt16
>(nVal
) );
152 case MID_VIEWLAYOUT_BOOKMODE
:
154 bool bBookMode
= false;
155 if ( rVal
>>= bBookMode
)
157 mbBookMode
= bBookMode
;
165 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */