Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/items/grfitem.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 <svx/grfcrop.hxx>
21
#include <editeng/itemtype.hxx>
22
#include <com/sun/star/text/GraphicCrop.hpp>
23
#include <tools/mapunit.hxx>
24
#include <tools/UnitConversion.hxx>
25
#include <o3tl/hash_combine.hxx>
26
27
using namespace ::com::sun::star;
28
29
SvxGrfCrop::SvxGrfCrop( TypedWhichId<SvxGrfCrop> nItemId )
30
9
    : SfxPoolItem( nItemId ),
31
9
    m_nLeft( 0 ), m_nRight( 0 ), m_nTop( 0 ), m_nBottom( 0 )
32
9
{}
33
34
SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
35
                        sal_Int32 nT, sal_Int32 nB, TypedWhichId<SvxGrfCrop> nItemId)
36
130k
    : SfxPoolItem( nItemId ),
37
130k
    m_nLeft( nL ), m_nRight( nR ), m_nTop( nT ), m_nBottom( nB )
38
130k
{}
39
40
SvxGrfCrop::~SvxGrfCrop()
41
253k
{
42
253k
}
43
44
bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
45
128k
{
46
128k
    assert(SfxPoolItem::operator==(rAttr));
47
48
128k
    const SvxGrfCrop& rCrop = static_cast<const SvxGrfCrop&>(rAttr);
49
128k
    return m_nLeft    == rCrop.GetLeft() &&
50
128k
           m_nRight   == rCrop.GetRight() &&
51
128k
           m_nTop     == rCrop.GetTop() &&
52
128k
           m_nBottom  == rCrop.GetBottom();
53
128k
}
54
55
size_t SvxGrfCrop::hashCode() const
56
12.5k
{
57
12.5k
    std::size_t seed(0);
58
12.5k
    o3tl::hash_combine(seed, m_nLeft);
59
12.5k
    o3tl::hash_combine(seed, m_nRight);
60
12.5k
    o3tl::hash_combine(seed, m_nTop);
61
12.5k
    o3tl::hash_combine(seed, m_nBottom);
62
12.5k
    return seed;
63
12.5k
}
64
65
bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
66
539
{
67
539
    bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
68
539
    text::GraphicCrop aRet;
69
539
    aRet.Left   = m_nLeft;
70
539
    aRet.Right  = m_nRight;
71
539
    aRet.Top    = m_nTop;
72
539
    aRet.Bottom = m_nBottom;
73
74
539
    if( bConvert )
75
0
    {
76
0
       aRet.Right   = convertTwipToMm100(aRet.Right );
77
0
       aRet.Top     = convertTwipToMm100(aRet.Top );
78
0
       aRet.Left    = convertTwipToMm100(aRet.Left   );
79
0
       aRet.Bottom  = convertTwipToMm100(aRet.Bottom);
80
0
    }
81
82
83
539
    rVal <<= aRet;
84
539
    return true;
85
539
}
86
87
bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
88
2.17k
{
89
2.17k
    ASSERT_CHANGE_REFCOUNTED_ITEM;
90
2.17k
    bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
91
2.17k
    text::GraphicCrop aVal;
92
93
2.17k
    if(!(rVal >>= aVal))
94
0
        return false;
95
2.17k
    if( bConvert )
96
549
    {
97
549
       aVal.Right   = o3tl::toTwips(aVal.Right, o3tl::Length::mm100);
98
549
       aVal.Top     = o3tl::toTwips(aVal.Top, o3tl::Length::mm100);
99
549
       aVal.Left    = o3tl::toTwips(aVal.Left, o3tl::Length::mm100);
100
549
       aVal.Bottom  = o3tl::toTwips(aVal.Bottom, o3tl::Length::mm100);
101
549
    }
102
103
2.17k
    m_nLeft   = aVal.Left  ;
104
2.17k
    m_nRight  = aVal.Right ;
105
2.17k
    m_nTop    = aVal.Top   ;
106
2.17k
    m_nBottom = aVal.Bottom;
107
2.17k
    return  true;
108
2.17k
}
109
110
bool SvxGrfCrop::GetPresentation(
111
    SfxItemPresentation ePres, MapUnit eCoreUnit, MapUnit /*ePresUnit*/,
112
    OUString &rText, const IntlWrapper& rIntl ) const
113
0
{
114
0
    rText.clear();
115
0
    switch( ePres )
116
0
    {
117
0
    case SfxItemPresentation::Nameless:
118
0
        return true;
119
0
    case SfxItemPresentation::Complete:
120
0
        rText = "L: "  + ::GetMetricText( GetLeft(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
121
0
                " R: " + ::GetMetricText( GetRight(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
122
0
                " T: " + ::GetMetricText( GetTop(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
123
0
                " B: " + ::GetMetricText( GetBottom(), eCoreUnit, MapUnit::MapMM, &rIntl );
124
0
        return true;
125
126
0
    default:
127
0
        return false;
128
0
    }
129
0
}
130
131
132
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */