| 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 | #pragma once |
| 21 | |
| 22 | #include <ooo/vba/excel/XHyperlinks.hpp> |
| 23 | #include <rtl/ref.hxx> |
| 24 | #include <vbahelper/vbacollectionimpl.hxx> |
| 25 | |
| 26 | class ScRangeList; |
| 27 | |
| 28 | namespace detail { |
| 29 | |
| 30 | class ScVbaHlinkContainer; |
| 31 | typedef ::rtl::Reference< ScVbaHlinkContainer > ScVbaHlinkContainerRef; |
| 32 | |
| 33 | /** Base class for ScVbaHyperlinks to get an initialized ScVbaHlinkContainer |
| 34 | class member before the ScVbaHyperlinks_BASE base class will be constructed. |
| 35 | */ |
| 36 | struct ScVbaHlinkContainerMember |
| 37 | { |
| 38 | ScVbaHlinkContainerRef mxContainer; |
| 39 | |
| 40 | explicit ScVbaHlinkContainerMember( ScVbaHlinkContainer* pContainer ); |
| 41 | ~ScVbaHlinkContainerMember(); |
| 42 | }; |
| 43 | |
| 44 | } // namespace detail |
| 45 | |
| 46 | class ScVbaHyperlinks; |
| 47 | typedef ::rtl::Reference< ScVbaHyperlinks > ScVbaHyperlinksRef; |
| 48 | |
| 49 | typedef CollTestImplHelper< ov::excel::XHyperlinks > ScVbaHyperlinks_BASE; |
| 50 | |
| 51 | /** Represents a collection of hyperlinks of a worksheet or of a range. |
| 52 | |
| 53 | When a Hyperlinks collection object has been constructed from a VBA |
| 54 | Worksheet object, it will always represent the current set of all |
| 55 | hyperlinks existing in the sheet. Insertion and deletion of hyperlinks will |
| 56 | be reflected by the instance. |
| 57 | |
| 58 | When a Hyperlinks collection object has been constructed from a VBA Range |
| 59 | object, it will represent the set of hyperlinks that have existed at its |
| 60 | construction time, and that are located completely inside the range(s) |
| 61 | represented by the Range object. Insertion and deletion of hyperlinks will |
| 62 | *not* be reflected by that instance. The instance will always offer all |
| 63 | hyperlinks it has been constructed with, even if they no longer exist. |
| 64 | Furthermore, the instance will not offer hyperlinks inserted later, even if |
| 65 | the instance itself has been used to insert the new hyperlinks. |
| 66 | |
| 67 | VBA code example: |
| 68 | |
| 69 | With ThisWorkbook.Worksheets(1) |
| 70 | |
| 71 | Set hlinks = .Hyperlinks ' global Hyperlinks object |
| 72 | Set myrange = .Range("A1:C3") |
| 73 | Set rangelinks1 = myrange.Hyperlinks ' hyperlinks of range A1:C3 |
| 74 | |
| 75 | MsgBox hlinks.Count ' 0 |
| 76 | MsgBox rangelinks1.Count ' 0 |
| 77 | |
| 78 | hlinks.Add .Range("A1"), "http://example.com" |
| 79 | ' a new hyperlink has been added in cell A1 |
| 80 | |
| 81 | MsgBox hlinks.Count ' 1 |
| 82 | MsgBox rangelinks1.Count ' still 0! |
| 83 | Set rangelinks2 = myrange.Hyperlinks ' hyperlinks of range A1:C3 |
| 84 | MsgBox rangelinks2.Count ' 1 (constructed after Add) |
| 85 | |
| 86 | rangelinks1.Add .Range("A2"), "http://example.com" |
| 87 | ' a new hyperlink has been constructed via the rangelinks1 object |
| 88 | ' but this addition has been done by the worksheet Hyperlinks object |
| 89 | |
| 90 | MsgBox hlinks.Count ' 2 |
| 91 | MsgBox rangelinks1.Count ' still 0!!! |
| 92 | MsgBox rangelinks2.Count ' still 1!!! |
| 93 | MsgBox myrange.Hyperlinks.Count ' 2 (constructed after Add) |
| 94 | |
| 95 | End With |
| 96 | */ |
| 97 | class ScVbaHyperlinks : private detail::ScVbaHlinkContainerMember, public ScVbaHyperlinks_BASE |
| 98 | { |
| 99 | public: |
| 100 | /// @throws css::uno::RuntimeException |
| 101 | explicit ScVbaHyperlinks( |
| 102 | const css::uno::Reference< ov::XHelperInterface >& rxParent, |
| 103 | const css::uno::Reference< css::uno::XComponentContext >& rxContext ); |
| 104 | |
| 105 | /// @throws css::uno::RuntimeException |
| 106 | explicit ScVbaHyperlinks( |
| 107 | const css::uno::Reference< ov::XHelperInterface >& rxParent, |
| 108 | const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 109 | const ScVbaHyperlinksRef& rxSheetHlinks, const ScRangeList& rScRanges ); |
| 110 | |
| 111 | virtual ~ScVbaHyperlinks() override; |
| 112 | |
| 113 | // XHyperlinks |
| 114 | virtual css::uno::Reference< ov::excel::XHyperlink > SAL_CALL Add( |
| 115 | const css::uno::Any& rAnchor, const css::uno::Any& rAddress, const css::uno::Any& rSubAddress, |
| 116 | const css::uno::Any& rScreenTip, const css::uno::Any& rTextToDisplay ) override; |
| 117 | |
| 118 | virtual void SAL_CALL Delete() override; |
| 119 | |
| 120 | // XEnumerationAccess |
| 121 | virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; |
| 122 | |
| 123 | // XElementAccess |
| 124 | virtual css::uno::Type SAL_CALL getElementType() override; |
| 125 | |
| 126 | // ScVbaCollectionBase |
| 127 | virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ) override; |
| 128 | |
| 129 | // XHelperInterface |
| 130 | VBAHELPER_DECL_XHELPERINTERFACE |
| 131 | |
| 132 | private: |
| 133 | ScVbaHyperlinksRef mxSheetHlinks; |
| 134 | }; |
| 135 | |
| 136 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |