diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index 61db429d97..659e549a75 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -26,6 +26,10 @@ Application HaikuDepot : PackageManager.cpp support.cpp + # textview stuff + Paragraph.cpp + ParagraphStyle.cpp + ParagraphStyleData.cpp TextLayout.cpp TextStyle.cpp TextView.cpp diff --git a/src/apps/haiku-depot/textview/Paragraph.cpp b/src/apps/haiku-depot/textview/Paragraph.cpp new file mode 100644 index 0000000000..b92bcf3c0c --- /dev/null +++ b/src/apps/haiku-depot/textview/Paragraph.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "Paragraph.h" + + +Paragraph::Paragraph() + : + fStyle() +{ +} + + +Paragraph::Paragraph(const ParagraphStyle& style) + : + fStyle(style) +{ +} + + +Paragraph::Paragraph(const Paragraph& other) + : + fStyle(other.fStyle) +{ +} + + +Paragraph& +Paragraph::operator=(const Paragraph& other) +{ + fStyle = other.fStyle; + + return *this; +} + + +bool +Paragraph::operator==(const Paragraph& other) const +{ + return fStyle == other.fStyle; +} + + +bool +Paragraph::operator!=(const Paragraph& other) const +{ + return !(*this == other); +} + + +void +Paragraph::SetStyle(const ParagraphStyle& style) +{ + fStyle = style; +} + diff --git a/src/apps/haiku-depot/textview/Paragraph.h b/src/apps/haiku-depot/textview/Paragraph.h new file mode 100644 index 0000000000..64476a0faf --- /dev/null +++ b/src/apps/haiku-depot/textview/Paragraph.h @@ -0,0 +1,31 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef PARAGRAPH_H +#define PARAGRAPH_H + +#include "List.h" +#include "ParagraphStyle.h" + + +class Paragraph { +public: + Paragraph(); + Paragraph(const ParagraphStyle& style); + Paragraph(const Paragraph& other); + + Paragraph& operator=(const Paragraph& other); + bool operator==(const Paragraph& other) const; + bool operator!=(const Paragraph& other) const; + + void SetStyle(const ParagraphStyle& style); + inline const ParagraphStyle& Style() const + { return fStyle; } + +private: + ParagraphStyle fStyle; +}; + + +#endif // PARAGRAPH_H diff --git a/src/apps/haiku-depot/textview/ParagraphStyle.cpp b/src/apps/haiku-depot/textview/ParagraphStyle.cpp new file mode 100644 index 0000000000..731dec706d --- /dev/null +++ b/src/apps/haiku-depot/textview/ParagraphStyle.cpp @@ -0,0 +1,104 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "ParagraphStyle.h" + + +ParagraphStyle::ParagraphStyle() + : + fStyleData(new ParagraphStyleData(), true) +{ +} + + +ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) + : + fStyleData(other.fStyleData) +{ +} + + +ParagraphStyle& +ParagraphStyle::operator=(const ParagraphStyle& other) +{ + if (this == &other) + return *this; + + fStyleData = other.fStyleData; + return *this; +} + + +bool +ParagraphStyle::operator==(const ParagraphStyle& other) const +{ + if (this == &other) + return true; + + if (fStyleData == other.fStyleData) + return true; + + if (fStyleData.Get() != NULL && other.fStyleData.Get() != NULL) + return *fStyleData.Get() == *other.fStyleData.Get(); + + return false; +} + + +bool +ParagraphStyle::operator!=(const ParagraphStyle& other) const +{ + return !(*this == other); +} + + +bool +ParagraphStyle::SetAlignment(::Alignment alignment) +{ + fStyleData.SetTo(fStyleData->SetAlignment(alignment)); + return fStyleData->Alignment() == alignment; +} + + +bool +ParagraphStyle::SetJustify(bool justify) +{ + fStyleData.SetTo(fStyleData->SetJustify(justify)); + return fStyleData->Justify() == justify; +} + + +bool +ParagraphStyle::SetFirstLineInset(float inset) +{ + fStyleData.SetTo(fStyleData->SetFirstLineInset(inset)); + return fStyleData->FirstLineInset() == inset; +} + + +bool +ParagraphStyle::SetLineInset(float inset) +{ + fStyleData.SetTo(fStyleData->SetLineInset(inset)); + return fStyleData->LineInset() == inset; +} + + +bool +ParagraphStyle::SetSpacingTop(float spacing) +{ + fStyleData.SetTo(fStyleData->SetSpacingTop(spacing)); + return fStyleData->SpacingTop() == spacing; +} + + +bool +ParagraphStyle::SetSpacingBottom(float spacing) +{ + fStyleData.SetTo(fStyleData->SetSpacingBottom(spacing)); + return fStyleData->SpacingBottom() == spacing; +} + + diff --git a/src/apps/haiku-depot/textview/ParagraphStyle.h b/src/apps/haiku-depot/textview/ParagraphStyle.h new file mode 100644 index 0000000000..f548db41c6 --- /dev/null +++ b/src/apps/haiku-depot/textview/ParagraphStyle.h @@ -0,0 +1,44 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef PARAGRAPH_STYLE_H +#define PARAGRAPH_STYLE_H + +#include "ParagraphStyleData.h" + + +class ParagraphStyle { +public: + ParagraphStyle(); + ParagraphStyle(const ParagraphStyle& other); + + ParagraphStyle& operator=(const ParagraphStyle& other); + bool operator==(const ParagraphStyle& other) const; + bool operator!=(const ParagraphStyle& other) const; + + bool SetAlignment(::Alignment alignment); + ::Alignment Alignment() const; + + bool SetJustify(bool justify); + bool Justify() const; + + bool SetFirstLineInset(float inset); + float FirstLineInset() const; + + bool SetLineInset(float inset); + float LineInset() const; + + bool SetSpacingTop(float spacing); + float SpacingTop() const; + + bool SetSpacingBottom(float spacing); + float SpacingBottom() const; + + +private: + ParagraphDataRef fStyleData; +}; + + +#endif // PARAGRAPH_STYLE_H diff --git a/src/apps/haiku-depot/textview/ParagraphStyleData.cpp b/src/apps/haiku-depot/textview/ParagraphStyleData.cpp new file mode 100644 index 0000000000..d7f3db02ea --- /dev/null +++ b/src/apps/haiku-depot/textview/ParagraphStyleData.cpp @@ -0,0 +1,158 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "ParagraphStyleData.h" + +#include + + +ParagraphStyleData::ParagraphStyleData() + : + fAlignment(ALIGN_LEFT), + fJustify(false), + + fFirstLineInset(0.0f), + fLineInset(0.0f), + + fSpacingTop(0.0f), + fSpacingBottom(0.0f) +{ +} + + +ParagraphStyleData::ParagraphStyleData(const ParagraphStyleData& other) + : + fAlignment(other.fAlignment), + fJustify(other.fJustify), + + fFirstLineInset(other.fFirstLineInset), + fLineInset(other.fLineInset), + + fSpacingTop(other.fSpacingTop), + fSpacingBottom(other.fSpacingBottom) +{ +} + + +bool +ParagraphStyleData::operator==(const ParagraphStyleData& other) const +{ + if (this == &other) + return true; + + return fAlignment == other.fAlignment + && fJustify == other.fJustify + && fFirstLineInset == other.fFirstLineInset + && fLineInset == other.fLineInset + && fSpacingTop == other.fSpacingTop + && fSpacingBottom == other.fSpacingBottom; +} + + +bool +ParagraphStyleData::operator!=(const ParagraphStyleData& other) const +{ + return !(*this == other); +} + + +ParagraphStyleData* +ParagraphStyleData::SetAlignment(::Alignment alignment) +{ + if (fAlignment == alignment) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fAlignment = alignment; + return ret; +} + + +ParagraphStyleData* +ParagraphStyleData::SetJustify(bool justify) +{ + if (fJustify == justify) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fJustify = justify; + return ret; +} + + +ParagraphStyleData* +ParagraphStyleData::SetFirstLineInset(float inset) +{ + if (fFirstLineInset == inset) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fFirstLineInset = inset; + return ret; +} + + +ParagraphStyleData* +ParagraphStyleData::SetLineInset(float inset) +{ + if (fLineInset == inset) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fLineInset = inset; + return ret; +} + + +ParagraphStyleData* +ParagraphStyleData::SetSpacingTop(float spacing) +{ + if (fSpacingTop == spacing) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fSpacingTop = spacing; + return ret; +} + + +ParagraphStyleData* +ParagraphStyleData::SetSpacingBottom(float spacing) +{ + if (fSpacingBottom == spacing) + return this; + + ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this); + if (ret == NULL) + return this; + + ret->fSpacingBottom = spacing; + return ret; +} + + +// #pragma mark - private + + +ParagraphStyleData& +ParagraphStyleData::operator=(const ParagraphStyleData& other) +{ + return *this; +} diff --git a/src/apps/haiku-depot/textview/ParagraphStyleData.h b/src/apps/haiku-depot/textview/ParagraphStyleData.h new file mode 100644 index 0000000000..96c9d4332f --- /dev/null +++ b/src/apps/haiku-depot/textview/ParagraphStyleData.h @@ -0,0 +1,72 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef PARAGRAPH_STYLE_DATA_H +#define PARAGRAPH_STYLE_DATA_H + +#include + + +enum Alignment { + ALIGN_LEFT = 0, + ALIGN_CENTER = 1, + ALIGN_RIGHT = 2, +}; + +// You cannot modify a ParagraphStyleData object once it has been +// created. +class ParagraphStyleData : public BReferenceable { +public: + ParagraphStyleData(); + ParagraphStyleData( + const ParagraphStyleData& other); + + bool operator==( + const ParagraphStyleData& other) const; + bool operator!=( + const ParagraphStyleData& other) const; + + ParagraphStyleData* SetAlignment(::Alignment alignment); + inline ::Alignment Alignment() const + { return fAlignment; } + + ParagraphStyleData* SetJustify(bool justify); + inline bool Justify() const + { return fJustify; } + + ParagraphStyleData* SetFirstLineInset(float inset); + inline float FirstLineInset() const + { return fFirstLineInset; } + + ParagraphStyleData* SetLineInset(float inset); + inline float LineInset() const + { return fLineInset; } + + ParagraphStyleData* SetSpacingTop(float spacing); + inline float SpacingTop() const + { return fSpacingTop; } + + ParagraphStyleData* SetSpacingBottom(float spacing); + inline float SpacingBottom() const + { return fSpacingBottom; } + +private: + ParagraphStyleData& operator=(const ParagraphStyleData& other); + +private: + ::Alignment fAlignment; + bool fJustify; + + float fFirstLineInset; + float fLineInset; + + float fSpacingTop; + float fSpacingBottom; +}; + + +typedef BReference ParagraphDataRef; + + +#endif // PARAGRAPH_STYLE_DATA_H