Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / grfitem.cxx
blob30c0977a034d906c4f84b357edf5ab2a907a789e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
26 using namespace ::com::sun::star;
28 SvxGrfCrop::SvxGrfCrop( TypedWhichId<SvxGrfCrop> nItemId )
29 : SfxPoolItem( nItemId ),
30 nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
33 SvxGrfCrop::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 )
39 SvxGrfCrop::~SvxGrfCrop()
43 bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
45 assert(SfxPoolItem::operator==(rAttr));
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();
55 bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
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;
64 if( bConvert )
66 aRet.Right = convertTwipToMm100(aRet.Right );
67 aRet.Top = convertTwipToMm100(aRet.Top );
68 aRet.Left = convertTwipToMm100(aRet.Left );
69 aRet.Bottom = convertTwipToMm100(aRet.Bottom);
73 rVal <<= aRet;
74 return true;
77 bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
79 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
80 text::GraphicCrop aVal;
82 if(!(rVal >>= aVal))
83 return false;
84 if( bConvert )
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);
92 nLeft = aVal.Left ;
93 nRight = aVal.Right ;
94 nTop = aVal.Top ;
95 nBottom = aVal.Bottom;
96 return true;
99 bool SvxGrfCrop::GetPresentation(
100 SfxItemPresentation ePres, MapUnit eCoreUnit, MapUnit /*ePresUnit*/,
101 OUString &rText, const IntlWrapper& rIntl ) const
103 rText.clear();
104 switch( ePres )
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;
115 default:
116 return false;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */