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(InsetCommandParams const & p, Buffer * bf)
27 : InsetCommand(p), master(bf)
32 void InsetRef::GenerateFlag()
34 if (getCmdName() == "ref")
36 else if (getCmdName() == "pageref")
38 else if (getCmdName() == "vref")
40 else if (getCmdName() == "vpageref")
42 else if (getCmdName() == "prettyref")
45 lyxerr << "ERROR (InsetRef::GenerateFlag): Unknown command name "
46 << getCmdName() << endl;
52 void InsetRef::Toggle() {
53 static string const cmd_names[REF_LAST+1]
54 = {"ref", "pageref", "vref", "vpageref", "prettyref"};
59 flag = static_cast<Ref_Flags>(flag + 1);
60 setCmdName(cmd_names[flag]);
64 void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
66 bv->owner()->getLyXFunc()->
67 Dispatch(LFUN_REFGOTO, getContents().c_str());
71 string InsetRef::getScreenLabel() const
73 static char const * labels[REF_LAST+1]
74 = { N_("Ref: "), N_("Page: "), N_("TextRef: "), N_("TextPage: "),
76 string temp = _(labels[flag]) + getContents();
77 if(!current_view->buffer()->isLatex()
78 && !getOptions().empty()) {
86 int InsetRef::Latex(Buffer const *, ostream & os,
87 bool /*fragile*/, bool /*fs*/) const
89 if(getOptions().empty())
90 os << escape(getCommand());
92 InsetCommandParams p( getCmdName(), getContents(), "" );
93 os << escape(p.getCommand());
99 int InsetRef::Ascii(Buffer const *, ostream & os) const
101 os << "[" << getContents() << "]";
106 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
108 os << "<ref id=\"" << getContents()
109 << "\" name=\"" << getOptions() << "\" >";
114 int InsetRef::DocBook(Buffer const *, ostream & os) const
116 os << "<link linkend=\"" << getContents()
117 << "\">" << getOptions() << "</link>";
122 // This function escapes 8-bit characters and other problematic characters
123 // It's exactly the same code as in insetlabel.C.
124 string InsetRef::escape(string const & lab) const
126 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
127 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
129 for (string::size_type i = 0; i < lab.length(); ++i) {
130 unsigned char c= lab[i];
131 if (c >= 128 || c == '=' || c == '%') {
133 enc += hexdigit[c>>4];
134 enc += hexdigit[c & 15];
142 void InsetRef::Validate(LaTeXFeatures & features) const
147 features.varioref = true;
150 features.prettyref = true;
159 void InsetRef::gotoLabel()
162 master->getUser()->gotoLabel(getContents());