9 #include FORMS_H_LOCATION
13 #include "lyx_gui_misc.h" // CancelCloseBoxCB
16 #include "commandtags.h"
18 #include "LaTeXFeatures.h"
23 extern BufferView * current_view;
26 InsetRef::InsetRef(string const & cmd, Buffer * bf)
34 InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
37 setCmdName(inscmd.getCmdName());
38 setContents(inscmd.getContents());
39 setOptions(inscmd.getOptions());
44 void InsetRef::GenerateFlag()
46 if (getCmdName() == "ref")
48 else if (getCmdName() == "pageref")
50 else if (getCmdName() == "vref")
52 else if (getCmdName() == "vpageref")
54 else if (getCmdName() == "prettyref")
57 lyxerr << "ERROR (InsetRef::GenerateFlag): Unknown command name "
58 << getCmdName() << endl;
64 void InsetRef::Toggle() {
65 static string const cmd_names[REF_LAST+1]
66 = {"ref", "pageref", "vref", "vpageref", "prettyref"};
71 flag = static_cast<Ref_Flags>(flag + 1);
72 setCmdName(cmd_names[flag]);
76 void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
78 bv->owner()->getLyXFunc()->
79 Dispatch(LFUN_REFGOTO, getContents().c_str());
83 string InsetRef::getScreenLabel() const
85 static char const * labels[REF_LAST+1]
86 = { N_("Ref: "), N_("Page: "), N_("vRef: "), N_("vPage: "),
88 string temp = _(labels[flag]) + getContents();
89 if(!current_view->buffer()->isLatex()
90 && !getOptions().empty()) {
98 int InsetRef::Latex(ostream & os,
99 bool /*fragile*/, bool /*fs*/) const
101 if(getOptions().empty())
102 os << escape(getCommand());
105 InsetCommand clone = InsetCommand(getCmdName(),
107 os << escape(clone.getCommand());
113 int InsetRef::Ascii(ostream & os) const
115 os << "[" << getContents() << "]";
120 int InsetRef::Linuxdoc(ostream & os) const
122 os << "<ref id=\"" << getContents()
123 << "\" name=\"" << getOptions() << "\" >";
128 int InsetRef::DocBook(ostream & os) const
130 os << "<link linkend=\"" << getContents()
131 << "\">" << getOptions() << "</link>";
136 // This function escapes 8-bit characters and other problematic characters
137 // It's exactly the same code as in insetlabel.C.
138 string InsetRef::escape(string const & lab) const
140 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
141 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
143 for (string::size_type i = 0; i < lab.length(); ++i) {
144 unsigned char c= lab[i];
145 if (c >= 128 || c == '=' || c == '%') {
147 enc += hexdigit[c>>4];
148 enc += hexdigit[c & 15];
156 void InsetRef::Validate(LaTeXFeatures & features) const
161 features.varioref = true;
164 features.prettyref = true;