2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/text-controller.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>
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>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const std::string EMPTY_STRING("");
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";
59 float ConvertToEven( float value )
61 int intValue(static_cast<int>( value ));
62 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
77 * @brief Adds a new font description run for the selected text.
79 * The new font parameters are added after the call to this method.
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.
86 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
87 LogicalModelPtr logicalModel,
88 CharacterIndex& startOfSelectedText,
89 Length& lengthOfSelectedText )
91 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
93 // Get start and end position of selection
94 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
95 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
98 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
99 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
101 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
103 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
104 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
106 // Recalculate the selection highlight as the metrics may have changed.
107 eventData->mUpdateLeftSelectionPosition = true;
108 eventData->mUpdateRightSelectionPosition = true;
109 eventData->mUpdateHighlightBox = true;
111 return fontDescriptionRun;
114 // public : Constructor.
116 ControllerPtr Controller::New()
118 return ControllerPtr( new Controller() );
121 ControllerPtr Controller::New( ControlInterface* controlInterface )
123 return ControllerPtr( new Controller( controlInterface ) );
126 ControllerPtr Controller::New( ControlInterface* controlInterface,
127 EditableControlInterface* editableControlInterface )
129 return ControllerPtr( new Controller( controlInterface,
130 editableControlInterface ) );
133 // public : Configure the text controller.
135 void Controller::EnableTextInput( DecoratorPtr decorator )
139 delete mImpl->mEventData;
140 mImpl->mEventData = NULL;
142 // Nothing else to do.
146 if( NULL == mImpl->mEventData )
148 mImpl->mEventData = new EventData( decorator );
152 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
154 // Metrics for bitmap & vector based glyphs are different
155 mImpl->mMetrics->SetGlyphType( glyphType );
157 // Clear the font-specific data
160 mImpl->RequestRelayout();
163 void Controller::SetMarkupProcessorEnabled( bool enable )
165 mImpl->mMarkupProcessorEnabled = enable;
168 bool Controller::IsMarkupProcessorEnabled() const
170 return mImpl->mMarkupProcessorEnabled;
173 void Controller::SetAutoScrollEnabled( bool enable )
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 );
177 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
181 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
182 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
192 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
193 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
200 mImpl->mIsAutoScrollEnabled = enable;
201 mImpl->RequestRelayout();
205 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
206 mImpl->mIsAutoScrollEnabled = false;
210 bool Controller::IsAutoScrollEnabled() const
212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
214 return mImpl->mIsAutoScrollEnabled;
217 CharacterDirection Controller::GetAutoScrollDirection() const
219 return mImpl->mAutoScrollDirectionRTL;
222 float Controller::GetAutoScrollLineAlignment() const
226 if( mImpl->mModel->mVisualModel &&
227 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
229 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
235 void Controller::SetHorizontalScrollEnabled( bool enable )
237 if( ( NULL != mImpl->mEventData ) &&
238 mImpl->mEventData->mDecorator )
240 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
243 bool Controller::IsHorizontalScrollEnabled() const
245 if( ( NULL != mImpl->mEventData ) &&
246 mImpl->mEventData->mDecorator )
248 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
254 void Controller::SetVerticalScrollEnabled( bool enable )
256 if( ( NULL != mImpl->mEventData ) &&
257 mImpl->mEventData->mDecorator )
259 if( mImpl->mEventData->mDecorator )
261 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
266 bool Controller::IsVerticalScrollEnabled() const
268 if( ( NULL != mImpl->mEventData ) &&
269 mImpl->mEventData->mDecorator )
271 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
277 void Controller::SetSmoothHandlePanEnabled( bool enable )
279 if( ( NULL != mImpl->mEventData ) &&
280 mImpl->mEventData->mDecorator )
282 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
286 bool Controller::IsSmoothHandlePanEnabled() const
288 if( ( NULL != mImpl->mEventData ) &&
289 mImpl->mEventData->mDecorator )
291 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
297 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
299 mImpl->mMaximumNumberOfCharacters = maxCharacters;
302 int Controller::GetMaximumNumberOfCharacters()
304 return mImpl->mMaximumNumberOfCharacters;
307 void Controller::SetEnableCursorBlink( bool enable )
309 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
311 if( NULL != mImpl->mEventData )
313 mImpl->mEventData->mCursorBlinkEnabled = enable;
316 mImpl->mEventData->mDecorator )
318 mImpl->mEventData->mDecorator->StopCursorBlink();
323 bool Controller::GetEnableCursorBlink() const
325 if( NULL != mImpl->mEventData )
327 return mImpl->mEventData->mCursorBlinkEnabled;
333 void Controller::SetMultiLineEnabled( bool enable )
335 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
337 if( layout != mImpl->mLayoutEngine.GetLayout() )
339 // Set the layout type.
340 mImpl->mLayoutEngine.SetLayout( layout );
342 // Set the flags to redo the layout operations
343 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
348 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
350 mImpl->RequestRelayout();
354 bool Controller::IsMultiLineEnabled() const
356 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
359 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
361 if( alignment != mImpl->mModel->mHorizontalAlignment )
363 // Set the alignment.
364 mImpl->mModel->mHorizontalAlignment = alignment;
366 // Set the flag to redo the alignment operation.
367 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
369 mImpl->RequestRelayout();
373 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
375 return mImpl->mModel->mHorizontalAlignment;
378 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
380 if( alignment != mImpl->mModel->mVerticalAlignment )
382 // Set the alignment.
383 mImpl->mModel->mVerticalAlignment = alignment;
385 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
387 mImpl->RequestRelayout();
391 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
393 return mImpl->mModel->mVerticalAlignment;
396 void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
398 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
400 // Set the text wrap mode.
401 mImpl->mModel->mLineWrapMode = lineWrapMode;
404 // Update Text layout for applying wrap mode
405 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
410 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
411 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
412 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
415 mImpl->RequestRelayout();
419 Layout::LineWrap::Mode Controller::GetLineWrapMode() const
421 return mImpl->mModel->mLineWrapMode;
424 void Controller::SetTextElideEnabled( bool enabled )
426 mImpl->mModel->mElideEnabled = enabled;
429 bool Controller::IsTextElideEnabled() const
431 return mImpl->mModel->mElideEnabled;
434 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
436 mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
437 mImpl->mEventData->mPlaceholderEllipsisFlag = true;
439 // Update placeholder if there is no text
440 if( mImpl->IsShowingPlaceholderText() ||
441 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
443 ShowPlaceholderText();
447 bool Controller::IsPlaceholderTextElideEnabled() const
449 return mImpl->mEventData->mIsPlaceholderElideEnabled;
452 void Controller::SetSelectionEnabled( bool enabled )
454 mImpl->mEventData->mSelectionEnabled = enabled;
457 bool Controller::IsSelectionEnabled() const
459 return mImpl->mEventData->mSelectionEnabled;
464 void Controller::SetText( const std::string& text )
466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
468 // Reset keyboard as text changed
469 mImpl->ResetImfManager();
471 // Remove the previously set text and style.
477 CharacterIndex lastCursorIndex = 0u;
479 if( NULL != mImpl->mEventData )
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 ) )
487 mImpl->ChangeState( EventData::EDITING );
493 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
495 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
496 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
498 Length textSize = 0u;
499 const uint8_t* utf8 = NULL;
500 if( mImpl->mMarkupProcessorEnabled )
502 ProcessMarkupString( text, markupProcessData );
503 textSize = markupProcessData.markupProcessedText.size();
505 // This is a bit horrible but std::string returns a (signed) char*
506 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
510 textSize = text.size();
512 // This is a bit horrible but std::string returns a (signed) char*
513 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
516 // Convert text into UTF-32
517 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
518 utf32Characters.Resize( textSize );
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 );
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() );
528 // The characters to be added.
529 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
531 // To reset the cursor position
532 lastCursorIndex = characterCount;
534 // Update the rest of the model during size negotiation
535 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
537 // The natural size needs to be re-calculated.
538 mImpl->mRecalculateNaturalSize = true;
540 // Apply modifications to the model
541 mImpl->mOperationsPending = ALL_OPERATIONS;
545 ShowPlaceholderText();
548 // Resets the cursor position.
549 ResetCursorPosition( lastCursorIndex );
551 // Scrolls the text to make the cursor visible.
552 ResetScrollPosition();
554 mImpl->RequestRelayout();
556 if( NULL != mImpl->mEventData )
558 // Cancel previously queued events
559 mImpl->mEventData->mEventQueue.clear();
562 // Do this last since it provides callbacks into application code.
563 if( NULL != mImpl->mEditableControlInterface )
565 mImpl->mEditableControlInterface->TextChanged();
569 void Controller::GetText( std::string& text ) const
571 if( !mImpl->IsShowingPlaceholderText() )
573 // Retrieves the text string.
574 mImpl->GetText( 0u, text );
578 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
582 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
584 if( NULL != mImpl->mEventData )
586 if( PLACEHOLDER_TYPE_INACTIVE == type )
588 mImpl->mEventData->mPlaceholderTextInactive = text;
592 mImpl->mEventData->mPlaceholderTextActive = text;
595 // Update placeholder if there is no text
596 if( mImpl->IsShowingPlaceholderText() ||
597 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
599 ShowPlaceholderText();
604 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
606 if( NULL != mImpl->mEventData )
608 if( PLACEHOLDER_TYPE_INACTIVE == type )
610 text = mImpl->mEventData->mPlaceholderTextInactive;
614 text = mImpl->mEventData->mPlaceholderTextActive;
619 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
621 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
623 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
625 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
626 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
630 mImpl->RequestRelayout();
634 // public : Default style & Input style
636 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
638 if( NULL == mImpl->mFontDefaults )
640 mImpl->mFontDefaults = new FontDefaults();
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();
647 // Clear the font-specific data
650 mImpl->RequestRelayout();
653 const std::string& Controller::GetDefaultFontFamily() const
655 if( NULL != mImpl->mFontDefaults )
657 return mImpl->mFontDefaults->mFontDescription.family;
663 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
665 if( NULL != mImpl->mEventData )
667 if( NULL == mImpl->mEventData->mPlaceholderFont )
669 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
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();
676 mImpl->RequestRelayout();
680 const std::string& Controller::GetPlaceholderFontFamily() const
682 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
684 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
690 void Controller::SetDefaultFontWeight( FontWeight weight )
692 if( NULL == mImpl->mFontDefaults )
694 mImpl->mFontDefaults = new FontDefaults();
697 mImpl->mFontDefaults->mFontDescription.weight = weight;
698 mImpl->mFontDefaults->weightDefined = true;
700 // Clear the font-specific data
703 mImpl->RequestRelayout();
706 bool Controller::IsDefaultFontWeightDefined() const
708 if( NULL != mImpl->mFontDefaults )
710 return mImpl->mFontDefaults->weightDefined;
716 FontWeight Controller::GetDefaultFontWeight() const
718 if( NULL != mImpl->mFontDefaults )
720 return mImpl->mFontDefaults->mFontDescription.weight;
723 return TextAbstraction::FontWeight::NORMAL;
726 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
728 if( NULL != mImpl->mEventData )
730 if( NULL == mImpl->mEventData->mPlaceholderFont )
732 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
735 mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
736 mImpl->mEventData->mPlaceholderFont->weightDefined = true;
738 mImpl->RequestRelayout();
742 bool Controller::IsPlaceholderTextFontWeightDefined() const
744 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
746 return mImpl->mEventData->mPlaceholderFont->weightDefined;
751 FontWeight Controller::GetPlaceholderTextFontWeight() const
753 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
755 return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
758 return TextAbstraction::FontWeight::NORMAL;
761 void Controller::SetDefaultFontWidth( FontWidth width )
763 if( NULL == mImpl->mFontDefaults )
765 mImpl->mFontDefaults = new FontDefaults();
768 mImpl->mFontDefaults->mFontDescription.width = width;
769 mImpl->mFontDefaults->widthDefined = true;
771 // Clear the font-specific data
774 mImpl->RequestRelayout();
777 bool Controller::IsDefaultFontWidthDefined() const
779 if( NULL != mImpl->mFontDefaults )
781 return mImpl->mFontDefaults->widthDefined;
787 FontWidth Controller::GetDefaultFontWidth() const
789 if( NULL != mImpl->mFontDefaults )
791 return mImpl->mFontDefaults->mFontDescription.width;
794 return TextAbstraction::FontWidth::NORMAL;
797 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
799 if( NULL != mImpl->mEventData )
801 if( NULL == mImpl->mEventData->mPlaceholderFont )
803 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
806 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
807 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
809 mImpl->RequestRelayout();
813 bool Controller::IsPlaceholderTextFontWidthDefined() const
815 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
817 return mImpl->mEventData->mPlaceholderFont->widthDefined;
822 FontWidth Controller::GetPlaceholderTextFontWidth() const
824 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
826 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
829 return TextAbstraction::FontWidth::NORMAL;
832 void Controller::SetDefaultFontSlant( FontSlant slant )
834 if( NULL == mImpl->mFontDefaults )
836 mImpl->mFontDefaults = new FontDefaults();
839 mImpl->mFontDefaults->mFontDescription.slant = slant;
840 mImpl->mFontDefaults->slantDefined = true;
842 // Clear the font-specific data
845 mImpl->RequestRelayout();
848 bool Controller::IsDefaultFontSlantDefined() const
850 if( NULL != mImpl->mFontDefaults )
852 return mImpl->mFontDefaults->slantDefined;
857 FontSlant Controller::GetDefaultFontSlant() const
859 if( NULL != mImpl->mFontDefaults )
861 return mImpl->mFontDefaults->mFontDescription.slant;
864 return TextAbstraction::FontSlant::NORMAL;
867 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
869 if( NULL != mImpl->mEventData )
871 if( NULL == mImpl->mEventData->mPlaceholderFont )
873 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
876 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
877 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
879 mImpl->RequestRelayout();
883 bool Controller::IsPlaceholderTextFontSlantDefined() const
885 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
887 return mImpl->mEventData->mPlaceholderFont->slantDefined;
892 FontSlant Controller::GetPlaceholderTextFontSlant() const
894 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
896 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
899 return TextAbstraction::FontSlant::NORMAL;
902 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
904 if( NULL == mImpl->mFontDefaults )
906 mImpl->mFontDefaults = new FontDefaults();
913 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
914 mImpl->mFontDefaults->sizeDefined = true;
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 );
925 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
926 mImpl->mFontDefaults->sizeDefined = true;
931 // Clear the font-specific data
934 mImpl->RequestRelayout();
937 float Controller::GetDefaultFontSize( FontSizeType type ) const
940 if( NULL != mImpl->mFontDefaults )
946 value = mImpl->mFontDefaults->mDefaultPointSize;
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 );
957 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
967 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
969 if( NULL != mImpl->mEventData )
971 if( NULL == mImpl->mEventData->mPlaceholderFont )
973 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
980 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
981 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
982 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
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 );
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
1000 mImpl->RequestRelayout();
1004 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1007 if( NULL != mImpl->mEventData )
1013 if( NULL != mImpl->mEventData->mPlaceholderFont )
1015 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1019 // If the placeholder text font size is not set, then return the default font size.
1020 value = GetDefaultFontSize( POINT_SIZE );
1026 if( NULL != mImpl->mEventData->mPlaceholderFont )
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 );
1034 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1038 // If the placeholder text font size is not set, then return the default font size.
1039 value = GetDefaultFontSize( PIXEL_SIZE );
1050 void Controller::SetDefaultColor( const Vector4& color )
1052 mImpl->mTextColor = color;
1054 if( !mImpl->IsShowingPlaceholderText() )
1056 mImpl->mModel->mVisualModel->SetTextColor( color );
1058 mImpl->RequestRelayout();
1062 const Vector4& Controller::GetDefaultColor() const
1064 return mImpl->mTextColor;
1067 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1069 if( NULL != mImpl->mEventData )
1071 mImpl->mEventData->mPlaceholderTextColor = textColor;
1074 if( mImpl->IsShowingPlaceholderText() )
1076 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1077 mImpl->RequestRelayout();
1081 const Vector4& Controller::GetPlaceholderTextColor() const
1083 if( NULL != mImpl->mEventData )
1085 return mImpl->mEventData->mPlaceholderTextColor;
1088 return Color::BLACK;
1091 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1093 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1095 mImpl->RequestRelayout();
1098 const Vector2& Controller::GetShadowOffset() const
1100 return mImpl->mModel->mVisualModel->GetShadowOffset();
1103 void Controller::SetShadowColor( const Vector4& shadowColor )
1105 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1107 mImpl->RequestRelayout();
1110 const Vector4& Controller::GetShadowColor() const
1112 return mImpl->mModel->mVisualModel->GetShadowColor();
1115 void Controller::SetUnderlineColor( const Vector4& color )
1117 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1119 mImpl->RequestRelayout();
1122 const Vector4& Controller::GetUnderlineColor() const
1124 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1127 void Controller::SetUnderlineEnabled( bool enabled )
1129 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1131 mImpl->RequestRelayout();
1134 bool Controller::IsUnderlineEnabled() const
1136 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1139 void Controller::SetUnderlineHeight( float height )
1141 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1143 mImpl->RequestRelayout();
1146 float Controller::GetUnderlineHeight() const
1148 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1151 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1153 if( NULL == mImpl->mEmbossDefaults )
1155 mImpl->mEmbossDefaults = new EmbossDefaults();
1158 mImpl->mEmbossDefaults->properties = embossProperties;
1161 const std::string& Controller::GetDefaultEmbossProperties() const
1163 if( NULL != mImpl->mEmbossDefaults )
1165 return mImpl->mEmbossDefaults->properties;
1168 return EMPTY_STRING;
1171 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1173 if( NULL == mImpl->mOutlineDefaults )
1175 mImpl->mOutlineDefaults = new OutlineDefaults();
1178 mImpl->mOutlineDefaults->properties = outlineProperties;
1181 const std::string& Controller::GetDefaultOutlineProperties() const
1183 if( NULL != mImpl->mOutlineDefaults )
1185 return mImpl->mOutlineDefaults->properties;
1188 return EMPTY_STRING;
1191 void Controller::SetDefaultLineSpacing( float lineSpacing )
1193 //TODO finish implementation
1194 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1197 float Controller::GetDefaultLineSpacing() const
1199 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1202 void Controller::SetInputColor( const Vector4& color )
1204 if( NULL != mImpl->mEventData )
1206 mImpl->mEventData->mInputStyle.textColor = color;
1207 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1209 if( EventData::SELECTING == mImpl->mEventData->mState )
1211 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
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;
1217 // Add the color run.
1218 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1219 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1221 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1222 colorRun.color = color;
1223 colorRun.characterRun.characterIndex = startOfSelectedText;
1224 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1226 // Request to relayout.
1227 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1228 mImpl->RequestRelayout();
1230 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1231 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1232 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1237 const Vector4& Controller::GetInputColor() const
1239 if( NULL != mImpl->mEventData )
1241 return mImpl->mEventData->mInputStyle.textColor;
1244 // Return the default text's color if there is no EventData.
1245 return mImpl->mTextColor;
1249 void Controller::SetInputFontFamily( const std::string& fontFamily )
1251 if( NULL != mImpl->mEventData )
1253 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1254 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1256 if( EventData::SELECTING == mImpl->mEventData->mState )
1258 CharacterIndex startOfSelectedText = 0u;
1259 Length lengthOfSelectedText = 0u;
1260 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1261 mImpl->mModel->mLogicalModel,
1262 startOfSelectedText,
1263 lengthOfSelectedText );
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;
1270 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1272 // Request to relayout.
1273 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1278 UPDATE_LAYOUT_SIZE |
1281 mImpl->mRecalculateNaturalSize = true;
1282 mImpl->RequestRelayout();
1284 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1285 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1286 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
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;
1297 const std::string& Controller::GetInputFontFamily() const
1299 if( NULL != mImpl->mEventData )
1301 return mImpl->mEventData->mInputStyle.familyName;
1304 // Return the default font's family if there is no EventData.
1305 return GetDefaultFontFamily();
1308 void Controller::SetInputFontWeight( FontWeight weight )
1310 if( NULL != mImpl->mEventData )
1312 mImpl->mEventData->mInputStyle.weight = weight;
1313 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1315 if( EventData::SELECTING == mImpl->mEventData->mState )
1317 CharacterIndex startOfSelectedText = 0u;
1318 Length lengthOfSelectedText = 0u;
1319 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1320 mImpl->mModel->mLogicalModel,
1321 startOfSelectedText,
1322 lengthOfSelectedText );
1324 fontDescriptionRun.weight = weight;
1325 fontDescriptionRun.weightDefined = true;
1327 // Request to relayout.
1328 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1333 UPDATE_LAYOUT_SIZE |
1336 mImpl->mRecalculateNaturalSize = true;
1337 mImpl->RequestRelayout();
1339 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1340 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1341 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
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;
1352 bool Controller::IsInputFontWeightDefined() const
1354 bool defined = false;
1356 if( NULL != mImpl->mEventData )
1358 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1364 FontWeight Controller::GetInputFontWeight() const
1366 if( NULL != mImpl->mEventData )
1368 return mImpl->mEventData->mInputStyle.weight;
1371 return GetDefaultFontWeight();
1374 void Controller::SetInputFontWidth( FontWidth width )
1376 if( NULL != mImpl->mEventData )
1378 mImpl->mEventData->mInputStyle.width = width;
1379 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1381 if( EventData::SELECTING == mImpl->mEventData->mState )
1383 CharacterIndex startOfSelectedText = 0u;
1384 Length lengthOfSelectedText = 0u;
1385 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1386 mImpl->mModel->mLogicalModel,
1387 startOfSelectedText,
1388 lengthOfSelectedText );
1390 fontDescriptionRun.width = width;
1391 fontDescriptionRun.widthDefined = true;
1393 // Request to relayout.
1394 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1399 UPDATE_LAYOUT_SIZE |
1402 mImpl->mRecalculateNaturalSize = true;
1403 mImpl->RequestRelayout();
1405 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1406 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1407 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
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;
1418 bool Controller::IsInputFontWidthDefined() const
1420 bool defined = false;
1422 if( NULL != mImpl->mEventData )
1424 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1430 FontWidth Controller::GetInputFontWidth() const
1432 if( NULL != mImpl->mEventData )
1434 return mImpl->mEventData->mInputStyle.width;
1437 return GetDefaultFontWidth();
1440 void Controller::SetInputFontSlant( FontSlant slant )
1442 if( NULL != mImpl->mEventData )
1444 mImpl->mEventData->mInputStyle.slant = slant;
1445 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1447 if( EventData::SELECTING == mImpl->mEventData->mState )
1449 CharacterIndex startOfSelectedText = 0u;
1450 Length lengthOfSelectedText = 0u;
1451 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1452 mImpl->mModel->mLogicalModel,
1453 startOfSelectedText,
1454 lengthOfSelectedText );
1456 fontDescriptionRun.slant = slant;
1457 fontDescriptionRun.slantDefined = true;
1459 // Request to relayout.
1460 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1465 UPDATE_LAYOUT_SIZE |
1468 mImpl->mRecalculateNaturalSize = true;
1469 mImpl->RequestRelayout();
1471 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1472 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1473 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
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;
1484 bool Controller::IsInputFontSlantDefined() const
1486 bool defined = false;
1488 if( NULL != mImpl->mEventData )
1490 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1496 FontSlant Controller::GetInputFontSlant() const
1498 if( NULL != mImpl->mEventData )
1500 return mImpl->mEventData->mInputStyle.slant;
1503 return GetDefaultFontSlant();
1506 void Controller::SetInputFontPointSize( float size )
1508 if( NULL != mImpl->mEventData )
1510 mImpl->mEventData->mInputStyle.size = size;
1511 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1513 if( EventData::SELECTING == mImpl->mEventData->mState )
1515 CharacterIndex startOfSelectedText = 0u;
1516 Length lengthOfSelectedText = 0u;
1517 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1518 mImpl->mModel->mLogicalModel,
1519 startOfSelectedText,
1520 lengthOfSelectedText );
1522 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1523 fontDescriptionRun.sizeDefined = true;
1525 // Request to relayout.
1526 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1531 UPDATE_LAYOUT_SIZE |
1534 mImpl->mRecalculateNaturalSize = true;
1535 mImpl->RequestRelayout();
1537 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1538 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1539 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
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;
1550 float Controller::GetInputFontPointSize() const
1552 if( NULL != mImpl->mEventData )
1554 return mImpl->mEventData->mInputStyle.size;
1557 // Return the default font's point size if there is no EventData.
1558 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1561 void Controller::SetInputLineSpacing( float lineSpacing )
1563 if( NULL != mImpl->mEventData )
1565 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1566 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1570 float Controller::GetInputLineSpacing() const
1572 if( NULL != mImpl->mEventData )
1574 return mImpl->mEventData->mInputStyle.lineSpacing;
1580 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1582 if( NULL != mImpl->mEventData )
1584 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1588 const std::string& Controller::GetInputShadowProperties() const
1590 if( NULL != mImpl->mEventData )
1592 return mImpl->mEventData->mInputStyle.shadowProperties;
1595 return EMPTY_STRING;
1598 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1600 if( NULL != mImpl->mEventData )
1602 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1606 const std::string& Controller::GetInputUnderlineProperties() const
1608 if( NULL != mImpl->mEventData )
1610 return mImpl->mEventData->mInputStyle.underlineProperties;
1613 return EMPTY_STRING;
1616 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1618 if( NULL != mImpl->mEventData )
1620 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1624 const std::string& Controller::GetInputEmbossProperties() const
1626 if( NULL != mImpl->mEventData )
1628 return mImpl->mEventData->mInputStyle.embossProperties;
1631 return GetDefaultEmbossProperties();
1634 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1636 if( NULL != mImpl->mEventData )
1638 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1642 const std::string& Controller::GetInputOutlineProperties() const
1644 if( NULL != mImpl->mEventData )
1646 return mImpl->mEventData->mInputStyle.outlineProperties;
1649 return GetDefaultOutlineProperties();
1652 void Controller::SetInputModePassword( bool passwordInput )
1654 if( NULL != mImpl->mEventData )
1656 mImpl->mEventData->mPasswordInput = passwordInput;
1660 bool Controller::IsInputModePassword()
1662 if( NULL != mImpl->mEventData )
1664 return mImpl->mEventData->mPasswordInput;
1669 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1671 if( NULL != mImpl->mEventData )
1673 mImpl->mEventData->mDoubleTapAction = action;
1677 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1679 NoTextTap::Action action = NoTextTap::NO_ACTION;
1681 if( NULL != mImpl->mEventData )
1683 action = mImpl->mEventData->mDoubleTapAction;
1689 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1691 if( NULL != mImpl->mEventData )
1693 mImpl->mEventData->mLongPressAction = action;
1697 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1699 NoTextTap::Action action = NoTextTap::NO_ACTION;
1701 if( NULL != mImpl->mEventData )
1703 action = mImpl->mEventData->mLongPressAction;
1709 bool Controller::IsUnderlineSetByString()
1711 return mImpl->mUnderlineSetByString;
1714 void Controller::UnderlineSetByString( bool setByString )
1716 mImpl->mUnderlineSetByString = setByString;
1719 bool Controller::IsShadowSetByString()
1721 return mImpl->mShadowSetByString;
1724 void Controller::ShadowSetByString( bool setByString )
1726 mImpl->mShadowSetByString = setByString;
1729 bool Controller::IsFontStyleSetByString()
1731 return mImpl->mFontStyleSetByString;
1734 void Controller::FontStyleSetByString( bool setByString )
1736 mImpl->mFontStyleSetByString = setByString;
1739 // public : Queries & retrieves.
1741 Layout::Engine& Controller::GetLayoutEngine()
1743 return mImpl->mLayoutEngine;
1746 View& Controller::GetView()
1748 return mImpl->mView;
1751 Vector3 Controller::GetNaturalSize()
1753 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1754 Vector3 naturalSize;
1756 // Make sure the model is up-to-date before layouting
1757 ProcessModifyEvents();
1759 if( mImpl->mRecalculateNaturalSize )
1761 // Operations that can be done only once until the text changes.
1762 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1769 GET_GLYPH_METRICS );
1771 // Set the update info to relayout the whole text.
1772 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1773 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1775 // Make sure the model is up-to-date before layouting
1776 mImpl->UpdateModel( onlyOnceOperations );
1778 // Layout the text for the new width.
1779 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
1781 // Store the actual control's size to restore later.
1782 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1784 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1785 static_cast<OperationsMask>( onlyOnceOperations |
1787 naturalSize.GetVectorXY() );
1789 // Do not do again the only once operations.
1790 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1792 // Do the size related operations again.
1793 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1796 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1798 // Stores the natural size to avoid recalculate it again
1799 // unless the text/style changes.
1800 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1802 mImpl->mRecalculateNaturalSize = false;
1804 // Clear the update info. This info will be set the next time the text is updated.
1805 mImpl->mTextUpdateInfo.Clear();
1807 // Restore the actual control's size.
1808 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1810 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1814 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1816 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1819 naturalSize.x = ConvertToEven( naturalSize.x );
1820 naturalSize.y = ConvertToEven( naturalSize.y );
1825 float Controller::GetHeightForWidth( float width )
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();
1832 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1833 mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
1834 mImpl->mTextUpdateInfo.mClearAll )
1836 // Operations that can be done only once until the text changes.
1837 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1844 GET_GLYPH_METRICS );
1846 // Set the update info to relayout the whole text.
1847 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1848 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1850 // Make sure the model is up-to-date before layouting
1851 mImpl->UpdateModel( onlyOnceOperations );
1854 // Layout the text for the new width.
1855 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1857 // Store the actual control's width.
1858 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1860 DoRelayout( Size( width, MAX_FLOAT ),
1861 static_cast<OperationsMask>( onlyOnceOperations |
1865 // Do not do again the only once operations.
1866 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1868 // Do the size related operations again.
1869 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1873 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1875 // Clear the update info. This info will be set the next time the text is updated.
1876 mImpl->mTextUpdateInfo.Clear();
1878 // Restore the actual control's width.
1879 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1881 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1885 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1886 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1889 return layoutSize.height;
1892 int Controller::GetLineCount( float width )
1894 GetHeightForWidth( width );
1895 int numberofLines = mImpl->mModel->GetNumberOfLines();
1896 return numberofLines;
1899 const ModelInterface* const Controller::GetTextModel() const
1901 return mImpl->mModel.Get();
1904 float Controller::GetScrollAmountByUserInput()
1906 float scrollAmount = 0.0f;
1908 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1910 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1911 mImpl->mEventData->mCheckScrollAmount = false;
1913 return scrollAmount;
1916 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1918 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
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 );
1928 void Controller::SetHiddenInputOption(const Property::Map& options )
1930 if( NULL == mImpl->mHiddenInput )
1932 mImpl->mHiddenInput = new HiddenText( this );
1934 mImpl->mHiddenInput->SetProperties(options);
1937 void Controller::GetHiddenInputOption(Property::Map& options )
1939 if( NULL != mImpl->mHiddenInput )
1941 mImpl->mHiddenInput->GetProperties(options);
1945 void Controller::SetPlaceholderProperty( const Property::Map& map )
1947 const Property::Map::SizeType count = map.Count();
1949 for( Property::Map::SizeType position = 0; position < count; ++position )
1951 KeyValuePair keyValue = map.GetKeyValue( position );
1952 Property::Key& key = keyValue.first;
1953 Property::Value& value = keyValue.second;
1955 if( key == PLACEHOLDER_TEXT )
1957 std::string text = "";
1959 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1961 else if( key == PLACEHOLDER_TEXT_FOCUSED )
1963 std::string text = "";
1965 SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
1967 else if( key == PLACEHOLDER_COLOR )
1970 value.Get( textColor );
1971 if( GetPlaceholderTextColor() != textColor )
1973 SetPlaceholderTextColor( textColor );
1976 else if( key == PLACEHOLDER_FONT_FAMILY )
1978 std::string fontFamily = "";
1979 value.Get( fontFamily );
1980 SetPlaceholderFontFamily( fontFamily );
1982 else if( key == PLACEHOLDER_FONT_STYLE )
1984 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
1986 else if( key == PLACEHOLDER_POINT_SIZE )
1989 value.Get( pointSize );
1990 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
1992 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
1995 else if( key == PLACEHOLDER_PIXEL_SIZE )
1998 value.Get( pixelSize );
1999 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2001 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2004 else if( key == PLACEHOLDER_ELLIPSIS )
2007 value.Get( ellipsis );
2008 SetPlaceholderTextElideEnabled( ellipsis );
2013 void Controller::GetPlaceholderProperty( Property::Map& map )
2015 if( NULL != mImpl->mEventData )
2017 if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2019 map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2021 if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2023 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2026 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2027 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
2029 Property::Value fontStyleMapGet;
2030 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2031 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
2033 // Choose font size : POINT_SIZE or PIXEL_SIZE
2034 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2036 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2040 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2043 if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2045 map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2050 // public : Relayout.
2052 Controller::UpdateTextType Controller::Relayout( const Size& size )
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" );
2056 UpdateTextType updateTextType = NONE_UPDATED;
2058 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2060 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2062 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2063 updateTextType = MODEL_UPDATED;
2066 // Clear the update info. This info will be set the next time the text is updated.
2067 mImpl->mTextUpdateInfo.Clear();
2069 // Not worth to relayout if width or height is equal to zero.
2070 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2072 return updateTextType;
2075 // Whether a new size has been set.
2076 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2080 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2082 // Layout operations that need to be done if the size changes.
2083 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2086 UPDATE_LAYOUT_SIZE |
2088 // Set the update info to relayout the whole text.
2089 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2090 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2092 // Store the size used to layout the text.
2093 mImpl->mModel->mVisualModel->mControlSize = size;
2096 // Whether there are modify events.
2097 if( 0u != mImpl->mModifyEvents.Count() )
2099 // Style operations that need to be done if the text is modified.
2100 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2104 // Set the update info to elide the text.
2105 if( mImpl->mModel->mElideEnabled ||
2106 ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2108 // Update Text layout for applying elided
2109 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2112 UPDATE_LAYOUT_SIZE |
2114 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2115 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2118 // Make sure the model is up-to-date before layouting.
2119 ProcessModifyEvents();
2120 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2124 updated = DoRelayout( size,
2125 mImpl->mOperationsPending,
2126 layoutSize ) || updated;
2130 updateTextType = MODEL_UPDATED;
2133 // Do not re-do any operation until something changes.
2134 mImpl->mOperationsPending = NO_OPERATION;
2135 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2137 // Whether the text control is editable
2138 const bool isEditable = NULL != mImpl->mEventData;
2140 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2142 if( newSize && isEditable )
2144 offset = mImpl->mModel->mScrollPosition;
2147 if( !isEditable || !IsMultiLineEnabled() )
2149 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2150 CalculateVerticalOffset( size );
2157 // If there is a new size, the scroll position needs to be clamped.
2158 mImpl->ClampHorizontalScroll( layoutSize );
2160 // Update the decorator's positions is needed if there is a new size.
2161 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2164 // Move the cursor, grab handle etc.
2165 if( mImpl->ProcessInputEvents() )
2167 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
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" );
2175 return updateTextType;
2178 void Controller::RequestRelayout()
2180 mImpl->RequestRelayout();
2183 // public : Input style change signals.
2185 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2187 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2190 void Controller::ProcessInputStyleChangedSignals()
2192 if( NULL == mImpl->mEventData )
2198 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2199 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2203 const InputStyle::Mask mask = *it;
2205 if( NULL != mImpl->mEditableControlInterface )
2207 // Emit the input style changed signal.
2208 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2212 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2215 // public : Text-input Event Queuing.
2217 void Controller::KeyboardFocusGainEvent()
2219 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2221 if( NULL != mImpl->mEventData )
2223 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2224 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
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;
2230 mImpl->NotifyImfMultiLineStatus();
2231 if( mImpl->IsShowingPlaceholderText() )
2233 // Show alternative placeholder-text when editing
2234 ShowPlaceholderText();
2237 mImpl->RequestRelayout();
2241 void Controller::KeyboardFocusLostEvent()
2243 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2245 if( NULL != mImpl->mEventData )
2247 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2249 mImpl->ChangeState( EventData::INACTIVE );
2251 if( !mImpl->IsShowingRealText() )
2253 // Revert to regular placeholder-text when not editing
2254 ShowPlaceholderText();
2258 mImpl->RequestRelayout();
2261 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2263 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2265 bool textChanged = false;
2266 bool relayoutNeeded = false;
2268 if( ( NULL != mImpl->mEventData ) &&
2269 ( keyEvent.state == KeyEvent::Down ) )
2271 int keyCode = keyEvent.keyCode;
2272 const std::string& keyString = keyEvent.keyPressed;
2274 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2276 // Pre-process to separate modifying events from non-modifying input events.
2279 // In some platforms arrive key events with no key code.
2283 else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
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 ) )
2293 // If don't have any text, do nothing.
2294 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
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();
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 ) )
2315 mImpl->mEventData->mCheckScrollAmount = true;
2316 Event event( Event::CURSOR_KEY_EVENT );
2317 event.p1.mInt = keyCode;
2318 mImpl->mEventData->mEventQueue.push_back( event );
2320 // Will request for relayout.
2321 relayoutNeeded = true;
2323 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2325 textChanged = BackspaceKeyEvent();
2327 // Will request for relayout.
2328 relayoutNeeded = true;
2330 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2331 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2332 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2334 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2335 mImpl->ChangeState( EventData::INACTIVE );
2337 // Will request for relayout.
2338 relayoutNeeded = true;
2340 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2342 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
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.
2350 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2352 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2358 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2360 // IMF manager is no longer handling key-events
2361 mImpl->ClearPreEditFlag();
2363 InsertText( keyString, COMMIT );
2366 // Will request for relayout.
2367 relayoutNeeded = true;
2370 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2371 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2373 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2374 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2375 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
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 );
2382 // Will request for relayout.
2383 relayoutNeeded = true;
2386 if( relayoutNeeded )
2388 mImpl->RequestRelayout();
2393 ( NULL != mImpl->mEditableControlInterface ) )
2395 // Do this last since it provides callbacks into application code
2396 mImpl->mEditableControlInterface->TextChanged();
2402 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2404 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2406 if( NULL != mImpl->mEventData )
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
2412 if( mImpl->IsClipboardVisible() )
2414 if( EventData::INACTIVE == state || EventData::EDITING == state)
2416 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2418 relayoutNeeded = true;
2420 else if( 1u == tapCount )
2422 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2424 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2427 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2429 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2430 relayoutNeeded = true;
2434 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2436 // Hide placeholder text
2440 if( EventData::INACTIVE == state )
2442 mImpl->ChangeState( EventData::EDITING );
2444 else if( !mImpl->IsClipboardEmpty() )
2446 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2448 relayoutNeeded = true;
2451 else if( 2u == tapCount )
2453 if( mImpl->mEventData->mSelectionEnabled &&
2454 mImpl->IsShowingRealText() )
2456 relayoutNeeded = true;
2457 mImpl->mEventData->mIsLeftHandleSelected = true;
2458 mImpl->mEventData->mIsRightHandleSelected = true;
2462 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2463 if( relayoutNeeded )
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 );
2471 mImpl->RequestRelayout();
2475 // Reset keyboard as tap event has occurred.
2476 mImpl->ResetImfManager();
2479 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2481 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2483 if( NULL != mImpl->mEventData )
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 );
2491 mImpl->RequestRelayout();
2495 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2497 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2499 if( ( state == Gesture::Started ) &&
2500 ( NULL != mImpl->mEventData ) )
2502 // The 1st long-press on inactive text-field is treated as tap
2503 if( EventData::INACTIVE == mImpl->mEventData->mState )
2505 mImpl->ChangeState( EventData::EDITING );
2507 Event event( Event::TAP_EVENT );
2509 event.p2.mFloat = x;
2510 event.p3.mFloat = y;
2511 mImpl->mEventData->mEventQueue.push_back( event );
2513 mImpl->RequestRelayout();
2515 else if( !mImpl->IsShowingRealText() )
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();
2524 else if( !mImpl->IsClipboardVisible() )
2526 // Reset the imf manager to commit the pre-edit before selecting the text.
2527 mImpl->ResetImfManager();
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();
2536 mImpl->mEventData->mIsLeftHandleSelected = true;
2537 mImpl->mEventData->mIsRightHandleSelected = true;
2542 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2544 // Whether the text needs to be relaid-out.
2545 bool requestRelayout = false;
2547 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2548 bool retrieveText = false;
2549 bool retrieveCursor = false;
2551 switch( imfEvent.eventName )
2553 case ImfManager::COMMIT:
2555 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2556 requestRelayout = true;
2557 retrieveCursor = true;
2560 case ImfManager::PREEDIT:
2562 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2563 requestRelayout = true;
2564 retrieveCursor = true;
2567 case ImfManager::DELETESURROUNDING:
2569 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2570 imfEvent.numberOfChars,
2571 DONT_UPDATE_INPUT_STYLE );
2575 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2576 !mImpl->IsPlaceholderAvailable() )
2578 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2582 ShowPlaceholderText();
2584 mImpl->mEventData->mUpdateCursorPosition = true;
2585 mImpl->mEventData->mScrollAfterDelete = true;
2587 requestRelayout = true;
2591 case ImfManager::GETSURROUNDING:
2593 retrieveText = true;
2594 retrieveCursor = true;
2597 case ImfManager::PRIVATECOMMAND:
2599 // PRIVATECOMMAND event is just for getting the private command message
2600 retrieveText = true;
2601 retrieveCursor = true;
2604 case ImfManager::VOID:
2611 if( requestRelayout )
2613 mImpl->mOperationsPending = ALL_OPERATIONS;
2614 mImpl->RequestRelayout();
2618 CharacterIndex cursorPosition = 0u;
2619 Length numberOfWhiteSpaces = 0u;
2621 if( retrieveCursor )
2623 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2625 cursorPosition = mImpl->GetLogicalCursorPosition();
2627 if( cursorPosition < numberOfWhiteSpaces )
2629 cursorPosition = 0u;
2633 cursorPosition -= numberOfWhiteSpaces;
2639 mImpl->GetText( numberOfWhiteSpaces, text );
2642 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2644 if( requestRelayout &&
2645 ( NULL != mImpl->mEditableControlInterface ) )
2647 // Do this last since it provides callbacks into application code
2648 mImpl->mEditableControlInterface->TextChanged();
2651 return callbackData;
2654 void Controller::PasteClipboardItemEvent()
2656 // Retrieve the clipboard contents first
2657 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2658 std::string stringToPaste( notifier.GetContent() );
2660 // Commit the current pre-edit text; the contents of the clipboard should be appended
2661 mImpl->ResetImfManager();
2663 // Temporary disable hiding clipboard
2664 mImpl->SetClipboardHideEnable( false );
2667 PasteText( stringToPaste );
2669 mImpl->SetClipboardHideEnable( true );
2672 // protected : Inherit from Text::Decorator::ControllerInterface.
2674 void Controller::GetTargetSize( Vector2& targetSize )
2676 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2679 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2681 if( NULL != mImpl->mEditableControlInterface )
2683 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2687 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2689 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2691 if( NULL != mImpl->mEventData )
2693 switch( handleType )
2697 Event event( Event::GRAB_HANDLE_EVENT );
2698 event.p1.mUint = state;
2699 event.p2.mFloat = x;
2700 event.p3.mFloat = y;
2702 mImpl->mEventData->mEventQueue.push_back( event );
2705 case LEFT_SELECTION_HANDLE:
2707 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2708 event.p1.mUint = state;
2709 event.p2.mFloat = x;
2710 event.p3.mFloat = y;
2712 mImpl->mEventData->mEventQueue.push_back( event );
2715 case RIGHT_SELECTION_HANDLE:
2717 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2718 event.p1.mUint = state;
2719 event.p2.mFloat = x;
2720 event.p3.mFloat = y;
2722 mImpl->mEventData->mEventQueue.push_back( event );
2725 case LEFT_SELECTION_HANDLE_MARKER:
2726 case RIGHT_SELECTION_HANDLE_MARKER:
2728 // Markers do not move the handles.
2731 case HANDLE_TYPE_COUNT:
2733 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2737 mImpl->RequestRelayout();
2741 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2743 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2745 if( NULL == mImpl->mEventData )
2752 case Toolkit::TextSelectionPopup::CUT:
2754 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2755 mImpl->mOperationsPending = ALL_OPERATIONS;
2757 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2758 !mImpl->IsPlaceholderAvailable() )
2760 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2764 ShowPlaceholderText();
2767 mImpl->mEventData->mUpdateCursorPosition = true;
2768 mImpl->mEventData->mScrollAfterDelete = true;
2770 mImpl->RequestRelayout();
2772 if( NULL != mImpl->mEditableControlInterface )
2774 mImpl->mEditableControlInterface->TextChanged();
2778 case Toolkit::TextSelectionPopup::COPY:
2780 mImpl->SendSelectionToClipboard( false ); // Text not modified
2782 mImpl->mEventData->mUpdateCursorPosition = true;
2784 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2787 case Toolkit::TextSelectionPopup::PASTE:
2789 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2792 case Toolkit::TextSelectionPopup::SELECT:
2794 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2796 if( mImpl->mEventData->mSelectionEnabled )
2798 // Creates a SELECT event.
2799 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2803 case Toolkit::TextSelectionPopup::SELECT_ALL:
2805 // Creates a SELECT_ALL event
2806 SelectEvent( 0.f, 0.f, true );
2809 case Toolkit::TextSelectionPopup::CLIPBOARD:
2811 mImpl->ShowClipboard();
2814 case Toolkit::TextSelectionPopup::NONE:
2822 void Controller::DisplayTimeExpired()
2824 mImpl->mEventData->mUpdateCursorPosition = true;
2825 // Apply modifications to the model
2826 mImpl->mOperationsPending = ALL_OPERATIONS;
2828 mImpl->RequestRelayout();
2831 // private : Update.
2833 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2835 bool removedPrevious = false;
2836 bool removedSelected = false;
2837 bool maxLengthReached = false;
2839 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2841 if( NULL == mImpl->mEventData )
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 );
2850 // TODO: At the moment the underline runs are only for pre-edit.
2851 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2853 // Remove the previous IMF pre-edit.
2854 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2856 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2857 mImpl->mEventData->mPreEditLength,
2858 DONT_UPDATE_INPUT_STYLE );
2860 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2861 mImpl->mEventData->mPreEditLength = 0u;
2865 // Remove the previous Selection.
2866 removedSelected = RemoveSelectedText();
2870 Vector<Character> utf32Characters;
2871 Length characterCount = 0u;
2875 // Convert text into UTF-32
2876 utf32Characters.Resize( text.size() );
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() );
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 );
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() );
2890 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2892 // The placeholder text is no longer needed
2893 if( mImpl->IsShowingPlaceholderText() )
2898 mImpl->ChangeState( EventData::EDITING );
2900 // Handle the IMF (predicitive text) state changes
2901 if( COMMIT == type )
2903 // IMF manager is no longer handling key-events
2904 mImpl->ClearPreEditFlag();
2908 if( !mImpl->mEventData->mPreEditFlag )
2910 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2912 // Record the start of the pre-edit text
2913 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2916 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2917 mImpl->mEventData->mPreEditFlag = true;
2919 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2922 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2924 // Restrict new text to fit within Maximum characters setting.
2925 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2926 maxLengthReached = ( characterCount > maxSizeOfNewText );
2928 // The cursor position.
2929 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2931 // Update the text's style.
2933 // Updates the text style runs by adding characters.
2934 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2936 // Get the character index from the cursor index.
2937 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2939 // Retrieve the text's style for the given index.
2941 mImpl->RetrieveDefaultInputStyle( style );
2942 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2944 // Whether to add a new text color run.
2945 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
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;
2957 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2958 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
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;
2966 if( addFontNameRun ||
2972 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2973 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2975 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2977 if( addFontNameRun )
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;
2984 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2987 if( addFontWeightRun )
2989 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2990 fontDescriptionRun.weightDefined = true;
2993 if( addFontWidthRun )
2995 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2996 fontDescriptionRun.widthDefined = true;
2999 if( addFontSlantRun )
3001 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3002 fontDescriptionRun.slantDefined = true;
3005 if( addFontSizeRun )
3007 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3008 fontDescriptionRun.sizeDefined = true;
3011 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3012 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3015 // Insert at current cursor position.
3016 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3018 if( cursorIndex < numberOfCharactersInModel )
3020 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3024 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3027 // Mark the first paragraph to be updated.
3028 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3030 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3031 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3032 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3033 mImpl->mTextUpdateInfo.mClearAll = true;
3037 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3038 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3041 // Update the cursor index.
3042 cursorIndex += maxSizeOfNewText;
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 );
3047 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3048 mImpl->IsPlaceholderAvailable() )
3050 // Show place-holder if empty after removing the pre-edit text
3051 ShowPlaceholderText();
3052 mImpl->mEventData->mUpdateCursorPosition = true;
3053 mImpl->ClearPreEditFlag();
3055 else if( removedPrevious ||
3057 ( 0 != utf32Characters.Count() ) )
3059 // Queue an inserted event
3060 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3062 mImpl->mEventData->mUpdateCursorPosition = true;
3063 if( removedSelected )
3065 mImpl->mEventData->mScrollAfterDelete = true;
3069 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3073 if( maxLengthReached )
3075 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3077 mImpl->ResetImfManager();
3079 if( NULL != mImpl->mEditableControlInterface )
3081 // Do this last since it provides callbacks into application code
3082 mImpl->mEditableControlInterface->MaxLengthReached();
3087 void Controller::PasteText( const std::string& stringToPaste )
3089 InsertText( stringToPaste, Text::Controller::COMMIT );
3090 mImpl->ChangeState( EventData::EDITING );
3091 mImpl->RequestRelayout();
3093 if( NULL != mImpl->mEditableControlInterface )
3095 // Do this last since it provides callbacks into application code
3096 mImpl->mEditableControlInterface->TextChanged();
3100 bool Controller::RemoveText( int cursorOffset,
3101 int numberOfCharacters,
3102 UpdateInputStyleType type )
3104 bool removed = false;
3106 if( NULL == mImpl->mEventData )
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 );
3114 if( !mImpl->IsShowingPlaceholderText() )
3116 // Delete at current cursor position
3117 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3118 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3120 CharacterIndex cursorIndex = 0;
3122 // Validate the cursor position & number of characters
3123 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3125 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3128 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3130 numberOfCharacters = currentText.Count() - cursorIndex;
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 ) )
3136 // Mark the paragraphs to be updated.
3137 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
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;
3146 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3147 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3150 // Update the input style and remove the text's style before removing the text.
3152 if( UPDATE_INPUT_STYLE == type )
3154 // Keep a copy of the current input style.
3155 InputStyle currentInputStyle;
3156 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3158 // Set first the default input style.
3159 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3161 // Update the input style.
3162 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3164 // Compare if the input style has changed.
3165 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3167 if( hasInputStyleChanged )
3169 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3170 // Queue the input style changed signal.
3171 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3175 // Updates the text style runs by removing characters. Runs with no characters are removed.
3176 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3178 // Remove the characters.
3179 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3180 Vector<Character>::Iterator last = first + numberOfCharacters;
3182 currentText.Erase( first, last );
3184 // Cursor position retreat
3185 oldCursorIndex = cursorIndex;
3187 mImpl->mEventData->mScrollAfterDelete = true;
3189 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3197 bool Controller::RemoveSelectedText()
3199 bool textRemoved( false );
3201 if( EventData::SELECTING == mImpl->mEventData->mState )
3203 std::string removedString;
3204 mImpl->RetrieveSelection( removedString, true );
3206 if( !removedString.empty() )
3209 mImpl->ChangeState( EventData::EDITING );
3216 // private : Relayout.
3218 bool Controller::DoRelayout( const Size& size,
3219 OperationsMask operationsRequired,
3222 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3223 bool viewUpdated( false );
3225 // Calculate the operations to be done.
3226 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3228 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3229 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3231 // Get the current layout size.
3232 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3234 if( NO_OPERATION != ( LAYOUT & operations ) )
3236 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
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.
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();
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();
3253 if( 0u == totalNumberOfGlyphs )
3255 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3257 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
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" );
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();
3273 // Set the layout parameters.
3274 Layout::Parameters layoutParameters( size,
3276 lineBreakInfo.Begin(),
3277 wordBreakInfo.Begin(),
3278 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3280 glyphsToCharactersMap.Begin(),
3281 charactersPerGlyph.Begin(),
3282 charactersToGlyphBuffer,
3283 glyphsPerCharacterBuffer,
3284 totalNumberOfGlyphs,
3285 mImpl->mModel->mHorizontalAlignment,
3286 mImpl->mModel->mLineWrapMode );
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 );
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;
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;
3302 // Update the ellipsis
3303 bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3305 if( NULL != mImpl->mEventData )
3307 if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3309 elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3311 else if( EventData::INACTIVE != mImpl->mEventData->mState )
3313 // Disable ellipsis when editing
3314 elideTextEnabled = false;
3317 // Reset the scroll position in inactive state
3318 if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3320 ResetScrollPosition();
3324 // Update the visual model.
3326 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3328 mImpl->mModel->mVisualModel->mLines,
3332 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3336 layoutSize = newLayoutSize;
3338 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3340 mImpl->mAutoScrollDirectionRTL = false;
3343 // Reorder the lines
3344 if( NO_OPERATION != ( REORDER & operations ) )
3346 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3347 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3349 // Check first if there are paragraphs with bidirectional info.
3350 if( 0u != bidirectionalInfo.Count() )
3353 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
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,
3359 requestedNumberOfCharacters,
3360 mImpl->mModel->mVisualModel->mLines,
3361 bidirectionalLineInfo );
3363 // Set the bidirectional info per line into the layout parameters.
3364 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3365 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3367 // Re-layout the text. Reorder those lines with right to left characters.
3368 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3370 requestedNumberOfCharacters,
3373 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3375 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3378 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3384 // Sets the layout size.
3385 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3387 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3392 if( NO_OPERATION != ( ALIGN & operations ) )
3394 // The laid-out lines.
3395 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
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,
3401 requestedNumberOfCharacters,
3402 mImpl->mModel->mHorizontalAlignment,
3404 mImpl->mModel->mAlignmentOffset );
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() );
3413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3417 void Controller::CalculateVerticalOffset( const Size& controlSize )
3419 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3421 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3423 // Get the line height of the default font.
3424 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3427 switch( mImpl->mModel->mVerticalAlignment )
3429 case Layout::VERTICAL_ALIGN_TOP:
3431 mImpl->mModel->mScrollPosition.y = 0.f;
3434 case Layout::VERTICAL_ALIGN_CENTER:
3436 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3439 case Layout::VERTICAL_ALIGN_BOTTOM:
3441 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3447 // private : Events.
3449 void Controller::ProcessModifyEvents()
3451 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3453 if( 0u == events.Count() )
3459 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3460 endIt = events.End();
3464 const ModifyEvent& event = *it;
3466 if( ModifyEvent::TEXT_REPLACED == event.type )
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" );
3471 TextReplacedEvent();
3473 else if( ModifyEvent::TEXT_INSERTED == event.type )
3475 TextInsertedEvent();
3477 else if( ModifyEvent::TEXT_DELETED == event.type )
3479 // Placeholder-text cannot be deleted
3480 if( !mImpl->IsShowingPlaceholderText() )
3487 if( NULL != mImpl->mEventData )
3489 // When the text is being modified, delay cursor blinking
3490 mImpl->mEventData->mDecorator->DelayCursorBlink();
3493 // Discard temporary text
3497 void Controller::TextReplacedEvent()
3499 // The natural size needs to be re-calculated.
3500 mImpl->mRecalculateNaturalSize = true;
3502 // Apply modifications to the model
3503 mImpl->mOperationsPending = ALL_OPERATIONS;
3506 void Controller::TextInsertedEvent()
3508 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3510 if( NULL == mImpl->mEventData )
3515 mImpl->mEventData->mCheckScrollAmount = true;
3517 // The natural size needs to be re-calculated.
3518 mImpl->mRecalculateNaturalSize = true;
3520 // Apply modifications to the model; TODO - Optimize this
3521 mImpl->mOperationsPending = ALL_OPERATIONS;
3524 void Controller::TextDeletedEvent()
3526 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3528 if( NULL == mImpl->mEventData )
3533 mImpl->mEventData->mCheckScrollAmount = true;
3535 // The natural size needs to be re-calculated.
3536 mImpl->mRecalculateNaturalSize = true;
3538 // Apply modifications to the model; TODO - Optimize this
3539 mImpl->mOperationsPending = ALL_OPERATIONS;
3542 void Controller::SelectEvent( float x, float y, bool selectAll )
3544 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3546 if( NULL != mImpl->mEventData )
3550 Event event( Event::SELECT_ALL );
3551 mImpl->mEventData->mEventQueue.push_back( event );
3555 Event event( Event::SELECT );
3556 event.p2.mFloat = x;
3557 event.p3.mFloat = y;
3558 mImpl->mEventData->mEventQueue.push_back( event );
3561 mImpl->mEventData->mCheckScrollAmount = true;
3562 mImpl->mEventData->mIsLeftHandleSelected = true;
3563 mImpl->mEventData->mIsRightHandleSelected = true;
3564 mImpl->RequestRelayout();
3568 bool Controller::BackspaceKeyEvent()
3570 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3572 bool removed = false;
3574 if( NULL == mImpl->mEventData )
3579 // IMF manager is no longer handling key-events
3580 mImpl->ClearPreEditFlag();
3582 if( EventData::SELECTING == mImpl->mEventData->mState )
3584 removed = RemoveSelectedText();
3586 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3588 // Remove the character before the current cursor position
3589 removed = RemoveText( -1,
3591 UPDATE_INPUT_STYLE );
3596 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3597 !mImpl->IsPlaceholderAvailable() )
3599 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3603 ShowPlaceholderText();
3605 mImpl->mEventData->mUpdateCursorPosition = true;
3606 mImpl->mEventData->mScrollAfterDelete = true;
3612 // private : Helpers.
3614 void Controller::ResetText()
3617 mImpl->mModel->mLogicalModel->mText.Clear();
3619 // We have cleared everything including the placeholder-text
3620 mImpl->PlaceholderCleared();
3622 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3623 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3624 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3626 // Clear any previous text.
3627 mImpl->mTextUpdateInfo.mClearAll = true;
3629 // The natural size needs to be re-calculated.
3630 mImpl->mRecalculateNaturalSize = true;
3632 // Apply modifications to the model
3633 mImpl->mOperationsPending = ALL_OPERATIONS;
3636 void Controller::ShowPlaceholderText()
3638 if( mImpl->IsPlaceholderAvailable() )
3640 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3642 if( NULL == mImpl->mEventData )
3647 mImpl->mEventData->mIsShowingPlaceholderText = true;
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 );
3654 const char* text( NULL );
3657 // TODO - Switch Placeholder text when changing state
3658 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3659 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3661 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3662 size = mImpl->mEventData->mPlaceholderTextActive.size();
3666 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3667 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3670 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3671 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3673 // Reset model for showing placeholder.
3674 mImpl->mModel->mLogicalModel->mText.Clear();
3675 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3677 // Convert text into UTF-32
3678 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3679 utf32Characters.Resize( size );
3681 // This is a bit horrible but std::string returns a (signed) char*
3682 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
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 );
3689 // The characters to be added.
3690 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3692 // Reset the cursor position
3693 mImpl->mEventData->mPrimaryCursorPosition = 0;
3695 // The natural size needs to be re-calculated.
3696 mImpl->mRecalculateNaturalSize = true;
3698 // Apply modifications to the model
3699 mImpl->mOperationsPending = ALL_OPERATIONS;
3701 // Update the rest of the model during size negotiation
3702 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3706 void Controller::ClearFontData()
3708 if( mImpl->mFontDefaults )
3710 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
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();
3718 mImpl->mTextUpdateInfo.mClearAll = true;
3719 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3720 mImpl->mRecalculateNaturalSize = true;
3722 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3727 UPDATE_LAYOUT_SIZE |
3732 void Controller::ClearStyleData()
3734 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3735 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3738 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3740 // Reset the cursor position
3741 if( NULL != mImpl->mEventData )
3743 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3745 // Update the cursor if it's in editing mode.
3746 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3748 mImpl->mEventData->mUpdateCursorPosition = true;
3753 void Controller::ResetScrollPosition()
3755 if( NULL != mImpl->mEventData )
3757 // Reset the scroll position.
3758 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3759 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3763 void Controller::SetControlInterface( ControlInterface* controlInterface )
3765 mImpl->mControlInterface = controlInterface;
3768 bool Controller::ShouldClearFocusOnEscape() const
3770 return mImpl->mShouldClearFocusOnEscape;
3773 // private : Private contructors & copy operator.
3775 Controller::Controller()
3778 mImpl = new Controller::Impl( NULL, NULL );
3781 Controller::Controller( ControlInterface* controlInterface )
3783 mImpl = new Controller::Impl( controlInterface, NULL );
3786 Controller::Controller( ControlInterface* controlInterface,
3787 EditableControlInterface* editableControlInterface )
3789 mImpl = new Controller::Impl( controlInterface,
3790 editableControlInterface );
3793 // The copy constructor and operator are left unimplemented.
3795 // protected : Destructor.
3797 Controller::~Controller()
3804 } // namespace Toolkit