xref: /aoo41x/main/sc/source/ui/vba/vbahyperlinks.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_VBA_HYPERLINKS_HXX
29 #define SC_VBA_HYPERLINKS_HXX
30 
31 #include <ooo/vba/excel/XHyperlinks.hpp>
32 #include <rtl/ref.hxx>
33 #include <vbahelper/vbacollectionimpl.hxx>
34 
35 class ScRangeList;
36 
37 // ============================================================================
38 
39 namespace detail {
40 
41 class ScVbaHlinkContainer;
42 typedef ::rtl::Reference< ScVbaHlinkContainer > ScVbaHlinkContainerRef;
43 
44 /** Base class for ScVbaHyperlinks to get an initialized ScVbaHlinkContainer
45     class member before the ScVbaHyperlinks_BASE base class will be constructed.
46  */
47 struct ScVbaHlinkContainerMember
48 {
49     ScVbaHlinkContainerRef mxContainer;
50 
51     explicit ScVbaHlinkContainerMember( ScVbaHlinkContainer* pContainer );
52     ~ScVbaHlinkContainerMember();
53 };
54 
55 } // namespace detail
56 
57 // ============================================================================
58 
59 class ScVbaHyperlinks;
60 typedef ::rtl::Reference< ScVbaHyperlinks > ScVbaHyperlinksRef;
61 
62 typedef CollTestImplHelper< ov::excel::XHyperlinks > ScVbaHyperlinks_BASE;
63 
64 /** Represents a collection of hyperlinks of a worksheet or of a range.
65 
66     When a Hyperlinks collection object has been constructed from a VBA
67     Worksheet object, it will always represent the current set of all
68     hyperlinks existing in the sheet. Insertion and deletion of hyperlinks will
69     be reflected by the instance.
70 
71     When a Hyperlinks collection object has been constructed from a VBA Range
72     object, it will represent the set of hyperlinks that have existed at its
73     construction time, and that are located completely inside the range(s)
74     represented by the Range object. Insertion and deletion of hyperlinks will
75     *not* be reflected by that instance. The instance will always offer all
76     hyperlinks it has been constructed with, even if they no longer exist.
77     Furthermore, the instance will not offer hyperlinks inserted later, even if
78     the instance itself has been used to insert the new hyperlinks.
79 
80     VBA code example:
81 
82     With ThisWorkbook.Worksheets(1)
83 
84         Set hlinks = .Hyperlinks                ' global Hyperlinks object
85         Set myrange = .Range("A1:C3")
86         Set rangelinks1 = myrange.Hyperlinks    ' hyperlinks of range A1:C3
87 
88         MsgBox hlinks.Count                     ' 0
89         MsgBox rangelinks1.Count                ' 0
90 
91         hlinks.Add .Range("A1"), "http://example.com"
92         ' a new hyperlink has been added in cell A1
93 
94         MsgBox hlinks.Count                     ' 1
95         MsgBox rangelinks1.Count                ' still 0!
96         Set rangelinks2 = myrange.Hyperlinks    ' hyperlinks of range A1:C3
97         MsgBox rangelinks2.Count                ' 1 (constructed after Add)
98 
99         rangelinks1.Add .Range("A2"), "http://example.com"
100         ' a new hyperlink has been constructed via the rangelinks1 object
101         ' but this addition has been done by the worksheet Hyperlinks object
102 
103         MsgBox hlinks.Count                     ' 2
104         MsgBox rangelinks1.Count                ' still 0!!!
105         MsgBox rangelinks2.Count                ' still 1!!!
106         MsgBox myrange.Hyperlinks.Count         ' 2 (constructed after Add)
107 
108     End With
109  */
110 class ScVbaHyperlinks : private detail::ScVbaHlinkContainerMember, public ScVbaHyperlinks_BASE
111 {
112 public:
113     explicit ScVbaHyperlinks(
114         const css::uno::Reference< ov::XHelperInterface >& rxParent,
115         const css::uno::Reference< css::uno::XComponentContext >& rxContext ) throw (css::uno::RuntimeException);
116 
117     explicit ScVbaHyperlinks(
118         const css::uno::Reference< ov::XHelperInterface >& rxParent,
119         const css::uno::Reference< css::uno::XComponentContext >& rxContext,
120         const ScVbaHyperlinksRef& rxSheetHlinks, const ScRangeList& rScRanges ) throw (css::uno::RuntimeException);
121 
122     virtual ~ScVbaHyperlinks();
123 
124     // XHyperlinks
125     virtual css::uno::Reference< ov::excel::XHyperlink > SAL_CALL Add(
126         const css::uno::Any& rAnchor, const css::uno::Any& rAddress, const css::uno::Any& rSubAddress,
127         const css::uno::Any& rScreenTip, const css::uno::Any& rTextToDisplay )
128             throw (css::uno::RuntimeException);
129 
130     virtual void SAL_CALL Delete() throw (css::uno::RuntimeException);
131 
132     // XEnumerationAccess
133     virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException);
134 
135     // XElementAccess
136     virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException);
137 
138     // ScVbaCollectionBase
139     virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource );
140 
141     // XHelperInterface
142     VBAHELPER_DECL_XHELPERINTERFACE
143 
144 private:
145     ScVbaHyperlinksRef mxSheetHlinks;
146 };
147 
148 // ============================================================================
149 
150 #endif
151