1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <tools/stream.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <svx/viewlayoutitem.hxx>
29cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
30cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // -----------------------------------------------------------------------
33cdf0e10cSrcweir 
34cdf0e10cSrcweir TYPEINIT1_FACTORY(SvxViewLayoutItem,SfxUInt16Item, new SvxViewLayoutItem);
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define VIEWLAYOUT_PARAM_COLUMNS    "Columns"
37cdf0e10cSrcweir #define VIEWLAYOUT_PARAM_BOOKMODE   "BookMode"
38cdf0e10cSrcweir #define VIEWLAYOUT_PARAMS           2
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // -----------------------------------------------------------------------
41cdf0e10cSrcweir 
SvxViewLayoutItem(sal_uInt16 nColumns,bool bBookMode,sal_uInt16 _nWhich)42cdf0e10cSrcweir SvxViewLayoutItem::SvxViewLayoutItem
43cdf0e10cSrcweir (
44cdf0e10cSrcweir     sal_uInt16      nColumns,
45cdf0e10cSrcweir     bool        bBookMode,
46cdf0e10cSrcweir     sal_uInt16  _nWhich
47cdf0e10cSrcweir )
48cdf0e10cSrcweir :   SfxUInt16Item( _nWhich, nColumns ),
49cdf0e10cSrcweir     mbBookMode( bBookMode )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // -----------------------------------------------------------------------
54cdf0e10cSrcweir 
SvxViewLayoutItem(const SvxViewLayoutItem & rOrig)55cdf0e10cSrcweir SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem& rOrig )
56cdf0e10cSrcweir :	SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
57cdf0e10cSrcweir     mbBookMode( rOrig.IsBookMode() )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // -----------------------------------------------------------------------
62cdf0e10cSrcweir 
~SvxViewLayoutItem()63cdf0e10cSrcweir SvxViewLayoutItem::~SvxViewLayoutItem()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------------
68cdf0e10cSrcweir 
Clone(SfxItemPool *) const69cdf0e10cSrcweir SfxPoolItem* SvxViewLayoutItem::Clone( SfxItemPool * /*pPool*/ ) const
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     return new SvxViewLayoutItem( *this );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // -----------------------------------------------------------------------
75cdf0e10cSrcweir 
Create(SvStream &,sal_uInt16) const76cdf0e10cSrcweir SfxPoolItem* SvxViewLayoutItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
77cdf0e10cSrcweir {
78cdf0e10cSrcweir /*   sal_uInt16 nValue;
79cdf0e10cSrcweir 	sal_uInt16 nValSet;
80cdf0e10cSrcweir 	sal_Int8 nType;
81cdf0e10cSrcweir 	rStrm >> nValue >> nValSet >> nType;
82cdf0e10cSrcweir 	SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
83cdf0e10cSrcweir     pNew->SetValueSet( nValSet );
84cdf0e10cSrcweir     return pNew;*/
85cdf0e10cSrcweir     return 0;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // -----------------------------------------------------------------------
89cdf0e10cSrcweir 
Store(SvStream & rStrm,sal_uInt16) const90cdf0e10cSrcweir SvStream& SvxViewLayoutItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir /*   rStrm << (sal_uInt16)GetValue()
93cdf0e10cSrcweir 		  << nValueSet
94cdf0e10cSrcweir           << (sal_Int8)eType;*/
95cdf0e10cSrcweir 	return rStrm;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // -----------------------------------------------------------------------
99cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const100cdf0e10cSrcweir int SvxViewLayoutItem::operator==( const SfxPoolItem& rAttr ) const
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     SvxViewLayoutItem& rItem = (SvxViewLayoutItem&)rAttr;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	return ( GetValue() == rItem.GetValue() 	&&
107cdf0e10cSrcweir              mbBookMode == rItem.IsBookMode() );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId) const110cdf0e10cSrcweir sal_Bool SvxViewLayoutItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
113cdf0e10cSrcweir     switch ( nMemberId )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         case 0 :
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( VIEWLAYOUT_PARAMS );
118cdf0e10cSrcweir             aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_COLUMNS ));
119cdf0e10cSrcweir             aSeq[0].Value <<= sal_Int32( GetValue() );
120cdf0e10cSrcweir             aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VIEWLAYOUT_PARAM_BOOKMODE ));
121cdf0e10cSrcweir             aSeq[1].Value <<= sal_Bool( mbBookMode );
122cdf0e10cSrcweir             rVal <<= aSeq;
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir         break;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         case MID_VIEWLAYOUT_COLUMNS : rVal <<= (sal_Int32) GetValue(); break;
127cdf0e10cSrcweir         case MID_VIEWLAYOUT_BOOKMODE: rVal <<= (sal_Bool) mbBookMode; break;
128cdf0e10cSrcweir         default:
129cdf0e10cSrcweir             DBG_ERROR("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
130cdf0e10cSrcweir             return sal_False;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     return sal_True;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId)136cdf0e10cSrcweir sal_Bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir //  sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
139cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
140cdf0e10cSrcweir     switch ( nMemberId )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         case 0 :
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
145cdf0e10cSrcweir             if (( rVal >>= aSeq ) && ( aSeq.getLength() == VIEWLAYOUT_PARAMS ))
146cdf0e10cSrcweir             {
147cdf0e10cSrcweir                 sal_Int32 nColumns( 0 );
148cdf0e10cSrcweir                 sal_Bool  bBookMode = sal_False;
149cdf0e10cSrcweir                 sal_Bool  bAllConverted( sal_True );
150cdf0e10cSrcweir                 sal_Int16 nConvertedCount( 0 );
151cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
152cdf0e10cSrcweir                 {
153cdf0e10cSrcweir                     if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_COLUMNS ))
154cdf0e10cSrcweir                     {
155cdf0e10cSrcweir                         bAllConverted &= ( aSeq[i].Value >>= nColumns );
156cdf0e10cSrcweir                         ++nConvertedCount;
157cdf0e10cSrcweir                     }
158cdf0e10cSrcweir                     else if ( aSeq[i].Name.equalsAscii( VIEWLAYOUT_PARAM_BOOKMODE ))
159cdf0e10cSrcweir                     {
160cdf0e10cSrcweir                         bAllConverted &= ( aSeq[i].Value >>= bBookMode );
161cdf0e10cSrcweir                         ++nConvertedCount;
162cdf0e10cSrcweir                     }
163cdf0e10cSrcweir                 }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir                 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
166cdf0e10cSrcweir                 {
167cdf0e10cSrcweir                     SetValue( (sal_uInt16)nColumns );
168cdf0e10cSrcweir                     mbBookMode = bBookMode;
169cdf0e10cSrcweir                     return sal_True;
170cdf0e10cSrcweir                 }
171cdf0e10cSrcweir             }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir             return sal_False;
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         case MID_VIEWLAYOUT_COLUMNS:
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir             sal_Int32 nVal = 0;
179cdf0e10cSrcweir             if ( rVal >>= nVal )
180cdf0e10cSrcweir             {
181cdf0e10cSrcweir                 SetValue( (sal_uInt16)nVal );
182cdf0e10cSrcweir                 return sal_True;
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir             else
185cdf0e10cSrcweir                 return sal_False;
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         case MID_VIEWLAYOUT_BOOKMODE:
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             sal_Bool bBookMode = sal_False;
191cdf0e10cSrcweir             if ( rVal >>= bBookMode )
192cdf0e10cSrcweir             {
193cdf0e10cSrcweir                  mbBookMode = bBookMode;
194cdf0e10cSrcweir                 return sal_True;
195cdf0e10cSrcweir             }
196cdf0e10cSrcweir             else
197cdf0e10cSrcweir                 return sal_False;
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         default:
201cdf0e10cSrcweir             DBG_ERROR("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
202cdf0e10cSrcweir             return sal_False;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     return sal_True;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208