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"
29 #include "frontends/LyXView.h"
30 #include "frontends/Dialogs.h"
43 RefInset::RefInset(string const & data)
48 auto_ptr<InsetBase> RefInset::doClone() const
50 return auto_ptr<InsetBase>(new RefInset(*this));
54 void RefInset::infoize(std::ostream & os) const
56 os << "Ref: " << cell(0);
60 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
63 case LFUN_INSET_MODIFY:
64 if (cmd.getArg(0) == "ref") {
66 if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
67 *this = *ar[0].nucleus()->asRefInset();
74 case LFUN_INSET_DIALOG_UPDATE: {
75 string const data = createDialogStr("ref");
76 cur.bv().updateDialog("ref", data);
80 case LFUN_MOUSE_RELEASE:
81 if (cmd.button() == mouse_button::button3) {
82 lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
83 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
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().showInsetDialog("ref", data, this);
95 case LFUN_MOUSE_PRESS:
96 case LFUN_MOUSE_MOTION:
97 // eat other mouse commands
101 CommandInset::doDispatch(cur, cmd);
107 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
108 FuncStatus & status) const
110 switch (cmd.action) {
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.enabled(true);
120 return CommandInset::getStatus(cur, cmd, status);
125 string const RefInset::screenLabel() const
128 for (int i = 0; !types[i].latex_name.empty(); ++i)
129 if (commandname() == types[i].latex_name) {
131 str = lyx::to_utf8(_(types[i].short_gui_name));
134 str += asString(cell(0));
136 //if (/* !isLatex && */ !cell(0).empty()) {
138 // str += asString(cell(1));
144 void RefInset::validate(LaTeXFeatures & features) const
146 if (commandname() == "vref" || commandname() == "vpageref")
147 features.require("varioref");
148 else if (commandname() == "prettyref")
149 features.require("prettyref");
153 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
155 os << '[' << asString(cell(0)) << ']';
160 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
162 if (cell(1).empty()) {
163 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
164 if (runparams.flavor == OutputParams::XML)
169 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
170 << "\">" << asString(cell(1)) << "</link>";
177 RefInset::ref_type_info RefInset::types[] = {
178 { "ref", N_("Standard"), N_("Ref: ")},
179 { "eqref", N_("Equation"), N_("EqRef: ")},
180 { "pageref", N_("Page Number"), N_("Page: ")},
181 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
182 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
183 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},