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 #pragma implementation
18 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
22 #include "frontends/LyXView.h"
23 #include "frontends/Dialogs.h"
24 #include "BufferView.h"
25 #include "support/lstrings.h"
29 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
30 : InsetCommand(p), isLatex(buf.isLatex())
34 void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
36 // FuncRequestually trigger dialog with button 3 not 1
37 if (button == mouse_button::button3)
38 bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
39 else if (button == mouse_button::button1)
40 bv->owner()->getDialogs().showRef(this);
44 void InsetRef::edit(BufferView *, bool)
48 string const InsetRef::getScreenLabel(Buffer const *) const
51 for (int i = 0; !types[i].latex_name.empty(); ++ i)
52 if (getCmdName() == types[i].latex_name) {
53 temp = _(types[i].short_gui_name);
56 temp += getContents();
59 && !getOptions().empty()) {
67 int InsetRef::latex(Buffer const *, ostream & os,
68 bool /*fragile*/, bool /*fs*/) const
70 if (getOptions().empty())
71 os << escape(getCommand());
73 InsetCommandParams p(getCmdName(), getContents(), "");
74 os << escape(p.getCommand());
80 int InsetRef::ascii(Buffer const *, ostream & os, int) const
82 os << "[" << getContents() << "]";
87 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
89 os << "<ref id=\"" << getContents()
90 << "\" name=\"" << getOptions() << "\" >";
95 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
97 if (getOptions().empty()) {
98 os << "<xref linkend=\"" << getContents() << "\">";
100 os << "<link linkend=\"" << getContents()
101 << "\">" << getOptions() << "</link>";
108 void InsetRef::validate(LaTeXFeatures & features) const
110 if (getCmdName() == "vref" || getCmdName() == "vpageref")
111 features.require("varioref");
112 else if (getCmdName() == "prettyref")
113 features.require("prettyref");
117 InsetRef::type_info InsetRef::types[] = {
118 { "ref", N_("Standard"), N_("Ref: ")},
119 { "pageref", N_("Page Number"), N_("Page: ")},
120 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
121 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
122 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
127 int InsetRef::getType(string const & name)
129 for (int i = 0; !types[i].latex_name.empty(); ++i)
130 if (name == types[i].latex_name)
136 string const & InsetRef::getName(int type)
138 return types[type].latex_name;