2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file BufferView_pimpl.C
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
2004-01-30 11:41:12 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
2003-06-30 23:56:22 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "BufferView_pimpl.h"
|
2003-05-23 13:54:09 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "bufferlist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2004-08-14 14:03:42 +00:00
|
|
|
|
#include "coordcache.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "cursor.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "factory.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "FloatList.h"
|
2002-08-07 08:11:41 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-04-01 08:58:45 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "intl.h"
|
2004-03-27 12:42:10 +00:00
|
|
|
|
#include "insetiterator.h"
|
2005-01-24 17:12:19 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "lyx_cb.h" // added for Dispatch functions
|
|
|
|
|
#include "lyx_main.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "lyxfind.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "lyxrc.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "lastfiles.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-08-27 13:51:18 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2004-04-07 20:20:15 +00:00
|
|
|
|
#include "rowpainter.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2005-06-25 15:57:15 +00:00
|
|
|
|
#include "insets/insetbibtex.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetref.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/FileDialog.h"
|
2005-01-10 09:28:06 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2003-02-26 19:28:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
#include "frontends/LyXScreenFactory.h"
|
|
|
|
|
#include "frontends/screen.h"
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
#include "frontends/WorkAreaFactory.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-11-25 11:08:32 +00:00
|
|
|
|
#include "support/filefilterlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "support/filetools.h"
|
2004-03-24 17:38:54 +00:00
|
|
|
|
#include "support/forkedcontr.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/package.h"
|
2004-04-07 20:20:15 +00:00
|
|
|
|
#include "support/types.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include <boost/current_function.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2004-11-06 15:23:12 +00:00
|
|
|
|
#include <functional>
|
2005-02-22 11:41:22 +00:00
|
|
|
|
#include <vector>
|
2004-11-06 15:23:12 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
|
|
|
|
|
using lyx::support::AddPath;
|
|
|
|
|
using lyx::support::bformat;
|
2004-01-08 10:59:51 +00:00
|
|
|
|
using lyx::support::FileFilterList;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::FileSearch;
|
2004-03-24 17:38:54 +00:00
|
|
|
|
using lyx::support::ForkedcallsController;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::IsDirWriteable;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
using lyx::support::MakeAbsPath;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
using lyx::support::package;
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
using std::endl;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
using std::istringstream;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
using std::make_pair;
|
2001-01-28 18:31:36 +00:00
|
|
|
|
using std::min;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
using std::max;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2004-11-06 15:23:12 +00:00
|
|
|
|
using std::mem_fun_ref;
|
2005-02-22 11:41:22 +00:00
|
|
|
|
using std::vector;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
2001-03-17 02:06:21 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2002-07-22 20:57:58 +00:00
|
|
|
|
unsigned int const saved_positions_num = 20;
|
|
|
|
|
|
|
|
|
|
// All the below connection objects are needed because of a bug in some
|
|
|
|
|
// versions of GCC (<=2.96 are on the suspects list.) By having and assigning
|
|
|
|
|
// to these connections we avoid a segfault upon startup, and also at exit.
|
|
|
|
|
// (Lgb)
|
|
|
|
|
|
2002-08-28 08:30:27 +00:00
|
|
|
|
boost::signals::connection dispatchcon;
|
2002-07-22 20:57:58 +00:00
|
|
|
|
boost::signals::connection timecon;
|
|
|
|
|
boost::signals::connection doccon;
|
|
|
|
|
boost::signals::connection resizecon;
|
|
|
|
|
boost::signals::connection kpresscon;
|
|
|
|
|
boost::signals::connection selectioncon;
|
|
|
|
|
boost::signals::connection lostcon;
|
2000-04-14 19:20:33 +00:00
|
|
|
|
|
2002-08-27 16:16:17 +00:00
|
|
|
|
|
2005-06-25 15:57:15 +00:00
|
|
|
|
/// Return an inset of this class if it exists at the current cursor position
|
2004-08-14 00:27:15 +00:00
|
|
|
|
template <class T>
|
|
|
|
|
T * getInsetByCode(LCursor & cur, InsetBase::Code code)
|
|
|
|
|
{
|
|
|
|
|
T * inset = 0;
|
|
|
|
|
DocIterator it = cur;
|
|
|
|
|
if (it.nextInset() &&
|
|
|
|
|
it.nextInset()->lyxCode() == code) {
|
|
|
|
|
inset = static_cast<T*>(it.nextInset());
|
|
|
|
|
}
|
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-17 02:06:21 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2000-04-14 19:20:33 +00:00
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
|
2004-04-28 17:22:05 +00:00
|
|
|
|
int width, int height)
|
2004-01-16 10:55:19 +00:00
|
|
|
|
: bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400),
|
2004-11-30 01:59:49 +00:00
|
|
|
|
using_xterm_cursor(false), cursor_(bv) ,
|
|
|
|
|
anchor_ref_(0), offset_ref_(0)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
|
2004-04-28 17:22:05 +00:00
|
|
|
|
workarea_.reset(WorkAreaFactory::create(*owner_, width, height));
|
2002-06-18 15:44:30 +00:00
|
|
|
|
screen_.reset(LyXScreenFactory::create(workarea()));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Setup the signals
|
2002-08-19 15:39:25 +00:00
|
|
|
|
doccon = workarea().scrollDocView
|
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
resizecon = workarea().workAreaResize
|
2002-06-20 20:37:42 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaResize, this));
|
2002-08-28 08:30:27 +00:00
|
|
|
|
dispatchcon = workarea().dispatch
|
2003-03-24 02:31:44 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
kpresscon = workarea().workAreaKeyPress
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
selectioncon = workarea().selectionRequested
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
|
2002-07-22 20:57:58 +00:00
|
|
|
|
lostcon = workarea().selectionLost
|
2002-05-29 16:21:03 +00:00
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-19 15:39:25 +00:00
|
|
|
|
timecon = cursor_timeout.timeout
|
|
|
|
|
.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor_timeout.start();
|
2001-01-28 18:31:36 +00:00
|
|
|
|
saved_positions.resize(saved_positions_num);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-06-20 23:03:43 +00:00
|
|
|
|
void BufferView::Pimpl::addError(ErrorItem const & ei)
|
|
|
|
|
{
|
|
|
|
|
errorlist_.push_back(ei);
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-07-10 12:26:40 +00:00
|
|
|
|
void BufferView::Pimpl::showReadonly(bool)
|
|
|
|
|
{
|
|
|
|
|
owner_->updateWindowTitle();
|
|
|
|
|
owner_->getDialogs().updateBufferDependent(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
void BufferView::Pimpl::connectBuffer(Buffer & buf)
|
|
|
|
|
{
|
|
|
|
|
if (errorConnection_.connected())
|
|
|
|
|
disconnectBuffer();
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
errorConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.error.connect(
|
|
|
|
|
boost::bind(&BufferView::Pimpl::addError, this, _1));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
messageConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.message.connect(
|
|
|
|
|
boost::bind(&LyXView::message, owner_, _1));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
busyConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.busy.connect(
|
|
|
|
|
boost::bind(&LyXView::busy, owner_, _1));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
titleConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.updateTitles.connect(
|
|
|
|
|
boost::bind(&LyXView::updateWindowTitle, owner_));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
timerConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.resetAutosaveTimers.connect(
|
|
|
|
|
boost::bind(&LyXView::resetAutosaveTimer, owner_));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
readonlyConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.readonly.connect(
|
|
|
|
|
boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
|
|
|
|
|
|
2004-01-16 10:55:19 +00:00
|
|
|
|
closingConnection_ =
|
2004-03-18 12:53:43 +00:00
|
|
|
|
buf.closing.connect(
|
|
|
|
|
boost::bind(&BufferView::Pimpl::setBuffer, this, (Buffer *)0));
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::disconnectBuffer()
|
|
|
|
|
{
|
|
|
|
|
errorConnection_.disconnect();
|
|
|
|
|
messageConnection_.disconnect();
|
|
|
|
|
busyConnection_.disconnect();
|
2003-07-10 12:26:40 +00:00
|
|
|
|
titleConnection_.disconnect();
|
|
|
|
|
timerConnection_.disconnect();
|
|
|
|
|
readonlyConnection_.disconnect();
|
2003-07-11 12:21:31 +00:00
|
|
|
|
closingConnection_.disconnect();
|
2003-07-07 08:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void BufferView::Pimpl::newFile(string const & filename, string const & tname,
|
|
|
|
|
bool isNamed)
|
2003-07-07 08:37:02 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(::newFile(filename, tname, isNamed));
|
2003-06-20 23:03:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
|
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2003-06-20 12:46:28 +00:00
|
|
|
|
string s = FileSearch(string(), filename, "lyx");
|
2003-08-01 21:18:49 +00:00
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
bool const found = !s.empty();
|
|
|
|
|
|
2003-08-01 21:18:49 +00:00
|
|
|
|
if (!found)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
s = filename;
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// File already open?
|
2003-06-20 12:46:28 +00:00
|
|
|
|
if (bufferlist.exists(s)) {
|
|
|
|
|
string const file = MakeDisplayPath(s, 20);
|
|
|
|
|
string text = bformat(_("The document %1$s is already "
|
|
|
|
|
"loaded.\n\nDo you want to revert "
|
|
|
|
|
"to the saved version?"), file);
|
|
|
|
|
int const ret = Alert::prompt(_("Revert to saved document?"),
|
|
|
|
|
text, 0, 1, _("&Revert"), _("&Switch to document"));
|
|
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(bufferlist.getBuffer(s));
|
2003-06-20 12:46:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// FIXME: should be LFUN_REVERT
|
|
|
|
|
if (!bufferlist.close(bufferlist.getBuffer(s), false))
|
|
|
|
|
return false;
|
|
|
|
|
// Fall through to new load. (Asger)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
Buffer * b;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (found) {
|
|
|
|
|
b = bufferlist.newBuffer(s);
|
|
|
|
|
connectBuffer(*b);
|
|
|
|
|
if (!::loadLyXFile(b, s)) {
|
|
|
|
|
bufferlist.release(b);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2003-07-07 08:37:02 +00:00
|
|
|
|
string text = bformat(_("The document %1$s does not yet "
|
|
|
|
|
"exist.\n\nDo you want to create "
|
2003-06-20 12:46:28 +00:00
|
|
|
|
"a new document?"), s);
|
|
|
|
|
int const ret = Alert::prompt(_("Create new document?"),
|
|
|
|
|
text, 0, 1, _("&Create"), _("Cancel"));
|
|
|
|
|
|
2003-07-29 16:40:26 +00:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
b = ::newFile(s, string(), true);
|
|
|
|
|
else
|
2003-06-27 07:11:31 +00:00
|
|
|
|
return false;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
}
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(b);
|
2003-07-29 16:40:26 +00:00
|
|
|
|
bv_->showErrorList(_("Parse"));
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
if (tolastfiles)
|
2003-10-14 21:30:23 +00:00
|
|
|
|
LyX::ref().lastfiles().newFile(b->fileName());
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
|
2002-06-11 22:38:49 +00:00
|
|
|
|
WorkArea & BufferView::Pimpl::workarea() const
|
|
|
|
|
{
|
|
|
|
|
return *workarea_.get();
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXScreen & BufferView::Pimpl::screen() const
|
2002-06-11 23:47:58 +00:00
|
|
|
|
{
|
|
|
|
|
return *screen_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
|
Painter & BufferView::Pimpl::painter() const
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2002-06-11 22:38:49 +00:00
|
|
|
|
return workarea().getPainter();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void BufferView::Pimpl::setBuffer(Buffer * b)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ b = " << b << "]" << endl;
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (buffer_)
|
2003-07-07 08:37:02 +00:00
|
|
|
|
disconnectBuffer();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// If we are closing current buffer, switch to the first in
|
2004-10-15 08:27:59 +00:00
|
|
|
|
// buffer list.
|
|
|
|
|
if (!b) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " No Buffer!" << endl;
|
|
|
|
|
// We are closing the buffer, use the first buffer as current
|
2004-10-15 08:27:59 +00:00
|
|
|
|
buffer_ = bufferlist.first();
|
|
|
|
|
owner_->getDialogs().hideBufferDependent();
|
|
|
|
|
} else {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Set current buffer
|
2004-10-15 08:27:59 +00:00
|
|
|
|
buffer_ = b;
|
|
|
|
|
}
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Reset old cursor
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cursor_ = LCursor(*bv_);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
offset_ref_ = 0;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// If we're quitting lyx, don't bother updating stuff
|
2003-02-15 19:21:11 +00:00
|
|
|
|
if (quitting)
|
2003-03-02 12:16:00 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
if (buffer_) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "Buffer addr: " << buffer_ << endl;
|
2003-07-07 08:37:02 +00:00
|
|
|
|
connectBuffer(*buffer_);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cursor_.push(buffer_->inset());
|
|
|
|
|
cursor_.resetAnchor();
|
2003-12-01 00:35:26 +00:00
|
|
|
|
buffer_->text().init(bv_);
|
2004-08-08 22:36:34 +00:00
|
|
|
|
buffer_->text().setCurrentFont(cursor_);
|
2003-12-01 00:35:26 +00:00
|
|
|
|
|
2003-04-02 09:10:08 +00:00
|
|
|
|
// Buffer-dependent dialogs should be updated or
|
2000-10-10 11:50:43 +00:00
|
|
|
|
// hidden. This should go here because some dialogs (eg ToC)
|
|
|
|
|
// require bv_->text.
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner_->getDialogs().updateBufferDependent(true);
|
2004-10-26 21:16:44 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-08-01 15:27:57 +00:00
|
|
|
|
update();
|
2002-06-21 02:22:13 +00:00
|
|
|
|
updateScrollbar();
|
|
|
|
|
owner_->updateMenubar();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
owner_->updateToolbars();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
owner_->updateWindowTitle();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
2004-07-05 14:34:50 +00:00
|
|
|
|
// This is done after the layout combox has been populated
|
|
|
|
|
if (buffer_)
|
|
|
|
|
owner_->setLayout(cursor_.paragraph().layout()->name());
|
|
|
|
|
|
2004-04-19 13:31:17 +00:00
|
|
|
|
if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
2003-07-21 21:30:57 +00:00
|
|
|
|
lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-02 22:20:49 +00:00
|
|
|
|
|
2003-08-11 09:09:01 +00:00
|
|
|
|
void BufferView::Pimpl::resizeCurrentBuffer()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << endl;
|
2003-02-14 14:49:51 +00:00
|
|
|
|
owner_->busy(true);
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner_->message(_("Formatting document..."));
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2004-01-13 10:37:38 +00:00
|
|
|
|
LyXText * text = bv_->text();
|
|
|
|
|
if (!text)
|
2003-11-28 15:08:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-03-01 16:29:30 +00:00
|
|
|
|
text->init(bv_);
|
2003-12-02 10:51:58 +00:00
|
|
|
|
update();
|
2002-03-12 17:15:44 +00:00
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
switchKeyMap();
|
2003-02-14 14:49:51 +00:00
|
|
|
|
owner_->busy(false);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Reset the "Formatting..." message
|
2003-04-07 16:57:38 +00:00
|
|
|
|
owner_->clearMessage();
|
|
|
|
|
|
2002-08-07 14:15:06 +00:00
|
|
|
|
updateScrollbar();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::Pimpl::updateScrollbar()
|
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
if (!bv_->text()) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " no text in updateScrollbar" << endl;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
workarea().setScrollbarParams(0, 0, 0);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
LyXText & t = *bv_->text();
|
|
|
|
|
if (anchor_ref_ > int(t.paragraphs().size()) - 1) {
|
|
|
|
|
anchor_ref_ = int(t.paragraphs().size()) - 1;
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
lyxerr[Debug::GUI]
|
2005-02-06 00:30:11 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " Updating scrollbar: height: " << t.paragraphs().size()
|
2005-02-07 15:37:07 +00:00
|
|
|
|
<< " curr par: " << cursor_.bottom().pit()
|
2004-03-18 12:53:43 +00:00
|
|
|
|
<< " default height " << defaultRowHeight() << endl;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// It would be better to fix the scrollbar to understand
|
|
|
|
|
// values in [0..1] and divide everything by wh
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const wh = workarea().workHeight() / 4;
|
|
|
|
|
int const h = t.getPar(anchor_ref_).height();
|
|
|
|
|
workarea().setScrollbarParams(t.paragraphs().size() * wh, anchor_ref_ * wh + int(offset_ref_ * wh / float(h)), int (wh * defaultRowHeight() / float(h)));
|
|
|
|
|
// workarea().setScrollbarParams(t.paragraphs().size(), anchor_ref_, 1);
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
|
void BufferView::Pimpl::scrollDocView(int value)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[ value = " << value << "]" << endl;
|
2002-04-05 15:17:24 +00:00
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
if (!buffer_)
|
|
|
|
|
return;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
screen().hideCursor();
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const wh = workarea().workHeight() / 4;
|
|
|
|
|
|
|
|
|
|
LyXText & t = *bv_->text();
|
|
|
|
|
|
|
|
|
|
float const bar = value / float(wh * t.paragraphs().size());
|
|
|
|
|
|
|
|
|
|
anchor_ref_ = int(bar * t.paragraphs().size());
|
|
|
|
|
t.redoParagraph(anchor_ref_);
|
|
|
|
|
int const h = t.getPar(anchor_ref_).height();
|
|
|
|
|
offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
|
|
|
|
|
update();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2002-08-29 13:05:55 +00:00
|
|
|
|
if (!lyxrc.cursor_follows_scrollbar)
|
2001-02-07 16:44:49 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
|
int const first = height;
|
|
|
|
|
int const last = workarea().workHeight() - height;
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bv_funcs::CurStatus st = bv_funcs::status(bv_, cur);
|
2003-03-18 20:54:01 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
switch (st) {
|
|
|
|
|
case bv_funcs::CUR_ABOVE:
|
|
|
|
|
t.setCursorFromCoordinates(cur, 0, first);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_BELOW:
|
|
|
|
|
t.setCursorFromCoordinates(cur, 0, last);
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
|
|
|
|
case bv_funcs::CUR_INSIDE:
|
2005-07-15 15:49:40 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const newy = min(last, max(y, first));
|
|
|
|
|
if (y != newy) {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cur.reset(buffer_->inset());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
t.setCursorFromCoordinates(cur, 0, newy);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-26 15:55:52 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
|
void BufferView::Pimpl::scroll(int /*lines*/)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// if (!buffer_)
|
|
|
|
|
// return;
|
|
|
|
|
//
|
|
|
|
|
// LyXText const * t = bv_->text();
|
|
|
|
|
// int const line_height = defaultRowHeight();
|
|
|
|
|
//
|
|
|
|
|
// // The new absolute coordinate
|
|
|
|
|
// int new_top_y = top_y() + lines * line_height;
|
|
|
|
|
//
|
|
|
|
|
// // Restrict to a valid value
|
|
|
|
|
// new_top_y = std::min(t->height() - 4 * line_height, new_top_y);
|
|
|
|
|
// new_top_y = std::max(0, new_top_y);
|
|
|
|
|
//
|
|
|
|
|
// scrollDocView(new_top_y);
|
|
|
|
|
//
|
|
|
|
|
// // Update the scrollbar.
|
|
|
|
|
// workarea().setScrollbarParams(t->height(), top_y(), defaultRowHeight());
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
|
|
|
|
|
key_modifier::state state)
|
2000-08-14 15:31:16 +00:00
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
owner_->getLyXFunc().processKeySym(key, state);
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
|
|
|
|
/* This is perhaps a bit of a hack. When we move
|
|
|
|
|
* around, or type, it's nice to be able to see
|
|
|
|
|
* the cursor immediately after the keypress. So
|
|
|
|
|
* we reset the toggle timeout and force the visibility
|
|
|
|
|
* of the cursor. Note we cannot do this inside
|
|
|
|
|
* dispatch() itself, because that's called recursively.
|
|
|
|
|
*/
|
2005-06-06 12:34:28 +00:00
|
|
|
|
if (available())
|
|
|
|
|
screen().showCursor(*bv_);
|
2000-08-14 15:31:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-01-13 17:28:42 +00:00
|
|
|
|
void BufferView::Pimpl::selectionRequested()
|
|
|
|
|
{
|
2002-03-20 10:36:03 +00:00
|
|
|
|
static string sel;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-04 11:30:25 +00:00
|
|
|
|
if (!available())
|
|
|
|
|
return;
|
2002-03-20 10:36:03 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2002-03-20 10:36:03 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection()) {
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!xsel_cache_.set ||
|
2005-02-08 13:18:05 +00:00
|
|
|
|
cur.top() != xsel_cache_.cursor ||
|
|
|
|
|
cur.anchor_.top() != xsel_cache_.anchor)
|
2002-03-20 10:36:03 +00:00
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
xsel_cache_.cursor = cur.top();
|
|
|
|
|
xsel_cache_.anchor = cur.anchor_.top();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
xsel_cache_.set = cur.selection();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
sel = cur.selectionAsString(false);
|
2003-12-12 15:19:35 +00:00
|
|
|
|
if (!sel.empty())
|
|
|
|
|
workarea().putClipboard(sel);
|
2004-03-24 17:38:54 +00:00
|
|
|
|
}
|
2002-01-13 17:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-07 16:43:54 +00:00
|
|
|
|
void BufferView::Pimpl::selectionLost()
|
|
|
|
|
{
|
2002-06-11 22:38:49 +00:00
|
|
|
|
if (available()) {
|
2003-05-03 18:05:53 +00:00
|
|
|
|
screen().hideCursor();
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.clearSelection();
|
2003-12-12 15:19:35 +00:00
|
|
|
|
xsel_cache_.set = false;
|
2002-03-05 16:18:02 +00:00
|
|
|
|
}
|
2002-02-07 16:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-20 20:37:42 +00:00
|
|
|
|
void BufferView::Pimpl::workAreaResize()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static int work_area_width;
|
2002-07-01 14:31:57 +00:00
|
|
|
|
static int work_area_height;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2002-06-11 22:38:49 +00:00
|
|
|
|
bool const widthChange = workarea().workWidth() != work_area_width;
|
2002-06-12 00:51:45 +00:00
|
|
|
|
bool const heightChange = workarea().workHeight() != work_area_height;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Update from work area
|
2002-06-11 22:38:49 +00:00
|
|
|
|
work_area_width = workarea().workWidth();
|
2002-06-12 00:51:45 +00:00
|
|
|
|
work_area_height = workarea().workHeight();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (buffer_ && widthChange) {
|
|
|
|
|
// The visible LyXView need a resize
|
|
|
|
|
resizeCurrentBuffer();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 15:27:57 +00:00
|
|
|
|
if (widthChange || heightChange)
|
|
|
|
|
update();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Always make sure that the scrollbar is sane.
|
2000-04-09 22:48:51 +00:00
|
|
|
|
updateScrollbar();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
owner_->updateLayoutChoice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
bool BufferView::Pimpl::fitCursor()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (bv_funcs::status(bv_, cursor_) == bv_funcs::CUR_INSIDE) {
|
|
|
|
|
LyXFont const font = cursor_.getFont();
|
2005-01-10 09:28:06 +00:00
|
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
|
int const des = font_metrics::maxDescent(font);
|
2005-07-15 15:49:40 +00:00
|
|
|
|
Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight())
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2005-02-07 15:37:07 +00:00
|
|
|
|
center();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 13:23:14 +00:00
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
void BufferView::Pimpl::update(Update::flags flags)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
|
|
|
|
<< "] buffer: " << buffer_ << endl;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Check needed to survive LyX startup
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (buffer_) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Update macro store
|
2004-04-13 06:27:29 +00:00
|
|
|
|
buffer_->buildMacros();
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
CoordCache backup;
|
|
|
|
|
std::swap(theCoords, backup);
|
2005-06-09 09:58:08 +00:00
|
|
|
|
|
2005-05-11 07:44:20 +00:00
|
|
|
|
// This, together with doneUpdating(), verifies (using
|
2005-06-09 09:58:08 +00:00
|
|
|
|
// asserts) that screen redraw is not called from
|
2005-05-11 07:44:20 +00:00
|
|
|
|
// within itself.
|
2005-01-31 16:29:48 +00:00
|
|
|
|
theCoords.startUpdating();
|
2005-02-06 00:30:11 +00:00
|
|
|
|
|
2005-05-11 07:44:20 +00:00
|
|
|
|
// First drawing step
|
2004-11-30 01:59:49 +00:00
|
|
|
|
ViewMetricsInfo vi = metrics();
|
2005-05-31 14:40:30 +00:00
|
|
|
|
bool forceupdate(flags & Update::Force);
|
2004-08-14 14:03:42 +00:00
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
if ((flags & Update::FitCursor) && fitCursor()) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
forceupdate = true;
|
2005-05-31 14:40:30 +00:00
|
|
|
|
vi = metrics(flags & Update::SinglePar);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
if (forceupdate) {
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Second drawing step
|
2004-11-30 01:59:49 +00:00
|
|
|
|
screen().redraw(*bv_, vi);
|
2005-01-31 16:29:48 +00:00
|
|
|
|
} else {
|
2005-05-11 07:44:20 +00:00
|
|
|
|
// Abort updating of the coord
|
|
|
|
|
// cache - just restore the old one
|
2004-11-30 01:59:49 +00:00
|
|
|
|
std::swap(theCoords, backup);
|
2005-01-31 16:29:48 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
} else
|
|
|
|
|
screen().greyOut();
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// And the scrollbar
|
2004-11-30 01:59:49 +00:00
|
|
|
|
updateScrollbar();
|
2005-02-07 15:37:07 +00:00
|
|
|
|
owner_->view_state_changed();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
// Callback for cursor timer
|
|
|
|
|
void BufferView::Pimpl::cursorToggle()
|
|
|
|
|
{
|
2004-03-24 17:38:54 +00:00
|
|
|
|
if (buffer_) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
screen().toggleCursor(*bv_);
|
2004-03-24 17:38:54 +00:00
|
|
|
|
|
|
|
|
|
// Use this opportunity to deal with any child processes that
|
|
|
|
|
// have finished but are waiting to communicate this fact
|
|
|
|
|
// to the rest of LyX.
|
|
|
|
|
ForkedcallsController & fcc = ForkedcallsController::get();
|
2005-04-20 17:35:47 +00:00
|
|
|
|
fcc.handleCompletedProcesses();
|
2004-03-24 17:38:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor_timeout.restart();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::Pimpl::available() const
|
|
|
|
|
{
|
2003-11-28 08:55:12 +00:00
|
|
|
|
return buffer_ && bv_->text();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
Change const BufferView::Pimpl::getCurrentChange()
|
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (!buffer_->params().tracking_changes)
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
|
|
2003-08-15 10:24:39 +00:00
|
|
|
|
LyXText * text = bv_->getLyXText();
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
return text->getPar(cur.selBegin().pit()).
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lookupChangeFull(cur.selBegin().pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
void BufferView::Pimpl::savePosition(unsigned int i)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2001-01-28 18:31:36 +00:00
|
|
|
|
if (i >= saved_positions_num)
|
|
|
|
|
return;
|
2005-02-07 15:37:07 +00:00
|
|
|
|
BOOST_ASSERT(cursor_.inTexted());
|
2001-01-28 18:31:36 +00:00
|
|
|
|
saved_positions[i] = Position(buffer_->fileName(),
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.paragraph().id(),
|
|
|
|
|
cursor_.pos());
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (i > 0)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
owner_->message(bformat(_("Saved bookmark %1$d"), i));
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
void BufferView::Pimpl::restorePosition(unsigned int i)
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2001-01-28 18:31:36 +00:00
|
|
|
|
if (i >= saved_positions_num)
|
|
|
|
|
return;
|
|
|
|
|
|
2001-05-03 14:31:33 +00:00
|
|
|
|
string const fname = saved_positions[i].filename;
|
2000-08-08 13:55:26 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.clearSelection();
|
2000-08-08 13:55:26 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (fname != buffer_->fileName()) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
Buffer * b = 0;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
if (bufferlist.exists(fname))
|
|
|
|
|
b = bufferlist.getBuffer(fname);
|
|
|
|
|
else {
|
|
|
|
|
b = bufferlist.newBuffer(fname);
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Don't ask, just load it
|
|
|
|
|
::loadLyXFile(b, fname);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (b)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
setBuffer(b);
|
2000-08-08 13:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
|
|
|
|
|
if (par == buffer_->par_iterator_end())
|
2001-01-28 18:31:36 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_->setCursor(makeDocIterator(par, min(par->size(), saved_positions[i].par_pos)));
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (i > 0)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
owner_->message(bformat(_("Moved to bookmark %1$d"), i));
|
2000-08-08 13:55:26 +00:00
|
|
|
|
}
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2000-06-21 12:41:18 +00:00
|
|
|
|
|
2001-01-28 18:31:36 +00:00
|
|
|
|
bool BufferView::Pimpl::isSavedPosition(unsigned int i)
|
2000-06-05 15:12:09 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
return i < saved_positions_num && !saved_positions[i].filename.empty();
|
2000-06-05 15:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-09 22:48:51 +00:00
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
|
void BufferView::Pimpl::switchKeyMap()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (!lyxrc.rtl_support)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
Intl & intl = owner_->getIntl();
|
|
|
|
|
if (bv_->getLyXText()->real_current_font.isRightToLeft()) {
|
|
|
|
|
if (intl.keymap == Intl::PRIMARY)
|
|
|
|
|
intl.KeyMapSec();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
} else {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (intl.keymap == Intl::SECONDARY)
|
|
|
|
|
intl.KeyMapPrim();
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void BufferView::Pimpl::center()
|
2000-04-09 22:48:51 +00:00
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
CursorSlice & bot = cursor_.bottom();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyx::pit_type const pit = bot.pit();
|
|
|
|
|
bot.text()->redoParagraph(pit);
|
|
|
|
|
Paragraph const & par = bot.text()->paragraphs()[pit];
|
|
|
|
|
anchor_ref_ = pit;
|
2005-07-15 15:49:40 +00:00
|
|
|
|
offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
|
|
|
|
|
+ par.ascent() - workarea().workHeight() / 2;
|
2000-04-09 22:48:51 +00:00
|
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
void BufferView::Pimpl::stuffClipboard(string const & content) const
|
2000-05-20 21:37:05 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
workarea().putClipboard(content);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string filename = filenm;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// Launch a file browser
|
|
|
|
|
string initpath = lyxrc.document_path;
|
|
|
|
|
|
|
|
|
|
if (available()) {
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const trypath = owner_->buffer()->filePath();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (IsDirWriteable(trypath))
|
2001-02-23 16:10:03 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
|
FileDialog fileDlg(_("Select LyX document to insert"),
|
2001-03-07 14:25:31 +00:00
|
|
|
|
LFUN_FILE_INSERT,
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Documents|#o#O")),
|
2001-05-29 09:50:02 +00:00
|
|
|
|
string(lyxrc.document_path)),
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Examples|#E#e")),
|
2005-01-10 19:17:43 +00:00
|
|
|
|
string(AddPath(package().system_support(), "examples"))));
|
2001-05-29 09:50:02 +00:00
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2002-11-17 08:32:09 +00:00
|
|
|
|
fileDlg.open(initpath,
|
2004-01-08 10:59:51 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filename = result.second;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
|
if (filename.empty()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner_->message(_("Canceled."));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-03-07 14:25:31 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2001-06-27 14:10:35 +00:00
|
|
|
|
filename = FileSearch(string(), filename, "lyx");
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const disp_fn = MakeDisplayPath(filename);
|
|
|
|
|
owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.clearSelection();
|
|
|
|
|
bv_->getLyXText()->breakParagraph(cursor_);
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
BOOST_ASSERT(cursor_.inTexted());
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
|
|
|
|
string const fname = MakeAbsPath(filename);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bool const res = buffer_->readFile(fname, cursor_.pit());
|
|
|
|
|
resizeCurrentBuffer();
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2004-10-05 10:11:42 +00:00
|
|
|
|
string s = res ? _("Document %1$s inserted.")
|
2004-08-14 19:55:00 +00:00
|
|
|
|
: _("Could not insert document %1$s");
|
|
|
|
|
owner_->message(bformat(s, disp_fn));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
void BufferView::Pimpl::trackChanges()
|
|
|
|
|
{
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bool const tracking = buffer_->params().tracking_changes;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
if (!tracking) {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
for_each(buffer_->par_iterator_begin(),
|
|
|
|
|
buffer_->par_iterator_end(),
|
2004-11-06 15:23:12 +00:00
|
|
|
|
bind(&Paragraph::trackChanges, _1, Change::UNCHANGED));
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->params().tracking_changes = true;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// We cannot allow undos beyond the freeze point
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->undostack().clear();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
} else {
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bv_->text()->setCursor(cursor_, 0, 0);
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning changes FIXME
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2005-02-06 00:30:11 +00:00
|
|
|
|
bool const found = lyx::find::findNextChange(bv_);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (found) {
|
2003-03-09 21:03:43 +00:00
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
for_each(buffer_->par_iterator_begin(),
|
|
|
|
|
buffer_->par_iterator_end(),
|
2004-11-06 15:23:12 +00:00
|
|
|
|
mem_fun_ref(&Paragraph::untrackChanges));
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->params().tracking_changes = false;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
buffer_->redostack().clear();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
|
2003-08-05 19:51:45 +00:00
|
|
|
|
{
|
2005-07-15 00:39:44 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
2004-01-30 11:41:12 +00:00
|
|
|
|
FuncRequest cmd = cmd0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Handle drag&drop
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cmd.action == LFUN_FILE_OPEN) {
|
|
|
|
|
owner_->dispatch(cmd);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
if (!buffer_)
|
2004-04-13 06:27:29 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
LCursor cur(*bv_);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cur.push(buffer_->inset());
|
|
|
|
|
cur.selection() = cursor_.selection();
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Doesn't go through lyxfunc, so we need to update
|
|
|
|
|
// the layout choice etc. ourselves
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// E.g. Qt mouse press when no buffer
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!available())
|
|
|
|
|
return false;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
screen().hideCursor();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Either the inset under the cursor or the
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// surrounding LyXText will handle this event.
|
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Build temporary cursor.
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cmd.y = min(max(cmd.y,-1), workarea().workHeight());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
|
2005-07-15 00:39:44 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * hit inset at tip: " << inset << endl;
|
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << " * created temp cursor:" << cur << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Put anchor at the same position.
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Try to dispatch to an non-editable inset near this position
|
2004-04-03 08:37:12 +00:00
|
|
|
|
// via the temp cursor. If the inset wishes to change the real
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// cursor it has to do so explicitly by using
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// cur.bv().cursor() = cur; (or similar)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (inset)
|
|
|
|
|
inset->dispatch(cur, cmd);
|
|
|
|
|
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// Now dispatch to the temporary cursor. If the real cursor should
|
2004-04-20 08:51:15 +00:00
|
|
|
|
// be modified, the inset's dispatch has to do so explicitly.
|
2004-08-13 14:56:06 +00:00
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(cmd);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|
2004-08-13 14:56:06 +00:00
|
|
|
|
if (cur.result().dispatched()) {
|
2004-04-07 20:20:15 +00:00
|
|
|
|
// Redraw if requested or necessary.
|
2005-05-31 14:40:30 +00:00
|
|
|
|
if (cur.result().update())
|
|
|
|
|
update(Update::FitCursor | Update::Force);
|
|
|
|
|
else
|
|
|
|
|
update();
|
2004-04-07 20:20:15 +00:00
|
|
|
|
}
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// See workAreaKeyPress
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cursor_timeout.restart();
|
|
|
|
|
screen().showCursor(*bv_);
|
2003-03-24 02:31:44 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Skip these when selecting
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cmd.action != LFUN_MOUSE_MOTION) {
|
|
|
|
|
owner_->updateLayoutChoice();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
owner_->updateToolbars();
|
2003-08-05 19:51:45 +00:00
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Slight hack: this is only called currently when we
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// clicked somewhere, so we force through the display
|
|
|
|
|
// of the new status here.
|
|
|
|
|
owner_->clearMessage();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return true;
|
2003-03-24 02:31:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
|
|
|
|
|
{
|
|
|
|
|
FuncStatus flag;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(!buffer_->undostack().empty());
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(!buffer_->redostack().empty());
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_FILE_INSERT:
|
|
|
|
|
case LFUN_FILE_INSERT_ASCII_PARA:
|
|
|
|
|
case LFUN_FILE_INSERT_ASCII:
|
|
|
|
|
case LFUN_FONT_STATE:
|
|
|
|
|
case LFUN_INSERT_LABEL:
|
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2005-02-09 11:27:21 +00:00
|
|
|
|
case LFUN_GOTO_PARAGRAPH:
|
2005-02-22 11:41:22 +00:00
|
|
|
|
case LFUN_GOTOERROR:
|
|
|
|
|
case LFUN_GOTONOTE:
|
|
|
|
|
case LFUN_REFERENCE_GOTO:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_WORD_FIND:
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
|
case LFUN_SETMARK:
|
|
|
|
|
case LFUN_CENTER:
|
2005-06-25 15:57:15 +00:00
|
|
|
|
case LFUN_BIBDB_ADD:
|
|
|
|
|
case LFUN_BIBDB_DEL:
|
2004-12-27 16:30:27 +00:00
|
|
|
|
case LFUN_WORDS_COUNT:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-06-06 13:11:30 +00:00
|
|
|
|
case LFUN_LABEL_GOTO: {
|
|
|
|
|
flag.enabled(!cmd.argument.empty()
|
|
|
|
|
|| getInsetByCode<InsetRef>(cursor_, InsetBase::REF_CODE));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(isSavedPosition(convert<unsigned int>(cmd.argument)));
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_TRACK_CHANGES:
|
|
|
|
|
flag.enabled(true);
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().tracking_changes);
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-01-24 17:12:19 +00:00
|
|
|
|
case LFUN_OUTPUT_CHANGES: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LaTeXFeatures features(*buffer_, buffer_->params(), false);
|
|
|
|
|
flag.enabled(buffer_ && buffer_->params().tracking_changes
|
2005-01-24 17:12:19 +00:00
|
|
|
|
&& features.isAvailable("dvipost"));
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.setOnOff(buffer_->params().output_changes);
|
2005-01-24 17:12:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
case LFUN_MERGE_CHANGES:
|
|
|
|
|
case LFUN_ACCEPT_CHANGE: // what about these two
|
|
|
|
|
case LFUN_REJECT_CHANGE: // what about these two
|
|
|
|
|
case LFUN_ACCEPT_ALL_CHANGES:
|
|
|
|
|
case LFUN_REJECT_ALL_CHANGES:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
flag.enabled(buffer_ && buffer_->params().tracking_changes);
|
2004-04-01 08:58:45 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << [ cmd = " << cmd << "]" << endl;
|
|
|
|
|
|
2003-02-26 19:28:38 +00:00
|
|
|
|
// Make sure that the cached BufferView is correct.
|
2005-02-06 00:30:11 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION
|
2004-01-30 11:41:12 +00:00
|
|
|
|
<< " action[" << cmd.action << ']'
|
|
|
|
|
<< " arg[" << cmd.argument << ']'
|
|
|
|
|
<< " x[" << cmd.x << ']'
|
|
|
|
|
<< " y[" << cmd.y << ']'
|
|
|
|
|
<< " button[" << cmd.button() << ']'
|
2002-08-28 08:30:27 +00:00
|
|
|
|
<< endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2005-02-07 15:37:07 +00:00
|
|
|
|
LCursor & cur = cursor_;
|
2002-05-01 22:17:09 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
switch (cmd.action) {
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
case LFUN_UNDO:
|
|
|
|
|
if (available()) {
|
|
|
|
|
cur.message(_("Undo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textUndo(*bv_))
|
|
|
|
|
cur.message(_("No further undo information"));
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REDO:
|
|
|
|
|
if (available()) {
|
|
|
|
|
cur.message(_("Redo"));
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (!textRedo(*bv_))
|
|
|
|
|
cur.message(_("No further redo information"));
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
MenuInsertLyXFile(cmd.argument);
|
2001-11-29 17:12:21 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
case LFUN_FILE_INSERT_ASCII_PARA:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsertAsciiFile(bv_, cmd.argument, true);
|
2001-03-07 14:25:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_FILE_INSERT_ASCII:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsertAsciiFile(bv_, cmd.argument, false);
|
2001-03-07 14:25:31 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_FONT_STATE:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(cur.currentState());
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2005-01-27 21:05:44 +00:00
|
|
|
|
savePosition(convert<unsigned int>(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2005-01-27 21:05:44 +00:00
|
|
|
|
restorePosition(convert<unsigned int>(cmd.argument));
|
2001-02-23 16:10:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-05-08 10:02:38 +00:00
|
|
|
|
case LFUN_LABEL_GOTO: {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string label = cmd.argument;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
if (label.empty()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
InsetRef * inset =
|
2005-02-07 15:37:07 +00:00
|
|
|
|
getInsetByCode<InsetRef>(cursor_,
|
2004-08-14 00:27:15 +00:00
|
|
|
|
InsetBase::REF_CODE);
|
2001-02-23 16:10:03 +00:00
|
|
|
|
if (inset) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
label = inset->getContents();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
savePosition(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-29 10:29:38 +00:00
|
|
|
|
if (!label.empty())
|
|
|
|
|
bv_->gotoLabel(label);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
break;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2005-02-09 11:27:21 +00:00
|
|
|
|
case LFUN_GOTO_PARAGRAPH: {
|
|
|
|
|
int const id = convert<int>(cmd.argument);
|
|
|
|
|
ParIterator par = buffer_->getParFromID(id);
|
|
|
|
|
if (par == buffer_->par_iterator_end()) {
|
|
|
|
|
lyxerr[Debug::INFO] << "No matching paragraph found! ["
|
|
|
|
|
<< id << ']' << endl;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] << "Paragraph " << par->id()
|
|
|
|
|
<< " found." << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the cursor
|
2005-02-22 11:41:22 +00:00
|
|
|
|
bv_->setCursor(makeDocIterator(par, 0));
|
2005-02-09 11:27:21 +00:00
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
switchKeyMap();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
case LFUN_GOTOERROR:
|
|
|
|
|
bv_funcs::gotoInset(bv_, InsetBase::ERROR_CODE, false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_GOTONOTE:
|
|
|
|
|
bv_funcs::gotoInset(bv_, InsetBase::NOTE_CODE, false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REFERENCE_GOTO: {
|
|
|
|
|
vector<InsetBase_code> tmp;
|
|
|
|
|
tmp.push_back(InsetBase::LABEL_CODE);
|
|
|
|
|
tmp.push_back(InsetBase::REF_CODE);
|
|
|
|
|
bv_funcs::gotoInset(bv_, tmp, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_TRACK_CHANGES:
|
|
|
|
|
trackChanges();
|
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2005-01-24 17:12:19 +00:00
|
|
|
|
case LFUN_OUTPUT_CHANGES: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bool const state = buffer_->params().output_changes;
|
|
|
|
|
buffer_->params().output_changes = !state;
|
2005-01-24 17:12:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_MERGE_CHANGES:
|
2003-03-09 21:03:43 +00:00
|
|
|
|
owner_->getDialogs().show("changes");
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_ACCEPT_ALL_CHANGES: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.reset(buffer_->inset());
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bv_->getLyXText()->acceptChange(cursor_);
|
2003-08-04 09:06:35 +00:00
|
|
|
|
update();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_REJECT_ALL_CHANGES: {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
cursor_.reset(buffer_->inset());
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-03-02 12:16:00 +00:00
|
|
|
|
#warning FIXME changes
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-08-04 09:06:35 +00:00
|
|
|
|
while (lyx::find::findNextChange(bv_))
|
2005-02-07 15:37:07 +00:00
|
|
|
|
bv_->getLyXText()->rejectChange(cursor_);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
|
case LFUN_WORD_FIND:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
lyx::find::find(bv_, cmd);
|
2004-01-07 17:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_WORD_REPLACE:
|
2004-01-30 11:41:12 +00:00
|
|
|
|
lyx::find::replace(bv_, cmd);
|
2004-01-07 17:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-01-14 17:21:39 +00:00
|
|
|
|
case LFUN_MARK_OFF:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.resetAnchor();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark off"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_ON:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.mark() = true;
|
|
|
|
|
cur.resetAnchor();
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark on"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_SETMARK:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (cur.mark()) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.mark() = false;
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark removed"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.mark() = true;
|
2004-02-03 11:49:05 +00:00
|
|
|
|
cur.message(N_("Mark set"));
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-01-14 17:21:39 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-02-20 11:00:41 +00:00
|
|
|
|
case LFUN_CENTER:
|
2005-02-07 15:37:07 +00:00
|
|
|
|
center();
|
2004-02-20 11:00:41 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-06-25 15:57:15 +00:00
|
|
|
|
case LFUN_BIBDB_ADD: {
|
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
|
|
|
|
if (inset)
|
|
|
|
|
inset->addDatabase(cmd.argument);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBDB_DEL: {
|
|
|
|
|
LCursor tmpcur = cursor_;
|
|
|
|
|
bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
|
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
|
|
|
|
InsetBase::BIBTEX_CODE);
|
|
|
|
|
if (inset)
|
|
|
|
|
inset->delDatabase(cmd.argument);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-27 16:30:27 +00:00
|
|
|
|
case LFUN_WORDS_COUNT: {
|
|
|
|
|
DocIterator from, to;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
|
} else {
|
2005-02-07 15:37:07 +00:00
|
|
|
|
from = doc_iterator_begin(buffer_->inset());
|
|
|
|
|
to = doc_iterator_end(buffer_->inset());
|
2004-12-27 16:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
int const count = countWords(from, to);
|
|
|
|
|
string message;
|
|
|
|
|
if (count != 1) {
|
|
|
|
|
if (cur.selection())
|
2005-01-06 15:40:49 +00:00
|
|
|
|
message = bformat(_("%1$d words in selection."),
|
|
|
|
|
count);
|
2004-12-27 16:30:27 +00:00
|
|
|
|
else
|
2005-01-06 15:40:49 +00:00
|
|
|
|
message = bformat(_("%1$d words in document."),
|
|
|
|
|
count);
|
2004-12-27 16:30:27 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = _("One word in selection.");
|
2005-01-06 15:40:49 +00:00
|
|
|
|
else
|
2004-12-27 16:30:27 +00:00
|
|
|
|
message = _("One word in document.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert::information(_("Count words"), message);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-09-21 23:00:47 +00:00
|
|
|
|
default:
|
2004-02-03 09:08:15 +00:00
|
|
|
|
return false;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
ViewMetricsInfo BufferView::Pimpl::metrics(bool singlepar)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Remove old position cache
|
2004-11-30 01:59:49 +00:00
|
|
|
|
theCoords.clear();
|
|
|
|
|
BufferView & bv = *bv_;
|
|
|
|
|
LyXText * const text = bv.text();
|
|
|
|
|
if (anchor_ref_ > int(text->paragraphs().size() - 1)) {
|
|
|
|
|
anchor_ref_ = int(text->paragraphs().size() - 1);
|
|
|
|
|
offset_ref_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyx::pit_type const pit = anchor_ref_;
|
|
|
|
|
int pit1 = pit;
|
|
|
|
|
int pit2 = pit;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
size_t const npit = text->paragraphs().size();
|
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " npit: " << npit
|
|
|
|
|
<< " pit1: " << pit1
|
|
|
|
|
<< " pit2: " << pit2
|
|
|
|
|
<< endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Rebreak anchor par
|
2004-11-30 01:59:49 +00:00
|
|
|
|
text->redoParagraph(pit);
|
|
|
|
|
int y0 = text->getPar(pit1).ascent() - offset_ref_;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Redo paragraphs above cursor if necessary
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y1 = y0;
|
2005-05-31 14:40:30 +00:00
|
|
|
|
while (!singlepar && y1 > 0 && pit1 > 0) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y1 -= text->getPar(pit1).ascent();
|
|
|
|
|
--pit1;
|
|
|
|
|
text->redoParagraph(pit1);
|
|
|
|
|
y1 -= text->getPar(pit1).descent();
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Take care of ascent of first line
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y1 -= text->getPar(pit1).ascent();
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Normalize anchor for next time
|
2004-11-30 01:59:49 +00:00
|
|
|
|
anchor_ref_ = pit1;
|
|
|
|
|
offset_ref_ = -y1;
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Grey at the beginning is ugly
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (pit1 == 0 && y1 > 0) {
|
|
|
|
|
y0 -= y1;
|
|
|
|
|
y1 = 0;
|
|
|
|
|
anchor_ref_ = 0;
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Redo paragraphs below cursor if necessary
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y2 = y0;
|
2005-05-31 14:40:30 +00:00
|
|
|
|
while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 += text->getPar(pit2).descent();
|
|
|
|
|
++pit2;
|
|
|
|
|
text->redoParagraph(pit2);
|
|
|
|
|
y2 += text->getPar(pit2).ascent();
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// Take care of descent of last line
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y2 += text->getPar(pit2).descent();
|
|
|
|
|
|
2005-02-06 00:30:11 +00:00
|
|
|
|
// The coordinates of all these paragraphs are correct, cache them
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int y = y1;
|
|
|
|
|
for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
|
|
|
|
|
y += text->getPar(pit).ascent();
|
2005-01-31 16:29:48 +00:00
|
|
|
|
theCoords.parPos()[text][pit] = Point(0, y);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
y += text->getPar(pit).descent();
|
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-07-14 08:20:10 +00:00
|
|
|
|
lyxerr[Debug::DEBUG]
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " y1: " << y1
|
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< endl;
|
2005-02-06 00:30:11 +00:00
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
return ViewMetricsInfo(pit1, pit2, y1, y2, singlepar);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|