lyx_mirror/src/textcursor.C
Alfredo Braunstein 025cb611e3 mouse selection patch
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8100 a592a061-630c-0410-9148-cb99ea01b6c8
2003-11-17 20:28:11 +00:00

70 lines
1.4 KiB
C

/**
* \file textcursor.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "textcursor.h"
#include "paragraph.h"
#include "ParagraphList_fwd.h"
#include "debug.h"
#include <string>
using std::string;
void TextCursor::setSelection()
{
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.par() < cursor.par() ||
(selection.cursor.par() == cursor.par()
&& selection.cursor.pos() < cursor.pos())) {
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())
{
selection.set(false);
}
}
void TextCursor::clearSelection()
{
selection.set(false);
selection.mark(false);
selection.end = cursor;
selection.start = cursor;
selection.cursor = cursor;
}