A bit more re-organization.
[lyx.git] / src / mathed / InsetMathRef.cpp
blob4fda1197cf97ddec254f106b9223fee7c8096a5a
1 /**
2 * \file InsetMathRef.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathRef.h"
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
17 #include "Buffer.h"
18 #include "Cursor.h"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "MathData.h"
22 #include "MathFactory.h"
23 #include "MathSupport.h"
24 #include "OutputParams.h"
25 #include "sgml.h"
27 #include "insets/InsetCommand.h"
29 #include "support/debug.h"
30 #include "support/gettext.h"
32 #include <ostream>
34 using namespace std;
36 namespace lyx {
38 InsetMathRef::InsetMathRef(Buffer * buf)
39 : CommandInset(buf, from_ascii("ref"), false)
43 InsetMathRef::InsetMathRef(Buffer * buf, docstring const & data)
44 : CommandInset(buf, data, false)
48 Inset * InsetMathRef::clone() const
50 return new InsetMathRef(*this);
54 void InsetMathRef::infoize(odocstream & os) const
56 os << "Ref: " << cell(0);
60 void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd)
62 switch (cmd.action) {
63 case LFUN_INSET_MODIFY:
64 if (cmd.getArg(0) == "ref") {
65 MathData ar;
66 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
67 *this = *ar[0].nucleus()->asRefInset();
68 break;
71 cur.undispatched();
72 break;
74 case LFUN_INSET_DIALOG_UPDATE: {
75 string const data = createDialogStr("ref");
76 cur.bv().updateDialog("ref", data);
77 break;
80 case LFUN_MOUSE_RELEASE:
81 if (cmd.button() == mouse_button::button3) {
82 LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
83 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
84 break;
86 if (cmd.button() == mouse_button::button1) {
87 // Eventually trigger dialog with button 3, not 1
88 string const data = createDialogStr("ref");
89 cur.bv().showDialog("ref", data, this);
90 break;
92 cur.undispatched();
93 break;
95 case LFUN_MOUSE_PRESS:
96 case LFUN_MOUSE_MOTION:
97 // eat other mouse commands
98 break;
100 default:
101 CommandInset::doDispatch(cur, cmd);
102 break;
107 bool InsetMathRef::getStatus(Cursor & cur, FuncRequest const & cmd,
108 FuncStatus & status) const
110 switch (cmd.action) {
111 // we handle these
112 case LFUN_INSET_MODIFY:
113 case LFUN_INSET_DIALOG_UPDATE:
114 case LFUN_MOUSE_RELEASE:
115 case LFUN_MOUSE_PRESS:
116 case LFUN_MOUSE_MOTION:
117 status.setEnabled(true);
118 return true;
119 default:
120 return CommandInset::getStatus(cur, cmd, status);
125 docstring const InsetMathRef::screenLabel() const
127 docstring str;
128 for (int i = 0; !types[i].latex_name.empty(); ++i) {
129 if (commandname() == types[i].latex_name) {
130 str = _(to_utf8(types[i].short_gui_name));
131 break;
134 str += asString(cell(0));
136 //if (/* !isLatex && */ !cell(0).empty()) {
137 // str += "||";
138 // str += asString(cell(1));
140 return str;
144 void InsetMathRef::validate(LaTeXFeatures & features) const
146 if (commandname() == "vref" || commandname() == "vpageref")
147 features.require("varioref");
148 else if (commandname() == "prettyref")
149 features.require("prettyref");
150 else if (commandname() == "eqref")
151 features.require("amsmath");
155 int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
157 if (cell(1).empty()) {
158 os << "<xref linkend=\""
159 << sgml::cleanID(buffer(), runparams, asString(cell(0)));
160 if (runparams.flavor == OutputParams::XML)
161 os << "\"/>";
162 else
163 os << "\">";
164 } else {
165 os << "<link linkend=\""
166 << sgml::cleanID(buffer(), runparams, asString(cell(0)))
167 << "\">"
168 << asString(cell(1))
169 << "</link>";
172 return 0;
176 string const InsetMathRef::createDialogStr(string const & name) const
178 InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
179 icp["reference"] = asString(cell(0));
180 if (!cell(1).empty())
181 icp["name"] = asString(cell(1));
182 return InsetCommand::params2string(name, icp);
186 InsetMathRef::ref_type_info InsetMathRef::types[] = {
187 { from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
188 { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
189 { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
190 { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
191 { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
192 { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
193 { from_ascii(""), from_ascii(""), from_ascii("") }
197 } // namespace lyx