(Build) Ensure default style is installed & remove autoconf file lists
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
1 /*
2  * Copyright (c) 2019 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/internal/text/text-controller.h>
20
21 // EXTERNAL INCLUDES
22 #include <limits>
23 #include <cmath>
24 #include <memory.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
30
31 // INTERNAL INCLUDES
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
41
42 namespace
43 {
44
45 #if defined(DEBUG_ENABLED)
46   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
47 #endif
48
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
50
51 const std::string EMPTY_STRING("");
52
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
56
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
66
67 float ConvertToEven( float value )
68 {
69   int intValue(static_cast<int>( value ));
70   return static_cast<float>( intValue + ( intValue & 1 ) );
71 }
72
73 int ConvertPixelToPint( float pixel )
74 {
75   unsigned int horizontalDpi = 0u;
76   unsigned int verticalDpi = 0u;
77   Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78   fontClient.GetDpi( horizontalDpi, verticalDpi );
79
80   return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
81 }
82
83
84 } // namespace
85
86 namespace Dali
87 {
88
89 namespace Toolkit
90 {
91
92 namespace Text
93 {
94
95 /**
96  * @brief Adds a new font description run for the selected text.
97  *
98  * The new font parameters are added after the call to this method.
99  *
100  * @param[in] eventData The event data pointer.
101  * @param[in] logicalModel The logical model where to add the new font description run.
102  * @param[out] startOfSelectedText Index to the first selected character.
103  * @param[out] lengthOfSelectedText Number of selected characters.
104  */
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106                                                  LogicalModelPtr logicalModel,
107                                                  CharacterIndex& startOfSelectedText,
108                                                  Length& lengthOfSelectedText )
109 {
110   const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
111
112   // Get start and end position of selection
113   startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114   lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115
116   // Add the font run.
117   const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118   logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
119
120   FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
121
122   fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123   fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
124
125   // Recalculate the selection highlight as the metrics may have changed.
126   eventData->mUpdateLeftSelectionPosition = true;
127   eventData->mUpdateRightSelectionPosition = true;
128   eventData->mUpdateHighlightBox = true;
129
130   return fontDescriptionRun;
131 }
132
133 // public : Constructor.
134
135 ControllerPtr Controller::New()
136 {
137   return ControllerPtr( new Controller() );
138 }
139
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
141 {
142   return ControllerPtr( new Controller( controlInterface ) );
143 }
144
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146                                EditableControlInterface* editableControlInterface )
147 {
148   return ControllerPtr( new Controller( controlInterface,
149                                         editableControlInterface ) );
150 }
151
152 // public : Configure the text controller.
153
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
155 {
156   if( !decorator )
157   {
158     delete mImpl->mEventData;
159     mImpl->mEventData = NULL;
160
161     // Nothing else to do.
162     return;
163   }
164
165   if( NULL == mImpl->mEventData )
166   {
167     mImpl->mEventData = new EventData( decorator, inputMethodContext );
168   }
169 }
170
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
172 {
173   // Metrics for bitmap & vector based glyphs are different
174   mImpl->mMetrics->SetGlyphType( glyphType );
175
176   // Clear the font-specific data
177   ClearFontData();
178
179   mImpl->RequestRelayout();
180 }
181
182 void Controller::SetMarkupProcessorEnabled( bool enable )
183 {
184   if( enable != mImpl->mMarkupProcessorEnabled )
185   {
186     //If Text was already set, call the SetText again for enabling or disabling markup
187     mImpl->mMarkupProcessorEnabled = enable;
188     std::string text;
189     GetText( text );
190     SetText( text );
191   }
192 }
193
194 bool Controller::IsMarkupProcessorEnabled() const
195 {
196   return mImpl->mMarkupProcessorEnabled;
197 }
198
199 void Controller::SetAutoScrollEnabled( bool enable )
200 {
201   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable)?"true":"false", ( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)?"true":"false", this );
202
203   if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
204   {
205     if( enable )
206     {
207       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
209                                                                LAYOUT                    |
210                                                                ALIGN                     |
211                                                                UPDATE_LAYOUT_SIZE        |
212                                                                UPDATE_DIRECTION          |
213                                                                REORDER );
214
215     }
216     else
217     {
218       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
220                                                                LAYOUT                    |
221                                                                ALIGN                     |
222                                                                UPDATE_LAYOUT_SIZE        |
223                                                                REORDER );
224     }
225
226     mImpl->mIsAutoScrollEnabled = enable;
227     mImpl->RequestRelayout();
228   }
229   else
230   {
231     DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232     mImpl->mIsAutoScrollEnabled = false;
233   }
234 }
235
236 bool Controller::IsAutoScrollEnabled() const
237 {
238   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
239
240   return mImpl->mIsAutoScrollEnabled;
241 }
242
243 CharacterDirection Controller::GetAutoScrollDirection() const
244 {
245   return mImpl->mIsTextDirectionRTL;
246 }
247
248 float Controller::GetAutoScrollLineAlignment() const
249 {
250   float offset = 0.f;
251
252   if( mImpl->mModel->mVisualModel &&
253       ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
254   {
255     offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
256   }
257
258   return offset;
259 }
260
261 void Controller::SetHorizontalScrollEnabled( bool enable )
262 {
263   if( ( NULL != mImpl->mEventData ) &&
264       mImpl->mEventData->mDecorator )
265   {
266     mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267   }
268 }
269 bool Controller::IsHorizontalScrollEnabled() const
270 {
271   if( ( NULL != mImpl->mEventData ) &&
272       mImpl->mEventData->mDecorator )
273   {
274     return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
275   }
276
277   return false;
278 }
279
280 void Controller::SetVerticalScrollEnabled( bool enable )
281 {
282   if( ( NULL != mImpl->mEventData ) &&
283       mImpl->mEventData->mDecorator )
284   {
285     if( mImpl->mEventData->mDecorator )
286     {
287       mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
288     }
289   }
290 }
291
292 bool Controller::IsVerticalScrollEnabled() const
293 {
294   if( ( NULL != mImpl->mEventData ) &&
295       mImpl->mEventData->mDecorator )
296   {
297     return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
298   }
299
300   return false;
301 }
302
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
304 {
305   if( ( NULL != mImpl->mEventData ) &&
306       mImpl->mEventData->mDecorator )
307   {
308     mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
309   }
310 }
311
312 bool Controller::IsSmoothHandlePanEnabled() const
313 {
314   if( ( NULL != mImpl->mEventData ) &&
315       mImpl->mEventData->mDecorator )
316   {
317     return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
318   }
319
320   return false;
321 }
322
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
324 {
325   mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
326 }
327
328 int Controller::GetMaximumNumberOfCharacters()
329 {
330   return mImpl->mMaximumNumberOfCharacters;
331 }
332
333 void Controller::SetEnableCursorBlink( bool enable )
334 {
335   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
336
337   if( NULL != mImpl->mEventData )
338   {
339     mImpl->mEventData->mCursorBlinkEnabled = enable;
340
341     if( !enable &&
342         mImpl->mEventData->mDecorator )
343     {
344       mImpl->mEventData->mDecorator->StopCursorBlink();
345     }
346   }
347 }
348
349 bool Controller::GetEnableCursorBlink() const
350 {
351   if( NULL != mImpl->mEventData )
352   {
353     return mImpl->mEventData->mCursorBlinkEnabled;
354   }
355
356   return false;
357 }
358
359 void Controller::SetMultiLineEnabled( bool enable )
360 {
361   const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
362
363   if( layout != mImpl->mLayoutEngine.GetLayout() )
364   {
365     // Set the layout type.
366     mImpl->mLayoutEngine.SetLayout( layout );
367
368     // Set the flags to redo the layout operations
369     const OperationsMask layoutOperations =  static_cast<OperationsMask>( LAYOUT             |
370                                                                           UPDATE_LAYOUT_SIZE |
371                                                                           ALIGN              |
372                                                                           REORDER );
373
374     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
376
377     // Need to recalculate natural size
378     mImpl->mRecalculateNaturalSize = true;
379
380     mImpl->RequestRelayout();
381   }
382 }
383
384 bool Controller::IsMultiLineEnabled() const
385 {
386   return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 }
388
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
390 {
391   if( alignment != mImpl->mModel->mHorizontalAlignment )
392   {
393     // Set the alignment.
394     mImpl->mModel->mHorizontalAlignment = alignment;
395
396     // Set the flag to redo the alignment operation.
397     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
398
399     mImpl->RequestRelayout();
400   }
401 }
402
403 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
404 {
405   return mImpl->mModel->mHorizontalAlignment;
406 }
407
408 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
409 {
410   if( alignment != mImpl->mModel->mVerticalAlignment )
411   {
412     // Set the alignment.
413     mImpl->mModel->mVerticalAlignment = alignment;
414
415     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
416
417     mImpl->RequestRelayout();
418   }
419 }
420
421 VerticalAlignment::Type Controller::GetVerticalAlignment() const
422 {
423   return mImpl->mModel->mVerticalAlignment;
424 }
425
426 bool Controller::IsIgnoreSpacesAfterText() const
427 {
428   return mImpl->mModel->mIgnoreSpacesAfterText;
429 }
430
431 void Controller::SetIgnoreSpacesAfterText( bool ignore )
432 {
433   mImpl->mModel->mIgnoreSpacesAfterText = ignore;
434 }
435
436 bool Controller::IsMatchSystemLanguageDirection() const
437 {
438   return mImpl->mModel->mMatchSystemLanguageDirection;
439 }
440
441 void Controller::SetMatchSystemLanguageDirection( bool match )
442 {
443   mImpl->mModel->mMatchSystemLanguageDirection = match;
444 }
445
446 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
447 {
448   mImpl->mLayoutDirection = layoutDirection;
449 }
450
451 bool Controller::IsShowingRealText() const
452 {
453   return mImpl->IsShowingRealText();
454 }
455
456
457 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
458 {
459   if( lineWrapMode != mImpl->mModel->mLineWrapMode )
460   {
461     // Set the text wrap mode.
462     mImpl->mModel->mLineWrapMode = lineWrapMode;
463
464
465     // Update Text layout for applying wrap mode
466     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
467                                                              ALIGN                     |
468                                                              LAYOUT                    |
469                                                              UPDATE_LAYOUT_SIZE        |
470                                                              REORDER                   );
471     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
472     mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
473     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
474
475     // Request relayout
476     mImpl->RequestRelayout();
477   }
478 }
479
480 Text::LineWrap::Mode Controller::GetLineWrapMode() const
481 {
482   return mImpl->mModel->mLineWrapMode;
483 }
484
485 void Controller::SetTextElideEnabled( bool enabled )
486 {
487   mImpl->mModel->mElideEnabled = enabled;
488 }
489
490 bool Controller::IsTextElideEnabled() const
491 {
492   return mImpl->mModel->mElideEnabled;
493 }
494
495 void Controller::SetTextFitEnabled(bool enabled)
496 {
497   mImpl->mTextFitEnabled = enabled;
498 }
499
500 bool Controller::IsTextFitEnabled() const
501 {
502   return mImpl->mTextFitEnabled;
503 }
504
505 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
506 {
507   switch( type )
508   {
509     case POINT_SIZE:
510     {
511       mImpl->mTextFitMinSize = minSize;
512       break;
513     }
514     case PIXEL_SIZE:
515     {
516       mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
517       break;
518     }
519   }
520 }
521
522 float Controller::GetTextFitMinSize() const
523 {
524   return mImpl->mTextFitMinSize;
525 }
526
527 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
528 {
529   switch( type )
530   {
531     case POINT_SIZE:
532     {
533       mImpl->mTextFitMaxSize = maxSize;
534       break;
535     }
536     case PIXEL_SIZE:
537     {
538       mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
539       break;
540     }
541   }
542 }
543
544 float Controller::GetTextFitMaxSize() const
545 {
546   return mImpl->mTextFitMaxSize;
547 }
548
549 void Controller::SetTextFitStepSize( float step, FontSizeType type )
550 {
551   switch( type )
552   {
553     case POINT_SIZE:
554     {
555       mImpl->mTextFitStepSize = step;
556       break;
557     }
558     case PIXEL_SIZE:
559     {
560       mImpl->mTextFitStepSize = ConvertPixelToPint( step );
561       break;
562     }
563   }
564 }
565
566 float Controller::GetTextFitStepSize() const
567 {
568   return mImpl->mTextFitStepSize;
569 }
570
571 void Controller::SetTextFitContentSize(Vector2 size)
572 {
573   mImpl->mTextFitContentSize = size;
574 }
575
576 Vector2 Controller::GetTextFitContentSize() const
577 {
578   return mImpl->mTextFitContentSize;
579 }
580
581 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
582 {
583   mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
584   mImpl->mEventData->mPlaceholderEllipsisFlag = true;
585
586   // Update placeholder if there is no text
587   if( mImpl->IsShowingPlaceholderText() ||
588       ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
589   {
590     ShowPlaceholderText();
591   }
592 }
593
594 bool Controller::IsPlaceholderTextElideEnabled() const
595 {
596   return mImpl->mEventData->mIsPlaceholderElideEnabled;
597 }
598
599 void Controller::SetSelectionEnabled( bool enabled )
600 {
601   mImpl->mEventData->mSelectionEnabled = enabled;
602 }
603
604 bool Controller::IsSelectionEnabled() const
605 {
606   return mImpl->mEventData->mSelectionEnabled;
607 }
608
609 void Controller::SetShiftSelectionEnabled( bool enabled )
610 {
611   mImpl->mEventData->mShiftSelectionFlag = enabled;
612 }
613
614 bool Controller::IsShiftSelectionEnabled() const
615 {
616   return mImpl->mEventData->mShiftSelectionFlag;
617 }
618
619 void Controller::SetGrabHandleEnabled( bool enabled )
620 {
621   mImpl->mEventData->mGrabHandleEnabled = enabled;
622 }
623
624 bool Controller::IsGrabHandleEnabled() const
625 {
626   return mImpl->mEventData->mGrabHandleEnabled;
627 }
628
629 void Controller::SetGrabHandlePopupEnabled(bool enabled)
630 {
631   mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
632 }
633
634 bool Controller::IsGrabHandlePopupEnabled() const
635 {
636   return mImpl->mEventData->mGrabHandlePopupEnabled;
637 }
638
639 // public : Update
640
641 void Controller::SetText( const std::string& text )
642 {
643   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
644
645   // Reset keyboard as text changed
646   mImpl->ResetInputMethodContext();
647
648   // Remove the previously set text and style.
649   ResetText();
650
651   // Remove the style.
652   ClearStyleData();
653
654   CharacterIndex lastCursorIndex = 0u;
655
656   if( NULL != mImpl->mEventData )
657   {
658     // If popup shown then hide it by switching to Editing state
659     if( ( EventData::SELECTING == mImpl->mEventData->mState )          ||
660         ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
661         ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
662         ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
663     {
664       mImpl->ChangeState( EventData::EDITING );
665     }
666   }
667
668   if( !text.empty() )
669   {
670     mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
671
672     MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
673                                          mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
674                                          mImpl->mModel->mLogicalModel->mEmbeddedItems );
675
676     Length textSize = 0u;
677     const uint8_t* utf8 = NULL;
678     if( mImpl->mMarkupProcessorEnabled )
679     {
680       ProcessMarkupString( text, markupProcessData );
681       textSize = markupProcessData.markupProcessedText.size();
682
683       // This is a bit horrible but std::string returns a (signed) char*
684       utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
685     }
686     else
687     {
688       textSize = text.size();
689
690       // This is a bit horrible but std::string returns a (signed) char*
691       utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
692     }
693
694     // Limit the text size. If the text size is too large, crash or deadlock will occur.
695     if( textSize > MAX_TEXT_LENGTH )
696     {
697       DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
698       textSize = MAX_TEXT_LENGTH;
699     }
700
701     //  Convert text into UTF-32
702     Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
703     utf32Characters.Resize( textSize );
704
705     // Transform a text array encoded in utf8 into an array encoded in utf32.
706     // It returns the actual number of characters.
707     Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
708     utf32Characters.Resize( characterCount );
709
710     DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
711     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
712
713     // The characters to be added.
714     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
715
716     // To reset the cursor position
717     lastCursorIndex = characterCount;
718
719     // Update the rest of the model during size negotiation
720     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
721
722     // The natural size needs to be re-calculated.
723     mImpl->mRecalculateNaturalSize = true;
724
725     // The text direction needs to be updated.
726     mImpl->mUpdateTextDirection = true;
727
728     // Apply modifications to the model
729     mImpl->mOperationsPending = ALL_OPERATIONS;
730   }
731   else
732   {
733     ShowPlaceholderText();
734   }
735
736   // Resets the cursor position.
737   ResetCursorPosition( lastCursorIndex );
738
739   // Scrolls the text to make the cursor visible.
740   ResetScrollPosition();
741
742   mImpl->RequestRelayout();
743
744   if( NULL != mImpl->mEventData )
745   {
746     // Cancel previously queued events
747     mImpl->mEventData->mEventQueue.clear();
748   }
749
750   // Do this last since it provides callbacks into application code.
751   if( NULL != mImpl->mEditableControlInterface )
752   {
753     mImpl->mEditableControlInterface->TextChanged();
754   }
755 }
756
757 void Controller::GetText( std::string& text ) const
758 {
759   if( !mImpl->IsShowingPlaceholderText() )
760   {
761     // Retrieves the text string.
762     mImpl->GetText( 0u, text );
763   }
764   else
765   {
766     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
767   }
768 }
769
770 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
771 {
772   if( NULL != mImpl->mEventData )
773   {
774     if( PLACEHOLDER_TYPE_INACTIVE == type )
775     {
776       mImpl->mEventData->mPlaceholderTextInactive = text;
777     }
778     else
779     {
780       mImpl->mEventData->mPlaceholderTextActive = text;
781     }
782
783     // Update placeholder if there is no text
784     if( mImpl->IsShowingPlaceholderText() ||
785         ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
786     {
787       ShowPlaceholderText();
788     }
789   }
790 }
791
792 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
793 {
794   if( NULL != mImpl->mEventData )
795   {
796     if( PLACEHOLDER_TYPE_INACTIVE == type )
797     {
798       text = mImpl->mEventData->mPlaceholderTextInactive;
799     }
800     else
801     {
802       text = mImpl->mEventData->mPlaceholderTextActive;
803     }
804   }
805 }
806
807 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
808 {
809   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
810
811   if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
812   {
813     DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
814     mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
815
816     ClearFontData();
817
818     mImpl->RequestRelayout();
819   }
820 }
821
822 // public : Default style & Input style
823
824 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
825 {
826   if( NULL == mImpl->mFontDefaults )
827   {
828     mImpl->mFontDefaults = new FontDefaults();
829   }
830
831   mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
832   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
833   mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
834
835   // Clear the font-specific data
836   ClearFontData();
837
838   mImpl->RequestRelayout();
839 }
840
841 const std::string& Controller::GetDefaultFontFamily() const
842 {
843   if( NULL != mImpl->mFontDefaults )
844   {
845     return mImpl->mFontDefaults->mFontDescription.family;
846   }
847
848   return EMPTY_STRING;
849 }
850
851 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
852 {
853   if( NULL != mImpl->mEventData )
854   {
855     if( NULL == mImpl->mEventData->mPlaceholderFont )
856     {
857       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
858     }
859
860     mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
861     DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
862     mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
863
864     mImpl->RequestRelayout();
865   }
866 }
867
868 const std::string& Controller::GetPlaceholderFontFamily() const
869 {
870   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
871   {
872     return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
873   }
874
875   return EMPTY_STRING;
876 }
877
878 void Controller::SetDefaultFontWeight( FontWeight weight )
879 {
880   if( NULL == mImpl->mFontDefaults )
881   {
882     mImpl->mFontDefaults = new FontDefaults();
883   }
884
885   mImpl->mFontDefaults->mFontDescription.weight = weight;
886   mImpl->mFontDefaults->weightDefined = true;
887
888   // Clear the font-specific data
889   ClearFontData();
890
891   mImpl->RequestRelayout();
892 }
893
894 bool Controller::IsDefaultFontWeightDefined() const
895 {
896   if( NULL != mImpl->mFontDefaults )
897   {
898     return mImpl->mFontDefaults->weightDefined;
899   }
900
901   return false;
902 }
903
904 FontWeight Controller::GetDefaultFontWeight() const
905 {
906   if( NULL != mImpl->mFontDefaults )
907   {
908     return mImpl->mFontDefaults->mFontDescription.weight;
909   }
910
911   return TextAbstraction::FontWeight::NORMAL;
912 }
913
914 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
915 {
916   if( NULL != mImpl->mEventData )
917   {
918     if( NULL == mImpl->mEventData->mPlaceholderFont )
919     {
920       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
921     }
922
923     mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
924     mImpl->mEventData->mPlaceholderFont->weightDefined = true;
925
926     mImpl->RequestRelayout();
927   }
928 }
929
930 bool Controller::IsPlaceholderTextFontWeightDefined() const
931 {
932   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
933   {
934     return mImpl->mEventData->mPlaceholderFont->weightDefined;
935   }
936   return false;
937 }
938
939 FontWeight Controller::GetPlaceholderTextFontWeight() const
940 {
941   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
942   {
943     return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
944   }
945
946   return TextAbstraction::FontWeight::NORMAL;
947 }
948
949 void Controller::SetDefaultFontWidth( FontWidth width )
950 {
951   if( NULL == mImpl->mFontDefaults )
952   {
953     mImpl->mFontDefaults = new FontDefaults();
954   }
955
956   mImpl->mFontDefaults->mFontDescription.width = width;
957   mImpl->mFontDefaults->widthDefined = true;
958
959   // Clear the font-specific data
960   ClearFontData();
961
962   mImpl->RequestRelayout();
963 }
964
965 bool Controller::IsDefaultFontWidthDefined() const
966 {
967   if( NULL != mImpl->mFontDefaults )
968   {
969     return mImpl->mFontDefaults->widthDefined;
970   }
971
972   return false;
973 }
974
975 FontWidth Controller::GetDefaultFontWidth() const
976 {
977   if( NULL != mImpl->mFontDefaults )
978   {
979     return mImpl->mFontDefaults->mFontDescription.width;
980   }
981
982   return TextAbstraction::FontWidth::NORMAL;
983 }
984
985 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
986 {
987   if( NULL != mImpl->mEventData )
988   {
989     if( NULL == mImpl->mEventData->mPlaceholderFont )
990     {
991       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
992     }
993
994     mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
995     mImpl->mEventData->mPlaceholderFont->widthDefined = true;
996
997     mImpl->RequestRelayout();
998   }
999 }
1000
1001 bool Controller::IsPlaceholderTextFontWidthDefined() const
1002 {
1003   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1004   {
1005     return mImpl->mEventData->mPlaceholderFont->widthDefined;
1006   }
1007   return false;
1008 }
1009
1010 FontWidth Controller::GetPlaceholderTextFontWidth() const
1011 {
1012   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1013   {
1014     return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1015   }
1016
1017   return TextAbstraction::FontWidth::NORMAL;
1018 }
1019
1020 void Controller::SetDefaultFontSlant( FontSlant slant )
1021 {
1022   if( NULL == mImpl->mFontDefaults )
1023   {
1024     mImpl->mFontDefaults = new FontDefaults();
1025   }
1026
1027   mImpl->mFontDefaults->mFontDescription.slant = slant;
1028   mImpl->mFontDefaults->slantDefined = true;
1029
1030   // Clear the font-specific data
1031   ClearFontData();
1032
1033   mImpl->RequestRelayout();
1034 }
1035
1036 bool Controller::IsDefaultFontSlantDefined() const
1037 {
1038   if( NULL != mImpl->mFontDefaults )
1039   {
1040     return mImpl->mFontDefaults->slantDefined;
1041   }
1042   return false;
1043 }
1044
1045 FontSlant Controller::GetDefaultFontSlant() const
1046 {
1047   if( NULL != mImpl->mFontDefaults )
1048   {
1049     return mImpl->mFontDefaults->mFontDescription.slant;
1050   }
1051
1052   return TextAbstraction::FontSlant::NORMAL;
1053 }
1054
1055 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1056 {
1057   if( NULL != mImpl->mEventData )
1058   {
1059     if( NULL == mImpl->mEventData->mPlaceholderFont )
1060     {
1061       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1062     }
1063
1064     mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1065     mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1066
1067     mImpl->RequestRelayout();
1068   }
1069 }
1070
1071 bool Controller::IsPlaceholderTextFontSlantDefined() const
1072 {
1073   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1074   {
1075     return mImpl->mEventData->mPlaceholderFont->slantDefined;
1076   }
1077   return false;
1078 }
1079
1080 FontSlant Controller::GetPlaceholderTextFontSlant() const
1081 {
1082   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1083   {
1084     return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1085   }
1086
1087   return TextAbstraction::FontSlant::NORMAL;
1088 }
1089
1090 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1091 {
1092   if( NULL == mImpl->mFontDefaults )
1093   {
1094     mImpl->mFontDefaults = new FontDefaults();
1095   }
1096
1097   switch( type )
1098   {
1099     case POINT_SIZE:
1100     {
1101       mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1102       mImpl->mFontDefaults->sizeDefined = true;
1103       break;
1104     }
1105     case PIXEL_SIZE:
1106     {
1107       // Point size = Pixel size * 72.f / DPI
1108       unsigned int horizontalDpi = 0u;
1109       unsigned int verticalDpi = 0u;
1110       TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1111       fontClient.GetDpi( horizontalDpi, verticalDpi );
1112
1113       mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1114       mImpl->mFontDefaults->sizeDefined = true;
1115       break;
1116     }
1117   }
1118
1119   // Clear the font-specific data
1120   ClearFontData();
1121
1122   mImpl->RequestRelayout();
1123 }
1124
1125 float Controller::GetDefaultFontSize( FontSizeType type ) const
1126 {
1127   float value = 0.0f;
1128   if( NULL != mImpl->mFontDefaults )
1129   {
1130     switch( type )
1131     {
1132       case POINT_SIZE:
1133       {
1134         value = mImpl->mFontDefaults->mDefaultPointSize;
1135         break;
1136       }
1137       case PIXEL_SIZE:
1138       {
1139         // Pixel size = Point size * DPI / 72.f
1140         unsigned int horizontalDpi = 0u;
1141         unsigned int verticalDpi = 0u;
1142         TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1143         fontClient.GetDpi( horizontalDpi, verticalDpi );
1144
1145         value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1146         break;
1147       }
1148     }
1149     return value;
1150   }
1151
1152   return value;
1153 }
1154
1155 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1156 {
1157   if( NULL != mImpl->mEventData )
1158   {
1159     if( NULL == mImpl->mEventData->mPlaceholderFont )
1160     {
1161       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1162     }
1163
1164     switch( type )
1165     {
1166       case POINT_SIZE:
1167       {
1168         mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1169         mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1170         mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1171         break;
1172       }
1173       case PIXEL_SIZE:
1174       {
1175         // Point size = Pixel size * 72.f / DPI
1176         unsigned int horizontalDpi = 0u;
1177         unsigned int verticalDpi = 0u;
1178         TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1179         fontClient.GetDpi( horizontalDpi, verticalDpi );
1180
1181         mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1182         mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1183         mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1184         break;
1185       }
1186     }
1187
1188     mImpl->RequestRelayout();
1189   }
1190 }
1191
1192 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1193 {
1194   float value = 0.0f;
1195   if( NULL != mImpl->mEventData )
1196   {
1197     switch( type )
1198     {
1199       case POINT_SIZE:
1200       {
1201         if( NULL != mImpl->mEventData->mPlaceholderFont )
1202         {
1203           value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1204         }
1205         else
1206         {
1207           // If the placeholder text font size is not set, then return the default font size.
1208           value = GetDefaultFontSize( POINT_SIZE );
1209         }
1210         break;
1211       }
1212       case PIXEL_SIZE:
1213       {
1214         if( NULL != mImpl->mEventData->mPlaceholderFont )
1215         {
1216           // Pixel size = Point size * DPI / 72.f
1217           unsigned int horizontalDpi = 0u;
1218           unsigned int verticalDpi = 0u;
1219           TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1220           fontClient.GetDpi( horizontalDpi, verticalDpi );
1221
1222           value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1223         }
1224         else
1225         {
1226           // If the placeholder text font size is not set, then return the default font size.
1227           value = GetDefaultFontSize( PIXEL_SIZE );
1228         }
1229         break;
1230       }
1231     }
1232     return value;
1233   }
1234
1235   return value;
1236 }
1237
1238 void Controller::SetDefaultColor( const Vector4& color )
1239 {
1240   mImpl->mTextColor = color;
1241
1242   if( !mImpl->IsShowingPlaceholderText() )
1243   {
1244     mImpl->mModel->mVisualModel->SetTextColor( color );
1245
1246     mImpl->RequestRelayout();
1247   }
1248 }
1249
1250 const Vector4& Controller::GetDefaultColor() const
1251 {
1252   return mImpl->mTextColor;
1253 }
1254
1255 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1256 {
1257   if( NULL != mImpl->mEventData )
1258   {
1259     mImpl->mEventData->mPlaceholderTextColor = textColor;
1260   }
1261
1262   if( mImpl->IsShowingPlaceholderText() )
1263   {
1264     mImpl->mModel->mVisualModel->SetTextColor( textColor );
1265     mImpl->RequestRelayout();
1266   }
1267 }
1268
1269 const Vector4& Controller::GetPlaceholderTextColor() const
1270 {
1271   if( NULL != mImpl->mEventData )
1272   {
1273     return mImpl->mEventData->mPlaceholderTextColor;
1274   }
1275
1276   return Color::BLACK;
1277 }
1278
1279 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1280 {
1281   mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1282
1283   mImpl->RequestRelayout();
1284 }
1285
1286 const Vector2& Controller::GetShadowOffset() const
1287 {
1288   return mImpl->mModel->mVisualModel->GetShadowOffset();
1289 }
1290
1291 void Controller::SetShadowColor( const Vector4& shadowColor )
1292 {
1293   mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1294
1295   mImpl->RequestRelayout();
1296 }
1297
1298 const Vector4& Controller::GetShadowColor() const
1299 {
1300   return mImpl->mModel->mVisualModel->GetShadowColor();
1301 }
1302
1303 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1304 {
1305   if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1306   {
1307     mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1308
1309     mImpl->RequestRelayout();
1310   }
1311 }
1312
1313 const float& Controller::GetShadowBlurRadius() const
1314 {
1315   return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1316 }
1317
1318 void Controller::SetUnderlineColor( const Vector4& color )
1319 {
1320   mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1321
1322   mImpl->RequestRelayout();
1323 }
1324
1325 const Vector4& Controller::GetUnderlineColor() const
1326 {
1327   return mImpl->mModel->mVisualModel->GetUnderlineColor();
1328 }
1329
1330 void Controller::SetUnderlineEnabled( bool enabled )
1331 {
1332   mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1333
1334   mImpl->RequestRelayout();
1335 }
1336
1337 bool Controller::IsUnderlineEnabled() const
1338 {
1339   return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1340 }
1341
1342 void Controller::SetUnderlineHeight( float height )
1343 {
1344   mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1345
1346   mImpl->RequestRelayout();
1347 }
1348
1349 float Controller::GetUnderlineHeight() const
1350 {
1351   return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1352 }
1353
1354 void Controller::SetOutlineColor( const Vector4& color )
1355 {
1356   mImpl->mModel->mVisualModel->SetOutlineColor( color );
1357
1358   mImpl->RequestRelayout();
1359 }
1360
1361 const Vector4& Controller::GetOutlineColor() const
1362 {
1363   return mImpl->mModel->mVisualModel->GetOutlineColor();
1364 }
1365
1366 void Controller::SetOutlineWidth( uint16_t width )
1367 {
1368   mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1369
1370   mImpl->RequestRelayout();
1371 }
1372
1373 uint16_t Controller::GetOutlineWidth() const
1374 {
1375   return mImpl->mModel->mVisualModel->GetOutlineWidth();
1376 }
1377
1378 void Controller::SetBackgroundColor( const Vector4& color )
1379 {
1380   mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1381
1382   mImpl->RequestRelayout();
1383 }
1384
1385 const Vector4& Controller::GetBackgroundColor() const
1386 {
1387   return mImpl->mModel->mVisualModel->GetBackgroundColor();
1388 }
1389
1390 void Controller::SetBackgroundEnabled( bool enabled )
1391 {
1392   mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1393
1394   mImpl->RequestRelayout();
1395 }
1396
1397 bool Controller::IsBackgroundEnabled() const
1398 {
1399   return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1400 }
1401
1402 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1403 {
1404   if( NULL == mImpl->mEmbossDefaults )
1405   {
1406     mImpl->mEmbossDefaults = new EmbossDefaults();
1407   }
1408
1409   mImpl->mEmbossDefaults->properties = embossProperties;
1410 }
1411
1412 const std::string& Controller::GetDefaultEmbossProperties() const
1413 {
1414   if( NULL != mImpl->mEmbossDefaults )
1415   {
1416     return mImpl->mEmbossDefaults->properties;
1417   }
1418
1419   return EMPTY_STRING;
1420 }
1421
1422 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1423 {
1424   if( NULL == mImpl->mOutlineDefaults )
1425   {
1426     mImpl->mOutlineDefaults = new OutlineDefaults();
1427   }
1428
1429   mImpl->mOutlineDefaults->properties = outlineProperties;
1430 }
1431
1432 const std::string& Controller::GetDefaultOutlineProperties() const
1433 {
1434   if( NULL != mImpl->mOutlineDefaults )
1435   {
1436     return mImpl->mOutlineDefaults->properties;
1437   }
1438
1439   return EMPTY_STRING;
1440 }
1441
1442 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1443 {
1444   if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1445   {
1446     mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1447     mImpl->mRecalculateNaturalSize = true;
1448     return true;
1449   }
1450   return false;
1451 }
1452
1453 float Controller::GetDefaultLineSpacing() const
1454 {
1455   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1456 }
1457
1458 void Controller::SetInputColor( const Vector4& color )
1459 {
1460   if( NULL != mImpl->mEventData )
1461   {
1462     mImpl->mEventData->mInputStyle.textColor = color;
1463     mImpl->mEventData->mInputStyle.isDefaultColor = false;
1464
1465     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1466     {
1467       const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1468
1469       // Get start and end position of selection
1470       const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1471       const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1472
1473       // Add the color run.
1474       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1475       mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1476
1477       ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1478       colorRun.color = color;
1479       colorRun.characterRun.characterIndex = startOfSelectedText;
1480       colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1481
1482       // Request to relayout.
1483       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1484       mImpl->RequestRelayout();
1485
1486       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1487       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1488       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1489     }
1490   }
1491 }
1492
1493 const Vector4& Controller::GetInputColor() const
1494 {
1495   if( NULL != mImpl->mEventData )
1496   {
1497     return mImpl->mEventData->mInputStyle.textColor;
1498   }
1499
1500   // Return the default text's color if there is no EventData.
1501   return mImpl->mTextColor;
1502
1503 }
1504
1505 void Controller::SetInputFontFamily( const std::string& fontFamily )
1506 {
1507   if( NULL != mImpl->mEventData )
1508   {
1509     mImpl->mEventData->mInputStyle.familyName = fontFamily;
1510     mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1511
1512     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1513     {
1514       CharacterIndex startOfSelectedText = 0u;
1515       Length lengthOfSelectedText = 0u;
1516       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1517                                                                             mImpl->mModel->mLogicalModel,
1518                                                                             startOfSelectedText,
1519                                                                             lengthOfSelectedText );
1520
1521       fontDescriptionRun.familyLength = fontFamily.size();
1522       fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1523       memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1524       fontDescriptionRun.familyDefined = true;
1525
1526       // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1527
1528       // Request to relayout.
1529       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1530                                                                VALIDATE_FONTS            |
1531                                                                SHAPE_TEXT                |
1532                                                                GET_GLYPH_METRICS         |
1533                                                                LAYOUT                    |
1534                                                                UPDATE_LAYOUT_SIZE        |
1535                                                                REORDER                   |
1536                                                                ALIGN );
1537       mImpl->mRecalculateNaturalSize = true;
1538       mImpl->RequestRelayout();
1539
1540       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1541       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1542       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1543
1544       // As the font changes, recalculate the handle positions is needed.
1545       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1546       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1547       mImpl->mEventData->mUpdateHighlightBox = true;
1548       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1549     }
1550   }
1551 }
1552
1553 const std::string& Controller::GetInputFontFamily() const
1554 {
1555   if( NULL != mImpl->mEventData )
1556   {
1557     return mImpl->mEventData->mInputStyle.familyName;
1558   }
1559
1560   // Return the default font's family if there is no EventData.
1561   return GetDefaultFontFamily();
1562 }
1563
1564 void Controller::SetInputFontWeight( FontWeight weight )
1565 {
1566   if( NULL != mImpl->mEventData )
1567   {
1568     mImpl->mEventData->mInputStyle.weight = weight;
1569     mImpl->mEventData->mInputStyle.isWeightDefined = true;
1570
1571     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1572     {
1573       CharacterIndex startOfSelectedText = 0u;
1574       Length lengthOfSelectedText = 0u;
1575       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1576                                                                             mImpl->mModel->mLogicalModel,
1577                                                                             startOfSelectedText,
1578                                                                             lengthOfSelectedText );
1579
1580       fontDescriptionRun.weight = weight;
1581       fontDescriptionRun.weightDefined = true;
1582
1583       // Request to relayout.
1584       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1585                                                                VALIDATE_FONTS            |
1586                                                                SHAPE_TEXT                |
1587                                                                GET_GLYPH_METRICS         |
1588                                                                LAYOUT                    |
1589                                                                UPDATE_LAYOUT_SIZE        |
1590                                                                REORDER                   |
1591                                                                ALIGN );
1592       mImpl->mRecalculateNaturalSize = true;
1593       mImpl->RequestRelayout();
1594
1595       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1596       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1597       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1598
1599       // As the font might change, recalculate the handle positions is needed.
1600       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1601       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1602       mImpl->mEventData->mUpdateHighlightBox = true;
1603       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1604     }
1605   }
1606 }
1607
1608 bool Controller::IsInputFontWeightDefined() const
1609 {
1610   bool defined = false;
1611
1612   if( NULL != mImpl->mEventData )
1613   {
1614     defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1615   }
1616
1617   return defined;
1618 }
1619
1620 FontWeight Controller::GetInputFontWeight() const
1621 {
1622   if( NULL != mImpl->mEventData )
1623   {
1624     return mImpl->mEventData->mInputStyle.weight;
1625   }
1626
1627   return GetDefaultFontWeight();
1628 }
1629
1630 void Controller::SetInputFontWidth( FontWidth width )
1631 {
1632   if( NULL != mImpl->mEventData )
1633   {
1634     mImpl->mEventData->mInputStyle.width = width;
1635     mImpl->mEventData->mInputStyle.isWidthDefined = true;
1636
1637     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1638     {
1639       CharacterIndex startOfSelectedText = 0u;
1640       Length lengthOfSelectedText = 0u;
1641       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1642                                                                             mImpl->mModel->mLogicalModel,
1643                                                                             startOfSelectedText,
1644                                                                             lengthOfSelectedText );
1645
1646       fontDescriptionRun.width = width;
1647       fontDescriptionRun.widthDefined = true;
1648
1649       // Request to relayout.
1650       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1651                                                                VALIDATE_FONTS            |
1652                                                                SHAPE_TEXT                |
1653                                                                GET_GLYPH_METRICS         |
1654                                                                LAYOUT                    |
1655                                                                UPDATE_LAYOUT_SIZE        |
1656                                                                REORDER                   |
1657                                                                ALIGN );
1658       mImpl->mRecalculateNaturalSize = true;
1659       mImpl->RequestRelayout();
1660
1661       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1662       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1663       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1664
1665       // As the font might change, recalculate the handle positions is needed.
1666       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1667       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1668       mImpl->mEventData->mUpdateHighlightBox = true;
1669       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1670     }
1671   }
1672 }
1673
1674 bool Controller::IsInputFontWidthDefined() const
1675 {
1676   bool defined = false;
1677
1678   if( NULL != mImpl->mEventData )
1679   {
1680     defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1681   }
1682
1683   return defined;
1684 }
1685
1686 FontWidth Controller::GetInputFontWidth() const
1687 {
1688   if( NULL != mImpl->mEventData )
1689   {
1690     return mImpl->mEventData->mInputStyle.width;
1691   }
1692
1693   return GetDefaultFontWidth();
1694 }
1695
1696 void Controller::SetInputFontSlant( FontSlant slant )
1697 {
1698   if( NULL != mImpl->mEventData )
1699   {
1700     mImpl->mEventData->mInputStyle.slant = slant;
1701     mImpl->mEventData->mInputStyle.isSlantDefined = true;
1702
1703     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1704     {
1705       CharacterIndex startOfSelectedText = 0u;
1706       Length lengthOfSelectedText = 0u;
1707       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1708                                                                             mImpl->mModel->mLogicalModel,
1709                                                                             startOfSelectedText,
1710                                                                             lengthOfSelectedText );
1711
1712       fontDescriptionRun.slant = slant;
1713       fontDescriptionRun.slantDefined = true;
1714
1715       // Request to relayout.
1716       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1717                                                                VALIDATE_FONTS            |
1718                                                                SHAPE_TEXT                |
1719                                                                GET_GLYPH_METRICS         |
1720                                                                LAYOUT                    |
1721                                                                UPDATE_LAYOUT_SIZE        |
1722                                                                REORDER                   |
1723                                                                ALIGN );
1724       mImpl->mRecalculateNaturalSize = true;
1725       mImpl->RequestRelayout();
1726
1727       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1728       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1729       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1730
1731       // As the font might change, recalculate the handle positions is needed.
1732       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1733       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1734       mImpl->mEventData->mUpdateHighlightBox = true;
1735       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1736     }
1737   }
1738 }
1739
1740 bool Controller::IsInputFontSlantDefined() const
1741 {
1742   bool defined = false;
1743
1744   if( NULL != mImpl->mEventData )
1745   {
1746     defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1747   }
1748
1749   return defined;
1750 }
1751
1752 FontSlant Controller::GetInputFontSlant() const
1753 {
1754   if( NULL != mImpl->mEventData )
1755   {
1756     return mImpl->mEventData->mInputStyle.slant;
1757   }
1758
1759   return GetDefaultFontSlant();
1760 }
1761
1762 void Controller::SetInputFontPointSize( float size )
1763 {
1764   if( NULL != mImpl->mEventData )
1765   {
1766     mImpl->mEventData->mInputStyle.size = size;
1767     mImpl->mEventData->mInputStyle.isSizeDefined = true;
1768
1769     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1770     {
1771       CharacterIndex startOfSelectedText = 0u;
1772       Length lengthOfSelectedText = 0u;
1773       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1774                                                                             mImpl->mModel->mLogicalModel,
1775                                                                             startOfSelectedText,
1776                                                                             lengthOfSelectedText );
1777
1778       fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1779       fontDescriptionRun.sizeDefined = true;
1780
1781       // Request to relayout.
1782       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1783                                                                VALIDATE_FONTS            |
1784                                                                SHAPE_TEXT                |
1785                                                                GET_GLYPH_METRICS         |
1786                                                                LAYOUT                    |
1787                                                                UPDATE_LAYOUT_SIZE        |
1788                                                                REORDER                   |
1789                                                                ALIGN );
1790       mImpl->mRecalculateNaturalSize = true;
1791       mImpl->RequestRelayout();
1792
1793       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1794       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1795       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1796
1797       // As the font might change, recalculate the handle positions is needed.
1798       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1799       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1800       mImpl->mEventData->mUpdateHighlightBox = true;
1801       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1802     }
1803   }
1804 }
1805
1806 float Controller::GetInputFontPointSize() const
1807 {
1808   if( NULL != mImpl->mEventData )
1809   {
1810     return mImpl->mEventData->mInputStyle.size;
1811   }
1812
1813   // Return the default font's point size if there is no EventData.
1814   return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1815 }
1816
1817 void Controller::SetInputLineSpacing( float lineSpacing )
1818 {
1819   if( NULL != mImpl->mEventData )
1820   {
1821     mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1822     mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1823   }
1824 }
1825
1826 float Controller::GetInputLineSpacing() const
1827 {
1828   if( NULL != mImpl->mEventData )
1829   {
1830     return mImpl->mEventData->mInputStyle.lineSpacing;
1831   }
1832
1833   return 0.f;
1834 }
1835
1836 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1837 {
1838   if( NULL != mImpl->mEventData )
1839   {
1840     mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1841   }
1842 }
1843
1844 const std::string& Controller::GetInputShadowProperties() const
1845 {
1846   if( NULL != mImpl->mEventData )
1847   {
1848     return mImpl->mEventData->mInputStyle.shadowProperties;
1849   }
1850
1851   return EMPTY_STRING;
1852 }
1853
1854 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1855 {
1856   if( NULL != mImpl->mEventData )
1857   {
1858     mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1859   }
1860 }
1861
1862 const std::string& Controller::GetInputUnderlineProperties() const
1863 {
1864   if( NULL != mImpl->mEventData )
1865   {
1866     return mImpl->mEventData->mInputStyle.underlineProperties;
1867   }
1868
1869   return EMPTY_STRING;
1870 }
1871
1872 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1873 {
1874   if( NULL != mImpl->mEventData )
1875   {
1876     mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1877   }
1878 }
1879
1880 const std::string& Controller::GetInputEmbossProperties() const
1881 {
1882   if( NULL != mImpl->mEventData )
1883   {
1884     return mImpl->mEventData->mInputStyle.embossProperties;
1885   }
1886
1887   return GetDefaultEmbossProperties();
1888 }
1889
1890 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1891 {
1892   if( NULL != mImpl->mEventData )
1893   {
1894     mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1895   }
1896 }
1897
1898 const std::string& Controller::GetInputOutlineProperties() const
1899 {
1900   if( NULL != mImpl->mEventData )
1901   {
1902     return mImpl->mEventData->mInputStyle.outlineProperties;
1903   }
1904
1905   return GetDefaultOutlineProperties();
1906 }
1907
1908 void Controller::SetInputModePassword( bool passwordInput )
1909 {
1910   if( NULL != mImpl->mEventData )
1911   {
1912     mImpl->mEventData->mPasswordInput = passwordInput;
1913   }
1914 }
1915
1916 bool Controller::IsInputModePassword()
1917 {
1918   if( NULL != mImpl->mEventData )
1919   {
1920     return mImpl->mEventData->mPasswordInput;
1921   }
1922   return false;
1923 }
1924
1925 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1926 {
1927   if( NULL != mImpl->mEventData )
1928   {
1929     mImpl->mEventData->mDoubleTapAction = action;
1930   }
1931 }
1932
1933 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1934 {
1935   NoTextTap::Action action = NoTextTap::NO_ACTION;
1936
1937   if( NULL != mImpl->mEventData )
1938   {
1939     action = mImpl->mEventData->mDoubleTapAction;
1940   }
1941
1942   return action;
1943 }
1944
1945 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1946 {
1947   if( NULL != mImpl->mEventData )
1948   {
1949     mImpl->mEventData->mLongPressAction = action;
1950   }
1951 }
1952
1953 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1954 {
1955   NoTextTap::Action action = NoTextTap::NO_ACTION;
1956
1957   if( NULL != mImpl->mEventData )
1958   {
1959     action = mImpl->mEventData->mLongPressAction;
1960   }
1961
1962   return action;
1963 }
1964
1965 bool Controller::IsUnderlineSetByString()
1966 {
1967   return mImpl->mUnderlineSetByString;
1968 }
1969
1970 void Controller::UnderlineSetByString( bool setByString )
1971 {
1972   mImpl->mUnderlineSetByString = setByString;
1973 }
1974
1975 bool Controller::IsShadowSetByString()
1976 {
1977   return mImpl->mShadowSetByString;
1978 }
1979
1980 void Controller::ShadowSetByString( bool setByString )
1981 {
1982   mImpl->mShadowSetByString = setByString;
1983 }
1984
1985 bool Controller::IsOutlineSetByString()
1986 {
1987   return mImpl->mOutlineSetByString;
1988 }
1989
1990 void Controller::OutlineSetByString( bool setByString )
1991 {
1992   mImpl->mOutlineSetByString = setByString;
1993 }
1994
1995 bool Controller::IsFontStyleSetByString()
1996 {
1997   return mImpl->mFontStyleSetByString;
1998 }
1999
2000 void Controller::FontStyleSetByString( bool setByString )
2001 {
2002   mImpl->mFontStyleSetByString = setByString;
2003 }
2004
2005 // public : Queries & retrieves.
2006
2007 Layout::Engine& Controller::GetLayoutEngine()
2008 {
2009   return mImpl->mLayoutEngine;
2010 }
2011
2012 View& Controller::GetView()
2013 {
2014   return mImpl->mView;
2015 }
2016
2017 Vector3 Controller::GetNaturalSize()
2018 {
2019   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2020   Vector3 naturalSize;
2021
2022   // Make sure the model is up-to-date before layouting
2023   ProcessModifyEvents();
2024
2025   if( mImpl->mRecalculateNaturalSize )
2026   {
2027     // Operations that can be done only once until the text changes.
2028     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2029                                                                            GET_SCRIPTS       |
2030                                                                            VALIDATE_FONTS    |
2031                                                                            GET_LINE_BREAKS   |
2032                                                                            GET_WORD_BREAKS   |
2033                                                                            BIDI_INFO         |
2034                                                                            SHAPE_TEXT        |
2035                                                                            GET_GLYPH_METRICS );
2036
2037     // Set the update info to relayout the whole text.
2038     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2039     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2040
2041     // Make sure the model is up-to-date before layouting
2042     mImpl->UpdateModel( onlyOnceOperations );
2043
2044     // Layout the text for the new width.
2045     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2046
2047     // Store the actual control's size to restore later.
2048     const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2049
2050     DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2051                 static_cast<OperationsMask>( onlyOnceOperations |
2052                                              LAYOUT | REORDER ),
2053                 naturalSize.GetVectorXY() );
2054
2055     // Do not do again the only once operations.
2056     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2057
2058     // Do the size related operations again.
2059     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
2060                                                                         ALIGN  |
2061                                                                         REORDER );
2062     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2063
2064     // Stores the natural size to avoid recalculate it again
2065     // unless the text/style changes.
2066     mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2067
2068     mImpl->mRecalculateNaturalSize = false;
2069
2070     // Clear the update info. This info will be set the next time the text is updated.
2071     mImpl->mTextUpdateInfo.Clear();
2072     mImpl->mTextUpdateInfo.mClearAll = true;
2073
2074     // Restore the actual control's size.
2075     mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2076
2077     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2078   }
2079   else
2080   {
2081     naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2082
2083     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2084   }
2085
2086   naturalSize.x = ConvertToEven( naturalSize.x );
2087   naturalSize.y = ConvertToEven( naturalSize.y );
2088
2089   return naturalSize;
2090 }
2091
2092 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2093 {
2094   Size textSize;
2095   mImpl->mFontDefaults->mFitPointSize = pointSize;
2096   mImpl->mFontDefaults->sizeDefined = true;
2097   ClearFontData();
2098
2099   // Operations that can be done only once until the text changes.
2100   const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2101                                                                               GET_SCRIPTS |
2102                                                                            VALIDATE_FONTS |
2103                                                                           GET_LINE_BREAKS |
2104                                                                           GET_WORD_BREAKS |
2105                                                                                 BIDI_INFO |
2106                                                                                 SHAPE_TEXT|
2107                                                                          GET_GLYPH_METRICS );
2108
2109   mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2110   mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2111
2112   // Make sure the model is up-to-date before layouting
2113   mImpl->UpdateModel( onlyOnceOperations );
2114
2115   DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2116               static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2117               textSize);
2118
2119   // Clear the update info. This info will be set the next time the text is updated.
2120   mImpl->mTextUpdateInfo.Clear();
2121   mImpl->mTextUpdateInfo.mClearAll = true;
2122
2123   if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2124   {
2125     return false;
2126   }
2127   return true;
2128 }
2129
2130 void Controller::FitPointSizeforLayout( Size layoutSize )
2131 {
2132   const OperationsMask operations  = mImpl->mOperationsPending;
2133   if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2134   {
2135     bool actualellipsis = mImpl->mModel->mElideEnabled;
2136     float minPointSize = mImpl->mTextFitMinSize;
2137     float maxPointSize = mImpl->mTextFitMaxSize;
2138     float pointInterval = mImpl->mTextFitStepSize;
2139
2140     mImpl->mModel->mElideEnabled = false;
2141     Vector<float> pointSizeArray;
2142
2143     // check zero value
2144     if( pointInterval < 1.f )
2145     {
2146       mImpl->mTextFitStepSize = pointInterval = 1.0f;
2147     }
2148
2149     pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2150
2151     for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2152     {
2153       pointSizeArray.PushBack( i );
2154     }
2155
2156     pointSizeArray.PushBack( maxPointSize );
2157
2158     int bestSizeIndex = 0;
2159     int min = bestSizeIndex + 1;
2160     int max = pointSizeArray.Size() - 1;
2161     while( min <= max )
2162     {
2163       int destI = ( min + max ) / 2;
2164
2165       if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2166       {
2167         bestSizeIndex = min;
2168         min = destI + 1;
2169       }
2170       else
2171       {
2172         max = destI - 1;
2173         bestSizeIndex = max;
2174       }
2175     }
2176
2177     mImpl->mModel->mElideEnabled = actualellipsis;
2178     mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2179     mImpl->mFontDefaults->sizeDefined = true;
2180     ClearFontData();
2181   }
2182 }
2183
2184 float Controller::GetHeightForWidth( float width )
2185 {
2186   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2187   // Make sure the model is up-to-date before layouting
2188   ProcessModifyEvents();
2189
2190   Size layoutSize;
2191   if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2192                                                          mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2193                                                          mImpl->mTextUpdateInfo.mClearAll            )
2194   {
2195     // Operations that can be done only once until the text changes.
2196     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2197                                                                            GET_SCRIPTS       |
2198                                                                            VALIDATE_FONTS    |
2199                                                                            GET_LINE_BREAKS   |
2200                                                                            GET_WORD_BREAKS   |
2201                                                                            BIDI_INFO         |
2202                                                                            SHAPE_TEXT        |
2203                                                                            GET_GLYPH_METRICS );
2204
2205     // Set the update info to relayout the whole text.
2206     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2207     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2208
2209     // Make sure the model is up-to-date before layouting
2210     mImpl->UpdateModel( onlyOnceOperations );
2211
2212
2213     // Layout the text for the new width.
2214     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2215
2216     // Store the actual control's width.
2217     const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2218
2219     DoRelayout( Size( width, MAX_FLOAT ),
2220                 static_cast<OperationsMask>( onlyOnceOperations |
2221                                              LAYOUT ),
2222                 layoutSize );
2223
2224     // Do not do again the only once operations.
2225     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2226
2227     // Do the size related operations again.
2228     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
2229                                                                         ALIGN  |
2230                                                                         REORDER );
2231
2232     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2233
2234     // Clear the update info. This info will be set the next time the text is updated.
2235     mImpl->mTextUpdateInfo.Clear();
2236     mImpl->mTextUpdateInfo.mClearAll = true;
2237
2238     // Restore the actual control's width.
2239     mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2240
2241     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2242   }
2243   else
2244   {
2245     layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2246     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2247   }
2248
2249   return layoutSize.height;
2250 }
2251
2252 int Controller::GetLineCount( float width )
2253 {
2254   GetHeightForWidth( width );
2255   int numberofLines = mImpl->mModel->GetNumberOfLines();
2256   return numberofLines;
2257 }
2258
2259 const ModelInterface* const Controller::GetTextModel() const
2260 {
2261   return mImpl->mModel.Get();
2262 }
2263
2264 float Controller::GetScrollAmountByUserInput()
2265 {
2266   float scrollAmount = 0.0f;
2267
2268   if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2269   {
2270     scrollAmount = mImpl->mModel->mScrollPosition.y -  mImpl->mModel->mScrollPositionLast.y;
2271     mImpl->mEventData->mCheckScrollAmount = false;
2272   }
2273   return scrollAmount;
2274 }
2275
2276 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2277 {
2278   const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2279   bool isScrolled;
2280
2281   controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2282   layoutHeight = layout.height;
2283   scrollPosition = mImpl->mModel->mScrollPosition.y;
2284   isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2285   return isScrolled;
2286 }
2287
2288 void Controller::SetHiddenInputOption(const Property::Map& options )
2289 {
2290   if( NULL == mImpl->mHiddenInput )
2291   {
2292     mImpl->mHiddenInput = new HiddenText( this );
2293   }
2294   mImpl->mHiddenInput->SetProperties(options);
2295 }
2296
2297 void Controller::GetHiddenInputOption(Property::Map& options )
2298 {
2299   if( NULL != mImpl->mHiddenInput )
2300   {
2301     mImpl->mHiddenInput->GetProperties(options);
2302   }
2303 }
2304
2305 void Controller::SetPlaceholderProperty( const Property::Map& map )
2306 {
2307   const Property::Map::SizeType count = map.Count();
2308
2309   for( Property::Map::SizeType position = 0; position < count; ++position )
2310   {
2311     KeyValuePair keyValue = map.GetKeyValue( position );
2312     Property::Key& key = keyValue.first;
2313     Property::Value& value = keyValue.second;
2314
2315     if( key == Toolkit::Text::PlaceHolder::Property::TEXT  || key == PLACEHOLDER_TEXT )
2316     {
2317       std::string text = "";
2318       value.Get( text );
2319       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2320     }
2321     else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2322     {
2323       std::string text = "";
2324       value.Get( text );
2325       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2326     }
2327     else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2328     {
2329       Vector4 textColor;
2330       value.Get( textColor );
2331       if( GetPlaceholderTextColor() != textColor )
2332       {
2333         SetPlaceholderTextColor( textColor );
2334       }
2335     }
2336     else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2337     {
2338       std::string fontFamily = "";
2339       value.Get( fontFamily );
2340       SetPlaceholderFontFamily( fontFamily );
2341     }
2342     else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2343     {
2344       SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2345     }
2346     else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2347     {
2348       float pointSize;
2349       value.Get( pointSize );
2350       if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2351       {
2352         SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2353       }
2354     }
2355     else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2356     {
2357       float pixelSize;
2358       value.Get( pixelSize );
2359       if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2360       {
2361         SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2362       }
2363     }
2364     else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2365     {
2366       bool ellipsis;
2367       value.Get( ellipsis );
2368       SetPlaceholderTextElideEnabled( ellipsis );
2369     }
2370   }
2371 }
2372
2373 void Controller::GetPlaceholderProperty( Property::Map& map )
2374 {
2375   if( NULL != mImpl->mEventData )
2376   {
2377     if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2378     {
2379       map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2380     }
2381     if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2382     {
2383       map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2384     }
2385
2386     map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2387     map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2388
2389     Property::Value fontStyleMapGet;
2390     GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2391     map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2392
2393     // Choose font size : POINT_SIZE or PIXEL_SIZE
2394     if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2395     {
2396       map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2397     }
2398     else
2399     {
2400       map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2401     }
2402
2403     if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2404     {
2405       map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2406     }
2407   }
2408 }
2409
2410 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2411 {
2412   // Make sure the model is up-to-date before layouting
2413   ProcessModifyEvents();
2414
2415   if ( mImpl->mUpdateTextDirection )
2416   {
2417     // Operations that can be done only once until the text changes.
2418     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2419                                                                            GET_SCRIPTS       |
2420                                                                            VALIDATE_FONTS    |
2421                                                                            GET_LINE_BREAKS   |
2422                                                                            GET_WORD_BREAKS   |
2423                                                                            BIDI_INFO         |
2424                                                                            SHAPE_TEXT        |
2425                                                                            GET_GLYPH_METRICS );
2426
2427     // Set the update info to relayout the whole text.
2428     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2429     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2430
2431     // Make sure the model is up-to-date before layouting
2432     mImpl->UpdateModel( onlyOnceOperations );
2433
2434     Vector3 naturalSize;
2435     DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2436                 static_cast<OperationsMask>( onlyOnceOperations |
2437                                              LAYOUT | REORDER | UPDATE_DIRECTION ),
2438                 naturalSize.GetVectorXY() );
2439
2440     // Do not do again the only once operations.
2441     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2442
2443     // Clear the update info. This info will be set the next time the text is updated.
2444     mImpl->mTextUpdateInfo.Clear();
2445
2446     mImpl->mUpdateTextDirection = false;
2447   }
2448
2449   return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2450 }
2451
2452 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2453 {
2454   return mImpl->mModel->GetVerticalLineAlignment();
2455 }
2456
2457 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2458 {
2459   mImpl->mModel->mVerticalLineAlignment = alignment;
2460 }
2461
2462 // public : Relayout.
2463
2464 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2465 {
2466   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false"  );
2467
2468   UpdateTextType updateTextType = NONE_UPDATED;
2469
2470   if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2471   {
2472     if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2473     {
2474       mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2475       updateTextType = MODEL_UPDATED;
2476     }
2477
2478     // Clear the update info. This info will be set the next time the text is updated.
2479     mImpl->mTextUpdateInfo.Clear();
2480
2481     // Not worth to relayout if width or height is equal to zero.
2482     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2483
2484     return updateTextType;
2485   }
2486
2487   // Whether a new size has been set.
2488   const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2489
2490   if( newSize )
2491   {
2492     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2493
2494     if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2495         ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2496         ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2497     {
2498       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2499     }
2500
2501     // Layout operations that need to be done if the size changes.
2502     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2503                                                              LAYOUT                    |
2504                                                              ALIGN                     |
2505                                                              UPDATE_LAYOUT_SIZE        |
2506                                                              REORDER );
2507     // Set the update info to relayout the whole text.
2508     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2509     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2510
2511     // Store the size used to layout the text.
2512     mImpl->mModel->mVisualModel->mControlSize = size;
2513   }
2514
2515   // Whether there are modify events.
2516   if( 0u != mImpl->mModifyEvents.Count() )
2517   {
2518     // Style operations that need to be done if the text is modified.
2519     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2520                                                              COLOR );
2521   }
2522
2523   // Set the update info to elide the text.
2524   if( mImpl->mModel->mElideEnabled ||
2525       ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2526   {
2527     // Update Text layout for applying elided
2528     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2529                                                              ALIGN                     |
2530                                                              LAYOUT                    |
2531                                                              UPDATE_LAYOUT_SIZE        |
2532                                                              REORDER );
2533     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2534     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2535   }
2536
2537   if( mImpl->mModel->mMatchSystemLanguageDirection  && mImpl->mLayoutDirection != layoutDirection )
2538   {
2539     // Clear the update info. This info will be set the next time the text is updated.
2540     mImpl->mTextUpdateInfo.mClearAll = true;
2541     // Apply modifications to the model
2542     // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2543     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2544                                                              GET_GLYPH_METRICS         |
2545                                                              SHAPE_TEXT                |
2546                                                              UPDATE_DIRECTION          |
2547                                                              LAYOUT                    |
2548                                                              BIDI_INFO                 |
2549                                                              REORDER );
2550     mImpl->mLayoutDirection = layoutDirection;
2551   }
2552
2553   // Make sure the model is up-to-date before layouting.
2554   ProcessModifyEvents();
2555   bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2556
2557   // Layout the text.
2558   Size layoutSize;
2559   updated = DoRelayout( size,
2560                         mImpl->mOperationsPending,
2561                         layoutSize ) || updated;
2562
2563
2564   if( updated )
2565   {
2566     updateTextType = MODEL_UPDATED;
2567   }
2568
2569   // Do not re-do any operation until something changes.
2570   mImpl->mOperationsPending = NO_OPERATION;
2571   mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2572
2573   // Whether the text control is editable
2574   const bool isEditable = NULL != mImpl->mEventData;
2575
2576   // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2577   Vector2 offset;
2578   if( newSize && isEditable )
2579   {
2580     offset = mImpl->mModel->mScrollPosition;
2581   }
2582
2583   if( !isEditable || !IsMultiLineEnabled() )
2584   {
2585     // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2586     CalculateVerticalOffset( size );
2587   }
2588
2589   if( isEditable )
2590   {
2591     if( newSize )
2592     {
2593       // If there is a new size, the scroll position needs to be clamped.
2594       mImpl->ClampHorizontalScroll( layoutSize );
2595
2596       // Update the decorator's positions is needed if there is a new size.
2597       mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2598     }
2599
2600     // Move the cursor, grab handle etc.
2601     if( mImpl->ProcessInputEvents() )
2602     {
2603       updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2604     }
2605   }
2606
2607   // Clear the update info. This info will be set the next time the text is updated.
2608   mImpl->mTextUpdateInfo.Clear();
2609   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2610
2611   return updateTextType;
2612 }
2613
2614 void Controller::RequestRelayout()
2615 {
2616   mImpl->RequestRelayout();
2617 }
2618
2619 // public : Input style change signals.
2620
2621 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2622 {
2623   return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2624 }
2625
2626 void Controller::ProcessInputStyleChangedSignals()
2627 {
2628   if( NULL == mImpl->mEventData )
2629   {
2630     // Nothing to do.
2631     return;
2632   }
2633
2634   for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2635          endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2636        it != endIt;
2637        ++it )
2638   {
2639     const InputStyle::Mask mask = *it;
2640
2641     if( NULL != mImpl->mEditableControlInterface )
2642     {
2643       // Emit the input style changed signal.
2644       mImpl->mEditableControlInterface->InputStyleChanged( mask );
2645     }
2646   }
2647
2648   mImpl->mEventData->mInputStyleChangedQueue.Clear();
2649 }
2650
2651 // public : Text-input Event Queuing.
2652
2653 void Controller::KeyboardFocusGainEvent()
2654 {
2655   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2656
2657   if( NULL != mImpl->mEventData )
2658   {
2659     if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2660         ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2661     {
2662       mImpl->ChangeState( EventData::EDITING );
2663       mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2664       mImpl->mEventData->mUpdateInputStyle = true;
2665       mImpl->mEventData->mScrollAfterUpdatePosition = true;
2666     }
2667     mImpl->NotifyInputMethodContextMultiLineStatus();
2668     if( mImpl->IsShowingPlaceholderText() )
2669     {
2670       // Show alternative placeholder-text when editing
2671       ShowPlaceholderText();
2672     }
2673
2674     mImpl->RequestRelayout();
2675   }
2676 }
2677
2678 void Controller::KeyboardFocusLostEvent()
2679 {
2680   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2681
2682   if( NULL != mImpl->mEventData )
2683   {
2684     if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2685     {
2686       mImpl->ChangeState( EventData::INACTIVE );
2687
2688       if( !mImpl->IsShowingRealText() )
2689       {
2690         // Revert to regular placeholder-text when not editing
2691         ShowPlaceholderText();
2692       }
2693     }
2694   }
2695   mImpl->RequestRelayout();
2696 }
2697
2698 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2699 {
2700   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2701
2702   bool textChanged = false;
2703   bool relayoutNeeded = false;
2704
2705   if( ( NULL != mImpl->mEventData ) &&
2706       ( keyEvent.state == KeyEvent::Down ) )
2707   {
2708     int keyCode = keyEvent.keyCode;
2709     const std::string& keyString = keyEvent.keyPressed;
2710     const std::string keyName = keyEvent.keyPressedName;
2711
2712     const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2713
2714     // Pre-process to separate modifying events from non-modifying input events.
2715     if( isNullKey )
2716     {
2717       // In some platforms arrive key events with no key code.
2718       // Do nothing.
2719       return false;
2720     }
2721     else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode  || Dali::DALI_KEY_SEARCH == keyCode )
2722     {
2723       // Do nothing
2724       return false;
2725     }
2726     else if( ( Dali::DALI_KEY_CURSOR_LEFT  == keyCode ) ||
2727              ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2728              ( Dali::DALI_KEY_CURSOR_UP    == keyCode ) ||
2729              ( Dali::DALI_KEY_CURSOR_DOWN  == keyCode ) )
2730     {
2731       // If don't have any text, do nothing.
2732       if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2733       {
2734         return false;
2735       }
2736
2737       uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2738       uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2739       uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2740       uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2741
2742       // Logic to determine whether this text control will lose focus or not.
2743       if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2744           ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2745           ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2746           ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2747           ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2748           ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2749       {
2750         // Release the active highlight.
2751         if( mImpl->mEventData->mState == EventData::SELECTING )
2752         {
2753           mImpl->ChangeState( EventData::EDITING );
2754
2755           // Update selection position.
2756           mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2757           mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2758           mImpl->mEventData->mUpdateCursorPosition = true;
2759           mImpl->RequestRelayout();
2760         }
2761         return false;
2762       }
2763
2764       mImpl->mEventData->mCheckScrollAmount = true;
2765       Event event( Event::CURSOR_KEY_EVENT );
2766       event.p1.mInt = keyCode;
2767       event.p2.mBool = keyEvent.IsShiftModifier();
2768       mImpl->mEventData->mEventQueue.push_back( event );
2769
2770       // Will request for relayout.
2771       relayoutNeeded = true;
2772     }
2773     else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2774     {
2775       // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2776       // If not handle it here, any selected text will be deleted
2777
2778       // Do nothing
2779       return false;
2780     }
2781     else if ( keyEvent.IsCtrlModifier() )
2782     {
2783       bool consumed = false;
2784       if (keyName == KEY_C_NAME)
2785       {
2786         // Ctrl-C to copy the selected text
2787         TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2788         consumed = true;
2789       }
2790       else if (keyName == KEY_V_NAME)
2791       {
2792         // Ctrl-V to paste the copied text
2793         TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2794         consumed = true;
2795       }
2796       else if (keyName == KEY_X_NAME)
2797       {
2798         // Ctrl-X to cut the selected text
2799         TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2800         consumed = true;
2801       }
2802       return consumed;
2803     }
2804     else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2805              ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2806     {
2807       textChanged = DeleteEvent( keyCode );
2808
2809       // Will request for relayout.
2810       relayoutNeeded = true;
2811     }
2812     else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2813              IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2814              IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2815     {
2816       // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2817       mImpl->ChangeState( EventData::INACTIVE );
2818
2819       // Will request for relayout.
2820       relayoutNeeded = true;
2821
2822       // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2823     }
2824     else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2825     {
2826       // DALI_KEY_SHIFT_LEFT or DALI_KEY_SHIFT_RIGHT is the key code for Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2827       // and a character is typed after the type of a upper case latin character.
2828
2829       // Do nothing.
2830       return false;
2831     }
2832     else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2833     {
2834       // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2835       // Do nothing.
2836       return false;
2837     }
2838     else
2839     {
2840       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2841
2842       if( !keyString.empty() )
2843       {
2844         // InputMethodContext is no longer handling key-events
2845         mImpl->ClearPreEditFlag();
2846
2847         InsertText( keyString, COMMIT );
2848
2849         textChanged = true;
2850
2851         // Will request for relayout.
2852         relayoutNeeded = true;
2853       }
2854
2855     }
2856
2857     if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2858          ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2859          ( !isNullKey ) &&
2860          ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2861          ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2862          ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2863          ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2864     {
2865       // Should not change the state if the key is the shift send by the InputMethodContext.
2866       // Otherwise, when the state is SELECTING the text controller can't send the right
2867       // surrounding info to the InputMethodContext.
2868       mImpl->ChangeState( EventData::EDITING );
2869
2870       // Will request for relayout.
2871       relayoutNeeded = true;
2872     }
2873
2874     if( relayoutNeeded )
2875     {
2876       mImpl->RequestRelayout();
2877     }
2878   }
2879
2880   if( textChanged &&
2881       ( NULL != mImpl->mEditableControlInterface ) )
2882   {
2883     // Do this last since it provides callbacks into application code
2884     mImpl->mEditableControlInterface->TextChanged();
2885   }
2886
2887   return true;
2888 }
2889
2890 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2891 {
2892   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2893
2894   if( NULL != mImpl->mEventData )
2895   {
2896     DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2897     EventData::State state( mImpl->mEventData->mState );
2898     bool relayoutNeeded( false );   // to avoid unnecessary relayouts when tapping an empty text-field
2899
2900     if( mImpl->IsClipboardVisible() )
2901     {
2902       if( EventData::INACTIVE == state || EventData::EDITING == state)
2903       {
2904         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2905       }
2906       relayoutNeeded = true;
2907     }
2908     else if( 1u == tapCount )
2909     {
2910       if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2911       {
2912         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );  // If Popup shown hide it here so can be shown again if required.
2913       }
2914
2915       if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2916       {
2917         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2918         relayoutNeeded = true;
2919       }
2920       else
2921       {
2922         if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2923         {
2924           // Hide placeholder text
2925           ResetText();
2926         }
2927
2928         if( EventData::INACTIVE == state )
2929         {
2930           mImpl->ChangeState( EventData::EDITING );
2931         }
2932         else if( !mImpl->IsClipboardEmpty() )
2933         {
2934           mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2935         }
2936         relayoutNeeded = true;
2937       }
2938     }
2939     else if( 2u == tapCount )
2940     {
2941       if( mImpl->mEventData->mSelectionEnabled &&
2942           mImpl->IsShowingRealText() )
2943       {
2944         relayoutNeeded = true;
2945         mImpl->mEventData->mIsLeftHandleSelected = true;
2946         mImpl->mEventData->mIsRightHandleSelected = true;
2947       }
2948     }
2949
2950     // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2951     if( relayoutNeeded )
2952     {
2953       Event event( Event::TAP_EVENT );
2954       event.p1.mUint = tapCount;
2955       event.p2.mFloat = x;
2956       event.p3.mFloat = y;
2957       mImpl->mEventData->mEventQueue.push_back( event );
2958
2959       mImpl->RequestRelayout();
2960     }
2961   }
2962
2963   // Reset keyboard as tap event has occurred.
2964   mImpl->ResetInputMethodContext();
2965 }
2966
2967 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2968 {
2969   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2970
2971   if( NULL != mImpl->mEventData )
2972   {
2973     Event event( Event::PAN_EVENT );
2974     event.p1.mInt = state;
2975     event.p2.mFloat = displacement.x;
2976     event.p3.mFloat = displacement.y;
2977     mImpl->mEventData->mEventQueue.push_back( event );
2978
2979     mImpl->RequestRelayout();
2980   }
2981 }
2982
2983 void Controller::LongPressEvent( Gesture::State state, float x, float y  )
2984 {
2985   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2986
2987   if( ( state == Gesture::Started ) &&
2988       ( NULL != mImpl->mEventData ) )
2989   {
2990     // The 1st long-press on inactive text-field is treated as tap
2991     if( EventData::INACTIVE == mImpl->mEventData->mState )
2992     {
2993       mImpl->ChangeState( EventData::EDITING );
2994
2995       Event event( Event::TAP_EVENT );
2996       event.p1.mUint = 1;
2997       event.p2.mFloat = x;
2998       event.p3.mFloat = y;
2999       mImpl->mEventData->mEventQueue.push_back( event );
3000
3001       mImpl->RequestRelayout();
3002     }
3003     else if( !mImpl->IsShowingRealText() )
3004     {
3005       Event event( Event::LONG_PRESS_EVENT );
3006       event.p1.mInt = state;
3007       event.p2.mFloat = x;
3008       event.p3.mFloat = y;
3009       mImpl->mEventData->mEventQueue.push_back( event );
3010       mImpl->RequestRelayout();
3011     }
3012     else if( !mImpl->IsClipboardVisible() )
3013     {
3014       // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3015       mImpl->ResetInputMethodContext();
3016
3017       Event event( Event::LONG_PRESS_EVENT );
3018       event.p1.mInt = state;
3019       event.p2.mFloat = x;
3020       event.p3.mFloat = y;
3021       mImpl->mEventData->mEventQueue.push_back( event );
3022       mImpl->RequestRelayout();
3023
3024       mImpl->mEventData->mIsLeftHandleSelected = true;
3025       mImpl->mEventData->mIsRightHandleSelected = true;
3026     }
3027   }
3028 }
3029
3030 void Controller::SelectEvent( float x, float y, bool selectAll )
3031 {
3032   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3033
3034   if( NULL != mImpl->mEventData )
3035   {
3036     if( selectAll )
3037     {
3038       Event event( Event::SELECT_ALL );
3039       mImpl->mEventData->mEventQueue.push_back( event );
3040     }
3041     else
3042     {
3043       Event event( Event::SELECT );
3044       event.p2.mFloat = x;
3045       event.p3.mFloat = y;
3046       mImpl->mEventData->mEventQueue.push_back( event );
3047     }
3048
3049     mImpl->mEventData->mCheckScrollAmount = true;
3050     mImpl->mEventData->mIsLeftHandleSelected = true;
3051     mImpl->mEventData->mIsRightHandleSelected = true;
3052     mImpl->RequestRelayout();
3053   }
3054 }
3055
3056 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3057 {
3058   // Whether the text needs to be relaid-out.
3059   bool requestRelayout = false;
3060
3061   // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3062   bool retrieveText = false;
3063   bool retrieveCursor = false;
3064
3065   switch( inputMethodContextEvent.eventName )
3066   {
3067     case InputMethodContext::COMMIT:
3068     {
3069       InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3070       requestRelayout = true;
3071       retrieveCursor = true;
3072       break;
3073     }
3074     case InputMethodContext::PRE_EDIT:
3075     {
3076       InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3077       requestRelayout = true;
3078       retrieveCursor = true;
3079       break;
3080     }
3081     case InputMethodContext::DELETE_SURROUNDING:
3082     {
3083       const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3084                                            inputMethodContextEvent.numberOfChars,
3085                                            DONT_UPDATE_INPUT_STYLE );
3086
3087       if( textDeleted )
3088       {
3089         if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3090             !mImpl->IsPlaceholderAvailable() )
3091         {
3092           mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3093         }
3094         else
3095         {
3096           ShowPlaceholderText();
3097         }
3098         mImpl->mEventData->mUpdateCursorPosition = true;
3099         mImpl->mEventData->mScrollAfterDelete = true;
3100
3101         requestRelayout = true;
3102       }
3103       break;
3104     }
3105     case InputMethodContext::GET_SURROUNDING:
3106     {
3107       retrieveText = true;
3108       retrieveCursor = true;
3109       break;
3110     }
3111     case InputMethodContext::PRIVATE_COMMAND:
3112     {
3113       // PRIVATECOMMAND event is just for getting the private command message
3114       retrieveText = true;
3115       retrieveCursor = true;
3116       break;
3117     }
3118     case InputMethodContext::VOID:
3119     {
3120       // do nothing
3121       break;
3122     }
3123   } // end switch
3124
3125   if( requestRelayout )
3126   {
3127     mImpl->mOperationsPending = ALL_OPERATIONS;
3128     mImpl->RequestRelayout();
3129   }
3130
3131   std::string text;
3132   CharacterIndex cursorPosition = 0u;
3133   Length numberOfWhiteSpaces = 0u;
3134
3135   if( retrieveCursor )
3136   {
3137     numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3138
3139     cursorPosition = mImpl->GetLogicalCursorPosition();
3140
3141     if( cursorPosition < numberOfWhiteSpaces )
3142     {
3143       cursorPosition = 0u;
3144     }
3145     else
3146     {
3147       cursorPosition -= numberOfWhiteSpaces;
3148     }
3149   }
3150
3151   if( retrieveText )
3152   {
3153     if( !mImpl->IsShowingPlaceholderText() )
3154     {
3155       // Retrieves the normal text string.
3156       mImpl->GetText( numberOfWhiteSpaces, text );
3157     }
3158     else
3159     {
3160       // When the current text is Placeholder Text, the surrounding text should be empty string.
3161       // It means DALi should send empty string ("") to IME.
3162       text = "";
3163     }
3164   }
3165
3166   InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3167
3168   if( requestRelayout &&
3169       ( NULL != mImpl->mEditableControlInterface ) )
3170   {
3171     // Do this last since it provides callbacks into application code
3172     mImpl->mEditableControlInterface->TextChanged();
3173   }
3174
3175   return callbackData;
3176 }
3177
3178 void Controller::PasteClipboardItemEvent()
3179 {
3180   // Retrieve the clipboard contents first
3181   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3182   std::string stringToPaste( notifier.GetContent() );
3183
3184   // Commit the current pre-edit text; the contents of the clipboard should be appended
3185   mImpl->ResetInputMethodContext();
3186
3187   // Temporary disable hiding clipboard
3188   mImpl->SetClipboardHideEnable( false );
3189
3190   // Paste
3191   PasteText( stringToPaste );
3192
3193   mImpl->SetClipboardHideEnable( true );
3194 }
3195
3196 // protected : Inherit from Text::Decorator::ControllerInterface.
3197
3198 void Controller::GetTargetSize( Vector2& targetSize )
3199 {
3200   targetSize = mImpl->mModel->mVisualModel->mControlSize;
3201 }
3202
3203 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3204 {
3205   if( NULL != mImpl->mEditableControlInterface )
3206   {
3207     mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3208   }
3209 }
3210
3211 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3212 {
3213   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3214
3215   if( NULL != mImpl->mEventData )
3216   {
3217     switch( handleType )
3218     {
3219       case GRAB_HANDLE:
3220       {
3221         Event event( Event::GRAB_HANDLE_EVENT );
3222         event.p1.mUint  = state;
3223         event.p2.mFloat = x;
3224         event.p3.mFloat = y;
3225
3226         mImpl->mEventData->mEventQueue.push_back( event );
3227         break;
3228       }
3229       case LEFT_SELECTION_HANDLE:
3230       {
3231         Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3232         event.p1.mUint  = state;
3233         event.p2.mFloat = x;
3234         event.p3.mFloat = y;
3235
3236         mImpl->mEventData->mEventQueue.push_back( event );
3237         break;
3238       }
3239       case RIGHT_SELECTION_HANDLE:
3240       {
3241         Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3242         event.p1.mUint  = state;
3243         event.p2.mFloat = x;
3244         event.p3.mFloat = y;
3245
3246         mImpl->mEventData->mEventQueue.push_back( event );
3247         break;
3248       }
3249       case LEFT_SELECTION_HANDLE_MARKER:
3250       case RIGHT_SELECTION_HANDLE_MARKER:
3251       {
3252         // Markers do not move the handles.
3253         break;
3254       }
3255       case HANDLE_TYPE_COUNT:
3256       {
3257         DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3258       }
3259     }
3260
3261     mImpl->RequestRelayout();
3262   }
3263 }
3264
3265 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3266
3267 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3268 {
3269   if( NULL == mImpl->mEventData )
3270   {
3271     return;
3272   }
3273
3274   switch( button )
3275   {
3276     case Toolkit::TextSelectionPopup::CUT:
3277     {
3278       mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3279       mImpl->mOperationsPending = ALL_OPERATIONS;
3280
3281       if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3282           !mImpl->IsPlaceholderAvailable() )
3283       {
3284         mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3285       }
3286       else
3287       {
3288         ShowPlaceholderText();
3289       }
3290
3291       mImpl->mEventData->mUpdateCursorPosition = true;
3292       mImpl->mEventData->mScrollAfterDelete = true;
3293
3294       mImpl->RequestRelayout();
3295
3296       if( NULL != mImpl->mEditableControlInterface )
3297       {
3298         mImpl->mEditableControlInterface->TextChanged();
3299       }
3300       break;
3301     }
3302     case Toolkit::TextSelectionPopup::COPY:
3303     {
3304       mImpl->SendSelectionToClipboard( false ); // Text not modified
3305
3306       mImpl->mEventData->mUpdateCursorPosition = true;
3307
3308       mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3309       break;
3310     }
3311     case Toolkit::TextSelectionPopup::PASTE:
3312     {
3313       mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3314       break;
3315     }
3316     case Toolkit::TextSelectionPopup::SELECT:
3317     {
3318       const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3319
3320       if( mImpl->mEventData->mSelectionEnabled )
3321       {
3322         // Creates a SELECT event.
3323         SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3324       }
3325       break;
3326     }
3327     case Toolkit::TextSelectionPopup::SELECT_ALL:
3328     {
3329       // Creates a SELECT_ALL event
3330       SelectEvent( 0.f, 0.f, true );
3331       break;
3332     }
3333     case Toolkit::TextSelectionPopup::CLIPBOARD:
3334     {
3335       mImpl->ShowClipboard();
3336       break;
3337     }
3338     case Toolkit::TextSelectionPopup::NONE:
3339     {
3340       // Nothing to do.
3341       break;
3342     }
3343   }
3344 }
3345
3346 void Controller::DisplayTimeExpired()
3347 {
3348   mImpl->mEventData->mUpdateCursorPosition = true;
3349   // Apply modifications to the model
3350   mImpl->mOperationsPending = ALL_OPERATIONS;
3351
3352   mImpl->RequestRelayout();
3353 }
3354
3355 // private : Update.
3356
3357 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3358 {
3359   bool removedPrevious = false;
3360   bool removedSelected = false;
3361   bool maxLengthReached = false;
3362
3363   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3364
3365   if( NULL == mImpl->mEventData )
3366   {
3367     return;
3368   }
3369
3370   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3371                  this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3372                  mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3373
3374   // TODO: At the moment the underline runs are only for pre-edit.
3375   mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3376
3377   // Remove the previous InputMethodContext pre-edit.
3378   if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3379   {
3380     removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3381                                   mImpl->mEventData->mPreEditLength,
3382                                   DONT_UPDATE_INPUT_STYLE );
3383
3384     mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3385     mImpl->mEventData->mPreEditLength = 0u;
3386   }
3387   else
3388   {
3389     // Remove the previous Selection.
3390     removedSelected = RemoveSelectedText();
3391
3392   }
3393
3394   Vector<Character> utf32Characters;
3395   Length characterCount = 0u;
3396
3397   if( !text.empty() )
3398   {
3399     //  Convert text into UTF-32
3400     utf32Characters.Resize( text.size() );
3401
3402     // This is a bit horrible but std::string returns a (signed) char*
3403     const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3404
3405     // Transform a text array encoded in utf8 into an array encoded in utf32.
3406     // It returns the actual number of characters.
3407     characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3408     utf32Characters.Resize( characterCount );
3409
3410     DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3411     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3412   }
3413
3414   if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3415   {
3416     // The placeholder text is no longer needed
3417     if( mImpl->IsShowingPlaceholderText() )
3418     {
3419       ResetText();
3420     }
3421
3422     mImpl->ChangeState( EventData::EDITING );
3423
3424     // Handle the InputMethodContext (predicitive text) state changes
3425     if( COMMIT == type )
3426     {
3427       // InputMethodContext is no longer handling key-events
3428       mImpl->ClearPreEditFlag();
3429     }
3430     else // PRE_EDIT
3431     {
3432       if( !mImpl->mEventData->mPreEditFlag )
3433       {
3434         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3435
3436         // Record the start of the pre-edit text
3437         mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3438       }
3439
3440       mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3441       mImpl->mEventData->mPreEditFlag = true;
3442
3443       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3444     }
3445
3446     const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3447
3448     // Restrict new text to fit within Maximum characters setting.
3449     Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3450     maxLengthReached = ( characterCount > maxSizeOfNewText );
3451
3452     // The cursor position.
3453     CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3454
3455     // Update the text's style.
3456
3457     // Updates the text style runs by adding characters.
3458     mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3459
3460     // Get the character index from the cursor index.
3461     const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3462
3463     // Retrieve the text's style for the given index.
3464     InputStyle style;
3465     mImpl->RetrieveDefaultInputStyle( style );
3466     mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3467
3468     // Whether to add a new text color run.
3469     const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3470
3471     // Whether to add a new font run.
3472     const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3473     const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3474     const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3475     const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3476     const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3477
3478     // Add style runs.
3479     if( addColorRun )
3480     {
3481       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3482       mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3483
3484       ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3485       colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3486       colorRun.characterRun.characterIndex = cursorIndex;
3487       colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3488     }
3489
3490     if( addFontNameRun   ||
3491         addFontWeightRun ||
3492         addFontWidthRun  ||
3493         addFontSlantRun  ||
3494         addFontSizeRun )
3495     {
3496       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3497       mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3498
3499       FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3500
3501       if( addFontNameRun )
3502       {
3503         fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3504         fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3505         memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3506         fontDescriptionRun.familyDefined = true;
3507
3508         // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3509       }
3510
3511       if( addFontWeightRun )
3512       {
3513         fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3514         fontDescriptionRun.weightDefined = true;
3515       }
3516
3517       if( addFontWidthRun )
3518       {
3519         fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3520         fontDescriptionRun.widthDefined = true;
3521       }
3522
3523       if( addFontSlantRun )
3524       {
3525         fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3526         fontDescriptionRun.slantDefined = true;
3527       }
3528
3529       if( addFontSizeRun )
3530       {
3531         fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3532         fontDescriptionRun.sizeDefined = true;
3533       }
3534
3535       fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3536       fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3537     }
3538
3539     // Insert at current cursor position.
3540     Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3541
3542     if( cursorIndex < numberOfCharactersInModel )
3543     {
3544       modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3545     }
3546     else
3547     {
3548       modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3549     }
3550
3551     // Mark the first paragraph to be updated.
3552     if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3553     {
3554       mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3555       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3556       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3557       mImpl->mTextUpdateInfo.mClearAll = true;
3558     }
3559     else
3560     {
3561       mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3562       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3563     }
3564
3565     // Update the cursor index.
3566     cursorIndex += maxSizeOfNewText;
3567
3568     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
3569   }
3570
3571   if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3572       mImpl->IsPlaceholderAvailable() )
3573   {
3574     // Show place-holder if empty after removing the pre-edit text
3575     ShowPlaceholderText();
3576     mImpl->mEventData->mUpdateCursorPosition = true;
3577     mImpl->ClearPreEditFlag();
3578   }
3579   else if( removedPrevious ||
3580            removedSelected ||
3581            ( 0 != utf32Characters.Count() ) )
3582   {
3583     // Queue an inserted event
3584     mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3585
3586     mImpl->mEventData->mUpdateCursorPosition = true;
3587     if( removedSelected )
3588     {
3589       mImpl->mEventData->mScrollAfterDelete = true;
3590     }
3591     else
3592     {
3593       mImpl->mEventData->mScrollAfterUpdatePosition = true;
3594     }
3595   }
3596
3597   if( maxLengthReached )
3598   {
3599     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3600
3601     mImpl->ResetInputMethodContext();
3602
3603     if( NULL != mImpl->mEditableControlInterface )
3604     {
3605       // Do this last since it provides callbacks into application code
3606       mImpl->mEditableControlInterface->MaxLengthReached();
3607     }
3608   }
3609 }
3610
3611 void Controller::PasteText( const std::string& stringToPaste )
3612 {
3613   InsertText( stringToPaste, Text::Controller::COMMIT );
3614   mImpl->ChangeState( EventData::EDITING );
3615   mImpl->RequestRelayout();
3616
3617   if( NULL != mImpl->mEditableControlInterface )
3618   {
3619     // Do this last since it provides callbacks into application code
3620     mImpl->mEditableControlInterface->TextChanged();
3621   }
3622 }
3623
3624 bool Controller::RemoveText( int cursorOffset,
3625                              int numberOfCharacters,
3626                              UpdateInputStyleType type )
3627 {
3628   bool removed = false;
3629
3630   if( NULL == mImpl->mEventData )
3631   {
3632     return removed;
3633   }
3634
3635   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3636                  this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3637
3638   if( !mImpl->IsShowingPlaceholderText() )
3639   {
3640     // Delete at current cursor position
3641     Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3642     CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3643
3644     CharacterIndex cursorIndex = 0;
3645
3646     // Validate the cursor position & number of characters
3647     if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3648     {
3649       cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3650     }
3651
3652     if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3653     {
3654       numberOfCharacters = currentText.Count() - cursorIndex;
3655     }
3656
3657     if( mImpl->mEventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
3658         ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3659     {
3660       // Mark the paragraphs to be updated.
3661       if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3662       {
3663         mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3664         mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3665         mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3666         mImpl->mTextUpdateInfo.mClearAll = true;
3667       }
3668       else
3669       {
3670         mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3671         mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3672       }
3673
3674       // Update the input style and remove the text's style before removing the text.
3675
3676       if( UPDATE_INPUT_STYLE == type )
3677       {
3678         // Keep a copy of the current input style.
3679         InputStyle currentInputStyle;
3680         currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3681
3682         // Set first the default input style.
3683         mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3684
3685         // Update the input style.
3686         mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3687
3688         // Compare if the input style has changed.
3689         const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3690
3691         if( hasInputStyleChanged )
3692         {
3693           const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3694           // Queue the input style changed signal.
3695           mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3696         }
3697       }
3698
3699       // Updates the text style runs by removing characters. Runs with no characters are removed.
3700       mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3701
3702       // Remove the characters.
3703       Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3704       Vector<Character>::Iterator last  = first + numberOfCharacters;
3705
3706       currentText.Erase( first, last );
3707
3708       // Cursor position retreat
3709       oldCursorIndex = cursorIndex;
3710
3711       mImpl->mEventData->mScrollAfterDelete = true;
3712
3713       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3714       removed = true;
3715     }
3716   }
3717
3718   return removed;
3719 }
3720
3721 bool Controller::RemoveSelectedText()
3722 {
3723   bool textRemoved( false );
3724
3725   if( EventData::SELECTING == mImpl->mEventData->mState )
3726   {
3727     std::string removedString;
3728     mImpl->RetrieveSelection( removedString, true );
3729
3730     if( !removedString.empty() )
3731     {
3732       textRemoved = true;
3733       mImpl->ChangeState( EventData::EDITING );
3734     }
3735   }
3736
3737   return textRemoved;
3738 }
3739
3740 // private : Relayout.
3741
3742 bool Controller::DoRelayout( const Size& size,
3743                              OperationsMask operationsRequired,
3744                              Size& layoutSize )
3745 {
3746   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3747   bool viewUpdated( false );
3748
3749   // Calculate the operations to be done.
3750   const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3751
3752   const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3753   const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3754
3755   // Get the current layout size.
3756   layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3757
3758   if( NO_OPERATION != ( LAYOUT & operations ) )
3759   {
3760     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3761
3762     // Some vectors with data needed to layout and reorder may be void
3763     // after the first time the text has been laid out.
3764     // Fill the vectors again.
3765
3766     // Calculate the number of glyphs to layout.
3767     const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3768     const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3769     const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3770     const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3771
3772     const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3773     const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3774
3775     // Make sure the index is not out of bound
3776     if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3777          requestedNumberOfCharacters > charactersToGlyph.Count() ||
3778          ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3779     {
3780       std::string currentText;
3781       GetText( currentText );
3782
3783       DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3784       DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3785       DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3786
3787       return false;
3788     }
3789
3790     const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3791     const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3792
3793     if( 0u == totalNumberOfGlyphs )
3794     {
3795       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3796       {
3797         mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3798       }
3799
3800       // Nothing else to do if there is no glyphs.
3801       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3802       return true;
3803     }
3804
3805     const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3806     const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3807     const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3808     const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3809     const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3810     const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3811     const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3812     const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3813
3814     // Set the layout parameters.
3815     Layout::Parameters layoutParameters( size,
3816                                          textBuffer,
3817                                          lineBreakInfo.Begin(),
3818                                          wordBreakInfo.Begin(),
3819                                          ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3820                                          glyphs.Begin(),
3821                                          glyphsToCharactersMap.Begin(),
3822                                          charactersPerGlyph.Begin(),
3823                                          charactersToGlyphBuffer,
3824                                          glyphsPerCharacterBuffer,
3825                                          totalNumberOfGlyphs,
3826                                          mImpl->mModel->mHorizontalAlignment,
3827                                          mImpl->mModel->mLineWrapMode,
3828                                          outlineWidth,
3829                                          mImpl->mModel->mIgnoreSpacesAfterText,
3830                                          mImpl->mModel->mMatchSystemLanguageDirection );
3831
3832     // Resize the vector of positions to have the same size than the vector of glyphs.
3833     Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3834     glyphPositions.Resize( totalNumberOfGlyphs );
3835
3836     // Whether the last character is a new paragraph character.
3837     mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph =  TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3838     layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3839
3840     // The initial glyph and the number of glyphs to layout.
3841     layoutParameters.startGlyphIndex = startGlyphIndex;
3842     layoutParameters.numberOfGlyphs = numberOfGlyphs;
3843     layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3844     layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3845
3846     // Update the ellipsis
3847     bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3848
3849     if( NULL != mImpl->mEventData )
3850     {
3851       if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3852       {
3853         elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3854       }
3855       else if( EventData::INACTIVE != mImpl->mEventData->mState )
3856       {
3857         // Disable ellipsis when editing
3858         elideTextEnabled = false;
3859       }
3860
3861       // Reset the scroll position in inactive state
3862       if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3863       {
3864         ResetScrollPosition();
3865       }
3866     }
3867
3868     // Update the visual model.
3869     bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3870     Size newLayoutSize;
3871     viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3872                                                    glyphPositions,
3873                                                    mImpl->mModel->mVisualModel->mLines,
3874                                                    newLayoutSize,
3875                                                    elideTextEnabled,
3876                                                    isAutoScrollEnabled );
3877     mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3878
3879     viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3880
3881     if( viewUpdated )
3882     {
3883       layoutSize = newLayoutSize;
3884
3885       if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3886       {
3887         mImpl->mIsTextDirectionRTL = false;
3888       }
3889
3890       // Reorder the lines
3891       if( NO_OPERATION != ( REORDER & operations ) )
3892       {
3893         Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3894         Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3895
3896         // Check first if there are paragraphs with bidirectional info.
3897         if( 0u != bidirectionalInfo.Count() )
3898         {
3899           // Get the lines
3900           const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3901
3902           // Reorder the lines.
3903           bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3904           ReorderLines( bidirectionalInfo,
3905                         startIndex,
3906                         requestedNumberOfCharacters,
3907                         mImpl->mModel->mVisualModel->mLines,
3908                         bidirectionalLineInfo );
3909
3910           // Set the bidirectional info per line into the layout parameters.
3911           layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3912           layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3913
3914           // Re-layout the text. Reorder those lines with right to left characters.
3915           mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3916                                                          startIndex,
3917                                                          requestedNumberOfCharacters,
3918                                                          glyphPositions );
3919
3920           if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3921           {
3922             const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3923             if ( firstline )
3924             {
3925               mImpl->mIsTextDirectionRTL = firstline->direction;
3926             }
3927           }
3928         }
3929       } // REORDER
3930
3931       // Sets the layout size.
3932       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3933       {
3934         mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3935       }
3936     } // view updated
3937   }
3938
3939   if( NO_OPERATION != ( ALIGN & operations ) )
3940   {
3941     // The laid-out lines.
3942     Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3943
3944     // Need to align with the control's size as the text may contain lines
3945     // starting either with left to right text or right to left.
3946     mImpl->mLayoutEngine.Align( size,
3947                                 startIndex,
3948                                 requestedNumberOfCharacters,
3949                                 mImpl->mModel->mHorizontalAlignment,
3950                                 lines,
3951                                 mImpl->mModel->mAlignmentOffset,
3952                                 mImpl->mLayoutDirection,
3953                                 mImpl->mModel->mMatchSystemLanguageDirection );
3954
3955     viewUpdated = true;
3956   }
3957 #if defined(DEBUG_ENABLED)
3958   std::string currentText;
3959   GetText( currentText );
3960   DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false",  currentText.c_str() );
3961 #endif
3962   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3963   return viewUpdated;
3964 }
3965
3966 void Controller::CalculateVerticalOffset( const Size& controlSize )
3967 {
3968   Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3969
3970   if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3971   {
3972     // Get the line height of the default font.
3973     layoutSize.height = mImpl->GetDefaultFontLineHeight();
3974   }
3975
3976   switch( mImpl->mModel->mVerticalAlignment )
3977   {
3978     case VerticalAlignment::TOP:
3979     {
3980       mImpl->mModel->mScrollPosition.y = 0.f;
3981       break;
3982     }
3983     case VerticalAlignment::CENTER:
3984     {
3985       mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3986       break;
3987     }
3988     case VerticalAlignment::BOTTOM:
3989     {
3990       mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3991       break;
3992     }
3993   }
3994 }
3995
3996 // private : Events.
3997
3998 void Controller::ProcessModifyEvents()
3999 {
4000   Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4001
4002   if( 0u == events.Count() )
4003   {
4004     // Nothing to do.
4005     return;
4006   }
4007
4008   for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4009          endIt = events.End();
4010        it != endIt;
4011        ++it )
4012   {
4013     const ModifyEvent& event = *it;
4014
4015     if( ModifyEvent::TEXT_REPLACED == event.type )
4016     {
4017       // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4018       DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4019
4020       TextReplacedEvent();
4021     }
4022     else if( ModifyEvent::TEXT_INSERTED == event.type )
4023     {
4024       TextInsertedEvent();
4025     }
4026     else if( ModifyEvent::TEXT_DELETED == event.type )
4027     {
4028       // Placeholder-text cannot be deleted
4029       if( !mImpl->IsShowingPlaceholderText() )
4030       {
4031         TextDeletedEvent();
4032       }
4033     }
4034   }
4035
4036   if( NULL != mImpl->mEventData )
4037   {
4038     // When the text is being modified, delay cursor blinking
4039     mImpl->mEventData->mDecorator->DelayCursorBlink();
4040
4041     // Update selection position after modifying the text
4042     mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4043     mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4044   }
4045
4046   // Discard temporary text
4047   events.Clear();
4048 }
4049
4050 void Controller::TextReplacedEvent()
4051 {
4052   // The natural size needs to be re-calculated.
4053   mImpl->mRecalculateNaturalSize = true;
4054
4055   // The text direction needs to be updated.
4056   mImpl->mUpdateTextDirection = true;
4057
4058   // Apply modifications to the model
4059   mImpl->mOperationsPending = ALL_OPERATIONS;
4060 }
4061
4062 void Controller::TextInsertedEvent()
4063 {
4064   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4065
4066   if( NULL == mImpl->mEventData )
4067   {
4068     return;
4069   }
4070
4071   mImpl->mEventData->mCheckScrollAmount = true;
4072
4073   // The natural size needs to be re-calculated.
4074   mImpl->mRecalculateNaturalSize = true;
4075
4076   // The text direction needs to be updated.
4077   mImpl->mUpdateTextDirection = true;
4078
4079   // Apply modifications to the model; TODO - Optimize this
4080   mImpl->mOperationsPending = ALL_OPERATIONS;
4081 }
4082
4083 void Controller::TextDeletedEvent()
4084 {
4085   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4086
4087   if( NULL == mImpl->mEventData )
4088   {
4089     return;
4090   }
4091
4092   mImpl->mEventData->mCheckScrollAmount = true;
4093
4094   // The natural size needs to be re-calculated.
4095   mImpl->mRecalculateNaturalSize = true;
4096
4097   // The text direction needs to be updated.
4098   mImpl->mUpdateTextDirection = true;
4099
4100   // Apply modifications to the model; TODO - Optimize this
4101   mImpl->mOperationsPending = ALL_OPERATIONS;
4102 }
4103
4104 bool Controller::DeleteEvent( int keyCode )
4105 {
4106   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4107
4108   bool removed = false;
4109
4110   if( NULL == mImpl->mEventData )
4111   {
4112     return removed;
4113   }
4114
4115   // InputMethodContext is no longer handling key-events
4116   mImpl->ClearPreEditFlag();
4117
4118   if( EventData::SELECTING == mImpl->mEventData->mState )
4119   {
4120     removed = RemoveSelectedText();
4121   }
4122   else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4123   {
4124     // Remove the character before the current cursor position
4125     removed = RemoveText( -1,
4126                           1,
4127                           UPDATE_INPUT_STYLE );
4128   }
4129   else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4130   {
4131     // Remove the character after the current cursor position
4132     removed = RemoveText( 0,
4133                           1,
4134                           UPDATE_INPUT_STYLE );
4135   }
4136
4137   if( removed )
4138   {
4139     if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4140         !mImpl->IsPlaceholderAvailable() )
4141     {
4142       mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4143     }
4144     else
4145     {
4146       ShowPlaceholderText();
4147     }
4148     mImpl->mEventData->mUpdateCursorPosition = true;
4149     mImpl->mEventData->mScrollAfterDelete = true;
4150   }
4151
4152   return removed;
4153 }
4154
4155 // private : Helpers.
4156
4157 void Controller::ResetText()
4158 {
4159   // Reset buffers.
4160   mImpl->mModel->mLogicalModel->mText.Clear();
4161
4162   // Reset the embedded images buffer.
4163   mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4164
4165   // We have cleared everything including the placeholder-text
4166   mImpl->PlaceholderCleared();
4167
4168   mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4169   mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4170   mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4171
4172   // Clear any previous text.
4173   mImpl->mTextUpdateInfo.mClearAll = true;
4174
4175   // The natural size needs to be re-calculated.
4176   mImpl->mRecalculateNaturalSize = true;
4177
4178   // The text direction needs to be updated.
4179   mImpl->mUpdateTextDirection = true;
4180
4181   // Apply modifications to the model
4182   mImpl->mOperationsPending = ALL_OPERATIONS;
4183 }
4184
4185 void Controller::ShowPlaceholderText()
4186 {
4187   if( mImpl->IsPlaceholderAvailable() )
4188   {
4189     DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4190
4191     if( NULL == mImpl->mEventData )
4192     {
4193       return;
4194     }
4195
4196     mImpl->mEventData->mIsShowingPlaceholderText = true;
4197
4198     // Disable handles when showing place-holder text
4199     mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4200     mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4201     mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4202
4203     const char* text( NULL );
4204     size_t size( 0 );
4205
4206     // TODO - Switch Placeholder text when changing state
4207     if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4208         ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4209     {
4210       text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4211       size = mImpl->mEventData->mPlaceholderTextActive.size();
4212     }
4213     else
4214     {
4215       text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4216       size = mImpl->mEventData->mPlaceholderTextInactive.size();
4217     }
4218
4219     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4220     mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4221
4222     // Reset model for showing placeholder.
4223     mImpl->mModel->mLogicalModel->mText.Clear();
4224     mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4225
4226     // Convert text into UTF-32
4227     Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4228     utf32Characters.Resize( size );
4229
4230     // This is a bit horrible but std::string returns a (signed) char*
4231     const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4232
4233     // Transform a text array encoded in utf8 into an array encoded in utf32.
4234     // It returns the actual number of characters.
4235     const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4236     utf32Characters.Resize( characterCount );
4237
4238     // The characters to be added.
4239     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4240
4241     // Reset the cursor position
4242     mImpl->mEventData->mPrimaryCursorPosition = 0;
4243
4244     // The natural size needs to be re-calculated.
4245     mImpl->mRecalculateNaturalSize = true;
4246
4247     // The text direction needs to be updated.
4248     mImpl->mUpdateTextDirection = true;
4249
4250     // Apply modifications to the model
4251     mImpl->mOperationsPending = ALL_OPERATIONS;
4252
4253     // Update the rest of the model during size negotiation
4254     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4255   }
4256 }
4257
4258 void Controller::ClearFontData()
4259 {
4260   if( mImpl->mFontDefaults )
4261   {
4262     mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4263   }
4264
4265   // Set flags to update the model.
4266   mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4267   mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4268   mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4269
4270   mImpl->mTextUpdateInfo.mClearAll = true;
4271   mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4272   mImpl->mRecalculateNaturalSize = true;
4273
4274   mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4275                                                            VALIDATE_FONTS            |
4276                                                            SHAPE_TEXT                |
4277                                                            BIDI_INFO                 |
4278                                                            GET_GLYPH_METRICS         |
4279                                                            LAYOUT                    |
4280                                                            UPDATE_LAYOUT_SIZE        |
4281                                                            REORDER                   |
4282                                                            ALIGN );
4283 }
4284
4285 void Controller::ClearStyleData()
4286 {
4287   mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4288   mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4289 }
4290
4291 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4292 {
4293   // Reset the cursor position
4294   if( NULL != mImpl->mEventData )
4295   {
4296     mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4297
4298     // Update the cursor if it's in editing mode.
4299     if( EventData::IsEditingState( mImpl->mEventData->mState )  )
4300     {
4301       mImpl->mEventData->mUpdateCursorPosition = true;
4302     }
4303   }
4304 }
4305
4306 void Controller::ResetScrollPosition()
4307 {
4308   if( NULL != mImpl->mEventData )
4309   {
4310     // Reset the scroll position.
4311     mImpl->mModel->mScrollPosition = Vector2::ZERO;
4312     mImpl->mEventData->mScrollAfterUpdatePosition = true;
4313   }
4314 }
4315
4316 void Controller::SetControlInterface( ControlInterface* controlInterface )
4317 {
4318   mImpl->mControlInterface = controlInterface;
4319 }
4320
4321 bool Controller::ShouldClearFocusOnEscape() const
4322 {
4323   return mImpl->mShouldClearFocusOnEscape;
4324 }
4325
4326 // private : Private contructors & copy operator.
4327
4328 Controller::Controller()
4329 : mImpl( NULL )
4330 {
4331   mImpl = new Controller::Impl( NULL, NULL );
4332 }
4333
4334 Controller::Controller( ControlInterface* controlInterface )
4335 {
4336   mImpl = new Controller::Impl( controlInterface, NULL );
4337 }
4338
4339 Controller::Controller( ControlInterface* controlInterface,
4340                         EditableControlInterface* editableControlInterface )
4341 {
4342   mImpl = new Controller::Impl( controlInterface,
4343                                 editableControlInterface );
4344 }
4345
4346 // The copy constructor and operator are left unimplemented.
4347
4348 // protected : Destructor.
4349
4350 Controller::~Controller()
4351 {
4352   delete mImpl;
4353 }
4354
4355 } // namespace Text
4356
4357 } // namespace Toolkit
4358
4359 } // namespace Dali