]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Change to use preffered calling of Boost.Function
[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 #include "insetref.h"
13
14 #include "buffer.h"
15 #include "cursor.h"
16 #include "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "LaTeXFeatures.h"
21 #include "outputparams.h"
22
23 #include "frontends/LyXView.h"
24
25 #include "support/lstrings.h"
26
27
28 using lyx::support::escape;
29
30 using std::string;
31 using std::ostream;
32
33
34 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
35         : InsetCommand(p, "ref"), isLatex(buf.isLatex())
36 {}
37
38
39 InsetRef::InsetRef(InsetRef const & ir)
40         : InsetCommand(ir), isLatex(ir.isLatex)
41 {}
42
43
44 void InsetRef::priv_dispatch(LCursor & cur, FuncRequest & cmd)
45 {
46         switch (cmd.action) {
47         case LFUN_MOUSE_PRESS:
48                 // Eventually trigger dialog with button 3 not 1
49                 if (cmd.button() == mouse_button::button3)
50                         cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
51                 else
52                         InsetCommandMailer("ref", *this).showDialog(&cur.bv());
53                 return;
54
55         case LFUN_MOUSE_RELEASE:
56                 return;
57
58         default:
59                 return InsetCommand::priv_dispatch(cur, cmd);
60         }
61 }
62
63
64 string const InsetRef::getScreenLabel(Buffer const &) const
65 {
66         string temp;
67         for (int i = 0; !types[i].latex_name.empty(); ++i) {
68                 if (getCmdName() == types[i].latex_name) {
69                         temp = _(types[i].short_gui_name);
70                         break;
71                 }
72         }
73         temp += getContents();
74
75         if (!isLatex && !getOptions().empty()) {
76                 temp += "||";
77                 temp += getOptions();
78         }
79         return temp;
80 }
81
82
83 int InsetRef::latex(Buffer const &, ostream & os,
84                     OutputParams const &) const
85 {
86         if (getOptions().empty())
87                 os << escape(getCommand());
88         else {
89                 InsetCommandParams p(getCmdName(), getContents(), "");
90                 os << escape(p.getCommand());
91         }
92         return 0;
93 }
94
95
96 int InsetRef::plaintext(Buffer const &, ostream & os,
97                     OutputParams const &) const
98 {
99         os << '[' << getContents() << ']';
100         return 0;
101 }
102
103
104 int InsetRef::linuxdoc(Buffer const &, ostream & os,
105                        OutputParams const &) const
106 {
107         os << "<ref id=\"" << getContents()
108            << "\" name=\"" << getOptions() << "\" >";
109         return 0;
110 }
111
112
113 int InsetRef::docbook(Buffer const &, ostream & os,
114                       OutputParams const & runparams) const
115 {
116         if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
117                 os << "<xref linkend=\"" << getContents() << "\" />";
118         } else if (getOptions().empty()) {
119                 os << "<xref linkend=\"" << getContents() << "\">";
120         } else {
121                 os << "<link linkend=\"" << getContents()
122                    << "\">" << getOptions() << "</link>";
123         }
124
125         return 0;
126 }
127
128
129 void InsetRef::validate(LaTeXFeatures & features) const
130 {
131         if (getCmdName() == "vref" || getCmdName() == "vpageref")
132                 features.require("varioref");
133         else if (getCmdName() == "prettyref")
134                 features.require("prettyref");
135         else if (getCmdName() == "eqref")
136                 features.require("amsmath");
137 }
138
139
140 InsetRef::type_info InsetRef::types[] = {
141         { "ref",       N_("Standard"),              N_("Ref: ")},
142         { "eqref",     N_("Equation"),              N_("EqRef: ")},
143         { "pageref",   N_("Page Number"),           N_("Page: ")},
144         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
145         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
146         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
147         { "", "", "" }
148 };
149
150
151 int InsetRef::getType(string const & name)
152 {
153         for (int i = 0; !types[i].latex_name.empty(); ++i)
154                 if (name == types[i].latex_name)
155                         return i;
156         return 0;
157 }
158
159
160 string const & InsetRef::getName(int type)
161 {
162         return types[type].latex_name;
163 }