9 #include "commandtags.h"
12 #include "LaTeXFeatures.h"
15 #include "frontends/Dialogs.h"
19 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
20 : InsetCommand(p), isLatex(buf.isLatex())
23 void InsetRef::Edit(BufferView * bv, int, int, unsigned int button)
25 // Eventually trigger dialog with button 3 not 1
27 bv->owner()->getLyXFunc()->
28 Dispatch(LFUN_REF_GOTO, getContents());
29 else if (button == 1 )
30 bv->owner()->getDialogs()->showRef( this );
34 string const InsetRef::getScreenLabel() const
37 for (int i = 0; !types[i].latex_name.empty(); ++ i)
38 if (getCmdName() == types[i].latex_name) {
39 temp = _(types[i].short_gui_name);
42 temp += getContents();
45 && !getOptions().empty()) {
53 int InsetRef::Latex(Buffer const *, ostream & os,
54 bool /*fragile*/, bool /*fs*/) const
56 if (getOptions().empty())
57 os << escape(getCommand());
59 InsetCommandParams p( getCmdName(), getContents(), "" );
60 os << escape(p.getCommand());
66 int InsetRef::Ascii(Buffer const *, ostream & os, int) const
68 os << "[" << getContents() << "]";
73 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
75 os << "<ref id=\"" << getContents()
76 << "\" name=\"" << getOptions() << "\" >";
81 int InsetRef::DocBook(Buffer const *, ostream & os) const
83 os << "<link linkend=\"" << getContents()
84 << "\">" << getOptions() << "</link>";
89 // This function escapes 8-bit characters and other problematic characters
90 // It's exactly the same code as in insetlabel.C.
91 string const InsetRef::escape(string const & lab) const
93 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
94 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
96 for (string::size_type i = 0; i < lab.length(); ++i) {
97 unsigned char c= lab[i];
98 if (c >= 128 || c == '=' || c == '%') {
100 enc += hexdigit[c>>4];
101 enc += hexdigit[c & 15];
110 void InsetRef::Validate(LaTeXFeatures & features) const
112 if (getCmdName() == "vref" || getCmdName() == "vpageref")
113 features.varioref = true;
114 else if (getCmdName() == "prettyref")
115 features.prettyref = true;
118 InsetRef::type_info InsetRef::types[] = {
119 { "ref", N_("Standard"), N_("Ref: ")},
120 { "pageref", N_("Page Number"), N_("Page: ")},
121 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
122 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
123 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
128 int InsetRef::getType(string const & name)
130 for (int i = 0; !types[i].latex_name.empty(); ++i)
131 if (name == types[i].latex_name)
137 string const & InsetRef::getName(int type)
139 return types[type].latex_name;