From 85ad88c67e0a8f799e4a15b649f6e72635542450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 12 Jan 2014 13:53:16 +0100 Subject: [PATCH] HaikuDepot: Added simple TextSelection class. --- .../haiku-depot/textview/TextSelection.cpp | 72 +++++++++++++++++++ src/apps/haiku-depot/textview/TextSelection.h | 36 ++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/apps/haiku-depot/textview/TextSelection.cpp create mode 100644 src/apps/haiku-depot/textview/TextSelection.h diff --git a/src/apps/haiku-depot/textview/TextSelection.cpp b/src/apps/haiku-depot/textview/TextSelection.cpp new file mode 100644 index 0000000000..c84facfcca --- /dev/null +++ b/src/apps/haiku-depot/textview/TextSelection.cpp @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Stephan Aßmus . + * 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; +} + diff --git a/src/apps/haiku-depot/textview/TextSelection.h b/src/apps/haiku-depot/textview/TextSelection.h new file mode 100644 index 0000000000..8fa98e0381 --- /dev/null +++ b/src/apps/haiku-depot/textview/TextSelection.h @@ -0,0 +1,36 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef TEXT_SELECTION_H +#define TEXT_SELECTION_H + + +#include + + +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