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 signed char /*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::Linuxdoc(ostream & os) const
89 os << "<ref id=\"" << getContents()
90 << "\" name=\"" << getOptions() << "\" >";
95 int InsetRef::DocBook(ostream & os) const
97 os << "<link linkend=\"" << getContents()
98 << "\">" << getOptions() << "</link>";
103 // This function escapes 8-bit characters and other problematic characters
104 // It's exactly the same code as in insetlabel.C.
105 string InsetRef::escape(string const & lab) const
107 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
108 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
110 for (string::size_type i = 0; i < lab.length(); ++i) {
111 unsigned char c= lab[i];
112 if (c >= 128 || c == '=' || c == '%') {
114 enc += hexdigit[c>>4];
115 enc += hexdigit[c & 15];