2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathRef.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
#include <config.h>
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathRef.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-04-18 19:57:58 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2004-11-02 11:25:20 +00:00
|
|
|
|
#include "buffer.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
2005-11-22 13:52:25 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "gettext.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathData.h"
|
|
|
|
|
#include "MathFactory.h"
|
|
|
|
|
#include "MathSupport.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "outputparams.h"
|
|
|
|
|
#include "sgml.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
|
|
RefInset::RefInset()
|
|
|
|
|
: CommandInset("ref")
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RefInset::RefInset(string const & data)
|
|
|
|
|
: CommandInset(data)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2005-02-23 12:01:50 +00:00
|
|
|
|
auto_ptr<InsetBase> RefInset::doClone() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new RefInset(*this));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RefInset::infoize(std::ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "Ref: " << cell(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2002-08-12 09:53:04 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
if (cmd.getArg(0) == "ref") {
|
|
|
|
|
MathArray ar;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (createInsetMath_fromDialogStr(to_utf8(cmd.argument()), ar)) {
|
2004-04-03 08:37:12 +00:00
|
|
|
|
*this = *ar[0].nucleus()->asRefInset();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2005-11-22 13:52:25 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
|
|
|
|
string const data = createDialogStr("ref");
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().updateDialog("ref", data);
|
2005-11-22 13:52:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
if (cmd.button() == mouse_button::button3) {
|
2004-04-18 19:57:58 +00:00
|
|
|
|
lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
|
2005-05-08 10:02:38 +00:00
|
|
|
|
cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
|
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// Eventually trigger dialog with button 3, not 1
|
2003-10-17 18:01:15 +00:00
|
|
|
|
string const data = createDialogStr("ref");
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().showInsetDialog("ref", data, this);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2003-10-17 18:01:15 +00:00
|
|
|
|
}
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
// eat other mouse commands
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
CommandInset::doDispatch(cur, cmd);
|
2004-03-01 17:12:09 +00:00
|
|
|
|
break;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-11-22 13:52:25 +00:00
|
|
|
|
bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
FuncStatus & status) const
|
2005-11-22 13:52:25 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// we handle these
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return CommandInset::getStatus(cur, cmd, status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const RefInset::screenLabel() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring str;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
for (int i = 0; !types[i].latex_name.empty(); ++i)
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (commandname() == types[i].latex_name) {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
str = _(types[i].short_gui_name);
|
2002-06-24 15:51:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-11 19:40:50 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
str += from_utf8(asString(cell(0)));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
|
|
//if (/* !isLatex && */ !cell(0).empty()) {
|
|
|
|
|
// str += "||";
|
|
|
|
|
// str += asString(cell(1));
|
|
|
|
|
//}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RefInset::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (commandname() == "vref" || commandname() == "vpageref")
|
2002-06-24 15:51:35 +00:00
|
|
|
|
features.require("varioref");
|
2003-06-12 08:52:36 +00:00
|
|
|
|
else if (commandname() == "prettyref")
|
2002-06-24 15:51:35 +00:00
|
|
|
|
features.require("prettyref");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
int RefInset::plaintext(odocstream & os, OutputParams const &) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '[' << from_utf8(asString(cell(0))) << ']';
|
2002-06-24 15:51:35 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int RefInset::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (cell(1).empty()) {
|
2006-10-19 21:00:33 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
os << "<xref linkend=\""
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< from_ascii(sgml::cleanID(buf, runparams, asString(cell(0))));
|
2004-11-24 21:58:42 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML)
|
2004-10-29 23:08:04 +00:00
|
|
|
|
os << "\"/>";
|
|
|
|
|
else
|
|
|
|
|
os << "\">";
|
2002-06-24 15:51:35 +00:00
|
|
|
|
} else {
|
2006-10-19 21:00:33 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
os << "<link linkend=\""
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< from_ascii(sgml::cleanID(buf, runparams, asString(cell(0))))
|
2006-10-19 21:00:33 +00:00
|
|
|
|
<< "\">"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< from_ascii(asString(cell(1)))
|
2006-10-19 21:00:33 +00:00
|
|
|
|
<< "</link>";
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-02-13 08:12:51 +00:00
|
|
|
|
RefInset::ref_type_info RefInset::types[] = {
|
2003-04-24 12:16:56 +00:00
|
|
|
|
{ "ref", N_("Standard"), N_("Ref: ")},
|
|
|
|
|
{ "eqref", N_("Equation"), N_("EqRef: ")},
|
|
|
|
|
{ "pageref", N_("Page Number"), N_("Page: ")},
|
|
|
|
|
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
|
|
|
|
|
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
|
|
|
|
|
{ "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{ "", "", "" }
|
|
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|