9 #include FORMS_H_LOCATION
13 #include "lyx_gui_misc.h" // CancelCloseBoxCB
16 #include "commandtags.h"
21 extern BufferView * current_view;
24 InsetRef::InsetRef(string const & cmd, Buffer * bf)
28 if (getCmdName() == "ref")
31 flag = InsetRef::PAGE_REF;
35 InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
38 setCmdName(inscmd.getCmdName());
39 setContents(inscmd.getContents());
40 setOptions(inscmd.getOptions());
41 if (getCmdName() == "ref")
44 flag = InsetRef::PAGE_REF;
48 void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
50 bv->owner()->getLyXFunc()->
51 Dispatch(LFUN_REFGOTO, getContents().c_str());
55 string InsetRef::getScreenLabel() const
58 if (flag == InsetRef::PAGE_REF)
62 temp += getContents();
63 if(!current_view->buffer()->isLatex()
64 && !getOptions().empty()) {
72 int InsetRef::Latex(ostream & os,
73 bool /*fragile*/, bool /*fs*/) const
75 if(getOptions().empty())
76 os << escape(getCommand());
79 InsetCommand clone = InsetCommand(getCmdName(),
81 os << escape(clone.getCommand());
87 int InsetRef::Ascii(ostream & os) const
89 os << "[" << getContents() << "]";
94 int InsetRef::Linuxdoc(ostream & os) const
96 os << "<ref id=\"" << getContents()
97 << "\" name=\"" << getOptions() << "\" >";
102 int InsetRef::DocBook(ostream & os) const
104 os << "<link linkend=\"" << getContents()
105 << "\">" << getOptions() << "</link>";
110 // This function escapes 8-bit characters and other problematic characters
111 // It's exactly the same code as in insetlabel.C.
112 string InsetRef::escape(string const & lab) const
114 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
115 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
117 for (string::size_type i = 0; i < lab.length(); ++i) {
118 unsigned char c= lab[i];
119 if (c >= 128 || c == '=' || c == '%') {
121 enc += hexdigit[c>>4];
122 enc += hexdigit[c & 15];