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"
26 #include "support/LOstream.h"
37 RefInset::RefInset(string const & data)
42 auto_ptr<InsetBase> RefInset::clone() const
44 return auto_ptr<InsetBase>(new RefInset(*this));
48 void RefInset::infoize(std::ostream & os) const
50 os << "Ref: " << cell(0);
55 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
58 case LFUN_MOUSE_RELEASE:
59 if (cmd.button() == mouse_button::button3) {
60 lyxerr << "trying to goto ref" << cell(0) << endl;
61 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
64 if (cmd.button() == mouse_button::button1) {
65 // Eventually trigger dialog with button 3
67 string const data = createDialogStr("ref");
68 cmd.view()->owner()->getDialogs().
69 show("ref", data, this);
73 case LFUN_MOUSE_PRESS:
74 case LFUN_MOUSE_MOTION:
75 // eat other mouse commands
78 return CommandInset::dispatch(cmd, idx, pos);
85 string const RefInset::screenLabel() const
88 for (int i = 0; !types[i].latex_name.empty(); ++i)
89 if (commandname() == types[i].latex_name) {
90 str = _(types[i].short_gui_name);
93 str += asString(cell(0));
95 //if (/* !isLatex && */ !cell(0).empty()) {
97 // str += asString(cell(1));
103 void RefInset::validate(LaTeXFeatures & features) const
105 if (commandname() == "vref" || commandname() == "vpageref")
106 features.require("varioref");
107 else if (commandname() == "prettyref")
108 features.require("prettyref");
112 int RefInset::ascii(std::ostream & os, int) const
114 os << '[' << asString(cell(0)) << ']';
119 int RefInset::linuxdoc(std::ostream & os) const
121 os << "<ref id=\"" << asString(cell(0))
122 << "\" name=\"" << asString(cell(1)) << "\" >";
127 int RefInset::docbook(std::ostream & os, bool) const
129 if (cell(1).empty()) {
130 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
132 os << "<link linkend=\"" << asString(cell(0))
133 << "\">" << asString(cell(1)) << "</link>";
140 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
142 if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
146 if (!createMathInset_fromDialogStr(cmd.argument, ar))
149 *this = *ar[0].nucleus()->asRefInset();
151 // // This does not compile because updateInset expects
152 // // an Inset* and 'this' isn't.
153 // cmd.view()->updateInset(this);
158 RefInset::ref_type_info RefInset::types[] = {
159 { "ref", N_("Standard"), N_("Ref: ")},
160 { "eqref", N_("Equation"), N_("EqRef: ")},
161 { "pageref", N_("Page Number"), N_("Page: ")},
162 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
163 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
164 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},