9 #include FORMS_H_LOCATION
13 #include "lyx_gui_misc.h" // CancelCloseBoxCB
16 #include "commandtags.h"
19 extern BufferView * current_view;
22 InsetRef::InsetRef(string const & cmd, Buffer * bf)
26 if (getCmdName() == "ref")
29 flag = InsetRef::PAGE_REF;
33 InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
36 setCmdName(inscmd.getCmdName());
37 setContents(inscmd.getContents());
38 setOptions(inscmd.getOptions());
39 if (getCmdName() == "ref")
42 flag = InsetRef::PAGE_REF;
46 void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
48 bv->owner()->getLyXFunc()->
49 Dispatch(LFUN_REFGOTO, getContents().c_str());
53 string InsetRef::getScreenLabel() const
56 if (flag == InsetRef::PAGE_REF)
60 temp += getContents();
61 if(!current_view->buffer()->isLatex()
62 && !getOptions().empty()) {
70 int InsetRef::Latex(ostream & os, signed char /*fragile*/, bool /*fs*/) const
72 if(getOptions().empty())
73 os << escape(getCommand());
76 InsetCommand clone = InsetCommand(getCmdName(),
78 os << escape(clone.getCommand());
84 int InsetRef::Linuxdoc(ostream & os) const
86 os << "<ref id=\"" << getContents()
87 << "\" name=\"" << getOptions() << "\" >";
92 int InsetRef::DocBook(ostream & os) const
94 os << "<link linkend=\"" << getContents()
95 << "\">" << getOptions() << "</link>";
100 // This function escapes 8-bit characters and other problematic characters
101 // It's exactly the same code as in insetlabel.C.
102 string InsetRef::escape(string const & lab) const
104 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
105 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
107 for (string::size_type i = 0; i < lab.length(); ++i) {
108 unsigned char c= lab[i];
109 if (c >= 128 || c == '=' || c == '%') {
111 enc += hexdigit[c>>4];
112 enc += hexdigit[c & 15];