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