1/* 2 * Copyright 2013, Stephan A��mus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5#ifndef TEXT_SPAN_H 6#define TEXT_SPAN_H 7 8 9#include <Cursor.h> 10#include <String.h> 11 12#include "CharacterStyle.h" 13 14 15class TextSpan { 16public: 17 TextSpan(); 18 TextSpan(const BString& text, 19 const CharacterStyle& style); 20 TextSpan(const TextSpan& other); 21 22 TextSpan& operator=(const TextSpan& other); 23 bool operator==(const TextSpan& other) const; 24 bool operator!=(const TextSpan& other) const; 25 26 void SetText(const BString& text); 27 inline const BString& Text() const 28 { return fText; } 29 30 void SetStyle(const CharacterStyle& style); 31 inline const CharacterStyle& Style() const 32 { return fStyle; } 33 34 inline int32 CountChars() const 35 { return fCharCount; } 36 37 bool Append(const BString& text); 38 bool Insert(int32 offset, const BString& text); 39 bool Remove(int32 start, int32 count); 40 41 TextSpan SubSpan(int32 start, int32 count) const; 42 43 void SetCursor(const BCursor& cursor); 44 inline const BCursor& Cursor() const 45 { return fCursor; } 46 void SetClickMessage(BMessage* message); 47 inline const BMessage* ClickMessage() const 48 { return fClickMessage.IsEmpty() ? NULL : &fClickMessage; } 49private: 50 void _TruncateInsert(int32& start) const; 51 void _TruncateRemove(int32& start, 52 int32& count) const; 53 54private: 55 BString fText; 56 int32 fCharCount; 57 CharacterStyle fStyle; 58 59 BCursor fCursor; 60 BMessage fClickMessage; 61}; 62 63 64#endif // TEXT_SPAN_H 65