]> git.lyx.org Git - lyx.git/blob - src/textcursor.C
A couple of changing resulting from gcc 3.4 debug mode testing.
[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 #include "debug.h"
17
18 #include <string>
19
20 using std::string;
21
22
23 void TextCursor::setSelection()
24 {
25         if (!selection.set()) {
26                 selection.start = selection.cursor;
27                 selection.end = selection.cursor;
28         }
29
30         selection.set(true);
31
32         // and now the whole selection
33         if (selection.cursor.par() == cursor.par())
34                 if (selection.cursor.pos() < cursor.pos()) {
35                         selection.end = cursor;
36                         selection.start = selection.cursor;
37                 } else {
38                         selection.end = selection.cursor;
39                         selection.start = cursor;
40                 }
41         else if (selection.cursor.par() < cursor.par() ||
42                  (selection.cursor.par() == cursor.par()
43                   && selection.cursor.pos() < cursor.pos())) {
44                 selection.end = cursor;
45                 selection.start = selection.cursor;
46         }
47         else {
48                 selection.end = selection.cursor;
49                 selection.start = cursor;
50         }
51
52         // a selection with no contents is not a selection
53         if (selection.start.par() == selection.end.par() &&
54             selection.start.pos() == selection.end.pos())
55         {
56                 selection.set(false);
57         }
58 }
59
60
61 void TextCursor::clearSelection()
62 {
63         selection.set(false);
64         selection.mark(false);
65         selection.end    = cursor;
66         selection.start  = cursor;
67         selection.cursor = cursor;
68 }
69