HaikuDepot: Added simple TextSelection class.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user