Fixed crash in case that overshoot scroll is not enabled
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 TextView::CharacterLayoutInfo::CharacterLayoutInfo()
31 : mSize(),
32   mPosition(),
33   mIsNewLineChar( false ),
34   mIsNewParagraphChar( false ),
35   mIsRightToLeftCharacter( false ),
36   mIsVisible( true ),
37   mDescender()
38 {
39 }
40
41 TextView::CharacterLayoutInfo::~CharacterLayoutInfo()
42 {
43 }
44
45 TextView::CharacterLayoutInfo::CharacterLayoutInfo( const TextView::CharacterLayoutInfo& characterLayoutInfo )
46 : mSize( characterLayoutInfo.mSize ),
47   mPosition( characterLayoutInfo.mPosition ),
48   mIsNewLineChar( characterLayoutInfo.mIsNewParagraphChar ),
49   mIsNewParagraphChar( characterLayoutInfo.mIsNewParagraphChar ),
50   mIsRightToLeftCharacter( characterLayoutInfo.mIsRightToLeftCharacter ),
51   mIsVisible( characterLayoutInfo.mIsVisible ),
52   mDescender( characterLayoutInfo.mDescender )
53 {
54 }
55
56 TextView::CharacterLayoutInfo& TextView::CharacterLayoutInfo::operator=( const TextView::CharacterLayoutInfo& characterLayoutInfo )
57 {
58   mSize = characterLayoutInfo.mSize;
59   mPosition = characterLayoutInfo.mPosition;
60   mIsNewLineChar = characterLayoutInfo.mIsNewParagraphChar;
61   mIsNewParagraphChar = characterLayoutInfo.mIsNewParagraphChar;
62   mIsRightToLeftCharacter = characterLayoutInfo.mIsRightToLeftCharacter;
63   mIsVisible = characterLayoutInfo.mIsVisible;
64   mDescender = characterLayoutInfo.mDescender;
65
66   return *this;
67 }
68
69 TextView::CharacterLayoutInfo::CharacterLayoutInfo( const Size& size,
70                                                     const Vector3& position,
71                                                     bool isNewParagraphChar,
72                                                     bool isRightToLeftCharacter,
73                                                     bool isVisible,
74                                                     float descender )
75 : mSize( size ),
76   mPosition( position ),
77   mIsNewLineChar( isNewParagraphChar ),
78   mIsNewParagraphChar( isNewParagraphChar ),
79   mIsRightToLeftCharacter( isRightToLeftCharacter ),
80   mIsVisible( isVisible ),
81   mDescender( descender )
82 {
83 }
84
85 TextView::TextLayoutInfo::TextLayoutInfo()
86 : mCharacterLayoutInfoTable(),
87   mLines(),
88   mCharacterLogicalToVisualMap(),
89   mCharacterVisualToLogicalMap(),
90   mTextSize(),
91   mScrollOffset()
92 {
93 }
94
95 TextView::TextLayoutInfo::~TextLayoutInfo()
96 {
97 }
98
99 TextView::TextLayoutInfo::TextLayoutInfo( const TextView::TextLayoutInfo& textLayoutInfo )
100 : mCharacterLayoutInfoTable( textLayoutInfo.mCharacterLayoutInfoTable ),
101   mLines( textLayoutInfo.mLines ),
102   mCharacterLogicalToVisualMap( textLayoutInfo.mCharacterLogicalToVisualMap ),
103   mCharacterVisualToLogicalMap( textLayoutInfo.mCharacterVisualToLogicalMap ),
104   mTextSize( textLayoutInfo.mTextSize ),
105   mScrollOffset( textLayoutInfo.mScrollOffset )
106 {
107 }
108
109 TextView::TextLayoutInfo& TextView::TextLayoutInfo::operator=( const TextView::TextLayoutInfo& textLayoutInfo )
110 {
111   mCharacterLayoutInfoTable = textLayoutInfo.mCharacterLayoutInfoTable;
112   mLines = textLayoutInfo.mLines;
113   mCharacterLogicalToVisualMap = textLayoutInfo.mCharacterLogicalToVisualMap;
114   mCharacterVisualToLogicalMap = textLayoutInfo.mCharacterVisualToLogicalMap;
115   mTextSize = textLayoutInfo.mTextSize;
116   mScrollOffset = textLayoutInfo.mScrollOffset;
117
118   return *this;
119 }
120
121 TextView::FadeBoundary::FadeBoundary()
122 : mLeft( 0 ),
123   mRight( 0 ),
124   mTop( 0 ),
125   mBottom( 0 )
126 {
127 }
128
129 TextView::FadeBoundary::FadeBoundary( PixelSize left, PixelSize right, PixelSize top, PixelSize bottom )
130 : mLeft( left ),
131   mRight( right ),
132   mTop( top ),
133   mBottom( bottom )
134 {
135 }
136
137 TextView::TextView()
138 {
139 }
140
141 TextView::TextView( const TextView& handle )
142 : Control( handle )
143 {
144 }
145
146 TextView::TextView( Dali::Internal::CustomActor* internal )
147 : Control( internal )
148 {
149   VerifyCustomActorPointer<Internal::TextView>(internal);
150 }
151
152 TextView& TextView::operator=( const TextView& handle )
153 {
154   if( &handle != this )
155   {
156     Control::operator=( handle );
157   }
158   return *this;
159 }
160
161 TextView TextView::New()
162 {
163   return Internal::TextView::New();
164 }
165
166 TextView TextView::New( const std::string& text )
167 {
168   TextView textView = Internal::TextView::New();
169   textView.SetText( text );
170   return textView;
171 }
172
173 TextView TextView::New( const MarkupProcessor::StyledTextArray& text )
174 {
175   TextView textView = Internal::TextView::New();
176   textView.SetText( text );
177   return textView;
178 }
179
180 TextView TextView::DownCast( BaseHandle handle )
181 {
182   return Control::DownCast<TextView, Internal::TextView>(handle);
183 }
184
185 TextView::~TextView()
186 {
187 }
188
189 void TextView::SetText( const std::string& text )
190 {
191   GetImpl( *this ).SetText( text );
192 }
193
194 void TextView::SetText( const MarkupProcessor::StyledTextArray& text )
195 {
196   GetImpl( *this ).SetText( text );
197 }
198
199 void TextView::InsertTextAt( std::size_t position, const std::string& text )
200 {
201   GetImpl( *this ).InsertTextAt( position, text );
202 }
203
204 void TextView::InsertTextAt( std::size_t position, const MarkupProcessor::StyledTextArray& text )
205 {
206   GetImpl( *this ).InsertTextAt( position, text );
207 }
208
209 void TextView::ReplaceTextFromTo( std::size_t position, std::size_t numberOfCharacters, const std::string& text )
210 {
211   GetImpl( *this ).ReplaceTextFromTo( position, numberOfCharacters, text );
212 }
213
214 void TextView::ReplaceTextFromTo( std::size_t position, std::size_t numberOfCharacters, const MarkupProcessor::StyledTextArray& text )
215 {
216   GetImpl( *this ).ReplaceTextFromTo( position, numberOfCharacters, text );
217 }
218
219 void TextView::RemoveTextFrom( std::size_t position, std::size_t numberOfCharacters )
220 {
221   GetImpl( *this ).RemoveTextFrom( position, numberOfCharacters );
222 }
223
224 std::string TextView::GetText() const
225 {
226   return GetImpl( *this ).GetText();
227 }
228
229 void TextView::SetLineHeightOffset( PointSize offset )
230 {
231   GetImpl( *this ).SetLineHeightOffset( offset );
232 }
233
234 PointSize TextView::GetLineHeightOffset() const
235 {
236   return GetImpl( *this ).GetLineHeightOffset();
237 }
238
239 void TextView::SetStyleToCurrentText( const TextStyle& style, TextStyle::Mask mask )
240 {
241   GetImpl( *this ).SetStyleToCurrentText( style, mask );
242 }
243
244 void TextView::SetTextAlignment( Alignment::Type align )
245 {
246   GetImpl( *this ).SetTextAlignment( align );
247 }
248
249 Alignment::Type TextView::GetTextAlignment() const
250 {
251   return GetImpl( *this ).GetTextAlignment();
252 }
253
254 void TextView::SetMultilinePolicy( TextView::MultilinePolicy policy )
255 {
256   GetImpl( *this ).SetMultilinePolicy( policy );
257 }
258
259 TextView::MultilinePolicy TextView::GetMultilinePolicy() const
260 {
261   return GetImpl( *this ).GetMultilinePolicy();
262 }
263
264 void TextView::SetWidthExceedPolicy( TextView::ExceedPolicy policy )
265 {
266   GetImpl( *this ).SetWidthExceedPolicy( policy );
267 }
268
269 TextView::ExceedPolicy TextView::GetWidthExceedPolicy() const
270 {
271   return GetImpl( *this ).GetWidthExceedPolicy();
272 }
273
274 void TextView::SetHeightExceedPolicy( ExceedPolicy policy )
275 {
276   GetImpl( *this ).SetHeightExceedPolicy( policy );
277 }
278
279 TextView::ExceedPolicy TextView::GetHeightExceedPolicy() const
280 {
281   return GetImpl( *this ).GetHeightExceedPolicy();
282 }
283
284 void TextView::SetLineJustification( TextView::LineJustification justification )
285 {
286   GetImpl( *this ).SetLineJustification( justification );
287 }
288
289 TextView::LineJustification TextView::GetLineJustification() const
290 {
291   return GetImpl( *this ).GetLineJustification();
292 }
293
294 void TextView::SetFadeBoundary( const TextView::FadeBoundary& fadeBoundary )
295 {
296   GetImpl( *this ).SetFadeBoundary( fadeBoundary );
297 }
298
299 const TextView::FadeBoundary& TextView::GetFadeBoundary() const
300 {
301   return GetImpl( *this ).GetFadeBoundary();
302 }
303
304 void TextView::SetEllipsizeText( const std::string& ellipsizeText )
305 {
306   GetImpl( *this ).SetEllipsizeText( ellipsizeText );
307 }
308
309 void TextView::SetEllipsizeText( const MarkupProcessor::StyledTextArray& ellipsizeText )
310 {
311   GetImpl( *this ).SetEllipsizeText( ellipsizeText );
312 }
313
314 std::string TextView::GetEllipsizeText() const
315 {
316   return GetImpl( *this ).GetEllipsizeText();
317 }
318
319 void TextView::GetTextLayoutInfo( TextLayoutInfo& textLayoutInfo )
320 {
321   GetImpl( *this ).GetTextLayoutInfo( textLayoutInfo );
322 }
323
324 void TextView::SetSortModifier( float depthOffset )
325 {
326   GetImpl( *this ).SetSortModifier( depthOffset );
327 }
328
329 void TextView::SetSnapshotModeEnabled( bool enable )
330 {
331   GetImpl( *this ).SetSnapshotModeEnabled( enable );
332 }
333
334 bool TextView::IsSnapshotModeEnabled() const
335 {
336   return GetImpl( *this ).IsSnapshotModeEnabled();
337 }
338
339 void TextView::SetScrollEnabled( bool enable )
340 {
341   GetImpl( *this ).SetScrollEnabled( enable );
342 }
343
344 bool TextView::IsScrollEnabled() const
345 {
346   return GetImpl( *this ).IsScrollEnabled();
347 }
348
349 void TextView::SetScrollPosition( const Vector2& position )
350 {
351   GetImpl( *this ).SetScrollPosition( position );
352 }
353
354 const Vector2& TextView::GetScrollPosition() const
355 {
356   return GetImpl( *this ).GetScrollPosition();
357 }
358
359 bool TextView::IsScrollPositionTrimmed() const
360 {
361   return GetImpl( *this ).IsScrollPositionTrimmed();
362 }
363
364 TextView::ScrolledSignalType& TextView::ScrolledSignal()
365 {
366   return GetImpl( *this ).ScrolledSignal();
367 }
368
369 void TextView::SetMarkupProcessingEnabled( bool enable )
370 {
371   return GetImpl( *this ).SetMarkupProcessingEnabled( enable );
372 }
373
374 bool TextView::IsMarkupProcessingEnabled() const
375 {
376   return GetImpl( *this ).IsMarkupProcessingEnabled();
377 }
378
379 TextView::TextView( Internal::TextView& implementation )
380 : Control( implementation )
381 {
382 }
383
384 } // namespace Toolkit
385
386 } // namespace Dali