HaikuDepot: Text stuff: Switched from TextStyle to CharacterStyle

This commit is contained in:
Stephan Aßmus 2013-09-05 10:59:03 +02:00
parent 036fabe903
commit f668e7dd19
4 changed files with 32 additions and 31 deletions

View File

@ -10,17 +10,17 @@ TextDocument::TextDocument()
:
fParagraphs(),
fEmptyLastParagraph(),
fDefaultTextStyle()
fDefaultCharacterStyle()
{
}
TextDocument::TextDocument(const TextStyle& textStyle,
TextDocument::TextDocument(const CharacterStyle& CharacterStyle,
const ParagraphStyle& paragraphStyle)
:
fParagraphs(),
fEmptyLastParagraph(paragraphStyle),
fDefaultTextStyle(textStyle)
fDefaultCharacterStyle(CharacterStyle)
{
}
@ -29,7 +29,7 @@ TextDocument::TextDocument(const TextDocument& other)
:
fParagraphs(other.fParagraphs),
fEmptyLastParagraph(other.fEmptyLastParagraph),
fDefaultTextStyle(other.fDefaultTextStyle)
fDefaultCharacterStyle(other.fDefaultCharacterStyle)
{
}
@ -39,7 +39,7 @@ TextDocument::operator=(const TextDocument& other)
{
fParagraphs = other.fParagraphs;
fEmptyLastParagraph = other.fEmptyLastParagraph;
fDefaultTextStyle = other.fDefaultTextStyle;
fDefaultCharacterStyle = other.fDefaultCharacterStyle;
return *this;
}
@ -52,7 +52,7 @@ TextDocument::operator==(const TextDocument& other) const
return true;
return fEmptyLastParagraph == other.fEmptyLastParagraph
&& fDefaultTextStyle == other.fDefaultTextStyle
&& fDefaultCharacterStyle == other.fDefaultCharacterStyle
&& fParagraphs == other.fParagraphs;
}
@ -70,12 +70,12 @@ TextDocument::operator!=(const TextDocument& other) const
status_t
TextDocument::Insert(int32 offset, const BString& text)
{
return Insert(offset, text, TextStyleAt(offset));
return Insert(offset, text, CharacterStyleAt(offset));
}
status_t
TextDocument::Insert(int32 offset, const BString& text, const TextStyle& style)
TextDocument::Insert(int32 offset, const BString& text, const CharacterStyle& style)
{
return Insert(offset, text, style, ParagraphStyleAt(offset));
}
@ -83,9 +83,9 @@ TextDocument::Insert(int32 offset, const BString& text, const TextStyle& style)
status_t
TextDocument::Insert(int32 offset, const BString& text,
const TextStyle& textStyle, const ParagraphStyle& paragraphStyle)
const CharacterStyle& CharacterStyle, const ParagraphStyle& paragraphStyle)
{
return Replace(offset, 0, text, textStyle, paragraphStyle);
return Replace(offset, 0, text, CharacterStyle, paragraphStyle);
}
@ -106,13 +106,13 @@ TextDocument::Remove(int32 offset, int32 length)
status_t
TextDocument::Replace(int32 offset, int32 length, const BString& text)
{
return Replace(offset, length, text, TextStyleAt(offset));
return Replace(offset, length, text, CharacterStyleAt(offset));
}
status_t
TextDocument::Replace(int32 offset, int32 length, const BString& text,
const TextStyle& style)
const CharacterStyle& style)
{
return Replace(offset, length, text, style, ParagraphStyleAt(offset));
}
@ -120,7 +120,7 @@ TextDocument::Replace(int32 offset, int32 length, const BString& text,
status_t
TextDocument::Replace(int32 offset, int32 length, const BString& text,
const TextStyle& textStyle, const ParagraphStyle& paragraphStyle)
const CharacterStyle& CharacterStyle, const ParagraphStyle& paragraphStyle)
{
// TODO: Implement
return B_ERROR;
@ -130,8 +130,8 @@ TextDocument::Replace(int32 offset, int32 length, const BString& text,
// #pragma mark -
const TextStyle&
TextDocument::TextStyleAt(int32 textOffset) const
const CharacterStyle&
TextDocument::CharacterStyleAt(int32 textOffset) const
{
int32 paragraphOffset;
const Paragraph& paragraph = ParagraphAt(textOffset, paragraphOffset);
@ -147,8 +147,7 @@ TextDocument::TextStyleAt(int32 textOffset) const
textOffset -= span.CharCount();
}
// TODO: Document should have a default TextStyle?
return fDefaultTextStyle;
return fDefaultCharacterStyle;
}

View File

@ -5,6 +5,7 @@
#ifndef TEXT_DOCUMENT_H
#define TEXT_DOCUMENT_H
#include "CharacterStyle.h"
#include "List.h"
#include "Paragraph.h"
@ -15,7 +16,8 @@ typedef List<Paragraph, false> ParagraphList;
class TextDocument {
public:
TextDocument();
TextDocument(const TextStyle& textStyle,
TextDocument(
const CharacterStyle& characterStyle,
const ParagraphStyle& paragraphStyle);
TextDocument(const TextDocument& other);
@ -26,9 +28,9 @@ public:
// Text insertion and removing
status_t Insert(int32 offset, const BString& text);
status_t Insert(int32 offset, const BString& text,
const TextStyle& style);
const CharacterStyle& style);
status_t Insert(int32 offset, const BString& text,
const TextStyle& textStyle,
const CharacterStyle& characterStyle,
const ParagraphStyle& paragraphStyle);
status_t Remove(int32 offset, int32 length);
@ -37,14 +39,14 @@ public:
const BString& text);
status_t Replace(int32 offset, int32 length,
const BString& text,
const TextStyle& style);
const CharacterStyle& style);
status_t Replace(int32 offset, int32 length,
const BString& text,
const TextStyle& textStyle,
const CharacterStyle& characterStyle,
const ParagraphStyle& paragraphStyle);
// Style access
const TextStyle& TextStyleAt(int32 textOffset) const;
const CharacterStyle& CharacterStyleAt(int32 textOffset) const;
const ParagraphStyle& ParagraphStyleAt(int32 textOffset) const;
// Paragraph access
@ -59,7 +61,7 @@ public:
private:
ParagraphList fParagraphs;
Paragraph fEmptyLastParagraph;
TextStyle fDefaultTextStyle;
CharacterStyle fDefaultCharacterStyle;
};

View File

@ -15,7 +15,7 @@ TextSpan::TextSpan()
}
TextSpan::TextSpan(const BString& text, const TextStyle& style)
TextSpan::TextSpan(const BString& text, const CharacterStyle& style)
:
fText(text),
fCharCount(text.CountChars()),
@ -69,7 +69,7 @@ TextSpan::SetText(const BString& text)
void
TextSpan::SetStyle(const TextStyle& style)
TextSpan::SetStyle(const CharacterStyle& style)
{
fStyle = style;
}

View File

@ -8,14 +8,14 @@
#include <String.h>
#include "TextStyle.h"
#include "CharacterStyle.h"
class TextSpan {
public:
TextSpan();
TextSpan(const BString& text,
const TextStyle& style);
const CharacterStyle& style);
TextSpan(const TextSpan& other);
TextSpan& operator=(const TextSpan& other);
@ -26,8 +26,8 @@ public:
inline const BString& Text() const
{ return fText; }
void SetStyle(const TextStyle& style);
inline const TextStyle& Style() const
void SetStyle(const CharacterStyle& style);
inline const CharacterStyle& Style() const
{ return fStyle; }
inline int32 CharCount() const
@ -46,7 +46,7 @@ private:
private:
BString fText;
int32 fCharCount;
TextStyle fStyle;
CharacterStyle fStyle;
};