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