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"
21 #include "FuncStatus.h"
23 #include "math_data.h"
24 #include "math_factory.h"
25 #include "math_support.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 (createMathInset_fromDialogStr(cmd.argument, ar)) {
67 *this = *ar[0].nucleus()->asRefInset();
74 case LFUN_INSET_DIALOG_UPDATE: {
75 string const data = createDialogStr("ref");
76 if (cur.bv().owner()->getDialogs().visible("ref"))
77 cur.bv().owner()->getDialogs().update("ref", data);
81 case LFUN_INSET_DIALOG_SHOW:
82 case LFUN_MOUSE_RELEASE:
83 if (cmd.button() == mouse_button::button3) {
84 lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
85 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
88 if (cmd.button() == mouse_button::button1) {
89 // Eventually trigger dialog with button 3, not 1
90 string const data = createDialogStr("ref");
91 cur.bv().owner()->getDialogs().show("ref", data, this);
97 case LFUN_MOUSE_PRESS:
98 case LFUN_MOUSE_MOTION:
99 // eat other mouse commands
103 CommandInset::doDispatch(cur, cmd);
109 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
110 FuncStatus & status) const
112 switch (cmd.action) {
114 case LFUN_INSET_MODIFY:
115 case LFUN_INSET_DIALOG_UPDATE:
116 case LFUN_INSET_DIALOG_SHOW:
117 case LFUN_MOUSE_RELEASE:
118 case LFUN_MOUSE_PRESS:
119 case LFUN_MOUSE_MOTION:
120 status.enabled(true);
123 return CommandInset::getStatus(cur, cmd, status);
128 string const RefInset::screenLabel() const
131 for (int i = 0; !types[i].latex_name.empty(); ++i)
132 if (commandname() == types[i].latex_name) {
133 str = _(types[i].short_gui_name);
136 str += asString(cell(0));
138 //if (/* !isLatex && */ !cell(0).empty()) {
140 // str += asString(cell(1));
146 void RefInset::validate(LaTeXFeatures & features) const
148 if (commandname() == "vref" || commandname() == "vpageref")
149 features.require("varioref");
150 else if (commandname() == "prettyref")
151 features.require("prettyref");
155 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
157 os << '[' << asString(cell(0)) << ']';
162 int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
164 os << "<ref id=\"" << asString(cell(0))
165 << "\" name=\"" << asString(cell(1)) << "\">";
170 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
172 if (cell(1).empty()) {
173 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
174 if (runparams.flavor == OutputParams::XML)
179 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
180 << "\">" << asString(cell(1)) << "</link>";
187 RefInset::ref_type_info RefInset::types[] = {
188 { "ref", N_("Standard"), N_("Ref: ")},
189 { "eqref", N_("Equation"), N_("EqRef: ")},
190 { "pageref", N_("Page Number"), N_("Page: ")},
191 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
192 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
193 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},