bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / viewlayoutitem.cxx
blob4e303a57802fec7d0daa4799a6ac9e2ec4f8a56c
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 <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
39 sal_uInt16 nColumns,
40 bool bBookMode,
41 sal_uInt16 _nWhich
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
73 return 0;
78 SvStream& SvxViewLayoutItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
80 return rStrm;
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;
98 switch ( nMemberId )
100 case 0 :
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;
107 rVal <<= aSeq;
109 break;
111 case MID_VIEWLAYOUT_COLUMNS : rVal <<= (sal_Int32) GetValue(); break;
112 case MID_VIEWLAYOUT_BOOKMODE: rVal <<= mbBookMode; break;
113 default:
114 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
115 return false;
118 return true;
121 bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
123 nMemberId &= ~CONVERT_TWIPS;
124 switch ( nMemberId )
126 case 0 :
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 );
140 ++nConvertedCount;
142 else if ( aSeq[i].Name == VIEWLAYOUT_PARAM_BOOKMODE )
144 bAllConverted &= ( aSeq[i].Value >>= bBookMode );
145 ++nConvertedCount;
149 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
151 SetValue( (sal_uInt16)nColumns );
152 mbBookMode = bBookMode;
153 return true;
157 return false;
160 case MID_VIEWLAYOUT_COLUMNS:
162 sal_Int32 nVal = 0;
163 if ( rVal >>= nVal )
165 SetValue( (sal_uInt16)nVal );
166 return true;
168 else
169 return false;
172 case MID_VIEWLAYOUT_BOOKMODE:
174 bool bBookMode = false;
175 if ( rVal >>= bBookMode )
177 mbBookMode = bBookMode;
178 return true;
180 else
181 return false;
184 default:
185 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
186 return false;
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */