Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/stream.hxx>
21 : #include <svx/grfcrop.hxx>
22 : #include <editeng/itemtype.hxx>
23 : #include <com/sun/star/text/GraphicCrop.hpp>
24 :
25 : using namespace ::com::sun::star;
26 :
27 : #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
28 : #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
29 : //TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new SvxGrfCrop(0))
30 :
31 : /******************************************************************************
32 : * Implementierung class SwCropGrf
33 : ******************************************************************************/
34 :
35 37 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
36 : : SfxPoolItem( nItemId ),
37 37 : nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
38 37 : {}
39 :
40 3216 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
41 : sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
42 : : SfxPoolItem( nItemId ),
43 3216 : nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
44 3216 : {}
45 :
46 4278 : SvxGrfCrop::~SvxGrfCrop()
47 : {
48 4278 : }
49 :
50 494 : bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
51 : {
52 : DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
53 906 : return nLeft == ((const SvxGrfCrop&)rAttr).GetLeft() &&
54 824 : nRight == ((const SvxGrfCrop&)rAttr).GetRight() &&
55 1281 : nTop == ((const SvxGrfCrop&)rAttr).GetTop() &&
56 869 : nBottom == ((const SvxGrfCrop&)rAttr).GetBottom();
57 : }
58 :
59 0 : SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
60 : {
61 : sal_Int32 top, left, right, bottom;
62 0 : rStrm.ReadInt32( top ).ReadInt32( left ).ReadInt32( right ).ReadInt32( bottom );
63 :
64 0 : if( GRFCROP_VERSION_SWDEFAULT == nVersion )
65 0 : top = -top, bottom = -bottom, left = -left, right = -right;
66 :
67 0 : SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
68 0 : pNew->SetLeft( left );
69 0 : pNew->SetRight( right );
70 0 : pNew->SetTop( top );
71 0 : pNew->SetBottom( bottom );
72 0 : return pNew;
73 : }
74 :
75 :
76 0 : SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
77 : {
78 0 : sal_Int32 left = GetLeft(), right = GetRight(),
79 0 : top = GetTop(), bottom = GetBottom();
80 0 : if( GRFCROP_VERSION_SWDEFAULT == nVersion )
81 0 : top = -top, bottom = -bottom, left = -left, right = -right;
82 :
83 0 : rStrm.WriteInt32( top ).WriteInt32( left ).WriteInt32( right ).WriteInt32( bottom );
84 :
85 0 : return rStrm;
86 : }
87 :
88 :
89 :
90 268 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
91 : {
92 268 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
93 268 : nMemberId &= ~CONVERT_TWIPS;
94 268 : text::GraphicCrop aRet;
95 268 : aRet.Left = nLeft;
96 268 : aRet.Right = nRight;
97 268 : aRet.Top = nTop;
98 268 : aRet.Bottom = nBottom;
99 :
100 268 : if( bConvert )
101 : {
102 52 : aRet.Right = TWIP_TO_MM100(aRet.Right );
103 52 : aRet.Top = TWIP_TO_MM100(aRet.Top );
104 52 : aRet.Left = TWIP_TO_MM100(aRet.Left );
105 52 : aRet.Bottom = TWIP_TO_MM100(aRet.Bottom);
106 : }
107 :
108 :
109 268 : rVal <<= aRet;
110 268 : return true;
111 : }
112 :
113 280 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
114 : {
115 280 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
116 280 : nMemberId &= ~CONVERT_TWIPS;
117 280 : text::GraphicCrop aVal;
118 :
119 280 : if(!(rVal >>= aVal))
120 0 : return false;
121 280 : if( bConvert )
122 : {
123 185 : aVal.Right = MM100_TO_TWIP(aVal.Right );
124 185 : aVal.Top = MM100_TO_TWIP(aVal.Top );
125 185 : aVal.Left = MM100_TO_TWIP(aVal.Left );
126 185 : aVal.Bottom = MM100_TO_TWIP(aVal.Bottom);
127 : }
128 :
129 280 : nLeft = aVal.Left ;
130 280 : nRight = aVal.Right ;
131 280 : nTop = aVal.Top ;
132 280 : nBottom = aVal.Bottom;
133 280 : return true;
134 : }
135 :
136 0 : SfxItemPresentation SvxGrfCrop::GetPresentation(
137 : SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
138 : OUString &rText, const IntlWrapper* pIntl ) const
139 : {
140 0 : rText = OUString();
141 0 : switch( ePres )
142 : {
143 : case SFX_ITEM_PRESENTATION_NAMELESS:
144 : case SFX_ITEM_PRESENTATION_COMPLETE:
145 0 : if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
146 : {
147 0 : rText = "L: " + OUString(::GetMetricText( GetLeft(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
148 0 : " R: " + OUString(::GetMetricText( GetRight(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
149 0 : " T: " + OUString(::GetMetricText( GetTop(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
150 0 : " B: " + OUString(::GetMetricText( GetBottom(), eCoreUnit, SFX_MAPUNIT_MM, pIntl ));
151 : }
152 0 : break;
153 :
154 : default:
155 0 : ePres = SFX_ITEM_PRESENTATION_NONE;
156 0 : break;
157 : }
158 0 : return ePres;
159 : }
160 :
161 :
162 :
163 :
164 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|