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 : #include <tools/mapunit.hxx>
25 :
26 : using namespace ::com::sun::star;
27 :
28 : /******************************************************************************
29 : * Implementierung class SwCropGrf
30 : ******************************************************************************/
31 :
32 0 : SvxGrfCrop::SvxGrfCrop( sal_uInt16 nItemId )
33 : : SfxPoolItem( nItemId ),
34 0 : nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
35 0 : {}
36 :
37 0 : SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
38 : sal_Int32 nT, sal_Int32 nB, sal_uInt16 nItemId )
39 : : SfxPoolItem( nItemId ),
40 0 : nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
41 0 : {}
42 :
43 0 : SvxGrfCrop::~SvxGrfCrop()
44 : {
45 0 : }
46 :
47 0 : bool SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
48 : {
49 : DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
50 0 : return nLeft == ((const SvxGrfCrop&)rAttr).GetLeft() &&
51 0 : nRight == ((const SvxGrfCrop&)rAttr).GetRight() &&
52 0 : nTop == ((const SvxGrfCrop&)rAttr).GetTop() &&
53 0 : nBottom == ((const SvxGrfCrop&)rAttr).GetBottom();
54 : }
55 :
56 0 : SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
57 : {
58 : sal_Int32 top, left, right, bottom;
59 0 : rStrm.ReadInt32( top ).ReadInt32( left ).ReadInt32( right ).ReadInt32( bottom );
60 :
61 0 : if( GRFCROP_VERSION_SWDEFAULT == nVersion )
62 0 : top = -top, bottom = -bottom, left = -left, right = -right;
63 :
64 0 : SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
65 0 : pNew->SetLeft( left );
66 0 : pNew->SetRight( right );
67 0 : pNew->SetTop( top );
68 0 : pNew->SetBottom( bottom );
69 0 : return pNew;
70 : }
71 :
72 :
73 0 : SvStream& SvxGrfCrop::Store( SvStream& rStrm, sal_uInt16 nVersion ) const
74 : {
75 0 : sal_Int32 left = GetLeft(), right = GetRight(),
76 0 : top = GetTop(), bottom = GetBottom();
77 0 : if( GRFCROP_VERSION_SWDEFAULT == nVersion )
78 0 : top = -top, bottom = -bottom, left = -left, right = -right;
79 :
80 0 : rStrm.WriteInt32( top ).WriteInt32( left ).WriteInt32( right ).WriteInt32( bottom );
81 :
82 0 : return rStrm;
83 : }
84 :
85 :
86 :
87 0 : bool SvxGrfCrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
88 : {
89 0 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
90 0 : nMemberId &= ~CONVERT_TWIPS;
91 0 : text::GraphicCrop aRet;
92 0 : aRet.Left = nLeft;
93 0 : aRet.Right = nRight;
94 0 : aRet.Top = nTop;
95 0 : aRet.Bottom = nBottom;
96 :
97 0 : if( bConvert )
98 : {
99 0 : aRet.Right = convertTwipToMm100(aRet.Right );
100 0 : aRet.Top = convertTwipToMm100(aRet.Top );
101 0 : aRet.Left = convertTwipToMm100(aRet.Left );
102 0 : aRet.Bottom = convertTwipToMm100(aRet.Bottom);
103 : }
104 :
105 :
106 0 : rVal <<= aRet;
107 0 : return true;
108 : }
109 :
110 0 : bool SvxGrfCrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
111 : {
112 0 : bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
113 0 : nMemberId &= ~CONVERT_TWIPS;
114 0 : text::GraphicCrop aVal;
115 :
116 0 : if(!(rVal >>= aVal))
117 0 : return false;
118 0 : if( bConvert )
119 : {
120 0 : aVal.Right = convertMm100ToTwip(aVal.Right );
121 0 : aVal.Top = convertMm100ToTwip(aVal.Top );
122 0 : aVal.Left = convertMm100ToTwip(aVal.Left );
123 0 : aVal.Bottom = convertMm100ToTwip(aVal.Bottom);
124 : }
125 :
126 0 : nLeft = aVal.Left ;
127 0 : nRight = aVal.Right ;
128 0 : nTop = aVal.Top ;
129 0 : nBottom = aVal.Bottom;
130 0 : return true;
131 : }
132 :
133 0 : SfxItemPresentation SvxGrfCrop::GetPresentation(
134 : SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
135 : OUString &rText, const IntlWrapper* pIntl ) const
136 : {
137 0 : rText = OUString();
138 0 : switch( ePres )
139 : {
140 : case SFX_ITEM_PRESENTATION_NAMELESS:
141 : case SFX_ITEM_PRESENTATION_COMPLETE:
142 0 : if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
143 : {
144 0 : rText = "L: " + OUString(::GetMetricText( GetLeft(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
145 0 : " R: " + OUString(::GetMetricText( GetRight(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
146 0 : " T: " + OUString(::GetMetricText( GetTop(), eCoreUnit, SFX_MAPUNIT_MM, pIntl )) +
147 0 : " B: " + OUString(::GetMetricText( GetBottom(), eCoreUnit, SFX_MAPUNIT_MM, pIntl ));
148 : }
149 0 : break;
150 :
151 : default:
152 0 : ePres = SFX_ITEM_PRESENTATION_NONE;
153 0 : break;
154 : }
155 0 : return ePres;
156 : }
157 :
158 :
159 :
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|