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;
51 void InsetRef::Edit(int, int)
53 current_view->owner()->getLyXFunc()
54 ->Dispatch(LFUN_REFGOTO, getContents().c_str());
58 string InsetRef::getScreenLabel() const
61 if (flag == InsetRef::PAGE_REF)
65 temp += getContents();
66 if(!current_view->buffer()->isLatex()
67 && !getOptions().empty()) {
75 int InsetRef::Latex(FILE * file, signed char /*fragile*/)
77 if(getOptions().empty())
78 fprintf(file, "%s", escape(getCommand()).c_str());
81 InsetCommand clone= InsetCommand(getCmdName(), getContents(), ns);
82 fprintf(file, "%s", escape(clone.getCommand()).c_str());
88 int InsetRef::Latex(string & file, signed char /*fragile*/)
90 if(getOptions().empty())
91 file += escape(getCommand());
94 InsetCommand clone= InsetCommand(getCmdName(), getContents(), ns);
95 file += escape(clone.getCommand());
101 int InsetRef::Linuxdoc(string & file)
103 file += "<ref id=\"" + getContents()
104 + "\" name=\""+ getOptions() +"\" >" ;
110 int InsetRef::DocBook(string & file)
112 file += "<link linkend=\"" + getContents()
113 + "\">"+ getOptions() +"</link>" ;
119 // This function escapes 8-bit characters and other problematic characters
120 // It's exactly the same code as in insetlabel.C.
121 string InsetRef::escape(string const & lab) const {
122 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
123 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
125 for (string::size_type i = 0; i < lab.length(); ++i) {
126 unsigned char c= lab[i];
127 if (c >= 128 || c == '=' || c == '%') {
129 enc += hexdigit[c>>4];
130 enc += hexdigit[c & 15];