3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathRef.h"
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "outputparams.h"
39 RefInset::RefInset(string const & data)
44 auto_ptr<InsetBase> RefInset::doClone() const
46 return auto_ptr<InsetBase>(new RefInset(*this));
50 void RefInset::infoize(std::ostream & os) const
52 os << "Ref: " << cell(0);
56 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
59 case LFUN_INSET_MODIFY:
60 if (cmd.getArg(0) == "ref") {
62 if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
63 *this = *ar[0].nucleus()->asRefInset();
70 case LFUN_INSET_DIALOG_UPDATE: {
71 string const data = createDialogStr("ref");
72 cur.bv().updateDialog("ref", data);
76 case LFUN_MOUSE_RELEASE:
77 if (cmd.button() == mouse_button::button3) {
78 lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
79 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
82 if (cmd.button() == mouse_button::button1) {
83 // Eventually trigger dialog with button 3, not 1
84 string const data = createDialogStr("ref");
85 cur.bv().showInsetDialog("ref", data, this);
91 case LFUN_MOUSE_PRESS:
92 case LFUN_MOUSE_MOTION:
93 // eat other mouse commands
97 CommandInset::doDispatch(cur, cmd);
103 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
104 FuncStatus & status) const
106 switch (cmd.action) {
108 case LFUN_INSET_MODIFY:
109 case LFUN_INSET_DIALOG_UPDATE:
110 case LFUN_MOUSE_RELEASE:
111 case LFUN_MOUSE_PRESS:
112 case LFUN_MOUSE_MOTION:
113 status.enabled(true);
116 return CommandInset::getStatus(cur, cmd, status);
121 string const RefInset::screenLabel() const
124 for (int i = 0; !types[i].latex_name.empty(); ++i)
125 if (commandname() == types[i].latex_name) {
127 str = lyx::to_utf8(_(types[i].short_gui_name));
130 str += asString(cell(0));
132 //if (/* !isLatex && */ !cell(0).empty()) {
134 // str += asString(cell(1));
140 void RefInset::validate(LaTeXFeatures & features) const
142 if (commandname() == "vref" || commandname() == "vpageref")
143 features.require("varioref");
144 else if (commandname() == "prettyref")
145 features.require("prettyref");
149 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
151 os << '[' << asString(cell(0)) << ']';
156 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
158 if (cell(1).empty()) {
159 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
160 if (runparams.flavor == OutputParams::XML)
165 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
166 << "\">" << asString(cell(1)) << "</link>";
173 RefInset::ref_type_info RefInset::types[] = {
174 { "ref", N_("Standard"), N_("Ref: ")},
175 { "eqref", N_("Equation"), N_("EqRef: ")},
176 { "pageref", N_("Page Number"), N_("Page: ")},
177 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
178 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
179 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},