]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Make it compile when USE_BOOST_FORMAT is unset
[lyx.git] / src / insets / insetref.C
1 /**
2  * \file insetref.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 "insetref.h"
17 #include "buffer.h"
18 #include "funcrequest.h"
19 #include "debug.h"
20 #include "gettext.h"
21 #include "LaTeXFeatures.h"
22 #include "frontends/LyXView.h"
23 #include "frontends/Dialogs.h"
24 #include "BufferView.h"
25 #include "support/lstrings.h"
26
27 using std::ostream;
28
29 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
30         : InsetCommand(p), isLatex(buf.isLatex())
31 {}
32
33
34 void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
35 {
36         // FuncRequestually trigger dialog with button 3 not 1
37         if (button == mouse_button::button3)
38                 bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
39         else if (button == mouse_button::button1)
40                 bv->owner()->getDialogs().showRef(this);
41 }
42
43
44 void InsetRef::edit(BufferView *, bool)
45 {}
46
47
48 string const InsetRef::getScreenLabel(Buffer const *) const
49 {
50         string temp;
51         for (int i = 0; !types[i].latex_name.empty(); ++ i)
52                 if (getCmdName() == types[i].latex_name) {
53                         temp = _(types[i].short_gui_name);
54                         break;
55                 }
56         temp += getContents();
57
58         if (!isLatex
59            && !getOptions().empty()) {
60                 temp += "||";
61                 temp += getOptions();
62         }
63         return temp;
64 }
65
66
67 int InsetRef::latex(Buffer const *, ostream & os,
68                     bool /*fragile*/, bool /*fs*/) const
69 {
70         if (getOptions().empty())
71                 os << escape(getCommand());
72         else {
73                 InsetCommandParams p(getCmdName(), getContents(), "");
74                 os << escape(p.getCommand());
75         }
76         return 0;
77 }
78
79
80 int InsetRef::ascii(Buffer const *, ostream & os, int) const
81 {
82         os << "[" << getContents() << "]";
83         return 0;
84 }
85
86
87 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
88 {
89         os << "<ref id=\"" << getContents()
90            << "\" name=\"" << getOptions() << "\" >";
91         return 0;
92 }
93
94
95 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
96 {
97         if (getOptions().empty()) {
98                 os << "<xref linkend=\"" << getContents() << "\">";
99         } else {
100                 os << "<link linkend=\"" << getContents()
101                    << "\">" << getOptions() << "</link>";
102         }
103
104         return 0;
105 }
106
107
108 void InsetRef::validate(LaTeXFeatures & features) const
109 {
110         if (getCmdName() == "vref" || getCmdName() == "vpageref")
111                 features.require("varioref");
112         else if (getCmdName() == "prettyref")
113                 features.require("prettyref");
114 }
115
116
117 InsetRef::type_info InsetRef::types[] = {
118         { "ref",        N_("Standard"),                 N_("Ref: ")},
119         { "pageref",    N_("Page Number"),              N_("Page: ")},
120         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
121         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
122         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
123         { "", "", "" }
124 };
125
126
127 int InsetRef::getType(string const & name)
128 {
129         for (int i = 0; !types[i].latex_name.empty(); ++i)
130                 if (name == types[i].latex_name)
131                         return i;
132         return 0;
133 }
134
135
136 string const & InsetRef::getName(int type)
137 {
138         return types[type].latex_name;
139 }