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 33 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
36 : : SfxPoolItem( nItemId ),
37 33 : nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
38 33 : {}
39 :
40 1519 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
41 : sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
42 : : SfxPoolItem( nItemId ),
43 1519 : nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
44 1519 : {}
45 :
46 1798 : SvxGrfCrop::~SvxGrfCrop()
47 : {
48 1798 : }
49 :
50 52 : int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
51 : {
52 : DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
53 104 : return nLeft == ((const SvxGrfCrop&)rAttr).GetLeft() &&
54 104 : nRight == ((const SvxGrfCrop&)rAttr).GetRight() &&
55 156 : nTop == ((const SvxGrfCrop&)rAttr).GetTop() &&
56 104 : 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 >> top >> left >> right >> 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 << top << left << right << bottom;
84 :
85 0 : return rStrm;
86 : }
87 :
88 :
89 :
90 28 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
91 : {
92 28 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
93 28 : nMemberId &= ~CONVERT_TWIPS;
94 28 : text::GraphicCrop aRet;
95 28 : aRet.Left = nLeft;
96 28 : aRet.Right = nRight;
97 28 : aRet.Top = nTop;
98 28 : aRet.Bottom = nBottom;
99 :
100 28 : if( bConvert )
101 : {
102 2 : aRet.Right = TWIP_TO_MM100(aRet.Right );
103 2 : aRet.Top = TWIP_TO_MM100(aRet.Top );
104 2 : aRet.Left = TWIP_TO_MM100(aRet.Left );
105 2 : aRet.Bottom = TWIP_TO_MM100(aRet.Bottom);
106 : }
107 :
108 :
109 28 : rVal <<= aRet;
110 28 : return true;
111 : }
112 :
113 43 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
114 : {
115 43 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
116 43 : nMemberId &= ~CONVERT_TWIPS;
117 43 : text::GraphicCrop aVal;
118 :
119 43 : if(!(rVal >>= aVal))
120 0 : return false;
121 43 : if( bConvert )
122 : {
123 28 : aVal.Right = MM100_TO_TWIP(aVal.Right );
124 28 : aVal.Top = MM100_TO_TWIP(aVal.Top );
125 28 : aVal.Left = MM100_TO_TWIP(aVal.Left );
126 28 : aVal.Bottom = MM100_TO_TWIP(aVal.Bottom);
127 : }
128 :
129 43 : nLeft = aVal.Left ;
130 43 : nRight = aVal.Right ;
131 43 : nTop = aVal.Top ;
132 43 : nBottom = aVal.Bottom;
133 43 : 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: */
|