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(int, int)
48 current_view->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*/)
72 if(getOptions().empty())
73 os << escape(getCommand());
76 InsetCommand clone = InsetCommand(getCmdName(),
78 os << escape(clone.getCommand());
84 int InsetRef::Latex(string & file, signed char /*fragile*/)
86 if(getOptions().empty())
87 file += escape(getCommand());
90 InsetCommand clone = InsetCommand(getCmdName(),
92 file += escape(clone.getCommand());
98 int InsetRef::Linuxdoc(string & file)
100 file += "<ref id=\"" + getContents()
101 + "\" name=\""+ getOptions() +"\" >" ;
107 int InsetRef::DocBook(string & file)
109 file += "<link linkend=\"" + getContents()
110 + "\">"+ getOptions() +"</link>" ;
116 // This function escapes 8-bit characters and other problematic characters
117 // It's exactly the same code as in insetlabel.C.
118 string InsetRef::escape(string const & lab) const
120 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
121 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
123 for (string::size_type i = 0; i < lab.length(); ++i) {
124 unsigned char c= lab[i];
125 if (c >= 128 || c == '=' || c == '%') {
127 enc += hexdigit[c>>4];
128 enc += hexdigit[c & 15];