diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index 659e549a75..766f3deb5d 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -31,6 +31,7 @@ Application HaikuDepot : ParagraphStyle.cpp ParagraphStyleData.cpp TextLayout.cpp + TextSpan.cpp TextStyle.cpp TextView.cpp diff --git a/src/apps/haiku-depot/textview/TextSpan.cpp b/src/apps/haiku-depot/textview/TextSpan.cpp new file mode 100644 index 0000000000..98e39b1bca --- /dev/null +++ b/src/apps/haiku-depot/textview/TextSpan.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "TextSpan.h" + + +TextSpan::TextSpan() + : + fText(), + fStyle() +{ +} + + +TextSpan::TextSpan(const BString& text, const TextStyle& style) + : + fText(text), + fStyle(style) +{ +} + + +TextSpan::TextSpan(const TextSpan& other) + : + fText(other.fText), + fStyle(other.fStyle) +{ +} + + +TextSpan& +TextSpan::operator=(const TextSpan& other) +{ + fText = other.fText; + fStyle = other.fStyle; + + return *this; +} + + +bool +TextSpan::operator==(const TextSpan& other) const +{ + return fText == other.fText + && fStyle == other.fStyle; +} + + +bool +TextSpan::operator!=(const TextSpan& other) const +{ + return !(*this == other); +} + + +void +TextSpan::SetText(const BString& text) +{ + fText = text; +} + + +void +TextSpan::SetStyle(const TextStyle& style) +{ + fStyle = style; +} + + +TextSpan +TextSpan::SubSpan(int32 start, int32 count) const +{ + if (start < 0) { + count += start; + start = 0; + } + + BString subString; + + int32 charCount = fText.CountChars(); + if (start < charCount) { + if (start + count > charCount) + count = charCount - start; + + fText.CopyCharsInto(subString, start, count); + } + + return TextSpan(subString, fStyle); +} + diff --git a/src/apps/haiku-depot/textview/TextSpan.h b/src/apps/haiku-depot/textview/TextSpan.h new file mode 100644 index 0000000000..e9edff8ff7 --- /dev/null +++ b/src/apps/haiku-depot/textview/TextSpan.h @@ -0,0 +1,41 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef TEXT_SPAN_H +#define TEXT_SPAN_H + + +#include + +#include "TextStyle.h" + + +class TextSpan { +public: + TextSpan(); + TextSpan(const BString& text, + const TextStyle& style); + TextSpan(const TextSpan& other); + + TextSpan& operator=(const TextSpan& other); + bool operator==(const TextSpan& other) const; + bool operator!=(const TextSpan& other) const; + + void SetText(const BString& text); + inline const BString& Text() const + { return fText; } + + void SetStyle(const TextStyle& style); + inline const TextStyle& Style() const + { return fStyle; } + + TextSpan SubSpan(int32 start, int32 count) const; + +private: + BString fText; + TextStyle fStyle; +}; + + +#endif // TEXT_SPAN_H