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