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 if (getCmdName() == "ref")
39 else if (getCmdName() == "pageref")
41 else if (getCmdName() == "vref")
42 temp = _( "TextRef: " );
43 else if (getCmdName() == "vpageref")
44 temp = _( "TextPage: " );
46 temp = _( "PrettyRef: " );
48 temp += getContents();
51 && !getOptions().empty()) {
59 int InsetRef::Latex(Buffer const *, ostream & os,
60 bool /*fragile*/, bool /*fs*/) const
62 if (getOptions().empty())
63 os << escape(getCommand());
65 InsetCommandParams p( getCmdName(), getContents(), "" );
66 os << escape(p.getCommand());
72 int InsetRef::Ascii(Buffer const *, ostream & os, int) const
74 os << "[" << getContents() << "]";
79 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
81 os << "<ref id=\"" << getContents()
82 << "\" name=\"" << getOptions() << "\" >";
87 int InsetRef::DocBook(Buffer const *, ostream & os) const
89 os << "<link linkend=\"" << getContents()
90 << "\">" << getOptions() << "</link>";
95 // This function escapes 8-bit characters and other problematic characters
96 // It's exactly the same code as in insetlabel.C.
97 string const InsetRef::escape(string const & lab) const
99 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
100 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
102 for (string::size_type i = 0; i < lab.length(); ++i) {
103 unsigned char c= lab[i];
104 if (c >= 128 || c == '=' || c == '%') {
106 enc += hexdigit[c>>4];
107 enc += hexdigit[c & 15];
116 void InsetRef::Validate(LaTeXFeatures & features) const
118 if (getCmdName() == "vref" || getCmdName() == "vpageref")
119 features.varioref = true;
120 else if (getCmdName() == "prettyref")
121 features.prettyref = true;