repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / ParagraphStyleData.cpp
blobc721b197f74e6e363add7b135ce213e04a24dd08
1 /*
2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "ParagraphStyleData.h"
8 #include <new>
11 ParagraphStyleData::ParagraphStyleData()
13 fAlignment(ALIGN_LEFT),
14 fJustify(false),
16 fFirstLineInset(0.0f),
17 fLineInset(0.0f),
18 fLineSpacing(0.0f),
20 fSpacingTop(0.0f),
21 fSpacingBottom(0.0f),
23 fBullet()
28 ParagraphStyleData::ParagraphStyleData(const ParagraphStyleData& other)
30 fAlignment(other.fAlignment),
31 fJustify(other.fJustify),
33 fFirstLineInset(other.fFirstLineInset),
34 fLineInset(other.fLineInset),
35 fLineSpacing(other.fLineSpacing),
37 fSpacingTop(other.fSpacingTop),
38 fSpacingBottom(other.fSpacingBottom),
40 fBullet(other.fBullet)
45 bool
46 ParagraphStyleData::operator==(const ParagraphStyleData& other) const
48 if (this == &other)
49 return true;
51 return fAlignment == other.fAlignment
52 && fJustify == other.fJustify
53 && fFirstLineInset == other.fFirstLineInset
54 && fLineInset == other.fLineInset
55 && fLineSpacing == other.fLineSpacing
56 && fSpacingTop == other.fSpacingTop
57 && fSpacingBottom == other.fSpacingBottom
58 && fBullet == other.fBullet;
62 bool
63 ParagraphStyleData::operator!=(const ParagraphStyleData& other) const
65 return !(*this == other);
69 ParagraphStyleDataRef
70 ParagraphStyleData::SetAlignment(::Alignment alignment)
72 if (fAlignment == alignment)
73 return ParagraphStyleDataRef(this);
75 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
76 if (ret == NULL)
77 return ParagraphStyleDataRef(this);
79 ret->fAlignment = alignment;
80 return ParagraphStyleDataRef(ret, true);
84 ParagraphStyleDataRef
85 ParagraphStyleData::SetJustify(bool justify)
87 if (fJustify == justify)
88 return ParagraphStyleDataRef(this);
90 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
91 if (ret == NULL)
92 return ParagraphStyleDataRef(this);
94 ret->fJustify = justify;
95 return ParagraphStyleDataRef(ret, true);
99 ParagraphStyleDataRef
100 ParagraphStyleData::SetFirstLineInset(float inset)
102 if (fFirstLineInset == inset)
103 return ParagraphStyleDataRef(this);
105 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
106 if (ret == NULL)
107 return ParagraphStyleDataRef(this);
109 ret->fFirstLineInset = inset;
110 return ParagraphStyleDataRef(ret, true);
114 ParagraphStyleDataRef
115 ParagraphStyleData::SetLineInset(float inset)
117 if (fLineInset == inset)
118 return ParagraphStyleDataRef(this);
120 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
121 if (ret == NULL)
122 return ParagraphStyleDataRef(this);
124 ret->fLineInset = inset;
125 return ParagraphStyleDataRef(ret, true);
129 ParagraphStyleDataRef
130 ParagraphStyleData::SetLineSpacing(float spacing)
132 if (fLineSpacing == spacing)
133 return ParagraphStyleDataRef(this);
135 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
136 if (ret == NULL)
137 return ParagraphStyleDataRef(this);
139 ret->fLineSpacing = spacing;
140 return ParagraphStyleDataRef(ret, true);
144 ParagraphStyleDataRef
145 ParagraphStyleData::SetSpacingTop(float spacing)
147 if (fSpacingTop == spacing)
148 return ParagraphStyleDataRef(this);
150 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
151 if (ret == NULL)
152 return ParagraphStyleDataRef(this);
154 ret->fSpacingTop = spacing;
155 return ParagraphStyleDataRef(ret, true);
159 ParagraphStyleDataRef
160 ParagraphStyleData::SetSpacingBottom(float spacing)
162 if (fSpacingBottom == spacing)
163 return ParagraphStyleDataRef(this);
165 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
166 if (ret == NULL)
167 return ParagraphStyleDataRef(this);
169 ret->fSpacingBottom = spacing;
170 return ParagraphStyleDataRef(ret, true);
174 ParagraphStyleDataRef
175 ParagraphStyleData::SetBullet(const ::Bullet& bullet)
177 if (fBullet == bullet)
178 return ParagraphStyleDataRef(this);
180 ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
181 if (ret == NULL)
182 return ParagraphStyleDataRef(this);
184 ret->fBullet = bullet;
185 return ParagraphStyleDataRef(ret, true);
189 // #pragma mark - private
192 ParagraphStyleData&
193 ParagraphStyleData::operator=(const ParagraphStyleData& other)
195 return *this;