2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathRef.cpp
|
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"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2005-11-22 13:52:25 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathFactory.h"
|
|
|
|
|
#include "MathSupport.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "sgml.h"
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetCommand.h"
|
2007-04-06 08:30:37 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
#include <ostream>
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
InsetMathRef::InsetMathRef()
|
2006-10-22 10:15:23 +00:00
|
|
|
|
: CommandInset(from_ascii("ref"))
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
InsetMathRef::InsetMathRef(docstring const & data)
|
2002-06-24 15:51:35 +00:00
|
|
|
|
: CommandInset(data)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathRef::clone() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathRef(*this);
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
void InsetMathRef::infoize(odocstream & os) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Ref: " << cell(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
void InsetMathRef::doDispatch(Cursor & 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") {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (createInsetMath_fromDialogStr(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) {
|
2007-11-28 22:12:03 +00:00
|
|
|
|
LYXERR0("trying to goto ref '" << to_utf8(asString(cell(0))) << "'");
|
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");
|
2007-11-18 00:39:15 +00:00
|
|
|
|
cur.bv().showDialog("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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
bool InsetMathRef::getStatus(Cursor & 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
docstring const InsetMathRef::screenLabel() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring str;
|
2006-10-22 10:15:23 +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-22 10:15:23 +00:00
|
|
|
|
str = _(to_utf8(types[i].short_gui_name));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-22 10:15:23 +00:00
|
|
|
|
}
|
|
|
|
|
str += asString(cell(0));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
|
|
|
|
//if (/* !isLatex && */ !cell(0).empty()) {
|
|
|
|
|
// str += "||";
|
|
|
|
|
// str += asString(cell(1));
|
|
|
|
|
//}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
void InsetMathRef::validate(LaTeXFeatures & features) const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetMathRef::docbook(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
|
|
|
|
os << "<xref linkend=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
|
<< sgml::cleanID(buffer(), 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
|
|
|
|
os << "<link linkend=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
|
<< sgml::cleanID(buffer(), runparams, asString(cell(0)))
|
2006-10-19 21:00:33 +00:00
|
|
|
|
<< "\">"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< asString(cell(1))
|
|
|
|
|
<< "</link>";
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
string const InsetMathRef::createDialogStr(string const & name) const
|
2007-04-06 08:30:37 +00:00
|
|
|
|
{
|
2007-10-19 17:22:55 +00:00
|
|
|
|
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
|
2007-04-06 08:30:37 +00:00
|
|
|
|
icp["reference"] = asString(cell(0));
|
|
|
|
|
if (!cell(1).empty())
|
|
|
|
|
icp["name"] = asString(cell(1));
|
|
|
|
|
return InsetCommandMailer::params2string(name, icp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 20:49:56 +00:00
|
|
|
|
InsetMathRef::ref_type_info InsetMathRef::types[] = {
|
2007-08-31 12:07:14 +00:00
|
|
|
|
{ from_ascii("ref"), from_ascii(N_("Standard[[mathref]]")), from_ascii(N_("Ref: "))},
|
2006-10-22 10:15:23 +00:00
|
|
|
|
{ from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
|
|
|
|
|
{ from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
|
|
|
|
|
{ from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
|
|
|
|
|
{ from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
|
2007-02-12 02:15:04 +00:00
|
|
|
|
{ from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
|
2006-10-22 10:15:23 +00:00
|
|
|
|
{ from_ascii(""), from_ascii(""), from_ascii("") }
|
2002-06-24 15:51:35 +00:00
|
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|