]> git.lyx.org Git - lyx.git/blob - src/insets/InsetHyperlink.cpp
The huge URL patch:
[lyx.git] / src / insets / InsetHyperlink.cpp
1 /**
2  * \file InsetHyperlink.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author José Matos
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetHyperlink.h"
14
15 #include "DispatchResult.h"
16 #include "FuncRequest.h"
17 #include "LaTeXFeatures.h"
18 #include "gettext.h"
19 #include "OutputParams.h"
20
21 #include "support/lstrings.h"
22
23 #include "support/std_ostream.h"
24
25
26 namespace lyx {
27
28 using support::subst;
29
30 using std::string;
31 using std::ostream;
32
33
34 InsetHyperlink::InsetHyperlink(InsetCommandParams const & p)
35         : InsetCommand(p, "href")
36 {}
37
38
39 docstring const InsetHyperlink::getScreenLabel(Buffer const &) const
40 {
41         docstring const temp = from_ascii("Hyperlink: ");
42
43         docstring url;
44
45         url += getParam("name");
46         if (url.empty())
47                 url += getParam("target");
48
49         // elide if long
50         if (url.length() > 30) {
51                 url = url.substr(0, 10) + "..."
52                         + url.substr(url.length() - 17, url.length());
53         }
54         return temp + url;
55 }
56
57
58 int InsetHyperlink::latex(Buffer const &, odocstream & os,
59                     OutputParams const & runparams) const
60 {
61         docstring const & name = getParam("name");
62         if (runparams.moving_arg)
63                 os << "\\protect";
64         //set the target for the name when no name is given
65         if (!getParam("name").empty())
66                 os << "\\href{" << getParam("target") << "}{" << getParam("name") << '}';
67         else
68                 os << "\\href{" << getParam("target") << "}{" << getParam("target") << '}';
69         return 0;
70 }
71
72
73 int InsetHyperlink::plaintext(Buffer const &, odocstream & os,
74                         OutputParams const &) const
75 {
76         odocstringstream oss;
77
78         oss << '[' << getParam("target");
79         if (getParam("name").empty())
80                 oss << ']';
81         else
82                 oss << "||" << getParam("name") << ']';
83
84         docstring const str = oss.str();
85         os << str;
86         return str.size();
87 }
88
89
90 int InsetHyperlink::docbook(Buffer const &, odocstream & os,
91                       OutputParams const &) const
92 {
93         os << "<ulink url=\""
94            << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
95            << "\">"
96            << getParam("name")
97            << "</ulink>";
98         return 0;
99 }
100
101
102 int InsetHyperlink::textString(Buffer const & buf, odocstream & os,
103                        OutputParams const & op) const
104 {
105         return plaintext(buf, os, op);
106 }
107
108
109 void InsetHyperlink::validate(LaTeXFeatures & features) const
110 {
111         features.require("hyperref");
112 }
113
114
115 } // namespace lyx