1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <tools/mapunit.hxx>
26 using namespace ::com::sun::star
;
28 SvxGrfCrop::SvxGrfCrop( sal_uInt16 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
, sal_uInt16 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 DBG_ASSERT( SfxPoolItem::operator==( rAttr
), "not equal attributes" );
46 const SvxGrfCrop
& rCrop
= static_cast<const SvxGrfCrop
&>(rAttr
);
47 return nLeft
== rCrop
.GetLeft() &&
48 nRight
== rCrop
.GetRight() &&
49 nTop
== rCrop
.GetTop() &&
50 nBottom
== rCrop
.GetBottom();
53 SfxPoolItem
* SvxGrfCrop::Create( SvStream
& rStrm
, sal_uInt16 nVersion
) const
55 sal_Int32 top
, left
, right
, bottom
;
56 rStrm
.ReadInt32( top
).ReadInt32( left
).ReadInt32( right
).ReadInt32( bottom
);
58 if( GRFCROP_VERSION_SWDEFAULT
== nVersion
)
59 top
= -top
, bottom
= -bottom
, left
= -left
, right
= -right
;
61 SvxGrfCrop
* pNew
= static_cast<SvxGrfCrop
*>(Clone());
62 pNew
->SetLeft( left
);
63 pNew
->SetRight( right
);
65 pNew
->SetBottom( bottom
);
70 SvStream
& SvxGrfCrop::Store( SvStream
& rStrm
, sal_uInt16 nVersion
) const
72 sal_Int32 left
= GetLeft(), right
= GetRight(),
73 top
= GetTop(), bottom
= GetBottom();
74 if( GRFCROP_VERSION_SWDEFAULT
== nVersion
)
75 top
= -top
, bottom
= -bottom
, left
= -left
, right
= -right
;
77 rStrm
.WriteInt32( top
).WriteInt32( left
).WriteInt32( right
).WriteInt32( bottom
);
84 bool SvxGrfCrop::QueryValue( uno::Any
& rVal
, sal_uInt8 nMemberId
) const
86 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
87 text::GraphicCrop aRet
;
91 aRet
.Bottom
= nBottom
;
95 aRet
.Right
= convertTwipToMm100(aRet
.Right
);
96 aRet
.Top
= convertTwipToMm100(aRet
.Top
);
97 aRet
.Left
= convertTwipToMm100(aRet
.Left
);
98 aRet
.Bottom
= convertTwipToMm100(aRet
.Bottom
);
106 bool SvxGrfCrop::PutValue( const uno::Any
& rVal
, sal_uInt8 nMemberId
)
108 bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
109 text::GraphicCrop aVal
;
115 aVal
.Right
= convertMm100ToTwip(aVal
.Right
);
116 aVal
.Top
= convertMm100ToTwip(aVal
.Top
);
117 aVal
.Left
= convertMm100ToTwip(aVal
.Left
);
118 aVal
.Bottom
= convertMm100ToTwip(aVal
.Bottom
);
122 nRight
= aVal
.Right
;
124 nBottom
= aVal
.Bottom
;
128 bool SvxGrfCrop::GetPresentation(
129 SfxItemPresentation ePres
, SfxMapUnit eCoreUnit
, SfxMapUnit
/*ePresUnit*/,
130 OUString
&rText
, const IntlWrapper
* pIntl
) const
135 case SFX_ITEM_PRESENTATION_NAMELESS
:
137 case SFX_ITEM_PRESENTATION_COMPLETE
:
138 rText
= "L: " + OUString(::GetMetricText( GetLeft(), eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
)) +
139 " R: " + OUString(::GetMetricText( GetRight(), eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
)) +
140 " T: " + OUString(::GetMetricText( GetTop(), eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
)) +
141 " B: " + OUString(::GetMetricText( GetBottom(), eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
));
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */