fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / docshell / servobj.cxx
blob8fddc9b7442789dfab832331cb31fc34878f5683
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 <sot/formats.hxx>
21 #include <sfx2/app.hxx>
22 #include <sfx2/linkmgr.hxx>
23 #include "servobj.hxx"
24 #include "docsh.hxx"
25 #include "impex.hxx"
26 #include "brdcst.hxx"
27 #include "rangenam.hxx"
28 #include "sc.hrc"
30 using namespace formula;
32 static bool lcl_FillRangeFromName( ScRange& rRange, ScDocShell* pDocSh, const OUString& rName )
34 if (pDocSh)
36 ScDocument& rDoc = pDocSh->GetDocument();
37 ScRangeName* pNames = rDoc.GetRangeName();
38 if (pNames)
40 const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(rName));
41 if (pData)
43 if ( pData->IsValidReference( rRange ) )
44 return true;
48 return false;
51 ScServerObjectSvtListenerForwarder::ScServerObjectSvtListenerForwarder(
52 ScServerObject* pObjP)
53 : pObj(pObjP)
57 ScServerObjectSvtListenerForwarder::~ScServerObjectSvtListenerForwarder()
59 //! do NOT access pObj
62 void ScServerObjectSvtListenerForwarder::Notify( const SfxHint& rHint )
64 pObj->Notify( aBroadcaster, rHint);
67 ScServerObject::ScServerObject( ScDocShell* pShell, const OUString& rItem ) :
68 aForwarder( this ),
69 pDocSh( pShell ),
70 bRefreshListener( false )
72 // parse item string
74 if ( lcl_FillRangeFromName( aRange, pDocSh, rItem ) )
76 aItemStr = rItem; // must be parsed again on ref update
78 else
80 // parse ref
81 ScDocument& rDoc = pDocSh->GetDocument();
82 SCTAB nTab = ScDocShell::GetCurTab();
83 aRange.aStart.SetTab( nTab );
85 // For DDE link, we always must parse references using OOO A1 convention.
87 if ( aRange.Parse( rItem, &rDoc, FormulaGrammar::CONV_OOO ) & SCA_VALID )
89 // area reference
91 else if ( aRange.aStart.Parse( rItem, &rDoc, FormulaGrammar::CONV_OOO ) & SCA_VALID )
93 // cell reference
94 aRange.aEnd = aRange.aStart;
96 else
98 OSL_FAIL("ScServerObject: invalid item");
102 pDocSh->GetDocument().GetLinkManager()->InsertServer( this );
103 pDocSh->GetDocument().StartListeningArea( aRange, false, &aForwarder );
105 StartListening(*pDocSh); // um mitzubekommen, wenn die DocShell geloescht wird
106 StartListening(*SfxGetpApp()); // for SC_HINT_AREAS_CHANGED
109 ScServerObject::~ScServerObject()
111 Clear();
114 void ScServerObject::Clear()
116 if (pDocSh)
118 ScDocShell* pTemp = pDocSh;
119 pDocSh = NULL;
121 pTemp->GetDocument().EndListeningArea(aRange, false, &aForwarder);
122 pTemp->GetDocument().GetLinkManager()->RemoveServer( this );
123 EndListening(*pTemp);
124 EndListening(*SfxGetpApp());
128 void ScServerObject::EndListeningAll()
130 aForwarder.EndListeningAll();
131 SfxListener::EndListeningAll();
134 bool ScServerObject::GetData(
135 ::com::sun::star::uno::Any & rData /*out param*/,
136 const OUString & rMimeType, bool /* bSynchron */ )
138 if (!pDocSh)
139 return false;
141 // named ranges may have changed -> update aRange
142 if ( !aItemStr.isEmpty() )
144 ScRange aNew;
145 if ( lcl_FillRangeFromName( aNew, pDocSh, aItemStr ) && aNew != aRange )
147 aRange = aNew;
148 bRefreshListener = true;
152 if ( bRefreshListener )
154 // refresh the listeners now (this is called from a timer)
156 EndListeningAll();
157 pDocSh->GetDocument().StartListeningArea( aRange, false, &aForwarder );
158 StartListening(*pDocSh);
159 StartListening(*SfxGetpApp());
160 bRefreshListener = false;
163 OUString aDdeTextFmt = pDocSh->GetDdeTextFmt();
164 ScDocument& rDoc = pDocSh->GetDocument();
166 if( SotClipboardFormatId::STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ))
168 ScImportExport aObj( &rDoc, aRange );
169 if( aDdeTextFmt[0] == 'F' )
170 aObj.SetFormulas( true );
171 if( aDdeTextFmt == "SYLK" || aDdeTextFmt == "FSYLK" )
173 OString aByteData;
174 if( aObj.ExportByteString( aByteData, osl_getThreadTextEncoding(), SotClipboardFormatId::SYLK ) )
176 rData <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
177 reinterpret_cast<const sal_Int8*>(aByteData.getStr()),
178 aByteData.getLength() + 1 );
179 return true;
181 return false;
183 if( aDdeTextFmt == "CSV" || aDdeTextFmt == "FCSV" )
184 aObj.SetSeparator( ',' );
185 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, ' ', false ) );
186 return aObj.ExportData( rMimeType, rData );
189 ScImportExport aObj( &rDoc, aRange );
190 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, ' ', false ) );
191 if( aObj.IsRef() )
192 return aObj.ExportData( rMimeType, rData );
193 return false;
196 void ScServerObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
198 bool bDataChanged = false;
200 // DocShell can't be tested via type info, because SFX_HINT_DYING comes from the dtor
201 if ( &rBC == pDocSh )
203 // from DocShell, only SFX_HINT_DYING is interesting
204 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>( &rHint );
205 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
207 pDocSh = NULL;
208 EndListening(*SfxGetpApp());
209 // don't access DocShell anymore for EndListening etc.
212 else if (rBC.ISA(SfxApplication))
214 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>( &rHint );
215 if ( !aItemStr.isEmpty() && pSimpleHint &&
216 pSimpleHint->GetId() == SC_HINT_AREAS_CHANGED )
218 // check if named range was modified
219 ScRange aNew;
220 if ( lcl_FillRangeFromName( aNew, pDocSh, aItemStr ) && aNew != aRange )
221 bDataChanged = true;
224 else
226 // must be from Area broadcasters
228 const ScHint* pScHint = dynamic_cast<const ScHint*>( &rHint );
229 if (pScHint && (pScHint->GetId() & SC_HINT_DATACHANGED))
230 bDataChanged = true;
231 else if ( dynamic_cast<const ScAreaChangedHint*>(&rHint) ) // position of broadcaster changed
233 ScRange aNewRange = static_cast<const ScAreaChangedHint&>(rHint).GetRange();
234 if ( aRange != aNewRange )
236 bRefreshListener = true;
237 bDataChanged = true;
240 else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) )
242 sal_uLong nId = static_cast<const SfxSimpleHint&>(rHint).GetId();
243 if (nId == SFX_HINT_DYING)
245 // If the range is being deleted, listening must be restarted
246 // after the deletion is complete (done in GetData)
247 bRefreshListener = true;
248 bDataChanged = true;
253 if ( bDataChanged && HasDataLinks() )
254 SvLinkSource::NotifyDataChanged();
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */