]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
The speed patch: redraw only rows that have changed
[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::support::subst;
26
27 using std::string;
28 using std::ostream;
29
30
31 InsetUrl::InsetUrl(InsetCommandParams const & p)
32         : InsetCommand(p, "url")
33 {}
34
35
36 string const InsetUrl::getScreenLabel(Buffer const &) const
37 {
38         string temp;
39         if (getCmdName() == "url")
40                 temp = _("Url: ");
41         else
42                 temp = _("HtmlUrl: ");
43
44         string url;
45
46         if (!getOptions().empty())
47                 url += getOptions();
48         else
49                 url += getContents();
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 &, ostream & os,
61                     OutputParams const & runparams) const
62 {
63         if (!getOptions().empty())
64                 os << getOptions() + ' ';
65         if (runparams.moving_arg)
66                 os << "\\protect";
67         os << "\\url{" << getContents() << '}';
68         return 0;
69 }
70
71
72 int InsetUrl::plaintext(Buffer const &, ostream & os,
73                     OutputParams const &) const
74 {
75         if (getOptions().empty())
76                 os << '[' << getContents() << ']';
77         else
78                 os << '[' << getContents() << "||" <<  getOptions() << ']';
79         return 0;
80 }
81
82
83 int InsetUrl::linuxdoc(Buffer const &, ostream & os,
84                        OutputParams const &) const
85 {
86         os << '<' << getCmdName()
87            << " url=\""  << getContents() << "\""
88            << " name=\"" << getOptions() << "\">";
89
90         return 0;
91 }
92
93
94 int InsetUrl::docbook(Buffer const &, ostream & os,
95                       OutputParams const &) const
96 {
97         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
98            << "\">" << getOptions() << "</ulink>";
99         return 0;
100 }
101
102
103 int InsetUrl::textString(Buffer const & buf, ostream & os,
104                        OutputParams const & op) const
105 {
106         return plaintext(buf, os, op);
107 }
108
109
110 void InsetUrl::validate(LaTeXFeatures & features) const
111 {
112         features.require("url");
113 }