2003-02-21 09:20:18 +00:00
|
|
|
/**
|
|
|
|
* \file insetbibitem.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-21 09:20:18 +00:00
|
|
|
*/
|
2003-10-21 16:15:14 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "insetbibitem.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
#include "buffer.h"
|
2006-10-09 14:21:11 +00:00
|
|
|
#include "BufferView.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
#include "dispatchresult.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
#include "funcrequest.h"
|
2003-09-16 13:43:30 +00:00
|
|
|
#include "lyxfont.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
#include "lyxlex.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.h"
|
2006-03-23 20:11:06 +00:00
|
|
|
#include "ParagraphList.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2004-08-14 18:41:27 +00:00
|
|
|
#include "support/std_ostream.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
using lyx::docstring;
|
2006-10-19 16:51:30 +00:00
|
|
|
using lyx::odocstream;
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::prefixIs;
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
using std::max;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
using std::auto_ptr;
|
2004-08-14 18:41:27 +00:00
|
|
|
using std::ostream;
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
int InsetBibitem::key_counter = 0;
|
2006-10-20 16:12:49 +00:00
|
|
|
docstring const key_prefix = lyx::from_ascii("key-");
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
|
2003-12-11 15:23:15 +00:00
|
|
|
: InsetCommand(p, "bibitem"), counter(1)
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
if (getParam("key").empty())
|
|
|
|
setParam("key", key_prefix + convert<docstring>(++key_counter));
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
auto_ptr<InsetBase> InsetBibitem::doClone() const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2003-11-03 17:47:28 +00:00
|
|
|
auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
|
2003-02-21 09:20:18 +00:00
|
|
|
b->setCounter(counter);
|
2003-07-25 17:11:25 +00:00
|
|
|
return auto_ptr<InsetBase>(b);
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
void InsetBibitem::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-02-26 19:28:38 +00:00
|
|
|
{
|
2003-03-07 21:44:48 +00:00
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
InsetCommandParams p("bibitem");
|
2006-09-01 15:41:38 +00:00
|
|
|
InsetCommandMailer::string2params("bibitem", lyx::to_utf8(cmd.argument()), p);
|
2006-10-09 14:21:11 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
|
|
|
cur.noUpdate();
|
|
|
|
break;
|
|
|
|
}
|
2006-10-20 16:12:49 +00:00
|
|
|
if (p["key"] != params()["key"])
|
|
|
|
// FIXME UNICODE
|
|
|
|
cur.bv().buffer()->changeRefsIfUnique(lyx::to_utf8(params()["key"]),
|
|
|
|
lyx::to_utf8(p["key"]), InsetBase::CITE_CODE);
|
2006-10-09 14:21:11 +00:00
|
|
|
setParams(p);
|
2003-03-07 21:44:48 +00:00
|
|
|
}
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-02-26 19:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
void InsetBibitem::setCounter(int c)
|
|
|
|
{
|
|
|
|
counter = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
void InsetBibitem::read(Buffer const & buf, LyXLex & lex)
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
InsetCommand::read(buf, lex);
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
if (prefixIs(getParam("key"), key_prefix)) {
|
|
|
|
int const key = convert<int>(getParam("key").substr(key_prefix.length()));
|
2003-02-21 09:20:18 +00:00
|
|
|
key_counter = max(key_counter, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const InsetBibitem::getBibLabel() const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
docstring const & label = getParam("label");
|
|
|
|
return label.empty() ? convert<docstring>(counter) : label;
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const InsetBibitem::getScreenLabel(Buffer const &) const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
return getParam("key") + " [" + getBibLabel() + ']';
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
int InsetBibitem::plaintext(Buffer const &, odocstream & os,
|
2004-08-14 18:41:27 +00:00
|
|
|
OutputParams const &) const
|
|
|
|
{
|
|
|
|
os << '[' << getCounter() << "] ";
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ale070405
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const bibitemWidest(Buffer const & buffer)
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
|
2003-05-27 22:41:04 +00:00
|
|
|
InsetBibitem const * bitem = 0;
|
2006-10-14 15:31:50 +00:00
|
|
|
|
2006-10-14 15:22:08 +00:00
|
|
|
// FIXME: this font is used unitialized for now but should be set to
|
2006-10-14 15:31:50 +00:00
|
|
|
// a proportional font. Here is what Georg Baum has to say about it:
|
2006-10-14 15:22:08 +00:00
|
|
|
/*
|
|
|
|
bibitemWidest() is supposed to find the bibitem with the widest label in the
|
|
|
|
output, because that is needed as an argument of the bibliography
|
|
|
|
environment to dtermine the correct indentation. To be 100% correct we
|
|
|
|
would need the metrics of the font that is used in the output, but usually
|
|
|
|
we don't have access to these.
|
|
|
|
In practice, any proportional font is probably good enough, since we don't
|
|
|
|
need to know the final with, we only need to know the which label is the
|
|
|
|
widest.
|
|
|
|
Unless there is an easy way to get the metrics of the output font I suggest
|
|
|
|
to use a hardcoded font like "Times" or so.
|
|
|
|
|
|
|
|
It is very important that the result of this function is the same both with
|
|
|
|
and without GUI. After thinking about this it is clear that no LyXFont
|
|
|
|
metrics should be used here, since these come from the gui. If we can't
|
|
|
|
easily get the LaTeX font metrics we should make our own poor mans front
|
|
|
|
metrics replacement, e.g. by hardcoding the metrics of the standard TeX
|
|
|
|
font.
|
|
|
|
*/
|
2003-02-21 09:20:18 +00:00
|
|
|
LyXFont font;
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
ParagraphList::const_iterator it = buffer.paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = buffer.paragraphs().end();
|
2003-05-28 06:47:15 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->bibitem()) {
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const label = it->bibitem()->getBibLabel();
|
2006-10-14 15:22:08 +00:00
|
|
|
|
2006-10-14 15:31:50 +00:00
|
|
|
// FIXME: we can't be sure using the following that the GUI
|
2006-10-14 15:22:08 +00:00
|
|
|
// version and the command-line version will give the same
|
|
|
|
// result.
|
2006-10-14 15:31:50 +00:00
|
|
|
//
|
|
|
|
//int const wx = lyx::use_gui?
|
|
|
|
// theFontMetrics(font).width(label): label.size();
|
|
|
|
//
|
|
|
|
// So for now we just use the label size in order to be sure
|
|
|
|
// that GUI and no-GUI gives the same bibitem (even if that is
|
|
|
|
// potentially the wrong one.
|
|
|
|
int const wx = label.size();
|
2006-10-14 15:22:08 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
if (wx > w) {
|
|
|
|
w = wx;
|
|
|
|
bitem = it->bibitem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitem && !bitem->getBibLabel().empty())
|
|
|
|
return bitem->getBibLabel();
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
return lyx::from_ascii("99");
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|