LibreOffice Module svx (master)  1
zoomslideritem.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <osl/diagnose.h>
21 
22 #include <svx/zoomslideritem.hxx>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 
25 
27 
28 #define ZOOMSLIDER_PARAM_CURRENTZOOM "Columns"
29 #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
30 #define ZOOMSLIDER_PARAM_MINZOOM "MinValue"
31 #define ZOOMSLIDER_PARAM_MAXZOOM "MaxValue"
32 #define ZOOMSLIDER_PARAMS 4
33 
34 
35 SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich )
36 : SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
37 {
38 }
39 
41 {
42  return new SvxZoomSliderItem( *this );
43 }
44 
45 bool SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
46 {
47  assert(SfxPoolItem::operator==(rAttr));
48 
49  const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
50 
51  return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
52  mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
53 }
54 
55 bool SvxZoomSliderItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
56 {
57  nMemberId &= ~CONVERT_TWIPS;
58  switch ( nMemberId )
59  {
60  case 0 :
61  {
62  css::uno::Sequence< css::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
63  aSeq[0].Name = ZOOMSLIDER_PARAM_CURRENTZOOM;
64  aSeq[0].Value <<= sal_Int32( GetValue() );
65  aSeq[1].Name = ZOOMSLIDER_PARAM_SNAPPINGPOINTS;
66  aSeq[1].Value <<= maValues;
67  aSeq[2].Name = ZOOMSLIDER_PARAM_MINZOOM;
68  aSeq[2].Value <<= mnMinZoom;
69  aSeq[3].Name = ZOOMSLIDER_PARAM_MAXZOOM;
70  aSeq[3].Value <<= mnMaxZoom;
71  rVal <<= aSeq;
72  }
73  break;
74 
75  case MID_ZOOMSLIDER_CURRENTZOOM :
76  {
77  rVal <<= static_cast<sal_Int32>(GetValue());
78  }
79  break;
80  case MID_ZOOMSLIDER_SNAPPINGPOINTS:
81  {
82  rVal <<= maValues;
83  }
84  break;
85  case MID_ZOOMSLIDER_MINZOOM:
86  {
87  rVal <<= mnMinZoom;
88  }
89  break;
90  case MID_ZOOMSLIDER_MAXZOOM:
91  {
92  rVal <<= mnMaxZoom;
93  }
94  break;
95  default:
96  OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
97  return false;
98  }
99 
100  return true;
101 }
102 
103 bool SvxZoomSliderItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
104 {
105  nMemberId &= ~CONVERT_TWIPS;
106  switch ( nMemberId )
107  {
108  case 0 :
109  {
110  css::uno::Sequence< css::beans::PropertyValue > aSeq;
111  if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
112  {
113  sal_Int32 nCurrentZoom( 0 );
114  css::uno::Sequence < sal_Int32 > aValues;
115 
116  bool bAllConverted( true );
117  sal_Int16 nConvertedCount( 0 );
118  sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
119 
120  for ( const auto& rProp : std::as_const(aSeq) )
121  {
122  if ( rProp.Name == ZOOMSLIDER_PARAM_CURRENTZOOM )
123  {
124  bAllConverted &= ( rProp.Value >>= nCurrentZoom );
125  ++nConvertedCount;
126  }
127  else if ( rProp.Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
128  {
129  bAllConverted &= ( rProp.Value >>= aValues );
130  ++nConvertedCount;
131  }
132  else if( rProp.Name == ZOOMSLIDER_PARAM_MINZOOM )
133  {
134  bAllConverted &= ( rProp.Value >>= nMinZoom );
135  ++nConvertedCount;
136  }
137  else if( rProp.Name == ZOOMSLIDER_PARAM_MAXZOOM )
138  {
139  bAllConverted &= ( rProp.Value >>= nMaxZoom );
140  ++nConvertedCount;
141  }
142  }
143 
144  if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
145  {
146  SetValue( static_cast<sal_uInt16>(nCurrentZoom) );
147  maValues = aValues;
148  mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
149  mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
150 
151  return true;
152  }
153  }
154 
155  return false;
156  }
157 
158  case MID_ZOOMSLIDER_CURRENTZOOM:
159  {
160  sal_Int32 nVal = 0;
161  if ( rVal >>= nVal )
162  {
163  SetValue( static_cast<sal_uInt16>(nVal) );
164  return true;
165  }
166  else
167  return false;
168  }
169 
170  case MID_ZOOMSLIDER_SNAPPINGPOINTS:
171  {
172  css::uno::Sequence < sal_Int32 > aValues;
173  if ( rVal >>= aValues )
174  {
175  maValues = aValues;
176  return true;
177  }
178  else
179  return false;
180  }
181  case MID_ZOOMSLIDER_MINZOOM:
182  {
183  sal_Int32 nVal = 0;
184  if( rVal >>= nVal )
185  {
186  mnMinZoom = static_cast<sal_uInt16>(nVal);
187  return true;
188  }
189  else
190  return false;
191  }
192  case MID_ZOOMSLIDER_MAXZOOM:
193  {
194  sal_Int32 nVal = 0;
195  if( rVal >>= nVal )
196  {
197  mnMaxZoom = static_cast<sal_uInt16>(nVal);
198  return true;
199  }
200  else
201  return false;
202  }
203  default:
204  OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
205  return false;
206  }
207 }
208 
210 {
211  const sal_Int32 nValues = maValues.getLength();
212  maValues.realloc( nValues + 1 );
213  sal_Int32* pValues = maValues.getArray();
214  pValues[ nValues ] = nNew;
215 }
216 
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
#define ZOOMSLIDER_PARAM_MINZOOM
sal_uInt16 GetValue() const
#define ZOOMSLIDER_PARAM_SNAPPINGPOINTS
void SetValue(sal_uInt16 nTheValue)
void AddSnappingPoint(sal_Int32 nNew)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
css::uno::Sequence< sal_Int32 > maValues
const PropertyValue * pValues
SvxZoomSliderItem(sal_uInt16 nCurrentZoom=100, sal_uInt16 nMinZoom=20, sal_uInt16 nMaxZoom=600, sal_uInt16 nWhich=SID_ATTR_ZOOMSLIDER)
unsigned char sal_uInt8
#define ZOOMSLIDER_PARAM_MAXZOOM
#define ZOOMSLIDER_PARAM_CURRENTZOOM
virtual SvxZoomSliderItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool operator==(const SfxPoolItem &) const override
Sequence< sal_Int8 > aSeq
static SfxPoolItem * CreateDefault()
#define ZOOMSLIDER_PARAMS
#define CONVERT_TWIPS