Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/doc/zoomitem.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 <sfx2/zoomitem.hxx>
21
#include <com/sun/star/uno/Sequence.hxx>
22
#include <com/sun/star/beans/PropertyValue.hpp>
23
24
#include <comphelper/propertyvalue.hxx>
25
#include <osl/diagnose.h>
26
27
#include <cassert>
28
29
30
0
SfxPoolItem* SvxZoomItem::CreateDefault() { return new SvxZoomItem; }
31
32
constexpr OUString ZOOM_PARAM_VALUE = u"Value"_ustr;
33
constexpr OUString ZOOM_PARAM_VALUESET = u"ValueSet"_ustr;
34
constexpr OUString ZOOM_PARAM_TYPE = u"Type"_ustr;
35
constexpr auto ZOOM_PARAMS = 3;
36
37
38
SvxZoomItem::SvxZoomItem
39
(
40
    SvxZoomType eZoomType,
41
    sal_uInt16      nVal,
42
    TypedWhichId<SvxZoomItem>      _nWhich
43
)
44
0
:   SfxUInt16Item( _nWhich, nVal ),
45
0
    nValueSet( SvxZoomEnableFlags::ALL ),
46
0
    eType( eZoomType )
47
0
{
48
0
}
49
50
SvxZoomItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
51
0
{
52
0
    return new SvxZoomItem( *this );
53
0
}
54
55
bool SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
56
0
{
57
0
    assert(SfxPoolItem::operator==(rAttr));
58
59
0
    const SvxZoomItem& rItem = static_cast<const SvxZoomItem&>(rAttr);
60
61
0
    return ( GetValue() == rItem.GetValue()     &&
62
0
             nValueSet  == rItem.GetValueSet()  &&
63
0
             eType      == rItem.GetType()          );
64
0
}
65
66
bool SvxZoomItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
67
0
{
68
0
    nMemberId &= ~CONVERT_TWIPS;
69
0
    switch( nMemberId )
70
0
    {
71
0
        case 0:
72
0
        {
73
0
            css::uno::Sequence< css::beans::PropertyValue > aSeq{
74
0
                comphelper::makePropertyValue(ZOOM_PARAM_VALUE, sal_Int32( GetValue() )),
75
0
                comphelper::makePropertyValue(ZOOM_PARAM_VALUESET, sal_Int16( nValueSet )),
76
0
                comphelper::makePropertyValue(ZOOM_PARAM_TYPE, sal_Int16( eType ))
77
0
            };
78
0
            assert(aSeq.getLength() == ZOOM_PARAMS);
79
0
            rVal <<= aSeq;
80
0
            break;
81
0
        }
82
83
0
        case MID_VALUE: rVal <<= static_cast<sal_Int32>(GetValue()); break;
84
0
        case MID_VALUESET: rVal <<= static_cast<sal_Int16>(nValueSet); break;
85
0
        case MID_TYPE: rVal <<= static_cast<sal_Int16>(eType); break;
86
0
        default:
87
0
            OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
88
0
            return false;
89
0
    }
90
91
0
    return true;
92
0
}
93
94
bool SvxZoomItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
95
0
{
96
0
    nMemberId &= ~CONVERT_TWIPS;
97
0
    switch( nMemberId )
98
0
    {
99
0
        case 0:
100
0
        {
101
0
            css::uno::Sequence< css::beans::PropertyValue > aSeq;
102
0
            if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
103
0
            {
104
0
                sal_Int32 nValueTmp( 0 );
105
0
                sal_Int16 nValueSetTmp( 0 );
106
0
                sal_Int16 nTypeTmp( 0 );
107
0
                bool bAllConverted( true );
108
0
                sal_Int16 nConvertedCount( 0 );
109
0
                for (const auto& rProp : aSeq)
110
0
                {
111
0
                    if ( rProp.Name == ZOOM_PARAM_VALUE )
112
0
                    {
113
0
                        bAllConverted &= ( rProp.Value >>= nValueTmp );
114
0
                        ++nConvertedCount;
115
0
                    }
116
0
                    else if ( rProp.Name == ZOOM_PARAM_VALUESET )
117
0
                    {
118
0
                        bAllConverted &= ( rProp.Value >>= nValueSetTmp );
119
0
                        ++nConvertedCount;
120
0
                    }
121
0
                    else if ( rProp.Name == ZOOM_PARAM_TYPE )
122
0
                    {
123
0
                        bAllConverted &= ( rProp.Value >>= nTypeTmp );
124
0
                        ++nConvertedCount;
125
0
                    }
126
0
                }
127
128
0
                if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
129
0
                {
130
0
                    SetValue( static_cast<sal_uInt16>(nValueTmp) );
131
0
                    nValueSet = static_cast<SvxZoomEnableFlags>(nValueSetTmp);
132
0
                    eType = static_cast<SvxZoomType>(nTypeTmp);
133
0
                    return true;
134
0
                }
135
0
            }
136
0
            return false;
137
0
        }
138
0
        case MID_VALUE:
139
0
        {
140
0
            sal_Int32 nVal = 0;
141
0
            if ( rVal >>= nVal )
142
0
            {
143
0
                SetValue( static_cast<sal_uInt16>(nVal) );
144
0
                return true;
145
0
            }
146
0
            else
147
0
                return false;
148
0
        }
149
150
0
        case MID_VALUESET:
151
0
        case MID_TYPE:
152
0
        {
153
0
            sal_Int16 nVal;
154
0
            if ( rVal >>= nVal )
155
0
            {
156
0
                if ( nMemberId == MID_VALUESET )
157
0
                    nValueSet = static_cast<SvxZoomEnableFlags>(nVal);
158
0
                else if ( nMemberId == MID_TYPE )
159
0
                    eType = static_cast<SvxZoomType>(nVal);
160
0
                return true;
161
0
            }
162
0
            else
163
0
                return false;
164
0
        }
165
166
0
        default:
167
0
            OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
168
0
            return false;
169
0
    }
170
0
}
171
172
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */