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
|
|
|
|
*
|
2002-09-25 14:26:13 +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"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "BufferView.h"
|
2003-07-15 06:51:47 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "debug.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
|
#include "dimension.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2003-06-20 23:03:43 +00:00
|
|
|
|
#include "errorlist.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "intl.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2000-05-15 14:49:36 +00:00
|
|
|
|
#include "LColor.h"
|
2003-05-19 17:03:12 +00:00
|
|
|
|
#include "Lsstream.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
#include "lyxcursor.h"
|
|
|
|
|
#include "lyxfind.h"
|
|
|
|
|
#include "lyxlex.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
#include "lyxrow.h"
|
2000-06-16 15:13:25 +00:00
|
|
|
|
#include "lyxrc.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "trans_mgr.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
|
#include "undo_funcs.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2002-08-21 17:35:24 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include "sgml.h"
|
2003-02-26 17:04:10 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-03-12 19:16:42 +00:00
|
|
|
|
#include "insetnewline.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
2001-12-18 03:21:10 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2002-03-22 15:24:32 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
2002-08-13 14:40:38 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
#include "frontends/screen.h"
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
|
|
|
|
#include "support/textutils.h"
|
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
#include "support/lstrings.h"
|
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>
|
|
|
|
|
|
2001-12-18 03:21:10 +00:00
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ifstream;
|
2000-04-24 20:58:23 +00:00
|
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::min;
|
|
|
|
|
using std::max;
|
2001-07-03 11:02:12 +00:00
|
|
|
|
using std::make_pair;
|
2001-11-07 13:22:43 +00:00
|
|
|
|
using std::vector;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::pair;
|
2002-08-14 18:38:59 +00:00
|
|
|
|
using std::for_each;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
2003-07-18 16:13:33 +00:00
|
|
|
|
using namespace lyx::graphics;
|
2003-07-15 06:51:47 +00:00
|
|
|
|
using namespace bv_funcs;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
using lyx::textclass_type;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
2001-08-19 13:13:47 +00:00
|
|
|
|
// These functions should probably go into bufferview_funcs somehow (Jug)
|
2001-07-12 12:26:06 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
void InsetText::saveLyXTextState() const
|
2001-07-12 12:26:06 +00:00
|
|
|
|
{
|
2001-08-10 12:21:42 +00:00
|
|
|
|
// check if my paragraphs are still valid
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin();
|
|
|
|
|
ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end();
|
2002-08-14 18:38:59 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2003-07-10 14:44:13 +00:00
|
|
|
|
if (it == text_.cursor.par())
|
2001-08-10 12:21:42 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
if (it != end && text_.cursor.pos() <= it->size())
|
|
|
|
|
sstate = text_; // slicing intended
|
2003-06-27 11:53:41 +00:00
|
|
|
|
else
|
|
|
|
|
sstate.cursor.par(end);
|
2001-07-12 12:26:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-18 16:58:16 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
void InsetText::restoreLyXTextState() const
|
2001-07-12 12:26:06 +00:00
|
|
|
|
{
|
2003-06-27 11:53:41 +00:00
|
|
|
|
if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
|
2003-03-16 00:45:31 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.selection.set(true);
|
2003-06-30 23:56:22 +00:00
|
|
|
|
// at this point just to avoid the DEPM when setting the cursor
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.selection.mark(sstate.selection.mark());
|
2003-06-27 11:53:41 +00:00
|
|
|
|
if (sstate.selection.set()) {
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.setCursor(sstate.selection.start.par(),
|
2003-06-27 11:53:41 +00:00
|
|
|
|
sstate.selection.start.pos(),
|
|
|
|
|
true, sstate.selection.start.boundary());
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.selection.cursor = text_.cursor;
|
|
|
|
|
text_.setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
|
2003-06-27 11:53:41 +00:00
|
|
|
|
true, sstate.selection.end.boundary());
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.setSelection();
|
|
|
|
|
text_.setCursor(sstate.cursor.par(), sstate.cursor.pos());
|
2003-03-16 00:45:31 +00:00
|
|
|
|
} else {
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.setCursor(sstate.cursor.par(), sstate.cursor.pos(),
|
2003-06-27 11:53:41 +00:00
|
|
|
|
true, sstate.cursor.boundary());
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.selection.cursor = text_.cursor;
|
|
|
|
|
text_.selection.set(false);
|
2001-07-12 12:26:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetText::InsetText(BufferParams const & bp)
|
2003-07-17 07:43:55 +00:00
|
|
|
|
: UpdatableInset(), text_(0, this)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-05-24 11:54:10 +00:00
|
|
|
|
paragraphs.push_back(Paragraph());
|
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-05-26 09:13:55 +00:00
|
|
|
|
init(0);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetText::InsetText(InsetText const & in)
|
2003-07-17 07:43:55 +00:00
|
|
|
|
: UpdatableInset(in), text_(0, this)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-05-26 09:13:55 +00:00
|
|
|
|
init(&in);
|
2000-03-28 16:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
InsetText & InsetText::operator=(InsetText const & it)
|
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
init(&it);
|
2003-07-10 08:00:41 +00:00
|
|
|
|
return *this;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
void InsetText::init(InsetText const * ins)
|
2000-03-28 16:18:02 +00:00
|
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
|
if (ins) {
|
2003-07-18 07:47:07 +00:00
|
|
|
|
textwidth_ = ins->textwidth_;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.bv_owner = ins->text_.bv_owner;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
setParagraphData(ins->paragraphs);
|
2001-08-07 15:07:36 +00:00
|
|
|
|
autoBreakRows = ins->autoBreakRows;
|
|
|
|
|
drawFrame_ = ins->drawFrame_;
|
|
|
|
|
frame_color = ins->frame_color;
|
|
|
|
|
} else {
|
2003-07-18 07:47:07 +00:00
|
|
|
|
textwidth_ = 0; // unbounded
|
2001-08-07 15:07:36 +00:00
|
|
|
|
drawFrame_ = NEVER;
|
|
|
|
|
frame_color = LColor::insetframe;
|
|
|
|
|
autoBreakRows = false;
|
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
the_locking_inset = 0;
|
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(),
|
|
|
|
|
boost::bind(&Paragraph::setInsetOwner, _1, this));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
top_y = 0;
|
2002-03-29 12:24:50 +00:00
|
|
|
|
no_selection = true;
|
2001-08-10 09:39:15 +00:00
|
|
|
|
need_update = FULL;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
drawTextXOffset = 0;
|
|
|
|
|
drawTextYOffset = 0;
|
|
|
|
|
locked = false;
|
2003-05-27 17:29:03 +00:00
|
|
|
|
old_par = paragraphs.end();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
last_drawn_width = -1;
|
2003-06-27 11:53:41 +00:00
|
|
|
|
sstate.cursor.par(paragraphs.end());
|
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();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
it->markErased();
|
|
|
|
|
}
|
|
|
|
|
need_update = FULL;
|
|
|
|
|
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);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-29 12:58:59 +00:00
|
|
|
|
reinitLyXText();
|
2001-08-10 10:24:44 +00:00
|
|
|
|
need_update = INIT;
|
2000-07-14 14:57:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
InsetBase * InsetText::clone() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-05-26 09:13:55 +00:00
|
|
|
|
return new InsetText(*this);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
|
2001-06-28 10:25:20 +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) {
|
2002-08-26 09:31:09 +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
|
|
|
|
|
2001-06-28 10:25:20 +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-02-08 19:18:01 +00:00
|
|
|
|
if (buf->params.tracking_changes)
|
|
|
|
|
paragraphs.begin()->trackChanges();
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
// delete the initial paragraph
|
|
|
|
|
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-03-12 02:39:12 +00:00
|
|
|
|
if (token == "\\the_end") {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lex.printError("\\the_end read in inset! Error in document!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-12 02:39:12 +00:00
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
// FIXME: ugly.
|
2003-03-12 11:52:23 +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'");
|
|
|
|
|
}
|
2001-08-10 09:39:15 +00:00
|
|
|
|
need_update = FULL;
|
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-07-22 10:12:24 +00:00
|
|
|
|
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << "\n";
|
2003-07-18 07:47:07 +00:00
|
|
|
|
if (mi.base.textwidth)
|
|
|
|
|
textwidth_ = mi.base.textwidth;
|
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-27 13:55:03 +00:00
|
|
|
|
dim.wid = max(dim.wid, 10);
|
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-07-18 07:47:07 +00:00
|
|
|
|
return textwidth_;
|
2000-06-23 15:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetText::draw(PainterInfo & pi, int x, int baseline) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
|
if (nodraw())
|
|
|
|
|
return;
|
|
|
|
|
|
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-07-18 15:43:52 +00:00
|
|
|
|
top_x = x;
|
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-03-22 17:26:03 +00:00
|
|
|
|
clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
// no draw is necessary !!!
|
2003-05-30 06:48:24 +00:00
|
|
|
|
if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
|
2001-04-27 14:03:25 +00:00
|
|
|
|
top_baseline = baseline;
|
|
|
|
|
need_update = NONE;
|
|
|
|
|
return;
|
2000-08-09 13:51:59 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
top_baseline = baseline;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
top_y = baseline - dim_.asc;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
2003-05-27 13:55:03 +00:00
|
|
|
|
if (last_drawn_width != dim_.wid) {
|
2001-08-06 14:55:02 +00:00
|
|
|
|
need_update |= FULL;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
last_drawn_width = dim_.wid;
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) {
|
2003-07-18 15:43:52 +00:00
|
|
|
|
inset_x = cix(bv) - x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2001-04-06 12:47:50 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
RowList::iterator rowit = text_.rows().begin();
|
|
|
|
|
RowList::iterator end = text_.rows().end();
|
2003-03-29 23:11:20 +00:00
|
|
|
|
|
|
|
|
|
int y_offset = baseline - rowit->ascent_of_text();
|
2000-10-19 09:11:39 +00:00
|
|
|
|
int ph = pain.paperHeight();
|
|
|
|
|
int first = 0;
|
2001-11-29 13:43:12 +00:00
|
|
|
|
int y = y_offset;
|
2003-07-18 15:43:52 +00:00
|
|
|
|
while (rowit != end && y + rowit->height() <= 0) {
|
2003-03-29 23:11:20 +00:00
|
|
|
|
y += rowit->height();
|
|
|
|
|
first += rowit->height();
|
|
|
|
|
++rowit;
|
2000-06-21 15:07:57 +00:00
|
|
|
|
}
|
2002-04-18 09:47:08 +00:00
|
|
|
|
if (y_offset < 0) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.top_y(-y_offset);
|
2002-04-18 09:47:08 +00:00
|
|
|
|
first = y;
|
|
|
|
|
y_offset = 0;
|
|
|
|
|
} else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.top_y(first);
|
2002-04-18 09:47:08 +00:00
|
|
|
|
first = 0;
|
|
|
|
|
}
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
int yf = y_offset + first;
|
|
|
|
|
y = 0;
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
|
|
|
|
bv->hideCursor();
|
|
|
|
|
|
2003-07-14 17:50:00 +00:00
|
|
|
|
while (rowit != end && yf < ph) {
|
|
|
|
|
paintRows(*bv, text_, rowit,
|
|
|
|
|
y + y_offset + first, int(x), y + text_.top_y());
|
2003-03-29 23:11:20 +00:00
|
|
|
|
y += rowit->height();
|
|
|
|
|
yf += rowit->height();
|
|
|
|
|
++rowit;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2001-06-14 14:10:25 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearPaint();
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-07-18 15:43:52 +00:00
|
|
|
|
if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked)) {
|
2003-03-22 17:26:03 +00:00
|
|
|
|
drawFrame(pain, int(start_x));
|
2001-09-09 22:02:19 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
|
if (need_update != INIT) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
need_update = NONE;
|
2001-09-09 22:02:19 +00:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
|
static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
|
2003-03-22 17:26:03 +00:00
|
|
|
|
frame_x = x + ttoD2;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
frame_y = top_baseline - dim_.asc + ttoD2;
|
|
|
|
|
frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
|
|
|
|
|
frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
|
2003-03-17 01:34:36 +00:00
|
|
|
|
pain.rectangle(frame_x, frame_y, frame_w, frame_h,
|
|
|
|
|
frame_color);
|
2001-04-27 14:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-14 15:17:40 +00:00
|
|
|
|
void InsetText::setUpdateStatus(int what) const
|
2001-02-14 08:38:21 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
need_update |= what;
|
2003-07-15 11:08:02 +00:00
|
|
|
|
// we will to redraw us full if our LyXText wants it
|
|
|
|
|
if (text_.needRefresh())
|
2001-04-02 14:02:58 +00:00
|
|
|
|
need_update |= FULL;
|
2001-02-22 14:33:08 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
// this to not draw a selection when we redraw all of it!
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (need_update & CURSOR && !(need_update & SELECTION)) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set())
|
2001-08-01 15:42:53 +00:00
|
|
|
|
need_update = FULL;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2001-08-01 15:42:53 +00:00
|
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
|
}
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
|
|
2003-03-06 10:02:40 +00:00
|
|
|
|
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
|
2000-07-04 11:30:07 +00:00
|
|
|
|
{
|
2003-07-17 06:45:39 +00:00
|
|
|
|
if (!bv)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-04-28 16:22:32 +00:00
|
|
|
|
if (!autoBreakRows && paragraphs.size() > 1)
|
|
|
|
|
collapseParagraphs(bv);
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.partialRebreak();
|
2003-07-14 15:17:40 +00:00
|
|
|
|
setUpdateStatus(what);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool flag = mark_dirty ||
|
2003-07-15 11:08:02 +00:00
|
|
|
|
((need_update != CURSOR && need_update != NONE) ||
|
|
|
|
|
text_.needRefresh() || text_.selection.set());
|
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-04-12 15:59:03 +00:00
|
|
|
|
bv->fitCursor();
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
|
|
|
|
if (flag) {
|
2003-07-15 16:25:02 +00:00
|
|
|
|
text_.postPaint();
|
2003-03-19 14:45:22 +00:00
|
|
|
|
bv->updateInset(const_cast<InsetText *>(this));
|
2003-03-24 04:17:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
|
if (need_update == CURSOR)
|
|
|
|
|
need_update = NONE;
|
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-07-10 13:21:45 +00:00
|
|
|
|
if (old_par != cpar()) {
|
|
|
|
|
bv->owner()->setLayout(cpar()->layout()->name());
|
|
|
|
|
old_par = cpar();
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetText::insetUnlock(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
the_locking_inset->insetUnlock(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
the_locking_inset = 0;
|
2002-04-16 14:10:39 +00:00
|
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-03-29 12:24:50 +00:00
|
|
|
|
no_selection = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
locked = false;
|
2002-04-22 14:31:47 +00:00
|
|
|
|
int code = NONE;
|
2003-03-17 01:34:36 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
|
|
|
|
text_.clearSelection();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
code = FULL;
|
2001-06-29 15:17:05 +00:00
|
|
|
|
} else if (owner()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
bv->owner()->setLayout(owner()->getLyXText(bv)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
->cursor.par()->layout()->name());
|
2001-06-29 15:17:05 +00:00
|
|
|
|
} else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
|
2001-08-08 13:29:13 +00:00
|
|
|
|
// hack for deleteEmptyParMech
|
2003-06-18 17:43:49 +00:00
|
|
|
|
ParagraphList::iterator first_par = paragraphs.begin();
|
|
|
|
|
if (!first_par->empty()) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursor(first_par, 0);
|
2003-06-18 17:43:49 +00:00
|
|
|
|
} else if (paragraphs.size() > 1) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursor(boost::next(first_par), 0);
|
2002-02-22 13:25:03 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#if 0
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updateLocal(bv, code, false);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#else
|
2002-04-22 14:31:47 +00:00
|
|
|
|
if (code != NONE)
|
2003-07-14 15:17:40 +00:00
|
|
|
|
setUpdateStatus(code);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::lockInset(BufferView * bv)
|
|
|
|
|
{
|
|
|
|
|
locked = true;
|
|
|
|
|
the_locking_inset = 0;
|
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
|
inset_boundary = false;
|
2003-05-27 17:29:03 +00:00
|
|
|
|
inset_par = paragraphs.end();
|
|
|
|
|
old_par = paragraphs.end();
|
2003-07-17 06:45:39 +00:00
|
|
|
|
text_.setCursorIntern(paragraphs.begin(), 0);
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2002-04-16 14:10:39 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
// If the inset is empty set the language of the current font to the
|
|
|
|
|
// language to the surronding text (if different).
|
2003-06-18 17:43:49 +00:00
|
|
|
|
if (paragraphs.begin()->empty() && paragraphs.size() == 1 &&
|
2003-07-10 08:00:41 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
int code = CURSOR;
|
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
|
code = CURSOR|DRAW_FRAME;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
setUpdateStatus(code);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
|
2001-12-14 11:55:58 +00:00
|
|
|
|
void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
|
|
|
|
|
{
|
|
|
|
|
the_locking_inset = inset;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2003-07-10 13:21:45 +00:00
|
|
|
|
inset_pos = cpos();
|
|
|
|
|
inset_par = cpar();
|
|
|
|
|
inset_boundary = cboundary();
|
2003-07-17 06:45:39 +00:00
|
|
|
|
//updateLocal(bv, CURSOR, false);
|
2001-12-14 11:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2001-04-06 12:47:50 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
|
|
|
|
|
<< inset << "): ";
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!inset)
|
|
|
|
|
return false;
|
2001-12-14 11:55:58 +00:00
|
|
|
|
if (!the_locking_inset) {
|
2003-04-02 21:19:35 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
|
2001-12-14 11:55:58 +00:00
|
|
|
|
int const id = inset->id();
|
2003-04-02 21:19:35 +00:00
|
|
|
|
for (; pit != pend; ++pit) {
|
2003-07-17 06:45:39 +00:00
|
|
|
|
InsetList::iterator it = pit->insetlist.begin();
|
|
|
|
|
InsetList::iterator const end = pit->insetlist.end();
|
2001-12-14 11:55:58 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it->inset == inset) {
|
2003-07-17 06:45:39 +00:00
|
|
|
|
lyxerr << "InsetText::lockInsetInInset: 1 a\n";
|
|
|
|
|
text_.setCursorIntern(pit, it->pos);
|
|
|
|
|
lyxerr << "InsetText::lockInsetInInset: 1 b\n";
|
|
|
|
|
lyxerr << "bv: " << bv << " inset: " << inset << "\n";
|
2001-12-14 11:55:58 +00:00
|
|
|
|
lockInset(bv, inset);
|
2003-07-17 06:45:39 +00:00
|
|
|
|
lyxerr << "InsetText::lockInsetInInset: 1 c" << endl;
|
2001-12-14 11:55:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it->inset->getInsetFromID(id)) {
|
2003-07-17 06:45:39 +00:00
|
|
|
|
lyxerr << "InsetText::lockInsetInInset: 2\n";
|
|
|
|
|
text_.setCursorIntern(pit, it->pos);
|
2003-05-29 01:13:18 +00:00
|
|
|
|
it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
|
2001-12-14 11:55:58 +00:00
|
|
|
|
return the_locking_inset->lockInsetInInset(bv, inset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-17 06:45:39 +00:00
|
|
|
|
lyxerr << "InsetText::lockInsetInInset: 3\n";
|
2001-12-14 11:55:58 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (inset == cpar()->getInset(cpos())) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
2001-12-14 11:55:58 +00:00
|
|
|
|
lockInset(bv, inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return true;
|
2003-07-17 06:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (the_locking_inset && the_locking_inset == inset) {
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (cpar() == inset_par && cpos() == inset_pos) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
|
|
|
|
|
}
|
|
|
|
|
} else if (the_locking_inset) {
|
|
|
|
|
lyxerr[Debug::INSETS] << "MAYBE" << endl;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return the_locking_inset->lockInsetInInset(bv, inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "NOT OK" << endl;
|
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool lr)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!the_locking_inset)
|
|
|
|
|
return false;
|
|
|
|
|
if (the_locking_inset == inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
the_locking_inset->insetUnlock(bv);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
getLyXText(bv)->updateInset(inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
the_locking_inset = 0;
|
|
|
|
|
if (lr)
|
2002-07-13 14:56:42 +00:00
|
|
|
|
moveRightIntern(bv, true, false);
|
2003-05-27 17:29:03 +00:00
|
|
|
|
old_par = paragraphs.end(); // force layout setting
|
2001-04-27 14:03:25 +00:00
|
|
|
|
if (scroll())
|
|
|
|
|
scroll(bv, 0.0F);
|
|
|
|
|
else
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return the_locking_inset->unlockInsetInInset(bv, inset, lr);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-06-18 17:43:49 +00:00
|
|
|
|
if (!autoBreakRows && paragraphs.size() > 1)
|
2002-04-12 15:59:03 +00:00
|
|
|
|
collapseParagraphs(bv);
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2001-12-18 14:36:27 +00:00
|
|
|
|
if (inset == this)
|
|
|
|
|
return true;
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2002-03-08 11:42:30 +00:00
|
|
|
|
if (inset->owner() != this) {
|
2002-03-11 11:26:22 +00:00
|
|
|
|
int ustat = CURSOR_PAR;
|
|
|
|
|
bool found = false;
|
|
|
|
|
UpdatableInset * tl_inset = the_locking_inset;
|
|
|
|
|
if (tl_inset)
|
|
|
|
|
found = tl_inset->updateInsetInInset(bv, inset);
|
|
|
|
|
if (!found) {
|
|
|
|
|
tl_inset = static_cast<UpdatableInset *>(inset);
|
|
|
|
|
while(tl_inset->owner() && tl_inset->owner() != this)
|
|
|
|
|
tl_inset = static_cast<UpdatableInset *>(tl_inset->owner());
|
|
|
|
|
if (!tl_inset->owner())
|
|
|
|
|
return false;
|
|
|
|
|
found = tl_inset->updateInsetInInset(bv, inset);
|
|
|
|
|
ustat = FULL;
|
|
|
|
|
}
|
|
|
|
|
if (found)
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.updateInset(tl_inset);
|
2001-12-03 14:46:22 +00:00
|
|
|
|
if (found)
|
2003-07-14 15:17:40 +00:00
|
|
|
|
setUpdateStatus(ustat);
|
2001-12-03 14:46:22 +00:00
|
|
|
|
return found;
|
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
bool found = text_.updateInset(inset);
|
2001-12-03 14:46:22 +00:00
|
|
|
|
if (found) {
|
2003-07-14 15:17:40 +00:00
|
|
|
|
setUpdateStatus(CURSOR_PAR);
|
2002-03-08 11:42:30 +00:00
|
|
|
|
if (the_locking_inset &&
|
2003-07-10 13:21:45 +00:00
|
|
|
|
cpar() == inset_par && cpos() == inset_pos)
|
2002-03-08 11:42:30 +00:00
|
|
|
|
{
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2001-12-03 14:46:22 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2001-12-03 14:46:22 +00:00
|
|
|
|
return found;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetText::lfunMousePress(FuncRequest const & cmd)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2002-03-29 15:49:45 +00:00
|
|
|
|
no_selection = true;
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
2001-12-24 14:36:31 +00:00
|
|
|
|
// use this to check mouse motion for selection!
|
2002-08-19 10:11:13 +00:00
|
|
|
|
mouse_x = cmd.x;
|
|
|
|
|
mouse_y = cmd.y;
|
2001-12-24 14:36:31 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.x -= inset_x;
|
|
|
|
|
cmd1.y -= inset_y;
|
2002-04-16 14:10:39 +00:00
|
|
|
|
if (!locked)
|
|
|
|
|
lockInset(bv);
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
int tmp_x = cmd.x - drawTextXOffset;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
|
2000-07-04 11:30:07 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
if (the_locking_inset == inset) {
|
2002-08-19 10:11:13 +00:00
|
|
|
|
the_locking_inset->localDispatch(cmd1);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
2002-04-03 13:59:04 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
// otherwise only unlock the_locking_inset
|
2001-06-28 10:25:20 +00:00
|
|
|
|
the_locking_inset->insetUnlock(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
the_locking_inset = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2002-03-29 15:49:45 +00:00
|
|
|
|
if (!inset)
|
|
|
|
|
no_selection = false;
|
2002-03-29 12:24:50 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (bv->theLockingInset()) {
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isHighlyEditableInset(inset)) {
|
2002-04-03 13:59:04 +00:00
|
|
|
|
// We just have to lock the inset before calling a
|
2002-08-13 17:43:40 +00:00
|
|
|
|
// PressEvent on it!
|
2001-04-02 14:02:58 +00:00
|
|
|
|
UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
|
2002-04-03 13:59:04 +00:00
|
|
|
|
if (!bv->lockInset(uinset)) {
|
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
inset->localDispatch(cmd1);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2000-09-19 13:50:47 +00:00
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
if (!inset) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
bool paste_internally = false;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
|
2002-08-13 17:43:40 +00:00
|
|
|
|
localDispatch(FuncRequest(bv, LFUN_COPY));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
paste_internally = true;
|
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
int old_top_y = text_.top_y();
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
|
2003-05-27 13:55:03 +00:00
|
|
|
|
cmd.y + dim_.asc);
|
2001-12-17 14:53:31 +00:00
|
|
|
|
// set the selection cursor!
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.selection.cursor = text_.cursor;
|
|
|
|
|
text_.cursor.x_fix(text_.cursor.x());
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
|
|
|
|
text_.clearSelection();
|
2001-08-06 14:55:02 +00:00
|
|
|
|
updateLocal(bv, FULL, false);
|
|
|
|
|
} else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2002-01-08 15:32:11 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
bv->owner()->setLayout(cpar()->layout()->name());
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-03-29 12:24:50 +00:00
|
|
|
|
// we moved the view we cannot do mouse selection in this case!
|
2003-03-06 20:21:21 +00:00
|
|
|
|
if (getLyXText(bv)->top_y() != old_top_y)
|
2002-03-29 12:24:50 +00:00
|
|
|
|
no_selection = true;
|
2003-07-10 13:21:45 +00:00
|
|
|
|
old_par = cpar();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
// Insert primary selection with middle mouse
|
|
|
|
|
// if there is a local selection in the current buffer,
|
|
|
|
|
// insert this
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button2) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (paste_internally)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
localDispatch(FuncRequest(bv, LFUN_PASTE));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
else
|
2002-08-13 17:43:40 +00:00
|
|
|
|
localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2001-12-17 14:53:31 +00:00
|
|
|
|
} else {
|
2001-12-18 09:13:34 +00:00
|
|
|
|
getLyXText(bv)->clearSelection();
|
2000-09-19 13:50:47 +00:00
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.x -= inset_x;
|
|
|
|
|
cmd1.y -= inset_y;
|
|
|
|
|
|
2002-03-29 12:24:50 +00:00
|
|
|
|
no_selection = true;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (the_locking_inset)
|
|
|
|
|
return the_locking_inset->localDispatch(cmd1);
|
|
|
|
|
|
|
|
|
|
int tmp_x = cmd.x - drawTextXOffset;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
|
2001-12-17 13:33:22 +00:00
|
|
|
|
bool ret = false;
|
|
|
|
|
if (inset) {
|
2003-04-01 19:22:14 +00:00
|
|
|
|
// This code should probably be removed now. Simple insets
|
|
|
|
|
// (!highlyEditable) can actually take the localDispatch,
|
|
|
|
|
// and turn it into edit() if necessary. But we still
|
|
|
|
|
// need to deal properly with the whole relative vs.
|
|
|
|
|
// absolute mouse co-ords thing in a realiable, sensible way
|
|
|
|
|
#if 0
|
2002-08-21 07:30:57 +00:00
|
|
|
|
if (isHighlyEditableInset(inset))
|
2002-08-19 10:11:13 +00:00
|
|
|
|
ret = inset->localDispatch(cmd1);
|
|
|
|
|
else {
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
cmd1.x = cmd.x - inset_x;
|
|
|
|
|
cmd1.y = cmd.x - inset_y;
|
|
|
|
|
inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
|
2003-04-01 19:22:14 +00:00
|
|
|
|
ret = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2003-04-01 19:22:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
ret = inset->localDispatch(cmd1);
|
2001-12-17 13:33:22 +00:00
|
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2003-04-01 19:22:14 +00:00
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
|
return ret;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
void InsetText::lfunMouseMotion(FuncRequest const & cmd)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
FuncRequest cmd1 = cmd;
|
|
|
|
|
cmd1.x -= inset_x;
|
|
|
|
|
cmd1.y -= inset_y;
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset) {
|
2002-08-19 10:11:13 +00:00
|
|
|
|
the_locking_inset->localDispatch(cmd1);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-29 15:49:45 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
|
2002-03-29 15:49:45 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXCursor cur = text_.cursor;
|
|
|
|
|
text_.setCursorFromCoordinates
|
2003-05-27 13:55:03 +00:00
|
|
|
|
(cmd.x - drawTextXOffset, cmd.y + dim_.asc);
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor.x_fix(text_.cursor.x());
|
|
|
|
|
if (cur == text_.cursor)
|
2001-12-17 14:53:31 +00:00
|
|
|
|
return;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setSelection();
|
|
|
|
|
bool flag = (text_.toggle_cursor.par() != text_.toggle_end_cursor.par() ||
|
|
|
|
|
text_.toggle_cursor.pos() != text_.toggle_end_cursor.pos());
|
2001-12-18 12:35:53 +00:00
|
|
|
|
if (flag) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, SELECTION, false);
|
2001-12-04 16:10:19 +00:00
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
2003-07-14 16:34:23 +00:00
|
|
|
|
setViewCache(bv);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-07-21 11:01:29 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_INSET_EDIT: {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
UpdatableInset::localDispatch(cmd);
|
|
|
|
|
|
|
|
|
|
if (!bv->lockInset(this)) {
|
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locked = true;
|
|
|
|
|
the_locking_inset = 0;
|
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
|
inset_boundary = false;
|
2003-05-27 17:29:03 +00:00
|
|
|
|
inset_par = paragraphs.end();
|
|
|
|
|
old_par = paragraphs.end();
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmd.argument.size()) {
|
|
|
|
|
if (cmd.argument == "left")
|
2003-07-17 06:45:39 +00:00
|
|
|
|
text_.setCursorIntern(paragraphs.begin(), 0);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
else {
|
|
|
|
|
ParagraphList::iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
while (boost::next(it) != end)
|
|
|
|
|
++it;
|
|
|
|
|
// int const pos = (p->size() ? p->size()-1 : p->size());
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursor(it, it->size());
|
2003-05-16 07:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
|
|
|
|
|
// we put here -1 and not button as now the button in the
|
|
|
|
|
// edit call should not be needed we will fix this in 1.3.x
|
|
|
|
|
// cycle hopefully (Jug 20020509)
|
|
|
|
|
// FIXME: GUII I've changed this to none: probably WRONG
|
|
|
|
|
if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
|
2003-05-27 13:55:03 +00:00
|
|
|
|
cmd.y + dim_.asc);
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor.x_fix(text_.cursor.x());
|
2003-05-16 07:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2003-05-16 07:44:00 +00:00
|
|
|
|
finishUndo();
|
|
|
|
|
|
|
|
|
|
// If the inset is empty set the language of the current font to the
|
|
|
|
|
// language to the surronding text (if different).
|
|
|
|
|
if (paragraphs.begin()->empty() &&
|
2003-06-18 17:43:49 +00:00
|
|
|
|
paragraphs.size() == 1 &&
|
2003-07-10 08:00:41 +00:00
|
|
|
|
bv->getParentLanguage(this) != text_.current_font.language())
|
2003-05-16 07:44:00 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
|
|
|
|
setFont(bv, font, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int code = CURSOR;
|
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
|
code = CURSOR | DRAW_FRAME;
|
|
|
|
|
|
|
|
|
|
updateLocal(bv, code, false);
|
|
|
|
|
// Tell the paragraph dialog that we've entered an insettext.
|
|
|
|
|
bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-21 11:01:29 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
lfunMousePress(cmd);
|
|
|
|
|
return DISPATCHED;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-07-21 11:01:29 +00:00
|
|
|
|
case LFUN_MOUSE_MOTION:
|
|
|
|
|
lfunMouseMotion(cmd);
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2002-08-28 16:32:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 21:19:35 +00:00
|
|
|
|
bool was_empty = (paragraphs.begin()->empty() &&
|
2003-06-18 17:43:49 +00:00
|
|
|
|
paragraphs.size() == 1);
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
no_selection = false;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
RESULT result = UpdatableInset::localDispatch(cmd);
|
2002-08-07 08:11:41 +00:00
|
|
|
|
if (result != UNDISPATCHED)
|
2001-01-08 16:14:09 +00:00
|
|
|
|
return DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
|
result = DISPATCHED;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (cmd.action < 0 && cmd.argument.empty())
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return FINISHED;
|
|
|
|
|
|
|
|
|
|
if (the_locking_inset) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
result = the_locking_inset->localDispatch(cmd);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (result == DISPATCHED_NOUPDATE)
|
|
|
|
|
return result;
|
|
|
|
|
else if (result == DISPATCHED) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return result;
|
2001-10-01 11:55:08 +00:00
|
|
|
|
} else if (result >= FINISHED) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
switch (result) {
|
2001-10-01 11:55:08 +00:00
|
|
|
|
case FINISHED_RIGHT:
|
2001-04-02 14:02:58 +00:00
|
|
|
|
moveRightIntern(bv, false, false);
|
2001-10-01 11:55:08 +00:00
|
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2001-10-01 11:55:08 +00:00
|
|
|
|
case FINISHED_UP:
|
|
|
|
|
if ((result = moveUp(bv)) >= FINISHED) {
|
|
|
|
|
updateLocal(bv, CURSOR, false);
|
|
|
|
|
bv->unlockInset(this);
|
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2001-10-01 11:55:08 +00:00
|
|
|
|
case FINISHED_DOWN:
|
2003-01-08 09:27:15 +00:00
|
|
|
|
if ((result = moveDown(bv)) >= FINISHED) {
|
2001-10-01 11:55:08 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
|
|
|
|
bv->unlockInset(this);
|
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2001-10-01 11:55:08 +00:00
|
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
the_locking_inset = 0;
|
2002-03-29 15:49:45 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2003-04-07 16:57:38 +00:00
|
|
|
|
// make sure status gets reset immediately
|
|
|
|
|
bv->owner()->clearMessage();
|
2001-10-01 11:55:08 +00:00
|
|
|
|
return result;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
|
int updwhat = 0;
|
|
|
|
|
int updflag = false;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
|
|
|
|
// what type of update to do on a cursor movement
|
|
|
|
|
int cursor_update = CURSOR;
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set())
|
2003-03-24 04:17:45 +00:00
|
|
|
|
cursor_update = SELECTION;
|
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
switch (cmd.action) {
|
2002-08-26 07:52:59 +00:00
|
|
|
|
|
2000-03-09 16:04:28 +00:00
|
|
|
|
// Normal chars
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case LFUN_SELFINSERT:
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (bv->buffer()->isReadonly()) {
|
2000-06-16 15:13:25 +00:00
|
|
|
|
// setErrorMessage(N_("Document is read only"));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (!cmd.argument.empty()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
/* Automatically delete the currently selected
|
|
|
|
|
* text and replace it with what is being
|
|
|
|
|
* typed in now. Depends on lyxrc settings
|
|
|
|
|
* "auto_region_delete", which defaults to
|
|
|
|
|
* true (on). */
|
2002-10-14 14:59:50 +00:00
|
|
|
|
#if 0
|
|
|
|
|
// This should not be needed here and is also WRONG!
|
2003-07-10 08:00:41 +00:00
|
|
|
|
setUndo(bv, Undo::INSERT, text_.cursor.par());
|
2002-10-14 14:59:50 +00:00
|
|
|
|
#endif
|
2002-07-17 04:13:41 +00:00
|
|
|
|
bv->switchKeyMap();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (lyxrc.auto_region_delete) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
|
|
|
|
text_.cutSelection(false, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2003-05-16 07:44:00 +00:00
|
|
|
|
for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
|
2002-08-13 14:40:38 +00:00
|
|
|
|
bv->owner()->getIntl().getTransManager().
|
2003-07-10 08:00:41 +00:00
|
|
|
|
TranslateAndInsert(cmd.argument[i], &text_);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2001-01-02 16:06:14 +00:00
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.selection.cursor = text_.cursor;
|
2002-04-05 12:31:42 +00:00
|
|
|
|
updwhat = CURSOR | CURSOR_PAR;
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updflag = true;
|
2001-06-29 15:17:05 +00:00
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
|
|
|
|
// cursor movements that need special handling
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_RIGHT:
|
|
|
|
|
result = moveRight(bv);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
finishUndo();
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_LEFT:
|
2001-07-06 15:57:54 +00:00
|
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
result = moveLeft(bv);
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_DOWN:
|
2001-07-06 15:57:54 +00:00
|
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
result = moveDown(bv);
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_UP:
|
2001-07-06 15:57:54 +00:00
|
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
result = moveUp(bv);
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2002-10-11 10:45:28 +00:00
|
|
|
|
case LFUN_PRIOR:
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (crow() == text_.rows().begin())
|
2002-10-11 10:45:28 +00:00
|
|
|
|
result = FINISHED_UP;
|
|
|
|
|
else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursorPrevious();
|
|
|
|
|
text_.clearSelection();
|
2002-10-11 10:45:28 +00:00
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2002-10-11 10:45:28 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2002-10-11 10:45:28 +00:00
|
|
|
|
case LFUN_NEXT:
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (boost::next(crow()) == text_.rows().end())
|
2002-10-11 10:45:28 +00:00
|
|
|
|
result = FINISHED_DOWN;
|
|
|
|
|
else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursorNext();
|
|
|
|
|
text_.clearSelection();
|
2002-10-11 10:45:28 +00:00
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
updwhat = cursor_update;
|
2002-10-11 10:45:28 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2001-06-29 15:17:05 +00:00
|
|
|
|
case LFUN_BACKSPACE: {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set())
|
|
|
|
|
text_.cutSelection(true, false);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
else
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.backspace();
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
break;
|
2001-06-29 15:17:05 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
case LFUN_DELETE: {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
|
|
|
|
text_.cutSelection(true, false);
|
2001-06-29 15:17:05 +00:00
|
|
|
|
} else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.Delete();
|
2001-06-29 15:17:05 +00:00
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
break;
|
2001-06-29 15:17:05 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
case LFUN_CUT: {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cutSelection(true, true);
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
break;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_COPY:
|
2001-07-06 15:57:54 +00:00
|
|
|
|
finishUndo();
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.copySelection();
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_PASTESELECTION:
|
|
|
|
|
{
|
2001-05-08 17:08:44 +00:00
|
|
|
|
string const clip(bv->getClipboard());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (clip.empty())
|
|
|
|
|
break;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (cmd.argument == "paragraph") {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.insertStringAsParagraphs(clip);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
} else {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.insertStringAsLines(clip);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-05-15 23:49:08 +00:00
|
|
|
|
// bug 393
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2000-07-14 14:57:20 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
case LFUN_PASTE: {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!autoBreakRows) {
|
2001-07-03 15:39:17 +00:00
|
|
|
|
if (CutAndPaste::nrOfParagraphs() > 1) {
|
2003-03-24 04:17:45 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning FIXME horrendously bad UI
|
|
|
|
|
#endif
|
2003-03-31 01:15:44 +00:00
|
|
|
|
Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2003-07-15 06:51:47 +00:00
|
|
|
|
replaceSelection(bv->getLyXText());
|
2003-06-17 15:33:49 +00:00
|
|
|
|
size_t sel_index = 0;
|
|
|
|
|
string const & arg = cmd.argument;
|
|
|
|
|
if (isStrUnsignedInt(arg)) {
|
|
|
|
|
size_t const paste_arg = strToUnsignedInt(arg);
|
|
|
|
|
#warning FIXME Check if the arg is in the domain of available selections.
|
|
|
|
|
sel_index = paste_arg;
|
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.pasteSelection(sel_index);
|
2002-05-15 23:49:08 +00:00
|
|
|
|
// bug 393
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.clearSelection();
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
break;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_BREAKPARAGRAPH:
|
2001-07-12 12:26:06 +00:00
|
|
|
|
if (!autoBreakRows) {
|
|
|
|
|
result = DISPATCHED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-07-15 06:51:47 +00:00
|
|
|
|
replaceSelection(bv->getLyXText());
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.breakParagraph(paragraphs, 0);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
updwhat = CURSOR | FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
2001-07-12 12:26:06 +00:00
|
|
|
|
if (!autoBreakRows) {
|
|
|
|
|
result = DISPATCHED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-07-15 06:51:47 +00:00
|
|
|
|
replaceSelection(bv->getLyXText());
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.breakParagraph(paragraphs, 1);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
updwhat = CURSOR | FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_BREAKLINE: {
|
2001-07-12 12:26:06 +00:00
|
|
|
|
if (!autoBreakRows) {
|
|
|
|
|
result = DISPATCHED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-24 04:17:45 +00:00
|
|
|
|
|
2003-07-15 06:51:47 +00:00
|
|
|
|
replaceSelection(bv->getLyXText());
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.insertInset(new InsetNewline);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
updwhat = CURSOR | CURSOR_PAR;
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updflag = true;
|
2003-03-24 04:17:45 +00:00
|
|
|
|
break;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
|
// do not set layouts on non breakable textinsets
|
|
|
|
|
if (autoBreakRows) {
|
2003-07-10 13:21:45 +00:00
|
|
|
|
string cur_layout = cpar()->layout()->name();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
// Derive layout number from given argument (string)
|
2002-03-21 17:09:55 +00:00
|
|
|
|
// and current buffer's textclass (number). */
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
bv->buffer()->params.getLyXTextClass();
|
2003-05-16 07:44:00 +00:00
|
|
|
|
string layout = cmd.argument;
|
2002-07-21 21:21:06 +00:00
|
|
|
|
bool hasLayout = tclass.hasLayout(layout);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
|
|
|
|
// If the entry is obsolete, use the new one instead.
|
2002-03-02 16:39:54 +00:00
|
|
|
|
if (hasLayout) {
|
|
|
|
|
string const & obs =
|
2002-07-21 21:21:06 +00:00
|
|
|
|
tclass[layout]->obsoleted_by();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
if (!obs.empty())
|
2002-03-03 20:25:07 +00:00
|
|
|
|
layout = obs;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// see if we found the layout number:
|
2002-03-02 16:39:54 +00:00
|
|
|
|
if (!hasLayout) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
|
2002-08-13 17:43:40 +00:00
|
|
|
|
bv->owner()->dispatch(lf);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
if (cur_layout != layout) {
|
|
|
|
|
cur_layout = layout;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setLayout(layout);
|
2003-07-10 13:21:45 +00:00
|
|
|
|
bv->owner()->setLayout(cpar()->layout()->name());
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// reset the layout box
|
2003-07-10 13:21:45 +00:00
|
|
|
|
bv->owner()->setLayout(cpar()->layout()->name());
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_PARAGRAPH_SPACING:
|
|
|
|
|
// This one is absolutely not working. When fiddling with this
|
|
|
|
|
// it also seems to me that the paragraphs inside the insettext
|
|
|
|
|
// inherit bufferparams/paragraphparams in a strange way. (Lgb)
|
2003-03-24 04:17:45 +00:00
|
|
|
|
// FIXME: how old is this comment ? ...
|
2001-04-02 14:02:58 +00:00
|
|
|
|
{
|
2003-07-10 08:00:41 +00:00
|
|
|
|
ParagraphList::iterator pit = text_.cursor.par();
|
2003-04-09 09:15:20 +00:00
|
|
|
|
Spacing::Space cur_spacing = pit->params().spacing().getSpace();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
float cur_value = 1.0;
|
|
|
|
|
if (cur_spacing == Spacing::Other) {
|
2003-04-09 09:15:20 +00:00
|
|
|
|
cur_value = pit->params().spacing().getValue();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
istringstream istr(STRCONV(cmd.argument));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
string tmp;
|
|
|
|
|
istr >> tmp;
|
|
|
|
|
Spacing::Space new_spacing = cur_spacing;
|
|
|
|
|
float new_value = cur_value;
|
|
|
|
|
if (tmp.empty()) {
|
|
|
|
|
lyxerr << "Missing argument to `paragraph-spacing'"
|
|
|
|
|
<< endl;
|
|
|
|
|
} else if (tmp == "single") {
|
|
|
|
|
new_spacing = Spacing::Single;
|
|
|
|
|
} else if (tmp == "onehalf") {
|
|
|
|
|
new_spacing = Spacing::Onehalf;
|
|
|
|
|
} else if (tmp == "double") {
|
|
|
|
|
new_spacing = Spacing::Double;
|
|
|
|
|
} else if (tmp == "other") {
|
|
|
|
|
new_spacing = Spacing::Other;
|
|
|
|
|
float tmpval = 0.0;
|
|
|
|
|
istr >> tmpval;
|
|
|
|
|
lyxerr << "new_value = " << tmpval << endl;
|
|
|
|
|
if (tmpval != 0.0)
|
|
|
|
|
new_value = tmpval;
|
|
|
|
|
} else if (tmp == "default") {
|
|
|
|
|
new_spacing = Spacing::Default;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << _("Unknown spacing argument: ")
|
2003-05-16 07:44:00 +00:00
|
|
|
|
<< cmd.argument << endl;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
|
|
|
|
if (cur_spacing != new_spacing || cur_value != new_value) {
|
2003-04-09 09:15:20 +00:00
|
|
|
|
pit->params().spacing(Spacing(new_spacing, new_value));
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
2000-09-25 11:10:15 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-24 04:17:45 +00:00
|
|
|
|
// These need to do repaints but don't require
|
|
|
|
|
// special handling otherwise. A *lot* of the
|
|
|
|
|
// above could probably be done similarly ...
|
|
|
|
|
|
|
|
|
|
case LFUN_HOME:
|
|
|
|
|
case LFUN_END:
|
|
|
|
|
case LFUN_WORDLEFT:
|
|
|
|
|
case LFUN_WORDRIGHT:
|
|
|
|
|
// these two are really unhandled ...
|
|
|
|
|
case LFUN_ENDBUF:
|
|
|
|
|
case LFUN_BEGINNINGBUF:
|
|
|
|
|
updwhat = cursor_update;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (!bv->dispatch(cmd))
|
2003-03-24 04:17:45 +00:00
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
|
case LFUN_UPSEL:
|
|
|
|
|
case LFUN_DOWNSEL:
|
|
|
|
|
case LFUN_LEFTSEL:
|
|
|
|
|
case LFUN_HOMESEL:
|
|
|
|
|
case LFUN_ENDSEL:
|
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
|
case LFUN_WORDRIGHTSEL:
|
|
|
|
|
updwhat = SELECTION;
|
|
|
|
|
|
|
|
|
|
// fallthrough
|
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
default:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (!bv->dispatch(cmd))
|
2001-04-02 14:02:58 +00:00
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-02-11 09:58:20 +00:00
|
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
|
if (updwhat > 0)
|
|
|
|
|
updateLocal(bv, updwhat, updflag);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
/// If the action has deleted all text in the inset, we need to change the
|
2001-07-12 12:26:06 +00:00
|
|
|
|
// 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
|
|
|
|
|
2002-03-18 14:53:21 +00:00
|
|
|
|
if (result >= FINISHED)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
bv->unlockInset(this);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
|
|
|
|
|
if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
|
|
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return result;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-22 22:44:30 +00:00
|
|
|
|
int InsetText::latex(Buffer const * buf, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
|
LatexRunParams 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
unsigned int lines = 0;
|
2002-03-21 17:09:55 +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;
|
2002-08-14 18:38:59 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
|
2002-01-14 13:04:06 +00:00
|
|
|
|
lines += lyx::count(tmp.begin(), tmp.end(), '\n');
|
2001-04-02 14:02:58 +00:00
|
|
|
|
os << tmp;
|
|
|
|
|
}
|
|
|
|
|
return lines;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
|
2000-10-27 10:04:51 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
unsigned int lines = 0;
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
|
|
vector<string> environment_stack(10);
|
|
|
|
|
vector<string> environment_inner(10);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
|
int const command_depth = 0;
|
|
|
|
|
string item_name;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
|
|
|
|
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
|
|
|
|
|
ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
|
|
|
|
for (; pit != pend; ++pit) {
|
2001-11-07 13:22:43 +00:00
|
|
|
|
string sgmlparam;
|
|
|
|
|
int desc_on = 0; // description mode
|
|
|
|
|
|
2003-04-02 21:19:35 +00:00
|
|
|
|
LyXLayout_ptr const & style = pit->layout();
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
|
|
// environment tag closing
|
2003-04-02 21:19:35 +00:00
|
|
|
|
for (; depth > pit->params().depth(); --depth) {
|
2001-11-07 13:22:43 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
|
item_name = "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth == pit->params().depth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& environment_stack[depth] != style->latexname()
|
2001-11-07 13:22:43 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
|
item_name= "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
}
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Write opening SGML tags.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
2001-11-07 13:22:43 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
2003-07-07 08:37:02 +00:00
|
|
|
|
buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
|
2001-11-07 13:22:43 +00:00
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth < pit->params().depth()) {
|
|
|
|
|
depth = pit->params().depth();
|
2001-11-07 13:22:43 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (environment_stack[depth] != style->latexname()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1) {
|
2001-11-07 13:22:43 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth] = style->latexname();
|
2001-11-07 13:22:43 +00:00
|
|
|
|
environment_inner[depth] = "!-- --";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
|
item_name= "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latextype == LATEX_ENVIRONMENT) {
|
|
|
|
|
if (!style->latexparam().empty()) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-11-07 13:22:43 +00:00
|
|
|
|
os << "<![CDATA[";
|
|
|
|
|
else
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
desc_on = (style->labeltype == LABEL_MANUAL);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
item_name = desc_on ? "term" : "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-02 10:06:07 +00:00
|
|
|
|
buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
|
|
string end_tag;
|
|
|
|
|
// write closing SGML tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
2001-11-07 13:22:43 +00:00
|
|
|
|
case LATEX_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!style->latexparam().empty()) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-11-07 13:22:43 +00:00
|
|
|
|
os << "]]>";
|
|
|
|
|
else
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
|
|
|
|
if (desc_on == 1) break;
|
|
|
|
|
end_tag= "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
|
2001-11-07 13:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close open tags
|
|
|
|
|
for (int d = depth; d >= 0; --d) {
|
|
|
|
|
if (!environment_stack[depth].empty()) {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
|
item_name = "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
|
2001-11-07 13:22:43 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return lines;
|
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-05-03 18:05:53 +00:00
|
|
|
|
void InsetText::getCursor(BufferView & bv, int & x, int & y) const
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
the_locking_inset->getCursor(bv, x, y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
x = cx(&bv);
|
2003-07-14 15:17:40 +00:00
|
|
|
|
y = cy() + InsetText::y();
|
2003-05-03 18:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-07-17 15:39:12 +00:00
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
the_locking_inset->getCursorPos(bv, x, y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
x = cx(bv) - top_x - TEXT_TO_INSET_OFFSET;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
y = cy() - 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
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!the_locking_inset)
|
|
|
|
|
return 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return (inset_y + the_locking_inset->insetInInsetY());
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
void InsetText::fitInsetCursor(BufferView * bv) const
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
the_locking_inset->fitInsetCursor(bv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-07-18 15:43:52 +00:00
|
|
|
|
LyXFont const font = text_.getFont(bv->buffer(), cpar(), cpos());
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2002-05-24 14:34:32 +00:00
|
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
|
int const desc = font_metrics::maxDescent(font);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
2003-07-14 15:17:40 +00:00
|
|
|
|
if (bv->fitLockedInsetCursor(cx(bv), cy(), asc, desc))
|
2002-03-29 15:49:45 +00:00
|
|
|
|
need_update |= FULL;
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
Inset::RESULT
|
2000-09-27 15:23:24 +00:00
|
|
|
|
InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
|
2001-01-08 16:14:09 +00:00
|
|
|
|
{
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
|
2002-07-13 14:56:42 +00:00
|
|
|
|
return moveLeftIntern(bv, false, activate_inset, selecting);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
else
|
2002-04-17 08:34:59 +00:00
|
|
|
|
return moveRightIntern(bv, true, activate_inset, selecting);
|
2001-01-08 16:14:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
Inset::RESULT
|
2001-01-08 16:14:09 +00:00
|
|
|
|
InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
|
|
|
|
|
{
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
|
2002-07-13 14:56:42 +00:00
|
|
|
|
return moveRightIntern(bv, true, activate_inset, selecting);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
else
|
2002-04-17 08:34:59 +00:00
|
|
|
|
return moveLeftIntern(bv, false, activate_inset, selecting);
|
2001-01-08 16:14:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
Inset::RESULT
|
2002-04-17 08:34:59 +00:00
|
|
|
|
InsetText::moveRightIntern(BufferView * bv, bool front,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool activate_inset, bool selecting)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-07-10 13:21:45 +00:00
|
|
|
|
ParagraphList::iterator c_par = cpar();
|
2003-04-28 16:22:32 +00:00
|
|
|
|
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
|
2001-08-16 08:52:30 +00:00
|
|
|
|
return FINISHED_RIGHT;
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (activate_inset && checkAndActivateInset(bv, front))
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return DISPATCHED;
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.cursorRight(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!selecting)
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.clearSelection();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 10:11:13 +00:00
|
|
|
|
Inset::RESULT
|
2002-04-17 08:34:59 +00:00
|
|
|
|
InsetText::moveLeftIntern(BufferView * bv, bool front,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool activate_inset, bool selecting)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (cpar() == paragraphs.begin() && cpos() <= 0)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return FINISHED;
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.cursorLeft(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!selecting)
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.clearSelection();
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (activate_inset && checkAndActivateInset(bv, front))
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return DISPATCHED;
|
|
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-11 10:45:28 +00:00
|
|
|
|
Inset::RESULT InsetText::moveUp(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (crow() == text_.rows().begin())
|
2001-08-16 08:52:30 +00:00
|
|
|
|
return FINISHED_UP;
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.cursorUp(bv);
|
|
|
|
|
text_.clearSelection();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-11 10:45:28 +00:00
|
|
|
|
Inset::RESULT InsetText::moveDown(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2003-07-14 16:34:23 +00:00
|
|
|
|
if (boost::next(crow()) == text_.rows().end())
|
2001-08-16 08:52:30 +00:00
|
|
|
|
return FINISHED_DOWN;
|
2003-07-14 16:34:23 +00:00
|
|
|
|
text_.cursorDown(bv);
|
|
|
|
|
text_.clearSelection();
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetText::insertInset(BufferView * bv, Inset * inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset) {
|
2001-07-19 08:52:59 +00:00
|
|
|
|
if (the_locking_inset->insetAllowed(inset))
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return the_locking_inset->insertInset(bv, inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-01-04 16:03:53 +00:00
|
|
|
|
inset->setOwner(this);
|
2003-07-18 15:43:52 +00:00
|
|
|
|
text_.insertInset(inset);
|
2001-08-02 14:55:06 +00:00
|
|
|
|
bv->fitCursor();
|
2001-12-18 12:35:53 +00:00
|
|
|
|
updateLocal(bv, CURSOR_PAR|CURSOR, true);
|
2001-07-12 12:26:06 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
bool InsetText::insetAllowed(Inset::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;
|
2001-07-12 12:26:06 +00:00
|
|
|
|
if (the_locking_inset)
|
2001-12-05 15:34:41 +00:00
|
|
|
|
ret = the_locking_inset->insetAllowed(code);
|
|
|
|
|
else if (owner())
|
|
|
|
|
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
|
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
|
UpdatableInset * InsetText::getLockingInset() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2001-07-12 12:26:06 +00:00
|
|
|
|
return the_locking_inset ? the_locking_inset->getLockingInset() :
|
|
|
|
|
const_cast<InsetText *>(this);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
|
2000-05-15 14:49:36 +00:00
|
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if (c == lyxCode())
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return this;
|
|
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return the_locking_inset->getFirstLockingInsetOfType(c);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetText::showInsetDialog(BufferView * bv) const
|
2001-03-26 14:47:34 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return the_locking_inset->showInsetDialog(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return false;
|
2001-03-26 14:47:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
void InsetText::getLabelList(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)
|
|
|
|
|
beg->inset->getLabelList(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
|
|
|
|
{
|
2001-06-01 15:10:26 +00:00
|
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
the_locking_inset->setFont(bv, font, toggleall, selectall);
|
2001-06-01 15:10:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
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-07-10 08:00:41 +00:00
|
|
|
|
setUndo(bv, Undo::EDIT, 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
|
|
|
|
|
2001-08-02 14:55:06 +00:00
|
|
|
|
bv->fitCursor();
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
bool flag = (selectall || text_.selection.set());
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
|
if (flag)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, FULL, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
else
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR_PAR, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-17 08:34:59 +00:00
|
|
|
|
bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
|
2000-03-08 13:52:57 +00:00
|
|
|
|
{
|
2003-07-10 13:21:45 +00:00
|
|
|
|
if (cpar()->isInset(cpos())) {
|
2001-04-02 14:02:58 +00:00
|
|
|
|
Inset * inset =
|
2003-07-10 13:21:45 +00:00
|
|
|
|
static_cast<UpdatableInset*>(cpar()->getInset(cpos()));
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (!isHighlyEditableInset(inset))
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return false;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
|
|
|
|
|
inset->localDispatch(cmd);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!the_locking_inset)
|
|
|
|
|
return false;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return true;
|
2000-07-04 11:30:07 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return false;
|
2000-03-27 15:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
|
bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
|
2002-05-26 17:33:14 +00:00
|
|
|
|
mouse_button::state button)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
x -= drawTextXOffset;
|
|
|
|
|
int dummyx = x;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int dummyy = y + dim_.asc;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
Inset * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
|
2002-05-14 09:10:14 +00:00
|
|
|
|
// we only do the edit() call if the inset was hit by the mouse
|
|
|
|
|
// or if it is a highly editable inset. So we should call this
|
|
|
|
|
// function from our own edit with button < 0.
|
2002-05-26 17:33:14 +00:00
|
|
|
|
// FIXME: GUII jbl. I've changed this to ::none for now which is probably
|
|
|
|
|
// WRONG
|
|
|
|
|
if (button == mouse_button::none && !isHighlyEditableInset(inset))
|
2002-05-14 09:10:14 +00:00
|
|
|
|
return false;
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (inset) {
|
|
|
|
|
if (x < 0)
|
2003-05-27 13:55:03 +00:00
|
|
|
|
x = dim_.wid;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (y < 0)
|
2003-05-27 13:55:03 +00:00
|
|
|
|
y = dim_.des;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2003-05-16 07:44:00 +00:00
|
|
|
|
FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
|
|
|
|
|
inset->localDispatch(cmd);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (!the_locking_inset)
|
|
|
|
|
return false;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
void InsetText::setParagraphData(ParagraphList const & plist)
|
2000-05-04 08:14:34 +00:00
|
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
|
// we have to unlock any locked inset otherwise we're in troubles
|
|
|
|
|
the_locking_inset = 0;
|
2001-04-06 12:47:50 +00:00
|
|
|
|
|
2003-05-24 11:54:10 +00:00
|
|
|
|
// But it it makes no difference that is a lot better.
|
|
|
|
|
#warning FIXME.
|
2003-05-26 09:13:55 +00:00
|
|
|
|
// See if this can be simplified when std::list is in effect.
|
|
|
|
|
paragraphs.clear();
|
2003-05-24 11:54:10 +00:00
|
|
|
|
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator it = plist.begin();
|
|
|
|
|
ParagraphList::const_iterator end = plist.end();
|
2003-05-26 09:13:55 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
paragraphs.push_back(*it);
|
|
|
|
|
Paragraph & tmp = paragraphs.back();
|
|
|
|
|
tmp.setInsetOwner(this);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2003-04-28 16:22:32 +00:00
|
|
|
|
|
2001-11-29 12:58:59 +00:00
|
|
|
|
reinitLyXText();
|
2001-08-10 10:24:44 +00:00
|
|
|
|
need_update = INIT;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void InsetText::markNew(bool track_changes)
|
|
|
|
|
{
|
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
|
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);
|
2002-03-26 11:05:30 +00:00
|
|
|
|
reinitLyXText();
|
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
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (flag != autoBreakRows) {
|
|
|
|
|
autoBreakRows = flag;
|
|
|
|
|
if (!flag)
|
|
|
|
|
removeNewlines();
|
2001-08-10 10:24:44 +00:00
|
|
|
|
need_update = INIT;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
|
2000-05-15 14:49:36 +00:00
|
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
|
if (how != drawFrame_) {
|
|
|
|
|
drawFrame_ = how;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (bv)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, DRAW_FRAME, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetText::setFrameColor(BufferView * bv, LColor::color col)
|
2000-05-15 14:49:36 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (frame_color != col) {
|
|
|
|
|
frame_color = col;
|
|
|
|
|
if (bv)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
updateLocal(bv, DRAW_FRAME, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-06-19 15:33:58 +00:00
|
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int InsetText::cx(BufferView * bv) const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2003-07-10 08:00:41 +00:00
|
|
|
|
int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
|
2000-12-05 14:15:44 +00:00
|
|
|
|
if (the_locking_inset) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXFont font = text_.getFont(bv->buffer(), text_.cursor.par(),
|
|
|
|
|
text_.cursor.pos());
|
2000-12-05 14:15:44 +00:00
|
|
|
|
if (font.isVisibleRightToLeft())
|
2003-07-18 07:47:07 +00:00
|
|
|
|
x -= the_locking_inset->width();
|
2000-12-05 14:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
return x;
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2002-04-12 15:59:03 +00:00
|
|
|
|
int InsetText::cix(BufferView * bv) const
|
|
|
|
|
{
|
2003-07-10 08:00:41 +00:00
|
|
|
|
int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
if (the_locking_inset) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXFont font = text_.getFont(bv->buffer(), text_.cursor.par(),
|
|
|
|
|
text_.cursor.pos());
|
2002-04-12 15:59:03 +00:00
|
|
|
|
if (font.isVisibleRightToLeft())
|
2003-07-18 07:47:07 +00:00
|
|
|
|
x -= the_locking_inset->width();
|
2002-04-12 15:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-14 15:17:40 +00:00
|
|
|
|
int InsetText::cy() const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2003-07-14 13:49:13 +00:00
|
|
|
|
return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
|
2000-06-21 15:07:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-07-14 15:17:40 +00:00
|
|
|
|
int InsetText::ciy() const
|
2002-04-11 15:08:22 +00:00
|
|
|
|
{
|
2003-07-14 13:49:13 +00:00
|
|
|
|
return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
|
2002-04-11 15:08:22 +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-07-10 11:31:54 +00:00
|
|
|
|
return text_.cursor.par();
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
bool InsetText::cboundary() const
|
2000-12-17 06:09:35 +00:00
|
|
|
|
{
|
2003-07-10 11:31:54 +00:00
|
|
|
|
return text_.cursor.boundary();
|
2000-12-17 06:09:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-07-10 13:21:45 +00:00
|
|
|
|
RowList::iterator InsetText::crow() const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2003-07-10 11:31:54 +00:00
|
|
|
|
return text_.cursorRow();
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXText * InsetText::getLyXText(BufferView const * bv,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool const recursive) const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2003-07-10 10:06:20 +00:00
|
|
|
|
setViewCache(bv);
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (recursive && the_locking_inset)
|
|
|
|
|
return the_locking_inset->getLyXText(bv, true);
|
|
|
|
|
return &text_;
|
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
|
|
|
|
|
{
|
|
|
|
|
if (bv)
|
|
|
|
|
text_.bv_owner = const_cast<BufferView *>(bv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
|
void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
|
2000-06-16 15:13:25 +00:00
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
|
if (recursive) {
|
|
|
|
|
/// then remove all LyXText in text-insets
|
2003-05-27 22:41:04 +00:00
|
|
|
|
for_each(const_cast<ParagraphList&>(paragraphs).begin(),
|
|
|
|
|
const_cast<ParagraphList&>(paragraphs).end(),
|
2002-08-14 18:38:59 +00:00
|
|
|
|
boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-07-14 14:57:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2001-06-07 14:51:20 +00:00
|
|
|
|
void InsetText::resizeLyXText(BufferView * bv, bool force) const
|
2000-07-14 14:57:20 +00:00
|
|
|
|
{
|
2003-06-18 17:43:49 +00:00
|
|
|
|
if (paragraphs.size() == 1 && paragraphs.begin()->empty()) {
|
|
|
|
|
// no data, resize not neccessary!
|
2001-12-19 16:13:21 +00:00
|
|
|
|
// we have to do this as a fixed width may have changed!
|
2003-07-10 14:44:13 +00:00
|
|
|
|
saveLyXTextState();
|
2003-07-15 08:26:17 +00:00
|
|
|
|
text_.init(bv);
|
2003-07-10 14:44:13 +00:00
|
|
|
|
restoreLyXTextState();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
return;
|
2001-12-19 16:13:21 +00:00
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (!bv)
|
2001-04-02 14:02:58 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
Assert(bv);
|
2003-07-14 16:34:23 +00:00
|
|
|
|
setViewCache(bv);
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
saveLyXTextState();
|
2002-08-14 18:38:59 +00:00
|
|
|
|
|
2003-05-27 22:41:04 +00:00
|
|
|
|
for_each(const_cast<ParagraphList&>(paragraphs).begin(),
|
|
|
|
|
const_cast<ParagraphList&>(paragraphs).end(),
|
2002-08-14 18:38:59 +00:00
|
|
|
|
boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
|
|
|
|
|
|
2003-07-15 08:26:17 +00:00
|
|
|
|
text_.init(bv);
|
2003-07-10 14:44:13 +00:00
|
|
|
|
restoreLyXTextState();
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-22 15:12:04 +00:00
|
|
|
|
// seems to be unneeded
|
|
|
|
|
#if 1
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (the_locking_inset) {
|
2002-04-12 15:59:03 +00:00
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.top_y(bv->screen().topCursorVisible(&text_));
|
2001-08-07 15:07:36 +00:00
|
|
|
|
if (!owner()) {
|
2003-03-06 10:02:40 +00:00
|
|
|
|
const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
// this will scroll the screen such that the cursor becomes visible
|
2001-08-07 15:07:36 +00:00
|
|
|
|
bv->updateScrollbar();
|
|
|
|
|
} else {
|
2001-08-02 14:55:06 +00:00
|
|
|
|
need_update |= FULL;
|
2001-08-07 15:07:36 +00:00
|
|
|
|
}
|
2003-07-22 15:12:04 +00:00
|
|
|
|
#endif
|
2000-06-16 15:13:25 +00:00
|
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-10 12:21:42 +00:00
|
|
|
|
void InsetText::reinitLyXText() const
|
2001-07-31 09:53:40 +00:00
|
|
|
|
{
|
2003-07-10 08:00:41 +00:00
|
|
|
|
BufferView * bv = text_.bv_owner;
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (!bv)
|
|
|
|
|
return;
|
2001-07-31 09:53:40 +00:00
|
|
|
|
|
2003-07-10 14:44:13 +00:00
|
|
|
|
saveLyXTextState();
|
2002-08-14 18:38:59 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
for_each(const_cast<ParagraphList&>(paragraphs).begin(),
|
|
|
|
|
const_cast<ParagraphList&>(paragraphs).end(),
|
|
|
|
|
boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
|
2002-08-14 18:38:59 +00:00
|
|
|
|
|
2003-07-15 08:26:17 +00:00
|
|
|
|
text_.init(bv);
|
2003-07-10 14:44:13 +00:00
|
|
|
|
restoreLyXTextState();
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2003-07-14 15:17:40 +00:00
|
|
|
|
inset_y = ciy() + drawTextYOffset;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
}
|
2003-07-10 14:44:13 +00:00
|
|
|
|
text_.top_y(bv->screen().topCursorVisible(&text_));
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (!owner()) {
|
|
|
|
|
const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
|
|
|
|
|
// this will scroll the screen such that the cursor becomes visible
|
|
|
|
|
bv->updateScrollbar();
|
|
|
|
|
} else {
|
|
|
|
|
need_update = FULL;
|
2001-07-31 09:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
|
void InsetText::removeNewlines()
|
|
|
|
|
{
|
2001-12-03 13:17:04 +00:00
|
|
|
|
bool changed = false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-08-14 18:38:59 +00:00
|
|
|
|
ParagraphList::iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
for (int i = 0; i < it->size(); ++i) {
|
2003-03-12 19:16:42 +00:00
|
|
|
|
if (it->isNewline(i)) {
|
2001-12-03 13:17:04 +00:00
|
|
|
|
changed = true;
|
2002-08-14 18:38:59 +00:00
|
|
|
|
it->erase(i);
|
2001-12-03 13:17:04 +00:00
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
|
}
|
2001-12-03 13:17:04 +00:00
|
|
|
|
if (changed)
|
|
|
|
|
reinitLyXText();
|
2000-08-07 15:21:05 +00:00
|
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
|
bool InsetText::nodraw() const
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset)
|
|
|
|
|
return the_locking_inset->nodraw();
|
|
|
|
|
return UpdatableInset::nodraw();
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
|
int InsetText::scroll(bool recursive) const
|
|
|
|
|
{
|
|
|
|
|
int sx = UpdatableInset::scroll(false);
|
|
|
|
|
|
|
|
|
|
if (recursive && the_locking_inset)
|
|
|
|
|
sx += the_locking_inset->scroll(recursive);
|
|
|
|
|
|
|
|
|
|
return sx;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
|
void InsetText::clearSelection(BufferView * bv)
|
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
getLyXText(bv)->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;
|
|
|
|
|
}
|
|
|
|
|
if ((ty + h) > pain.paperHeight())
|
|
|
|
|
h = pain.paperHeight();
|
|
|
|
|
if ((top_x + drawTextXOffset + w) > pain.paperWidth())
|
|
|
|
|
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
|
|
|
|
need_update = FULL;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
LyXCursor const & InsetText::cursor(BufferView * bv) const
|
|
|
|
|
{
|
2003-02-18 16:58:16 +00:00
|
|
|
|
if (the_locking_inset)
|
|
|
|
|
return the_locking_inset->cursor(bv);
|
|
|
|
|
return getLyXText(bv)->cursor;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Inset * InsetText::getInsetFromID(int id_arg) const
|
|
|
|
|
{
|
|
|
|
|
if (id_arg == id())
|
|
|
|
|
return const_cast<InsetText *>(this);
|
|
|
|
|
|
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 it = pit->insetlist.begin();
|
|
|
|
|
InsetList::const_iterator end = pit->insetlist.end();
|
2002-08-14 18:38:59 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it->inset->id() == id_arg)
|
|
|
|
|
return it->inset;
|
|
|
|
|
Inset * in = it->inset->getInsetFromID(id_arg);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
if (in)
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-17 15:39:12 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
WordLangTuple const
|
2003-07-10 13:21:45 +00:00
|
|
|
|
InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
|
2001-07-17 15:39:12 +00:00
|
|
|
|
{
|
2002-08-06 22:38:44 +00:00
|
|
|
|
WordLangTuple word;
|
2001-07-17 15:39:12 +00:00
|
|
|
|
if (the_locking_inset) {
|
2002-08-06 22:38:44 +00:00
|
|
|
|
word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
|
|
|
|
|
if (!word.word().empty()) {
|
2003-07-14 15:17:40 +00:00
|
|
|
|
value += cy();
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return word;
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
2002-08-06 22:38:44 +00:00
|
|
|
|
// we have to go on checking so move cursor to the next char
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor.pos(text_.cursor.pos() + 1);
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
word = text_.selectNextWordToSpellcheck(value);
|
2002-08-06 22:38:44 +00:00
|
|
|
|
if (word.word().empty())
|
2001-07-17 15:39:12 +00:00
|
|
|
|
bv->unlockInset(const_cast<InsetText *>(this));
|
|
|
|
|
else
|
2003-07-14 15:17:40 +00:00
|
|
|
|
value = cy();
|
2002-08-06 22:38:44 +00:00
|
|
|
|
return word;
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::selectSelectedWord(BufferView * bv)
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
the_locking_inset->selectSelectedWord(bv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
getLyXText(bv)->selectSelectedWord();
|
2001-07-17 15:39:12 +00:00
|
|
|
|
updateLocal(bv, SELECTION, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
the_locking_inset->toggleSelection(bv, kill_selection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x = top_x + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
RowList::iterator rowit = text_.rows().begin();
|
|
|
|
|
RowList::iterator end = text_.rows().end();
|
2003-03-29 23:11:20 +00:00
|
|
|
|
int y_offset = top_baseline - rowit->ascent_of_text();
|
2001-11-29 13:43:12 +00:00
|
|
|
|
int y = y_offset;
|
2003-03-29 23:11:20 +00:00
|
|
|
|
while ((rowit != end) && ((y + rowit->height()) <= 0)) {
|
|
|
|
|
y += rowit->height();
|
|
|
|
|
++rowit;
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (y_offset < 0)
|
|
|
|
|
y_offset = y;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (need_update & SELECTION)
|
|
|
|
|
need_update = NONE;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
bv->screen().toggleSelection(&text_, bv, kill_selection, y_offset, x);
|
2001-07-17 15:39:12 +00:00
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
|
|
|
|
|
{
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
|
if (the_locking_inset->nextChange(bv, length))
|
|
|
|
|
return true;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursorRight(true);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
lyxfind::SearchResult result =
|
2003-07-10 08:00:41 +00:00
|
|
|
|
lyxfind::findNextChange(bv, &text_, length);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
if (result == lyxfind::SR_FOUND) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXCursor cur = text_.cursor;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
|
|
|
|
if (bv->lockInset(this))
|
|
|
|
|
locked = true;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor = cur;
|
|
|
|
|
text_.setSelectionRange(length);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
updateLocal(bv, SELECTION, false);
|
|
|
|
|
}
|
|
|
|
|
return result != lyxfind::SR_NOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 23:19:01 +00:00
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
bool InsetText::searchForward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool cs, bool mw)
|
2001-07-20 14:18:48 +00:00
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (the_locking_inset) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (the_locking_inset->searchForward(bv, str, cs, mw))
|
|
|
|
|
return true;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursorRight(true);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
lyxfind::SearchResult result =
|
2003-07-10 08:00:41 +00:00
|
|
|
|
lyxfind::LyXFind(bv, &text_, str, true, cs, mw);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
if (result == lyxfind::SR_FOUND) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXCursor cur = text_.cursor;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
|
|
|
|
if (bv->lockInset(this))
|
|
|
|
|
locked = true;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor = cur;
|
|
|
|
|
text_.setSelectionRange(str.length());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
updateLocal(bv, SELECTION, false);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return (result != lyxfind::SR_NOT_FOUND);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InsetText::searchBackward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bool cs, bool mw)
|
2001-07-20 14:18:48 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (the_locking_inset) {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (the_locking_inset->searchBackward(bv, str, cs, mw))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (!locked) {
|
2003-04-02 21:19:35 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
|
|
|
|
|
while (boost::next(pit) != pend)
|
|
|
|
|
++pit;
|
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.setCursor(pit, pit->size());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
lyxfind::SearchResult result =
|
2003-07-10 08:00:41 +00:00
|
|
|
|
lyxfind::LyXFind(bv, &text_, str, false, cs, mw);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
if (result == lyxfind::SR_FOUND) {
|
2003-07-10 08:00:41 +00:00
|
|
|
|
LyXCursor cur = text_.cursor;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
|
|
|
|
if (bv->lockInset(this))
|
|
|
|
|
locked = true;
|
2003-07-10 08:00:41 +00:00
|
|
|
|
text_.cursor = cur;
|
|
|
|
|
text_.setSelectionRange(str.length());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
updateLocal(bv, SELECTION, false);
|
|
|
|
|
}
|
|
|
|
|
return (result != lyxfind::SR_NOT_FOUND);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
2001-10-22 09:45:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::checkInsertChar(LyXFont & font)
|
|
|
|
|
{
|
|
|
|
|
if (owner())
|
|
|
|
|
return owner()->checkInsertChar(font);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
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) {
|
|
|
|
|
ParagraphList::iterator first_par = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator next_par = boost::next(first_par);
|
|
|
|
|
size_t const first_par_size = first_par->size();
|
|
|
|
|
|
|
|
|
|
if (!first_par->empty() &&
|
|
|
|
|
!next_par->empty() &&
|
|
|
|
|
!first_par->isSeparator(first_par_size - 1)) {
|
|
|
|
|
first_par->insertChar(first_par_size, ' ');
|
2002-03-26 11:05:30 +00:00
|
|
|
|
}
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.set()) {
|
|
|
|
|
if (text_.selection.start.par() == next_par) {
|
|
|
|
|
text_.selection.start.par(first_par);
|
|
|
|
|
text_.selection.start.pos(
|
|
|
|
|
text_.selection.start.pos() + first_par_size);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
}
|
2003-07-10 08:00:41 +00:00
|
|
|
|
if (text_.selection.end.par() == next_par) {
|
|
|
|
|
text_.selection.end.par(first_par);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
mergeParagraph(bv->buffer()->params, paragraphs, first_par);
|
2001-12-18 12:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
reinitLyXText();
|
|
|
|
|
}
|
2002-02-20 14:55:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::getDrawFont(LyXFont & font) const
|
|
|
|
|
{
|
|
|
|
|
if (!owner())
|
|
|
|
|
return;
|
|
|
|
|
owner()->getDrawFont(font);
|
|
|
|
|
}
|
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;
|
|
|
|
|
mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator pend = plist.end();
|
|
|
|
|
for (; pit != pend; ++pit) {
|
2003-05-24 11:54:10 +00:00
|
|
|
|
paragraphs.push_back(*pit);
|
2003-04-28 16:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 15:58:54 +00:00
|
|
|
|
reinitLyXText();
|
|
|
|
|
}
|
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();
|
2002-08-02 16:39:43 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|