2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insettext.C
|
|
|
|
|
* 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
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author J<EFBFBD>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>
|
|
|
|
|
|
|
|
|
|
#include "insettext.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "insetnewline.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "BufferView.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2003-11-06 11:56:10 +00:00
|
|
|
|
#include "cursor.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "errorlist.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "intl.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
|
#include "LColor.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "lyxfind.h"
|
|
|
|
|
#include "lyxlex.h"
|
2000-06-16 15:13:25 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "output_docbook.h"
|
|
|
|
|
#include "output_latex.h"
|
|
|
|
|
#include "output_linuxdoc.h"
|
|
|
|
|
#include "output_plaintext.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-11-20 10:38:12 +00:00
|
|
|
|
#include "lyxrow.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "sgml.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "texrow.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
2001-12-18 03:21:10 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
2002-01-14 13:04:06 +00:00
|
|
|
|
#include "support/lyxalgo.h" // lyx::count
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
2002-08-14 18:38:59 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using bv_funcs::replaceSelection;
|
|
|
|
|
|
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
|
|
|
|
using lyx::graphics::PreviewLoader;
|
|
|
|
|
|
|
|
|
|
using lyx::support::isStrUnsignedInt;
|
|
|
|
|
using lyx::support::strToUnsignedInt;
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
using std::endl;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::for_each;
|
2000-04-04 00:19:15 +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;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::vector;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-08-01 12:52:59 +00:00
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetText::InsetText(BufferParams const & bp)
|
2003-10-08 14:29:16 +00:00
|
|
|
|
: UpdatableInset(),
|
|
|
|
|
paragraphs(1),
|
|
|
|
|
autoBreakRows_(false),
|
|
|
|
|
drawFrame_(NEVER),
|
|
|
|
|
frame_color_(LColor::insetframe),
|
|
|
|
|
text_(0, this, true, paragraphs)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-10-08 14:29:16 +00:00
|
|
|
|
textwidth_ = 0; // broken
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (bp.tracking_changes)
|
|
|
|
|
paragraphs.begin()->trackChanges();
|
2003-10-08 14:29:16 +00:00
|
|
|
|
init();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetText::InsetText(InsetText const & in)
|
2003-10-08 14:29:16 +00:00
|
|
|
|
: UpdatableInset(in),
|
|
|
|
|
text_(in.text_.bv_owner, this, true, paragraphs)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-10-08 14:29:16 +00:00
|
|
|
|
// this is ugly...
|
|
|
|
|
operator=(in);
|
2000-03-28 16:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2003-10-08 14:29:16 +00:00
|
|
|
|
void InsetText::operator=(InsetText const & in)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2003-10-08 14:29:16 +00:00
|
|
|
|
UpdatableInset::operator=(in);
|
|
|
|
|
paragraphs = in.paragraphs;
|
|
|
|
|
autoBreakRows_ = in.autoBreakRows_;
|
|
|
|
|
drawFrame_ = in.drawFrame_;
|
|
|
|
|
frame_color_ = in.frame_color_;
|
|
|
|
|
textwidth_ = in.textwidth_;
|
|
|
|
|
text_ = LyXText(in.text_.bv_owner, this, true, paragraphs);
|
|
|
|
|
init();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2003-10-08 14:29:16 +00:00
|
|
|
|
void InsetText::init()
|
2000-03-28 16:18:02 +00:00
|
|
|
|
{
|
2003-10-08 14:29:16 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
for (; pit != end; ++pit)
|
|
|
|
|
pit->setInsetOwner(this);
|
|
|
|
|
text_.paragraphs_ = ¶graphs;
|
2003-10-10 09:01:23 +00:00
|
|
|
|
old_par = -1;
|
2001-12-05 15:34:41 +00:00
|
|
|
|
in_insetAllowed = false;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void InsetText::clear(bool just_mark_erased)
|
2000-07-14 14:57:20 +00:00
|
|
|
|
{
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (just_mark_erased) {
|
|
|
|
|
ParagraphList::iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
2003-08-28 07:41:31 +00:00
|
|
|
|
for (; it != end; ++it)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
it->markErased();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2002-03-04 16:10:47 +00:00
|
|
|
|
// This is a gross hack...
|
2002-08-12 00:15:19 +00:00
|
|
|
|
LyXLayout_ptr old_layout = paragraphs.begin()->layout();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.clear();
|
2003-05-24 11:54:10 +00:00
|
|
|
|
paragraphs.push_back(Paragraph());
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.begin()->setInsetOwner(this);
|
|
|
|
|
paragraphs.begin()->layout(old_layout);
|
2000-07-14 14:57:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetText::clone() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetText(*this));
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetText::write(Buffer const & buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
os << "Text\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
|
writeParagraphData(buf, os);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetText::writeParagraphData(Buffer const & buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::const_iterator end = paragraphs.end();
|
2002-08-26 09:31:09 +00:00
|
|
|
|
Paragraph::depth_type dth = 0;
|
2002-08-20 17:29:37 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
it->write(buf, os, buf.params(), dth);
|
2002-08-20 17:29:37 +00:00
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetText::read(Buffer const & buf, LyXLex & lex)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
string token;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
clear(false);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-02 12:01:24 +00:00
|
|
|
|
#warning John, look here. Doesnt make much sense.
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (buf.params().tracking_changes)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
paragraphs.begin()->trackChanges();
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
// delete the initial paragraph
|
2003-10-02 12:01:24 +00:00
|
|
|
|
Paragraph oldpar = *paragraphs.begin();
|
2003-03-12 05:46:35 +00:00
|
|
|
|
paragraphs.clear();
|
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
|
while (lex.isOK()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
token = lex.getString();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
2001-07-25 19:45:21 +00:00
|
|
|
|
if (token == "\\end_inset") {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2001-07-25 19:45:21 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-07-28 22:30:50 +00:00
|
|
|
|
if (token == "\\end_document") {
|
|
|
|
|
lex.printError("\\end_document read in inset! Error in document!");
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-12 02:39:12 +00:00
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
// FIXME: ugly.
|
2003-08-28 07:41:31 +00:00
|
|
|
|
const_cast<Buffer&>(buf).readParagraph(lex, token, paragraphs, pit, depth);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator const end = paragraphs.end();
|
|
|
|
|
for (; pit != end; ++pit)
|
|
|
|
|
pit->setInsetOwner(this);
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
|
"Read: `$$Token'");
|
|
|
|
|
}
|
2003-10-02 12:01:24 +00:00
|
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
|
// ensure we have at least one par.
|
|
|
|
|
if (paragraphs.empty())
|
|
|
|
|
paragraphs.push_back(oldpar);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
textwidth_ = max(40, mi.base.textwidth - 30);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
BufferView * bv = mi.base.bv;
|
2003-07-14 13:49:13 +00:00
|
|
|
|
setViewCache(bv);
|
2003-07-22 10:12:24 +00:00
|
|
|
|
text_.metrics(mi, dim);
|
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
2003-05-21 08:22:25 +00:00
|
|
|
|
dim_ = dim;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-18 12:05:50 +00:00
|
|
|
|
int InsetText::textWidth() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-08-26 14:50:16 +00:00
|
|
|
|
return textwidth_;
|
2000-06-23 15:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2003-03-22 17:26:03 +00:00
|
|
|
|
// update our idea of where we are. Clearly, we should
|
|
|
|
|
// not have to know this information.
|
2003-11-10 15:38:20 +00:00
|
|
|
|
xo_ = x;
|
|
|
|
|
yo_ = y;
|
2003-03-22 17:26:03 +00:00
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
int const start_x = x;
|
2003-03-22 17:26:03 +00:00
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
BufferView * bv = pi.base.bv;
|
|
|
|
|
Painter & pain = pi.pain;
|
2001-08-02 14:55:06 +00:00
|
|
|
|
|
|
|
|
|
// repaint the background if needed
|
2003-03-17 01:34:36 +00:00
|
|
|
|
if (backgroundColor() != LColor::background)
|
2003-08-19 16:46:47 +00:00
|
|
|
|
clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, y);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
|
2003-07-28 13:18:35 +00:00
|
|
|
|
bv->hideCursor();
|
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
|
if (!owner())
|
2003-05-30 06:48:24 +00:00
|
|
|
|
x += scroll();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
|
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2001-04-06 12:47:50 +00:00
|
|
|
|
|
2003-11-21 08:35:15 +00:00
|
|
|
|
text_.xo_ = x;
|
|
|
|
|
text_.yo_ = y - text_.firstRow()->ascent_of_text() + bv->top_y();
|
2003-11-20 10:38:12 +00:00
|
|
|
|
|
2003-08-19 16:46:47 +00:00
|
|
|
|
paintTextInset(*bv, text_, x, y);
|
2001-06-14 14:10:25 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
|
2003-08-19 16:46:47 +00:00
|
|
|
|
drawFrame(pain, start_x);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
|
void InsetText::drawFrame(Painter & pain, int x) const
|
2001-04-27 14:03:25 +00:00
|
|
|
|
{
|
2003-08-05 11:29:58 +00:00
|
|
|
|
int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
|
|
|
|
|
int const frame_x = x + ttoD2;
|
2003-11-10 15:38:20 +00:00
|
|
|
|
int const frame_y = yo_ - dim_.asc + ttoD2;
|
2003-08-05 11:29:58 +00:00
|
|
|
|
int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
|
|
|
|
|
int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
|
2003-09-16 10:30:59 +00:00
|
|
|
|
pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor());
|
2001-04-27 14:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-05 11:29:58 +00:00
|
|
|
|
void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/)
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
2003-07-17 06:45:39 +00:00
|
|
|
|
if (!bv)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-09-16 10:01:29 +00:00
|
|
|
|
if (!autoBreakRows_ && paragraphs.size() > 1)
|
2003-04-28 16:22:32 +00:00
|
|
|
|
collapseParagraphs(bv);
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (!text_.selection.set())
|
|
|
|
|
text_.selection.cursor = text_.cursor;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
bv->owner()->view_state_changed();
|
2002-01-13 13:07:27 +00:00
|
|
|
|
bv->owner()->updateMenubar();
|
|
|
|
|
bv->owner()->updateToolbar();
|
2003-10-10 09:01:23 +00:00
|
|
|
|
if (old_par != text_.cursor.par()) {
|
2003-07-10 13:21:45 +00:00
|
|
|
|
bv->owner()->setLayout(cpar()->layout()->name());
|
2003-10-10 09:01:23 +00:00
|
|
|
|
old_par = text_.cursor.par();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
string const InsetText::editMessage() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return _("Opened Text Inset");
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
void InsetText::sanitizeEmptyText(BufferView * bv)
|
2002-04-16 14:10:39 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (paragraphs.size() == 1
|
|
|
|
|
&& paragraphs.begin()->empty()
|
|
|
|
|
&& bv->getParentLanguage(this) != text_.current_font.language()) {
|
2002-04-16 14:10:39 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
|
|
|
|
setFont(bv, font, false);
|
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
extern LCursor theTempCursor;
|
2000-02-25 13:35:38 +00:00
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void InsetText::edit(BufferView * bv, bool left)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
{
|
2003-11-06 16:43:12 +00:00
|
|
|
|
lyxerr << "InsetText: edit left/right" << endl;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
setViewCache(bv);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
old_par = -1;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
if (left)
|
|
|
|
|
text_.setCursorIntern(0, 0);
|
|
|
|
|
else
|
|
|
|
|
text_.setCursor(paragraphs.size() - 1, paragraphs.back().size());
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
sanitizeEmptyText(bv);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
updateLocal(bv, false);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
bv->updateParagraphDialog();
|
2003-11-04 12:36:59 +00:00
|
|
|
|
}
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
void InsetText::edit(BufferView * bv, int x, int y)
|
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
lyxerr << "InsetText::edit xy" << endl;
|
2003-11-04 12:36:59 +00:00
|
|
|
|
old_par = -1;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
sanitizeEmptyText(bv);
|
2003-11-21 08:35:15 +00:00
|
|
|
|
text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y()
|
|
|
|
|
- text_.yo_);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
text_.clearSelection();
|
|
|
|
|
finishUndo();
|
|
|
|
|
|
|
|
|
|
updateLocal(bv, false);
|
2003-11-10 09:06:48 +00:00
|
|
|
|
bv->updateParagraphDialog();
|
2003-11-04 12:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
|
idx_type &, pos_type &)
|
2003-11-04 12:36:59 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
lyxerr << "InsetText::priv_dispatch (begin), act: "
|
2003-11-17 20:28:11 +00:00
|
|
|
|
<< cmd.action << " " << endl;
|
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
setViewCache(bv);
|
2003-11-17 20:28:11 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
DispatchResult result;
|
|
|
|
|
result.dispatched(true);
|
|
|
|
|
|
|
|
|
|
bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1;
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
2003-07-21 11:01:29 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2003-11-17 20:28:11 +00:00
|
|
|
|
bv->cursor() = theTempCursor;
|
|
|
|
|
// fall through
|
2001-04-02 14:02:58 +00:00
|
|
|
|
default:
|
2003-11-10 09:06:48 +00:00
|
|
|
|
result = text_.dispatch(cmd);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-02-11 09:58:20 +00:00
|
|
|
|
|
2003-11-17 20:28:11 +00:00
|
|
|
|
// If the action has deleted all text in the inset, we need
|
|
|
|
|
// to change the language to the language of the surronding
|
|
|
|
|
// text.
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (!was_empty && paragraphs.begin()->empty() &&
|
2003-06-18 17:43:49 +00:00
|
|
|
|
paragraphs.size() == 1) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
2001-06-28 10:25:20 +00:00
|
|
|
|
setFont(bv, font, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2001-02-11 09:58:20 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
lyxerr << "InsetText::priv_dispatch (end)" << endl;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return result;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetText::latex(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
TexRow texrow;
|
2003-05-22 22:44:30 +00:00
|
|
|
|
latexParagraphs(buf, paragraphs, os, texrow, runparams);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return texrow.rows();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetText::plaintext(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator beg = paragraphs.begin();
|
|
|
|
|
ParagraphList::const_iterator end = paragraphs.end();
|
|
|
|
|
ParagraphList::const_iterator it = beg;
|
2003-10-31 18:45:43 +00:00
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
asciiParagraph(buf, *it, os, runparams, it == beg);
|
|
|
|
|
|
|
|
|
|
//FIXME: Give the total numbers of lines
|
|
|
|
|
return 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-27 18:56:26 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetText::linuxdoc(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-07-26 21:53:54 +00:00
|
|
|
|
{
|
2003-10-31 18:45:43 +00:00
|
|
|
|
linuxdocParagraphs(buf, paragraphs, os, runparams);
|
2003-07-26 21:53:54 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2003-07-27 18:56:26 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetText::docbook(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-10-27 10:04:51 +00:00
|
|
|
|
{
|
2003-10-31 18:45:43 +00:00
|
|
|
|
docbookParagraphs(buf, paragraphs, os, runparams);
|
2003-10-30 08:47:16 +00:00
|
|
|
|
return 0;
|
2000-10-27 10:04:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetText::validate(LaTeXFeatures & features) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2002-08-14 18:38:59 +00:00
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(),
|
|
|
|
|
boost::bind(&Paragraph::validate, _1, boost::ref(features)));
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
void InsetText::getCursorPos(BufferView *, int & x, int & y) const
|
2003-05-03 18:05:53 +00:00
|
|
|
|
{
|
2003-11-17 12:39:24 +00:00
|
|
|
|
x = text_.cursor.x() + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
y = text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
int InsetText::insetInInsetY() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2002-01-04 16:03:53 +00:00
|
|
|
|
inset->setOwner(this);
|
2003-07-18 15:43:52 +00:00
|
|
|
|
text_.insertInset(inset);
|
2003-08-04 15:14:11 +00:00
|
|
|
|
updateLocal(bv, true);
|
2001-07-12 12:26:06 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
bool InsetText::insetAllowed(InsetOld::Code code) const
|
2001-07-12 12:26:06 +00:00
|
|
|
|
{
|
2001-12-05 23:13:02 +00:00
|
|
|
|
// in_insetAllowed is a really gross hack,
|
|
|
|
|
// to allow us to call the owner's insetAllowed
|
|
|
|
|
// without stack overflow, which can happen
|
|
|
|
|
// when the owner uses InsetCollapsable::insetAllowed()
|
2001-12-05 15:34:41 +00:00
|
|
|
|
bool ret = true;
|
|
|
|
|
if (in_insetAllowed)
|
|
|
|
|
return ret;
|
|
|
|
|
in_insetAllowed = true;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (owner())
|
2001-12-05 15:34:41 +00:00
|
|
|
|
ret = owner()->insetAllowed(code);
|
|
|
|
|
in_insetAllowed = false;
|
|
|
|
|
return ret;
|
2001-07-12 14:35:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 20:18:39 +00:00
|
|
|
|
void InsetText::getLabelList(Buffer const & buffer,
|
|
|
|
|
std::vector<string> & list) const
|
2001-04-04 23:00:42 +00:00
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::const_iterator pend = paragraphs.end();
|
2002-08-14 18:38:59 +00:00
|
|
|
|
for (; pit != pend; ++pit) {
|
2003-05-29 01:13:18 +00:00
|
|
|
|
InsetList::const_iterator beg = pit->insetlist.begin();
|
|
|
|
|
InsetList::const_iterator end = pit->insetlist.end();
|
2003-06-16 11:49:38 +00:00
|
|
|
|
for (; beg != end; ++beg)
|
2003-09-18 20:18:39 +00:00
|
|
|
|
beg->inset->getLabelList(buffer, list);
|
2001-04-04 23:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool selectall)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-06-18 17:43:49 +00:00
|
|
|
|
if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
|
2003-07-10 13:21:45 +00:00
|
|
|
|
|| cpar()->empty()) {
|
2003-07-18 15:43:52 +00:00
|
|
|
|
text_.setFont(font, toggleall);
|
2001-08-03 13:09:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-16 07:15:10 +00:00
|
|
|
|
if (text_.selection.set())
|
2003-10-13 10:59:31 +00:00
|
|
|
|
text_.recUndo(text_.cursor.par());
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-16 07:15:10 +00:00
|
|
|
|
if (selectall) {
|
|
|
|
|
text_.cursorTop();
|
|
|
|
|
text_.selection.cursor = text_.cursor;
|
|
|
|
|
text_.cursorBottom();
|
|
|
|
|
text_.setSelection();
|
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.toggleFree(font, toggleall);
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (selectall)
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-08-04 15:14:11 +00:00
|
|
|
|
updateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void InsetText::markNew(bool track_changes)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
2003-08-05 11:54:44 +00:00
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
for (; pit != end; ++pit) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (track_changes) {
|
|
|
|
|
pit->trackChanges();
|
|
|
|
|
} else {
|
|
|
|
|
// no-op when not tracking
|
|
|
|
|
pit->cleanChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2002-03-26 11:05:30 +00:00
|
|
|
|
void InsetText::setText(string const & data, LyXFont const & font)
|
2001-01-03 16:04:05 +00:00
|
|
|
|
{
|
2003-02-08 19:18:01 +00:00
|
|
|
|
clear(false);
|
2002-08-12 00:15:19 +00:00
|
|
|
|
for (unsigned int i = 0; i < data.length(); ++i)
|
|
|
|
|
paragraphs.begin()->insertChar(i, data[i], font);
|
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
|
|
|
|
{
|
2003-09-16 10:01:29 +00:00
|
|
|
|
if (flag != autoBreakRows_) {
|
|
|
|
|
autoBreakRows_ = flag;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!flag)
|
|
|
|
|
removeNewlines();
|
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
void InsetText::setDrawFrame(DrawFrame how)
|
2000-05-15 14:49:36 +00:00
|
|
|
|
{
|
2003-08-11 09:09:01 +00:00
|
|
|
|
drawFrame_ = how;
|
2000-05-15 14:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
|
LColor_color InsetText::frameColor() const
|
2003-09-16 10:30:59 +00:00
|
|
|
|
{
|
|
|
|
|
return LColor::color(frame_color_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 11:48:11 +00:00
|
|
|
|
void InsetText::setFrameColor(LColor_color 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
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
pos_type InsetText::cpos() const
|
2000-06-21 15:07:57 +00:00
|
|
|
|
{
|
2003-07-10 11:31:54 +00:00
|
|
|
|
return text_.cursor.pos();
|
2000-06-21 15:07:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
ParagraphList::iterator InsetText::cpar() const
|
2000-06-21 15:07:57 +00:00
|
|
|
|
{
|
2003-10-09 10:52:12 +00:00
|
|
|
|
return text_.cursorPar();
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
RowList::iterator InsetText::crow() const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2003-10-24 09:45:07 +00:00
|
|
|
|
return cpar()->getRow(cpos());
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-07-10 10:06:20 +00:00
|
|
|
|
void InsetText::setViewCache(BufferView const * bv) const
|
|
|
|
|
{
|
2003-08-11 09:09:01 +00:00
|
|
|
|
if (bv) {
|
|
|
|
|
if (bv != text_.bv_owner) {
|
2003-08-15 14:54:19 +00:00
|
|
|
|
//lyxerr << "setting view cache from "
|
|
|
|
|
// << text_.bv_owner << " to " << bv << "\n";
|
2003-08-11 09:09:01 +00:00
|
|
|
|
text_.init(const_cast<BufferView *>(bv));
|
|
|
|
|
}
|
2003-07-10 10:06:20 +00:00
|
|
|
|
text_.bv_owner = const_cast<BufferView *>(bv);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
}
|
2003-07-10 10:06:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
|
void InsetText::removeNewlines()
|
|
|
|
|
{
|
2002-08-14 18:38:59 +00:00
|
|
|
|
ParagraphList::iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
2003-08-11 09:09:01 +00:00
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
for (int i = 0; i < it->size(); ++i)
|
|
|
|
|
if (it->isNewline(i))
|
2002-08-14 18:38:59 +00:00
|
|
|
|
it->erase(i);
|
2000-08-07 15:21:05 +00:00
|
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
int InsetText::scroll(bool /*recursive*/) const
|
2001-04-27 14:03:25 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return UpdatableInset::scroll(false);
|
2001-04-27 14:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetText::clearSelection(BufferView *)
|
2001-05-28 15:11:24 +00:00
|
|
|
|
{
|
2003-08-19 16:46:47 +00:00
|
|
|
|
text_.clearSelection();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
|
void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
|
2001-06-01 15:10:26 +00:00
|
|
|
|
{
|
2001-12-04 16:10:19 +00:00
|
|
|
|
Painter & pain = bv->painter();
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int w = dim_.wid;
|
|
|
|
|
int h = dim_.asc + dim_.des;
|
|
|
|
|
int ty = baseline - dim_.asc;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-06-01 15:10:26 +00:00
|
|
|
|
if (ty < 0) {
|
|
|
|
|
h += ty;
|
|
|
|
|
ty = 0;
|
|
|
|
|
}
|
2003-07-31 10:48:50 +00:00
|
|
|
|
if (ty + h > pain.paperHeight())
|
2001-06-01 15:10:26 +00:00
|
|
|
|
h = pain.paperHeight();
|
2003-11-10 15:38:20 +00:00
|
|
|
|
if (xo_ + w > pain.paperWidth())
|
2001-06-01 15:10:26 +00:00
|
|
|
|
w = pain.paperWidth();
|
2003-03-22 17:26:03 +00:00
|
|
|
|
pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
|
2001-06-01 15:10:26 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
2003-05-05 15:39:48 +00:00
|
|
|
|
ParagraphList * InsetText::getParagraphs(int i) const
|
2001-09-01 21:26:34 +00:00
|
|
|
|
{
|
2003-05-05 15:39:48 +00:00
|
|
|
|
return (i == 0) ? const_cast<ParagraphList*>(¶graphs) : 0;
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
LyXText * InsetText::getText(int i) const
|
|
|
|
|
{
|
|
|
|
|
return (i == 0) ? const_cast<LyXText*>(&text_) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-22 09:45:31 +00:00
|
|
|
|
bool InsetText::checkInsertChar(LyXFont & font)
|
|
|
|
|
{
|
2003-08-04 15:59:01 +00:00
|
|
|
|
return owner() ? owner()->checkInsertChar(font) : true;
|
2001-10-22 09:45:31 +00:00
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-06 10:02:40 +00:00
|
|
|
|
void InsetText::collapseParagraphs(BufferView * bv)
|
2001-12-18 12:35:53 +00:00
|
|
|
|
{
|
2003-06-18 17:43:49 +00:00
|
|
|
|
while (paragraphs.size() > 1) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
ParagraphList::iterator const first = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator second = first;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
++second;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
size_t const first_par_size = first->size();
|
|
|
|
|
|
|
|
|
|
if (!first->empty() &&
|
|
|
|
|
!second->empty() &&
|
|
|
|
|
!first->isSeparator(first_par_size - 1)) {
|
|
|
|
|
first->insertChar(first_par_size, ' ');
|
2002-03-26 11:05:30 +00:00
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
#warning probably broken
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (text_.selection.start.par() == 1) {
|
|
|
|
|
text_.selection.start.par(1);
|
|
|
|
|
text_.selection.start.pos(text_.selection.start.pos() + first_par_size);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (text_.selection.end.par() == 2) {
|
|
|
|
|
text_.selection.end.par(1);
|
|
|
|
|
text_.selection.end.pos(text_.selection.end.pos() + first_par_size);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-10-09 10:52:12 +00:00
|
|
|
|
mergeParagraph(bv->buffer()->params(), paragraphs, first);
|
2001-12-18 12:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-20 14:55:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (owner())
|
|
|
|
|
owner()->getDrawFont(font);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
}
|
2002-03-21 15:58:54 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
|
2002-03-21 15:58:54 +00:00
|
|
|
|
{
|
2003-04-28 16:22:32 +00:00
|
|
|
|
#warning FIXME Check if Changes stuff needs changing here. (Lgb)
|
|
|
|
|
// And it probably does. You have to take a look at this John. (Lgb)
|
|
|
|
|
#warning John, have a look here. (Lgb)
|
|
|
|
|
ParagraphList::iterator pit = plist.begin();
|
2003-05-24 12:13:30 +00:00
|
|
|
|
ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
|
2003-04-28 16:22:32 +00:00
|
|
|
|
++pit;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
mergeParagraph(buffer->params(), paragraphs, boost::prior(ins));
|
2003-04-28 16:22:32 +00:00
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pend = plist.end();
|
2003-08-04 15:59:01 +00:00
|
|
|
|
for (; pit != pend; ++pit)
|
2003-05-24 11:54:10 +00:00
|
|
|
|
paragraphs.push_back(*pit);
|
2002-03-21 15:58:54 +00:00
|
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-18 16:13:33 +00:00
|
|
|
|
void InsetText::addPreview(PreviewLoader & loader) const
|
2002-08-02 16:39:43 +00:00
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::const_iterator pend = paragraphs.end();
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
|
|
|
|
for (; pit != pend; ++pit) {
|
2003-05-29 01:13:18 +00:00
|
|
|
|
InsetList::const_iterator it = pit->insetlist.begin();
|
|
|
|
|
InsetList::const_iterator end = pit->insetlist.end();
|
2003-08-04 15:59:01 +00:00
|
|
|
|
for (; it != end; ++it)
|
2003-05-29 01:13:18 +00:00
|
|
|
|
it->inset->addPreview(loader);
|
2002-08-02 16:39:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|