bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / items / grfitem.cxx
blobd63e32e06e5908352d23266bcae1b0cc92a4e31b
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 <tools/stream.hxx>
21 #include <svx/grfcrop.hxx>
22 #include <editeng/itemtype.hxx>
23 #include <com/sun/star/text/GraphicCrop.hpp>
25 using namespace ::com::sun::star;
27 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
28 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
29 //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new SvxGrfCrop(0))
31 /******************************************************************************
32 * Implementierung class SwCropGrf
33 ******************************************************************************/
35 SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
36 : SfxPoolItem( nItemId ),
37 nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
40 SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
41 sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
42 : SfxPoolItem( nItemId ),
43 nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
46 SvxGrfCrop::~SvxGrfCrop()
50 int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
52 DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
53 return nLeft == ((const SvxGrfCrop&)rAttr).GetLeft() &&
54 nRight == ((const SvxGrfCrop&)rAttr).GetRight() &&
55 nTop == ((const SvxGrfCrop&)rAttr).GetTop() &&
56 nBottom == ((const SvxGrfCrop&)rAttr).GetBottom();
59 SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
61 sal_Int32 top, left, right, bottom;
62 rStrm >> top >> left >> right >> bottom;
64 if( GRFCROP_VERSION_SWDEFAULT == nVersion )
65 top = -top, bottom = -bottom, left = -left, right = -right;
67 SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
68 pNew->SetLeft( left );
69 pNew->SetRight( right );
70 pNew->SetTop( top );
71 pNew->SetBottom( bottom );
72 return pNew;
76 SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
78 sal_Int32 left = GetLeft(), right = GetRight(),
79 top = GetTop(), bottom = GetBottom();
80 if( GRFCROP_VERSION_SWDEFAULT == nVersion )
81 top = -top, bottom = -bottom, left = -left, right = -right;
83 rStrm << top << left << right << bottom;
85 return rStrm;
90 bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
92 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
93 nMemberId &= ~CONVERT_TWIPS;
94 text::GraphicCrop aRet;
95 aRet.Left = nLeft;
96 aRet.Right = nRight;
97 aRet.Top = nTop;
98 aRet.Bottom = nBottom;
100 if( bConvert )
102 aRet.Right = TWIP_TO_MM100(aRet.Right );
103 aRet.Top = TWIP_TO_MM100(aRet.Top );
104 aRet.Left = TWIP_TO_MM100(aRet.Left );
105 aRet.Bottom = TWIP_TO_MM100(aRet.Bottom);
109 rVal <<= aRet;
110 return true;
113 bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
115 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
116 nMemberId &= ~CONVERT_TWIPS;
117 text::GraphicCrop aVal;
119 if(!(rVal >>= aVal))
120 return false;
121 if( bConvert )
123 aVal.Right = MM100_TO_TWIP(aVal.Right );
124 aVal.Top = MM100_TO_TWIP(aVal.Top );
125 aVal.Left = MM100_TO_TWIP(aVal.Left );
126 aVal.Bottom = MM100_TO_TWIP(aVal.Bottom);
129 nLeft = aVal.Left ;
130 nRight = aVal.Right ;
131 nTop = aVal.Top ;
132 nBottom = aVal.Bottom;
133 return true;
136 SfxItemPresentation SvxGrfCrop::GetPresentation(
137 SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
138 OUString &rText, const IntlWrapper* pIntl ) const
140 rText = OUString();
141 switch( ePres )
143 case SFX_ITEM_PRESENTATION_NAMELESS:
144 case SFX_ITEM_PRESENTATION_COMPLETE:
145 if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
147 rText = "L: " + OUString(::GetMetricText( GetLeft(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
148 " R: " + OUString(::GetMetricText( GetRight(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
149 " T: " + OUString(::GetMetricText( GetTop(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
150 " B: " + OUString(::GetMetricText( GetBottom(), eCoreUnit, SFX_MAPUNIT_MM, pIntl ));
152 break;
154 default:
155 ePres = SFX_ITEM_PRESENTATION_NONE;
156 break;
158 return ePres;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */