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"
14 #include "math_factory.h"
16 #include "BufferView.h"
18 #include "funcrequest.h"
19 #include "math_support.h"
21 #include "LaTeXFeatures.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Dialogs.h"
36 RefInset::RefInset(string const & data)
41 auto_ptr<InsetBase> RefInset::clone() const
43 return auto_ptr<InsetBase>(new RefInset(*this));
47 void RefInset::infoize(std::ostream & os) const
49 os << "Ref: " << cell(0);
54 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
57 case LFUN_MOUSE_RELEASE:
58 if (cmd.button() == mouse_button::button3) {
59 lyxerr << "trying to goto ref" << cell(0) << endl;
60 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
63 if (cmd.button() == mouse_button::button1) {
64 // Eventually trigger dialog with button 3
66 string const data = createDialogStr("ref");
67 cmd.view()->owner()->getDialogs().
68 show("ref", data, this);
72 case LFUN_MOUSE_PRESS:
73 case LFUN_MOUSE_MOTION:
74 // eat other mouse commands
77 return CommandInset::dispatch(cmd, idx, pos);
84 string const RefInset::screenLabel() const
87 for (int i = 0; !types[i].latex_name.empty(); ++i)
88 if (commandname() == types[i].latex_name) {
89 str = _(types[i].short_gui_name);
92 str += asString(cell(0));
94 //if (/* !isLatex && */ !cell(0).empty()) {
96 // str += asString(cell(1));
102 void RefInset::validate(LaTeXFeatures & features) const
104 if (commandname() == "vref" || commandname() == "vpageref")
105 features.require("varioref");
106 else if (commandname() == "prettyref")
107 features.require("prettyref");
111 int RefInset::ascii(std::ostream & os, int) const
113 os << '[' << asString(cell(0)) << ']';
118 int RefInset::linuxdoc(std::ostream & os) const
120 os << "<ref id=\"" << asString(cell(0))
121 << "\" name=\"" << asString(cell(1)) << "\" >";
126 int RefInset::docbook(std::ostream & os, bool) const
128 if (cell(1).empty()) {
129 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
131 os << "<link linkend=\"" << asString(cell(0))
132 << "\">" << asString(cell(1)) << "</link>";
139 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
141 if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
145 if (!createMathInset_fromDialogStr(cmd.argument, ar))
148 *this = *ar[0].nucleus()->asRefInset();
150 // // This does not compile because updateInset expects
151 // // an Inset* and 'this' isn't.
152 // cmd.view()->updateInset(this);
157 RefInset::ref_type_info RefInset::types[] = {
158 { "ref", N_("Standard"), N_("Ref: ")},
159 { "eqref", N_("Equation"), N_("EqRef: ")},
160 { "pageref", N_("Page Number"), N_("Page: ")},
161 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
162 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
163 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},