]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
Introduce wide streams. This fixes the remaining problems of plain text
[lyx.git] / src / insets / inseturl.C
1 /**
2  * \file inseturl.C
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 using lyx::docstring;
26 using lyx::support::subst;
27
28 using std::string;
29 using std::ostream;
30
31
32 InsetUrl::InsetUrl(InsetCommandParams const & p)
33         : InsetCommand(p, "url")
34 {}
35
36
37 docstring const InsetUrl::getScreenLabel(Buffer const &) const
38 {
39         docstring const temp =
40                 (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
41
42         string url;
43
44         if (!getOptions().empty())
45                 url += getOptions();
46         else
47                 url += getContents();
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         // FIXME UNICODE
55         return temp + lyx::from_utf8(url);
56 }
57
58
59 int InsetUrl::latex(Buffer const &, ostream & os,
60                     OutputParams const & runparams) const
61 {
62         if (!getOptions().empty())
63                 os << getOptions() + ' ';
64         if (runparams.moving_arg)
65                 os << "\\protect";
66         os << "\\url{" << getContents() << '}';
67         return 0;
68 }
69
70
71 int InsetUrl::plaintext(Buffer const &, lyx::odocstream & os,
72                     OutputParams const &) const
73 {
74         // FIXME UNICODE
75         os << '[' << lyx::from_utf8(getContents());
76         if (getOptions().empty())
77                 os << ']';
78         else
79                 // FIXME UNICODE
80                 os << "||" << lyx::from_utf8(getOptions()) << ']';
81         return 0;
82 }
83
84
85 int InsetUrl::docbook(Buffer const &, ostream & os,
86                       OutputParams const &) const
87 {
88         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
89            << "\">" << getOptions() << "</ulink>";
90         return 0;
91 }
92
93
94 int InsetUrl::textString(Buffer const & buf, lyx::odocstream & os,
95                        OutputParams const & op) const
96 {
97         return plaintext(buf, os, op);
98 }
99
100
101 void InsetUrl::validate(LaTeXFeatures & features) const
102 {
103         features.require("url");
104 }