#include "lyxfunc.h"
#include "commandtags.h"
#include "gettext.h"
+#include "LaTeXFeatures.h"
+
+using std::ostream;
+using std::endl;
extern BufferView * current_view;
: master(bf)
{
scanCommand(cmd);
- if (getCmdName() == "ref")
- flag = InsetRef::REF;
- else
- flag = InsetRef::PAGE_REF;
+ GenerateFlag();
}
setCmdName(inscmd.getCmdName());
setContents(inscmd.getContents());
setOptions(inscmd.getOptions());
- if (getCmdName() == "ref")
- flag = InsetRef::REF;
- else
- flag = InsetRef::PAGE_REF;
+ GenerateFlag();
}
-InsetRef::~InsetRef()
+void InsetRef::GenerateFlag()
{
+ if (getCmdName() == "ref")
+ flag = REF;
+ else if (getCmdName() == "pageref")
+ flag = PAGE_REF;
+ else if (getCmdName() == "vref")
+ flag = VREF;
+ else if (getCmdName() == "vpageref")
+ flag = VPAGE_REF;
+ else if (getCmdName() == "prettyref")
+ flag = PRETTY_REF;
+ else {
+ lyxerr << "ERROR (InsetRef::GenerateFlag): Unknown command name "
+ << getCmdName() << endl;
+ flag = REF;
+ }
+}
+
+
+void InsetRef::Toggle() {
+ static string const cmd_names[REF_LAST+1]
+ = {"ref", "pageref", "vref", "vpageref", "prettyref"};
+
+ if (flag == REF_LAST)
+ flag = REF_FIRST;
+ else
+ flag = static_cast<Ref_Flags>(flag + 1);
+ setCmdName(cmd_names[flag]);
}
-void InsetRef::Edit(int, int)
+void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
{
- current_view->owner()->getLyXFunc()
- ->Dispatch(LFUN_REFGOTO, getContents().c_str());
+ bv->owner()->getLyXFunc()->
+ Dispatch(LFUN_REFGOTO, getContents().c_str());
}
string InsetRef::getScreenLabel() const
{
- string temp;
- if (flag == InsetRef::PAGE_REF)
- temp += _("Page: ");
- else
- temp += _("Ref: ");
- temp += getContents();
+ static char const * labels[REF_LAST+1]
+ = { N_("Ref: "), N_("Page: "), N_("TextRef: "), N_("TextPage: "),
+ N_("PrettyRef: ")};
+ string temp = _(labels[flag]) + getContents();
if(!current_view->buffer()->isLatex()
&& !getOptions().empty()) {
temp += "||";
}
-int InsetRef::Latex(FILE * file, signed char /*fragile*/)
+int InsetRef::Latex(Buffer const *, ostream & os,
+ bool /*fragile*/, bool /*fs*/) const
{
if(getOptions().empty())
- fprintf(file, "%s", escape(getCommand()).c_str());
+ os << escape(getCommand());
else {
string ns;
- InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
- fprintf(file, "%s", escape(clone.getCommand()).c_str());
+ InsetCommand clone = InsetCommand(getCmdName(),
+ getContents(), ns);
+ os << escape(clone.getCommand());
}
return 0;
}
-int InsetRef::Latex(string & file, signed char /*fragile*/)
+int InsetRef::Ascii(Buffer const *, ostream & os) const
{
- if(getOptions().empty())
- file += escape(getCommand());
- else {
- string ns;
- InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
- file += escape(clone.getCommand());
- }
+ os << "[" << getContents() << "]";
return 0;
}
-int InsetRef::Linuxdoc(string & file)
+int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
{
- file += "<ref id=\"" + getContents()
- + "\" name=\""+ getOptions() +"\" >" ;
-
+ os << "<ref id=\"" << getContents()
+ << "\" name=\"" << getOptions() << "\" >";
return 0;
}
-int InsetRef::DocBook(string & file)
+int InsetRef::DocBook(Buffer const *, ostream & os) const
{
- file += "<link linkend=\"" + getContents()
- + "\">"+ getOptions() +"</link>" ;
-
+ os << "<link linkend=\"" << getContents()
+ << "\">" << getOptions() << "</link>";
return 0;
}
// This function escapes 8-bit characters and other problematic characters
// It's exactly the same code as in insetlabel.C.
-string InsetRef::escape(string const & lab) const {
+string InsetRef::escape(string const & lab) const
+{
char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
string enc;
for (string::size_type i = 0; i < lab.length(); ++i) {
- unsigned char c=lab[i];
- if (c >= 128 || c=='=' || c=='%') {
+ unsigned char c= lab[i];
+ if (c >= 128 || c == '=' || c == '%') {
enc += '=';
enc += hexdigit[c>>4];
enc += hexdigit[c & 15];
}
return enc;
}
+
+void InsetRef::Validate(LaTeXFeatures & features) const
+{
+ switch (flag) {
+ case VREF:
+ case VPAGE_REF:
+ features.varioref = true;
+ break;
+ case PRETTY_REF:
+ features.prettyref = true;
+ break;
+ case REF:
+ case PAGE_REF:
+ break;
+ }
+}