1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetlabel.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "support/LOstream.h"
|
2000-05-19 16:46:01 +00:00
|
|
|
#include "lyx_gui_misc.h" //askForText
|
|
|
|
#include "support/lstrings.h" //frontStrip, strip
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "buffer.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-05-19 16:46:01 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::pair;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* Label. Used to insert a label automatically */
|
|
|
|
|
|
|
|
|
2000-08-04 13:12:30 +00:00
|
|
|
InsetLabel::InsetLabel(InsetCommandParams const & p)
|
|
|
|
: InsetCommand(p)
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
vector<string> const InsetLabel::getLabelList() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-06-07 08:53:40 +00:00
|
|
|
return vector<string>(1,getContents());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
void InsetLabel::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-06-05 15:12:09 +00:00
|
|
|
if (bv->buffer()->isReadonly()) {
|
2000-05-19 16:46:01 +00:00
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
|
|
|
return;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-06-07 08:53:40 +00:00
|
|
|
pair<bool, string> result = askForText(_("Enter label:"), getContents());
|
2000-05-19 16:46:01 +00:00
|
|
|
if (result.first) {
|
|
|
|
string new_contents = frontStrip(strip(result.second));
|
|
|
|
if (!new_contents.empty() &&
|
2000-06-07 08:53:40 +00:00
|
|
|
getContents() != new_contents) {
|
2000-06-05 15:12:09 +00:00
|
|
|
bv->buffer()->markDirty();
|
2000-12-11 09:46:09 +00:00
|
|
|
bool flag = bv->ChangeRefsIfUnique(getContents(),
|
|
|
|
new_contents);
|
|
|
|
setContents(new_contents);
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->RedoParagraph(bv);
|
2000-05-19 16:46:01 +00:00
|
|
|
if (flag) {
|
|
|
|
bv->redraw();
|
2000-09-28 14:05:24 +00:00
|
|
|
bv->fitCursor(getLyXText(bv));
|
2000-05-19 16:46:01 +00:00
|
|
|
} else
|
2001-02-14 08:38:21 +00:00
|
|
|
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-05-19 16:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
int InsetLabel::Latex(Buffer const *, ostream & os,
|
2000-04-19 01:42:55 +00:00
|
|
|
bool /*fragile*/, bool /*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-27 15:23:24 +00:00
|
|
|
int InsetLabel::Ascii(Buffer const *, ostream & os, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
os << "<" << getContents() << ">";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetLabel::Linuxdoc(Buffer const *, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
os << "<label id=\"" << getContents() << "\" >";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetLabel::DocBook(Buffer const *, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2000-11-13 15:43:36 +00:00
|
|
|
os << "<anchor id=\"" << getContents() << "\" ></anchor>";
|
2000-03-06 02:42:40 +00:00
|
|
|
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 insetref.C.
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetLabel::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;
|
1999-11-15 10:58:38 +00:00
|
|
|
for (string::size_type i= 0; i < lab.length(); ++i) {
|
1999-11-04 01:40:20 +00:00
|
|
|
unsigned char c = lab[i];
|
|
|
|
if (c >= 128 || c == '=' || c == '%') {
|
1999-09-27 18:44:28 +00:00
|
|
|
enc += '=';
|
1999-11-04 01:40:20 +00:00
|
|
|
enc += hexdigit[c >> 4];
|
1999-09-27 18:44:28 +00:00
|
|
|
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;
|
|
|
|
}
|