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 "ref_inset.h"
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
20 #include "funcrequest.h"
22 #include "math_data.h"
23 #include "math_factory.h"
24 #include "math_support.h"
25 #include "outputparams.h"
28 #include "frontends/LyXView.h"
29 #include "frontends/Dialogs.h"
42 RefInset::RefInset(string const & data)
47 auto_ptr<InsetBase> RefInset::doClone() const
49 return auto_ptr<InsetBase>(new RefInset(*this));
53 void RefInset::infoize(std::ostream & os) const
55 os << "Ref: " << cell(0);
59 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
62 case LFUN_INSET_MODIFY:
63 if (cmd.getArg(0) == "ref") {
65 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
66 *this = *ar[0].nucleus()->asRefInset();
73 case LFUN_MOUSE_RELEASE:
74 if (cmd.button() == mouse_button::button3) {
75 lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
76 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
79 if (cmd.button() == mouse_button::button1) {
80 // Eventually trigger dialog with button 3, not 1
81 string const data = createDialogStr("ref");
82 cur.bv().owner()->getDialogs().show("ref", data, this);
88 case LFUN_MOUSE_PRESS:
89 case LFUN_MOUSE_MOTION:
90 // eat other mouse commands
94 CommandInset::doDispatch(cur, cmd);
100 string const RefInset::screenLabel() const
103 for (int i = 0; !types[i].latex_name.empty(); ++i)
104 if (commandname() == types[i].latex_name) {
105 str = _(types[i].short_gui_name);
108 str += asString(cell(0));
110 //if (/* !isLatex && */ !cell(0).empty()) {
112 // str += asString(cell(1));
118 void RefInset::validate(LaTeXFeatures & features) const
120 if (commandname() == "vref" || commandname() == "vpageref")
121 features.require("varioref");
122 else if (commandname() == "prettyref")
123 features.require("prettyref");
127 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
129 os << '[' << asString(cell(0)) << ']';
134 int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
136 os << "<ref id=\"" << asString(cell(0))
137 << "\" name=\"" << asString(cell(1)) << "\">";
142 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
144 if (cell(1).empty()) {
145 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
146 if (runparams.flavor == OutputParams::XML)
151 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
152 << "\">" << asString(cell(1)) << "</link>";
159 RefInset::ref_type_info RefInset::types[] = {
160 { "ref", N_("Standard"), N_("Ref: ")},
161 { "eqref", N_("Equation"), N_("EqRef: ")},
162 { "pageref", N_("Page Number"), N_("Page: ")},
163 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
164 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
165 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},