# -*- coding: utf-8 -*- module Axlsx # a hlinkClick object adds a click behaviour to a drawing object. # using the hlink_click method on a drawing object is the recommended way to manage hlinks # @see Pic#link_to class Hyperlink # the type of hyper link defines the onclick or mouseover trigger. # type must be one of :hlinkClick or :hlinkMouse def type @type ||= :hlinkClick end # sets the type of the object. # @param [Symbol] type one of :hlinkClick or hlinkMouse def type(v) RestrictionValidator.validate "Hyperlink.type", [:hlinkClick, :hlinkMouse], v; @type = v end # The destination of the hyperlink # This value is actually stored in the drawings .rels. doc as a relationship. attr_accessor :href # The docs say: # Specifies the URL when it has been determined by the generating application that the URL is invalid. That is the generating application can still store the URL but it is known that this URL is not correct. attr_accessor :invalidUrl # Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened. attr_accessor :tgtFrame # Specifies the tooltip that should be displayed when the hyperlink text is hovered over with the mouse. If this attribute is omitted, than the hyperlink text itself can be displayed. attr_accessor :tooltip #Creates a hyperlink object # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent # @param [Pic] parent # @option [String] tooltip message shown when hyperlinked object is hovered over with mouse. # @option [String] tgtFrame Target frame for opening hyperlink # @option [String] invalidUrl supposedly use to store the href when we know it is an invalid resource. # @option [String] href the target resource this hyperlink links to. def initialize(parent, options=>{}) DataTypeValidator.validate "Hyperlink.parent", [Pic], parent @parent = parent options.each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end end # The index of this hyperlink in the owning document's hyperlinks collection # @returns [Integer] def index self.parent.anchor.drawing.hyperlinks.index(self) end # The relational ID for this hyperlink # @returns [String] def r:id reference_count = self.parent.anchor.drawing.charts.size + self.parent.anchor.drawing.images.size + index end def to_xml(xml) xml.send(type, end end end