1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <tools/stream.hxx>
29cdf0e10cSrcweir #include <svx/grfcrop.hxx>
30cdf0e10cSrcweir #include <editeng/itemtype.hxx>
31cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir
35cdf0e10cSrcweir #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
36cdf0e10cSrcweir #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
37cdf0e10cSrcweir //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new SvxGrfCrop(0))
38cdf0e10cSrcweir
39cdf0e10cSrcweir /******************************************************************************
40cdf0e10cSrcweir * Implementierung class SwCropGrf
41cdf0e10cSrcweir ******************************************************************************/
42cdf0e10cSrcweir
SvxGrfCrop(sal_uInt16 nItemId)43cdf0e10cSrcweir SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
44cdf0e10cSrcweir : SfxPoolItem( nItemId ),
45cdf0e10cSrcweir nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
46cdf0e10cSrcweir {}
47cdf0e10cSrcweir
SvxGrfCrop(sal_Int32 nL,sal_Int32 nR,sal_Int32 nT,sal_Int32 nB,sal_uInt16 nItemId)48cdf0e10cSrcweir SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
49cdf0e10cSrcweir sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
50cdf0e10cSrcweir : SfxPoolItem( nItemId ),
51cdf0e10cSrcweir nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
52cdf0e10cSrcweir {}
53cdf0e10cSrcweir
~SvxGrfCrop()54cdf0e10cSrcweir SvxGrfCrop::~SvxGrfCrop()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
operator ==(const SfxPoolItem & rAttr) const58cdf0e10cSrcweir int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
59cdf0e10cSrcweir {
60cdf0e10cSrcweir DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
61cdf0e10cSrcweir return nLeft == ((const SvxGrfCrop&)rAttr).GetLeft() &&
62cdf0e10cSrcweir nRight == ((const SvxGrfCrop&)rAttr).GetRight() &&
63cdf0e10cSrcweir nTop == ((const SvxGrfCrop&)rAttr).GetTop() &&
64cdf0e10cSrcweir nBottom == ((const SvxGrfCrop&)rAttr).GetBottom();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir /*
68cdf0e10cSrcweir SfxPoolItem* SvxGrfCrop::Clone( SfxItemPool* ) const
69cdf0e10cSrcweir {
70cdf0e10cSrcweir return new SvxGrfCrop( *this );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir */
73cdf0e10cSrcweir
74cdf0e10cSrcweir /*
75cdf0e10cSrcweir sal_uInt16 SvxGrfCrop::GetVersion( sal_uInt16 nFFVer ) const
76cdf0e10cSrcweir {
77cdf0e10cSrcweir DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
78cdf0e10cSrcweir SOFFICE_FILEFORMAT_40==nFFVer ||
79cdf0e10cSrcweir SOFFICE_FILEFORMAT_NOW==nFFVer,
80cdf0e10cSrcweir "SvxGrfCrop: exist a new fileformat?" );
81cdf0e10cSrcweir return GRFCROP_VERSION_SWDEFAULT;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir */
84cdf0e10cSrcweir
Create(SvStream & rStrm,sal_uInt16 nVersion) const85cdf0e10cSrcweir SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
86cdf0e10cSrcweir {
87cdf0e10cSrcweir sal_Int32 top, left, right, bottom;
88cdf0e10cSrcweir rStrm >> top >> left >> right >> bottom;
89cdf0e10cSrcweir
90cdf0e10cSrcweir if( GRFCROP_VERSION_SWDEFAULT == nVersion )
91cdf0e10cSrcweir top = -top, bottom = -bottom, left = -left, right = -right;
92cdf0e10cSrcweir
93cdf0e10cSrcweir SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
94cdf0e10cSrcweir pNew->SetLeft( left );
95cdf0e10cSrcweir pNew->SetRight( right );
96cdf0e10cSrcweir pNew->SetTop( top );
97cdf0e10cSrcweir pNew->SetBottom( bottom );
98cdf0e10cSrcweir return pNew;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir
Store(SvStream & rStrm,sal_uInt16 nVersion) const102cdf0e10cSrcweir SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir sal_Int32 left = GetLeft(), right = GetRight(),
105cdf0e10cSrcweir top = GetTop(), bottom = GetBottom();
106cdf0e10cSrcweir if( GRFCROP_VERSION_SWDEFAULT == nVersion )
107cdf0e10cSrcweir top = -top, bottom = -bottom, left = -left, right = -right;
108cdf0e10cSrcweir
109cdf0e10cSrcweir rStrm << top << left << right << bottom;
110cdf0e10cSrcweir
111cdf0e10cSrcweir return rStrm;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir
115cdf0e10cSrcweir
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const116cdf0e10cSrcweir sal_Bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
119cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS;
120cdf0e10cSrcweir text::GraphicCrop aRet;
121cdf0e10cSrcweir aRet.Left = nLeft;
122cdf0e10cSrcweir aRet.Right = nRight;
123cdf0e10cSrcweir aRet.Top = nTop;
124cdf0e10cSrcweir aRet.Bottom = nBottom;
125cdf0e10cSrcweir
126cdf0e10cSrcweir if( bConvert )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir aRet.Right = TWIP_TO_MM100(aRet.Right );
129cdf0e10cSrcweir aRet.Top = TWIP_TO_MM100(aRet.Top );
130cdf0e10cSrcweir aRet.Left = TWIP_TO_MM100(aRet.Left );
131cdf0e10cSrcweir aRet.Bottom = TWIP_TO_MM100(aRet.Bottom);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir rVal <<= aRet;
136cdf0e10cSrcweir return sal_True;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)139cdf0e10cSrcweir sal_Bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
142cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS;
143cdf0e10cSrcweir text::GraphicCrop aVal;
144cdf0e10cSrcweir
145cdf0e10cSrcweir if(!(rVal >>= aVal))
146cdf0e10cSrcweir return sal_False;
147cdf0e10cSrcweir if( bConvert )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir aVal.Right = MM100_TO_TWIP(aVal.Right );
150cdf0e10cSrcweir aVal.Top = MM100_TO_TWIP(aVal.Top );
151cdf0e10cSrcweir aVal.Left = MM100_TO_TWIP(aVal.Left );
152cdf0e10cSrcweir aVal.Bottom = MM100_TO_TWIP(aVal.Bottom);
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir nLeft = aVal.Left ;
156cdf0e10cSrcweir nRight = aVal.Right ;
157cdf0e10cSrcweir nTop = aVal.Top ;
158cdf0e10cSrcweir nBottom = aVal.Bottom;
159cdf0e10cSrcweir return sal_True;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
GetPresentation(SfxItemPresentation ePres,SfxMapUnit eCoreUnit,SfxMapUnit,String & rText,const IntlWrapper * pIntl) const162cdf0e10cSrcweir SfxItemPresentation SvxGrfCrop::GetPresentation(
163cdf0e10cSrcweir SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
164cdf0e10cSrcweir String &rText, const IntlWrapper* pIntl ) const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir rText.Erase();
167cdf0e10cSrcweir switch( ePres )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir case SFX_ITEM_PRESENTATION_NAMELESS:
170cdf0e10cSrcweir case SFX_ITEM_PRESENTATION_COMPLETE:
171cdf0e10cSrcweir if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir ( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
174cdf0e10cSrcweir eCoreUnit, SFX_MAPUNIT_MM, pIntl );
175cdf0e10cSrcweir ( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
176cdf0e10cSrcweir eCoreUnit, SFX_MAPUNIT_MM, pIntl );
177cdf0e10cSrcweir ( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
178cdf0e10cSrcweir eCoreUnit, SFX_MAPUNIT_MM, pIntl );
179cdf0e10cSrcweir ( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
180cdf0e10cSrcweir eCoreUnit, SFX_MAPUNIT_MM, pIntl );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir break;
183cdf0e10cSrcweir
184cdf0e10cSrcweir default:
185cdf0e10cSrcweir ePres = SFX_ITEM_PRESENTATION_NONE;
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir return ePres;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
191cdf0e10cSrcweir
192cdf0e10cSrcweir
193cdf0e10cSrcweir
194