]> git.lyx.org Git - lyx.git/blob - src/textcursor.C
ws changes only
[lyx.git] / src / textcursor.C
1 /**
2  * \file textcursor.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "textcursor.h"
14 #include "paragraph.h"
15 #include "ParagraphList_fwd.h"
16
17 #include <string>
18
19 using std::string;
20
21
22 void TextCursor::setSelection()
23 {
24         if (!selection.set()) {
25                 selection.start = selection.cursor;
26                 selection.end = selection.cursor;
27         }
28
29         selection.set(true);
30
31         // and now the whole selection
32         if (selection.cursor.par() == cursor.par())
33                 if (selection.cursor.pos() < cursor.pos()) {
34                         selection.end = cursor;
35                         selection.start = selection.cursor;
36                 } else {
37                         selection.end = selection.cursor;
38                         selection.start = cursor;
39                 }
40         else if (selection.cursor.y() < cursor.y() ||
41                  (selection.cursor.y() == cursor.y()
42                   && selection.cursor.x() < cursor.x())) {
43                 selection.end = cursor;
44                 selection.start = selection.cursor;
45         }
46         else {
47                 selection.end = selection.cursor;
48                 selection.start = cursor;
49         }
50
51         // a selection with no contents is not a selection
52         if (selection.start.par() == selection.end.par() &&
53             selection.start.pos() == selection.end.pos())
54         {
55                 selection.set(false);
56         }
57 }
58
59
60 void TextCursor::clearSelection()
61 {
62         selection.set(false);
63         selection.mark(false);
64         selection.end    = cursor;
65         selection.start  = cursor;
66         selection.cursor = cursor;
67 }
68