2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file textcursor.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
#include <config.h>
|
2003-06-27 13:13:04 +00:00
|
|
|
|
|
|
|
|
|
#include "textcursor.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-10-09 10:52:12 +00:00
|
|
|
|
#include "ParagraphList_fwd.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2003-06-27 13:13:04 +00:00
|
|
|
|
|
2003-08-05 10:54:19 +00:00
|
|
|
|
void TextCursor::setSelection()
|
2003-06-27 13:13:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
selection.end = selection.cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selection.set(true);
|
|
|
|
|
|
|
|
|
|
// and now the whole selection
|
|
|
|
|
if (selection.cursor.par() == cursor.par())
|
|
|
|
|
if (selection.cursor.pos() < cursor.pos()) {
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
} else {
|
|
|
|
|
selection.end = selection.cursor;
|
|
|
|
|
selection.start = cursor;
|
|
|
|
|
}
|
|
|
|
|
else if (selection.cursor.y() < cursor.y() ||
|
|
|
|
|
(selection.cursor.y() == cursor.y()
|
|
|
|
|
&& selection.cursor.x() < cursor.x())) {
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
selection.end = selection.cursor;
|
|
|
|
|
selection.start = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a selection with no contents is not a selection
|
|
|
|
|
if (selection.start.par() == selection.end.par() &&
|
|
|
|
|
selection.start.pos() == selection.end.pos())
|
2003-08-05 10:54:19 +00:00
|
|
|
|
{
|
2003-06-27 13:13:04 +00:00
|
|
|
|
selection.set(false);
|
2003-08-05 10:54:19 +00:00
|
|
|
|
}
|
2003-06-27 13:13:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TextCursor::clearSelection()
|
|
|
|
|
{
|
|
|
|
|
selection.set(false);
|
|
|
|
|
selection.mark(false);
|
2003-08-05 10:54:19 +00:00
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = cursor;
|
|
|
|
|
selection.cursor = cursor;
|
2003-06-27 13:13:04 +00:00
|
|
|
|
}
|
|
|
|
|
|