Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/items/zoomslideritem.cxx
Line
Count
Source
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 <sal/config.h>
21
22
#include <comphelper/propertyvalue.hxx>
23
#include <osl/diagnose.h>
24
25
#include <svx/zoomslideritem.hxx>
26
#include <com/sun/star/beans/PropertyValue.hpp>
27
28
29
0
SfxPoolItem* SvxZoomSliderItem::CreateDefault() { return new SvxZoomSliderItem; }
30
31
constexpr OUString ZOOMSLIDER_PARAM_CURRENTZOOM = u"Columns"_ustr;
32
constexpr OUString ZOOMSLIDER_PARAM_SNAPPINGPOINTS = u"SnappingPoints"_ustr;
33
constexpr OUString ZOOMSLIDER_PARAM_MINZOOM = u"MinValue"_ustr;
34
constexpr OUString ZOOMSLIDER_PARAM_MAXZOOM = u"MaxValue"_ustr;
35
0
#define ZOOMSLIDER_PARAMS           4
36
37
38
SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, TypedWhichId<SvxZoomSliderItem> _nWhich )
39
0
:   SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
40
0
{
41
0
}
42
43
SvxZoomSliderItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
44
0
{
45
0
    return new SvxZoomSliderItem( *this );
46
0
}
47
48
bool SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
49
0
{
50
0
    assert(SfxPoolItem::operator==(rAttr));
51
52
0
    const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
53
54
0
    return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
55
0
             mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
56
0
}
57
58
bool SvxZoomSliderItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
59
0
{
60
0
    nMemberId &= ~CONVERT_TWIPS;
61
0
    switch ( nMemberId )
62
0
    {
63
0
        case 0 :
64
0
            {
65
0
                css::uno::Sequence< css::beans::PropertyValue > aSeq{
66
0
                    comphelper::makePropertyValue(ZOOMSLIDER_PARAM_CURRENTZOOM, sal_Int32( GetValue() )),
67
0
                    comphelper::makePropertyValue(ZOOMSLIDER_PARAM_SNAPPINGPOINTS, maValues),
68
0
                    comphelper::makePropertyValue(ZOOMSLIDER_PARAM_MINZOOM, mnMinZoom),
69
0
                    comphelper::makePropertyValue(ZOOMSLIDER_PARAM_MAXZOOM, mnMaxZoom)
70
0
                };
71
0
                assert(aSeq.getLength() == ZOOMSLIDER_PARAMS);
72
0
                rVal <<= aSeq;
73
0
            }
74
0
            break;
75
76
0
        case MID_ZOOMSLIDER_CURRENTZOOM :
77
0
            {
78
0
                rVal <<= static_cast<sal_Int32>(GetValue());
79
0
            }
80
0
            break;
81
0
        case MID_ZOOMSLIDER_SNAPPINGPOINTS:
82
0
            {
83
0
                 rVal <<= maValues;
84
0
            }
85
0
            break;
86
0
        case MID_ZOOMSLIDER_MINZOOM:
87
0
            {
88
0
                rVal <<= mnMinZoom;
89
0
            }
90
0
            break;
91
0
        case MID_ZOOMSLIDER_MAXZOOM:
92
0
            {
93
0
                rVal <<= mnMaxZoom;
94
0
            }
95
0
            break;
96
0
        default:
97
0
            OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
98
0
            return false;
99
0
    }
100
101
0
    return true;
102
0
}
103
104
bool SvxZoomSliderItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
105
0
{
106
0
    nMemberId &= ~CONVERT_TWIPS;
107
0
    switch ( nMemberId )
108
0
    {
109
0
        case 0 :
110
0
            {
111
0
                css::uno::Sequence< css::beans::PropertyValue > aSeq;
112
0
                if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
113
0
                {
114
0
                    sal_Int32 nCurrentZoom( 0 );
115
0
                    css::uno::Sequence < sal_Int32 > aValues;
116
117
0
                    bool bAllConverted( true );
118
0
                    sal_Int16 nConvertedCount( 0 );
119
0
                    sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
120
121
0
                    for (const auto& rProp : aSeq)
122
0
                    {
123
0
                        if ( rProp.Name == ZOOMSLIDER_PARAM_CURRENTZOOM )
124
0
                        {
125
0
                            bAllConverted &= ( rProp.Value >>= nCurrentZoom );
126
0
                            ++nConvertedCount;
127
0
                        }
128
0
                        else if ( rProp.Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
129
0
                        {
130
0
                            bAllConverted &= ( rProp.Value >>= aValues );
131
0
                            ++nConvertedCount;
132
0
                        }
133
0
                        else if( rProp.Name == ZOOMSLIDER_PARAM_MINZOOM )
134
0
                        {
135
0
                            bAllConverted &= ( rProp.Value >>= nMinZoom );
136
0
                            ++nConvertedCount;
137
0
                        }
138
0
                        else if( rProp.Name == ZOOMSLIDER_PARAM_MAXZOOM )
139
0
                        {
140
0
                            bAllConverted &= ( rProp.Value >>= nMaxZoom );
141
0
                            ++nConvertedCount;
142
0
                        }
143
0
                    }
144
145
0
                    if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
146
0
                    {
147
0
                        SetValue( static_cast<sal_uInt16>(nCurrentZoom) );
148
0
                        maValues = std::move(aValues);
149
0
                        mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
150
0
                        mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
151
152
0
                        return true;
153
0
                    }
154
0
                }
155
156
0
                return false;
157
0
            }
158
159
0
        case MID_ZOOMSLIDER_CURRENTZOOM:
160
0
            {
161
0
                sal_Int32 nVal = 0;
162
0
                if ( rVal >>= nVal )
163
0
                {
164
0
                    SetValue( static_cast<sal_uInt16>(nVal) );
165
0
                    return true;
166
0
                }
167
0
                else
168
0
                    return false;
169
0
            }
170
171
0
        case MID_ZOOMSLIDER_SNAPPINGPOINTS:
172
0
            {
173
0
                css::uno::Sequence < sal_Int32 > aValues;
174
0
                if ( rVal >>= aValues )
175
0
                {
176
0
                    maValues = std::move(aValues);
177
0
                    return true;
178
0
                }
179
0
                else
180
0
                    return false;
181
0
            }
182
0
        case MID_ZOOMSLIDER_MINZOOM:
183
0
            {
184
0
                sal_Int32 nVal = 0;
185
0
                if( rVal >>= nVal )
186
0
                {
187
0
                    mnMinZoom = static_cast<sal_uInt16>(nVal);
188
0
                    return true;
189
0
                }
190
0
                else
191
0
                    return false;
192
0
            }
193
0
        case MID_ZOOMSLIDER_MAXZOOM:
194
0
            {
195
0
                sal_Int32 nVal = 0;
196
0
                if( rVal >>= nVal )
197
0
                {
198
0
                    mnMaxZoom = static_cast<sal_uInt16>(nVal);
199
0
                    return true;
200
0
                }
201
0
                else
202
0
                    return false;
203
0
            }
204
0
        default:
205
0
            OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
206
0
            return false;
207
0
    }
208
0
}
209
210
void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
211
0
{
212
0
    const sal_Int32 nValues = maValues.getLength();
213
0
    maValues.realloc(  nValues + 1 );
214
0
    sal_Int32* pValues = maValues.getArray();
215
0
    pValues[ nValues ] = nNew;
216
0
}
217
218
219
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */