1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grfitem.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include <tools/stream.hxx>
36 #include <svx/grfcrop.hxx>
37 #include <svx/itemtype.hxx>
38 #include <com/sun/star/text/GraphicCrop.hpp>
40 using namespace ::com::sun::star
;
42 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
43 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
44 //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new SvxGrfCrop(0))
46 /******************************************************************************
47 * Implementierung class SwCropGrf
48 ******************************************************************************/
50 SvxGrfCrop::SvxGrfCrop( USHORT nItemId
)
51 : SfxPoolItem( nItemId
),
52 nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
55 SvxGrfCrop::SvxGrfCrop( sal_Int32 nL
, sal_Int32 nR
,
56 sal_Int32 nT
, sal_Int32 nB
, USHORT nItemId
)
57 : SfxPoolItem( nItemId
),
58 nLeft( nL
), nRight( nR
), nTop( nT
), nBottom( nB
)
61 SvxGrfCrop::~SvxGrfCrop()
65 int SvxGrfCrop::operator==( const SfxPoolItem
& rAttr
) const
67 DBG_ASSERT( SfxPoolItem::operator==( rAttr
), "not equal attributes" );
68 return nLeft
== ((const SvxGrfCrop
&)rAttr
).GetLeft() &&
69 nRight
== ((const SvxGrfCrop
&)rAttr
).GetRight() &&
70 nTop
== ((const SvxGrfCrop
&)rAttr
).GetTop() &&
71 nBottom
== ((const SvxGrfCrop
&)rAttr
).GetBottom();
75 SfxPoolItem* SvxGrfCrop::Clone( SfxItemPool* ) const
77 return new SvxGrfCrop( *this );
82 USHORT SvxGrfCrop::GetVersion( USHORT nFFVer ) const
84 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
85 SOFFICE_FILEFORMAT_40==nFFVer ||
86 SOFFICE_FILEFORMAT_NOW==nFFVer,
87 "SvxGrfCrop: exist a new fileformat?" );
88 return GRFCROP_VERSION_SWDEFAULT;
92 SfxPoolItem
* SvxGrfCrop::Create( SvStream
& rStrm
, USHORT nVersion
) const
94 INT32 top
, left
, right
, bottom
;
95 rStrm
>> top
>> left
>> right
>> bottom
;
97 if( GRFCROP_VERSION_SWDEFAULT
== nVersion
)
98 top
= -top
, bottom
= -bottom
, left
= -left
, right
= -right
;
100 SvxGrfCrop
* pNew
= (SvxGrfCrop
*)Clone();
101 pNew
->SetLeft( left
);
102 pNew
->SetRight( right
);
104 pNew
->SetBottom( bottom
);
109 SvStream
& SvxGrfCrop::Store( SvStream
& rStrm
, USHORT nVersion
) const
111 INT32 left
= GetLeft(), right
= GetRight(),
112 top
= GetTop(), bottom
= GetBottom();
113 if( GRFCROP_VERSION_SWDEFAULT
== nVersion
)
114 top
= -top
, bottom
= -bottom
, left
= -left
, right
= -right
;
116 rStrm
<< top
<< left
<< right
<< bottom
;
123 BOOL
SvxGrfCrop::QueryValue( uno::Any
& rVal
, BYTE nMemberId
) const
125 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
126 nMemberId
&= ~CONVERT_TWIPS
;
127 text::GraphicCrop aRet
;
131 aRet
.Bottom
= nBottom
;
135 aRet
.Right
= TWIP_TO_MM100(aRet
.Right
);
136 aRet
.Top
= TWIP_TO_MM100(aRet
.Top
);
137 aRet
.Left
= TWIP_TO_MM100(aRet
.Left
);
138 aRet
.Bottom
= TWIP_TO_MM100(aRet
.Bottom
);
146 BOOL
SvxGrfCrop::PutValue( const uno::Any
& rVal
, BYTE nMemberId
)
148 sal_Bool bConvert
= 0!=(nMemberId
&CONVERT_TWIPS
);
149 nMemberId
&= ~CONVERT_TWIPS
;
150 text::GraphicCrop aVal
;
156 aVal
.Right
= MM100_TO_TWIP(aVal
.Right
);
157 aVal
.Top
= MM100_TO_TWIP(aVal
.Top
);
158 aVal
.Left
= MM100_TO_TWIP(aVal
.Left
);
159 aVal
.Bottom
= MM100_TO_TWIP(aVal
.Bottom
);
163 nRight
= aVal
.Right
;
165 nBottom
= aVal
.Bottom
;
169 SfxItemPresentation
SvxGrfCrop::GetPresentation(
170 SfxItemPresentation ePres
, SfxMapUnit eCoreUnit
, SfxMapUnit
/*ePresUnit*/,
171 String
&rText
, const IntlWrapper
* pIntl
) const
176 case SFX_ITEM_PRESENTATION_NAMELESS
:
177 case SFX_ITEM_PRESENTATION_COMPLETE
:
178 if( SFX_ITEM_PRESENTATION_COMPLETE
== ePres
)
180 ( rText
.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
181 eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
);
182 ( rText
.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
183 eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
);
184 ( rText
.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
185 eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
);
186 ( rText
.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
187 eCoreUnit
, SFX_MAPUNIT_MM
, pIntl
);
192 ePres
= SFX_ITEM_PRESENTATION_NONE
;