2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetText.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-02-25 12:06:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetText.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
2008-06-03 11:12:45 +00:00
|
|
|
#include "insets/InsetOptArg.h"
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "buffer_funcs.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "Buffer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "BufferView.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "CompletionList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "ErrorList.h"
|
|
|
|
#include "FuncRequest.h"
|
2008-10-05 09:51:28 +00:00
|
|
|
#include "FuncStatus.h"
|
2009-06-19 13:50:19 +00:00
|
|
|
#include "InsetCaption.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "InsetList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Intl.h"
|
2009-07-14 13:00:42 +00:00
|
|
|
#include "Language.h"
|
2009-07-14 18:27:54 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "lyxfind.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "MetricsInfo.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
#include "output_docbook.h"
|
|
|
|
#include "output_latex.h"
|
2009-06-05 17:48:14 +00:00
|
|
|
#include "output_xhtml.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "OutputParams.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
#include "output_plaintext.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "Paragraph.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "ParIterator.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Row.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "sgml.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "TexRow.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2008-03-15 00:02:41 +00:00
|
|
|
#include "Text.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "TextMetrics.h"
|
2008-06-03 11:12:45 +00:00
|
|
|
#include "TocBackend.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "frontends/alert.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2002-08-14 18:38:59 +00:00
|
|
|
#include <boost/bind.hpp>
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2006-09-10 10:53:23 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-12-12 10:16:00 +00:00
|
|
|
|
|
|
|
using boost::bind;
|
|
|
|
using boost::ref;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2003-09-09 22:13:45 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
using graphics::PreviewLoader;
|
|
|
|
|
2003-08-01 12:52:59 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetText::InsetText(Buffer * buf, UsePlain type)
|
|
|
|
: Inset(buf), drawFrame_(false), frame_color_(Color_insetframe), text_(this)
|
2003-12-01 13:35:49 +00:00
|
|
|
{
|
2009-04-04 19:34:14 +00:00
|
|
|
initParagraphs(type);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
InsetText::InsetText(InsetText const & in)
|
2009-08-09 15:05:36 +00:00
|
|
|
: Inset(in), text_(this)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2004-12-17 16:27:12 +00:00
|
|
|
text_.autoBreakRows_ = in.text_.autoBreakRows_;
|
2003-10-08 14:29:16 +00:00
|
|
|
drawFrame_ = in.drawFrame_;
|
|
|
|
frame_color_ = in.frame_color_;
|
2003-12-01 13:35:49 +00:00
|
|
|
text_.paragraphs() = in.text_.paragraphs();
|
It used to be that things like InsetFlex, InsetCaption, and the like used the default layout, whatever that is---usually Standard. That gave rise to bug 2178, the solution to which is to define a new empty layout, which insets like these use instead of the default. See r22966.
So, when we have an older LyX file, it will look like this:
\begin_inset ERT
status open
\begin_layout Standard
this that
\end_layout
\end_inset
which is now invalid, because ERT uses only PlainLayout. So I had put some code into Text::readParToken, where the layout for a paragraph gets set as it is read:
if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
} else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
} else {
// otherwise, the empty layout maps to the default
if (layoutname == tclass.emptyLayoutName())
layoutname = tclass.defaultLayoutName();
}
This turns out not to work, because par.forceEmptyLayout() and par.useEmptyLayout() always return false here, because par.inInset() always returns a null pointer, because the paragraph's inset hasn't yet been set when Text::readParagraph() gets called from Text::read() gets called from InsetText::read(). The solution is to set the paragraph's inset when it is created, which means passing a pointer to the various read() routines along the way.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23057 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-19 02:35:07 +00:00
|
|
|
setParagraphOwner();
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2008-07-23 12:55:24 +00:00
|
|
|
void InsetText::setBuffer(Buffer & buf)
|
|
|
|
{
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
|
|
|
for (ParagraphList::iterator it = paragraphs().begin(); it != end; ++it)
|
|
|
|
it->setBuffer(buf);
|
2008-07-23 13:10:18 +00:00
|
|
|
Inset::setBuffer(buf);
|
2008-07-23 12:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-04 19:34:14 +00:00
|
|
|
void InsetText::initParagraphs(UsePlain type)
|
2008-03-04 22:28:18 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(paragraphs().empty(), /**/);
|
2008-03-04 22:28:18 +00:00
|
|
|
paragraphs().push_back(Paragraph());
|
|
|
|
Paragraph & ourpar = paragraphs().back();
|
|
|
|
ourpar.setInsetOwner(this);
|
2009-04-04 19:34:14 +00:00
|
|
|
DocumentClass const & dc = buffer_->params().documentClass();
|
|
|
|
if (type == DefaultLayout)
|
|
|
|
ourpar.setDefaultLayout(dc);
|
|
|
|
else
|
|
|
|
ourpar.setPlainLayout(dc);
|
2008-03-04 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
2008-07-29 12:07:08 +00:00
|
|
|
|
It used to be that things like InsetFlex, InsetCaption, and the like used the default layout, whatever that is---usually Standard. That gave rise to bug 2178, the solution to which is to define a new empty layout, which insets like these use instead of the default. See r22966.
So, when we have an older LyX file, it will look like this:
\begin_inset ERT
status open
\begin_layout Standard
this that
\end_layout
\end_inset
which is now invalid, because ERT uses only PlainLayout. So I had put some code into Text::readParToken, where the layout for a paragraph gets set as it is read:
if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
} else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
} else {
// otherwise, the empty layout maps to the default
if (layoutname == tclass.emptyLayoutName())
layoutname = tclass.defaultLayoutName();
}
This turns out not to work, because par.forceEmptyLayout() and par.useEmptyLayout() always return false here, because par.inInset() always returns a null pointer, because the paragraph's inset hasn't yet been set when Text::readParagraph() gets called from Text::read() gets called from InsetText::read(). The solution is to set the paragraph's inset when it is created, which means passing a pointer to the various read() routines along the way.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23057 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-19 02:35:07 +00:00
|
|
|
void InsetText::setParagraphOwner()
|
2000-03-28 16:18:02 +00:00
|
|
|
{
|
2004-11-23 23:04:52 +00:00
|
|
|
for_each(paragraphs().begin(), paragraphs().end(),
|
|
|
|
bind(&Paragraph::setInsetOwner, _1, this));
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-07 10:37:05 +00:00
|
|
|
void InsetText::clear()
|
2000-07-14 14:57:20 +00:00
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
ParagraphList & pars = paragraphs();
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(!pars.empty(), /**/);
|
2003-03-03 23:19:01 +00:00
|
|
|
|
2002-03-04 16:10:47 +00:00
|
|
|
// This is a gross hack...
|
2008-03-08 00:08:03 +00:00
|
|
|
Layout const & old_layout = pars.begin()->layout();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
pars.clear();
|
|
|
|
pars.push_back(Paragraph());
|
|
|
|
pars.begin()->setInsetOwner(this);
|
2008-02-23 16:45:38 +00:00
|
|
|
pars.begin()->setLayout(old_layout);
|
2000-07-14 14:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 21:45:14 +00:00
|
|
|
Dimension const InsetText::dimension(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
TextMetrics const & tm = bv.textMetrics(&text_);
|
|
|
|
Dimension dim = tm.dimension();
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
return dim;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetText::write(ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
os << "Text\n";
|
2009-08-09 15:29:34 +00:00
|
|
|
text_.write(os);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetText::read(Lexer & lex)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2005-09-07 10:37:05 +00:00
|
|
|
clear();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
// delete the initial paragraph
|
2003-12-01 13:35:49 +00:00
|
|
|
Paragraph oldpar = *paragraphs().begin();
|
|
|
|
paragraphs().clear();
|
2006-08-13 16:16:43 +00:00
|
|
|
ErrorList errorList;
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.setContext("InsetText::read");
|
2009-08-09 15:29:34 +00:00
|
|
|
bool res = text_.read(lex, errorList, this);
|
2003-03-12 05:46:35 +00:00
|
|
|
|
2008-04-05 21:24:57 +00:00
|
|
|
if (!res)
|
|
|
|
lex.printError("Missing \\end_inset at this point. ");
|
2003-10-02 12:01:24 +00:00
|
|
|
|
|
|
|
// sanity check
|
2004-11-30 01:59:49 +00:00
|
|
|
// ensure we have at least one paragraph.
|
2003-12-01 13:35:49 +00:00
|
|
|
if (paragraphs().empty())
|
|
|
|
paragraphs().push_back(oldpar);
|
2009-07-14 13:05:13 +00:00
|
|
|
// Force default font, if so requested
|
|
|
|
// This avoids paragraphs in buffer language that would have a
|
|
|
|
// foreign language after a document language change, and it ensures
|
|
|
|
// that all new text in ERT and similar gets the "latex" language,
|
|
|
|
// since new text inherits the language from the last position of the
|
|
|
|
// existing text. As a side effect this makes us also robust against
|
|
|
|
// bugs in LyX that might lead to font changes in ERT in .lyx files.
|
|
|
|
fixParagraphsFont();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2006-12-29 23:54:48 +00:00
|
|
|
TextMetrics & tm = mi.base.bv->textMetrics(&text_);
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
|
2007-09-02 13:50:37 +00:00
|
|
|
|
2006-02-05 13:20:16 +00:00
|
|
|
// Hand font through to contained lyxtext:
|
2007-10-28 18:51:54 +00:00
|
|
|
tm.font_.fontInfo() = mi.base.font;
|
2007-09-17 21:45:14 +00:00
|
|
|
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
2009-05-09 20:26:04 +00:00
|
|
|
|
|
|
|
// This can happen when a layout has a left and right margin,
|
|
|
|
// and the view is made very narrow. We can't do better than
|
|
|
|
// to draw it partly out of view (bug 5890).
|
|
|
|
if (mi.base.textwidth < 1)
|
|
|
|
mi.base.textwidth = 1;
|
|
|
|
|
2007-09-18 08:52:38 +00:00
|
|
|
if (hasFixedWidth())
|
|
|
|
tm.metrics(mi, dim, mi.base.textwidth);
|
|
|
|
else
|
|
|
|
tm.metrics(mi, dim);
|
2007-09-17 21:45:14 +00:00
|
|
|
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-19 16:46:47 +00:00
|
|
|
void InsetText::draw(PainterInfo & pi, int x, int y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2006-12-29 23:54:48 +00:00
|
|
|
TextMetrics & tm = pi.base.bv->textMetrics(&text_);
|
|
|
|
|
2007-08-30 22:12:13 +00:00
|
|
|
if (drawFrame_ || pi.full_repaint) {
|
2008-02-14 08:24:52 +00:00
|
|
|
int const w = tm.width() + TEXT_TO_INSET_OFFSET;
|
2007-09-17 21:45:14 +00:00
|
|
|
int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent();
|
|
|
|
int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
|
2008-02-14 08:24:52 +00:00
|
|
|
int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
|
2007-08-30 22:12:13 +00:00
|
|
|
if (pi.full_repaint)
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.pain.fillRectangle(xframe, yframe, w, h,
|
|
|
|
pi.backgroundColor(this));
|
|
|
|
|
2007-08-30 22:12:13 +00:00
|
|
|
if (drawFrame_)
|
2008-02-14 08:24:52 +00:00
|
|
|
pi.pain.rectangle(xframe, yframe, w, h, frameColor());
|
2005-07-17 01:13:36 +00:00
|
|
|
}
|
2008-10-25 10:47:38 +00:00
|
|
|
ColorCode const old_color = pi.background_color;
|
|
|
|
pi.background_color = pi.backgroundColor(this, false);
|
|
|
|
|
2007-09-17 21:45:14 +00:00
|
|
|
tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
|
2008-10-25 10:47:38 +00:00
|
|
|
|
|
|
|
pi.background_color = old_color;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
void InsetText::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2001-04-02 14:02:58 +00:00
|
|
|
{
|
2008-02-10 19:52:45 +00:00
|
|
|
pit_type const pit = front ? 0 : paragraphs().size() - 1;
|
|
|
|
pos_type pos = front ? 0 : paragraphs().back().size();
|
|
|
|
|
|
|
|
// if visual information is not to be ignored, move to extreme right/left
|
2008-02-11 08:20:13 +00:00
|
|
|
if (entry_from != ENTRY_DIRECTION_IGNORE) {
|
2008-02-10 19:52:45 +00:00
|
|
|
Cursor temp_cur = cur;
|
|
|
|
temp_cur.pit() = pit;
|
|
|
|
temp_cur.pos() = pos;
|
2008-02-11 08:20:13 +00:00
|
|
|
temp_cur.posVisToRowExtremity(entry_from == ENTRY_DIRECTION_LEFT);
|
2008-02-10 19:52:45 +00:00
|
|
|
pos = temp_cur.pos();
|
|
|
|
}
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
text_.setCursor(cur.top(), pit, pos);
|
2004-01-20 14:25:24 +00:00
|
|
|
cur.clearSelection();
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.finishUndo();
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * InsetText::editXY(Cursor & cur, int x, int y)
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2007-09-02 09:44:08 +00:00
|
|
|
return cur.bv().textMetrics(&text_).editXY(cur, x, y);
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::ACTION, "InsetText::doDispatch()"
|
|
|
|
<< " [ cmd.action = " << cmd.action << ']');
|
2009-04-09 22:15:06 +00:00
|
|
|
|
2009-07-14 21:14:39 +00:00
|
|
|
if (getLayout().isPassThru()) {
|
2009-07-14 13:32:36 +00:00
|
|
|
// Force any new text to latex_language FIXME: This
|
|
|
|
// should only be necessary in constructor, but new
|
|
|
|
// paragraphs that are created by pressing enter at
|
|
|
|
// the start of an existing paragraph get the buffer
|
|
|
|
// language and not latex_language, so we take this
|
|
|
|
// brute force approach.
|
|
|
|
cur.current_font.setLanguage(latex_language);
|
|
|
|
cur.real_current_font.setLanguage(latex_language);
|
|
|
|
}
|
|
|
|
|
2009-07-14 13:00:42 +00:00
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_PASTE:
|
|
|
|
case LFUN_CLIPBOARD_PASTE:
|
|
|
|
case LFUN_SELECTION_PASTE:
|
|
|
|
case LFUN_PRIMARY_SELECTION_PASTE:
|
2009-04-09 22:15:06 +00:00
|
|
|
text_.dispatch(cur, cmd);
|
2009-07-14 13:00:42 +00:00
|
|
|
// If we we can only store plain text, we must reset all
|
|
|
|
// attributes.
|
|
|
|
// FIXME: Change only the pasted paragraphs
|
|
|
|
fixParagraphsFont();
|
|
|
|
break;
|
2009-10-26 23:49:43 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_DISSOLVE: {
|
|
|
|
bool const main_inset = &buffer().inset() == this;
|
|
|
|
bool const target_inset = cmd.argument().empty()
|
|
|
|
|| cmd.getArg(0) == insetName(lyxCode());
|
2009-11-02 04:01:45 +00:00
|
|
|
bool const one_cell = nargs() == 1;
|
2009-10-26 23:49:43 +00:00
|
|
|
|
|
|
|
if (!main_inset && target_inset && one_cell) {
|
|
|
|
// Text::dissolveInset assumes that the cursor
|
|
|
|
// is inside the Inset.
|
|
|
|
if (&cur.inset() != this)
|
|
|
|
cur.pushBackward(*this);
|
|
|
|
cur.beginUndoGroup();
|
|
|
|
text_.dispatch(cur, cmd);
|
|
|
|
cur.endUndoGroup();
|
|
|
|
} else
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-14 13:00:42 +00:00
|
|
|
default:
|
|
|
|
text_.dispatch(cur, cmd);
|
|
|
|
}
|
2009-04-10 00:08:50 +00:00
|
|
|
|
|
|
|
if (!cur.result().dispatched())
|
2009-04-09 22:15:06 +00:00
|
|
|
Inset::doDispatch(cur, cmd);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-03-18 13:57:20 +00:00
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2008-10-05 09:51:28 +00:00
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
status.setEnabled(!forcePlainLayout());
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
|
|
|
case LFUN_PARAGRAPH_PARAMS:
|
|
|
|
case LFUN_PARAGRAPH_PARAMS_APPLY:
|
|
|
|
case LFUN_PARAGRAPH_UPDATE:
|
|
|
|
status.setEnabled(allowParagraphCustomization());
|
|
|
|
return true;
|
2009-10-26 23:49:43 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_DISSOLVE: {
|
|
|
|
bool const main_inset = &buffer().inset() == this;
|
|
|
|
bool const target_inset = cmd.argument().empty()
|
|
|
|
|| cmd.getArg(0) == insetName(lyxCode());
|
2009-11-02 04:01:45 +00:00
|
|
|
bool const one_cell = nargs() == 1;
|
2009-10-26 23:49:43 +00:00
|
|
|
|
2009-11-02 04:01:45 +00:00
|
|
|
if (target_inset)
|
|
|
|
status.setEnabled(!main_inset && one_cell);
|
|
|
|
return target_inset;
|
2009-10-26 23:49:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-05 09:51:28 +00:00
|
|
|
default:
|
2009-02-23 19:00:23 +00:00
|
|
|
// Dispatch only to text_ if the cursor is inside
|
|
|
|
// the text_. It is not for context menus (bug 5797).
|
2009-04-10 00:08:50 +00:00
|
|
|
bool ret = false;
|
2009-02-23 19:00:23 +00:00
|
|
|
if (cur.text() == &text_)
|
2009-04-10 00:08:50 +00:00
|
|
|
ret = text_.getStatus(cur, cmd, status);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ret = Inset::getStatus(cur, cmd, status);
|
|
|
|
return ret;
|
2008-10-05 09:51:28 +00:00
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 13:00:42 +00:00
|
|
|
void InsetText::fixParagraphsFont()
|
|
|
|
{
|
2009-08-01 16:53:58 +00:00
|
|
|
if (!getLayout().isPassThru())
|
|
|
|
return;
|
|
|
|
|
2009-07-14 13:00:42 +00:00
|
|
|
Font font(inherit_font, buffer().params().language);
|
2009-08-01 16:53:58 +00:00
|
|
|
font.setLanguage(latex_language);
|
|
|
|
ParagraphList::iterator par = paragraphs().begin();
|
|
|
|
ParagraphList::iterator const end = paragraphs().end();
|
|
|
|
while (par != end) {
|
|
|
|
par->resetFonts(font);
|
|
|
|
par->params().clear();
|
|
|
|
++par;
|
2009-07-14 13:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-20 09:29:19 +00:00
|
|
|
void InsetText::setChange(Change const & change)
|
|
|
|
{
|
|
|
|
ParagraphList::iterator pit = paragraphs().begin();
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
|
|
|
for (; pit != end; ++pit) {
|
|
|
|
pit->setChange(change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-16 08:37:32 +00:00
|
|
|
void InsetText::acceptChanges()
|
2006-10-24 06:11:45 +00:00
|
|
|
{
|
2009-08-09 15:52:33 +00:00
|
|
|
text_.acceptChanges();
|
2006-10-24 21:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-16 08:37:32 +00:00
|
|
|
void InsetText::rejectChanges()
|
2006-10-24 21:38:47 +00:00
|
|
|
{
|
2009-08-09 15:52:33 +00:00
|
|
|
text_.rejectChanges();
|
2006-10-24 06:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 21:14:39 +00:00
|
|
|
void InsetText::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.useInsetLayout(getLayout());
|
|
|
|
for_each(paragraphs().begin(), paragraphs().end(),
|
|
|
|
bind(&Paragraph::validate, _1, ref(features)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetText::latex(odocstream & os, OutputParams const & runparams) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2009-07-14 18:27:54 +00:00
|
|
|
// This implements the standard way of handling the LaTeX
|
|
|
|
// output of a text inset, either a command or an
|
|
|
|
// environment. Standard collapsable insets should not
|
|
|
|
// redefine this, non-standard ones may call this.
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
int rows = 0;
|
|
|
|
if (!il.latexname().empty()) {
|
|
|
|
if (il.latextype() == InsetLayout::COMMAND) {
|
|
|
|
// FIXME UNICODE
|
|
|
|
if (runparams.moving_arg)
|
|
|
|
os << "\\protect";
|
|
|
|
os << '\\' << from_utf8(il.latexname());
|
|
|
|
if (!il.latexparam().empty())
|
|
|
|
os << from_utf8(il.latexparam());
|
|
|
|
os << '{';
|
|
|
|
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
|
|
|
|
os << "%\n\\begin{" << from_utf8(il.latexname()) << "}\n";
|
|
|
|
if (!il.latexparam().empty())
|
|
|
|
os << from_utf8(il.latexparam());
|
|
|
|
rows += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OutputParams rp = runparams;
|
|
|
|
if (il.isPassThru())
|
|
|
|
rp.verbatim = true;
|
|
|
|
if (il.isNeedProtect())
|
|
|
|
rp.moving_arg = true;
|
|
|
|
|
|
|
|
// Output the contents of the inset
|
2001-04-02 14:02:58 +00:00
|
|
|
TexRow texrow;
|
2009-07-14 18:27:54 +00:00
|
|
|
latexParagraphs(buffer(), text_, os, texrow, rp);
|
|
|
|
rows += texrow.rows();
|
|
|
|
|
|
|
|
if (!il.latexname().empty()) {
|
|
|
|
if (il.latextype() == InsetLayout::COMMAND) {
|
|
|
|
os << "}";
|
|
|
|
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
|
|
|
|
os << "\n\\end{" << from_utf8(il.latexname()) << "}\n";
|
|
|
|
rows += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
|
2000-09-26 15:25:14 +00:00
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
ParagraphList::const_iterator beg = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = paragraphs().end();
|
2003-05-27 22:41:04 +00:00
|
|
|
ParagraphList::const_iterator it = beg;
|
2005-07-15 19:10:25 +00:00
|
|
|
bool ref_printed = false;
|
2007-02-15 22:04:33 +00:00
|
|
|
int len = 0;
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it != beg) {
|
|
|
|
os << '\n';
|
|
|
|
if (runparams.linelen > 0)
|
|
|
|
os << '\n';
|
|
|
|
}
|
|
|
|
odocstringstream oss;
|
2008-02-27 20:43:16 +00:00
|
|
|
writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed);
|
2007-02-15 22:04:33 +00:00
|
|
|
docstring const str = oss.str();
|
|
|
|
os << str;
|
|
|
|
// FIXME: len is not computed fully correctly; in principle,
|
|
|
|
// we have to count the characters after the last '\n'
|
|
|
|
len = str.size();
|
|
|
|
}
|
2003-10-31 18:45:43 +00:00
|
|
|
|
2007-02-15 22:04:33 +00:00
|
|
|
return len;
|
2000-09-26 15:25:14 +00:00
|
|
|
}
|
|
|
|
|
2003-07-27 18:56:26 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
|
2000-10-27 10:04:51 +00:00
|
|
|
{
|
2009-07-14 20:25:25 +00:00
|
|
|
ParagraphList::const_iterator const beg = paragraphs().begin();
|
|
|
|
|
|
|
|
if (!undefined())
|
|
|
|
sgml::openTag(os, getLayout().latexname(),
|
|
|
|
beg->getID(buffer(), runparams) + getLayout().latexparam());
|
|
|
|
|
2009-08-09 18:35:39 +00:00
|
|
|
docbookParagraphs(text_, buffer(), os, runparams);
|
2009-07-14 20:25:25 +00:00
|
|
|
|
|
|
|
if (!undefined())
|
|
|
|
sgml::closeTag(os, getLayout().latexname());
|
|
|
|
|
2003-10-30 08:47:16 +00:00
|
|
|
return 0;
|
2000-10-27 10:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 21:05:34 +00:00
|
|
|
docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
|
2009-11-21 22:56:42 +00:00
|
|
|
{
|
|
|
|
return insetAsXHTML(xs, runparams, WriteEverything);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:22:23 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// There are cases where we may need to close open fonts and such
|
|
|
|
// and then re-open them when we are done. This would be the case, e.g.,
|
|
|
|
// if we were otherwise about to write:
|
|
|
|
// <em>word <div class='foot'>footnote text.</div> emph</em>
|
|
|
|
// The problem isn't so much that the footnote text will get emphasized:
|
|
|
|
// we can handle that with CSS. The problem is that this is invalid XHTML.
|
|
|
|
// One solution would be to make the footnote <span>, but the problem is
|
|
|
|
// completely general, and so we'd have to make absolutely everything into
|
|
|
|
// span. What I think will work is to check if we're about to write "div" and,
|
|
|
|
// if so, try to close fonts, etc.
|
|
|
|
// There are probably limits to how well we can do here, though, and we will
|
|
|
|
// have to rely upon users not putting footnotes inside noun-type insets.
|
2009-11-21 22:56:42 +00:00
|
|
|
docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & runparams,
|
|
|
|
XHTMLOptions opts) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2009-07-14 21:14:39 +00:00
|
|
|
if (undefined()) {
|
2009-11-19 17:51:06 +00:00
|
|
|
xhtmlParagraphs(text_, buffer(), xs, runparams);
|
2009-07-14 21:14:39 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
2009-06-05 17:48:14 +00:00
|
|
|
|
2009-10-27 19:17:52 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
2009-11-21 22:56:42 +00:00
|
|
|
if (opts & WriteOuterTag)
|
|
|
|
xs << StartTag(il.htmltag(), il.htmlattr());
|
|
|
|
if ((opts & WriteLabel) && !il.counter().empty()) {
|
2009-07-14 21:14:39 +00:00
|
|
|
BufferParams const & bp = buffer().masterBuffer()->params();
|
|
|
|
Counters & cntrs = bp.documentClass().counters();
|
|
|
|
cntrs.step(il.counter());
|
|
|
|
// FIXME: translate to paragraph language
|
2009-10-27 19:17:52 +00:00
|
|
|
if (!il.htmllabel().empty()) {
|
|
|
|
docstring const lbl =
|
|
|
|
cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
|
|
|
|
// FIXME is this check necessary?
|
|
|
|
if (!lbl.empty()) {
|
2009-11-19 17:51:06 +00:00
|
|
|
xs << StartTag(il.htmllabeltag(), il.htmllabelattr());
|
|
|
|
xs << lbl;
|
|
|
|
xs << EndTag(il.htmllabeltag());
|
2009-10-27 19:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-14 21:14:39 +00:00
|
|
|
}
|
2009-10-27 19:17:52 +00:00
|
|
|
|
2009-11-21 22:56:42 +00:00
|
|
|
if (opts & WriteInnerTag)
|
|
|
|
xs << StartTag(il.htmlinnertag(), il.htmlinnerattr());
|
2009-11-19 22:31:52 +00:00
|
|
|
if (il.isMultiPar())
|
|
|
|
xhtmlParagraphs(text_, buffer(), xs, runparams);
|
|
|
|
else {
|
|
|
|
OutputParams ours = runparams;
|
|
|
|
ours.html_make_pars = false;
|
|
|
|
xhtmlParagraphs(text_, buffer(), xs, ours);
|
|
|
|
}
|
2009-11-21 22:56:42 +00:00
|
|
|
if (opts & WriteInnerTag)
|
|
|
|
xs << EndTag(il.htmlinnertag());
|
|
|
|
if (opts & WriteOuterTag)
|
|
|
|
xs << EndTag(il.htmltag());
|
2009-07-14 21:14:39 +00:00
|
|
|
return docstring();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Move BufferView cached pointer out of LyXText:
* LyXText
- bv(), bv_owner, : deleted.
- These methods now need a (Buffer const &) argument: getFont(), applyOuterFont(), getLayoutFont(), getLabelFont(), setCharFont(), setLayout(), singleWidth(), leftMargin(), rightMargin(), computeRowMetrics(), isMainText(), spacing(), isRTL(), cursorX(), rowBreakPoint(), setRowWidth(), labelFill(), labelEnd().
- These methods now need a (BufferView const &) argument and are propably candidates for future removal when 1.6 is opened for development: redoParagraph(), x2pos(), getRowNearY(), getColumnNearX(), checkInsetHit(), setHeightOfRow().
- recUndo(): now need a LCursor argument.
* CoordCache::get(LyXText const *, pit_type):
- now const.
- use const_iterator instead of iterator.
* FontIterator:
- add (Buffer const &) argument to ctor
- buffer_: new const reference to applicable BufferView.
* InsetBase
- xo(), yo(), covers() and neverIndent() are now const.
* InsetText::setViewCache(): deleted
All other changes are due to the LyXText and InsetBase API changes.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15618 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-30 12:45:33 +00:00
|
|
|
void InsetText::cursorPos(BufferView const & bv,
|
2006-10-17 16:23:27 +00:00
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2003-05-03 18:05:53 +00:00
|
|
|
{
|
2007-09-17 21:45:14 +00:00
|
|
|
x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
|
2007-09-02 09:44:08 +00:00
|
|
|
y = bv.textMetrics(&text_).cursorY(sl, boundary);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
bool InsetText::showInsetDialog(BufferView *) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
return false;
|
2001-03-26 14:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
void InsetText::setText(docstring const & data, Font const & font, bool trackChanges)
|
2001-01-03 16:04:05 +00:00
|
|
|
{
|
2005-09-07 10:37:05 +00:00
|
|
|
clear();
|
2004-11-23 23:04:52 +00:00
|
|
|
Paragraph & first = paragraphs().front();
|
2002-08-12 00:15:19 +00:00
|
|
|
for (unsigned int i = 0; i < data.length(); ++i)
|
2006-10-20 11:44:58 +00:00
|
|
|
first.insertChar(i, data[i], font, trackChanges);
|
2001-01-03 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setAutoBreakRows(bool flag)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2005-07-17 01:13:36 +00:00
|
|
|
if (flag == text_.autoBreakRows_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
text_.autoBreakRows_ = flag;
|
|
|
|
if (flag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// remove previously existing newlines
|
|
|
|
ParagraphList::iterator it = paragraphs().begin();
|
|
|
|
ParagraphList::iterator end = paragraphs().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
for (int i = 0; i < it->size(); ++i)
|
|
|
|
if (it->isNewline(i))
|
2006-10-19 17:46:50 +00:00
|
|
|
// do not track the change, because the user
|
|
|
|
// is not allowed to revert/reject it
|
2006-10-21 17:05:20 +00:00
|
|
|
it->eraseChar(i, false);
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2004-08-14 15:55:22 +00:00
|
|
|
void InsetText::setDrawFrame(bool flag)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2004-08-14 15:55:22 +00:00
|
|
|
drawFrame_ = flag;
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
ColorCode InsetText::frameColor() const
|
2003-09-16 10:30:59 +00:00
|
|
|
{
|
2007-10-29 10:46:13 +00:00
|
|
|
return frame_color_;
|
2003-09-16 10:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
void InsetText::setFrameColor(ColorCode col)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2003-09-16 10:01:29 +00:00
|
|
|
frame_color_ = col;
|
2000-06-19 15:33:58 +00:00
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetText::appendParagraphs(ParagraphList & plist)
|
2002-03-21 15:58:54 +00:00
|
|
|
{
|
2006-10-20 14:06:18 +00:00
|
|
|
// There is little we can do here to keep track of changes.
|
|
|
|
// As of 2006/10/20, appendParagraphs is used exclusively by
|
|
|
|
// LyXTabular::setMultiColumn. In this context, the paragraph break
|
|
|
|
// is lost irreversibly and the appended text doesn't really change
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
ParagraphList & pl = paragraphs();
|
2004-11-24 21:58:42 +00:00
|
|
|
|
2003-04-28 16:22:32 +00:00
|
|
|
ParagraphList::iterator pit = plist.begin();
|
2004-11-23 23:04:52 +00:00
|
|
|
ParagraphList::iterator ins = pl.insert(pl.end(), *pit);
|
2003-04-28 16:22:32 +00:00
|
|
|
++pit;
|
2008-02-27 20:43:16 +00:00
|
|
|
mergeParagraph(buffer().params(), pl,
|
2007-12-12 19:28:07 +00:00
|
|
|
distance(pl.begin(), ins) - 1);
|
2003-04-28 16:22:32 +00:00
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
for_each(pit, plist.end(),
|
2007-05-28 22:27:45 +00:00
|
|
|
bind(&ParagraphList::push_back, ref(pl), _1));
|
2002-03-21 15:58:54 +00:00
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
|
|
|
|
|
2009-11-22 20:50:35 +00:00
|
|
|
void InsetText::addPreview(DocIterator const & text_inset_pos,
|
|
|
|
PreviewLoader & loader) const
|
2002-08-02 16:39:43 +00:00
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
ParagraphList::const_iterator pit = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator pend = paragraphs().end();
|
2009-11-22 20:50:35 +00:00
|
|
|
int pidx = 0;
|
2003-04-02 21:19:35 +00:00
|
|
|
|
2009-11-22 20:50:35 +00:00
|
|
|
DocIterator inset_pos = text_inset_pos;
|
|
|
|
inset_pos.push_back(CursorSlice(*const_cast<InsetText *>(this)));
|
|
|
|
|
|
|
|
for (; pit != pend; ++pit, ++pidx) {
|
2007-10-18 15:29:51 +00:00
|
|
|
InsetList::const_iterator it = pit->insetList().begin();
|
|
|
|
InsetList::const_iterator end = pit->insetList().end();
|
2009-11-22 20:50:35 +00:00
|
|
|
inset_pos.pit() = pidx;
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
inset_pos.pos() = it->pos;
|
|
|
|
it->inset->addPreview(inset_pos, loader);
|
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-01 13:35:49 +00:00
|
|
|
|
|
|
|
|
2004-03-28 22:00:22 +00:00
|
|
|
ParagraphList const & InsetText::paragraphs() const
|
|
|
|
{
|
|
|
|
return text_.paragraphs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList & InsetText::paragraphs()
|
2003-12-01 13:35:49 +00:00
|
|
|
{
|
2004-03-28 22:00:22 +00:00
|
|
|
return text_.paragraphs();
|
2003-12-01 13:35:49 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetText::updateLabels(ParIterator const & it)
|
2007-08-12 21:43:58 +00:00
|
|
|
{
|
|
|
|
ParIterator it2 = it;
|
|
|
|
it2.forwardPos();
|
2008-11-16 17:49:00 +00:00
|
|
|
LASSERT(&it2.inset() == this && it2.pit() == 0, return);
|
2009-05-09 20:26:04 +00:00
|
|
|
if (producesOutput())
|
2008-11-16 17:49:00 +00:00
|
|
|
buffer().updateLabels(it2);
|
2009-05-09 20:26:04 +00:00
|
|
|
else {
|
2008-11-15 19:30:58 +00:00
|
|
|
DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
|
2008-04-23 10:55:51 +00:00
|
|
|
Counters const savecnt = tclass.counters();
|
2008-11-16 17:49:00 +00:00
|
|
|
buffer().updateLabels(it2);
|
2008-04-23 10:55:51 +00:00
|
|
|
tclass.counters() = savecnt;
|
|
|
|
}
|
2007-08-12 21:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 21:14:39 +00:00
|
|
|
void InsetText::tocString(odocstream & os) const
|
|
|
|
{
|
|
|
|
if (!getLayout().isInToc())
|
|
|
|
return;
|
|
|
|
os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-03 11:12:45 +00:00
|
|
|
void InsetText::addToToc(DocIterator const & cdit)
|
|
|
|
{
|
|
|
|
DocIterator dit = cdit;
|
|
|
|
dit.push_back(CursorSlice(*this));
|
|
|
|
Toc & toc = buffer().tocBackend().toc("tableofcontents");
|
|
|
|
|
|
|
|
BufferParams const & bufparams = buffer_->params();
|
|
|
|
const int min_toclevel = bufparams.documentClass().min_toclevel();
|
|
|
|
|
|
|
|
// For each paragraph, traverse its insets and let them add
|
|
|
|
// their toc items
|
|
|
|
ParagraphList & pars = paragraphs();
|
|
|
|
pit_type pend = paragraphs().size();
|
|
|
|
for (pit_type pit = 0; pit != pend; ++pit) {
|
|
|
|
Paragraph const & par = pars[pit];
|
|
|
|
dit.pit() = pit;
|
|
|
|
// the string that goes to the toc (could be the optarg)
|
|
|
|
docstring tocstring;
|
|
|
|
InsetList::const_iterator it = par.insetList().begin();
|
|
|
|
InsetList::const_iterator end = par.insetList().end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
Inset & inset = *it->inset;
|
|
|
|
dit.pos() = it->pos;
|
|
|
|
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
|
|
|
|
inset.addToToc(dit);
|
|
|
|
switch (inset.lyxCode()) {
|
|
|
|
case OPTARG_CODE: {
|
|
|
|
if (!tocstring.empty())
|
|
|
|
break;
|
|
|
|
dit.pos() = 0;
|
|
|
|
Paragraph const & insetpar =
|
|
|
|
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
|
|
|
|
if (!par.labelString().empty())
|
|
|
|
tocstring = par.labelString() + ' ';
|
2008-11-03 13:47:12 +00:00
|
|
|
tocstring += insetpar.asString(AS_STR_INSETS);
|
2008-06-03 11:12:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-11 20:08:39 +00:00
|
|
|
// now the toc entry for the paragraph
|
2008-06-03 11:12:45 +00:00
|
|
|
int const toclevel = par.layout().toclevel;
|
|
|
|
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
|
|
|
|
dit.pos() = 0;
|
|
|
|
// insert this into the table of contents
|
|
|
|
if (tocstring.empty())
|
2008-11-03 13:47:12 +00:00
|
|
|
tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);
|
2008-06-03 11:12:45 +00:00
|
|
|
toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring));
|
|
|
|
}
|
2008-09-30 11:06:34 +00:00
|
|
|
|
|
|
|
// And now the list of changes.
|
|
|
|
par.addChangesToToc(dit, buffer());
|
2008-06-03 11:12:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 19:20:12 +00:00
|
|
|
bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
if (buffer().isClean())
|
2008-02-26 19:20:12 +00:00
|
|
|
return Inset::notifyCursorLeaves(old, cur);
|
|
|
|
|
|
|
|
// find text inset in old cursor
|
|
|
|
Cursor insetCur = old;
|
|
|
|
int scriptSlice = insetCur.find(this);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(scriptSlice != -1, /**/);
|
2008-02-26 19:20:12 +00:00
|
|
|
insetCur.cutOff(scriptSlice);
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(&insetCur.inset() == this, /**/);
|
2008-02-26 19:20:12 +00:00
|
|
|
|
|
|
|
// update the old paragraph's words
|
2009-05-01 10:30:16 +00:00
|
|
|
insetCur.paragraph().updateWords();
|
2008-02-26 19:20:12 +00:00
|
|
|
|
|
|
|
return Inset::notifyCursorLeaves(old, cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
bool InsetText::completionSupported(Cursor const & cur) const
|
|
|
|
{
|
2008-11-17 11:46:07 +00:00
|
|
|
//LASSERT(&cur.bv().cursor().inset() != this, return false);
|
2008-03-15 12:22:28 +00:00
|
|
|
return text_.completionSupported(cur);
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::inlineCompletionSupported(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
return completionSupported(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::automaticInlineCompletion() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_inline_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::automaticPopupCompletion() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_popup_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 17:07:10 +00:00
|
|
|
bool InsetText::showCompletionCursor() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_cursor_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
|
2008-02-21 19:42:34 +00:00
|
|
|
{
|
2008-03-15 12:22:28 +00:00
|
|
|
return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetText::completionPrefix(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
if (!completionSupported(cur))
|
|
|
|
return docstring();
|
2008-03-15 12:22:28 +00:00
|
|
|
return text_.completionPrefix(cur);
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
|
2008-03-15 12:22:28 +00:00
|
|
|
bool finished)
|
2008-02-21 19:42:34 +00:00
|
|
|
{
|
|
|
|
if (!completionSupported(cur))
|
|
|
|
return false;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
2008-03-15 12:22:28 +00:00
|
|
|
return text_.insertCompletion(cur, s, finished);
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y,
|
2008-02-25 09:26:46 +00:00
|
|
|
Dimension & dim) const
|
2008-02-21 19:42:34 +00:00
|
|
|
{
|
|
|
|
TextMetrics const & tm = cur.bv().textMetrics(&text_);
|
2008-03-15 12:22:28 +00:00
|
|
|
tm.completionPosAndDim(cur, x, y, dim);
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 22:57:22 +00:00
|
|
|
docstring InsetText::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
2008-03-09 23:30:02 +00:00
|
|
|
return from_ascii("context-edit");
|
2008-03-08 22:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-19 13:50:19 +00:00
|
|
|
InsetCaption const * InsetText::getCaptionInset() const
|
|
|
|
{
|
|
|
|
ParagraphList::const_iterator pit = paragraphs().begin();
|
|
|
|
for (; pit != paragraphs().end(); ++pit) {
|
|
|
|
InsetList::const_iterator it = pit->insetList().begin();
|
|
|
|
for (; it != pit->insetList().end(); ++it) {
|
|
|
|
Inset & inset = *it->inset;
|
|
|
|
if (inset.lyxCode() == CAPTION_CODE) {
|
|
|
|
InsetCaption const * ins =
|
|
|
|
static_cast<InsetCaption const *>(it->inset);
|
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetText::getCaptionText(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
InsetCaption const * ins = getCaptionInset();
|
|
|
|
if (ins == 0)
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
odocstringstream ods;
|
|
|
|
ins->getCaptionAsPlaintext(ods, runparams);
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
InsetCaption const * ins = getCaptionInset();
|
|
|
|
if (ins == 0)
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
odocstringstream ods;
|
|
|
|
docstring def = ins->getCaptionAsHTML(ods, runparams);
|
|
|
|
if (!def.empty())
|
|
|
|
ods << def << '\n';
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|