2002-06-12 02:54:19 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file BufferView.cpp
|
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-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-10-20 11:41:21 +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 John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 02:54:19 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
2008-05-28 16:02:09 +00:00
|
|
|
|
#include "BranchList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferList.h"
|
|
|
|
|
#include "BufferParams.h"
|
|
|
|
|
#include "CoordCache.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
|
#include "Cursor.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "ErrorList.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "factory.h"
|
|
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2004-04-01 08:58:45 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Intl.h"
|
|
|
|
|
#include "InsetIterator.h"
|
|
|
|
|
#include "Language.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyX.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "lyxfind.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXFunc.h"
|
2007-04-29 18:58:28 +00:00
|
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXRC.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Paragraph.h"
|
2003-04-15 00:11:03 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "ParIterator.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
|
#include "Session.h"
|
|
|
|
|
#include "Text.h"
|
|
|
|
|
#include "TextClass.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
|
#include "TextMetrics.h"
|
|
|
|
|
#include "TexRow.h"
|
2008-03-07 19:46:04 +00:00
|
|
|
|
#include "TocBackend.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "VSpace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "WordLangTuple.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetBibtex.h"
|
|
|
|
|
#include "insets/InsetCommand.h" // ChangeRefs
|
2008-03-24 04:27:43 +00:00
|
|
|
|
#include "insets/InsetExternal.h"
|
|
|
|
|
#include "insets/InsetGraphics.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetRef.h"
|
|
|
|
|
#include "insets/InsetText.h"
|
2008-06-24 07:18:06 +00:00
|
|
|
|
#include "insets/InsetNote.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2007-12-25 22:27:32 +00:00
|
|
|
|
#include "frontends/Application.h"
|
2007-10-02 18:27:20 +00:00
|
|
|
|
#include "frontends/Delegates.h"
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2007-08-27 22:53:16 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2007-08-10 10:21:09 +00:00
|
|
|
|
#include "frontends/Selection.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
|
|
|
|
#include "support/convert.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2008-01-03 16:41:06 +00:00
|
|
|
|
#include "support/ExceptionMessage.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "support/filetools.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
#include "support/lstrings.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/Package.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "support/types.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
#include <cerrno>
|
|
|
|
|
#include <fstream>
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <functional>
|
2007-11-06 22:20:05 +00:00
|
|
|
|
#include <iterator>
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2007-07-17 17:40:44 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
namespace Alert = frontend::Alert;
|
2006-10-07 16:47:54 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/// Return an inset of this class if it exists at the current cursor position
|
|
|
|
|
template <class T>
|
2007-10-13 09:04:52 +00:00
|
|
|
|
T * getInsetByCode(Cursor const & cur, InsetCode code)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
|
|
|
|
DocIterator it = cur;
|
2007-09-29 07:34:42 +00:00
|
|
|
|
Inset * inset = it.nextInset();
|
|
|
|
|
if (inset && inset->lyxCode() == code)
|
|
|
|
|
return static_cast<T*>(inset);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
|
bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
|
2007-09-29 07:34:42 +00:00
|
|
|
|
bool same_content);
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
|
bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
|
2007-10-23 18:51:04 +00:00
|
|
|
|
docstring const & contents)
|
2007-09-29 07:34:42 +00:00
|
|
|
|
{
|
|
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
|
|
|
|
|
|
while (tmpdit) {
|
|
|
|
|
Inset const * inset = tmpdit.nextInset();
|
|
|
|
|
if (inset
|
2008-02-07 17:04:06 +00:00
|
|
|
|
&& std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
|
2007-09-29 07:34:42 +00:00
|
|
|
|
&& (contents.empty() ||
|
2007-10-23 18:51:04 +00:00
|
|
|
|
static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
|
2007-09-29 07:34:42 +00:00
|
|
|
|
dit = tmpdit;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
tmpdit.forwardInset();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-09-29 07:34:42 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-29 07:34:42 +00:00
|
|
|
|
|
2007-10-23 18:51:04 +00:00
|
|
|
|
/// Looks for next inset with one of the given codes.
|
2007-10-13 09:04:52 +00:00
|
|
|
|
bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
|
2007-09-29 07:34:42 +00:00
|
|
|
|
bool same_content)
|
|
|
|
|
{
|
2007-10-23 18:51:04 +00:00
|
|
|
|
docstring contents;
|
2007-09-29 07:34:42 +00:00
|
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
|
tmpdit.forwardInset();
|
|
|
|
|
if (!tmpdit)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (same_content) {
|
|
|
|
|
Inset const * inset = tmpdit.nextInset();
|
|
|
|
|
if (inset
|
2008-02-07 17:04:06 +00:00
|
|
|
|
&& std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
|
2007-10-23 18:51:04 +00:00
|
|
|
|
contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
|
2007-09-29 07:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!findNextInset(tmpdit, codes, contents)) {
|
|
|
|
|
if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
|
|
|
|
|
tmpdit = doc_iterator_begin(tmpdit.bottom().inset());
|
|
|
|
|
if (!findNextInset(tmpdit, codes, contents))
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dit = tmpdit;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Looks for next inset with the given code
|
2007-10-13 09:04:52 +00:00
|
|
|
|
void findInset(DocIterator & dit, InsetCode code, bool same_content)
|
2007-09-29 07:34:42 +00:00
|
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
|
findInset(dit, vector<InsetCode>(1, code), same_content);
|
2007-09-29 07:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Moves cursor to the next inset with one of the given codes.
|
2007-10-13 09:04:52 +00:00
|
|
|
|
void gotoInset(BufferView * bv, vector<InsetCode> const & codes,
|
2007-09-29 07:34:42 +00:00
|
|
|
|
bool same_content)
|
|
|
|
|
{
|
|
|
|
|
Cursor tmpcur = bv->cursor();
|
|
|
|
|
if (!findInset(tmpcur, codes, same_content)) {
|
|
|
|
|
bv->cursor().message(_("No more insets"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpcur.clearSelection();
|
|
|
|
|
bv->setCursor(tmpcur);
|
2007-12-22 10:19:26 +00:00
|
|
|
|
bv->showCursor();
|
2007-09-29 07:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Moves cursor to the next inset with given code.
|
2007-10-13 09:04:52 +00:00
|
|
|
|
void gotoInset(BufferView * bv, InsetCode code, bool same_content)
|
2007-09-29 07:34:42 +00:00
|
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
|
gotoInset(bv, vector<InsetCode>(1, code), same_content);
|
2007-09-29 07:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
|
/// A map from a Text to the associated text metrics
|
2007-12-12 19:28:07 +00:00
|
|
|
|
typedef map<Text const *, TextMetrics> TextMetricsCache;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
enum ScreenUpdateStrategy {
|
|
|
|
|
NoScreenUpdate,
|
|
|
|
|
SingleParUpdate,
|
|
|
|
|
FullScreenUpdate,
|
|
|
|
|
DecorationUpdate
|
|
|
|
|
};
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
2007-09-29 20:25:50 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// BufferView
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
struct BufferView::Private
|
2007-10-11 09:59:01 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Private(BufferView & bv): wh_(0), cursor_(bv),
|
2007-12-21 08:28:18 +00:00
|
|
|
|
anchor_pit_(0), anchor_ypos_(0),
|
2008-04-16 21:23:45 +00:00
|
|
|
|
inlineCompletionUniqueChars_(0),
|
|
|
|
|
last_inset_(0), gui_(0)
|
2007-10-11 09:59:01 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
ScrollbarParameters scrollbarParameters_;
|
|
|
|
|
///
|
2007-11-17 11:27:03 +00:00
|
|
|
|
ScreenUpdateStrategy update_strategy_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
///
|
|
|
|
|
CoordCache coord_cache_;
|
|
|
|
|
|
|
|
|
|
/// Estimated average par height for scrollbar.
|
|
|
|
|
int wh_;
|
|
|
|
|
/// this is used to handle XSelection events in the right manner.
|
|
|
|
|
struct {
|
|
|
|
|
CursorSlice cursor;
|
|
|
|
|
CursorSlice anchor;
|
|
|
|
|
bool set;
|
|
|
|
|
} xsel_cache_;
|
|
|
|
|
///
|
|
|
|
|
Cursor cursor_;
|
|
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
|
pit_type anchor_pit_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
|
int anchor_ypos_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
|
vector<int> par_height_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
|
DocIterator inlineCompletionPos_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
|
docstring inlineCompletion_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
///
|
2008-04-16 20:43:30 +00:00
|
|
|
|
size_t inlineCompletionUniqueChars_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
|
/// keyboard mapping object.
|
|
|
|
|
Intl intl_;
|
|
|
|
|
|
|
|
|
|
/// last visited inset.
|
|
|
|
|
/** kept to send setMouseHover(false).
|
|
|
|
|
* Not owned, so don't delete.
|
|
|
|
|
*/
|
|
|
|
|
Inset * last_inset_;
|
|
|
|
|
|
|
|
|
|
mutable TextMetricsCache text_metrics_;
|
|
|
|
|
|
|
|
|
|
/// Whom to notify.
|
|
|
|
|
/** Not owned, so don't delete.
|
|
|
|
|
*/
|
|
|
|
|
frontend::GuiBufferViewDelegate * gui_;
|
2008-03-26 19:20:17 +00:00
|
|
|
|
|
|
|
|
|
/// Cache for Find Next
|
|
|
|
|
FuncRequest search_request_cache_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
2007-09-29 20:25:50 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView::BufferView(Buffer & buf)
|
2008-02-09 17:20:23 +00:00
|
|
|
|
: width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this))
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->xsel_cache_.set = false;
|
|
|
|
|
d->intl_.initKeyMapper(lyxrc.use_kbmap);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.push(buffer_.inset());
|
|
|
|
|
d->cursor_.resetAnchor();
|
|
|
|
|
d->cursor_.setCurrentFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
2008-07-14 08:35:00 +00:00
|
|
|
|
thePreviews().generateBufferPreviews(buffer_);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView::~BufferView()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2007-08-22 09:06:13 +00:00
|
|
|
|
// current buffer is going to be switched-off, save cursor pos
|
|
|
|
|
// Ideally, the whole cursor stack should be saved, but session
|
|
|
|
|
// currently can only handle bottom (whole document) level pit and pos.
|
|
|
|
|
// That is to say, if a cursor is in a nested inset, it will be
|
|
|
|
|
// restore to the left of the top level inset.
|
2007-11-02 19:59:08 +00:00
|
|
|
|
LastFilePosSection::FilePos fp;
|
|
|
|
|
fp.pit = d->cursor_.bottom().pit();
|
|
|
|
|
fp.pos = d->cursor_.bottom().pos();
|
2008-07-14 08:35:00 +00:00
|
|
|
|
theSession().lastFilePos().save(buffer_.fileName(), fp);
|
2007-10-11 09:59:01 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
delete d;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-09 17:20:23 +00:00
|
|
|
|
int BufferView::rightMargin() const
|
|
|
|
|
{
|
2008-02-19 21:51:55 +00:00
|
|
|
|
// The additional test for the case the outliner is opened.
|
|
|
|
|
if (!full_screen_ ||
|
|
|
|
|
!lyxrc.full_screen_limit ||
|
|
|
|
|
width_ < lyxrc.full_screen_width + 20)
|
|
|
|
|
return 10;
|
2008-02-10 10:01:16 +00:00
|
|
|
|
|
2008-02-19 21:51:55 +00:00
|
|
|
|
return (width_ - lyxrc.full_screen_width) / 2;
|
2008-02-09 17:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int BufferView::leftMargin() const
|
|
|
|
|
{
|
2008-02-10 10:01:16 +00:00
|
|
|
|
return rightMargin();
|
2008-02-09 17:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-06 12:41:38 +00:00
|
|
|
|
bool BufferView::isTopScreen() const
|
|
|
|
|
{
|
|
|
|
|
return d->scrollbarParameters_.position == d->scrollbarParameters_.min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::isBottomScreen() const
|
|
|
|
|
{
|
|
|
|
|
return d->scrollbarParameters_.position == d->scrollbarParameters_.max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
|
Intl & BufferView::getIntl()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->intl_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intl const & BufferView::getIntl() const
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->intl_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CoordCache & BufferView::coordCache()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->coord_cache_;
|
2007-10-11 09:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CoordCache const & BufferView::coordCache() const
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->coord_cache_;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer & BufferView::buffer()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return buffer_;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-19 17:57:40 +00:00
|
|
|
|
|
2007-08-21 13:03:55 +00:00
|
|
|
|
Buffer const & BufferView::buffer() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return buffer_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool BufferView::fitCursor()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (cursorStatus(d->cursor_) == CUR_INSIDE) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
frontend::FontMetrics const & fm =
|
2007-10-28 18:51:54 +00:00
|
|
|
|
theFontMetrics(d->cursor_.getFont().fontInfo());
|
2006-10-07 16:15:06 +00:00
|
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
|
int const des = fm.maxDescent();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Point const p = getPos(d->cursor_, d->cursor_.boundary());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (p.y_ - asc >= 0 && p.y_ + des < height_)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-10 08:52:55 +00:00
|
|
|
|
void BufferView::processUpdateFlags(Update::flags flags)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-01-03 23:05:27 +00:00
|
|
|
|
// last_inset_ points to the last visited inset. This pointer may become
|
2007-01-04 19:59:58 +00:00
|
|
|
|
// invalid because of keyboard editing. Since all such operations
|
2007-01-03 23:05:27 +00:00
|
|
|
|
// causes screen update(), I reset last_inset_ to avoid such a problem.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->last_inset_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// This is close to a hot-path.
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::DEBUG, "BufferView::processUpdateFlags()"
|
2007-04-01 15:09:08 +00:00
|
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< "] buffer: " << &buffer_);
|
2006-10-21 10:56:36 +00:00
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
buffer_.updateMacros();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// Now do the first drawing step if needed. This consists on updating
|
|
|
|
|
// the CoordCache in updateMetrics().
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// The second drawing step is done in WorkArea::redraw() if needed.
|
|
|
|
|
|
2006-11-17 17:42:52 +00:00
|
|
|
|
// Case when no explicit update is requested.
|
2006-11-20 14:42:18 +00:00
|
|
|
|
if (!flags) {
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// no need to redraw anything.
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = NoScreenUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
|
return;
|
2006-11-17 17:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-20 01:23:07 +00:00
|
|
|
|
if (flags == Update::Decoration) {
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = DecorationUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
|
buffer_.changed();
|
|
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (flags == Update::FitCursor
|
2007-01-20 01:23:07 +00:00
|
|
|
|
|| flags == (Update::Decoration | Update::FitCursor)) {
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// tell the frontend to update the screen if needed.
|
2007-12-21 08:28:18 +00:00
|
|
|
|
if (fitCursor()) {
|
2007-12-21 08:35:43 +00:00
|
|
|
|
showCursor();
|
2007-10-10 08:52:55 +00:00
|
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
|
}
|
|
|
|
|
if (flags & Update::Decoration) {
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = DecorationUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
|
buffer_.changed();
|
|
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
|
}
|
|
|
|
|
// no screen update is needed.
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = NoScreenUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
|
return;
|
2006-11-21 16:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
|
bool const full_metrics = flags & Update::Force || !singleParUpdate();
|
2006-11-20 14:42:18 +00:00
|
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
|
if (full_metrics)
|
2007-11-06 08:32:25 +00:00
|
|
|
|
// We have to update the full screen metrics.
|
|
|
|
|
updateMetrics();
|
2006-11-17 17:42:52 +00:00
|
|
|
|
|
2007-10-10 08:52:55 +00:00
|
|
|
|
if (!(flags & Update::FitCursor)) {
|
2007-12-21 09:45:04 +00:00
|
|
|
|
// Nothing to do anymore. Trigger a redraw and return
|
2007-09-26 21:27:17 +00:00
|
|
|
|
buffer_.changed();
|
2007-10-10 08:52:55 +00:00
|
|
|
|
return;
|
2007-09-26 21:27:17 +00:00
|
|
|
|
}
|
2006-11-17 17:42:52 +00:00
|
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
|
// updateMetrics() does not update paragraph position
|
2007-10-10 08:52:55 +00:00
|
|
|
|
// This is done at draw() time. So we need a redraw!
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
|
2007-12-21 09:45:04 +00:00
|
|
|
|
if (fitCursor()) {
|
|
|
|
|
// The cursor is off screen so ensure it is visible.
|
|
|
|
|
// refresh it:
|
|
|
|
|
showCursor();
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateScrollbar()
|
|
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
|
if (height_ == 0 && width_ == 0)
|
2007-12-21 08:28:18 +00:00
|
|
|
|
return;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
|
// We prefer fixed size line scrolling.
|
|
|
|
|
d->scrollbarParameters_.single_step = defaultRowHeight();
|
|
|
|
|
// We prefer full screen page scrolling.
|
|
|
|
|
d->scrollbarParameters_.page_step = height_;
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
Text & t = buffer_.text();
|
|
|
|
|
TextMetrics & tm = d->text_metrics_[&t];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
|
LYXERR(Debug::GUI, " Updating scrollbar: height: "
|
|
|
|
|
<< t.paragraphs().size()
|
2007-10-13 07:33:07 +00:00
|
|
|
|
<< " curr par: " << d->cursor_.bottom().pit()
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< " default height " << defaultRowHeight());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2008-02-09 15:23:05 +00:00
|
|
|
|
size_t const parsize = t.paragraphs().size();
|
2007-12-21 08:28:18 +00:00
|
|
|
|
if (d->par_height_.size() != parsize) {
|
|
|
|
|
d->par_height_.clear();
|
2007-12-21 13:38:09 +00:00
|
|
|
|
// FIXME: We assume a default paragraph height of 2 rows. This
|
2007-12-21 08:28:18 +00:00
|
|
|
|
// should probably be pondered with the screen width.
|
2007-12-21 13:38:09 +00:00
|
|
|
|
d->par_height_.resize(parsize, defaultRowHeight() * 2);
|
2007-12-21 08:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Look at paragraph heights on-screen
|
2007-12-21 08:28:18 +00:00
|
|
|
|
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
|
|
|
|
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
|
|
|
|
for (pit_type pit = first.first; pit <= last.first; ++pit) {
|
2008-01-16 09:06:36 +00:00
|
|
|
|
d->par_height_[pit] = tm.parMetrics(pit).height();
|
|
|
|
|
LYXERR(Debug::SCROLLING, "storing height for pit " << pit << " : "
|
|
|
|
|
<< d->par_height_[pit]);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-10-26 08:10:22 +00:00
|
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
|
int top_pos = first.second->position() - first.second->ascent();
|
|
|
|
|
int bottom_pos = last.second->position() + last.second->descent();
|
|
|
|
|
bool first_visible = first.first == 0 && top_pos >= 0;
|
2008-02-09 15:23:05 +00:00
|
|
|
|
bool last_visible = last.first + 1 == int(parsize) && bottom_pos <= height_;
|
2008-01-17 17:06:55 +00:00
|
|
|
|
if (first_visible && last_visible) {
|
|
|
|
|
d->scrollbarParameters_.min = 0;
|
|
|
|
|
d->scrollbarParameters_.max = 0;
|
|
|
|
|
return;
|
2007-12-21 08:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 17:06:55 +00:00
|
|
|
|
d->scrollbarParameters_.min = top_pos;
|
2008-02-09 15:23:05 +00:00
|
|
|
|
for (size_t i = 0; i != size_t(first.first); ++i)
|
2008-01-17 17:06:55 +00:00
|
|
|
|
d->scrollbarParameters_.min -= d->par_height_[i];
|
|
|
|
|
d->scrollbarParameters_.max = bottom_pos;
|
|
|
|
|
for (size_t i = last.first + 1; i != parsize; ++i)
|
|
|
|
|
d->scrollbarParameters_.max += d->par_height_[i];
|
|
|
|
|
|
|
|
|
|
d->scrollbarParameters_.position = 0;
|
|
|
|
|
// The reference is the top position so we remove one page.
|
|
|
|
|
d->scrollbarParameters_.max -= d->scrollbarParameters_.page_step;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
ScrollbarParameters const & BufferView::scrollbarParameters() const
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->scrollbarParameters_;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
|
docstring BufferView::toolTip(int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
// Get inset under mouse, if there is one.
|
|
|
|
|
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
|
|
|
|
|
if (!covering_inset)
|
|
|
|
|
// No inset, no tooltip...
|
|
|
|
|
return docstring();
|
|
|
|
|
return covering_inset->toolTip(*this, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-26 12:40:58 +00:00
|
|
|
|
docstring BufferView::contextMenu(int x, int y) const
|
2007-12-25 20:12:07 +00:00
|
|
|
|
{
|
2008-08-14 09:45:42 +00:00
|
|
|
|
//If there is a selection, return the containing inset menu
|
|
|
|
|
if (d->cursor_.selection())
|
|
|
|
|
return d->cursor_.inset().contextMenu(*this, x, y);
|
|
|
|
|
|
2007-12-26 12:40:58 +00:00
|
|
|
|
// Get inset under mouse, if there is one.
|
|
|
|
|
Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
|
|
|
|
|
if (covering_inset)
|
|
|
|
|
return covering_inset->contextMenu(*this, x, y);
|
|
|
|
|
|
2008-03-08 22:57:22 +00:00
|
|
|
|
return buffer_.inset().contextMenu(*this, x, y);
|
2007-12-25 20:12:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
|
void BufferView::scrollDocView(int value)
|
2001-02-19 16:01:31 +00:00
|
|
|
|
{
|
2008-01-29 13:34:18 +00:00
|
|
|
|
int const offset = value - d->scrollbarParameters_.position;
|
|
|
|
|
// If the offset is less than 2 screen height, prefer to scroll instead.
|
|
|
|
|
if (abs(offset) <= 2 * height_) {
|
|
|
|
|
scroll(offset);
|
2008-07-04 11:33:28 +00:00
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2008-01-29 13:34:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 09:51:12 +00:00
|
|
|
|
// cut off at the top
|
|
|
|
|
if (value <= d->scrollbarParameters_.min) {
|
|
|
|
|
DocIterator dit = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
showCursor(dit);
|
|
|
|
|
LYXERR(Debug::SCROLLING, "scroll to top");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
|
// cut off at the bottom
|
2008-01-29 09:51:12 +00:00
|
|
|
|
if (value >= d->scrollbarParameters_.max) {
|
|
|
|
|
DocIterator dit = doc_iterator_end(buffer_.inset());
|
|
|
|
|
dit.backwardPos();
|
|
|
|
|
showCursor(dit);
|
|
|
|
|
LYXERR(Debug::SCROLLING, "scroll to bottom");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
|
// find paragraph at target position
|
2008-01-26 00:47:22 +00:00
|
|
|
|
int par_pos = d->scrollbarParameters_.min;
|
2008-01-29 10:17:41 +00:00
|
|
|
|
pit_type i = 0;
|
2008-02-09 15:23:05 +00:00
|
|
|
|
for (; i != int(d->par_height_.size()); ++i) {
|
2007-12-21 08:28:18 +00:00
|
|
|
|
par_pos += d->par_height_[i];
|
2008-01-29 10:17:41 +00:00
|
|
|
|
if (par_pos >= value)
|
2007-12-21 08:28:18 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
|
if (par_pos < value) {
|
|
|
|
|
// It seems we didn't find the correct pit so stay on the safe side and
|
|
|
|
|
// scroll to bottom.
|
|
|
|
|
LYXERR0("scrolling position not found!");
|
|
|
|
|
scrollDocView(d->scrollbarParameters_.max);
|
|
|
|
|
return;
|
2008-01-26 00:47:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-29 10:17:41 +00:00
|
|
|
|
DocIterator dit = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
dit.pit() = i;
|
|
|
|
|
LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
|
|
|
|
|
showCursor(dit);
|
2001-02-19 16:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
// FIXME: this method is not working well.
|
2006-08-16 15:24:38 +00:00
|
|
|
|
void BufferView::setCursorFromScrollbar()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[&buffer_.text()];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
int const height = 2 * defaultRowHeight();
|
|
|
|
|
int const first = height;
|
|
|
|
|
int const last = height_ - height;
|
2008-08-14 09:59:04 +00:00
|
|
|
|
int newy = 0;
|
|
|
|
|
Cursor const & oldcur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2008-08-14 09:59:04 +00:00
|
|
|
|
switch (cursorStatus(oldcur)) {
|
2007-09-29 08:02:37 +00:00
|
|
|
|
case CUR_ABOVE:
|
2008-08-14 09:59:04 +00:00
|
|
|
|
newy = first;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
|
case CUR_BELOW:
|
2008-08-14 09:59:04 +00:00
|
|
|
|
newy = last;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
|
case CUR_INSIDE:
|
2008-08-14 09:59:04 +00:00
|
|
|
|
int const y = getPos(oldcur, oldcur.boundary()).y_;
|
|
|
|
|
newy = min(last, max(y, first));
|
|
|
|
|
if (y == newy)
|
|
|
|
|
return;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2008-08-14 09:59:04 +00:00
|
|
|
|
// We reset the cursor because cursorStatus() does not
|
|
|
|
|
// work when the cursor is within mathed.
|
|
|
|
|
Cursor cur(*this);
|
|
|
|
|
cur.reset(buffer_.inset());
|
|
|
|
|
tm.setCursorFromCoordinates(cur, 0, newy);
|
|
|
|
|
mouseSetCursor(cur);
|
2006-08-16 15:24:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 20:01:32 +00:00
|
|
|
|
Change const BufferView::getCurrentChange() const
|
2003-02-08 19:18:01 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (!d->cursor_.selection())
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return Change(Change::UNCHANGED);
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
DocIterator dit = d->cursor_.selectionBegin();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return dit.paragraph().lookupChange(dit.pos());
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2007-09-29 08:02:37 +00:00
|
|
|
|
// this could be used elsewhere as well?
|
|
|
|
|
// FIXME: This does not work within mathed!
|
|
|
|
|
CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
|
|
|
|
|
{
|
2007-09-29 09:22:17 +00:00
|
|
|
|
Point const p = getPos(dit, dit.boundary());
|
2007-09-29 08:02:37 +00:00
|
|
|
|
if (p.y_ < 0)
|
|
|
|
|
return CUR_ABOVE;
|
|
|
|
|
if (p.y_ > workHeight())
|
|
|
|
|
return CUR_BELOW;
|
|
|
|
|
return CUR_INSIDE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-29 03:41:55 +00:00
|
|
|
|
void BufferView::saveBookmark(unsigned int idx)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// tenatively save bookmark, id and pos will be used to
|
|
|
|
|
// acturately locate a bookmark in a 'live' lyx session.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// pit and pos will be updated with bottom level pit/pos
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// when lyx exits.
|
2008-07-14 08:35:00 +00:00
|
|
|
|
theSession().bookmarks().save(
|
2007-11-03 17:37:37 +00:00
|
|
|
|
buffer_.fileName(),
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.bottom().pit(),
|
|
|
|
|
d->cursor_.bottom().pos(),
|
|
|
|
|
d->cursor_.paragraph().id(),
|
|
|
|
|
d->cursor_.pos(),
|
2007-03-29 03:41:55 +00:00
|
|
|
|
idx
|
2006-11-01 15:55:17 +00:00
|
|
|
|
);
|
2007-03-29 03:41:55 +00:00
|
|
|
|
if (idx)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// emit message signal.
|
2006-11-01 15:55:17 +00:00
|
|
|
|
message(_("Save bookmark"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-22 14:25:51 +00:00
|
|
|
|
bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
|
2007-04-16 19:01:32 +00:00
|
|
|
|
int top_id, pos_type top_pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-22 14:25:51 +00:00
|
|
|
|
bool success = false;
|
2008-02-09 15:23:05 +00:00
|
|
|
|
DocIterator dit;
|
2007-08-22 14:25:51 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.clearSelection();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-01-11 16:01:10 +00:00
|
|
|
|
// if a valid par_id is given, try it first
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// This is the case for a 'live' bookmark when unique paragraph ID
|
|
|
|
|
// is used to track bookmarks.
|
|
|
|
|
if (top_id > 0) {
|
2008-02-09 15:23:05 +00:00
|
|
|
|
dit = buffer_.getParFromID(top_id);
|
|
|
|
|
if (!dit.atEnd()) {
|
|
|
|
|
dit.pos() = min(dit.paragraph().size(), top_pos);
|
2007-05-10 07:53:00 +00:00
|
|
|
|
// Some slices of the iterator may not be
|
|
|
|
|
// reachable (e.g. closed collapsable inset)
|
|
|
|
|
// so the dociterator may need to be
|
|
|
|
|
// shortened. Otherwise, setCursor may crash
|
|
|
|
|
// lyx when the cursor can not be set to these
|
|
|
|
|
// insets.
|
2008-02-09 15:23:05 +00:00
|
|
|
|
size_t const n = dit.depth();
|
2007-04-16 20:47:40 +00:00
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2008-02-09 15:23:05 +00:00
|
|
|
|
if (dit[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
|
|
|
|
|
dit.resize(i);
|
2007-04-16 20:47:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-22 14:38:25 +00:00
|
|
|
|
success = true;
|
2007-01-11 16:01:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-22 14:25:51 +00:00
|
|
|
|
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// if top_id == 0, or searching through top_id failed
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// This is the case for a 'restored' bookmark when only bottom
|
2007-04-16 19:01:32 +00:00
|
|
|
|
// (document level) pit was saved. Because of this, bookmark
|
|
|
|
|
// restoration is inaccurate. If a bookmark was within an inset,
|
|
|
|
|
// it will be restored to the left of the outmost inset that contains
|
|
|
|
|
// the bookmark.
|
2008-02-09 15:23:05 +00:00
|
|
|
|
if (bottom_pit < int(buffer_.paragraphs().size())) {
|
|
|
|
|
dit = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
|
|
|
|
|
dit.pit() = bottom_pit;
|
|
|
|
|
dit.pos() = min(bottom_pos, dit.paragraph().size());
|
2007-08-22 14:25:51 +00:00
|
|
|
|
success = true;
|
2007-01-11 16:01:10 +00:00
|
|
|
|
}
|
2007-08-22 14:25:51 +00:00
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
// Note: only bottom (document) level pit is set.
|
2008-02-09 15:23:05 +00:00
|
|
|
|
setCursor(dit);
|
2007-08-22 14:25:51 +00:00
|
|
|
|
// set the current font.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setCurrentFont();
|
2007-11-19 10:04:14 +00:00
|
|
|
|
// To center the screen on this new position we need the
|
|
|
|
|
// paragraph position which is computed at draw() time.
|
|
|
|
|
// So we need a redraw!
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
if (fitCursor())
|
2007-12-21 08:35:43 +00:00
|
|
|
|
showCursor();
|
2007-08-22 14:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
2000-06-05 15:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-11 22:05:44 +00:00
|
|
|
|
void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur)
|
2000-02-04 09:38:32 +00:00
|
|
|
|
{
|
2007-06-13 06:27:33 +00:00
|
|
|
|
if (lyxrc.rtl_support) {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->cursor_.real_current_font.isRightToLeft()) {
|
|
|
|
|
if (d->intl_.keymap == Intl::PRIMARY)
|
|
|
|
|
d->intl_.keyMapSec();
|
2007-06-13 06:27:33 +00:00
|
|
|
|
} else {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->intl_.keymap == Intl::SECONDARY)
|
|
|
|
|
d->intl_.keyMapPrim();
|
2007-06-13 06:27:33 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-09-16 10:38:25 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->intl_.getTransManager().translateAndInsert(c, t, cur);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
}
|
2000-01-07 03:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int BufferView::workWidth() const
|
2000-02-25 12:06:15 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return width_;
|
2000-02-23 16:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 08:35:43 +00:00
|
|
|
|
void BufferView::showCursor()
|
2008-01-29 09:51:12 +00:00
|
|
|
|
{
|
|
|
|
|
showCursor(d->cursor_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::showCursor(DocIterator const & dit)
|
2000-02-17 19:59:08 +00:00
|
|
|
|
{
|
2007-08-22 14:44:34 +00:00
|
|
|
|
// We are not properly started yet, delay until resizing is
|
|
|
|
|
// done.
|
2007-08-22 14:14:52 +00:00
|
|
|
|
if (height_ == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
LYXERR(Debug::SCROLLING, "recentering!");
|
2007-12-19 07:47:03 +00:00
|
|
|
|
|
2008-01-29 09:51:12 +00:00
|
|
|
|
CursorSlice const & bot = dit.bottom();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[bot.text()];
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
2007-12-22 09:04:53 +00:00
|
|
|
|
pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1);
|
2008-01-29 09:51:12 +00:00
|
|
|
|
int bot_pit = bot.pit();
|
2007-12-22 09:04:53 +00:00
|
|
|
|
if (bot_pit > max_pit) {
|
|
|
|
|
// FIXME: Why does this happen?
|
|
|
|
|
LYXERR0("bottom pit is greater that max pit: "
|
|
|
|
|
<< bot_pit << " > " << max_pit);
|
|
|
|
|
bot_pit = max_pit;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
if (bot_pit == tm.first().first - 1)
|
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
|
else if (bot_pit == tm.last().first + 1)
|
|
|
|
|
tm.newParMetricsDown();
|
|
|
|
|
|
2008-02-27 23:03:26 +00:00
|
|
|
|
if (tm.contains(bot_pit)) {
|
2007-12-21 08:28:18 +00:00
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(!pm.rows().empty(), /**/);
|
2008-01-29 09:51:12 +00:00
|
|
|
|
// FIXME: smooth scrolling doesn't work in mathed.
|
|
|
|
|
CursorSlice const & cs = dit.innerTextSlice();
|
|
|
|
|
int offset = coordOffset(dit, dit.boundary()).y_;
|
2007-12-21 08:28:18 +00:00
|
|
|
|
int ypos = pm.position() + offset;
|
2008-01-29 09:51:12 +00:00
|
|
|
|
Dimension const & row_dim =
|
|
|
|
|
pm.getRow(cs.pos(), dit.boundary()).dimension();
|
2008-07-04 11:33:28 +00:00
|
|
|
|
int scrolled = 0;
|
2007-12-21 08:28:18 +00:00
|
|
|
|
if (ypos - row_dim.ascent() < 0)
|
2008-07-04 11:33:28 +00:00
|
|
|
|
scrolled = scrollUp(- ypos + row_dim.ascent());
|
2007-12-21 08:28:18 +00:00
|
|
|
|
else if (ypos + row_dim.descent() > height_)
|
2008-07-04 11:33:28 +00:00
|
|
|
|
scrolled = scrollDown(ypos - height_ + row_dim.descent());
|
2007-12-21 08:28:18 +00:00
|
|
|
|
// else, nothing to do, the cursor is already visible so we just return.
|
2008-07-04 11:33:28 +00:00
|
|
|
|
if (scrolled != 0) {
|
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
|
return;
|
2007-12-19 07:47:03 +00:00
|
|
|
|
}
|
2007-08-22 14:14:52 +00:00
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
// fix inline completion position
|
2008-04-16 20:43:30 +00:00
|
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
tm.redoParagraph(bot_pit);
|
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
|
2008-01-29 09:51:12 +00:00
|
|
|
|
int offset = coordOffset(dit, dit.boundary()).y_;
|
2007-08-22 14:14:52 +00:00
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
d->anchor_pit_ = bot_pit;
|
2008-01-29 09:51:12 +00:00
|
|
|
|
CursorSlice const & cs = dit.innerTextSlice();
|
|
|
|
|
Dimension const & row_dim =
|
|
|
|
|
pm.getRow(cs.pos(), dit.boundary()).dimension();
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
|
|
if (d->anchor_pit_ == 0)
|
|
|
|
|
d->anchor_ypos_ = offset + pm.ascent();
|
2007-12-22 09:04:53 +00:00
|
|
|
|
else if (d->anchor_pit_ == max_pit)
|
2007-12-21 10:11:32 +00:00
|
|
|
|
d->anchor_ypos_ = height_ - offset - row_dim.descent();
|
2007-12-22 09:04:53 +00:00
|
|
|
|
else
|
2008-01-08 15:49:03 +00:00
|
|
|
|
d->anchor_ypos_ = defaultRowHeight() * 2 - offset - row_dim.descent();
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2000-02-17 19:59:08 +00:00
|
|
|
|
}
|
2000-05-20 01:38:25 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
FuncStatus BufferView::getStatus(FuncRequest const & cmd)
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
FuncStatus flag;
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor & cur = d->cursor_;
|
2007-06-10 15:07:21 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(buffer_.undo().hasUndoStack());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(buffer_.undo().hasRedoStack());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// FIXME: Actually, these LFUNS should be moved to Text
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(cur.inTexted());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_FONT_STATE:
|
|
|
|
|
case LFUN_LABEL_INSERT:
|
2007-10-11 14:52:00 +00:00
|
|
|
|
case LFUN_INFO_INSERT:
|
2008-04-27 16:20:12 +00:00
|
|
|
|
case LFUN_INSET_EDIT:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_PARAGRAPH_GOTO:
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
|
|
|
|
case LFUN_REFERENCE_NEXT:
|
|
|
|
|
case LFUN_WORD_FIND:
|
2007-06-19 21:48:04 +00:00
|
|
|
|
case LFUN_WORD_REPLACE:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
|
case LFUN_MARK_TOGGLE:
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD:
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL:
|
2008-06-24 07:18:06 +00:00
|
|
|
|
case LFUN_NOTES_MUTATE:
|
2008-06-24 07:52:49 +00:00
|
|
|
|
case LFUN_ALL_INSETS_TOGGLE:
|
2008-01-08 15:18:00 +00:00
|
|
|
|
case LFUN_STATISTICS:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2008-04-30 13:03:19 +00:00
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE:
|
2008-03-24 13:33:48 +00:00
|
|
|
|
case LFUN_NEXT_INSET_MODIFY: {
|
|
|
|
|
// this is the real function we want to invoke
|
2008-05-13 14:44:53 +00:00
|
|
|
|
FuncRequest tmpcmd = cmd;
|
|
|
|
|
tmpcmd.action = (cmd.action == LFUN_NEXT_INSET_TOGGLE)
|
2008-04-30 13:03:19 +00:00
|
|
|
|
? LFUN_INSET_TOGGLE : LFUN_INSET_MODIFY;
|
2008-03-24 13:33:48 +00:00
|
|
|
|
// if there is an inset at cursor, see whether it
|
2008-04-30 13:03:19 +00:00
|
|
|
|
// handles the lfun, other start from scratch
|
2008-03-24 13:33:48 +00:00
|
|
|
|
Inset * inset = cur.nextInset();
|
2008-04-30 13:03:19 +00:00
|
|
|
|
if (!inset || !inset->getStatus(cur, tmpcmd, flag))
|
|
|
|
|
flag = lyx::getStatus(tmpcmd);
|
2008-03-24 13:33:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_LABEL_GOTO: {
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(!cmd.argument().empty()
|
2007-10-13 09:04:52 +00:00
|
|
|
|
|| getInsetByCode<InsetRef>(cur, REF_CODE));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.setOnOff(buffer_.params().trackChanges);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-03-15 18:10:16 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.setOnOff(buffer_.params().outputChanges);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_MERGE:
|
2006-10-04 21:43:40 +00:00
|
|
|
|
case LFUN_CHANGE_NEXT:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT:
|
|
|
|
|
case LFUN_ALL_CHANGES_REJECT:
|
2006-11-24 23:01:24 +00:00
|
|
|
|
// TODO: context-sensitive enabling of LFUNs
|
|
|
|
|
// In principle, these command should only be enabled if there
|
|
|
|
|
// is a change in the document. However, without proper
|
|
|
|
|
// optimizations, this will inevitably result in poor performance.
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION: {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.setOnOff(buffer_.params().compressed);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-10-21 20:06:44 +00:00
|
|
|
|
|
2007-09-15 12:28:41 +00:00
|
|
|
|
case LFUN_SCREEN_UP:
|
|
|
|
|
case LFUN_SCREEN_DOWN:
|
2007-12-27 11:37:07 +00:00
|
|
|
|
case LFUN_SCROLL:
|
2007-09-15 12:28:41 +00:00
|
|
|
|
case LFUN_SCREEN_UP_SELECT:
|
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2007-09-15 12:28:41 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-10-11 13:20:21 +00:00
|
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(cur.innerInsetOfType(TABULAR_CODE));
|
2007-10-11 13:20:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LAYOUT:
|
2008-07-10 17:41:52 +00:00
|
|
|
|
flag.setEnabled(!cur.inset().forcePlainLayout(cur.idx()));
|
2008-03-19 16:21:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-10-11 13:20:21 +00:00
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(cur.inset().allowParagraphCustomization(cur.idx()));
|
2007-10-11 13:20:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_SETTINGS: {
|
2007-10-13 09:04:52 +00:00
|
|
|
|
InsetCode code = cur.inset().lyxCode();
|
2008-05-05 15:34:10 +00:00
|
|
|
|
if (cmd.getArg(0) == insetName(code)) {
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(true);
|
2008-05-05 15:34:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-10-11 13:20:21 +00:00
|
|
|
|
bool enable = false;
|
2008-05-05 15:34:10 +00:00
|
|
|
|
InsetCode next_code = cur.nextInset()
|
|
|
|
|
? cur.nextInset()->lyxCode() : NO_CODE;
|
2008-06-05 15:08:46 +00:00
|
|
|
|
//FIXME: remove these special cases:
|
2008-05-05 15:34:10 +00:00
|
|
|
|
switch (next_code) {
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case TABULAR_CODE:
|
|
|
|
|
case ERT_CODE:
|
|
|
|
|
case FLOAT_CODE:
|
|
|
|
|
case WRAP_CODE:
|
|
|
|
|
case NOTE_CODE:
|
|
|
|
|
case BRANCH_CODE:
|
|
|
|
|
case BOX_CODE:
|
|
|
|
|
case LISTINGS_CODE:
|
2008-03-24 16:33:56 +00:00
|
|
|
|
enable = (cmd.argument().empty() ||
|
2008-05-05 15:34:10 +00:00
|
|
|
|
cmd.getArg(0) == insetName(next_code));
|
2007-10-11 13:20:21 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(enable);
|
2007-10-11 13:20:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(cur.inset().lyxCode() != ERT_CODE &&
|
2007-10-13 09:04:52 +00:00
|
|
|
|
cur.inset().lyxCode() != LISTINGS_CODE);
|
|
|
|
|
if (cur.inset().lyxCode() == CAPTION_CODE) {
|
2007-10-11 13:20:21 +00:00
|
|
|
|
FuncStatus flag;
|
|
|
|
|
if (cur.inset().getStatus(cur, cmd, flag))
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2008-05-28 16:02:09 +00:00
|
|
|
|
case LFUN_BRANCH_ACTIVATE:
|
|
|
|
|
case LFUN_BRANCH_DEACTIVATE: {
|
|
|
|
|
bool enable = false;
|
|
|
|
|
docstring const branchName = cmd.argument();
|
|
|
|
|
if (!branchName.empty())
|
|
|
|
|
enable = buffer_.params().branchlist().find(branchName);
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(enable);
|
2008-05-28 16:02:09 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
default:
|
2008-05-29 15:14:00 +00:00
|
|
|
|
flag.setEnabled(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
2004-04-01 08:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 10:42:59 +00:00
|
|
|
|
bool BufferView::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2007-11-30 08:35:54 +00:00
|
|
|
|
//lyxerr << [ cmd = " << cmd << "]" << endl;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Make sure that the cached BufferView is correct.
|
2007-11-30 08:35:54 +00:00
|
|
|
|
LYXERR(Debug::ACTION, " action[" << cmd.action << ']'
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< " arg[" << to_utf8(cmd.argument()) << ']'
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< " x[" << cmd.x << ']'
|
|
|
|
|
<< " y[" << cmd.y << ']'
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< " button[" << cmd.button() << ']');
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor & cur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("Undo"));
|
|
|
|
|
cur.clearSelection();
|
2007-12-21 10:42:59 +00:00
|
|
|
|
if (!cur.textUndo())
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("No further undo information"));
|
2007-12-26 14:10:24 +00:00
|
|
|
|
else
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REDO:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("Redo"));
|
|
|
|
|
cur.clearSelection();
|
2007-12-21 10:42:59 +00:00
|
|
|
|
if (!cur.textRedo())
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("No further redo information"));
|
2007-12-26 14:10:24 +00:00
|
|
|
|
else
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FONT_STATE:
|
2006-12-21 13:58:28 +00:00
|
|
|
|
cur.message(cur.currentState());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BOOKMARK_SAVE:
|
2006-11-01 15:55:17 +00:00
|
|
|
|
saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LABEL_GOTO: {
|
2006-10-12 10:50:45 +00:00
|
|
|
|
docstring label = cmd.argument();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (label.empty()) {
|
|
|
|
|
InsetRef * inset =
|
2007-10-13 07:33:07 +00:00
|
|
|
|
getInsetByCode<InsetRef>(d->cursor_,
|
2007-10-13 09:04:52 +00:00
|
|
|
|
REF_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset) {
|
2006-10-20 16:12:49 +00:00
|
|
|
|
label = inset->getParam("reference");
|
2006-11-01 15:55:17 +00:00
|
|
|
|
// persistent=false: use temp_bookmark
|
2007-03-29 03:41:55 +00:00
|
|
|
|
saveBookmark(0);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!label.empty())
|
|
|
|
|
gotoLabel(label);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-03-24 04:27:43 +00:00
|
|
|
|
|
2008-04-27 16:20:12 +00:00
|
|
|
|
case LFUN_INSET_EDIT: {
|
2008-03-24 04:27:43 +00:00
|
|
|
|
FuncRequest fr(cmd);
|
2008-04-27 16:20:12 +00:00
|
|
|
|
// if there is an inset at cursor, see whether it
|
|
|
|
|
// can be modified.
|
|
|
|
|
Inset * inset = cur.nextInset();
|
2008-03-24 04:27:43 +00:00
|
|
|
|
if (inset)
|
2008-04-27 16:20:12 +00:00
|
|
|
|
inset->dispatch(cur, fr);
|
|
|
|
|
// if it did not work, try the underlying inset.
|
|
|
|
|
if (!inset || !cur.result().dispatched())
|
|
|
|
|
cur.dispatch(cmd);
|
2008-03-24 04:27:43 +00:00
|
|
|
|
|
2008-07-19 16:03:04 +00:00
|
|
|
|
// FIXME I'm adding the last break to solve a crash,
|
|
|
|
|
// but that is obviously not right.
|
2008-04-27 16:20:12 +00:00
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
// It did not work too; no action needed.
|
|
|
|
|
break;
|
2008-07-19 16:03:04 +00:00
|
|
|
|
break;
|
2008-03-24 04:27:43 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_PARAGRAPH_GOTO: {
|
2008-05-16 12:48:13 +00:00
|
|
|
|
int const id = convert<int>(cmd.getArg(0));
|
|
|
|
|
int const pos = convert<int>(cmd.getArg(1));
|
2006-11-13 16:53:49 +00:00
|
|
|
|
int i = 0;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
for (Buffer * b = &buffer_; i == 0 || b != &buffer_;
|
|
|
|
|
b = theBufferList().next(b)) {
|
|
|
|
|
|
2008-02-09 15:23:05 +00:00
|
|
|
|
DocIterator dit = b->getParFromID(id);
|
|
|
|
|
if (dit.atEnd()) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::INFO, "No matching paragraph found! [" << id << "].");
|
2008-02-12 08:04:59 +00:00
|
|
|
|
++i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
LYXERR(Debug::INFO, "Paragraph " << dit.paragraph().id()
|
|
|
|
|
<< " found in buffer `"
|
|
|
|
|
<< b->absFileName() << "'.");
|
|
|
|
|
|
|
|
|
|
if (b == &buffer_) {
|
|
|
|
|
// Set the cursor
|
2008-05-16 12:48:13 +00:00
|
|
|
|
dit.pos() = pos;
|
2008-02-12 08:04:59 +00:00
|
|
|
|
setCursor(dit);
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2006-11-13 16:53:49 +00:00
|
|
|
|
} else {
|
2008-02-12 08:04:59 +00:00
|
|
|
|
// Switch to other buffer view and resend cmd
|
|
|
|
|
theLyXFunc().dispatch(FuncRequest(
|
|
|
|
|
LFUN_BUFFER_SWITCH, b->absFileName()));
|
|
|
|
|
theLyXFunc().dispatch(cmd);
|
2006-11-13 16:53:49 +00:00
|
|
|
|
}
|
2008-02-12 08:04:59 +00:00
|
|
|
|
break;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_NOTE_NEXT:
|
2007-10-13 09:04:52 +00:00
|
|
|
|
gotoInset(this, NOTE_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_REFERENCE_NEXT: {
|
2007-10-13 09:04:52 +00:00
|
|
|
|
vector<InsetCode> tmp;
|
|
|
|
|
tmp.push_back(LABEL_CODE);
|
|
|
|
|
tmp.push_back(REF_CODE);
|
2007-09-29 07:34:42 +00:00
|
|
|
|
gotoInset(this, tmp, true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_CHANGES_TRACK:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.params().trackChanges = !buffer_.params().trackChanges;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
case LFUN_CHANGES_OUTPUT:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.params().outputChanges = !buffer_.params().outputChanges;
|
|
|
|
|
if (buffer_.params().outputChanges) {
|
2007-05-13 15:17:57 +00:00
|
|
|
|
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
|
|
|
|
|
bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
|
2007-05-28 22:27:45 +00:00
|
|
|
|
LaTeXFeatures::isAvailable("xcolor");
|
|
|
|
|
|
2007-05-13 15:17:57 +00:00
|
|
|
|
if (!dvipost && !xcolorsoul) {
|
2007-05-08 17:46:03 +00:00
|
|
|
|
Alert::warning(_("Changes not shown in LaTeX output"),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
_("Changes will not be highlighted in LaTeX output, "
|
|
|
|
|
"because neither dvipost nor xcolor/soul are installed.\n"
|
|
|
|
|
"Please install these packages or redefine "
|
|
|
|
|
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
|
2007-05-13 15:17:57 +00:00
|
|
|
|
} else if (!xcolorsoul) {
|
2007-05-08 17:46:03 +00:00
|
|
|
|
Alert::warning(_("Changes not shown in LaTeX output"),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
_("Changes will not be highlighted in LaTeX output "
|
|
|
|
|
"when using pdflatex, because xcolor and soul are not installed.\n"
|
|
|
|
|
"Please install both packages or redefine "
|
|
|
|
|
"\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
|
2007-05-08 17:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-10-04 21:43:40 +00:00
|
|
|
|
case LFUN_CHANGE_NEXT:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
findNextChange(this);
|
2006-10-04 21:43:40 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_CHANGES_MERGE:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (findNextChange(this))
|
2006-09-19 13:36:20 +00:00
|
|
|
|
showDialog("changes");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-02-01 13:19:05 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_ACCEPT:
|
|
|
|
|
// select complete document
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.reset(buffer_.inset());
|
|
|
|
|
d->cursor_.selHandle(true);
|
|
|
|
|
buffer_.text().cursorBottom(d->cursor_);
|
2007-02-01 13:19:05 +00:00
|
|
|
|
// accept everything in a single step to support atomic undo
|
2007-10-13 07:33:07 +00:00
|
|
|
|
buffer_.text().acceptOrRejectChanges(d->cursor_, Text::ACCEPT);
|
2008-07-11 09:03:09 +00:00
|
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-02-01 13:19:05 +00:00
|
|
|
|
case LFUN_ALL_CHANGES_REJECT:
|
|
|
|
|
// select complete document
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.reset(buffer_.inset());
|
|
|
|
|
d->cursor_.selHandle(true);
|
|
|
|
|
buffer_.text().cursorBottom(d->cursor_);
|
2007-02-01 13:19:05 +00:00
|
|
|
|
// reject everything in a single step to support atomic undo
|
|
|
|
|
// Note: reject does not work recursively; the user may have to repeat the operation
|
2007-10-13 07:33:07 +00:00
|
|
|
|
buffer_.text().acceptOrRejectChanges(d->cursor_, Text::REJECT);
|
2008-07-11 09:03:09 +00:00
|
|
|
|
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2008-03-26 19:20:17 +00:00
|
|
|
|
case LFUN_WORD_FIND: {
|
|
|
|
|
FuncRequest req = cmd;
|
|
|
|
|
if (cmd.argument().empty() && !d->search_request_cache_.argument().empty())
|
|
|
|
|
req = d->search_request_cache_;
|
2008-09-26 10:07:10 +00:00
|
|
|
|
if (req.argument().empty()) {
|
|
|
|
|
theLyXFunc().dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-03-26 19:20:17 +00:00
|
|
|
|
if (find(this, req))
|
2008-02-10 18:52:32 +00:00
|
|
|
|
showCursor();
|
|
|
|
|
else
|
|
|
|
|
message(_("String not found!"));
|
2008-03-26 19:20:17 +00:00
|
|
|
|
d->search_request_cache_ = req;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2008-03-26 19:20:17 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-06-19 21:48:04 +00:00
|
|
|
|
case LFUN_WORD_REPLACE: {
|
|
|
|
|
bool has_deleted = false;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
DocIterator beg = cur.selectionBegin();
|
|
|
|
|
DocIterator end = cur.selectionEnd();
|
|
|
|
|
if (beg.pit() == end.pit()) {
|
|
|
|
|
for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
|
|
|
|
|
if (cur.paragraph().isDeleted(p))
|
|
|
|
|
has_deleted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
replace(this, cmd, has_deleted);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2007-06-19 21:48:04 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MARK_OFF:
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
cur.resetAnchor();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark off")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_ON:
|
|
|
|
|
cur.clearSelection();
|
2008-09-24 21:27:41 +00:00
|
|
|
|
cur.setMark(true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cur.resetAnchor();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark on")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_MARK_TOGGLE:
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
if (cur.mark()) {
|
2008-09-24 21:27:41 +00:00
|
|
|
|
cur.setMark(false);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark removed")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
} else {
|
2008-09-24 21:27:41 +00:00
|
|
|
|
cur.setMark(true);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cur.message(from_utf8(N_("Mark set")));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_SCREEN_RECENTER:
|
2007-12-21 08:35:43 +00:00
|
|
|
|
showCursor();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_ADD: {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor tmpcur = d->cursor_;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
findInset(tmpcur, BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-10-13 09:04:52 +00:00
|
|
|
|
BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset) {
|
2008-03-29 14:49:13 +00:00
|
|
|
|
if (inset->addDatabase(cmd.argument()))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.updateBibfilesCache();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_BIBTEX_DATABASE_DEL: {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor tmpcur = d->cursor_;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
findInset(tmpcur, BIBTEX_CODE, false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
|
2007-10-13 09:04:52 +00:00
|
|
|
|
BIBTEX_CODE);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (inset) {
|
2008-03-29 14:49:13 +00:00
|
|
|
|
if (inset->delDatabase(cmd.argument()))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.updateBibfilesCache();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-08 15:18:00 +00:00
|
|
|
|
case LFUN_STATISTICS: {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
DocIterator from, to;
|
|
|
|
|
if (cur.selection()) {
|
|
|
|
|
from = cur.selectionBegin();
|
|
|
|
|
to = cur.selectionEnd();
|
|
|
|
|
} else {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
from = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
to = doc_iterator_end(buffer_.inset());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2008-01-08 15:18:00 +00:00
|
|
|
|
int const words = countWords(from, to);
|
|
|
|
|
int const chars = countChars(from, to, false);
|
|
|
|
|
int const chars_blanks = countChars(from, to, true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
docstring message;
|
2008-01-08 15:18:00 +00:00
|
|
|
|
if (cur.selection())
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message = _("Statistics for the selection:");
|
2008-01-08 15:18:00 +00:00
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message = _("Statistics for the document:");
|
|
|
|
|
message += "\n\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
|
if (words != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += bformat(_("%1$d words"), words);
|
2008-01-08 15:18:00 +00:00
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += _("One word");
|
|
|
|
|
message += "\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
|
if (chars_blanks != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += bformat(_("%1$d characters (including blanks)"),
|
2008-01-08 15:18:00 +00:00
|
|
|
|
chars_blanks);
|
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += _("One character (including blanks)");
|
|
|
|
|
message += "\n";
|
2008-01-08 15:18:00 +00:00
|
|
|
|
if (chars != 1)
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += bformat(_("%1$d characters (excluding blanks)"),
|
2008-01-08 15:18:00 +00:00
|
|
|
|
chars);
|
|
|
|
|
else
|
2008-01-18 22:50:19 +00:00
|
|
|
|
message += _("One character (excluding blanks)");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2008-01-08 15:18:00 +00:00
|
|
|
|
Alert::information(_("Statistics"), message);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFER_TOGGLE_COMPRESSION:
|
|
|
|
|
// turn compression on/off
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.params().compressed = !buffer_.params().compressed;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
2007-10-21 20:06:44 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE: {
|
2008-05-13 14:44:53 +00:00
|
|
|
|
// create the the real function we want to invoke
|
|
|
|
|
FuncRequest tmpcmd = cmd;
|
|
|
|
|
tmpcmd.action = LFUN_INSET_TOGGLE;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// if there is an inset at cursor, see whether it
|
|
|
|
|
// wants to toggle.
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * inset = cur.nextInset();
|
2007-09-10 16:06:01 +00:00
|
|
|
|
if (inset) {
|
|
|
|
|
if (inset->isActive()) {
|
|
|
|
|
Cursor tmpcur = cur;
|
2007-11-05 19:41:16 +00:00
|
|
|
|
tmpcur.pushBackward(*inset);
|
2007-09-10 16:06:01 +00:00
|
|
|
|
inset->dispatch(tmpcur, tmpcmd);
|
2008-05-13 14:44:53 +00:00
|
|
|
|
if (tmpcur.result().dispatched())
|
2007-09-10 16:06:01 +00:00
|
|
|
|
cur.dispatched();
|
2008-05-13 14:44:53 +00:00
|
|
|
|
} else
|
|
|
|
|
inset->dispatch(cur, tmpcmd);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
// if it did not work, try the underlying inset.
|
2008-03-24 18:22:54 +00:00
|
|
|
|
if (!inset || !cur.result().dispatched())
|
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
|
|
|
|
|
|
if (!cur.result().dispatched())
|
2007-12-27 09:44:39 +00:00
|
|
|
|
// It did not work too; no action needed.
|
|
|
|
|
break;
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
processUpdateFlags(Update::SinglePar | Update::FitCursor);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-24 13:33:48 +00:00
|
|
|
|
case LFUN_NEXT_INSET_MODIFY: {
|
2008-05-13 14:44:53 +00:00
|
|
|
|
// create the the real function we want to invoke
|
|
|
|
|
FuncRequest tmpcmd = cmd;
|
|
|
|
|
tmpcmd.action = LFUN_INSET_MODIFY;
|
2008-03-24 13:33:48 +00:00
|
|
|
|
// if there is an inset at cursor, see whether it
|
|
|
|
|
// can be modified.
|
|
|
|
|
Inset * inset = cur.nextInset();
|
|
|
|
|
if (inset)
|
|
|
|
|
inset->dispatch(cur, tmpcmd);
|
|
|
|
|
// if it did not work, try the underlying inset.
|
2008-03-24 18:22:54 +00:00
|
|
|
|
if (!inset || !cur.result().dispatched())
|
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
|
|
|
|
|
|
if (!cur.result().dispatched())
|
2008-03-24 13:33:48 +00:00
|
|
|
|
// It did not work too; no action needed.
|
|
|
|
|
break;
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-15 12:28:41 +00:00
|
|
|
|
case LFUN_SCREEN_UP:
|
|
|
|
|
case LFUN_SCREEN_DOWN: {
|
2007-09-29 09:22:17 +00:00
|
|
|
|
Point p = getPos(cur, cur.boundary());
|
2007-09-15 14:33:37 +00:00
|
|
|
|
if (p.y_ < 0 || p.y_ > height_) {
|
|
|
|
|
// The cursor is off-screen so recenter before proceeding.
|
2007-12-21 08:35:43 +00:00
|
|
|
|
showCursor();
|
2007-09-29 09:22:17 +00:00
|
|
|
|
p = getPos(cur, cur.boundary());
|
2007-09-15 14:33:37 +00:00
|
|
|
|
}
|
2008-07-04 11:33:28 +00:00
|
|
|
|
int const scrolled = scroll(cmd.action == LFUN_SCREEN_UP
|
|
|
|
|
? - height_ : height_);
|
|
|
|
|
if (cmd.action == LFUN_SCREEN_UP && scrolled > - height_)
|
|
|
|
|
p = Point(0, 0);
|
|
|
|
|
if (cmd.action == LFUN_SCREEN_DOWN && scrolled < height_)
|
|
|
|
|
p = Point(width_, height_);
|
2007-09-15 12:28:41 +00:00
|
|
|
|
cur.reset(buffer_.inset());
|
2008-07-04 11:33:28 +00:00
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
|
2007-09-15 12:28:41 +00:00
|
|
|
|
//FIXME: what to do with cur.x_target()?
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.finishUndo();
|
2007-09-15 12:28:41 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-27 11:37:07 +00:00
|
|
|
|
case LFUN_SCROLL:
|
|
|
|
|
lfunScroll(cmd);
|
|
|
|
|
break;
|
|
|
|
|
|
2008-03-06 15:39:30 +00:00
|
|
|
|
case LFUN_SCREEN_UP_SELECT: {
|
2007-09-15 12:28:41 +00:00
|
|
|
|
cur.selHandle(true);
|
2008-03-06 15:39:30 +00:00
|
|
|
|
if (isTopScreen()) {
|
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN_SELECT));
|
|
|
|
|
cur.finishUndo();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
int y = getPos(cur, cur.boundary()).y_;
|
|
|
|
|
int const ymin = y - height_ + defaultRowHeight();
|
|
|
|
|
while (y > ymin && cur.up())
|
|
|
|
|
y = getPos(cur, cur.boundary()).y_;
|
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.finishUndo();
|
2008-03-06 15:39:30 +00:00
|
|
|
|
processUpdateFlags(Update::SinglePar | Update::FitCursor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT: {
|
|
|
|
|
cur.selHandle(true);
|
|
|
|
|
if (isBottomScreen()) {
|
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
|
|
|
|
|
cur.finishUndo();
|
|
|
|
|
break;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
}
|
2008-03-06 15:39:30 +00:00
|
|
|
|
int y = getPos(cur, cur.boundary()).y_;
|
|
|
|
|
int const ymax = y + height_ - defaultRowHeight();
|
|
|
|
|
while (y < ymax && cur.down())
|
|
|
|
|
y = getPos(cur, cur.boundary()).y_;
|
|
|
|
|
|
|
|
|
|
cur.finishUndo();
|
|
|
|
|
processUpdateFlags(Update::SinglePar | Update::FitCursor);
|
2007-09-15 12:28:41 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-28 16:02:09 +00:00
|
|
|
|
case LFUN_BRANCH_ACTIVATE:
|
|
|
|
|
case LFUN_BRANCH_DEACTIVATE:
|
|
|
|
|
buffer_.dispatch(cmd);
|
|
|
|
|
processUpdateFlags(Update::Force);
|
|
|
|
|
break;
|
|
|
|
|
|
2008-09-25 20:50:33 +00:00
|
|
|
|
// This could be rewriten using some command like forall <insetname> <command>
|
2008-06-24 07:18:06 +00:00
|
|
|
|
// once the insets refactoring is done.
|
|
|
|
|
case LFUN_NOTES_MUTATE: {
|
|
|
|
|
if (cmd.argument().empty())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (mutateNotes(cur, cmd.getArg(0), cmd.getArg(1))) {
|
|
|
|
|
processUpdateFlags(Update::Force);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-24 07:52:49 +00:00
|
|
|
|
case LFUN_ALL_INSETS_TOGGLE: {
|
|
|
|
|
string action;
|
|
|
|
|
string const name = split(to_utf8(cmd.argument()), action, ' ');
|
|
|
|
|
InsetCode const inset_code = insetCode(name);
|
|
|
|
|
|
|
|
|
|
FuncRequest fr(LFUN_INSET_TOGGLE, action);
|
|
|
|
|
|
|
|
|
|
Inset & inset = cur.buffer().inset();
|
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
|
for (; it != end; ++it) {
|
2008-07-19 18:35:48 +00:00
|
|
|
|
if (it->asInsetCollapsable()
|
2008-06-24 07:52:49 +00:00
|
|
|
|
&& (inset_code == NO_CODE
|
|
|
|
|
|| inset_code == it->lyxCode())) {
|
|
|
|
|
Cursor tmpcur = cur;
|
|
|
|
|
tmpcur.pushBackward(*it);
|
2008-07-19 18:35:48 +00:00
|
|
|
|
it->dispatch(tmpcur, fr);
|
2008-06-24 07:52:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
default:
|
2007-12-21 10:42:59 +00:00
|
|
|
|
return false;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-21 10:42:59 +00:00
|
|
|
|
return true;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
2002-08-28 10:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-17 08:35:12 +00:00
|
|
|
|
docstring const BufferView::requestSelection()
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor & cur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2008-07-20 20:16:33 +00:00
|
|
|
|
LYXERR(Debug::SELECTION, "requestSelection: cur.selection: " << cur.selection());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (!cur.selection()) {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->xsel_cache_.set = false;
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return docstring();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 00:33:37 +00:00
|
|
|
|
LYXERR(Debug::SELECTION, "requestSelection: xsel_cache.set: " << d->xsel_cache_.set);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (!d->xsel_cache_.set ||
|
|
|
|
|
cur.top() != d->xsel_cache_.cursor ||
|
|
|
|
|
cur.anchor_.top() != d->xsel_cache_.anchor)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->xsel_cache_.cursor = cur.top();
|
|
|
|
|
d->xsel_cache_.anchor = cur.anchor_.top();
|
|
|
|
|
d->xsel_cache_.set = cur.selection();
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return cur.selectionAsString(false);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-09-17 08:35:12 +00:00
|
|
|
|
return docstring();
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-17 08:35:12 +00:00
|
|
|
|
void BufferView::clearSelection()
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.clearSelection();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
// Clear the selection buffer. Otherwise a subsequent
|
|
|
|
|
// middle-mouse-button paste would use the selection buffer,
|
|
|
|
|
// not the more current external selection.
|
|
|
|
|
cap::clearSelection();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->xsel_cache_.set = false;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
// The buffer did not really change, but this causes the
|
|
|
|
|
// redraw we need because we cleared the selection above.
|
|
|
|
|
buffer_.changed();
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-24 07:05:19 +00:00
|
|
|
|
void BufferView::resize(int width, int height)
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Update from work area
|
|
|
|
|
width_ = width;
|
|
|
|
|
height_ = height;
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
// Clear the paragraph height cache.
|
|
|
|
|
d->par_height_.clear();
|
2008-02-20 14:53:19 +00:00
|
|
|
|
// Redo the metrics.
|
2007-11-06 08:32:25 +00:00
|
|
|
|
updateMetrics();
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
|
Inset const * BufferView::getCoveringInset(Text const & text,
|
|
|
|
|
int x, int y) const
|
2007-03-28 14:47:52 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[&text];
|
2007-09-21 20:39:47 +00:00
|
|
|
|
Inset * inset = tm.checkInsetHit(x, y);
|
|
|
|
|
if (!inset)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!inset->descendable())
|
|
|
|
|
// No need to go further down if the inset is not
|
|
|
|
|
// descendable.
|
|
|
|
|
return inset;
|
|
|
|
|
|
|
|
|
|
size_t cell_number = inset->nargs();
|
|
|
|
|
// Check all the inner cell.
|
|
|
|
|
for (size_t i = 0; i != cell_number; ++i) {
|
|
|
|
|
Text const * inner_text = inset->getText(i);
|
|
|
|
|
if (inner_text) {
|
|
|
|
|
// Try deeper.
|
|
|
|
|
Inset const * inset_deeper =
|
|
|
|
|
getCoveringInset(*inner_text, x, y);
|
|
|
|
|
if (inset_deeper)
|
|
|
|
|
return inset_deeper;
|
2007-03-28 14:47:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-21 20:39:47 +00:00
|
|
|
|
|
|
|
|
|
return inset;
|
2007-03-28 14:47:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-05 09:38:40 +00:00
|
|
|
|
void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
{
|
2007-11-30 08:35:54 +00:00
|
|
|
|
//lyxerr << "[ cmd0 " << cmd0 << "]" << endl;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
|
|
|
|
FuncRequest cmd = cmd0;
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
|
Cursor old = cursor();
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor cur(*this);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.push(buffer_.inset());
|
2008-09-24 21:27:41 +00:00
|
|
|
|
cur.setSelection(d->cursor_.selection());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Either the inset under the cursor or the
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// surrounding Text will handle this event.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-03-27 10:07:53 +00:00
|
|
|
|
// make sure we stay within the screen...
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cmd.y = min(max(cmd.y, -1), height_);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
if (cmd.action == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// Get inset under mouse, if there is one.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
Inset const * covering_inset =
|
2007-08-21 07:33:46 +00:00
|
|
|
|
getCoveringInset(buffer_.text(), cmd.x, cmd.y);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (covering_inset == d->last_inset_)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// Same inset, no need to do anything...
|
2007-10-05 09:38:40 +00:00
|
|
|
|
return;
|
2007-03-27 10:07:53 +00:00
|
|
|
|
|
2006-12-07 11:46:27 +00:00
|
|
|
|
bool need_redraw = false;
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// const_cast because of setMouseHover().
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * inset = const_cast<Inset *>(covering_inset);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->last_inset_)
|
2007-03-28 14:47:52 +00:00
|
|
|
|
// Remove the hint on the last hovered inset (if any).
|
2007-10-13 07:33:07 +00:00
|
|
|
|
need_redraw |= d->last_inset_->setMouseHover(false);
|
2007-03-28 14:47:52 +00:00
|
|
|
|
if (inset)
|
|
|
|
|
// Highlighted the newly hovered inset (if any).
|
|
|
|
|
need_redraw |= inset->setMouseHover(true);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->last_inset_ = inset;
|
2007-09-20 08:48:28 +00:00
|
|
|
|
if (!need_redraw)
|
2007-10-05 09:38:40 +00:00
|
|
|
|
return;
|
2006-12-07 11:46:27 +00:00
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "Mouse hover detected at: ("
|
|
|
|
|
<< cmd.x << ", " << cmd.y << ")");
|
|
|
|
|
|
|
|
|
|
d->update_strategy_ = DecorationUpdate;
|
2006-12-07 11:46:27 +00:00
|
|
|
|
|
2006-12-04 04:31:18 +00:00
|
|
|
|
// This event (moving without mouse click) is not passed further.
|
|
|
|
|
// This should be changed if it is further utilized.
|
2007-10-05 09:38:40 +00:00
|
|
|
|
buffer_.changed();
|
|
|
|
|
return;
|
2006-12-04 04:31:18 +00:00
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-03-27 10:07:53 +00:00
|
|
|
|
// Build temporary cursor.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Inset * inset = d->text_metrics_[&buffer_.text()].editXY(cur, cmd.x, cmd.y);
|
2006-12-04 04:31:18 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Put anchor at the same position.
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
2008-09-18 13:44:54 +00:00
|
|
|
|
cur.beginUndoGroup();
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Try to dispatch to an non-editable inset near this position
|
|
|
|
|
// via the temp cursor. If the inset wishes to change the real
|
|
|
|
|
// cursor it has to do so explicitly by using
|
|
|
|
|
// cur.bv().cursor() = cur; (or similar)
|
2007-10-05 09:38:40 +00:00
|
|
|
|
if (inset)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
inset->dispatch(cur, cmd);
|
|
|
|
|
|
|
|
|
|
// Now dispatch to the temporary cursor. If the real cursor should
|
|
|
|
|
// be modified, the inset's dispatch has to do so explicitly.
|
2008-03-24 18:22:54 +00:00
|
|
|
|
if (!inset || !cur.result().dispatched())
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cur.dispatch(cmd);
|
|
|
|
|
|
2008-09-18 13:44:54 +00:00
|
|
|
|
cur.endUndoGroup();
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
|
// Notify left insets
|
|
|
|
|
if (cur != old) {
|
|
|
|
|
old.fixIfBroken();
|
|
|
|
|
bool badcursor = notifyCursorLeaves(old, cur);
|
|
|
|
|
if (badcursor)
|
|
|
|
|
cursor().fixIfBroken();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do we have a selection?
|
2007-08-10 10:21:09 +00:00
|
|
|
|
theSelection().haveSelection(cursor().selection());
|
|
|
|
|
|
2007-10-05 09:38:40 +00:00
|
|
|
|
// If the command has been dispatched,
|
2008-02-22 20:45:18 +00:00
|
|
|
|
if (cur.result().dispatched() || cur.result().update())
|
2007-10-10 08:52:55 +00:00
|
|
|
|
processUpdateFlags(cur.result().update());
|
* frontends/WorkArea.h(workAreaResize, scrollDocView, workAreaKeyPress,
dispatch, selectionReuqested, selectionLost): remove signals
* BufferView.[Ch] (selectionRequested, selectionLost, workAreaResize,
workAreaKeyPress, workAreaDispatch): add forwarding functions to the pimpl
* BufferView_pimpl.C (Pimpl): Remove the setup of the now deleted signals,
also remove corresponding connection objects.
* frontends/xforms/XWorkArea.h:
* frontends/qt2/QWorkArea.h:
* frontends/qt4/QWorkArea.h:
* frontends/gtk/GWorkArea.h: add LyXView as class variable view_ (qt
classes also get view() medthod)
* frontends/qt2/QWorkArea.C:
* frontends/qt2/QContentPane.C:
* frontends/qt4/QWorkArea.C:
* frontends/xforms/XWorkArea.C:
* frontends/gtk/GWorkArea.C: Change from calling signals to call
the functions directly through view_.view()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13671 a592a061-630c-0410-9148-cb99ea01b6c8
2006-04-13 18:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-27 11:37:07 +00:00
|
|
|
|
void BufferView::lfunScroll(FuncRequest const & cmd)
|
|
|
|
|
{
|
|
|
|
|
string const scroll_type = cmd.getArg(0);
|
|
|
|
|
int const scroll_step =
|
2008-04-16 18:18:12 +00:00
|
|
|
|
(scroll_type == "line") ? d->scrollbarParameters_.single_step
|
|
|
|
|
: (scroll_type == "page") ? d->scrollbarParameters_.page_step : 0;
|
2007-12-27 11:37:07 +00:00
|
|
|
|
if (scroll_step == 0)
|
|
|
|
|
return;
|
|
|
|
|
string const scroll_quantity = cmd.getArg(1);
|
|
|
|
|
if (scroll_quantity == "up")
|
|
|
|
|
scrollUp(scroll_step);
|
|
|
|
|
else if (scroll_quantity == "down")
|
|
|
|
|
scrollDown(scroll_step);
|
|
|
|
|
else {
|
|
|
|
|
int const scroll_value = convert<int>(scroll_quantity);
|
|
|
|
|
if (scroll_value)
|
|
|
|
|
scroll(scroll_step * scroll_value);
|
|
|
|
|
}
|
2008-07-04 11:33:28 +00:00
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2007-12-27 11:37:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
|
int BufferView::scroll(int y)
|
2002-08-28 10:45:38 +00:00
|
|
|
|
{
|
2007-09-15 12:28:41 +00:00
|
|
|
|
if (y > 0)
|
2008-07-04 11:33:28 +00:00
|
|
|
|
return scrollDown(y);
|
|
|
|
|
if (y < 0)
|
|
|
|
|
return scrollUp(-y);
|
|
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
|
int BufferView::scrollDown(int offset)
|
2007-09-15 12:28:41 +00:00
|
|
|
|
{
|
|
|
|
|
Text * text = &buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[text];
|
2007-09-15 12:28:41 +00:00
|
|
|
|
int ymax = height_ + offset;
|
|
|
|
|
while (true) {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
2007-09-20 08:48:28 +00:00
|
|
|
|
int bottom_pos = last.second->position() + last.second->descent();
|
2007-09-29 07:34:42 +00:00
|
|
|
|
if (last.first + 1 == int(text->paragraphs().size())) {
|
2007-09-15 12:28:41 +00:00
|
|
|
|
if (bottom_pos <= height_)
|
2008-07-04 11:33:28 +00:00
|
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
offset = min(offset, bottom_pos - height_);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (bottom_pos > ymax)
|
|
|
|
|
break;
|
|
|
|
|
tm.newParMetricsDown();
|
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
|
d->anchor_ypos_ -= offset;
|
2008-07-04 11:33:28 +00:00
|
|
|
|
return -offset;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-04 11:33:28 +00:00
|
|
|
|
int BufferView::scrollUp(int offset)
|
2007-09-15 12:28:41 +00:00
|
|
|
|
{
|
|
|
|
|
Text * text = &buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[text];
|
2007-09-15 12:28:41 +00:00
|
|
|
|
int ymin = - offset;
|
|
|
|
|
while (true) {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
2007-09-20 08:48:28 +00:00
|
|
|
|
int top_pos = first.second->position() - first.second->ascent();
|
2007-09-15 12:28:41 +00:00
|
|
|
|
if (first.first == 0) {
|
|
|
|
|
if (top_pos >= 0)
|
2008-07-04 11:33:28 +00:00
|
|
|
|
return 0;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
offset = min(offset, - top_pos);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (top_pos < ymin)
|
|
|
|
|
break;
|
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
|
d->anchor_ypos_ += offset;
|
2008-07-04 11:33:28 +00:00
|
|
|
|
return offset;
|
2002-08-28 10:45:38 +00:00
|
|
|
|
}
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setCursorFromRow(int row)
|
|
|
|
|
{
|
|
|
|
|
int tmpid = -1;
|
|
|
|
|
int tmppos = -1;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.reset(buffer_.inset());
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (tmpid == -1)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
buffer_.text().setCursor(d->cursor_, 0, 0);
|
2003-10-09 10:52:12 +00:00
|
|
|
|
else
|
2007-10-13 07:33:07 +00:00
|
|
|
|
buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-17 14:51:27 +00:00
|
|
|
|
bool BufferView::setCursorFromInset(Inset const * inset)
|
|
|
|
|
{
|
|
|
|
|
// are we already there?
|
|
|
|
|
if (cursor().nextInset() == inset)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Inset is not at cursor position. Find it in the document.
|
|
|
|
|
Cursor cur(*this);
|
|
|
|
|
cur.reset(buffer().inset());
|
|
|
|
|
do
|
|
|
|
|
cur.forwardInset();
|
|
|
|
|
while (cur && cur.nextInset() != inset);
|
|
|
|
|
|
|
|
|
|
if (cur) {
|
|
|
|
|
setCursor(cur);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-12 10:50:45 +00:00
|
|
|
|
void BufferView::gotoLabel(docstring const & label)
|
2002-08-29 13:05:55 +00:00
|
|
|
|
{
|
2008-03-07 19:46:04 +00:00
|
|
|
|
Toc & toc = buffer().tocBackend().toc("label");
|
|
|
|
|
TocIterator toc_it = toc.begin();
|
|
|
|
|
TocIterator end = toc.end();
|
|
|
|
|
for (; toc_it != end; ++toc_it) {
|
|
|
|
|
if (label == toc_it->str())
|
|
|
|
|
dispatch(toc_it->action());
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
2008-03-07 19:46:04 +00:00
|
|
|
|
//FIXME: We could do a bit more searching thanks to this:
|
|
|
|
|
//InsetLabel const * inset = buffer_.insetLabel(label);
|
2002-08-29 13:05:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
TextMetrics const & BufferView::textMetrics(Text const * t) const
|
2006-12-29 23:54:48 +00:00
|
|
|
|
{
|
|
|
|
|
return const_cast<BufferView *>(this)->textMetrics(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
TextMetrics & BufferView::textMetrics(Text const * t)
|
2006-12-29 23:54:48 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t);
|
|
|
|
|
if (tmc_it == d->text_metrics_.end()) {
|
|
|
|
|
tmc_it = d->text_metrics_.insert(
|
2007-04-29 23:33:02 +00:00
|
|
|
|
make_pair(t, TextMetrics(this, const_cast<Text *>(t)))).first;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
}
|
2006-12-29 23:54:48 +00:00
|
|
|
|
return tmc_it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
|
ParagraphMetrics const & BufferView::parMetrics(Text const * t,
|
2006-12-29 23:54:48 +00:00
|
|
|
|
pit_type pit) const
|
|
|
|
|
{
|
|
|
|
|
return textMetrics(t).parMetrics(pit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-29 13:41:58 +00:00
|
|
|
|
int BufferView::workHeight() const
|
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return height_;
|
2002-08-29 13:41:58 +00:00
|
|
|
|
}
|
2003-11-04 07:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
void BufferView::setCursor(DocIterator const & dit)
|
2004-02-02 11:07:51 +00:00
|
|
|
|
{
|
2005-02-22 11:41:22 +00:00
|
|
|
|
size_t const n = dit.depth();
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
dit[i].inset().edit(d->cursor_, true);
|
2004-03-31 17:58:11 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setCursor(dit);
|
2008-09-24 21:27:41 +00:00
|
|
|
|
d->cursor_.setSelection(false);
|
2004-02-02 11:07:51 +00:00
|
|
|
|
}
|
2004-01-14 17:21:39 +00:00
|
|
|
|
|
2005-02-08 13:18:05 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool BufferView::checkDepm(Cursor & cur, Cursor & old)
|
2006-12-30 15:05:15 +00:00
|
|
|
|
{
|
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool need_anchor_change = false;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
bool changed = d->cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
|
2006-12-30 15:05:15 +00:00
|
|
|
|
need_anchor_change);
|
|
|
|
|
|
|
|
|
|
if (need_anchor_change)
|
|
|
|
|
cur.resetAnchor();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
if (!changed)
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-12-27 10:39:25 +00:00
|
|
|
|
d->cursor_ = cur;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2007-01-31 14:07:37 +00:00
|
|
|
|
|
2007-11-06 08:32:25 +00:00
|
|
|
|
updateMetrics();
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.changed();
|
2006-12-30 15:05:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
|
bool BufferView::mouseSetCursor(Cursor & cur, bool select)
|
2005-12-01 10:28:50 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(&cur.bv() == this, /**/);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
|
if (!select)
|
|
|
|
|
// this event will clear selection so we save selection for
|
|
|
|
|
// persistent selection
|
|
|
|
|
cap::saveSelection(cursor());
|
2007-07-10 12:44:19 +00:00
|
|
|
|
|
2005-12-01 10:28:50 +00:00
|
|
|
|
// Has the cursor just left the inset?
|
2006-08-17 21:32:04 +00:00
|
|
|
|
bool badcursor = false;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
bool leftinset = (&d->cursor_.inset() != &cur.inset());
|
2008-02-22 20:45:18 +00:00
|
|
|
|
if (leftinset) {
|
|
|
|
|
d->cursor_.fixIfBroken();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
badcursor = notifyCursorLeaves(d->cursor_, cur);
|
2008-02-22 20:45:18 +00:00
|
|
|
|
if (badcursor)
|
|
|
|
|
cur.fixIfBroken();
|
|
|
|
|
}
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
2007-10-11 14:46:53 +00:00
|
|
|
|
// FIXME: shift-mouse selection doesn't work well across insets.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
bool do_selection = select && &d->cursor_.anchor().inset() == &cur.inset();
|
2007-10-11 14:46:53 +00:00
|
|
|
|
|
2005-12-01 10:28:50 +00:00
|
|
|
|
// do the dEPM magic if needed
|
2007-04-10 16:50:19 +00:00
|
|
|
|
// FIXME: (1) move this to InsetText::notifyCursorLeaves?
|
|
|
|
|
// FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
|
|
|
|
|
// the leftinset bool would not be necessary (badcursor instead).
|
|
|
|
|
bool update = leftinset;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (!do_selection && !badcursor && d->cursor_.inTexted())
|
|
|
|
|
update |= checkDepm(cur, d->cursor_);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
|
d->cursor_.setCursor(cur);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.boundary(cur.boundary());
|
2007-10-11 14:46:53 +00:00
|
|
|
|
if (do_selection)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setSelection();
|
2007-10-11 14:46:53 +00:00
|
|
|
|
else
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.clearSelection();
|
2007-10-11 14:46:53 +00:00
|
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
|
d->cursor_.finishUndo();
|
2007-10-29 18:57:56 +00:00
|
|
|
|
d->cursor_.setCurrentFont();
|
2006-12-11 13:59:40 +00:00
|
|
|
|
return update;
|
2005-12-01 10:28:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void BufferView::putSelectionAt(DocIterator const & cur,
|
2004-03-28 22:00:22 +00:00
|
|
|
|
int length, bool backwards)
|
2004-01-14 17:21:39 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.clearSelection();
|
2004-01-14 17:21:39 +00:00
|
|
|
|
|
2005-02-22 11:41:22 +00:00
|
|
|
|
setCursor(cur);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-01-14 17:21:39 +00:00
|
|
|
|
if (length) {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
if (backwards) {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.pos() += length;
|
|
|
|
|
d->cursor_.setSelection(d->cursor_, -length);
|
2004-03-31 17:58:11 +00:00
|
|
|
|
} else
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setSelection(d->cursor_, length);
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
2008-02-10 19:18:57 +00:00
|
|
|
|
// Ensure a redraw happens in any case because the new selection could
|
|
|
|
|
// possibly be on the same screen as the previous selection.
|
|
|
|
|
processUpdateFlags(Update::Force | Update::FitCursor);
|
2004-01-14 17:21:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-15 11:58:35 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & BufferView::cursor()
|
2004-01-20 14:25:24 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->cursor_;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor const & BufferView::cursor() const
|
2004-01-15 11:58:35 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->cursor_;
|
2004-01-15 11:58:35 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
pit_type BufferView::anchor_ref() const
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
2007-12-21 08:28:18 +00:00
|
|
|
|
return d->anchor_pit_;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
|
bool BufferView::singleParUpdate()
|
|
|
|
|
{
|
|
|
|
|
Text & buftext = buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
pit_type const bottom_pit = d->cursor_.bottom().pit();
|
2007-09-28 09:11:24 +00:00
|
|
|
|
TextMetrics & tm = textMetrics(&buftext);
|
|
|
|
|
int old_height = tm.parMetrics(bottom_pit).height();
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
// make sure inline completion pointer is ok
|
2008-04-16 20:43:30 +00:00
|
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
|
// In Single Paragraph mode, rebreak only
|
|
|
|
|
// the (main text, not inset!) paragraph containing the cursor.
|
|
|
|
|
// (if this paragraph contains insets etc., rebreaking will
|
|
|
|
|
// recursively descend)
|
|
|
|
|
tm.redoParagraph(bottom_pit);
|
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bottom_pit);
|
|
|
|
|
if (pm.height() != old_height)
|
|
|
|
|
// Paragraph height has changed so we cannot proceed to
|
|
|
|
|
// the singlePar optimisation.
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = SingleParUpdate;
|
|
|
|
|
|
2007-11-30 08:35:54 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "\ny1: " << pm.position() - pm.ascent()
|
2007-11-17 11:27:03 +00:00
|
|
|
|
<< " y2: " << pm.position() + pm.descent()
|
2007-09-28 09:11:24 +00:00
|
|
|
|
<< " pit: " << bottom_pit
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< " singlepar: 1");
|
2007-09-28 09:11:24 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-06 08:32:25 +00:00
|
|
|
|
void BufferView::updateMetrics()
|
2006-07-08 20:24:32 +00:00
|
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
|
if (height_ == 0 || width_ == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & buftext = buffer_.text();
|
2007-09-11 16:04:10 +00:00
|
|
|
|
pit_type const npit = int(buftext.paragraphs().size());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
|
// Clear out the position cache in case of full screen redraw,
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->coord_cache_.clear();
|
2007-09-16 10:38:25 +00:00
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
|
// Clear out paragraph metrics to avoid having invalid metrics
|
|
|
|
|
// in the cache from paragraphs not relayouted below
|
|
|
|
|
// The complete text metrics will be redone.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->text_metrics_.clear();
|
2007-08-30 16:48:47 +00:00
|
|
|
|
|
|
|
|
|
TextMetrics & tm = textMetrics(&buftext);
|
2007-06-21 06:41:55 +00:00
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
// make sure inline completion pointer is ok
|
2008-04-16 20:43:30 +00:00
|
|
|
|
if (d->inlineCompletionPos_.fixIfBroken())
|
|
|
|
|
d->inlineCompletionPos_ = DocIterator();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
2008-03-02 19:07:15 +00:00
|
|
|
|
if (d->anchor_pit_ >= npit)
|
|
|
|
|
// The anchor pit must have been deleted...
|
|
|
|
|
d->anchor_pit_ = npit - 1;
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Rebreak anchor paragraph.
|
2007-12-21 08:28:18 +00:00
|
|
|
|
tm.redoParagraph(d->anchor_pit_);
|
|
|
|
|
ParagraphMetrics & anchor_pm = tm.par_metrics_[d->anchor_pit_];
|
2008-02-05 14:23:59 +00:00
|
|
|
|
|
|
|
|
|
// position anchor
|
|
|
|
|
if (d->anchor_pit_ == 0) {
|
|
|
|
|
int scrollRange = d->scrollbarParameters_.max - d->scrollbarParameters_.min;
|
|
|
|
|
|
|
|
|
|
// Complete buffer visible? Then it's easy.
|
|
|
|
|
if (scrollRange == 0)
|
|
|
|
|
d->anchor_ypos_ = anchor_pm.ascent();
|
|
|
|
|
|
|
|
|
|
// FIXME: Some clever handling needed to show
|
|
|
|
|
// the _first_ paragraph up to the top if the cursor is
|
|
|
|
|
// in the first line.
|
|
|
|
|
}
|
2007-12-21 08:28:18 +00:00
|
|
|
|
anchor_pm.setPosition(d->anchor_ypos_);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "metrics: "
|
|
|
|
|
<< " anchor pit = " << d->anchor_pit_
|
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs above anchor if necessary.
|
2007-12-21 08:28:18 +00:00
|
|
|
|
int y1 = d->anchor_ypos_ - anchor_pm.ascent();
|
|
|
|
|
// We are now just above the anchor paragraph.
|
|
|
|
|
pit_type pit1 = d->anchor_pit_ - 1;
|
2007-12-22 09:10:49 +00:00
|
|
|
|
for (; pit1 >= 0 && y1 >= 0; --pit1) {
|
2007-09-11 16:04:10 +00:00
|
|
|
|
tm.redoParagraph(pit1);
|
2007-12-21 08:28:18 +00:00
|
|
|
|
ParagraphMetrics & pm = tm.par_metrics_[pit1];
|
|
|
|
|
y1 -= pm.descent();
|
|
|
|
|
// Save the paragraph position in the cache.
|
|
|
|
|
pm.setPosition(y1);
|
|
|
|
|
y1 -= pm.ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs below the anchor if necessary.
|
2007-12-21 08:28:18 +00:00
|
|
|
|
int y2 = d->anchor_ypos_ + anchor_pm.descent();
|
|
|
|
|
// We are now just below the anchor paragraph.
|
|
|
|
|
pit_type pit2 = d->anchor_pit_ + 1;
|
2007-12-22 09:04:53 +00:00
|
|
|
|
for (; pit2 < npit && y2 <= height_; ++pit2) {
|
2007-09-11 16:04:10 +00:00
|
|
|
|
tm.redoParagraph(pit2);
|
2007-12-21 08:28:18 +00:00
|
|
|
|
ParagraphMetrics & pm = tm.par_metrics_[pit2];
|
|
|
|
|
y2 += pm.ascent();
|
|
|
|
|
// Save the paragraph position in the cache.
|
|
|
|
|
pm.setPosition(y2);
|
|
|
|
|
y2 += pm.descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-21 08:28:18 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "Metrics: "
|
|
|
|
|
<< " anchor pit = " << d->anchor_pit_
|
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_
|
|
|
|
|
<< " y1 = " << y1
|
|
|
|
|
<< " y2 = " << y2
|
|
|
|
|
<< " pit1 = " << pit1
|
|
|
|
|
<< " pit2 = " << pit2);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
d->update_strategy_ = FullScreenUpdate;
|
2006-10-20 20:57:21 +00:00
|
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::WORKAREA, "BufferView::updateMetrics");
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->coord_cache_.dump();
|
2006-10-20 20:57:21 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
|
void BufferView::insertLyXFile(FileName const & fname)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(d->cursor_.inTexted(), /**/);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2007-12-02 17:50:08 +00:00
|
|
|
|
FileName filename = fileSearch(string(), fname.absFilename(), "lyx");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
|
docstring const disp_fn = makeDisplayPath(filename.absFilename());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(_("Inserting document %1$s..."), disp_fn));
|
|
|
|
|
|
|
|
|
|
docstring res;
|
|
|
|
|
Buffer buf("", false);
|
2007-12-02 17:50:08 +00:00
|
|
|
|
if (buf.loadLyXFile(filename)) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
ErrorList & el = buffer_.errorList("Parse");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Copy the inserted document error list into the current buffer one.
|
|
|
|
|
el = buf.errorList("Parse");
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buffer_.undo().recordUndo(d->cursor_);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
|
2008-02-28 01:42:02 +00:00
|
|
|
|
buf.params().documentClassPtr(), el);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
res = _("Document %1$s inserted.");
|
2007-10-21 10:50:56 +00:00
|
|
|
|
} else {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
res = _("Could not insert document %1$s");
|
2007-10-21 10:50:56 +00:00
|
|
|
|
}
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(res, disp_fn));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.errors("Parse");
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
2007-09-29 09:22:17 +00:00
|
|
|
|
Point BufferView::coordOffset(DocIterator const & dit, bool boundary) const
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
int lastw = 0;
|
|
|
|
|
|
|
|
|
|
// Addup contribution of nested insets, from inside to outside,
|
|
|
|
|
// keeping the outer paragraph for a special handling below
|
|
|
|
|
for (size_t i = dit.depth() - 1; i >= 1; --i) {
|
|
|
|
|
CursorSlice const & sl = dit[i];
|
|
|
|
|
int xx = 0;
|
|
|
|
|
int yy = 0;
|
|
|
|
|
|
|
|
|
|
// get relative position inside sl.inset()
|
|
|
|
|
sl.inset().cursorPos(*this, sl, boundary && (i + 1 == dit.depth()), xx, yy);
|
|
|
|
|
|
|
|
|
|
// Make relative position inside of the edited inset relative to sl.inset()
|
|
|
|
|
x += xx;
|
|
|
|
|
y += yy;
|
|
|
|
|
|
|
|
|
|
// In case of an RTL inset, the edited inset will be positioned to the left
|
|
|
|
|
// of xx:yy
|
|
|
|
|
if (sl.text()) {
|
|
|
|
|
bool boundary_i = boundary && i + 1 == dit.depth();
|
|
|
|
|
bool rtl = textMetrics(sl.text()).isRTL(sl, boundary_i);
|
|
|
|
|
if (rtl)
|
|
|
|
|
x -= lastw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remember width for the case that sl.inset() is positioned in an RTL inset
|
|
|
|
|
if (i && dit[i - 1].text()) {
|
|
|
|
|
// If this Inset is inside a Text Inset, retrieve the Dimension
|
|
|
|
|
// from the containing text instead of using Inset::dimension() which
|
|
|
|
|
// might not be implemented.
|
|
|
|
|
// FIXME (Abdel 23/09/2007): this is a bit messy because of the
|
|
|
|
|
// elimination of Inset::dim_ cache. This coordOffset() method needs
|
|
|
|
|
// to be rewritten in light of the new design.
|
|
|
|
|
Dimension const & dim = parMetrics(dit[i - 1].text(),
|
|
|
|
|
dit[i - 1].pit()).insetDimension(&sl.inset());
|
|
|
|
|
lastw = dim.wid;
|
|
|
|
|
} else {
|
|
|
|
|
Dimension const dim = sl.inset().dimension(*this);
|
|
|
|
|
lastw = dim.wid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//lyxerr << "Cursor::getPos, i: "
|
|
|
|
|
// << i << " x: " << xx << " y: " << y << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add contribution of initial rows of outermost paragraph
|
|
|
|
|
CursorSlice const & sl = dit[0];
|
|
|
|
|
TextMetrics const & tm = textMetrics(sl.text());
|
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(sl.pit());
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(!pm.rows().empty(), /**/);
|
2007-09-29 09:22:17 +00:00
|
|
|
|
y -= pm.rows()[0].ascent();
|
|
|
|
|
#if 1
|
|
|
|
|
// FIXME: document this mess
|
|
|
|
|
size_t rend;
|
|
|
|
|
if (sl.pos() > 0 && dit.depth() == 1) {
|
|
|
|
|
int pos = sl.pos();
|
|
|
|
|
if (pos && boundary)
|
|
|
|
|
--pos;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
// lyxerr << "coordOffset: boundary:" << boundary << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << endl;
|
2007-09-29 09:22:17 +00:00
|
|
|
|
rend = pm.pos2row(pos);
|
|
|
|
|
} else
|
|
|
|
|
rend = pm.pos2row(sl.pos());
|
|
|
|
|
#else
|
|
|
|
|
size_t rend = pm.pos2row(sl.pos());
|
|
|
|
|
#endif
|
|
|
|
|
for (size_t rit = 0; rit != rend; ++rit)
|
|
|
|
|
y += pm.rows()[rit].height();
|
|
|
|
|
y += pm.rows()[rend].ascent();
|
|
|
|
|
|
|
|
|
|
TextMetrics const & bottom_tm = textMetrics(dit.bottom().text());
|
|
|
|
|
|
|
|
|
|
// Make relative position from the nested inset now bufferview absolute.
|
|
|
|
|
int xx = bottom_tm.cursorX(dit.bottom(), boundary && dit.depth() == 1);
|
|
|
|
|
x += xx;
|
|
|
|
|
|
|
|
|
|
// In the RTL case place the nested inset at the left of the cursor in
|
|
|
|
|
// the outer paragraph
|
|
|
|
|
bool boundary_1 = boundary && 1 == dit.depth();
|
|
|
|
|
bool rtl = bottom_tm.isRTL(dit.bottom(), boundary_1);
|
|
|
|
|
if (rtl)
|
|
|
|
|
x -= lastw;
|
|
|
|
|
|
|
|
|
|
return Point(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Point BufferView::getPos(DocIterator const & dit, bool boundary) const
|
|
|
|
|
{
|
|
|
|
|
CursorSlice const & bot = dit.bottom();
|
|
|
|
|
TextMetrics const & tm = textMetrics(bot.text());
|
2008-02-27 23:03:26 +00:00
|
|
|
|
if (!tm.contains(bot.pit()))
|
2007-09-29 09:22:17 +00:00
|
|
|
|
return Point(-1, -1);
|
|
|
|
|
|
|
|
|
|
Point p = coordOffset(dit, boundary); // offset from outer paragraph
|
|
|
|
|
p.y_ += tm.parMetrics(bot.pit()).position();
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-27 22:53:16 +00:00
|
|
|
|
void BufferView::draw(frontend::Painter & pain)
|
|
|
|
|
{
|
2008-06-19 13:10:25 +00:00
|
|
|
|
if (height_ == 0 || width_ == 0)
|
|
|
|
|
return;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "\t\t*** START DRAWING ***");
|
2007-11-06 14:07:49 +00:00
|
|
|
|
Text & text = buffer_.text();
|
|
|
|
|
TextMetrics const & tm = d->text_metrics_[&text];
|
2007-12-21 08:28:18 +00:00
|
|
|
|
int const y = tm.first().second->position();
|
2007-08-27 22:53:16 +00:00
|
|
|
|
PainterInfo pi(this, pain);
|
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
switch (d->update_strategy_) {
|
2007-11-06 14:07:49 +00:00
|
|
|
|
|
|
|
|
|
case NoScreenUpdate:
|
|
|
|
|
// If no screen painting is actually needed, only some the different
|
|
|
|
|
// coordinates of insets and paragraphs needs to be updated.
|
|
|
|
|
pi.full_repaint = true;
|
2007-11-06 14:18:09 +00:00
|
|
|
|
pi.pain.setDrawingEnabled(false);
|
|
|
|
|
tm.draw(pi, 0, y);
|
2007-11-06 14:07:49 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SingleParUpdate:
|
|
|
|
|
pi.full_repaint = false;
|
2007-11-17 11:27:03 +00:00
|
|
|
|
// In general, only the current row of the outermost paragraph
|
|
|
|
|
// will be redrawn. Particular cases where selection spans
|
|
|
|
|
// multiple paragraph are correctly detected in TextMetrics.
|
|
|
|
|
tm.draw(pi, 0, y);
|
2007-11-06 14:07:49 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DecorationUpdate:
|
|
|
|
|
// FIXME: We should also distinguish DecorationUpdate to avoid text
|
|
|
|
|
// drawing if possible. This is not possible to do easily right now
|
|
|
|
|
// because of the single backing pixmap.
|
|
|
|
|
|
|
|
|
|
case FullScreenUpdate:
|
|
|
|
|
// The whole screen, including insets, will be refreshed.
|
|
|
|
|
pi.full_repaint = true;
|
|
|
|
|
|
2007-11-17 11:27:03 +00:00
|
|
|
|
// Clear background.
|
|
|
|
|
pain.fillRectangle(0, 0, width_, height_,
|
2007-09-02 14:34:15 +00:00
|
|
|
|
buffer_.inset().backgroundColor());
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
|
|
// Draw everything.
|
2007-09-09 20:21:43 +00:00
|
|
|
|
tm.draw(pi, 0, y);
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
2007-11-06 14:07:49 +00:00
|
|
|
|
// and possibly grey out below
|
2007-12-12 19:28:07 +00:00
|
|
|
|
pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
|
2007-11-17 11:27:03 +00:00
|
|
|
|
int const y2 = lastpm.second->position() + lastpm.second->descent();
|
|
|
|
|
if (y2 < height_)
|
|
|
|
|
pain.fillRectangle(0, y2, width_, height_ - y2, Color_bottomarea);
|
2007-11-06 14:07:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::PAINTING, "\n\t\t*** END DRAWING ***");
|
2007-12-21 08:28:18 +00:00
|
|
|
|
|
|
|
|
|
// The scrollbar needs an update.
|
|
|
|
|
updateScrollbar();
|
|
|
|
|
|
|
|
|
|
// Normalize anchor for next time
|
|
|
|
|
pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
|
|
|
|
|
pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
|
|
|
|
|
for (pit_type pit = firstpm.first; pit <= lastpm.first; ++pit) {
|
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(pit);
|
|
|
|
|
if (pm.position() + pm.descent() > 0) {
|
|
|
|
|
d->anchor_pit_ = pit;
|
|
|
|
|
d->anchor_ypos_ = pm.position();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LYXERR(Debug::PAINTING, "Found new anchor pit = " << d->anchor_pit_
|
|
|
|
|
<< " anchor ypos = " << d->anchor_ypos_);
|
2007-08-27 22:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-02 18:27:20 +00:00
|
|
|
|
|
|
|
|
|
void BufferView::message(docstring const & msg)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
|
|
|
|
d->gui_->message(msg);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void BufferView::showDialog(string const & name)
|
2007-10-02 18:27:20 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
2007-11-18 00:39:15 +00:00
|
|
|
|
d->gui_->showDialog(name, string());
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void BufferView::showDialog(string const & name,
|
|
|
|
|
string const & data, Inset * inset)
|
2007-10-02 18:27:20 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
2007-11-18 00:39:15 +00:00
|
|
|
|
d->gui_->showDialog(name, data, inset);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void BufferView::updateDialog(string const & name, string const & data)
|
2007-10-02 18:27:20 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
|
|
|
|
d->gui_->updateDialog(name, data);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->gui_ = gui;
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
// FIXME: Move this out of BufferView again
|
2007-12-02 20:05:17 +00:00
|
|
|
|
docstring BufferView::contentsOfPlaintextFile(FileName const & fname)
|
2007-10-03 18:56:37 +00:00
|
|
|
|
{
|
2007-11-25 11:18:16 +00:00
|
|
|
|
if (!fname.isReadableFile()) {
|
2007-10-03 18:56:37 +00:00
|
|
|
|
docstring const error = from_ascii(strerror(errno));
|
|
|
|
|
docstring const file = makeDisplayPath(fname.absFilename(), 50);
|
|
|
|
|
docstring const text =
|
|
|
|
|
bformat(_("Could not read the specified document\n"
|
|
|
|
|
"%1$s\ndue to the error: %2$s"), file, error);
|
|
|
|
|
Alert::error(_("Could not read file"), text);
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-02 11:55:25 +00:00
|
|
|
|
if (!fname.isReadableFile()) {
|
2007-10-03 18:56:37 +00:00
|
|
|
|
docstring const file = makeDisplayPath(fname.absFilename(), 50);
|
|
|
|
|
docstring const text =
|
2007-12-02 11:55:25 +00:00
|
|
|
|
bformat(_("%1$s\n is not readable."), file);
|
2007-10-03 18:56:37 +00:00
|
|
|
|
Alert::error(_("Could not open file"), text);
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME UNICODE: We don't know the encoding of the file
|
2007-12-02 11:55:25 +00:00
|
|
|
|
docstring file_content = fname.fileContents("UTF-8");
|
2007-10-03 18:56:37 +00:00
|
|
|
|
if (file_content.empty()) {
|
|
|
|
|
Alert::error(_("Reading not UTF-8 encoded file"),
|
|
|
|
|
_("The file is not UTF-8 encoded.\n"
|
|
|
|
|
"It will be read as local 8Bit-encoded.\n"
|
|
|
|
|
"If this does not give the correct result\n"
|
|
|
|
|
"then please change the encoding of the file\n"
|
|
|
|
|
"to UTF-8 with a program other than LyX.\n"));
|
2007-12-02 11:55:25 +00:00
|
|
|
|
file_content = fname.fileContents("local8bit");
|
2007-10-03 18:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return normalize_c(file_content);
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
|
2007-12-02 11:55:25 +00:00
|
|
|
|
void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
|
2007-10-03 18:56:37 +00:00
|
|
|
|
{
|
2007-12-02 20:05:17 +00:00
|
|
|
|
docstring const tmpstr = contentsOfPlaintextFile(f);
|
2007-10-03 18:56:37 +00:00
|
|
|
|
|
|
|
|
|
if (tmpstr.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Cursor & cur = cursor();
|
|
|
|
|
cap::replaceSelection(cur);
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buffer_.undo().recordUndo(cur);
|
2007-10-03 18:56:37 +00:00
|
|
|
|
if (asParagraph)
|
|
|
|
|
cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
|
|
|
|
|
else
|
|
|
|
|
cur.innerText()->insertStringAsLines(cur, tmpstr);
|
2007-12-02 20:05:17 +00:00
|
|
|
|
|
|
|
|
|
updateMetrics();
|
|
|
|
|
buffer_.changed();
|
2007-10-03 18:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
|
|
docstring const & BufferView::inlineCompletion() const
|
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
|
return d->inlineCompletion_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t const & BufferView::inlineCompletionUniqueChars() const
|
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
|
return d->inlineCompletionUniqueChars_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DocIterator const & BufferView::inlineCompletionPos() const
|
|
|
|
|
{
|
2008-04-16 20:43:30 +00:00
|
|
|
|
return d->inlineCompletionPos_;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-21 19:43:16 +00:00
|
|
|
|
bool samePar(DocIterator const & a, DocIterator const & b)
|
|
|
|
|
{
|
|
|
|
|
if (a.empty() && b.empty())
|
|
|
|
|
return true;
|
|
|
|
|
if (a.empty() || b.empty())
|
|
|
|
|
return false;
|
|
|
|
|
return &a.innerParagraph() == &b.innerParagraph();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
|
2008-02-21 19:42:34 +00:00
|
|
|
|
docstring const & completion, size_t uniqueChars)
|
|
|
|
|
{
|
2008-02-21 19:43:16 +00:00
|
|
|
|
uniqueChars = min(completion.size(), uniqueChars);
|
2008-04-16 20:43:30 +00:00
|
|
|
|
bool changed = d->inlineCompletion_ != completion
|
|
|
|
|
|| d->inlineCompletionUniqueChars_ != uniqueChars;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
bool singlePar = true;
|
2008-04-16 20:43:30 +00:00
|
|
|
|
d->inlineCompletion_ = completion;
|
|
|
|
|
d->inlineCompletionUniqueChars_ = min(completion.size(), uniqueChars);
|
2008-02-21 19:43:16 +00:00
|
|
|
|
|
2008-02-23 03:13:54 +00:00
|
|
|
|
//lyxerr << "setInlineCompletion pos=" << pos << " completion=" << completion << " uniqueChars=" << uniqueChars << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
|
|
|
|
|
// at new position?
|
2008-04-16 20:43:30 +00:00
|
|
|
|
DocIterator const & old = d->inlineCompletionPos_;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
if (old != pos) {
|
2008-02-23 03:13:54 +00:00
|
|
|
|
//lyxerr << "inlineCompletionPos changed" << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
// old or pos are in another paragraph?
|
|
|
|
|
if ((!samePar(cur, pos) && !pos.empty())
|
|
|
|
|
|| (!samePar(cur, old) && !old.empty())) {
|
|
|
|
|
singlePar = false;
|
2008-02-23 03:13:54 +00:00
|
|
|
|
//lyxerr << "different paragraph" << std::endl;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
}
|
2008-04-16 20:43:30 +00:00
|
|
|
|
d->inlineCompletionPos_ = pos;
|
2008-02-21 19:43:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set update flags
|
|
|
|
|
if (changed) {
|
2008-02-29 09:18:46 +00:00
|
|
|
|
if (singlePar && !(cur.disp_.update() & Update::Force))
|
2008-02-26 14:22:56 +00:00
|
|
|
|
cur.updateFlags(cur.disp_.update() | Update::SinglePar);
|
|
|
|
|
else
|
|
|
|
|
cur.updateFlags(cur.disp_.update() | Update::Force);
|
2008-02-21 19:43:16 +00:00
|
|
|
|
}
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|