1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_LINKUNO_HXX 25 #define SC_LINKUNO_HXX 26 27 #include <svl/lstner.hxx> 28 #include <svl/itemprop.hxx> 29 #include <com/sun/star/sheet/XDDELink.hpp> 30 #include <com/sun/star/sheet/XDDELinkResults.hpp> 31 #include <com/sun/star/sheet/XDDELinks.hpp> 32 #include <com/sun/star/sheet/XExternalDocLink.hpp> 33 #include <com/sun/star/sheet/XExternalDocLinks.hpp> 34 #include <com/sun/star/sheet/XExternalSheetCache.hpp> 35 #include <com/sun/star/sheet/XAreaLink.hpp> 36 #include <com/sun/star/sheet/XAreaLinks.hpp> 37 #include <com/sun/star/util/XRefreshable.hpp> 38 #include <com/sun/star/lang/XServiceInfo.hpp> 39 #include <com/sun/star/beans/XPropertySet.hpp> 40 #include <com/sun/star/container/XEnumerationAccess.hpp> 41 #include <com/sun/star/container/XNameAccess.hpp> 42 #include <com/sun/star/container/XIndexAccess.hpp> 43 #include <com/sun/star/container/XNamed.hpp> 44 #include <cppuhelper/implbase1.hxx> 45 #include <cppuhelper/implbase3.hxx> 46 #include <cppuhelper/implbase4.hxx> 47 #include <cppuhelper/implbase5.hxx> 48 49 #include "externalrefmgr.hxx" 50 51 #include <hash_map> 52 #include <vector> 53 54 class ScAreaLink; 55 class ScDocShell; 56 class ScTableLink; 57 58 typedef ::com::sun::star::uno::Reference< 59 ::com::sun::star::util::XRefreshListener >* XRefreshListenerPtr; 60 SV_DECL_PTRARR_DEL( XRefreshListenerArr_Impl, XRefreshListenerPtr, 4, 4 ) 61 62 63 64 class ScSheetLinkObj : public cppu::WeakImplHelper4< 65 com::sun::star::container::XNamed, 66 com::sun::star::util::XRefreshable, 67 com::sun::star::beans::XPropertySet, 68 com::sun::star::lang::XServiceInfo >, 69 public SfxListener 70 { 71 private: 72 SfxItemPropertySet aPropSet; 73 ScDocShell* pDocShell; 74 String aFileName; 75 XRefreshListenerArr_Impl aRefreshListeners; 76 77 ScTableLink* GetLink_Impl() const; 78 void Refreshed_Impl(); 79 void ModifyRefreshDelay_Impl( sal_Int32 nRefresh ); 80 81 public: 82 ScSheetLinkObj(ScDocShell* pDocSh, const String& rName); 83 virtual ~ScSheetLinkObj(); 84 85 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 86 87 // XNamed 88 virtual ::rtl::OUString SAL_CALL getName(); 89 virtual void SAL_CALL setName( const ::rtl::OUString& aName ); 90 91 // XRefreshable 92 virtual void SAL_CALL refresh(); 93 virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< 94 ::com::sun::star::util::XRefreshListener >& l ); 95 virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< 96 ::com::sun::star::util::XRefreshListener >& l ); 97 98 // XPropertySet 99 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > 100 SAL_CALL getPropertySetInfo( ); 101 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, 102 const ::com::sun::star::uno::Any& aValue ); 103 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( 104 const ::rtl::OUString& PropertyName ); 105 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, 106 const ::com::sun::star::uno::Reference< 107 ::com::sun::star::beans::XPropertyChangeListener >& xListener ); 108 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, 109 const ::com::sun::star::uno::Reference< 110 ::com::sun::star::beans::XPropertyChangeListener >& aListener ); 111 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, 112 const ::com::sun::star::uno::Reference< 113 ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 114 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, 115 const ::com::sun::star::uno::Reference< 116 ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 117 118 // aus get/setPropertyValue gerufen: 119 ::rtl::OUString getFileName(void) const; 120 void setFileName(const ::rtl::OUString& FileName); 121 ::rtl::OUString getFilter(void) const; 122 void setFilter(const ::rtl::OUString& Filter); 123 ::rtl::OUString getFilterOptions(void) const; 124 void setFilterOptions(const ::rtl::OUString& FilterOptions); 125 sal_Int32 getRefreshDelay(void) const; 126 void setRefreshDelay(sal_Int32 nRefreshDelay); 127 128 // XServiceInfo 129 virtual ::rtl::OUString SAL_CALL getImplementationName(); 130 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 131 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 132 }; 133 134 135 class ScSheetLinksObj : public cppu::WeakImplHelper4< 136 com::sun::star::container::XNameAccess, 137 com::sun::star::container::XEnumerationAccess, 138 com::sun::star::container::XIndexAccess, 139 com::sun::star::lang::XServiceInfo >, 140 public SfxListener 141 { 142 private: 143 ScDocShell* pDocShell; 144 145 ScSheetLinkObj* GetObjectByIndex_Impl(sal_Int32 nIndex); 146 ScSheetLinkObj* GetObjectByName_Impl(const ::rtl::OUString& aName); 147 148 public: 149 ScSheetLinksObj(ScDocShell* pDocSh); 150 virtual ~ScSheetLinksObj(); 151 152 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 153 154 // XNameAccess 155 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 156 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(); 157 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 158 159 // XIndexAccess 160 virtual sal_Int32 SAL_CALL getCount(); 161 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index ); 162 163 // XEnumerationAccess 164 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL 165 createEnumeration(); 166 167 // XElementAccess 168 virtual ::com::sun::star::uno::Type SAL_CALL getElementType(); 169 virtual sal_Bool SAL_CALL hasElements(); 170 171 // XServiceInfo 172 virtual ::rtl::OUString SAL_CALL getImplementationName(); 173 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 174 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 175 }; 176 177 178 class ScAreaLinkObj : public cppu::WeakImplHelper4< 179 com::sun::star::sheet::XAreaLink, 180 com::sun::star::util::XRefreshable, 181 com::sun::star::beans::XPropertySet, 182 com::sun::star::lang::XServiceInfo >, 183 public SfxListener 184 { 185 private: 186 SfxItemPropertySet aPropSet; 187 ScDocShell* pDocShell; 188 sal_uInt16 nPos; 189 XRefreshListenerArr_Impl aRefreshListeners; 190 191 void Modify_Impl( const ::rtl::OUString* pNewFile, const ::rtl::OUString* pNewFilter, 192 const ::rtl::OUString* pNewOptions, const ::rtl::OUString* pNewSource, 193 const com::sun::star::table::CellRangeAddress* pNewDest ); 194 void ModifyRefreshDelay_Impl( sal_Int32 nRefresh ); 195 void Refreshed_Impl(); 196 197 public: 198 ScAreaLinkObj(ScDocShell* pDocSh, sal_uInt16 nP); 199 virtual ~ScAreaLinkObj(); 200 201 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 202 203 // XRefreshable 204 virtual void SAL_CALL refresh(); 205 virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< 206 ::com::sun::star::util::XRefreshListener >& l ); 207 virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< 208 ::com::sun::star::util::XRefreshListener >& l ); 209 210 // XPropertySet 211 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > 212 SAL_CALL getPropertySetInfo( ); 213 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, 214 const ::com::sun::star::uno::Any& aValue ); 215 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( 216 const ::rtl::OUString& PropertyName ); 217 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, 218 const ::com::sun::star::uno::Reference< 219 ::com::sun::star::beans::XPropertyChangeListener >& xListener ); 220 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, 221 const ::com::sun::star::uno::Reference< 222 ::com::sun::star::beans::XPropertyChangeListener >& aListener ); 223 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, 224 const ::com::sun::star::uno::Reference< 225 ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 226 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, 227 const ::com::sun::star::uno::Reference< 228 ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 229 230 // aus get/setPropertyValue gerufen: 231 ::rtl::OUString getFileName(void) const; 232 void setFileName(const ::rtl::OUString& FileName); 233 ::rtl::OUString getFilter(void) const; 234 void setFilter(const ::rtl::OUString& Filter); 235 ::rtl::OUString getFilterOptions(void) const; 236 void setFilterOptions(const ::rtl::OUString& FilterOptions); 237 sal_Int32 getRefreshDelay(void) const; 238 void setRefreshDelay(sal_Int32 nRefreshDelay); 239 240 // XAreaLink 241 virtual ::rtl::OUString SAL_CALL getSourceArea(); 242 virtual void SAL_CALL setSourceArea( const ::rtl::OUString& aSourceArea ); 243 virtual ::com::sun::star::table::CellRangeAddress SAL_CALL getDestArea(); 244 virtual void SAL_CALL setDestArea( const ::com::sun::star::table::CellRangeAddress& aDestArea ); 245 246 // XServiceInfo 247 virtual ::rtl::OUString SAL_CALL getImplementationName(); 248 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 249 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 250 }; 251 252 253 class ScAreaLinksObj : public cppu::WeakImplHelper3< 254 com::sun::star::sheet::XAreaLinks, 255 com::sun::star::container::XEnumerationAccess, 256 com::sun::star::lang::XServiceInfo >, 257 public SfxListener 258 { 259 private: 260 ScDocShell* pDocShell; 261 262 ScAreaLinkObj* GetObjectByIndex_Impl(sal_Int32 nIndex); 263 264 public: 265 ScAreaLinksObj(ScDocShell* pDocSh); 266 virtual ~ScAreaLinksObj(); 267 268 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 269 270 // XAreaLinks 271 virtual void SAL_CALL insertAtPosition( const ::com::sun::star::table::CellAddress& aDestPos, 272 const ::rtl::OUString& aFileName, 273 const ::rtl::OUString& aSourceArea, 274 const ::rtl::OUString& aFilter, 275 const ::rtl::OUString& aFilterOptions ); 276 virtual void SAL_CALL removeByIndex( sal_Int32 nIndex ); 277 278 // XIndexAccess 279 virtual sal_Int32 SAL_CALL getCount(); 280 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index ); 281 282 // XEnumerationAccess 283 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL 284 createEnumeration(); 285 286 // XElementAccess 287 virtual ::com::sun::star::uno::Type SAL_CALL getElementType(); 288 virtual sal_Bool SAL_CALL hasElements(); 289 290 // XServiceInfo 291 virtual ::rtl::OUString SAL_CALL getImplementationName(); 292 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 293 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 294 }; 295 296 297 //! order of XNamed and DDELink changed to avoid "duplicate comdat" symbols 298 299 class ScDDELinkObj : public cppu::WeakImplHelper5< 300 com::sun::star::sheet::XDDELink, 301 com::sun::star::container::XNamed, 302 com::sun::star::util::XRefreshable, 303 com::sun::star::sheet::XDDELinkResults, 304 com::sun::star::lang::XServiceInfo >, 305 public SfxListener 306 { 307 private: 308 ScDocShell* pDocShell; 309 String aAppl; 310 String aTopic; 311 String aItem; 312 XRefreshListenerArr_Impl aRefreshListeners; 313 314 void Refreshed_Impl(); 315 316 public: 317 ScDDELinkObj(ScDocShell* pDocSh, const String& rA, 318 const String& rT, const String& rI); 319 virtual ~ScDDELinkObj(); 320 321 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 322 323 // XNamed 324 virtual ::rtl::OUString SAL_CALL getName(); 325 virtual void SAL_CALL setName( const ::rtl::OUString& aName ); 326 327 // XDDELink 328 virtual ::rtl::OUString SAL_CALL getApplication(); 329 virtual ::rtl::OUString SAL_CALL getTopic(); 330 virtual ::rtl::OUString SAL_CALL getItem(); 331 332 // XRefreshable 333 virtual void SAL_CALL refresh(); 334 virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< 335 ::com::sun::star::util::XRefreshListener >& l ); 336 virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< 337 ::com::sun::star::util::XRefreshListener >& l ); 338 339 // XDDELinkResults 340 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > 341 SAL_CALL getResults( ); 342 virtual void SAL_CALL setResults( 343 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aResults ); 344 345 // XServiceInfo 346 virtual ::rtl::OUString SAL_CALL getImplementationName(); 347 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 348 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 349 }; 350 351 352 class ScDDELinksObj : public cppu::WeakImplHelper4< 353 com::sun::star::container::XEnumerationAccess, 354 com::sun::star::container::XIndexAccess, 355 com::sun::star::sheet::XDDELinks, 356 com::sun::star::lang::XServiceInfo >, 357 public SfxListener 358 { 359 private: 360 ScDocShell* pDocShell; 361 362 ScDDELinkObj* GetObjectByIndex_Impl(sal_Int32 nIndex); 363 ScDDELinkObj* GetObjectByName_Impl(const ::rtl::OUString& aName); 364 365 public: 366 ScDDELinksObj(ScDocShell* pDocSh); 367 virtual ~ScDDELinksObj(); 368 369 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 370 371 // XNameAccess 372 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 373 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(); 374 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 375 376 // XIndexAccess 377 virtual sal_Int32 SAL_CALL getCount(); 378 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index ); 379 380 // XEnumerationAccess 381 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL 382 createEnumeration(); 383 384 // XElementAccess 385 virtual ::com::sun::star::uno::Type SAL_CALL getElementType(); 386 virtual sal_Bool SAL_CALL hasElements(); 387 388 // XDDELinks 389 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDDELink > SAL_CALL addDDELink( 390 const ::rtl::OUString& aApplication, const ::rtl::OUString& aTopic, 391 const ::rtl::OUString& aItem, ::com::sun::star::sheet::DDELinkMode nMode ); 392 393 // XServiceInfo 394 virtual ::rtl::OUString SAL_CALL getImplementationName(); 395 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 396 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(); 397 }; 398 399 // ============================================================================ 400 401 class ScExternalSheetCacheObj : public cppu::WeakImplHelper1< ::com::sun::star::sheet::XExternalSheetCache > 402 { 403 public: 404 explicit ScExternalSheetCacheObj(ScExternalRefCache::TableTypeRef pTable, size_t nIndex); 405 ~ScExternalSheetCacheObj(); 406 407 // XExternalSheetCache 408 virtual void SAL_CALL setCellValue( 409 sal_Int32 nCol, sal_Int32 nRow, const ::com::sun::star::uno::Any& rAny); 410 411 virtual ::com::sun::star::uno::Any SAL_CALL getCellValue(sal_Int32 nCol, sal_Int32 nRow); 412 413 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getAllRows(); 414 415 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getAllColumns(sal_Int32 nRow); 416 417 // Attributes 418 virtual sal_Int32 SAL_CALL getTokenIndex(); 419 420 private: 421 ScExternalSheetCacheObj(); 422 ScExternalSheetCacheObj(const ScExternalSheetCacheObj&); 423 424 private: 425 ScExternalRefCache::TableTypeRef mpTable; 426 size_t mnIndex; 427 }; 428 429 // ============================================================================ 430 431 class ScExternalDocLinkObj : public cppu::WeakImplHelper1< ::com::sun::star::sheet::XExternalDocLink > 432 { 433 public: 434 ScExternalDocLinkObj(ScExternalRefManager* pRefMgr, sal_uInt16 nFileId); 435 ~ScExternalDocLinkObj(); 436 437 // XExternalDocLink 438 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache > 439 SAL_CALL addSheetCache( const ::rtl::OUString& aSheetName, sal_Bool bDynamicCache ); 440 441 // XNameAccess 442 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 443 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(); 444 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 445 446 // XIndexAccess 447 virtual sal_Int32 SAL_CALL getCount(); 448 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ); 449 450 // XEnumerationAccess 451 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL 452 createEnumeration(); 453 454 // XElementAccess 455 virtual ::com::sun::star::uno::Type SAL_CALL getElementType(); 456 virtual sal_Bool SAL_CALL hasElements(); 457 458 // Attributes 459 virtual sal_Int32 SAL_CALL getTokenIndex(); 460 461 private: 462 ScExternalRefManager* mpRefMgr; 463 sal_uInt16 mnFileId; 464 }; 465 466 // ============================================================================ 467 468 /** This is the UNO API equivalent of ScExternalRefManager. */ 469 class ScExternalDocLinksObj : public cppu::WeakImplHelper1< ::com::sun::star::sheet::XExternalDocLinks > 470 { 471 public: 472 ScExternalDocLinksObj(ScDocShell* pDocShell); 473 ~ScExternalDocLinksObj(); 474 475 // XExternalDocLinks 476 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalDocLink > 477 SAL_CALL addDocLink( const ::rtl::OUString& aDocName ); 478 479 // XNameAccess 480 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 481 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(); 482 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 483 484 // XIndexAccess 485 virtual sal_Int32 SAL_CALL getCount(); 486 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ); 487 488 // XEnumerationAccess 489 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL 490 createEnumeration(); 491 492 // XElementAccess 493 virtual ::com::sun::star::uno::Type SAL_CALL getElementType(); 494 virtual sal_Bool SAL_CALL hasElements(); 495 496 private: 497 ScExternalDocLinksObj(); 498 ScExternalDocLinksObj(const ScExternalDocLinksObj&); 499 500 private: 501 ScDocShell* mpDocShell; 502 ScExternalRefManager* mpRefMgr; 503 }; 504 505 #endif 506