Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / viewlayoutitem.cxx
blobd923133a19bcc682bb1c02a157e5eb9b8704e68f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <cassert>
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
39 sal_uInt16 nColumns,
40 bool bBookMode,
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;
78 switch ( nMemberId )
80 case 0 :
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);
87 rVal <<= aSeq;
89 break;
91 case MID_VIEWLAYOUT_COLUMNS : rVal <<= static_cast<sal_Int32>(GetValue()); break;
92 case MID_VIEWLAYOUT_BOOKMODE: rVal <<= mbBookMode; break;
93 default:
94 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
95 return false;
98 return true;
101 bool SvxViewLayoutItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
103 nMemberId &= ~CONVERT_TWIPS;
104 switch ( nMemberId )
106 case 0 :
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 );
120 ++nConvertedCount;
122 else if ( rProp.Name == VIEWLAYOUT_PARAM_BOOKMODE )
124 bAllConverted &= ( rProp.Value >>= bBookMode );
125 ++nConvertedCount;
129 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
131 SetValue( static_cast<sal_uInt16>(nColumns) );
132 mbBookMode = bBookMode;
133 return true;
137 return false;
140 case MID_VIEWLAYOUT_COLUMNS:
142 sal_Int32 nVal = 0;
143 if ( rVal >>= nVal )
145 SetValue( static_cast<sal_uInt16>(nVal) );
146 return true;
148 else
149 return false;
152 case MID_VIEWLAYOUT_BOOKMODE:
154 bool bBookMode = false;
155 if ( rVal >>= bBookMode )
157 mbBookMode = bBookMode;
158 return true;
160 else
161 return false;
164 default:
165 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
166 return false;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */