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>
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
);
71 pNew
->SetBottom( bottom
);
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
;
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
;
98 aRet
.Bottom
= nBottom
;
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
);
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
;
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
);
130 nRight
= aVal
.Right
;
132 nBottom
= aVal
.Bottom
;
136 SfxItemPresentation
SvxGrfCrop::GetPresentation(
137 SfxItemPresentation ePres
, SfxMapUnit eCoreUnit
, SfxMapUnit
/*ePresUnit*/,
138 OUString
&rText
, const IntlWrapper
* pIntl
) const
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
));
155 ePres
= SFX_ITEM_PRESENTATION_NONE
;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */