]> git.lyx.org Git - lyx.git/blob - src/insets/InsetUrl.cpp
InsetListings: change the interface of diaplay function and allow AlignLeft. Applied...
[lyx.git] / src / insets / InsetUrl.cpp
1 /**
2  * \file InsetUrl.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 "InsetUrl.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 InsetUrl::InsetUrl(InsetCommandParams const & p)
35         : InsetCommand(p, "url")
36 {}
37
38
39 docstring const InsetUrl::getScreenLabel(Buffer const &) const
40 {
41         docstring const temp =
42                 (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
43
44         docstring url;
45
46         if (!getParam("name").empty())
47                 url += getParam("name");
48         else
49                 url += getParam("target");
50
51         // elide if long
52         if (url.length() > 30) {
53                 url = url.substr(0, 10) + "..."
54                         + url.substr(url.length() - 17, url.length());
55         }
56         return temp + url;
57 }
58
59
60 int InsetUrl::latex(Buffer const &, odocstream & os,
61                     OutputParams const & runparams) const
62 {
63         docstring const & name = getParam("name");
64         if (!name.empty())
65                 os << name + ' ';
66         if (runparams.moving_arg)
67                 os << "\\protect";
68         os << "\\url{" << getParam("target") << '}';
69         return 0;
70 }
71
72
73 int InsetUrl::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 InsetUrl::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 InsetUrl::textString(Buffer const & buf, odocstream & os,
103                        OutputParams const & op) const
104 {
105         return plaintext(buf, os, op);
106 }
107
108
109 void InsetUrl::validate(LaTeXFeatures & features) const
110 {
111         features.require("url");
112 }
113
114
115 } // namespace lyx