1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_VBA_HYPERLINKS_HXX 25cdf0e10cSrcweir #define SC_VBA_HYPERLINKS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <ooo/vba/excel/XHyperlinks.hpp> 28cdf0e10cSrcweir #include <rtl/ref.hxx> 29cdf0e10cSrcweir #include <vbahelper/vbacollectionimpl.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir class ScRangeList; 32cdf0e10cSrcweir 33cdf0e10cSrcweir // ============================================================================ 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace detail { 36cdf0e10cSrcweir 37cdf0e10cSrcweir class ScVbaHlinkContainer; 38cdf0e10cSrcweir typedef ::rtl::Reference< ScVbaHlinkContainer > ScVbaHlinkContainerRef; 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** Base class for ScVbaHyperlinks to get an initialized ScVbaHlinkContainer 41cdf0e10cSrcweir class member before the ScVbaHyperlinks_BASE base class will be constructed. 42cdf0e10cSrcweir */ 43cdf0e10cSrcweir struct ScVbaHlinkContainerMember 44cdf0e10cSrcweir { 45cdf0e10cSrcweir ScVbaHlinkContainerRef mxContainer; 46cdf0e10cSrcweir 47cdf0e10cSrcweir explicit ScVbaHlinkContainerMember( ScVbaHlinkContainer* pContainer ); 48cdf0e10cSrcweir ~ScVbaHlinkContainerMember(); 49cdf0e10cSrcweir }; 50cdf0e10cSrcweir 51cdf0e10cSrcweir } // namespace detail 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ============================================================================ 54cdf0e10cSrcweir 55cdf0e10cSrcweir class ScVbaHyperlinks; 56cdf0e10cSrcweir typedef ::rtl::Reference< ScVbaHyperlinks > ScVbaHyperlinksRef; 57cdf0e10cSrcweir 58cdf0e10cSrcweir typedef CollTestImplHelper< ov::excel::XHyperlinks > ScVbaHyperlinks_BASE; 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** Represents a collection of hyperlinks of a worksheet or of a range. 61cdf0e10cSrcweir 62cdf0e10cSrcweir When a Hyperlinks collection object has been constructed from a VBA 63cdf0e10cSrcweir Worksheet object, it will always represent the current set of all 64cdf0e10cSrcweir hyperlinks existing in the sheet. Insertion and deletion of hyperlinks will 65cdf0e10cSrcweir be reflected by the instance. 66cdf0e10cSrcweir 67cdf0e10cSrcweir When a Hyperlinks collection object has been constructed from a VBA Range 68cdf0e10cSrcweir object, it will represent the set of hyperlinks that have existed at its 69cdf0e10cSrcweir construction time, and that are located completely inside the range(s) 70cdf0e10cSrcweir represented by the Range object. Insertion and deletion of hyperlinks will 71cdf0e10cSrcweir *not* be reflected by that instance. The instance will always offer all 72cdf0e10cSrcweir hyperlinks it has been constructed with, even if they no longer exist. 73cdf0e10cSrcweir Furthermore, the instance will not offer hyperlinks inserted later, even if 74cdf0e10cSrcweir the instance itself has been used to insert the new hyperlinks. 75cdf0e10cSrcweir 76cdf0e10cSrcweir VBA code example: 77cdf0e10cSrcweir 78cdf0e10cSrcweir With ThisWorkbook.Worksheets(1) 79cdf0e10cSrcweir 80cdf0e10cSrcweir Set hlinks = .Hyperlinks ' global Hyperlinks object 81cdf0e10cSrcweir Set myrange = .Range("A1:C3") 82cdf0e10cSrcweir Set rangelinks1 = myrange.Hyperlinks ' hyperlinks of range A1:C3 83cdf0e10cSrcweir 84cdf0e10cSrcweir MsgBox hlinks.Count ' 0 85cdf0e10cSrcweir MsgBox rangelinks1.Count ' 0 86cdf0e10cSrcweir 87cdf0e10cSrcweir hlinks.Add .Range("A1"), "http://example.com" 88cdf0e10cSrcweir ' a new hyperlink has been added in cell A1 89cdf0e10cSrcweir 90cdf0e10cSrcweir MsgBox hlinks.Count ' 1 91cdf0e10cSrcweir MsgBox rangelinks1.Count ' still 0! 92cdf0e10cSrcweir Set rangelinks2 = myrange.Hyperlinks ' hyperlinks of range A1:C3 93cdf0e10cSrcweir MsgBox rangelinks2.Count ' 1 (constructed after Add) 94cdf0e10cSrcweir 95cdf0e10cSrcweir rangelinks1.Add .Range("A2"), "http://example.com" 96cdf0e10cSrcweir ' a new hyperlink has been constructed via the rangelinks1 object 97cdf0e10cSrcweir ' but this addition has been done by the worksheet Hyperlinks object 98cdf0e10cSrcweir 99cdf0e10cSrcweir MsgBox hlinks.Count ' 2 100cdf0e10cSrcweir MsgBox rangelinks1.Count ' still 0!!! 101cdf0e10cSrcweir MsgBox rangelinks2.Count ' still 1!!! 102cdf0e10cSrcweir MsgBox myrange.Hyperlinks.Count ' 2 (constructed after Add) 103cdf0e10cSrcweir 104cdf0e10cSrcweir End With 105cdf0e10cSrcweir */ 106cdf0e10cSrcweir class ScVbaHyperlinks : private detail::ScVbaHlinkContainerMember, public ScVbaHyperlinks_BASE 107cdf0e10cSrcweir { 108cdf0e10cSrcweir public: 109cdf0e10cSrcweir explicit ScVbaHyperlinks( 110cdf0e10cSrcweir const css::uno::Reference< ov::XHelperInterface >& rxParent, 111cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext >& rxContext ) throw (css::uno::RuntimeException); 112cdf0e10cSrcweir 113cdf0e10cSrcweir explicit ScVbaHyperlinks( 114cdf0e10cSrcweir const css::uno::Reference< ov::XHelperInterface >& rxParent, 115cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext >& rxContext, 116cdf0e10cSrcweir const ScVbaHyperlinksRef& rxSheetHlinks, const ScRangeList& rScRanges ) throw (css::uno::RuntimeException); 117cdf0e10cSrcweir 118cdf0e10cSrcweir virtual ~ScVbaHyperlinks(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir // XHyperlinks 121cdf0e10cSrcweir virtual css::uno::Reference< ov::excel::XHyperlink > SAL_CALL Add( 122cdf0e10cSrcweir const css::uno::Any& rAnchor, const css::uno::Any& rAddress, const css::uno::Any& rSubAddress, 123cdf0e10cSrcweir const css::uno::Any& rScreenTip, const css::uno::Any& rTextToDisplay ) 124cdf0e10cSrcweir throw (css::uno::RuntimeException); 125cdf0e10cSrcweir 126cdf0e10cSrcweir virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); 127cdf0e10cSrcweir 128cdf0e10cSrcweir // XEnumerationAccess 129cdf0e10cSrcweir virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // XElementAccess 132cdf0e10cSrcweir virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); 133cdf0e10cSrcweir 134cdf0e10cSrcweir // ScVbaCollectionBase 135cdf0e10cSrcweir virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir // XHelperInterface 138cdf0e10cSrcweir VBAHELPER_DECL_XHELPERINTERFACE 139cdf0e10cSrcweir 140cdf0e10cSrcweir private: 141cdf0e10cSrcweir ScVbaHyperlinksRef mxSheetHlinks; 142cdf0e10cSrcweir }; 143cdf0e10cSrcweir 144cdf0e10cSrcweir // ============================================================================ 145cdf0e10cSrcweir 146cdf0e10cSrcweir #endif 147