fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / addruno.cxx
blob9a8a759adf9cd7a0ce123fea26651de944bdf8b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/table/CellAddress.hpp>
21 #include <com/sun/star/table/CellRangeAddress.hpp>
22 #include <cppuhelper/supportsservice.hxx>
24 #include <svl/itemprop.hxx>
25 #include <vcl/svapp.hxx>
27 #include "docsh.hxx"
28 #include "unonames.hxx"
29 #include "miscuno.hxx"
30 #include "convuno.hxx"
31 #include "addruno.hxx"
33 using namespace com::sun::star;
35 ScAddressConversionObj::ScAddressConversionObj(ScDocShell* pDocSh, bool _bIsRange) :
36 pDocShell( pDocSh ),
37 nRefSheet( 0 ),
38 bIsRange( _bIsRange )
40 pDocShell->GetDocument().AddUnoObject(*this);
43 ScAddressConversionObj::~ScAddressConversionObj()
45 SolarMutexGuard g;
47 if (pDocShell)
48 pDocShell->GetDocument().RemoveUnoObject(*this);
51 void ScAddressConversionObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
53 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>( &rHint );
54 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
56 pDocShell = NULL; // invalid
60 bool ScAddressConversionObj::ParseUIString( const OUString& rUIString, ::formula::FormulaGrammar::AddressConvention eConv )
62 if (!pDocShell)
63 return false;
65 ScDocument& rDoc = pDocShell->GetDocument();
66 bool bSuccess = false;
67 if ( bIsRange )
69 sal_uInt16 nResult = aRange.ParseAny( rUIString, &rDoc, eConv );
70 if ( nResult & SCA_VALID )
72 if ( ( nResult & SCA_TAB_3D ) == 0 )
73 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
74 if ( ( nResult & SCA_TAB2_3D ) == 0 )
75 aRange.aEnd.SetTab( aRange.aStart.Tab() );
76 // different sheets are not supported in CellRangeAddress
77 if ( aRange.aStart.Tab() == aRange.aEnd.Tab() )
78 bSuccess = true;
81 else
83 sal_uInt16 nResult = aRange.aStart.Parse( rUIString, &rDoc, eConv );
84 if ( nResult & SCA_VALID )
86 if ( ( nResult & SCA_TAB_3D ) == 0 )
87 aRange.aStart.SetTab( static_cast<SCTAB>(nRefSheet) );
88 bSuccess = true;
91 return bSuccess;
94 // XPropertySet
96 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAddressConversionObj::getPropertySetInfo()
97 throw(uno::RuntimeException, std::exception)
99 SolarMutexGuard aGuard;
101 if ( bIsRange )
103 static const SfxItemPropertyMapEntry aPropertyMap[] =
105 { OUString(SC_UNONAME_ADDRESS), 0, cppu::UnoType<table::CellRangeAddress>::get(), 0, 0 },
106 { OUString(SC_UNONAME_PERSREPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
107 { OUString(SC_UNONAME_XLA1REPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
108 { OUString(SC_UNONAME_REFSHEET), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
109 { OUString(SC_UNONAME_UIREPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
110 { OUString(SC_UNONAME_XLA1REPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
111 { OUString(), 0, css::uno::Type(), 0, 0 }
113 static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
114 return aRef;
116 else
118 static const SfxItemPropertyMapEntry aPropertyMap[] =
120 { OUString(SC_UNONAME_ADDRESS), 0, cppu::UnoType<table::CellAddress>::get(), 0, 0 },
121 { OUString(SC_UNONAME_PERSREPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
122 { OUString(SC_UNONAME_XLA1REPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
123 { OUString(SC_UNONAME_REFSHEET), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
124 { OUString(SC_UNONAME_UIREPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
125 { OUString(SC_UNONAME_XLA1REPR), 0, cppu::UnoType<OUString>::get(), 0, 0 },
126 { OUString(), 0, css::uno::Type(), 0, 0 }
128 static uno::Reference<beans::XPropertySetInfo> aRef(new SfxItemPropertySetInfo( aPropertyMap ));
129 return aRef;
133 void SAL_CALL ScAddressConversionObj::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
134 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
135 lang::IllegalArgumentException, lang::WrappedTargetException,
136 uno::RuntimeException, std::exception)
138 if ( !pDocShell )
139 throw uno::RuntimeException();
141 bool bSuccess = false;
142 OUString aNameStr(aPropertyName);
143 if ( aNameStr == SC_UNONAME_ADDRESS )
145 // read the cell/range address from API struct
146 if ( bIsRange )
148 table::CellRangeAddress aRangeAddress;
149 if ( aValue >>= aRangeAddress )
151 ScUnoConversion::FillScRange( aRange, aRangeAddress );
152 bSuccess = true;
155 else
157 table::CellAddress aCellAddress;
158 if ( aValue >>= aCellAddress )
160 ScUnoConversion::FillScAddress( aRange.aStart, aCellAddress );
161 bSuccess = true;
165 else if ( aNameStr == SC_UNONAME_REFSHEET )
167 // set the reference sheet
168 sal_Int32 nIntVal = 0;
169 if ( aValue >>= nIntVal )
171 nRefSheet = nIntVal;
172 bSuccess = true;
175 else if ( aNameStr == SC_UNONAME_UIREPR )
177 // parse the UI representation string
178 OUString sRepresentation;
179 if (aValue >>= sRepresentation)
181 OUString aUIString = sRepresentation;
182 bSuccess = ParseUIString( aUIString );
185 else if ( aNameStr == SC_UNONAME_PERSREPR || aNameStr == SC_UNONAME_XLA1REPR )
187 ::formula::FormulaGrammar::AddressConvention eConv = aNameStr == SC_UNONAME_XLA1REPR ?
188 ::formula::FormulaGrammar::CONV_XL_A1 : ::formula::FormulaGrammar::CONV_OOO;
190 // parse the file format string
191 OUString sRepresentation;
192 if (aValue >>= sRepresentation)
194 OUString aUIString(sRepresentation);
196 // cell or range: strip a single "." at the start
197 if ( aUIString[0]== (sal_Unicode) '.' )
198 aUIString = aUIString.copy( 1 );
200 if ( bIsRange )
202 // range: also strip a "." after the last colon
203 sal_Int32 nColon = OUString(aUIString).lastIndexOf( (sal_Unicode) ':' );
204 if ( nColon >= 0 && nColon < aUIString.getLength() - 1 &&
205 aUIString[nColon+1] == '.' )
206 aUIString = aUIString.replaceAt( nColon+1, 1, "" );
209 // parse the rest like a UI string
210 bSuccess = ParseUIString( aUIString, eConv );
213 else
214 throw beans::UnknownPropertyException();
216 if ( !bSuccess )
217 throw lang::IllegalArgumentException();
220 uno::Any SAL_CALL ScAddressConversionObj::getPropertyValue( const OUString& aPropertyName )
221 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
222 uno::RuntimeException, std::exception)
224 if ( !pDocShell )
225 throw uno::RuntimeException();
227 ScDocument& rDoc = pDocShell->GetDocument();
228 uno::Any aRet;
230 OUString aNameStr(aPropertyName);
231 if ( aNameStr == SC_UNONAME_ADDRESS )
233 if ( bIsRange )
235 table::CellRangeAddress aRangeAddress;
236 ScUnoConversion::FillApiRange( aRangeAddress, aRange );
237 aRet <<= aRangeAddress;
239 else
241 table::CellAddress aCellAddress;
242 ScUnoConversion::FillApiAddress( aCellAddress, aRange.aStart );
243 aRet <<= aCellAddress;
246 else if ( aNameStr == SC_UNONAME_REFSHEET )
248 aRet <<= nRefSheet;
250 else if ( aNameStr == SC_UNONAME_UIREPR )
252 // generate UI representation string - include sheet only if different from ref sheet
253 OUString aFormatStr;
254 sal_uInt16 nFlags = SCA_VALID;
255 if ( aRange.aStart.Tab() != nRefSheet )
256 nFlags |= SCA_TAB_3D;
257 if ( bIsRange )
258 aFormatStr = aRange.Format(nFlags, &rDoc);
259 else
260 aFormatStr = aRange.aStart.Format(nFlags, &rDoc);
261 aRet <<= aFormatStr;
263 else if ( aNameStr == SC_UNONAME_PERSREPR || aNameStr == SC_UNONAME_XLA1REPR )
265 ::formula::FormulaGrammar::AddressConvention eConv = aNameStr == SC_UNONAME_XLA1REPR ?
266 ::formula::FormulaGrammar::CONV_XL_A1 : ::formula::FormulaGrammar::CONV_OOO;
268 // generate file format string - always include sheet
269 OUString aFormatStr(aRange.aStart.Format(SCA_VALID | SCA_TAB_3D, &rDoc, eConv));
270 if ( bIsRange )
272 // manually concatenate range so both parts always have the sheet name
273 aFormatStr += ":";
274 sal_uInt16 nFlags = SCA_VALID;
275 if( eConv != ::formula::FormulaGrammar::CONV_XL_A1 )
276 nFlags |= SCA_TAB_3D;
277 OUString aSecond(aRange.aEnd.Format(nFlags, &rDoc, eConv));
278 aFormatStr += aSecond ;
280 aRet <<= OUString( aFormatStr );
282 else
283 throw beans::UnknownPropertyException();
285 return aRet;
288 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAddressConversionObj )
290 // lang::XServiceInfo
292 OUString SAL_CALL ScAddressConversionObj::getImplementationName() throw(uno::RuntimeException, std::exception)
294 return OUString("ScAddressConversionObj" );
297 sal_Bool SAL_CALL ScAddressConversionObj::supportsService( const OUString& rServiceName )
298 throw(uno::RuntimeException, std::exception)
300 return cppu::supportsService(this, rServiceName);
303 uno::Sequence<OUString> SAL_CALL ScAddressConversionObj::getSupportedServiceNames()
304 throw(uno::RuntimeException, std::exception)
306 uno::Sequence<OUString> aRet(1);
307 OUString* pArray = aRet.getArray();
308 pArray[0] = bIsRange ? OUString(SC_SERVICENAME_RANGEADDRESS)
309 : OUString(SC_SERVICENAME_CELLADDRESS);
310 return aRet;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */