1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "insetref.h"
|
|
|
|
#include "buffer.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
extern BufferView * current_view;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetRef::InsetRef(string const & cmd, Buffer * bf)
|
1999-09-27 18:44:28 +00:00
|
|
|
: master(bf)
|
|
|
|
{
|
|
|
|
scanCommand(cmd);
|
|
|
|
if (getCmdName() == "ref")
|
|
|
|
flag = InsetRef::REF;
|
|
|
|
else
|
|
|
|
flag = InsetRef::PAGE_REF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
|
1999-09-27 18:44:28 +00:00
|
|
|
: master(bf)
|
|
|
|
{
|
|
|
|
setCmdName(inscmd.getCmdName());
|
|
|
|
setContents(inscmd.getContents());
|
|
|
|
setOptions(inscmd.getOptions());
|
|
|
|
if (getCmdName() == "ref")
|
|
|
|
flag = InsetRef::REF;
|
|
|
|
else
|
|
|
|
flag = InsetRef::PAGE_REF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-25 12:06:15 +00:00
|
|
|
bv->owner()->getLyXFunc()->
|
|
|
|
Dispatch(LFUN_REFGOTO, getContents().c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetRef::getScreenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (flag == InsetRef::PAGE_REF)
|
|
|
|
temp += _("Page: ");
|
|
|
|
else
|
|
|
|
temp += _("Ref: ");
|
|
|
|
temp += getContents();
|
1999-11-09 22:53:41 +00:00
|
|
|
if(!current_view->buffer()->isLatex()
|
1999-11-04 01:40:20 +00:00
|
|
|
&& !getOptions().empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
temp += "||";
|
|
|
|
temp += getOptions();
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
int InsetRef::Latex(ostream & os,
|
|
|
|
signed char /*fragile*/, bool /*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if(getOptions().empty())
|
1999-12-07 00:44:53 +00:00
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
else {
|
1999-10-02 16:21:10 +00:00
|
|
|
string ns;
|
1999-12-07 00:44:53 +00:00
|
|
|
InsetCommand clone = InsetCommand(getCmdName(),
|
|
|
|
getContents(), ns);
|
|
|
|
os << escape(clone.getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
int InsetRef::Linuxdoc(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "<ref id=\"" << getContents()
|
|
|
|
<< "\" name=\"" << getOptions() << "\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetRef::DocBook(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "<link linkend=\"" << getContents()
|
|
|
|
<< "\">" << getOptions() << "</link>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This function escapes 8-bit characters and other problematic characters
|
|
|
|
// It's exactly the same code as in insetlabel.C.
|
1999-12-07 00:44:53 +00:00
|
|
|
string InsetRef::escape(string const & lab) const
|
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
1999-10-02 16:21:10 +00:00
|
|
|
string enc;
|
|
|
|
for (string::size_type i = 0; i < lab.length(); ++i) {
|
1999-11-15 10:58:38 +00:00
|
|
|
unsigned char c= lab[i];
|
|
|
|
if (c >= 128 || c == '=' || c == '%') {
|
1999-09-27 18:44:28 +00:00
|
|
|
enc += '=';
|
|
|
|
enc += hexdigit[c>>4];
|
|
|
|
enc += hexdigit[c & 15];
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
enc += c;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return enc;
|
|
|
|
}
|