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