LibreOffice Module svx (master) 1
grfitem.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 <svx/grfcrop.hxx>
21#include <editeng/itemtype.hxx>
22#include <com/sun/star/text/GraphicCrop.hpp>
23#include <tools/mapunit.hxx>
25
26using namespace ::com::sun::star;
27
29 : SfxPoolItem( nItemId ),
30 nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
31{}
32
33SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
34 sal_Int32 nT, sal_Int32 nB, TypedWhichId<SvxGrfCrop> nItemId )
35 : SfxPoolItem( nItemId ),
36 nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
37{}
38
40{
41}
42
43bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
44{
45 assert(SfxPoolItem::operator==(rAttr));
46
47 const SvxGrfCrop& rCrop = static_cast<const SvxGrfCrop&>(rAttr);
48 return nLeft == rCrop.GetLeft() &&
49 nRight == rCrop.GetRight() &&
50 nTop == rCrop.GetTop() &&
51 nBottom == rCrop.GetBottom();
52}
53
54
55bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
56{
57 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
58 text::GraphicCrop aRet;
59 aRet.Left = nLeft;
60 aRet.Right = nRight;
61 aRet.Top = nTop;
62 aRet.Bottom = nBottom;
63
64 if( bConvert )
65 {
66 aRet.Right = convertTwipToMm100(aRet.Right );
67 aRet.Top = convertTwipToMm100(aRet.Top );
68 aRet.Left = convertTwipToMm100(aRet.Left );
69 aRet.Bottom = convertTwipToMm100(aRet.Bottom);
70 }
71
72
73 rVal <<= aRet;
74 return true;
75}
76
77bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
78{
79 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
80 text::GraphicCrop aVal;
81
82 if(!(rVal >>= aVal))
83 return false;
84 if( bConvert )
85 {
86 aVal.Right = o3tl::toTwips(aVal.Right, o3tl::Length::mm100);
87 aVal.Top = o3tl::toTwips(aVal.Top, o3tl::Length::mm100);
88 aVal.Left = o3tl::toTwips(aVal.Left, o3tl::Length::mm100);
89 aVal.Bottom = o3tl::toTwips(aVal.Bottom, o3tl::Length::mm100);
90 }
91
92 nLeft = aVal.Left ;
93 nRight = aVal.Right ;
94 nTop = aVal.Top ;
95 nBottom = aVal.Bottom;
96 return true;
97}
98
100 SfxItemPresentation ePres, MapUnit eCoreUnit, MapUnit /*ePresUnit*/,
101 OUString &rText, const IntlWrapper& rIntl ) const
102{
103 rText.clear();
104 switch( ePres )
105 {
106 case SfxItemPresentation::Nameless:
107 return true;
108 case SfxItemPresentation::Complete:
109 rText = "L: " + ::GetMetricText( GetLeft(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
110 " R: " + ::GetMetricText( GetRight(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
111 " T: " + ::GetMetricText( GetTop(), eCoreUnit, MapUnit::MapMM, &rIntl ) +
112 " B: " + ::GetMetricText( GetBottom(), eCoreUnit, MapUnit::MapMM, &rIntl );
113 return true;
114
115 default:
116 return false;
117 }
118}
119
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr auto convertTwipToMm100(N n)
sal_Int32 nBottom
Definition: grfcrop.hxx:31
sal_Int32 GetTop() const
Definition: grfcrop.hxx:63
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &rIntl) const override
Definition: grfitem.cxx:99
sal_Int32 nRight
Definition: grfcrop.hxx:31
sal_Int32 GetRight() const
Definition: grfcrop.hxx:62
SvxGrfCrop(TypedWhichId< SvxGrfCrop >)
Definition: grfitem.cxx:28
sal_Int32 GetLeft() const
Definition: grfcrop.hxx:61
sal_Int32 GetBottom() const
Definition: grfcrop.hxx:64
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grfitem.cxx:55
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grfitem.cxx:77
sal_Int32 nLeft
Definition: grfcrop.hxx:31
virtual bool operator==(const SfxPoolItem &) const override
Definition: grfitem.cxx:43
virtual ~SvxGrfCrop() override
Definition: grfitem.cxx:39
sal_Int32 nTop
Definition: grfcrop.hxx:31
MapUnit
constexpr auto toTwips(N number, Length from)
SfxItemPresentation
#define CONVERT_TWIPS
unsigned char sal_uInt8