xref: /haiku/src/apps/haikudepot/textview/TextSelection.cpp (revision d7f7bf2d890f652e20b8cf34e9b4c6ae1d3e20eb)
1*d7f7bf2dSAxel Dörfler /*
2*d7f7bf2dSAxel Dörfler  * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
3*d7f7bf2dSAxel Dörfler  * All rights reserved. Distributed under the terms of the MIT License.
4*d7f7bf2dSAxel Dörfler  */
5*d7f7bf2dSAxel Dörfler 
6*d7f7bf2dSAxel Dörfler #include "TextSelection.h"
7*d7f7bf2dSAxel Dörfler 
8*d7f7bf2dSAxel Dörfler 
TextSelection()9*d7f7bf2dSAxel Dörfler TextSelection::TextSelection()
10*d7f7bf2dSAxel Dörfler 	:
11*d7f7bf2dSAxel Dörfler 	fAnchor(0),
12*d7f7bf2dSAxel Dörfler 	fCaret(0)
13*d7f7bf2dSAxel Dörfler {
14*d7f7bf2dSAxel Dörfler }
15*d7f7bf2dSAxel Dörfler 
16*d7f7bf2dSAxel Dörfler 
TextSelection(int32 anchor,int32 caret)17*d7f7bf2dSAxel Dörfler TextSelection::TextSelection(int32 anchor, int32 caret)
18*d7f7bf2dSAxel Dörfler 	:
19*d7f7bf2dSAxel Dörfler 	fAnchor(anchor),
20*d7f7bf2dSAxel Dörfler 	fCaret(caret)
21*d7f7bf2dSAxel Dörfler {
22*d7f7bf2dSAxel Dörfler }
23*d7f7bf2dSAxel Dörfler 
24*d7f7bf2dSAxel Dörfler 
TextSelection(const TextSelection & other)25*d7f7bf2dSAxel Dörfler TextSelection::TextSelection(const TextSelection& other)
26*d7f7bf2dSAxel Dörfler 	:
27*d7f7bf2dSAxel Dörfler 	fAnchor(other.fAnchor),
28*d7f7bf2dSAxel Dörfler 	fCaret(other.fCaret)
29*d7f7bf2dSAxel Dörfler {
30*d7f7bf2dSAxel Dörfler }
31*d7f7bf2dSAxel Dörfler 
32*d7f7bf2dSAxel Dörfler 
33*d7f7bf2dSAxel Dörfler TextSelection&
operator =(const TextSelection & other)34*d7f7bf2dSAxel Dörfler TextSelection::operator=(const TextSelection& other)
35*d7f7bf2dSAxel Dörfler {
36*d7f7bf2dSAxel Dörfler 	if (this == &other)
37*d7f7bf2dSAxel Dörfler 		return *this;
38*d7f7bf2dSAxel Dörfler 
39*d7f7bf2dSAxel Dörfler 	fAnchor = other.fAnchor;
40*d7f7bf2dSAxel Dörfler 	fCaret = other.fCaret;
41*d7f7bf2dSAxel Dörfler 	return *this;
42*d7f7bf2dSAxel Dörfler }
43*d7f7bf2dSAxel Dörfler 
44*d7f7bf2dSAxel Dörfler 
45*d7f7bf2dSAxel Dörfler bool
operator ==(const TextSelection & other) const46*d7f7bf2dSAxel Dörfler TextSelection::operator==(const TextSelection& other) const
47*d7f7bf2dSAxel Dörfler {
48*d7f7bf2dSAxel Dörfler 	return (this == &other)
49*d7f7bf2dSAxel Dörfler 		|| (fAnchor == other.fAnchor && fCaret == other.fCaret);
50*d7f7bf2dSAxel Dörfler }
51*d7f7bf2dSAxel Dörfler 
52*d7f7bf2dSAxel Dörfler 
53*d7f7bf2dSAxel Dörfler bool
operator !=(const TextSelection & other) const54*d7f7bf2dSAxel Dörfler TextSelection::operator!=(const TextSelection& other) const
55*d7f7bf2dSAxel Dörfler {
56*d7f7bf2dSAxel Dörfler 	return !(*this == other);
57*d7f7bf2dSAxel Dörfler }
58*d7f7bf2dSAxel Dörfler 
59*d7f7bf2dSAxel Dörfler 
60*d7f7bf2dSAxel Dörfler void
SetAnchor(int32 anchor)61*d7f7bf2dSAxel Dörfler TextSelection::SetAnchor(int32 anchor)
62*d7f7bf2dSAxel Dörfler {
63*d7f7bf2dSAxel Dörfler 	fAnchor = anchor;
64*d7f7bf2dSAxel Dörfler }
65*d7f7bf2dSAxel Dörfler 
66*d7f7bf2dSAxel Dörfler 
67*d7f7bf2dSAxel Dörfler void
SetCaret(int32 caret)68*d7f7bf2dSAxel Dörfler TextSelection::SetCaret(int32 caret)
69*d7f7bf2dSAxel Dörfler {
70*d7f7bf2dSAxel Dörfler 	fCaret = caret;
71*d7f7bf2dSAxel Dörfler }
72*d7f7bf2dSAxel Dörfler 
73