1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SC_SOURCE_UI_VBA_VBAHYPERLINKS_HXX
21 #define INCLUDED_SC_SOURCE_UI_VBA_VBAHYPERLINKS_HXX
23 #include <ooo/vba/excel/XHyperlinks.hpp>
24 #include <rtl/ref.hxx>
25 #include <vbahelper/vbacollectionimpl.hxx>
31 class ScVbaHlinkContainer
;
32 typedef ::rtl::Reference
< ScVbaHlinkContainer
> ScVbaHlinkContainerRef
;
34 /** Base class for ScVbaHyperlinks to get an initialized ScVbaHlinkContainer
35 class member before the ScVbaHyperlinks_BASE base class will be constructed.
37 struct ScVbaHlinkContainerMember
39 ScVbaHlinkContainerRef mxContainer
;
41 explicit ScVbaHlinkContainerMember( ScVbaHlinkContainer
* pContainer
);
42 ~ScVbaHlinkContainerMember();
47 class ScVbaHyperlinks
;
48 typedef ::rtl::Reference
< ScVbaHyperlinks
> ScVbaHyperlinksRef
;
50 typedef CollTestImplHelper
< ov::excel::XHyperlinks
> ScVbaHyperlinks_BASE
;
52 /** Represents a collection of hyperlinks of a worksheet or of a range.
54 When a Hyperlinks collection object has been constructed from a VBA
55 Worksheet object, it will always represent the current set of all
56 hyperlinks existing in the sheet. Insertion and deletion of hyperlinks will
57 be reflected by the instance.
59 When a Hyperlinks collection object has been constructed from a VBA Range
60 object, it will represent the set of hyperlinks that have existed at its
61 construction time, and that are located completely inside the range(s)
62 represented by the Range object. Insertion and deletion of hyperlinks will
63 *not* be reflected by that instance. The instance will always offer all
64 hyperlinks it has been constructed with, even if they no longer exist.
65 Furthermore, the instance will not offer hyperlinks inserted later, even if
66 the instance itself has been used to insert the new hyperlinks.
70 With ThisWorkbook.Worksheets(1)
72 Set hlinks = .Hyperlinks ' global Hyperlinks object
73 Set myrange = .Range("A1:C3")
74 Set rangelinks1 = myrange.Hyperlinks ' hyperlinks of range A1:C3
76 MsgBox hlinks.Count ' 0
77 MsgBox rangelinks1.Count ' 0
79 hlinks.Add .Range("A1"), "http://example.com"
80 ' a new hyperlink has been added in cell A1
82 MsgBox hlinks.Count ' 1
83 MsgBox rangelinks1.Count ' still 0!
84 Set rangelinks2 = myrange.Hyperlinks ' hyperlinks of range A1:C3
85 MsgBox rangelinks2.Count ' 1 (constructed after Add)
87 rangelinks1.Add .Range("A2"), "http://example.com"
88 ' a new hyperlink has been constructed via the rangelinks1 object
89 ' but this addition has been done by the worksheet Hyperlinks object
91 MsgBox hlinks.Count ' 2
92 MsgBox rangelinks1.Count ' still 0!!!
93 MsgBox rangelinks2.Count ' still 1!!!
94 MsgBox myrange.Hyperlinks.Count ' 2 (constructed after Add)
98 class ScVbaHyperlinks
: private detail::ScVbaHlinkContainerMember
, public ScVbaHyperlinks_BASE
101 /// @throws css::uno::RuntimeException
102 explicit ScVbaHyperlinks(
103 const css::uno::Reference
< ov::XHelperInterface
>& rxParent
,
104 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
106 /// @throws css::uno::RuntimeException
107 explicit ScVbaHyperlinks(
108 const css::uno::Reference
< ov::XHelperInterface
>& rxParent
,
109 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
110 const ScVbaHyperlinksRef
& rxSheetHlinks
, const ScRangeList
& rScRanges
);
112 virtual ~ScVbaHyperlinks() override
;
115 virtual css::uno::Reference
< ov::excel::XHyperlink
> SAL_CALL
Add(
116 const css::uno::Any
& rAnchor
, const css::uno::Any
& rAddress
, const css::uno::Any
& rSubAddress
,
117 const css::uno::Any
& rScreenTip
, const css::uno::Any
& rTextToDisplay
) override
;
119 virtual void SAL_CALL
Delete() override
;
121 // XEnumerationAccess
122 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration() override
;
125 virtual css::uno::Type SAL_CALL
getElementType() override
;
127 // ScVbaCollectionBase
128 virtual css::uno::Any
createCollectionObject( const css::uno::Any
& rSource
) override
;
131 VBAHELPER_DECL_XHELPERINTERFACE
134 ScVbaHyperlinksRef mxSheetHlinks
;
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */