HaikuDepot: Added simple TextSelection class.

This commit is contained in:
Stephan Aßmus
2014-01-12 13:53:16 +01:00
parent 810f0a42e5
commit 85ad88c67e
2 changed files with 108 additions and 0 deletions
@@ -0,0 +1,72 @@
/*
* Copyright 2014, Stephan Aßmus <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TextSelection.h"
TextSelection::TextSelection()
:
fAnchor(0),
fCaret(0)
{
}
TextSelection::TextSelection(int32 anchor, int32 caret)
:
fAnchor(anchor),
fCaret(caret)
{
}
TextSelection::TextSelection(const TextSelection& other)
:
fAnchor(other.fAnchor),
fCaret(other.fCaret)
{
}
TextSelection&
TextSelection::operator=(const TextSelection& other)
{
if (this == &other)
return *this;
fAnchor = other.fAnchor;
fCaret = other.fCaret;
return *this;
}
bool
TextSelection::operator==(const TextSelection& other) const
{
return (this == &other)
|| (fAnchor == other.fAnchor && fCaret == other.fCaret);
}
bool
TextSelection::operator!=(const TextSelection& other) const
{
return !(*this == other);
}
void
TextSelection::SetAnchor(int32 anchor)
{
fAnchor = anchor;
}
void
TextSelection::SetCaret(int32 caret)
{
fCaret = caret;
}
@@ -0,0 +1,36 @@
/*
* Copyright 2014, Stephan Aßmus <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef TEXT_SELECTION_H
#define TEXT_SELECTION_H
#include <SupportDefs.h>
class TextSelection {
public:
TextSelection();
TextSelection(int32 anchor, int32 caret);
TextSelection(const TextSelection& other);
TextSelection& operator=(const TextSelection& other);
bool operator==(const TextSelection& other) const;
bool operator!=(const TextSelection& other) const;
void SetAnchor(int32 anchor);
inline int32 Anchor() const
{ return fAnchor; }
void SetCaret(int32 caret);
inline int32 Caret() const
{ return fCaret; }
private:
int32 fAnchor;
int32 fCaret;
};
#endif // TEXT_SELECTION_H