7ea334eefe32f8e1c46a0468a81a7ecbe299aaf5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / text-view / text-view.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18
19 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
20
21 // INTERNAL INCLUDES
22
23 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31
32 const char* const TextView::SIGNAL_TEXT_SCROLLED = "scrolled";
33 const char* const TextView::PROPERTY_TEXT = "text";
34 const char* const TextView::PROPERTY_MULTILINE_POLICY = "multiline-policy";
35 const char* const TextView::PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy";
36 const char* const TextView::PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy";
37 const char* const TextView::PROPERTY_LINE_JUSTIFICATION = "line-justification";
38 const char* const TextView::PROPERTY_FADE_BOUNDARY_LEFT = "fade-boundary-left";
39 const char* const TextView::PROPERTY_FADE_BOUNDARY_RIGHT = "fade-boundary-right";
40 const char* const TextView::PROPERTY_FADE_BOUNDARY_TOP = "fade-boundary-top";
41 const char* const TextView::PROPERTY_FADE_BOUNDARY_BOTTOM = "fade-boundary-bottom";
42 const char* const TextView::PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset";
43 const char* const TextView::PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment";
44 const char* const TextView::PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment";
45
46 TextView::CharacterLayoutInfo::CharacterLayoutInfo()
47 : mSize(),
48   mPosition(),
49   mIsNewLineChar( false ),
50   mIsRightToLeftCharacter( false ),
51   mIsVisible( true ),
52   mDescender()
53 {
54 }
55
56 TextView::CharacterLayoutInfo::~CharacterLayoutInfo()
57 {
58 }
59
60 TextView::CharacterLayoutInfo::CharacterLayoutInfo( const TextView::CharacterLayoutInfo& characterLayoutInfo )
61 : mSize( characterLayoutInfo.mSize ),
62   mPosition( characterLayoutInfo.mPosition ),
63   mIsNewLineChar( characterLayoutInfo.mIsNewLineChar ),
64   mIsRightToLeftCharacter( characterLayoutInfo.mIsRightToLeftCharacter ),
65   mIsVisible( characterLayoutInfo.mIsVisible ),
66   mDescender( characterLayoutInfo.mDescender )
67 {
68 }
69
70 TextView::CharacterLayoutInfo& TextView::CharacterLayoutInfo::operator=( const TextView::CharacterLayoutInfo& characterLayoutInfo )
71 {
72   mSize = characterLayoutInfo.mSize;
73   mPosition = characterLayoutInfo.mPosition;
74   mIsNewLineChar = characterLayoutInfo.mIsNewLineChar;
75   mIsRightToLeftCharacter = characterLayoutInfo.mIsRightToLeftCharacter;
76   mIsVisible = characterLayoutInfo.mIsVisible;
77   mDescender = characterLayoutInfo.mDescender;
78
79   return *this;
80 }
81
82 TextView::CharacterLayoutInfo::CharacterLayoutInfo( const Size& size,
83                                                     const Vector3& position,
84                                                     const bool isNewLineChar,
85                                                     const bool isRightToLeftCharacter,
86                                                     const bool isVisible,
87                                                     const float descender )
88 : mSize( size ),
89   mPosition( position ),
90   mIsNewLineChar( isNewLineChar ),
91   mIsRightToLeftCharacter( isRightToLeftCharacter ),
92   mIsVisible( isVisible ),
93   mDescender( descender )
94 {
95 }
96
97 TextView::TextLayoutInfo::TextLayoutInfo()
98 : mCharacterLayoutInfoTable(),
99   mLines(),
100   mCharacterLogicalToVisualMap(),
101   mCharacterVisualToLogicalMap(),
102   mTextSize(),
103   mScrollOffset()
104 {
105 }
106
107 TextView::TextLayoutInfo::~TextLayoutInfo()
108 {
109 }
110
111 TextView::TextLayoutInfo::TextLayoutInfo( const TextView::TextLayoutInfo& textLayoutInfo )
112 : mCharacterLayoutInfoTable( textLayoutInfo.mCharacterLayoutInfoTable ),
113   mLines( textLayoutInfo.mLines ),
114   mCharacterLogicalToVisualMap( textLayoutInfo.mCharacterLogicalToVisualMap ),
115   mCharacterVisualToLogicalMap( textLayoutInfo.mCharacterVisualToLogicalMap ),
116   mTextSize( textLayoutInfo.mTextSize ),
117   mScrollOffset( textLayoutInfo.mScrollOffset )
118 {
119 }
120
121 TextView::TextLayoutInfo& TextView::TextLayoutInfo::operator=( const TextView::TextLayoutInfo& textLayoutInfo )
122 {
123   mCharacterLayoutInfoTable = textLayoutInfo.mCharacterLayoutInfoTable;
124   mLines = textLayoutInfo.mLines;
125   mCharacterLogicalToVisualMap = textLayoutInfo.mCharacterLogicalToVisualMap;
126   mCharacterVisualToLogicalMap = textLayoutInfo.mCharacterVisualToLogicalMap;
127   mTextSize = textLayoutInfo.mTextSize;
128   mScrollOffset = textLayoutInfo.mScrollOffset;
129
130   return *this;
131 }
132
133 TextView::FadeBoundary::FadeBoundary()
134 : mLeft( 0 ),
135   mRight( 0 ),
136   mTop( 0 ),
137   mBottom( 0 )
138 {
139 }
140
141 TextView::FadeBoundary::FadeBoundary( const PixelSize left, const PixelSize right, const PixelSize top, const PixelSize bottom )
142 : mLeft( left ),
143   mRight( right ),
144   mTop( top ),
145   mBottom( bottom )
146 {
147 }
148
149 TextView::TextView()
150 {
151 }
152
153 TextView::TextView( const TextView& handle )
154 : Control( handle )
155 {
156 }
157
158 TextView::TextView( Dali::Internal::CustomActor* internal )
159 : Control( internal )
160 {
161   VerifyCustomActorPointer<Internal::TextView>(internal);
162 }
163
164 TextView& TextView::operator=( const TextView& handle )
165 {
166   if( &handle != this )
167   {
168     Control::operator=( handle );
169   }
170   return *this;
171 }
172
173 TextView TextView::New()
174 {
175   return Internal::TextView::New();
176 }
177
178 TextView TextView::New( const std::string& text )
179 {
180   TextView textView = Internal::TextView::New();
181   textView.SetText( text );
182   return textView;
183 }
184
185 TextView TextView::New( const MarkupProcessor::StyledTextArray& text )
186 {
187   TextView textView = Internal::TextView::New();
188   textView.SetText( text );
189   return textView;
190 }
191
192 TextView TextView::DownCast( BaseHandle handle )
193 {
194   return Control::DownCast<TextView, Internal::TextView>(handle);
195 }
196
197 TextView::~TextView()
198 {
199 }
200
201 void TextView::SetText( const std::string& text )
202 {
203   GetImpl( *this ).SetText( text );
204 }
205
206 void TextView::SetText( const MarkupProcessor::StyledTextArray& text )
207 {
208   GetImpl( *this ).SetText( text );
209 }
210
211 void TextView::InsertTextAt( const std::size_t position, const std::string& text )
212 {
213   GetImpl( *this ).InsertTextAt( position, text );
214 }
215
216 void TextView::InsertTextAt( const std::size_t position, const MarkupProcessor::StyledTextArray& text )
217 {
218   GetImpl( *this ).InsertTextAt( position, text );
219 }
220
221 void TextView::ReplaceTextFromTo( const std::size_t position, const std::size_t numberOfCharacters, const std::string& text )
222 {
223   GetImpl( *this ).ReplaceTextFromTo( position, numberOfCharacters, text );
224 }
225
226 void TextView::ReplaceTextFromTo( const std::size_t position, const std::size_t numberOfCharacters, const MarkupProcessor::StyledTextArray& text )
227 {
228   GetImpl( *this ).ReplaceTextFromTo( position, numberOfCharacters, text );
229 }
230
231 void TextView::RemoveTextFrom( const std::size_t position, const std::size_t numberOfCharacters )
232 {
233   GetImpl( *this ).RemoveTextFrom( position, numberOfCharacters );
234 }
235
236 std::string TextView::GetText() const
237 {
238   return GetImpl( *this ).GetText();
239 }
240
241 void TextView::SetLineHeightOffset( const PointSize offset )
242 {
243   GetImpl( *this ).SetLineHeightOffset( offset );
244 }
245
246 PointSize TextView::GetLineHeightOffset() const
247 {
248   return GetImpl( *this ).GetLineHeightOffset();
249 }
250
251 void TextView::SetStyleToCurrentText( const TextStyle& style, const TextStyle::Mask mask )
252 {
253   GetImpl( *this ).SetStyleToCurrentText( style, mask );
254 }
255
256 void TextView::SetTextAlignment( Alignment::Type align )
257 {
258   GetImpl( *this ).SetTextAlignment( align );
259 }
260
261 Alignment::Type TextView::GetTextAlignment() const
262 {
263   return GetImpl( *this ).GetTextAlignment();
264 }
265
266 void TextView::SetMultilinePolicy( TextView::MultilinePolicy policy )
267 {
268   GetImpl( *this ).SetMultilinePolicy( policy );
269 }
270
271 TextView::MultilinePolicy TextView::GetMultilinePolicy() const
272 {
273   return GetImpl( *this ).GetMultilinePolicy();
274 }
275
276 void TextView::SetWidthExceedPolicy( TextView::ExceedPolicy policy )
277 {
278   GetImpl( *this ).SetWidthExceedPolicy( policy );
279 }
280
281 TextView::ExceedPolicy TextView::GetWidthExceedPolicy() const
282 {
283   return GetImpl( *this ).GetWidthExceedPolicy();
284 }
285
286 void TextView::SetHeightExceedPolicy( ExceedPolicy policy )
287 {
288   GetImpl( *this ).SetHeightExceedPolicy( policy );
289 }
290
291 TextView::ExceedPolicy TextView::GetHeightExceedPolicy() const
292 {
293   return GetImpl( *this ).GetHeightExceedPolicy();
294 }
295
296 void TextView::SetLineJustification( TextView::LineJustification justification )
297 {
298   GetImpl( *this ).SetLineJustification( justification );
299 }
300
301 TextView::LineJustification TextView::GetLineJustification() const
302 {
303   return GetImpl( *this ).GetLineJustification();
304 }
305
306 void TextView::SetFadeBoundary( const TextView::FadeBoundary& fadeBoundary )
307 {
308   GetImpl( *this ).SetFadeBoundary( fadeBoundary );
309 }
310
311 const TextView::FadeBoundary& TextView::GetFadeBoundary() const
312 {
313   return GetImpl( *this ).GetFadeBoundary();
314 }
315
316 void TextView::SetEllipsizeText( const std::string& ellipsizeText )
317 {
318   GetImpl( *this ).SetEllipsizeText( ellipsizeText );
319 }
320
321 void TextView::SetEllipsizeText( const MarkupProcessor::StyledTextArray& ellipsizeText )
322 {
323   GetImpl( *this ).SetEllipsizeText( ellipsizeText );
324 }
325
326 std::string TextView::GetEllipsizeText() const
327 {
328   return GetImpl( *this ).GetEllipsizeText();
329 }
330
331 void TextView::GetTextLayoutInfo( TextLayoutInfo& textLayoutInfo )
332 {
333   GetImpl( *this ).GetTextLayoutInfo( textLayoutInfo );
334 }
335
336 void TextView::SetSortModifier( float depthOffset )
337 {
338   GetImpl( *this ).SetSortModifier( depthOffset );
339 }
340
341 void TextView::SetSnapshotModeEnabled( bool enable )
342 {
343   GetImpl( *this ).SetSnapshotModeEnabled( enable );
344 }
345
346 bool TextView::IsSnapshotModeEnabled() const
347 {
348   return GetImpl( *this ).IsSnapshotModeEnabled();
349 }
350
351 void TextView::SetScrollEnabled( bool enable )
352 {
353   GetImpl( *this ).SetScrollEnabled( enable );
354 }
355
356 bool TextView::IsScrollEnabled() const
357 {
358   return GetImpl( *this ).IsScrollEnabled();
359 }
360
361 void TextView::SetScrollPosition( const Vector2& position )
362 {
363   GetImpl( *this ).SetScrollPosition( position );
364 }
365
366 const Vector2& TextView::GetScrollPosition() const
367 {
368   return GetImpl( *this ).GetScrollPosition();
369 }
370
371 bool TextView::IsScrollPositionTrimmed() const
372 {
373   return GetImpl( *this ).IsScrollPositionTrimmed();
374 }
375
376 TextView::ScrolledSignalV2& TextView::ScrolledSignal()
377 {
378   return GetImpl( *this ).ScrolledSignal();
379 }
380
381 TextView::TextView( Internal::TextView& implementation )
382 : Control( implementation )
383 {
384 }
385
386 } // namespace Toolkit
387
388 } // namespace Dali