Branch data TLA Line data Source code
1 : : // Copyright (c) 2014-2022 Thomas Fussell
2 : : // Copyright (c) 2010-2015 openpyxl
3 : : // Copyright (c) 2024-2025 xlnt-community
4 : : //
5 : : // Permission is hereby granted, free of charge, to any person obtaining a copy
6 : : // of this software and associated documentation files (the "Software"), to deal
7 : : // in the Software without restriction, including without limitation the rights
8 : : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : : // copies of the Software, and to permit persons to whom the Software is
10 : : // furnished to do so, subject to the following conditions:
11 : : //
12 : : // The above copyright notice and this permission notice shall be included in
13 : : // all copies or substantial portions of the Software.
14 : : //
15 : : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : : // THE SOFTWARE
22 : : //
23 : : // @license: http://www.opensource.org/licenses/mit-license.php
24 : : // @author: see AUTHORS file
25 : :
26 : : #include <xlnt/cell/hyperlink.hpp>
27 : : #include <xlnt/utils/exceptions.hpp>
28 : : #include <detail/implementations/hyperlink_impl.hpp>
29 : :
30 : : namespace xlnt {
31 : :
32 :CBC 61 : hyperlink::hyperlink(detail::hyperlink_impl *d)
33 : 61 : : d_(d)
34 : : {
35 : 61 : }
36 : :
37 : 19 : relationship hyperlink::relationship() const
38 : : {
39 [ - + ]: 19 : if (!external())
40 : : {
41 [ # # ]:UBC 0 : throw xlnt::exception("only external hyperlinks have associated relationships");
42 : : }
43 : :
44 :CBC 19 : return d_->relationship;
45 : : }
46 : :
47 : 6 : std::string hyperlink::url() const
48 : : {
49 [ - + ]: 6 : if (!external())
50 : : {
51 [ # # ]:UBC 0 : throw xlnt::exception("only external hyperlinks have associated urls");
52 : : }
53 : :
54 :CBC 6 : return d_->relationship.target().to_string();
55 : : }
56 : :
57 : 9 : std::string hyperlink::target_range() const
58 : : {
59 [ - + ]: 9 : if (external())
60 : : {
61 [ # # ]:UBC 0 : throw xlnt::exception("only internal hyperlinks have a target range");
62 : : }
63 : :
64 :CBC 9 : return d_->relationship.target().to_string();
65 : : }
66 : :
67 : 61 : bool hyperlink::external() const
68 : : {
69 : 61 : return d_->relationship.target_mode() == target_mode::external;
70 : : }
71 : :
72 :UBC 0 : bool hyperlink::has_display() const
73 : : {
74 : 0 : return d_->display.is_set();
75 : : }
76 : :
77 : 0 : void hyperlink::display(const std::string &value)
78 : : {
79 : 0 : d_->display.set(value);
80 : 0 : }
81 : :
82 :CBC 24 : const std::string &hyperlink::display() const
83 : : {
84 : 24 : return d_->display.get();
85 : : }
86 : :
87 :UBC 0 : bool hyperlink::has_tooltip() const
88 : : {
89 : 0 : return d_->tooltip.is_set();
90 : : }
91 : :
92 : 0 : void hyperlink::tooltip(const std::string &value)
93 : : {
94 : 0 : d_->tooltip.set(value);
95 : 0 : }
96 : :
97 : 0 : const std::string &hyperlink::tooltip() const
98 : : {
99 : 0 : return d_->tooltip.get();
100 : : }
101 : :
102 : 0 : bool hyperlink::has_location() const
103 : : {
104 : 0 : return d_->location.is_set();
105 : : }
106 : :
107 : 0 : void hyperlink::location(const std::string &value)
108 : : {
109 : 0 : d_->location.set(value);
110 : 0 : }
111 : :
112 : 0 : const std::string &hyperlink::location() const
113 : : {
114 : 0 : return d_->location.get();
115 : : }
116 : :
117 : : } // namespace xlnt
|