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