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
|
|
|
|
|
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"
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#include "debug.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"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "gettext.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"
|
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-10-11 09:59:01 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetBibtex.h"
|
|
|
|
|
#include "insets/InsetCommand.h" // ChangeRefs
|
|
|
|
|
#include "insets/InsetRef.h"
|
|
|
|
|
#include "insets/InsetText.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2007-10-02 18:27:20 +00:00
|
|
|
|
#include "frontends/Delegates.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "frontends/FileDialog.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"
|
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/FileFilterList.h"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include "support/filetools.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"
|
2007-10-03 20:15:49 +00:00
|
|
|
|
#include "support/fs_extras.h"
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
#include <boost/current_function.hpp>
|
2007-10-02 18:27:20 +00:00
|
|
|
|
#include <boost/next_prior.hpp>
|
2007-10-03 20:15:49 +00:00
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
#include <cerrno>
|
|
|
|
|
#include <fstream>
|
2006-09-16 10:08:51 +00:00
|
|
|
|
#include <functional>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2007-07-17 17:40:44 +00:00
|
|
|
|
using std::distance;
|
|
|
|
|
using std::endl;
|
2007-10-03 20:15:49 +00:00
|
|
|
|
using std::ifstream;
|
2007-07-17 17:40:44 +00:00
|
|
|
|
using std::istringstream;
|
2007-10-03 20:15:49 +00:00
|
|
|
|
using std::istream_iterator;
|
2007-07-17 17:40:44 +00:00
|
|
|
|
using std::make_pair;
|
|
|
|
|
using std::min;
|
|
|
|
|
using std::max;
|
|
|
|
|
using std::mem_fun_ref;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
namespace fs = boost::filesystem;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::addPath;
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::FileFilterList;
|
2006-12-02 16:07:15 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::fileSearch;
|
|
|
|
|
using support::makeDisplayPath;
|
2007-10-03 20:15:49 +00:00
|
|
|
|
using support::makeAbsPath;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::package;
|
2002-08-29 13:05:55 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
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-09-29 07:34:42 +00:00
|
|
|
|
string const & contents)
|
|
|
|
|
{
|
|
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
|
|
|
|
|
|
while (tmpdit) {
|
|
|
|
|
Inset const * inset = tmpdit.nextInset();
|
|
|
|
|
if (inset
|
|
|
|
|
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
|
|
|
|
|
&& (contents.empty() ||
|
|
|
|
|
static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/// Looks for next inset with one of the the given code
|
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)
|
|
|
|
|
{
|
|
|
|
|
string contents;
|
|
|
|
|
DocIterator tmpdit = dit;
|
|
|
|
|
tmpdit.forwardInset();
|
|
|
|
|
if (!tmpdit)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (same_content) {
|
|
|
|
|
Inset const * inset = tmpdit.nextInset();
|
|
|
|
|
if (inset
|
|
|
|
|
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
|
|
|
|
|
contents = static_cast<InsetCommand const *>(inset)->getContents();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 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-09-29 20:25:50 +00:00
|
|
|
|
|
|
|
|
|
/// the type of outline operation
|
|
|
|
|
enum OutlineOp {
|
|
|
|
|
OutlineUp, // Move this header with text down
|
|
|
|
|
OutlineDown, // Move this header with text up
|
|
|
|
|
OutlineIn, // Make this header deeper
|
|
|
|
|
OutlineOut // Make this header shallower
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void outline(OutlineOp mode, Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
Buffer & buf = cur.buffer();
|
|
|
|
|
pit_type & pit = cur.pit();
|
|
|
|
|
ParagraphList & pars = buf.text().paragraphs();
|
|
|
|
|
ParagraphList::iterator bgn = pars.begin();
|
|
|
|
|
// The first paragraph of the area to be copied:
|
|
|
|
|
ParagraphList::iterator start = boost::next(bgn, pit);
|
|
|
|
|
// The final paragraph of area to be copied:
|
|
|
|
|
ParagraphList::iterator finish = start;
|
|
|
|
|
ParagraphList::iterator end = pars.end();
|
|
|
|
|
|
|
|
|
|
TextClass::const_iterator lit =
|
|
|
|
|
buf.params().getTextClass().begin();
|
|
|
|
|
TextClass::const_iterator const lend =
|
|
|
|
|
buf.params().getTextClass().end();
|
|
|
|
|
|
|
|
|
|
int const thistoclevel = start->layout()->toclevel;
|
|
|
|
|
int toclevel;
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case OutlineUp: {
|
|
|
|
|
// Move out (down) from this section header
|
|
|
|
|
if (finish != end)
|
|
|
|
|
++finish;
|
|
|
|
|
// Seek the one (on same level) below
|
|
|
|
|
for (; finish != end; ++finish) {
|
|
|
|
|
toclevel = finish->layout()->toclevel;
|
|
|
|
|
if (toclevel != Layout::NOT_IN_TOC
|
|
|
|
|
&& toclevel <= thistoclevel) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ParagraphList::iterator dest = start;
|
|
|
|
|
// Move out (up) from this header
|
|
|
|
|
if (dest == bgn)
|
|
|
|
|
break;
|
|
|
|
|
// Search previous same-level header above
|
|
|
|
|
do {
|
|
|
|
|
--dest;
|
|
|
|
|
toclevel = dest->layout()->toclevel;
|
|
|
|
|
} while(dest != bgn
|
|
|
|
|
&& (toclevel == Layout::NOT_IN_TOC
|
|
|
|
|
|| toclevel > thistoclevel));
|
|
|
|
|
// Not found; do nothing
|
|
|
|
|
if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
|
|
|
|
|
break;
|
|
|
|
|
pit_type const newpit = std::distance(bgn, dest);
|
|
|
|
|
pit_type const len = std::distance(start, finish);
|
|
|
|
|
pit_type const deletepit = pit + len;
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
|
2007-09-29 20:25:50 +00:00
|
|
|
|
pars.insert(dest, start, finish);
|
|
|
|
|
start = boost::next(pars.begin(), deletepit);
|
|
|
|
|
pit = newpit;
|
|
|
|
|
pars.erase(start, finish);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case OutlineDown: {
|
|
|
|
|
// Go down out of current header:
|
|
|
|
|
if (finish != end)
|
|
|
|
|
++finish;
|
|
|
|
|
// Find next same-level header:
|
|
|
|
|
for (; finish != end; ++finish) {
|
|
|
|
|
toclevel = finish->layout()->toclevel;
|
|
|
|
|
if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ParagraphList::iterator dest = finish;
|
|
|
|
|
// Go one down from *this* header:
|
|
|
|
|
if (dest != end)
|
|
|
|
|
++dest;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
// Go further down to find header to insert in front of:
|
|
|
|
|
for (; dest != end; ++dest) {
|
|
|
|
|
toclevel = dest->layout()->toclevel;
|
|
|
|
|
if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// One such was found:
|
|
|
|
|
pit_type newpit = std::distance(bgn, dest);
|
|
|
|
|
pit_type const len = std::distance(start, finish);
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
|
2007-09-29 20:25:50 +00:00
|
|
|
|
pars.insert(dest, start, finish);
|
|
|
|
|
start = boost::next(bgn, pit);
|
|
|
|
|
pit = newpit - len;
|
|
|
|
|
pars.erase(start, finish);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case OutlineIn:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buf.undo().recordUndo(cur);
|
2007-09-29 20:25:50 +00:00
|
|
|
|
for (; lit != lend; ++lit) {
|
|
|
|
|
if ((*lit)->toclevel == thistoclevel + 1 &&
|
|
|
|
|
start->layout()->labeltype == (*lit)->labeltype) {
|
|
|
|
|
start->layout((*lit));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OutlineOut:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
buf.undo().recordUndo(cur);
|
2007-09-29 20:25:50 +00:00
|
|
|
|
for (; lit != lend; ++lit) {
|
|
|
|
|
if ((*lit)->toclevel == thistoclevel - 1 &&
|
|
|
|
|
start->layout()->labeltype == (*lit)->labeltype) {
|
|
|
|
|
start->layout((*lit));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-11 09:59:01 +00:00
|
|
|
|
/// A map from a Text to the associated text metrics
|
|
|
|
|
typedef std::map<Text const *, TextMetrics> TextMetricsCache;
|
|
|
|
|
|
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-10-11 09:59:01 +00:00
|
|
|
|
multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0),
|
|
|
|
|
need_centering_(false), last_inset_(0), gui_(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
ScrollbarParameters scrollbarParameters_;
|
|
|
|
|
///
|
|
|
|
|
ViewMetricsInfo metrics_info_;
|
|
|
|
|
///
|
|
|
|
|
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_;
|
|
|
|
|
///
|
|
|
|
|
bool multiparsel_cache_;
|
|
|
|
|
///
|
|
|
|
|
pit_type anchor_ref_;
|
|
|
|
|
///
|
|
|
|
|
int offset_ref_;
|
|
|
|
|
///
|
|
|
|
|
bool need_centering_;
|
|
|
|
|
|
|
|
|
|
/// 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_;
|
|
|
|
|
};
|
|
|
|
|
|
2007-09-29 20:25:50 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BufferView::BufferView(Buffer & buf)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
: width_(0), height_(0), 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)
|
|
|
|
|
graphics::Previews::get().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.
|
|
|
|
|
LyX::ref().session().lastFilePos().save(
|
2007-10-20 10:03:45 +00:00
|
|
|
|
support::FileName(buffer_.absFileName()),
|
2007-10-13 07:33:07 +00:00
|
|
|
|
boost::tie(d->cursor_.bottom().pit(), d->cursor_.bottom().pos()) );
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-13 07:33:07 +00:00
|
|
|
|
theFontMetrics(d->cursor_.getFont());
|
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;
|
|
|
|
|
}
|
|
|
|
|
center();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BufferView::multiParSel()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (!d->cursor_.selection())
|
2006-09-16 10:08:51 +00:00
|
|
|
|
return false;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
bool ret = d->multiparsel_cache_;
|
|
|
|
|
d->multiparsel_cache_ = d->cursor_.selBegin().pit() != d->cursor_.selEnd().pit();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Either this, or previous selection spans paragraphs
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return ret || d->multiparsel_cache_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-04-01 15:09:08 +00:00
|
|
|
|
LYXERR(Debug::DEBUG)
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "[fitcursor = " << (flags & Update::FitCursor)
|
|
|
|
|
<< ", forceupdate = " << (flags & Update::Force)
|
|
|
|
|
<< ", singlepar = " << (flags & Update::SinglePar)
|
2007-08-21 07:33:46 +00:00
|
|
|
|
<< "] buffer: " << &buffer_ << endl;
|
2006-10-21 10:56:36 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
// Update macro store
|
2007-04-19 13:37:17 +00:00
|
|
|
|
if (!(cursor().inMathed() && cursor().inMacroMode()))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.buildMacros();
|
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-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_.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-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_.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-11-21 16:58:45 +00:00
|
|
|
|
bool const fit_cursor = fitCursor();
|
2006-12-07 11:46:27 +00:00
|
|
|
|
// tell the frontend to update the screen if needed.
|
2007-01-20 01:23:07 +00:00
|
|
|
|
if (fit_cursor) {
|
|
|
|
|
updateMetrics(false);
|
2007-10-10 08:52:55 +00:00
|
|
|
|
buffer_.changed();
|
|
|
|
|
return;
|
2007-01-20 01:23:07 +00:00
|
|
|
|
}
|
|
|
|
|
if (flags & Update::Decoration) {
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_.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-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_.update_strategy = NoScreenUpdate;
|
2007-10-10 08:52:55 +00:00
|
|
|
|
return;
|
2006-11-21 16:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-20 14:42:18 +00:00
|
|
|
|
bool full_metrics = flags & Update::Force;
|
|
|
|
|
if (flags & Update::MultiParSel)
|
|
|
|
|
full_metrics |= multiParSel();
|
|
|
|
|
|
|
|
|
|
bool const single_par = !full_metrics;
|
2006-11-17 17:42:52 +00:00
|
|
|
|
updateMetrics(single_par);
|
|
|
|
|
|
2007-10-10 08:52:55 +00:00
|
|
|
|
if (!(flags & Update::FitCursor)) {
|
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-10-10 08:52:55 +00:00
|
|
|
|
//FIXME: updateMetrics() does not update paragraph position
|
|
|
|
|
// This is done at draw() time. So we need a redraw!
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
if (!fitCursor())
|
|
|
|
|
// The screen has already been updated thanks to the
|
|
|
|
|
// 'buffer_.changed()' call three line above. So no need
|
|
|
|
|
// to redraw again.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// The screen has been recentered around the cursor position so
|
|
|
|
|
// refresh it:
|
|
|
|
|
updateMetrics(false);
|
|
|
|
|
buffer_.changed();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateScrollbar()
|
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & t = buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[&t];
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const parsize = int(t.paragraphs().size() - 1);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->anchor_ref_ > parsize) {
|
|
|
|
|
d->anchor_ref_ = parsize;
|
|
|
|
|
d->offset_ref_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 15:09:08 +00:00
|
|
|
|
LYXERR(Debug::GUI)
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< " Updating scrollbar: height: " << t.paragraphs().size()
|
2007-10-13 07:33:07 +00:00
|
|
|
|
<< " curr par: " << d->cursor_.bottom().pit()
|
2007-04-01 15:09:08 +00:00
|
|
|
|
<< " default height " << defaultRowHeight() << endl;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// It would be better to fix the scrollbar to understand
|
|
|
|
|
// values in [0..1] and divide everything by wh
|
|
|
|
|
|
|
|
|
|
// estimated average paragraph height:
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->wh_ == 0)
|
|
|
|
|
d->wh_ = height_ / 4;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
int h = tm.parMetrics(d->anchor_ref_).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Normalize anchor/offset (MV):
|
2007-10-13 07:33:07 +00:00
|
|
|
|
while (d->offset_ref_ > h && d->anchor_ref_ < parsize) {
|
|
|
|
|
d->anchor_ref_++;
|
|
|
|
|
d->offset_ref_ -= h;
|
|
|
|
|
h = tm.parMetrics(d->anchor_ref_).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
// Look at paragraph heights on-screen
|
|
|
|
|
int sumh = 0;
|
|
|
|
|
int nh = 0;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
for (pit_type pit = d->anchor_ref_; pit <= parsize; ++pit) {
|
2006-09-16 10:08:51 +00:00
|
|
|
|
if (sumh > height_)
|
|
|
|
|
break;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
int const h2 = tm.parMetrics(pit).height();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
sumh += h2;
|
|
|
|
|
nh++;
|
|
|
|
|
}
|
2006-10-26 08:10:22 +00:00
|
|
|
|
|
|
|
|
|
BOOST_ASSERT(nh);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const hav = sumh / nh;
|
|
|
|
|
// More realistic average paragraph height
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (hav > d->wh_)
|
|
|
|
|
d->wh_ = hav;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-10-26 08:10:22 +00:00
|
|
|
|
BOOST_ASSERT(h);
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->scrollbarParameters_.height = (parsize + 1) * d->wh_;
|
|
|
|
|
d->scrollbarParameters_.position = d->anchor_ref_ * d->wh_ + int(d->offset_ref_ * d->wh_ / float(h));
|
|
|
|
|
d->scrollbarParameters_.lineScrollHeight = int(d->wh_ * defaultRowHeight() / float(h));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
|
void BufferView::scrollDocView(int value)
|
2001-02-19 16:01:31 +00:00
|
|
|
|
{
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< "[ value = " << value << "]" << endl;
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Text & t = buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[&t];
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
float const bar = value / float(d->wh_ * t.paragraphs().size());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->anchor_ref_ = int(bar * t.paragraphs().size());
|
|
|
|
|
if (d->anchor_ref_ > int(t.paragraphs().size()) - 1)
|
|
|
|
|
d->anchor_ref_ = int(t.paragraphs().size()) - 1;
|
2006-12-29 23:54:48 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
tm.redoParagraph(d->anchor_ref_);
|
|
|
|
|
int const h = tm.parMetrics(d->anchor_ref_).height();
|
|
|
|
|
d->offset_ref_ = int((bar * t.paragraphs().size() - d->anchor_ref_) * h);
|
2006-11-20 14:42:18 +00:00
|
|
|
|
updateMetrics(false);
|
2007-09-15 13:59:26 +00:00
|
|
|
|
buffer_.changed();
|
2001-02-19 16:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor & cur = d->cursor_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-09-29 08:02:37 +00:00
|
|
|
|
switch (cursorStatus(cur)) {
|
|
|
|
|
case CUR_ABOVE:
|
|
|
|
|
// We reset the cursor because cursorStatus() does not
|
2007-01-27 09:04:36 +00:00
|
|
|
|
// work when the cursor is within mathed.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.reset(buffer_.inset());
|
2007-09-02 09:44:08 +00:00
|
|
|
|
tm.setCursorFromCoordinates(cur, 0, first);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
|
case CUR_BELOW:
|
|
|
|
|
// We reset the cursor because cursorStatus() does not
|
2007-01-27 09:04:36 +00:00
|
|
|
|
// work when the cursor is within mathed.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.reset(buffer_.inset());
|
2007-09-02 09:44:08 +00:00
|
|
|
|
tm.setCursorFromCoordinates(cur, 0, last);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
cur.clearSelection();
|
|
|
|
|
break;
|
2007-09-29 08:02:37 +00:00
|
|
|
|
case CUR_INSIDE:
|
2007-09-29 09:22:17 +00:00
|
|
|
|
int const y = getPos(cur, cur.boundary()).y_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int const newy = min(last, max(y, first));
|
|
|
|
|
if (y != newy) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.reset(buffer_.inset());
|
2007-09-02 09:44:08 +00:00
|
|
|
|
tm.setCursorFromCoordinates(cur, 0, newy);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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.
|
2006-11-01 15:55:17 +00:00
|
|
|
|
LyX::ref().session().bookmarks().save(
|
2007-10-20 10:03:45 +00:00
|
|
|
|
FileName(buffer_.absFileName()),
|
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;
|
|
|
|
|
DocIterator doc_it;
|
|
|
|
|
|
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) {
|
2007-08-21 07:33:46 +00:00
|
|
|
|
ParIterator par = buffer_.getParFromID(top_id);
|
|
|
|
|
if (par != buffer_.par_iterator_end()) {
|
2007-08-22 14:25:51 +00:00
|
|
|
|
doc_it = makeDocIterator(par, min(par->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.
|
2007-08-22 14:25:51 +00:00
|
|
|
|
size_t const n = doc_it.depth();
|
2007-04-16 20:47:40 +00:00
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2007-08-22 14:25:51 +00:00
|
|
|
|
if (doc_it[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
|
|
|
|
|
doc_it.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.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (static_cast<size_t>(bottom_pit) < buffer_.paragraphs().size()) {
|
2007-08-22 14:25:51 +00:00
|
|
|
|
doc_it = doc_iterator_begin(buffer_.inset());
|
|
|
|
|
doc_it.pit() = bottom_pit;
|
|
|
|
|
doc_it.pos() = min(bottom_pos, doc_it.paragraph().size());
|
|
|
|
|
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.
|
|
|
|
|
setCursor(doc_it);
|
|
|
|
|
// set the current font.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setCurrentFont();
|
2007-08-22 14:25:51 +00:00
|
|
|
|
// center the screen on this new position.
|
|
|
|
|
center();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-08-22 14:14:52 +00:00
|
|
|
|
void BufferView::updateOffsetRef()
|
2000-02-17 19:59:08 +00:00
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
// No need to update d->offset_ref_ in this case.
|
|
|
|
|
if (!d->need_centering_)
|
2007-08-22 14:14:52 +00:00
|
|
|
|
return;
|
|
|
|
|
|
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-10-13 07:33:07 +00:00
|
|
|
|
CursorSlice & bot = d->cursor_.bottom();
|
|
|
|
|
TextMetrics & tm = d->text_metrics_[bot.text()];
|
2007-08-22 14:44:34 +00:00
|
|
|
|
ParagraphMetrics const & pm = tm.parMetrics(bot.pit());
|
2007-10-13 07:33:07 +00:00
|
|
|
|
int y = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
|
|
|
|
|
d->offset_ref_ = y + pm.ascent() - height_ / 2;
|
2007-08-22 14:14:52 +00:00
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->need_centering_ = false;
|
2007-08-22 14:14:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::center()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->anchor_ref_ = d->cursor_.bottom().pit();
|
|
|
|
|
d->need_centering_ = true;
|
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:
|
2007-10-18 15:38:12 +00:00
|
|
|
|
flag.enabled(buffer_.undo().hasUndoStack());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2007-10-18 15:38:12 +00:00
|
|
|
|
flag.enabled(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
|
2007-06-10 15:07:21 +00:00
|
|
|
|
flag.enabled(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:
|
2006-09-16 10:08:51 +00:00
|
|
|
|
case LFUN_PARAGRAPH_GOTO:
|
|
|
|
|
// FIXME handle non-trivially
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
|
|
|
|
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:
|
|
|
|
|
case LFUN_WORDS_COUNT:
|
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LABEL_GOTO: {
|
|
|
|
|
flag.enabled(!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:
|
|
|
|
|
flag.enabled(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:
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(true);
|
|
|
|
|
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.
|
2007-08-21 07:33:46 +00:00
|
|
|
|
flag.enabled(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-09-15 12:28:41 +00:00
|
|
|
|
case LFUN_SCREEN_UP:
|
|
|
|
|
case LFUN_SCREEN_DOWN:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// FIXME: LFUN_SCREEN_DOWN_SELECT should be removed from
|
|
|
|
|
// everywhere else before this can enabled:
|
|
|
|
|
case LFUN_SCREEN_UP_SELECT:
|
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-10-11 13:20:21 +00:00
|
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2007-10-13 09:04:52 +00:00
|
|
|
|
flag.enabled(cur.innerInsetOfType(TABULAR_CODE));
|
2007-10-11 13:20:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
|
|
|
|
flag.enabled(cur.inset().forceDefaultParagraphs(cur.idx()));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_SETTINGS: {
|
2007-10-13 09:04:52 +00:00
|
|
|
|
InsetCode code = cur.inset().lyxCode();
|
2007-10-11 13:20:21 +00:00
|
|
|
|
bool enable = false;
|
|
|
|
|
switch (code) {
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case TABULAR_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "tabular";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case ERT_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "ert";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case FLOAT_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "float";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case WRAP_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "wrap";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case NOTE_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "note";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case BRANCH_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "branch";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case BOX_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "box";
|
|
|
|
|
break;
|
2007-10-13 09:04:52 +00:00
|
|
|
|
case LISTINGS_CODE:
|
2007-10-11 13:20:21 +00:00
|
|
|
|
enable = cmd.argument() == "listings";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
flag.enabled(enable);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET:
|
2007-10-13 09:04:52 +00:00
|
|
|
|
flag.enabled(cur.inset().lyxCode() != ERT_CODE &&
|
|
|
|
|
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;
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
default:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
2004-04-01 08:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
Update::flags BufferView::dispatch(FuncRequest const & cmd)
|
2001-02-23 16:10:03 +00:00
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION
|
|
|
|
|
// << [ cmd = " << cmd << "]" << endl;
|
|
|
|
|
|
|
|
|
|
// Make sure that the cached BufferView is correct.
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< " 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 << ']'
|
|
|
|
|
<< " button[" << cmd.button() << ']'
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
Cursor & cur = d->cursor_;
|
2007-01-24 23:10:03 +00:00
|
|
|
|
// Default Update flags.
|
|
|
|
|
Update::flags updateFlags = Update::Force | Update::FitCursor;
|
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-10-18 11:51:17 +00:00
|
|
|
|
if (!cur.textUndo()) {
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("No further undo information"));
|
|
|
|
|
updateFlags = Update::None;
|
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-10-18 11:51:17 +00:00
|
|
|
|
if (!cur.textRedo()) {
|
2007-01-24 23:10:03 +00:00
|
|
|
|
cur.message(_("No further redo information"));
|
|
|
|
|
updateFlags = Update::None;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FILE_INSERT:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
menuInsertLyXFile(to_utf8(cmd.argument()));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-10-03 20:15:49 +00:00
|
|
|
|
insertPlaintextFile(to_utf8(cmd.argument()), true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-01-15 22:49:14 +00:00
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-10-03 20:15:49 +00:00
|
|
|
|
insertPlaintextFile(to_utf8(cmd.argument()), false);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_PARAGRAPH_GOTO: {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
int const id = convert<int>(to_utf8(cmd.argument()));
|
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)) {
|
|
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
ParIterator par = b->getParFromID(id);
|
|
|
|
|
if (par == b->par_iterator_end()) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INFO)
|
2006-11-13 16:53:49 +00:00
|
|
|
|
<< "No matching paragraph found! ["
|
|
|
|
|
<< id << "]." << endl;
|
|
|
|
|
} else {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INFO)
|
2006-11-13 16:53:49 +00:00
|
|
|
|
<< "Paragraph " << par->id()
|
|
|
|
|
<< " found in buffer `"
|
2007-10-20 10:03:45 +00:00
|
|
|
|
<< b->absFileName() << "'." << endl;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
if (b == &buffer_) {
|
2006-11-13 16:53:49 +00:00
|
|
|
|
// Set the cursor
|
|
|
|
|
setCursor(makeDocIterator(par, 0));
|
|
|
|
|
} else {
|
|
|
|
|
// Switch to other buffer view and resend cmd
|
|
|
|
|
theLyXFunc().dispatch(FuncRequest(
|
2007-10-20 10:03:45 +00:00
|
|
|
|
LFUN_BUFFER_SWITCH, b->absFileName()));
|
2006-11-13 16:53:49 +00:00
|
|
|
|
theLyXFunc().dispatch(cmd);
|
2007-01-24 23:10:03 +00:00
|
|
|
|
updateFlags = Update::None;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_OUTLINE_UP:
|
2007-10-13 07:33:07 +00:00
|
|
|
|
outline(OutlineUp, d->cursor_);
|
|
|
|
|
d->cursor_.text()->setCursor(d->cursor_, d->cursor_.pit(), 0);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_DOWN:
|
2007-10-13 07:33:07 +00:00
|
|
|
|
outline(OutlineDown, d->cursor_);
|
|
|
|
|
d->cursor_.text()->setCursor(d->cursor_, d->cursor_.pit(), 0);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_IN:
|
2007-10-13 07:33:07 +00:00
|
|
|
|
outline(OutlineIn, d->cursor_);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_OUTLINE_OUT:
|
2007-10-13 07:33:07 +00:00
|
|
|
|
outline(OutlineOut, d->cursor_);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
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);
|
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);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_WORD_FIND:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
find(this, cmd);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
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();
|
|
|
|
|
cur.mark() = true;
|
|
|
|
|
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()) {
|
|
|
|
|
cur.mark() = 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 {
|
|
|
|
|
cur.mark() = 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:
|
|
|
|
|
center();
|
|
|
|
|
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) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->addDatabase(to_utf8(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) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (inset->delDatabase(to_utf8(cmd.argument())))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.updateBibfilesCache();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_WORDS_COUNT: {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
int const count = countWords(from, to);
|
|
|
|
|
docstring message;
|
|
|
|
|
if (count != 1) {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = bformat(_("%1$d words in selection."),
|
|
|
|
|
count);
|
|
|
|
|
else
|
|
|
|
|
message = bformat(_("%1$d words in document."),
|
|
|
|
|
count);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (cur.selection())
|
|
|
|
|
message = _("One word in selection.");
|
|
|
|
|
else
|
|
|
|
|
message = _("One word in document.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert::information(_("Count words"), message);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
case LFUN_NEXT_INSET_TOGGLE: {
|
|
|
|
|
// this is the real function we want to invoke
|
|
|
|
|
FuncRequest tmpcmd = FuncRequest(LFUN_INSET_TOGGLE, cmd.origin);
|
|
|
|
|
// 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;
|
|
|
|
|
tmpcur.pushLeft(*inset);
|
|
|
|
|
inset->dispatch(tmpcur, tmpcmd);
|
|
|
|
|
if (tmpcur.result().dispatched()) {
|
|
|
|
|
cur.dispatched();
|
|
|
|
|
}
|
|
|
|
|
} else if (inset->editable() == Inset::IS_EDITABLE) {
|
|
|
|
|
inset->edit(cur, true);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if it did not work, try the underlying inset.
|
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(tmpcmd);
|
|
|
|
|
|
|
|
|
|
if (cur.result().dispatched())
|
|
|
|
|
cur.clearSelection();
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
center();
|
|
|
|
|
updateMetrics(false);
|
|
|
|
|
//FIXME: updateMetrics() does not update paragraph position
|
|
|
|
|
// This is done at draw() time. So we need a redraw!
|
|
|
|
|
buffer_.changed();
|
2007-09-29 09:22:17 +00:00
|
|
|
|
p = getPos(cur, cur.boundary());
|
2007-09-15 14:33:37 +00:00
|
|
|
|
}
|
2007-09-15 12:28:41 +00:00
|
|
|
|
scroll(cmd.action == LFUN_SCREEN_UP? - height_ : height_);
|
|
|
|
|
cur.reset(buffer_.inset());
|
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
|
|
|
|
// The metrics are already up to date. see scroll()
|
|
|
|
|
updateFlags = Update::None;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_SCREEN_UP_SELECT:
|
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT: {
|
|
|
|
|
cur.selHandle(true);
|
|
|
|
|
size_t initial_depth = cur.depth();
|
2007-09-29 09:22:17 +00:00
|
|
|
|
Point const p = getPos(cur, cur.boundary());
|
2007-09-15 12:28:41 +00:00
|
|
|
|
scroll(cmd.action == LFUN_SCREEN_UP_SELECT? - height_ : height_);
|
|
|
|
|
// FIXME: We need to verify if the cursor stayed within an inset...
|
|
|
|
|
//cur.reset(buffer_.inset());
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.finishUndo();
|
2007-09-15 12:28:41 +00:00
|
|
|
|
while (cur.depth() > initial_depth) {
|
|
|
|
|
cur.forwardInset();
|
|
|
|
|
}
|
|
|
|
|
// FIXME: we need to do a redraw again because of the selection
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
updateFlags = Update::Force | Update::FitCursor;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 10:08:51 +00:00
|
|
|
|
default:
|
2007-01-24 23:10:03 +00:00
|
|
|
|
updateFlags = Update::None;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-24 23:10:03 +00:00
|
|
|
|
return updateFlags;
|
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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
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-08-21 07:33:46 +00:00
|
|
|
|
updateMetrics(false);
|
* 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-04-29 23:33:02 +00:00
|
|
|
|
Inset const * BufferView::getCoveringInset(Text const & text, int x, int y)
|
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
|
|
|
|
{
|
2006-09-16 10:08:51 +00:00
|
|
|
|
//lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
|
|
|
|
|
|
|
|
|
|
// This is only called for mouse related events including
|
|
|
|
|
// LFUN_FILE_OPEN generated by drag-and-drop.
|
|
|
|
|
FuncRequest cmd = cmd0;
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor cur(*this);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
cur.push(buffer_.inset());
|
2007-10-13 07:33:07 +00:00
|
|
|
|
cur.selection() = 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
|
|
|
|
|
|
|
|
|
// if last metrics update was in singlepar mode, WorkArea::redraw() will
|
|
|
|
|
// not expose the button for redraw. We adjust here the metrics dimension
|
2007-09-25 08:47:54 +00:00
|
|
|
|
// to enable a full redraw in any case as this is not costly.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics & tm = d->text_metrics_[&buffer_.text()];
|
2007-09-25 08:47:54 +00:00
|
|
|
|
std::pair<pit_type, ParagraphMetrics const *> firstpm = tm.first();
|
|
|
|
|
std::pair<pit_type, ParagraphMetrics const *> lastpm = tm.last();
|
|
|
|
|
int y1 = firstpm.second->position() - firstpm.second->ascent();
|
|
|
|
|
int y2 = lastpm.second->position() + lastpm.second->descent();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_ = ViewMetricsInfo(firstpm.first, lastpm.first, y1, y2,
|
2007-09-25 08:47:54 +00:00
|
|
|
|
FullScreenUpdate, buffer_.text().paragraphs().size());
|
|
|
|
|
// Reinitialize anchor to first pit.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->anchor_ref_ = firstpm.first;
|
|
|
|
|
d->offset_ref_ = -y1;
|
2007-09-25 08:47:54 +00:00
|
|
|
|
LYXERR(Debug::PAINTING)
|
|
|
|
|
<< "Mouse hover detected at: (" << cmd.x << ", " << cmd.y << ")"
|
|
|
|
|
<< "\nTriggering redraw: y1: " << y1 << " y2: " << y2
|
|
|
|
|
<< " pit1: " << firstpm.first << " pit2: " << lastpm.first << endl;
|
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();
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
if (!cur.result().dispatched())
|
|
|
|
|
cur.dispatch(cmd);
|
|
|
|
|
|
2007-08-10 10:21:09 +00:00
|
|
|
|
//Do we have a selection?
|
|
|
|
|
theSelection().haveSelection(cursor().selection());
|
|
|
|
|
|
2007-10-05 09:38:40 +00:00
|
|
|
|
// If the command has been dispatched,
|
|
|
|
|
if (cur.result().dispatched()
|
|
|
|
|
// an update is asked,
|
2007-10-10 08:52:55 +00:00
|
|
|
|
&& cur.result().update())
|
|
|
|
|
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-09-15 12:28:41 +00:00
|
|
|
|
void BufferView::scroll(int y)
|
2002-08-28 10:45:38 +00:00
|
|
|
|
{
|
2007-09-15 12:28:41 +00:00
|
|
|
|
if (y > 0)
|
|
|
|
|
scrollDown(y);
|
|
|
|
|
else if (y < 0)
|
|
|
|
|
scrollUp(-y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::scrollDown(int offset)
|
|
|
|
|
{
|
|
|
|
|
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-09-20 08:48:28 +00:00
|
|
|
|
std::pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
|
|
|
|
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_)
|
|
|
|
|
return;
|
|
|
|
|
offset = min(offset, bottom_pos - height_);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (bottom_pos > ymax)
|
|
|
|
|
break;
|
|
|
|
|
tm.newParMetricsDown();
|
|
|
|
|
}
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->offset_ref_ += offset;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
updateMetrics(false);
|
|
|
|
|
buffer_.changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::scrollUp(int offset)
|
|
|
|
|
{
|
|
|
|
|
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-09-20 08:48:28 +00:00
|
|
|
|
std::pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
|
|
|
|
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)
|
|
|
|
|
return;
|
|
|
|
|
offset = min(offset, - top_pos);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (top_pos < ymin)
|
|
|
|
|
break;
|
|
|
|
|
tm.newParMetricsUp();
|
|
|
|
|
}
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->offset_ref_ -= offset;
|
2007-09-15 12:28:41 +00:00
|
|
|
|
updateMetrics(false);
|
|
|
|
|
buffer_.changed();
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-12 10:50:45 +00:00
|
|
|
|
void BufferView::gotoLabel(docstring const & label)
|
2002-08-29 13:05:55 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
for (InsetIterator it = inset_iterator_begin(buffer_.inset()); it; ++it) {
|
2006-10-12 10:50:45 +00:00
|
|
|
|
vector<docstring> labels;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
it->getLabelList(buffer_, labels);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (std::find(labels.begin(), labels.end(), label) != labels.end()) {
|
2005-02-22 11:41:22 +00:00
|
|
|
|
setCursor(it);
|
2007-10-10 08:52:55 +00:00
|
|
|
|
processUpdateFlags(Update::FitCursor);
|
2003-03-29 10:29:38 +00:00
|
|
|
|
return;
|
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);
|
|
|
|
|
d->cursor_.selection() = 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-08-21 07:33:46 +00:00
|
|
|
|
updateLabels(buffer_);
|
2007-01-31 14:07:37 +00:00
|
|
|
|
|
2006-12-30 15:05:15 +00:00
|
|
|
|
updateMetrics(false);
|
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
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(&cur.bv() == this);
|
|
|
|
|
|
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());
|
2007-04-10 16:50:19 +00:00
|
|
|
|
if (leftinset)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
badcursor = notifyCursorLeaves(d->cursor_, cur);
|
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
|
|
|
|
|
2007-01-17 15:32:43 +00:00
|
|
|
|
// if the cursor was in an empty script inset and the new
|
|
|
|
|
// position is in the nucleus of the inset, notifyCursorLeaves
|
|
|
|
|
// will kill the script inset itself. So we check all the
|
|
|
|
|
// elements of the cursor to make sure that they are correct.
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// For an example, see bug 2933:
|
|
|
|
|
// http://bugzilla.lyx.org/show_bug.cgi?id=2933
|
2007-01-17 15:32:43 +00:00
|
|
|
|
// The code below could maybe be moved to a DocIterator method.
|
|
|
|
|
//lyxerr << "cur before " << cur <<std::endl;
|
|
|
|
|
DocIterator dit(cur.inset());
|
|
|
|
|
dit.push_back(cur.bottom());
|
|
|
|
|
size_t i = 1;
|
|
|
|
|
while (i < cur.depth() && dit.nextInset() == &cur[i].inset()) {
|
|
|
|
|
dit.push_back(cur[i]);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
//lyxerr << "5 cur after" << dit <<std::endl;
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->cursor_.setCursor(dit);
|
|
|
|
|
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();
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-10-13 07:33:07 +00:00
|
|
|
|
return d->anchor_ref_;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-04 00:04:46 +00:00
|
|
|
|
ViewMetricsInfo const & BufferView::viewMetricsInfo()
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
return d->metrics_info_;
|
2006-07-04 00:04:46 +00:00
|
|
|
|
}
|
2006-07-08 20:24:32 +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();
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
int y1 = pm.position() - pm.ascent();
|
|
|
|
|
int y2 = pm.position() + pm.descent();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_ = ViewMetricsInfo(bottom_pit, bottom_pit, y1, y2,
|
2007-09-28 09:11:24 +00:00
|
|
|
|
SingleParUpdate, buftext.paragraphs().size());
|
|
|
|
|
LYXERR(Debug::PAINTING)
|
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
|
|
|
|
<< "\ny1: " << y1
|
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< " pit: " << bottom_pit
|
|
|
|
|
<< " singlepar: 1"
|
|
|
|
|
<< endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-14 09:56:21 +00:00
|
|
|
|
void BufferView::updateMetrics(bool singlepar)
|
2006-07-08 20:24:32 +00:00
|
|
|
|
{
|
2007-09-28 09:11:24 +00:00
|
|
|
|
if (singlepar && singleParUpdate())
|
|
|
|
|
// No need to update the full screen metrics.
|
|
|
|
|
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-10-13 07:33:07 +00:00
|
|
|
|
if (d->anchor_ref_ > int(npit - 1)) {
|
|
|
|
|
d->anchor_ref_ = int(npit - 1);
|
|
|
|
|
d->offset_ref_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
2007-05-28 22:27:45 +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
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
pit_type const pit = d->anchor_ref_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int pit1 = pit;
|
|
|
|
|
int pit2 = pit;
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Rebreak anchor paragraph.
|
2007-09-11 16:04:10 +00:00
|
|
|
|
tm.redoParagraph(pit);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-09-28 09:11:24 +00:00
|
|
|
|
// Take care of anchor offset if case a recentering is needed.
|
2007-08-22 14:14:52 +00:00
|
|
|
|
updateOffsetRef();
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
int y0 = tm.parMetrics(pit).ascent() - d->offset_ref_;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs above anchor if necessary.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int y1 = y0;
|
|
|
|
|
while (y1 > 0 && pit1 > 0) {
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 -= tm.parMetrics(pit1).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
--pit1;
|
2007-09-11 16:04:10 +00:00
|
|
|
|
tm.redoParagraph(pit1);
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 -= tm.parMetrics(pit1).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Take care of ascent of first line
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y1 -= tm.parMetrics(pit1).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Normalize anchor for next time
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->anchor_ref_ = pit1;
|
|
|
|
|
d->offset_ref_ = -y1;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// Grey at the beginning is ugly
|
|
|
|
|
if (pit1 == 0 && y1 > 0) {
|
|
|
|
|
y0 -= y1;
|
|
|
|
|
y1 = 0;
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->anchor_ref_ = 0;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-01-06 09:15:59 +00:00
|
|
|
|
// Redo paragraphs below the anchor if necessary.
|
2006-09-16 10:08:51 +00:00
|
|
|
|
int y2 = y0;
|
|
|
|
|
while (y2 < height_ && pit2 < int(npit) - 1) {
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y2 += tm.parMetrics(pit2).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
++pit2;
|
2007-09-11 16:04:10 +00:00
|
|
|
|
tm.redoParagraph(pit2);
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y2 += tm.parMetrics(pit2).ascent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Take care of descent of last line
|
2006-12-29 23:54:48 +00:00
|
|
|
|
y2 += tm.parMetrics(pit2).descent();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2007-09-11 16:04:10 +00:00
|
|
|
|
LYXERR(Debug::PAINTING)
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< BOOST_CURRENT_FUNCTION
|
2007-09-11 16:04:10 +00:00
|
|
|
|
<< "\n y1: " << y1
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< " y2: " << y2
|
|
|
|
|
<< " pit1: " << pit1
|
|
|
|
|
<< " pit2: " << pit2
|
|
|
|
|
<< " npit: " << npit
|
2007-09-28 09:11:24 +00:00
|
|
|
|
<< " singlepar: 0"
|
2006-09-16 10:08:51 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
|
2007-10-13 07:33:07 +00:00
|
|
|
|
d->metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2,
|
2007-09-11 16:04:10 +00:00
|
|
|
|
FullScreenUpdate, npit);
|
2006-10-20 20:57:21 +00:00
|
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::WORKAREA)) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::WORKAREA) << "BufferView::updateMetrics" << endl;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::menuInsertLyXFile(string const & filenm)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
BOOST_ASSERT(d->cursor_.inTexted());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
string filename = filenm;
|
|
|
|
|
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// Launch a file browser
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-09-16 10:08:51 +00:00
|
|
|
|
string initpath = lyxrc.document_path;
|
2007-08-21 07:33:46 +00:00
|
|
|
|
string const trypath = buffer_.filePath();
|
|
|
|
|
// If directory is writeable, use this as default.
|
2007-10-18 23:03:51 +00:00
|
|
|
|
if (FileName(trypath).isDirWritable())
|
2007-08-21 07:33:46 +00:00
|
|
|
|
initpath = trypath;
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
FileDialog fileDlg(_("Select LyX document to insert"),
|
2006-09-16 10:08:51 +00:00
|
|
|
|
LFUN_FILE_INSERT,
|
2006-10-21 00:16:43 +00:00
|
|
|
|
make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
|
2007-06-10 15:07:21 +00:00
|
|
|
|
make_pair(_("Examples|#E#e"),
|
|
|
|
|
from_utf8(addPath(package().system_support().absFilename(),
|
|
|
|
|
"examples"))));
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2006-10-21 00:16:43 +00:00
|
|
|
|
fileDlg.open(from_utf8(initpath),
|
2006-10-09 16:33:20 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
docstring());
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
2006-10-09 16:33:20 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
filename = to_utf8(result.second);
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(_("Canceled."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get absolute path of file and add ".lyx"
|
|
|
|
|
// to the filename if necessary
|
2006-11-26 21:30:39 +00:00
|
|
|
|
filename = fileSearch(string(), filename, "lyx").absFilename();
|
2006-09-16 10:08:51 +00:00
|
|
|
|
|
|
|
|
|
docstring const disp_fn = makeDisplayPath(filename);
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(_("Inserting document %1$s..."), disp_fn));
|
|
|
|
|
|
|
|
|
|
docstring res;
|
|
|
|
|
Buffer buf("", false);
|
2007-10-21 10:50:56 +00:00
|
|
|
|
if (buf.loadLyXFile(FileName(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(),
|
2007-09-18 17:46:14 +00:00
|
|
|
|
buf.params().getTextClassPtr(), 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
|
|
|
|
|
|
|
|
|
// emit message signal.
|
|
|
|
|
message(bformat(res, disp_fn));
|
2007-08-21 07:33:46 +00:00
|
|
|
|
buffer_.errors("Parse");
|
|
|
|
|
updateMetrics(false);
|
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());
|
|
|
|
|
BOOST_ASSERT(!pm.rows().empty());
|
|
|
|
|
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;
|
|
|
|
|
// lyxerr << "coordOffset: boundary:" << boundary << " depth:" << dit.depth() << " pos:" << pos << " sl.pos:" << sl.pos() << std::endl;
|
|
|
|
|
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());
|
|
|
|
|
if (!tm.has(bot.pit()))
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
PainterInfo pi(this, pain);
|
|
|
|
|
// Should the whole screen, including insets, be refreshed?
|
|
|
|
|
// 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.
|
2007-10-13 07:33:07 +00:00
|
|
|
|
pi.full_repaint = d->metrics_info_.update_strategy != SingleParUpdate;
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
2007-08-30 15:17:38 +00:00
|
|
|
|
if (pi.full_repaint)
|
2007-08-27 22:53:16 +00:00
|
|
|
|
// Clear background (if not delegated to rows)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
pain.fillRectangle(0, d->metrics_info_.y1, width_,
|
|
|
|
|
d->metrics_info_.y2 - d->metrics_info_.y1,
|
2007-09-02 14:34:15 +00:00
|
|
|
|
buffer_.inset().backgroundColor());
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
2007-09-01 09:33:57 +00:00
|
|
|
|
LYXERR(Debug::PAINTING) << "\t\t*** START DRAWING ***" << endl;
|
2007-09-05 13:29:31 +00:00
|
|
|
|
Text & text = buffer_.text();
|
2007-10-13 07:33:07 +00:00
|
|
|
|
TextMetrics const & tm = d->text_metrics_[&text];
|
|
|
|
|
int y = d->metrics_info_.y1 + tm.parMetrics(d->metrics_info_.p1).ascent();
|
2007-09-05 13:04:05 +00:00
|
|
|
|
if (!pi.full_repaint)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
tm.drawParagraph(pi, d->metrics_info_.p1, 0, y);
|
2007-09-05 13:04:05 +00:00
|
|
|
|
else
|
2007-09-09 20:21:43 +00:00
|
|
|
|
tm.draw(pi, 0, y);
|
2007-09-01 09:33:57 +00:00
|
|
|
|
LYXERR(Debug::PAINTING) << "\n\t\t*** END DRAWING ***" << endl;
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
// and grey out above (should not happen later)
|
2007-10-13 07:33:07 +00:00
|
|
|
|
// lyxerr << "par ascent: " << text.getPar(d->metrics_info_.p1).ascent() << endl;
|
|
|
|
|
if (d->metrics_info_.y1 > 0
|
|
|
|
|
&& d->metrics_info_.update_strategy == FullScreenUpdate)
|
|
|
|
|
pain.fillRectangle(0, 0, width_, d->metrics_info_.y1, Color::bottomarea);
|
2007-08-27 22:53:16 +00:00
|
|
|
|
|
|
|
|
|
// and possibly grey out below
|
2007-10-13 07:33:07 +00:00
|
|
|
|
// lyxerr << "par descent: " << text.getPar(d->metrics_info_.p1).ascent() << endl;
|
|
|
|
|
if (d->metrics_info_.y2 < height_
|
|
|
|
|
&& d->metrics_info_.update_strategy == FullScreenUpdate)
|
|
|
|
|
pain.fillRectangle(0, d->metrics_info_.y2, width_,
|
|
|
|
|
height_ - d->metrics_info_.y2, Color::bottomarea);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::showDialog(std::string const & name)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
|
|
|
|
d->gui_->showDialog(name);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::showDialogWithData(std::string const & name,
|
|
|
|
|
std::string const & data)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
|
|
|
|
d->gui_->showDialogWithData(name, data);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::showInsetDialog(std::string const & name,
|
|
|
|
|
std::string const & data, Inset * inset)
|
|
|
|
|
{
|
2007-10-13 07:33:07 +00:00
|
|
|
|
if (d->gui_)
|
|
|
|
|
d->gui_->showInsetDialog(name, data, inset);
|
2007-10-02 18:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateDialog(std::string const & name, std::string const & data)
|
|
|
|
|
{
|
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
|
|
|
|
|
docstring BufferView::contentsOfPlaintextFile(string const & f,
|
2007-10-03 18:56:37 +00:00
|
|
|
|
bool asParagraph)
|
|
|
|
|
{
|
|
|
|
|
FileName fname(f);
|
|
|
|
|
|
|
|
|
|
if (fname.empty()) {
|
|
|
|
|
FileDialog fileDlg(_("Select file to insert"),
|
|
|
|
|
( asParagraph
|
|
|
|
|
? LFUN_FILE_INSERT_PLAINTEXT_PARA
|
|
|
|
|
: LFUN_FILE_INSERT_PLAINTEXT) );
|
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2007-10-03 20:15:49 +00:00
|
|
|
|
fileDlg.open(from_utf8(buffer().filePath()),
|
2007-10-03 18:56:37 +00:00
|
|
|
|
FileFilterList(), docstring());
|
|
|
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
|
|
fname = makeAbsPath(to_utf8(result.second));
|
|
|
|
|
|
|
|
|
|
if (fname.empty())
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fs::is_readable(fname.toFilesystemEncoding())) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ifstream ifs(fname.toFilesystemEncoding().c_str());
|
|
|
|
|
if (!ifs) {
|
|
|
|
|
docstring const error = from_ascii(strerror(errno));
|
|
|
|
|
docstring const file = makeDisplayPath(fname.absFilename(), 50);
|
|
|
|
|
docstring const text =
|
|
|
|
|
bformat(_("Could not open the specified document\n"
|
|
|
|
|
"%1$s\ndue to the error: %2$s"), file, error);
|
|
|
|
|
Alert::error(_("Could not open file"), text);
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
ifs.unsetf(std::ios::skipws);
|
2007-10-03 18:56:37 +00:00
|
|
|
|
istream_iterator<char> ii(ifs);
|
|
|
|
|
istream_iterator<char> end;
|
|
|
|
|
#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
|
|
|
|
|
// We use this until the compilers get better...
|
|
|
|
|
std::vector<char> tmp;
|
|
|
|
|
copy(ii, end, back_inserter(tmp));
|
|
|
|
|
string const tmpstr(tmp.begin(), tmp.end());
|
|
|
|
|
#else
|
|
|
|
|
// This is what we want to use and what we will use once the
|
|
|
|
|
// compilers get good enough.
|
|
|
|
|
//string tmpstr(ii, end); // yet a reason for using std::string
|
|
|
|
|
// alternate approach to get the file into a string:
|
|
|
|
|
string tmpstr;
|
|
|
|
|
copy(ii, end, back_inserter(tmpstr));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// FIXME UNICODE: We don't know the encoding of the file
|
|
|
|
|
docstring file_content = from_utf8(tmpstr);
|
|
|
|
|
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"));
|
|
|
|
|
file_content = from_local8bit(tmpstr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return normalize_c(file_content);
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 20:15:49 +00:00
|
|
|
|
|
2007-10-03 18:56:37 +00:00
|
|
|
|
void BufferView::insertPlaintextFile(string const & f, bool asParagraph)
|
|
|
|
|
{
|
2007-10-03 20:15:49 +00:00
|
|
|
|
docstring const tmpstr = contentsOfPlaintextFile(f, asParagraph);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|