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