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_data.h"
15 #include "math_factory.h"
17 #include "BufferView.h"
18 #include "dispatchresult.h"
20 #include "funcrequest.h"
21 #include "math_support.h"
23 #include "LaTeXFeatures.h"
25 #include "frontends/LyXView.h"
26 #include "frontends/Dialogs.h"
39 RefInset::RefInset(string const & data)
44 auto_ptr<InsetBase> RefInset::clone() const
46 return auto_ptr<InsetBase>(new RefInset(*this));
50 void RefInset::infoize(std::ostream & os) const
52 os << "Ref: " << cell(0);
57 RefInset::priv_dispatch(FuncRequest const & cmd,
58 idx_type & idx, pos_type & pos)
61 case LFUN_INSET_MODIFY:
62 if (cmd.getArg(0) == "ref") {
64 if (!createMathInset_fromDialogStr(cmd.argument, ar))
65 return DispatchResult(false);
67 *this = *ar[0].nucleus()->asRefInset();
69 return DispatchResult(true, true);
72 case LFUN_MOUSE_RELEASE:
73 if (cmd.button() == mouse_button::button3) {
74 lyxerr << "trying to goto ref" << cell(0) << endl;
75 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
76 return DispatchResult(true, true);
78 if (cmd.button() == mouse_button::button1) {
79 // Eventually trigger dialog with button 3
81 string const data = createDialogStr("ref");
82 cmd.view()->owner()->getDialogs().
83 show("ref", data, this);
84 return DispatchResult(true, true);
87 case LFUN_MOUSE_PRESS:
88 case LFUN_MOUSE_MOTION:
89 // eat other mouse commands
90 return DispatchResult(true, true);
92 return CommandInset::priv_dispatch(cmd, idx, pos);
95 return DispatchResult(false);
99 string const RefInset::screenLabel() const
102 for (int i = 0; !types[i].latex_name.empty(); ++i)
103 if (commandname() == types[i].latex_name) {
104 str = _(types[i].short_gui_name);
107 str += asString(cell(0));
109 //if (/* !isLatex && */ !cell(0).empty()) {
111 // str += asString(cell(1));
117 void RefInset::validate(LaTeXFeatures & features) const
119 if (commandname() == "vref" || commandname() == "vpageref")
120 features.require("varioref");
121 else if (commandname() == "prettyref")
122 features.require("prettyref");
126 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
128 os << '[' << asString(cell(0)) << ']';
133 int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
135 os << "<ref id=\"" << asString(cell(0))
136 << "\" name=\"" << asString(cell(1)) << "\" >";
141 int RefInset::docbook(std::ostream & os, OutputParams const &) const
143 if (cell(1).empty()) {
144 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
146 os << "<link linkend=\"" << asString(cell(0))
147 << "\">" << asString(cell(1)) << "</link>";
156 RefInset::ref_type_info RefInset::types[] = {
157 { "ref", N_("Standard"), N_("Ref: ")},
158 { "eqref", N_("Equation"), N_("EqRef: ")},
159 { "pageref", N_("Page Number"), N_("Page: ")},
160 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
161 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
162 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},