xref: /aoo41x/main/svx/source/items/grfitem.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <tools/stream.hxx>
33*cdf0e10cSrcweir #include <svx/grfcrop.hxx>
34*cdf0e10cSrcweir #include <editeng/itemtype.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir using namespace ::com::sun::star;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #define TWIP_TO_MM100(TWIP) 	((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
40*cdf0e10cSrcweir #define MM100_TO_TWIP(MM100)	((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
41*cdf0e10cSrcweir //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new  SvxGrfCrop(0))
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /******************************************************************************
44*cdf0e10cSrcweir  *	Implementierung		class SwCropGrf
45*cdf0e10cSrcweir  ******************************************************************************/
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
48*cdf0e10cSrcweir 	: SfxPoolItem( nItemId ),
49*cdf0e10cSrcweir 	nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
50*cdf0e10cSrcweir {}
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
53*cdf0e10cSrcweir 						sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
54*cdf0e10cSrcweir 	: SfxPoolItem( nItemId ),
55*cdf0e10cSrcweir 	nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
56*cdf0e10cSrcweir {}
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir SvxGrfCrop::~SvxGrfCrop()
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
65*cdf0e10cSrcweir 	return nLeft 	== ((const SvxGrfCrop&)rAttr).GetLeft() &&
66*cdf0e10cSrcweir 		   nRight 	== ((const SvxGrfCrop&)rAttr).GetRight() &&
67*cdf0e10cSrcweir 		   nTop 	== ((const SvxGrfCrop&)rAttr).GetTop() &&
68*cdf0e10cSrcweir 		   nBottom	== ((const SvxGrfCrop&)rAttr).GetBottom();
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir /*
72*cdf0e10cSrcweir SfxPoolItem* SvxGrfCrop::Clone( SfxItemPool* ) const
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	return new SvxGrfCrop( *this );
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir */
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir /*
79*cdf0e10cSrcweir sal_uInt16 SvxGrfCrop::GetVersion( sal_uInt16 nFFVer ) const
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
82*cdf0e10cSrcweir 				SOFFICE_FILEFORMAT_40==nFFVer ||
83*cdf0e10cSrcweir 				SOFFICE_FILEFORMAT_NOW==nFFVer,
84*cdf0e10cSrcweir 				"SvxGrfCrop: exist a new fileformat?" );
85*cdf0e10cSrcweir 	return GRFCROP_VERSION_SWDEFAULT;
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir */
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	sal_Int32 top, left, right, bottom;
92*cdf0e10cSrcweir 	rStrm >> top >> left >> right >> bottom;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	if( GRFCROP_VERSION_SWDEFAULT == nVersion )
95*cdf0e10cSrcweir 		top = -top, bottom = -bottom, left = -left, right = -right;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
98*cdf0e10cSrcweir 	pNew->SetLeft( left );
99*cdf0e10cSrcweir 	pNew->SetRight( right );
100*cdf0e10cSrcweir 	pNew->SetTop( top );
101*cdf0e10cSrcweir 	pNew->SetBottom( bottom );
102*cdf0e10cSrcweir 	return pNew;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	sal_Int32 left = GetLeft(), right = GetRight(),
109*cdf0e10cSrcweir 			top = GetTop(), bottom = GetBottom();
110*cdf0e10cSrcweir 	if( GRFCROP_VERSION_SWDEFAULT == nVersion )
111*cdf0e10cSrcweir 		top = -top, bottom = -bottom, left = -left, right = -right;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	rStrm << top << left << right << bottom;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	return rStrm;
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir sal_Bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
123*cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
124*cdf0e10cSrcweir 	text::GraphicCrop aRet;
125*cdf0e10cSrcweir 	aRet.Left 	= nLeft;
126*cdf0e10cSrcweir 	aRet.Right	= nRight;
127*cdf0e10cSrcweir 	aRet.Top 	= nTop;
128*cdf0e10cSrcweir 	aRet.Bottom = nBottom;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     if( bConvert )
131*cdf0e10cSrcweir 	{
132*cdf0e10cSrcweir 	   aRet.Right 	= TWIP_TO_MM100(aRet.Right );
133*cdf0e10cSrcweir 	   aRet.Top    	= TWIP_TO_MM100(aRet.Top );
134*cdf0e10cSrcweir 	   aRet.Left  	= TWIP_TO_MM100(aRet.Left 	);
135*cdf0e10cSrcweir 	   aRet.Bottom	= TWIP_TO_MM100(aRet.Bottom);
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	rVal <<= aRet;
140*cdf0e10cSrcweir 	return	 sal_True;
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir sal_Bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
146*cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
147*cdf0e10cSrcweir 	text::GraphicCrop aVal;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	if(!(rVal >>= aVal))
150*cdf0e10cSrcweir 		return sal_False;
151*cdf0e10cSrcweir     if( bConvert )
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 	   aVal.Right 	= MM100_TO_TWIP(aVal.Right );
154*cdf0e10cSrcweir 	   aVal.Top    	= MM100_TO_TWIP(aVal.Top );
155*cdf0e10cSrcweir 	   aVal.Left  	= MM100_TO_TWIP(aVal.Left 	);
156*cdf0e10cSrcweir 	   aVal.Bottom	= MM100_TO_TWIP(aVal.Bottom);
157*cdf0e10cSrcweir 	}
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	nLeft	= aVal.Left	 ;
160*cdf0e10cSrcweir 	nRight  = aVal.Right ;
161*cdf0e10cSrcweir 	nTop	= aVal.Top	 ;
162*cdf0e10cSrcweir 	nBottom = aVal.Bottom;
163*cdf0e10cSrcweir 	return	sal_True;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir SfxItemPresentation SvxGrfCrop::GetPresentation(
167*cdf0e10cSrcweir     SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
168*cdf0e10cSrcweir     String &rText, const IntlWrapper* pIntl ) const
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	rText.Erase();
171*cdf0e10cSrcweir 	switch( ePres )
172*cdf0e10cSrcweir 	{
173*cdf0e10cSrcweir 	case SFX_ITEM_PRESENTATION_NAMELESS:
174*cdf0e10cSrcweir 	case SFX_ITEM_PRESENTATION_COMPLETE:
175*cdf0e10cSrcweir 		if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
176*cdf0e10cSrcweir 		{
177*cdf0e10cSrcweir 			( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
178*cdf0e10cSrcweir                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
179*cdf0e10cSrcweir 			( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
180*cdf0e10cSrcweir                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
181*cdf0e10cSrcweir 			( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
182*cdf0e10cSrcweir                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
183*cdf0e10cSrcweir 			( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
184*cdf0e10cSrcweir                                             eCoreUnit, SFX_MAPUNIT_MM, pIntl );
185*cdf0e10cSrcweir 		}
186*cdf0e10cSrcweir 		break;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	default:
189*cdf0e10cSrcweir 		ePres = SFX_ITEM_PRESENTATION_NONE;
190*cdf0e10cSrcweir 		break;
191*cdf0e10cSrcweir 	}
192*cdf0e10cSrcweir 	return ePres;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 
198