xref: /haiku/src/apps/haikudepot/textview/ParagraphStyleData.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #include "ParagraphStyleData.h"
7 
8 #include <new>
9 
10 
11 ParagraphStyleData::ParagraphStyleData()
12 	:
13 	fAlignment(ALIGN_LEFT),
14 	fJustify(false),
15 
16 	fFirstLineInset(0.0f),
17 	fLineInset(0.0f),
18 	fLineSpacing(0.0f),
19 
20 	fSpacingTop(0.0f),
21 	fSpacingBottom(0.0f),
22 
23 	fBullet()
24 {
25 }
26 
27 
28 ParagraphStyleData::ParagraphStyleData(const ParagraphStyleData& other)
29 	:
30 	fAlignment(other.fAlignment),
31 	fJustify(other.fJustify),
32 
33 	fFirstLineInset(other.fFirstLineInset),
34 	fLineInset(other.fLineInset),
35 	fLineSpacing(other.fLineSpacing),
36 
37 	fSpacingTop(other.fSpacingTop),
38 	fSpacingBottom(other.fSpacingBottom),
39 
40 	fBullet(other.fBullet)
41 {
42 }
43 
44 
45 bool
46 ParagraphStyleData::operator==(const ParagraphStyleData& other) const
47 {
48 	if (this == &other)
49 		return true;
50 
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;
59 }
60 
61 
62 bool
63 ParagraphStyleData::operator!=(const ParagraphStyleData& other) const
64 {
65 	return !(*this == other);
66 }
67 
68 
69 ParagraphStyleDataRef
70 ParagraphStyleData::SetAlignment(::Alignment alignment)
71 {
72 	if (fAlignment == alignment)
73 		return ParagraphStyleDataRef(this);
74 
75 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
76 	if (ret == NULL)
77 		return ParagraphStyleDataRef(this);
78 
79 	ret->fAlignment = alignment;
80 	return ParagraphStyleDataRef(ret, true);
81 }
82 
83 
84 ParagraphStyleDataRef
85 ParagraphStyleData::SetJustify(bool justify)
86 {
87 	if (fJustify == justify)
88 		return ParagraphStyleDataRef(this);
89 
90 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
91 	if (ret == NULL)
92 		return ParagraphStyleDataRef(this);
93 
94 	ret->fJustify = justify;
95 	return ParagraphStyleDataRef(ret, true);
96 }
97 
98 
99 ParagraphStyleDataRef
100 ParagraphStyleData::SetFirstLineInset(float inset)
101 {
102 	if (fFirstLineInset == inset)
103 		return ParagraphStyleDataRef(this);
104 
105 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
106 	if (ret == NULL)
107 		return ParagraphStyleDataRef(this);
108 
109 	ret->fFirstLineInset = inset;
110 	return ParagraphStyleDataRef(ret, true);
111 }
112 
113 
114 ParagraphStyleDataRef
115 ParagraphStyleData::SetLineInset(float inset)
116 {
117 	if (fLineInset == inset)
118 		return ParagraphStyleDataRef(this);
119 
120 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
121 	if (ret == NULL)
122 		return ParagraphStyleDataRef(this);
123 
124 	ret->fLineInset = inset;
125 	return ParagraphStyleDataRef(ret, true);
126 }
127 
128 
129 ParagraphStyleDataRef
130 ParagraphStyleData::SetLineSpacing(float spacing)
131 {
132 	if (fLineSpacing == spacing)
133 		return ParagraphStyleDataRef(this);
134 
135 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
136 	if (ret == NULL)
137 		return ParagraphStyleDataRef(this);
138 
139 	ret->fLineSpacing = spacing;
140 	return ParagraphStyleDataRef(ret, true);
141 }
142 
143 
144 ParagraphStyleDataRef
145 ParagraphStyleData::SetSpacingTop(float spacing)
146 {
147 	if (fSpacingTop == spacing)
148 		return ParagraphStyleDataRef(this);
149 
150 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
151 	if (ret == NULL)
152 		return ParagraphStyleDataRef(this);
153 
154 	ret->fSpacingTop = spacing;
155 	return ParagraphStyleDataRef(ret, true);
156 }
157 
158 
159 ParagraphStyleDataRef
160 ParagraphStyleData::SetSpacingBottom(float spacing)
161 {
162 	if (fSpacingBottom == spacing)
163 		return ParagraphStyleDataRef(this);
164 
165 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
166 	if (ret == NULL)
167 		return ParagraphStyleDataRef(this);
168 
169 	ret->fSpacingBottom = spacing;
170 	return ParagraphStyleDataRef(ret, true);
171 }
172 
173 
174 ParagraphStyleDataRef
175 ParagraphStyleData::SetBullet(const ::Bullet& bullet)
176 {
177 	if (fBullet == bullet)
178 		return ParagraphStyleDataRef(this);
179 
180 	ParagraphStyleData* ret = new(std::nothrow) ParagraphStyleData(*this);
181 	if (ret == NULL)
182 		return ParagraphStyleDataRef(this);
183 
184 	ret->fBullet = bullet;
185 	return ParagraphStyleDataRef(ret, true);
186 }
187 
188 
189 // #pragma mark - private
190 
191 
192 ParagraphStyleData&
193 ParagraphStyleData::operator=(const ParagraphStyleData& other)
194 {
195 	return *this;
196 }
197