hyperlink.cpp 2.9 KB

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