9 #include "commandtags.h"
12 #include "LaTeXFeatures.h"
14 #include "frontends/Dialogs.h"
16 #include "BufferView.h"
20 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
21 : InsetCommand(p), isLatex(buf.isLatex())
24 void InsetRef::Edit(BufferView * bv, int, int, unsigned int button)
26 // Eventually trigger dialog with button 3 not 1
28 bv->owner()->getLyXFunc()->
29 Dispatch(LFUN_REF_GOTO, getContents());
30 else if (button == 1 )
31 bv->owner()->getDialogs()->showRef( this );
35 string const InsetRef::getScreenLabel() const
38 for (int i = 0; !types[i].latex_name.empty(); ++ i)
39 if (getCmdName() == types[i].latex_name) {
40 temp = _(types[i].short_gui_name);
43 temp += getContents();
46 && !getOptions().empty()) {
54 int InsetRef::Latex(Buffer const *, ostream & os,
55 bool /*fragile*/, bool /*fs*/) const
57 if (getOptions().empty())
58 os << escape(getCommand());
60 InsetCommandParams p( getCmdName(), getContents(), "" );
61 os << escape(p.getCommand());
67 int InsetRef::Ascii(Buffer const *, ostream & os, int) const
69 os << "[" << getContents() << "]";
74 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
76 os << "<ref id=\"" << getContents()
77 << "\" name=\"" << getOptions() << "\" >";
82 int InsetRef::DocBook(Buffer const *, ostream & os) const
84 os << "<link linkend=\"" << getContents()
85 << "\">" << getOptions() << "</link>";
90 // This function escapes 8-bit characters and other problematic characters
91 // It's exactly the same code as in insetlabel.C.
92 string const InsetRef::escape(string const & lab) const
94 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
95 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
97 for (string::size_type i = 0; i < lab.length(); ++i) {
98 unsigned char c= lab[i];
99 if (c >= 128 || c == '=' || c == '%') {
101 enc += hexdigit[c>>4];
102 enc += hexdigit[c & 15];
111 void InsetRef::Validate(LaTeXFeatures & features) const
113 if (getCmdName() == "vref" || getCmdName() == "vpageref")
114 features.varioref = true;
115 else if (getCmdName() == "prettyref")
116 features.prettyref = true;
119 InsetRef::type_info InsetRef::types[] = {
120 { "ref", N_("Standard"), N_("Ref: ")},
121 { "pageref", N_("Page Number"), N_("Page: ")},
122 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
123 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
124 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
129 int InsetRef::getType(string const & name)
131 for (int i = 0; !types[i].latex_name.empty(); ++i)
132 if (name == types[i].latex_name)
138 string const & InsetRef::getName(int type)
140 return types[type].latex_name;