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 #ifndef USE_OSTREAM_ONLY
85 int InsetRef::Latex(string & file, signed char /*fragile*/, bool /*fs*/) const
87 if(getOptions().empty())
88 file += escape(getCommand());
91 InsetCommand clone = InsetCommand(getCmdName(),
93 file += escape(clone.getCommand());
99 int InsetRef::Linuxdoc(string & file) const
101 file += "<ref id=\"" + getContents()
102 + "\" name=\""+ getOptions() +"\" >" ;
108 int InsetRef::DocBook(string & file) const
110 file += "<link linkend=\"" + getContents()
111 + "\">"+ getOptions() +"</link>" ;
118 int InsetRef::Linuxdoc(ostream & os) const
120 os << "<ref id=\"" << getContents()
121 << "\" name=\"" << getOptions() << "\" >";
126 int InsetRef::DocBook(ostream & os) const
128 os << "<link linkend=\"" << getContents()
129 << "\">" << getOptions() << "</link>";
135 // This function escapes 8-bit characters and other problematic characters
136 // It's exactly the same code as in insetlabel.C.
137 string InsetRef::escape(string const & lab) const
139 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
140 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
142 for (string::size_type i = 0; i < lab.length(); ++i) {
143 unsigned char c= lab[i];
144 if (c >= 128 || c == '=' || c == '%') {
146 enc += hexdigit[c>>4];
147 enc += hexdigit[c & 15];