9 #include "commandtags.h"
12 #include "LaTeXFeatures.h"
15 #include "frontends/Dialogs.h"
19 extern BufferView * current_view;
22 InsetRef::InsetRef(InsetCommandParams const & p)
26 void InsetRef::Edit(BufferView * bv, int, int, unsigned int button)
28 // Eventually trigger dialog with button 3 not 1
30 bv->owner()->getLyXFunc()->
31 Dispatch(LFUN_REF_GOTO, getContents());
32 else if( button == 1 )
33 bv->owner()->getDialogs()->showRef( this );
37 string const InsetRef::getScreenLabel() const
40 if (getCmdName() == "ref")
42 else if (getCmdName() == "pageref")
44 else if (getCmdName() == "vref")
45 temp = _( "TextRef: " );
46 else if (getCmdName() == "vpageref")
47 temp = _( "TextPage: " );
49 temp = _( "PrettyRef: " );
51 temp += getContents();
53 if(!current_view->buffer()->isLatex()
54 && !getOptions().empty()) {
62 int InsetRef::Latex(Buffer const *, ostream & os,
63 bool /*fragile*/, bool /*fs*/) const
65 if(getOptions().empty())
66 os << escape(getCommand());
68 InsetCommandParams p( getCmdName(), getContents(), "" );
69 os << escape(p.getCommand());
75 int InsetRef::Ascii(Buffer const *, ostream & os, int) const
77 os << "[" << getContents() << "]";
82 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
84 os << "<ref id=\"" << getContents()
85 << "\" name=\"" << getOptions() << "\" >";
90 int InsetRef::DocBook(Buffer const *, ostream & os) const
92 os << "<link linkend=\"" << getContents()
93 << "\">" << getOptions() << "</link>";
98 // This function escapes 8-bit characters and other problematic characters
99 // It's exactly the same code as in insetlabel.C.
100 string const InsetRef::escape(string const & lab) const
102 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
103 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
105 for (string::size_type i = 0; i < lab.length(); ++i) {
106 unsigned char c= lab[i];
107 if (c >= 128 || c == '=' || c == '%') {
109 enc += hexdigit[c>>4];
110 enc += hexdigit[c & 15];
119 void InsetRef::Validate(LaTeXFeatures & features) const
121 if (getCmdName() == "vref" || getCmdName() == "vpageref")
122 features.varioref = true;
123 else if(getCmdName() == "prettyref")
124 features.prettyref = true;