]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
Make it compile when USE_BOOST_FORMAT is unset
[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 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "inseturl.h"
17 #include "BufferView.h"
18 #include "LaTeXFeatures.h"
19 #include "frontends/LyXView.h"
20 #include "debug.h"
21 #include "frontends/Dialogs.h"
22 #include "support/lstrings.h"
23 #include "gettext.h"
24
25 using std::ostream;
26
27
28 InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
29                 : InsetCommand(p)
30 {}
31
32
33 void InsetUrl::edit(BufferView * bv, int, int, mouse_button::state)
34 {
35         bv->owner()->getDialogs().showUrl(this);
36 }
37
38
39 void InsetUrl::edit(BufferView * bv, bool)
40 {
41         edit(bv, 0, 0, mouse_button::none);
42 }
43
44
45 string const InsetUrl::getScreenLabel(Buffer const *) const
46 {
47         string temp;
48         if (getCmdName() == "url")
49                 temp = _("Url: ");
50         else
51                 temp = _("HtmlUrl: ");
52
53         string url;
54  
55         if (!getOptions().empty())
56                 url += getOptions();
57         else
58                 url += getContents();
59
60         // elide if long
61         if (url.length() > 30) {
62                 url = url.substr(0, 10) + "..."
63                         + url.substr(url.length() - 17, url.length());
64         }
65         return temp + url;
66 }
67
68
69 int InsetUrl::latex(Buffer const *, ostream & os,
70                     bool fragile, bool /*free_spc*/) const
71 {
72         if (!getOptions().empty())
73                 os << getOptions() + ' ';
74         if (fragile)
75                 os << "\\protect";
76         os << "\\url{" << getContents() << '}';
77         return 0;
78 }
79
80
81 int InsetUrl::ascii(Buffer const *, ostream & os, int) const
82 {
83         if (getOptions().empty())
84                 os << "[" << getContents() << "]";
85         else
86                 os << "[" << getContents() << "||" <<  getOptions() << "]";
87         return 0;
88 }
89
90
91 int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
92 {
93         os << "<" << getCmdName()
94            << " url=\""  << getContents() << "\""
95            << " name=\"" << getOptions() << "\">";
96
97         return 0;
98 }
99
100
101 int InsetUrl::docbook(Buffer const *, ostream & os, bool) const
102 {
103         os << "<ulink url=\"" << subst(getContents(),"&","&amp;")
104            << "\">" << getOptions() << "</ulink>";
105         return 0;
106 }
107
108
109 void InsetUrl::validate(LaTeXFeatures & features) const
110 {
111         features.require("url");
112 }