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_COLOR = "placeholderColor";
52 const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
53 const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
54 const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
55 const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
57 float ConvertToEven( float value )
59 int intValue(static_cast<int>( value ));
60 return static_cast<float>(intValue % 2 == 0) ? intValue : (intValue + 1);
75 * @brief Adds a new font description run for the selected text.
77 * The new font parameters are added after the call to this method.
79 * @param[in] eventData The event data pointer.
80 * @param[in] logicalModel The logical model where to add the new font description run.
81 * @param[out] startOfSelectedText Index to the first selected character.
82 * @param[out] lengthOfSelectedText Number of selected characters.
84 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
85 LogicalModelPtr logicalModel,
86 CharacterIndex& startOfSelectedText,
87 Length& lengthOfSelectedText )
89 const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
91 // Get start and end position of selection
92 startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
93 lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
96 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
97 logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
99 FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
101 fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
102 fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
104 // Recalculate the selection highlight as the metrics may have changed.
105 eventData->mUpdateLeftSelectionPosition = true;
106 eventData->mUpdateRightSelectionPosition = true;
107 eventData->mUpdateHighlightBox = true;
109 return fontDescriptionRun;
112 // public : Constructor.
114 ControllerPtr Controller::New()
116 return ControllerPtr( new Controller() );
119 ControllerPtr Controller::New( ControlInterface* controlInterface )
121 return ControllerPtr( new Controller( controlInterface ) );
124 ControllerPtr Controller::New( ControlInterface* controlInterface,
125 EditableControlInterface* editableControlInterface )
127 return ControllerPtr( new Controller( controlInterface,
128 editableControlInterface ) );
131 // public : Configure the text controller.
133 void Controller::EnableTextInput( DecoratorPtr decorator )
137 delete mImpl->mEventData;
138 mImpl->mEventData = NULL;
140 // Nothing else to do.
144 if( NULL == mImpl->mEventData )
146 mImpl->mEventData = new EventData( decorator );
150 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
152 // Metrics for bitmap & vector based glyphs are different
153 mImpl->mMetrics->SetGlyphType( glyphType );
155 // Clear the font-specific data
158 mImpl->RequestRelayout();
161 void Controller::SetMarkupProcessorEnabled( bool enable )
163 mImpl->mMarkupProcessorEnabled = enable;
166 bool Controller::IsMarkupProcessorEnabled() const
168 return mImpl->mMarkupProcessorEnabled;
171 void Controller::SetAutoScrollEnabled( bool enable )
173 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 );
175 if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
179 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
180 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
190 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
191 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
198 mImpl->mIsAutoScrollEnabled = enable;
199 mImpl->RequestRelayout();
203 DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
204 mImpl->mIsAutoScrollEnabled = false;
208 bool Controller::IsAutoScrollEnabled() const
210 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
212 return mImpl->mIsAutoScrollEnabled;
215 CharacterDirection Controller::GetAutoScrollDirection() const
217 return mImpl->mAutoScrollDirectionRTL;
220 float Controller::GetAutoScrollLineAlignment() const
224 if( mImpl->mModel->mVisualModel &&
225 ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
227 offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
233 void Controller::SetHorizontalScrollEnabled( bool enable )
235 if( ( NULL != mImpl->mEventData ) &&
236 mImpl->mEventData->mDecorator )
238 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
241 bool Controller::IsHorizontalScrollEnabled() const
243 if( ( NULL != mImpl->mEventData ) &&
244 mImpl->mEventData->mDecorator )
246 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
252 void Controller::SetVerticalScrollEnabled( bool enable )
254 if( ( NULL != mImpl->mEventData ) &&
255 mImpl->mEventData->mDecorator )
257 if( mImpl->mEventData->mDecorator )
259 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
264 bool Controller::IsVerticalScrollEnabled() const
266 if( ( NULL != mImpl->mEventData ) &&
267 mImpl->mEventData->mDecorator )
269 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
275 void Controller::SetSmoothHandlePanEnabled( bool enable )
277 if( ( NULL != mImpl->mEventData ) &&
278 mImpl->mEventData->mDecorator )
280 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
284 bool Controller::IsSmoothHandlePanEnabled() const
286 if( ( NULL != mImpl->mEventData ) &&
287 mImpl->mEventData->mDecorator )
289 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
295 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
297 mImpl->mMaximumNumberOfCharacters = maxCharacters;
300 int Controller::GetMaximumNumberOfCharacters()
302 return mImpl->mMaximumNumberOfCharacters;
305 void Controller::SetEnableCursorBlink( bool enable )
307 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
309 if( NULL != mImpl->mEventData )
311 mImpl->mEventData->mCursorBlinkEnabled = enable;
314 mImpl->mEventData->mDecorator )
316 mImpl->mEventData->mDecorator->StopCursorBlink();
321 bool Controller::GetEnableCursorBlink() const
323 if( NULL != mImpl->mEventData )
325 return mImpl->mEventData->mCursorBlinkEnabled;
331 void Controller::SetMultiLineEnabled( bool enable )
333 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
335 if( layout != mImpl->mLayoutEngine.GetLayout() )
337 // Set the layout type.
338 mImpl->mLayoutEngine.SetLayout( layout );
340 // Set the flags to redo the layout operations
341 const OperationsMask layoutOperations = static_cast<OperationsMask>( LAYOUT |
346 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
348 mImpl->RequestRelayout();
352 bool Controller::IsMultiLineEnabled() const
354 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
357 void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
359 if( alignment != mImpl->mModel->mHorizontalAlignment )
361 // Set the alignment.
362 mImpl->mModel->mHorizontalAlignment = alignment;
364 // Set the flag to redo the alignment operation.
365 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
367 mImpl->RequestRelayout();
371 Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
373 return mImpl->mModel->mHorizontalAlignment;
376 void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
378 if( alignment != mImpl->mModel->mVerticalAlignment )
380 // Set the alignment.
381 mImpl->mModel->mVerticalAlignment = alignment;
383 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
385 mImpl->RequestRelayout();
389 Layout::VerticalAlignment Controller::GetVerticalAlignment() const
391 return mImpl->mModel->mVerticalAlignment;
394 void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
396 if( lineWrapMode != mImpl->mModel->mLineWrapMode )
398 // Set the text wrap mode.
399 mImpl->mModel->mLineWrapMode = lineWrapMode;
402 // Update Text layout for applying wrap mode
403 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
408 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
409 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
410 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
413 mImpl->RequestRelayout();
417 Layout::LineWrap::Mode Controller::GetLineWrapMode() const
419 return mImpl->mModel->mLineWrapMode;
422 void Controller::SetTextElideEnabled( bool enabled )
424 mImpl->mModel->mElideEnabled = enabled;
427 bool Controller::IsTextElideEnabled() const
429 return mImpl->mModel->mElideEnabled;
432 void Controller::SetSelectionEnabled( bool enabled )
434 mImpl->mEventData->mSelectionEnabled = enabled;
437 bool Controller::IsSelectionEnabled() const
439 return mImpl->mEventData->mSelectionEnabled;
444 void Controller::SetText( const std::string& text )
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
448 // Reset keyboard as text changed
449 mImpl->ResetImfManager();
451 // Remove the previously set text and style.
457 CharacterIndex lastCursorIndex = 0u;
459 if( NULL != mImpl->mEventData )
461 // If popup shown then hide it by switching to Editing state
462 if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
463 ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
464 ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
465 ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
467 mImpl->ChangeState( EventData::EDITING );
473 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
475 MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
476 mImpl->mModel->mLogicalModel->mFontDescriptionRuns );
478 Length textSize = 0u;
479 const uint8_t* utf8 = NULL;
480 if( mImpl->mMarkupProcessorEnabled )
482 ProcessMarkupString( text, markupProcessData );
483 textSize = markupProcessData.markupProcessedText.size();
485 // This is a bit horrible but std::string returns a (signed) char*
486 utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
490 textSize = text.size();
492 // This is a bit horrible but std::string returns a (signed) char*
493 utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
496 // Convert text into UTF-32
497 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
498 utf32Characters.Resize( textSize );
500 // Transform a text array encoded in utf8 into an array encoded in utf32.
501 // It returns the actual number of characters.
502 Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
503 utf32Characters.Resize( characterCount );
505 DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
506 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
508 // The characters to be added.
509 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
511 // To reset the cursor position
512 lastCursorIndex = characterCount;
514 // Update the rest of the model during size negotiation
515 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
517 // The natural size needs to be re-calculated.
518 mImpl->mRecalculateNaturalSize = true;
520 // Apply modifications to the model
521 mImpl->mOperationsPending = ALL_OPERATIONS;
525 ShowPlaceholderText();
528 // Resets the cursor position.
529 ResetCursorPosition( lastCursorIndex );
531 // Scrolls the text to make the cursor visible.
532 ResetScrollPosition();
534 mImpl->RequestRelayout();
536 if( NULL != mImpl->mEventData )
538 // Cancel previously queued events
539 mImpl->mEventData->mEventQueue.clear();
542 // Do this last since it provides callbacks into application code.
543 if( NULL != mImpl->mEditableControlInterface )
545 mImpl->mEditableControlInterface->TextChanged();
549 void Controller::GetText( std::string& text ) const
551 if( !mImpl->IsShowingPlaceholderText() )
553 // Retrieves the text string.
554 mImpl->GetText( 0u, text );
558 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
562 void Controller::SetPlaceholderText( const std::string& text )
564 if( NULL != mImpl->mEventData )
566 mImpl->mEventData->mPlaceholderText = text;
568 // Update placeholder if there is no text
569 if( mImpl->IsShowingPlaceholderText() ||
570 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
572 ShowPlaceholderText();
577 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
578 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
580 if( NULL != mImpl->mEventData )
582 if( PLACEHOLDER_TYPE_INACTIVE == type )
584 mImpl->mEventData->mPlaceholderTextInactive = text;
588 mImpl->mEventData->mPlaceholderTextActive = text;
591 // Update placeholder if there is no text
592 if( mImpl->IsShowingPlaceholderText() ||
593 ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
595 ShowPlaceholderText();
600 void Controller::GetPlaceholderText( std::string& text ) const
602 if( NULL != mImpl->mEventData )
604 text = mImpl->mEventData->mPlaceholderText;
608 // This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
609 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
611 if( NULL != mImpl->mEventData )
613 if( PLACEHOLDER_TYPE_INACTIVE == type )
615 text = mImpl->mEventData->mPlaceholderTextInactive;
619 text = mImpl->mEventData->mPlaceholderTextActive;
624 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
626 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
628 if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
630 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
631 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
635 mImpl->RequestRelayout();
639 // public : Default style & Input style
641 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
643 if( NULL == mImpl->mFontDefaults )
645 mImpl->mFontDefaults = new FontDefaults();
648 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
649 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
650 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
652 // Clear the font-specific data
655 mImpl->RequestRelayout();
658 const std::string& Controller::GetDefaultFontFamily() const
660 if( NULL != mImpl->mFontDefaults )
662 return mImpl->mFontDefaults->mFontDescription.family;
668 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
670 if( NULL != mImpl->mEventData )
672 if( NULL == mImpl->mEventData->mPlaceholderFont )
674 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
677 mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
678 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
679 mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
681 mImpl->RequestRelayout();
685 const std::string& Controller::GetPlaceholderFontFamily() const
687 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
689 return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
695 void Controller::SetDefaultFontWeight( FontWeight weight )
697 if( NULL == mImpl->mFontDefaults )
699 mImpl->mFontDefaults = new FontDefaults();
702 mImpl->mFontDefaults->mFontDescription.weight = weight;
703 mImpl->mFontDefaults->weightDefined = true;
705 // Clear the font-specific data
708 mImpl->RequestRelayout();
711 bool Controller::IsDefaultFontWeightDefined() const
713 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 return mImpl->mFontDefaults->widthDefined;
782 FontWidth Controller::GetDefaultFontWidth() const
784 if( NULL != mImpl->mFontDefaults )
786 return mImpl->mFontDefaults->mFontDescription.width;
789 return TextAbstraction::FontWidth::NORMAL;
792 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
794 if( NULL != mImpl->mEventData )
796 if( NULL == mImpl->mEventData->mPlaceholderFont )
798 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
801 mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
802 mImpl->mEventData->mPlaceholderFont->widthDefined = true;
804 mImpl->RequestRelayout();
808 bool Controller::IsPlaceholderTextFontWidthDefined() const
810 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
812 return mImpl->mEventData->mPlaceholderFont->widthDefined;
817 FontWidth Controller::GetPlaceholderTextFontWidth() const
819 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
821 return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
824 return TextAbstraction::FontWidth::NORMAL;
827 void Controller::SetDefaultFontSlant( FontSlant slant )
829 if( NULL == mImpl->mFontDefaults )
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.slant = slant;
835 mImpl->mFontDefaults->slantDefined = true;
837 // Clear the font-specific data
840 mImpl->RequestRelayout();
843 bool Controller::IsDefaultFontSlantDefined() const
845 return mImpl->mFontDefaults->slantDefined;
848 FontSlant Controller::GetDefaultFontSlant() const
850 if( NULL != mImpl->mFontDefaults )
852 return mImpl->mFontDefaults->mFontDescription.slant;
855 return TextAbstraction::FontSlant::NORMAL;
858 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
860 if( NULL != mImpl->mEventData )
862 if( NULL == mImpl->mEventData->mPlaceholderFont )
864 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
867 mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
868 mImpl->mEventData->mPlaceholderFont->slantDefined = true;
870 mImpl->RequestRelayout();
874 bool Controller::IsPlaceholderTextFontSlantDefined() const
876 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
878 return mImpl->mEventData->mPlaceholderFont->slantDefined;
883 FontSlant Controller::GetPlaceholderTextFontSlant() const
885 if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
887 return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
890 return TextAbstraction::FontSlant::NORMAL;
893 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
895 if( NULL == mImpl->mFontDefaults )
897 mImpl->mFontDefaults = new FontDefaults();
904 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
905 mImpl->mFontDefaults->sizeDefined = true;
910 // Point size = Pixel size * 72.f / DPI
911 unsigned int horizontalDpi = 0u;
912 unsigned int verticalDpi = 0u;
913 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
914 fontClient.GetDpi( horizontalDpi, verticalDpi );
916 mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
917 mImpl->mFontDefaults->sizeDefined = true;
922 // Clear the font-specific data
925 mImpl->RequestRelayout();
928 float Controller::GetDefaultFontSize( FontSizeType type ) const
931 if( NULL != mImpl->mFontDefaults )
937 value = mImpl->mFontDefaults->mDefaultPointSize;
942 // Pixel size = Point size * DPI / 72.f
943 unsigned int horizontalDpi = 0u;
944 unsigned int verticalDpi = 0u;
945 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
946 fontClient.GetDpi( horizontalDpi, verticalDpi );
948 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
958 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
960 if( NULL != mImpl->mEventData )
962 if( NULL == mImpl->mEventData->mPlaceholderFont )
964 mImpl->mEventData->mPlaceholderFont = new FontDefaults();
971 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
972 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
973 mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
978 // Point size = Pixel size * 72.f / DPI
979 unsigned int horizontalDpi = 0u;
980 unsigned int verticalDpi = 0u;
981 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
982 fontClient.GetDpi( horizontalDpi, verticalDpi );
984 mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
985 mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
986 mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
991 mImpl->RequestRelayout();
995 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
998 if( NULL != mImpl->mEventData )
1004 if( NULL != mImpl->mEventData->mPlaceholderFont )
1006 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1010 // If the placeholder text font size is not set, then return the default font size.
1011 value = GetDefaultFontSize( POINT_SIZE );
1017 if( NULL != mImpl->mEventData->mPlaceholderFont )
1019 // Pixel size = Point size * DPI / 72.f
1020 unsigned int horizontalDpi = 0u;
1021 unsigned int verticalDpi = 0u;
1022 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1023 fontClient.GetDpi( horizontalDpi, verticalDpi );
1025 value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1029 // If the placeholder text font size is not set, then return the default font size.
1030 value = GetDefaultFontSize( PIXEL_SIZE );
1041 void Controller::SetDefaultColor( const Vector4& color )
1043 mImpl->mTextColor = color;
1045 if( !mImpl->IsShowingPlaceholderText() )
1047 mImpl->mModel->mVisualModel->SetTextColor( color );
1049 mImpl->RequestRelayout();
1053 const Vector4& Controller::GetDefaultColor() const
1055 return mImpl->mTextColor;
1058 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1060 if( NULL != mImpl->mEventData )
1062 mImpl->mEventData->mPlaceholderTextColor = textColor;
1065 if( mImpl->IsShowingPlaceholderText() )
1067 mImpl->mModel->mVisualModel->SetTextColor( textColor );
1068 mImpl->RequestRelayout();
1072 const Vector4& Controller::GetPlaceholderTextColor() const
1074 if( NULL != mImpl->mEventData )
1076 return mImpl->mEventData->mPlaceholderTextColor;
1079 return Color::BLACK;
1082 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1084 mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1086 mImpl->RequestRelayout();
1089 const Vector2& Controller::GetShadowOffset() const
1091 return mImpl->mModel->mVisualModel->GetShadowOffset();
1094 void Controller::SetShadowColor( const Vector4& shadowColor )
1096 mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1098 mImpl->RequestRelayout();
1101 const Vector4& Controller::GetShadowColor() const
1103 return mImpl->mModel->mVisualModel->GetShadowColor();
1106 void Controller::SetUnderlineColor( const Vector4& color )
1108 mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1110 mImpl->RequestRelayout();
1113 const Vector4& Controller::GetUnderlineColor() const
1115 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1118 void Controller::SetUnderlineEnabled( bool enabled )
1120 mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1122 mImpl->RequestRelayout();
1125 bool Controller::IsUnderlineEnabled() const
1127 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1130 void Controller::SetUnderlineHeight( float height )
1132 mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1134 mImpl->RequestRelayout();
1137 float Controller::GetUnderlineHeight() const
1139 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1142 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1144 if( NULL == mImpl->mEmbossDefaults )
1146 mImpl->mEmbossDefaults = new EmbossDefaults();
1149 mImpl->mEmbossDefaults->properties = embossProperties;
1152 const std::string& Controller::GetDefaultEmbossProperties() const
1154 if( NULL != mImpl->mEmbossDefaults )
1156 return mImpl->mEmbossDefaults->properties;
1159 return EMPTY_STRING;
1162 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1164 if( NULL == mImpl->mOutlineDefaults )
1166 mImpl->mOutlineDefaults = new OutlineDefaults();
1169 mImpl->mOutlineDefaults->properties = outlineProperties;
1172 const std::string& Controller::GetDefaultOutlineProperties() const
1174 if( NULL != mImpl->mOutlineDefaults )
1176 return mImpl->mOutlineDefaults->properties;
1179 return EMPTY_STRING;
1182 void Controller::SetDefaultLineSpacing( float lineSpacing )
1184 //TODO finish implementation
1185 mImpl->mLayoutEngine.SetDefaultLineSpacing( lineSpacing );
1188 float Controller::GetDefaultLineSpacing() const
1190 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1193 void Controller::SetInputColor( const Vector4& color )
1195 if( NULL != mImpl->mEventData )
1197 mImpl->mEventData->mInputStyle.textColor = color;
1198 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1200 if( EventData::SELECTING == mImpl->mEventData->mState )
1202 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1204 // Get start and end position of selection
1205 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1206 const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1208 // Add the color run.
1209 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1210 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1212 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1213 colorRun.color = color;
1214 colorRun.characterRun.characterIndex = startOfSelectedText;
1215 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1217 // Request to relayout.
1218 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1219 mImpl->RequestRelayout();
1221 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1222 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1223 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1228 const Vector4& Controller::GetInputColor() const
1230 if( NULL != mImpl->mEventData )
1232 return mImpl->mEventData->mInputStyle.textColor;
1235 // Return the default text's color if there is no EventData.
1236 return mImpl->mTextColor;
1240 void Controller::SetInputFontFamily( const std::string& fontFamily )
1242 if( NULL != mImpl->mEventData )
1244 mImpl->mEventData->mInputStyle.familyName = fontFamily;
1245 mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1247 if( EventData::SELECTING == mImpl->mEventData->mState )
1249 CharacterIndex startOfSelectedText = 0u;
1250 Length lengthOfSelectedText = 0u;
1251 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1252 mImpl->mModel->mLogicalModel,
1253 startOfSelectedText,
1254 lengthOfSelectedText );
1256 fontDescriptionRun.familyLength = fontFamily.size();
1257 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1258 memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1259 fontDescriptionRun.familyDefined = true;
1261 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1263 // Request to relayout.
1264 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1269 UPDATE_LAYOUT_SIZE |
1272 mImpl->mRecalculateNaturalSize = true;
1273 mImpl->RequestRelayout();
1275 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1276 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1277 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1279 // As the font changes, recalculate the handle positions is needed.
1280 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1281 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1282 mImpl->mEventData->mUpdateHighlightBox = true;
1283 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1288 const std::string& Controller::GetInputFontFamily() const
1290 if( NULL != mImpl->mEventData )
1292 return mImpl->mEventData->mInputStyle.familyName;
1295 // Return the default font's family if there is no EventData.
1296 return GetDefaultFontFamily();
1299 void Controller::SetInputFontWeight( FontWeight weight )
1301 if( NULL != mImpl->mEventData )
1303 mImpl->mEventData->mInputStyle.weight = weight;
1304 mImpl->mEventData->mInputStyle.isWeightDefined = true;
1306 if( EventData::SELECTING == mImpl->mEventData->mState )
1308 CharacterIndex startOfSelectedText = 0u;
1309 Length lengthOfSelectedText = 0u;
1310 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1311 mImpl->mModel->mLogicalModel,
1312 startOfSelectedText,
1313 lengthOfSelectedText );
1315 fontDescriptionRun.weight = weight;
1316 fontDescriptionRun.weightDefined = true;
1318 // Request to relayout.
1319 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1324 UPDATE_LAYOUT_SIZE |
1327 mImpl->mRecalculateNaturalSize = true;
1328 mImpl->RequestRelayout();
1330 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1331 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1332 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1334 // As the font might change, recalculate the handle positions is needed.
1335 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1336 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1337 mImpl->mEventData->mUpdateHighlightBox = true;
1338 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1343 bool Controller::IsInputFontWeightDefined() const
1345 bool defined = false;
1347 if( NULL != mImpl->mEventData )
1349 defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1355 FontWeight Controller::GetInputFontWeight() const
1357 if( NULL != mImpl->mEventData )
1359 return mImpl->mEventData->mInputStyle.weight;
1362 return GetDefaultFontWeight();
1365 void Controller::SetInputFontWidth( FontWidth width )
1367 if( NULL != mImpl->mEventData )
1369 mImpl->mEventData->mInputStyle.width = width;
1370 mImpl->mEventData->mInputStyle.isWidthDefined = true;
1372 if( EventData::SELECTING == mImpl->mEventData->mState )
1374 CharacterIndex startOfSelectedText = 0u;
1375 Length lengthOfSelectedText = 0u;
1376 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1377 mImpl->mModel->mLogicalModel,
1378 startOfSelectedText,
1379 lengthOfSelectedText );
1381 fontDescriptionRun.width = width;
1382 fontDescriptionRun.widthDefined = true;
1384 // Request to relayout.
1385 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1390 UPDATE_LAYOUT_SIZE |
1393 mImpl->mRecalculateNaturalSize = true;
1394 mImpl->RequestRelayout();
1396 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1397 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1398 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1400 // As the font might change, recalculate the handle positions is needed.
1401 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1402 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1403 mImpl->mEventData->mUpdateHighlightBox = true;
1404 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1409 bool Controller::IsInputFontWidthDefined() const
1411 bool defined = false;
1413 if( NULL != mImpl->mEventData )
1415 defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1421 FontWidth Controller::GetInputFontWidth() const
1423 if( NULL != mImpl->mEventData )
1425 return mImpl->mEventData->mInputStyle.width;
1428 return GetDefaultFontWidth();
1431 void Controller::SetInputFontSlant( FontSlant slant )
1433 if( NULL != mImpl->mEventData )
1435 mImpl->mEventData->mInputStyle.slant = slant;
1436 mImpl->mEventData->mInputStyle.isSlantDefined = true;
1438 if( EventData::SELECTING == mImpl->mEventData->mState )
1440 CharacterIndex startOfSelectedText = 0u;
1441 Length lengthOfSelectedText = 0u;
1442 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1443 mImpl->mModel->mLogicalModel,
1444 startOfSelectedText,
1445 lengthOfSelectedText );
1447 fontDescriptionRun.slant = slant;
1448 fontDescriptionRun.slantDefined = true;
1450 // Request to relayout.
1451 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1456 UPDATE_LAYOUT_SIZE |
1459 mImpl->mRecalculateNaturalSize = true;
1460 mImpl->RequestRelayout();
1462 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1463 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1464 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1466 // As the font might change, recalculate the handle positions is needed.
1467 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1468 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1469 mImpl->mEventData->mUpdateHighlightBox = true;
1470 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1475 bool Controller::IsInputFontSlantDefined() const
1477 bool defined = false;
1479 if( NULL != mImpl->mEventData )
1481 defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1487 FontSlant Controller::GetInputFontSlant() const
1489 if( NULL != mImpl->mEventData )
1491 return mImpl->mEventData->mInputStyle.slant;
1494 return GetDefaultFontSlant();
1497 void Controller::SetInputFontPointSize( float size )
1499 if( NULL != mImpl->mEventData )
1501 mImpl->mEventData->mInputStyle.size = size;
1502 mImpl->mEventData->mInputStyle.isSizeDefined = true;
1504 if( EventData::SELECTING == mImpl->mEventData->mState )
1506 CharacterIndex startOfSelectedText = 0u;
1507 Length lengthOfSelectedText = 0u;
1508 FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1509 mImpl->mModel->mLogicalModel,
1510 startOfSelectedText,
1511 lengthOfSelectedText );
1513 fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1514 fontDescriptionRun.sizeDefined = true;
1516 // Request to relayout.
1517 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1522 UPDATE_LAYOUT_SIZE |
1525 mImpl->mRecalculateNaturalSize = true;
1526 mImpl->RequestRelayout();
1528 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1529 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1530 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1532 // As the font might change, recalculate the handle positions is needed.
1533 mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1534 mImpl->mEventData->mUpdateRightSelectionPosition = true;
1535 mImpl->mEventData->mUpdateHighlightBox = true;
1536 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1541 float Controller::GetInputFontPointSize() const
1543 if( NULL != mImpl->mEventData )
1545 return mImpl->mEventData->mInputStyle.size;
1548 // Return the default font's point size if there is no EventData.
1549 return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1552 void Controller::SetInputLineSpacing( float lineSpacing )
1554 if( NULL != mImpl->mEventData )
1556 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1557 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1561 float Controller::GetInputLineSpacing() const
1563 if( NULL != mImpl->mEventData )
1565 return mImpl->mEventData->mInputStyle.lineSpacing;
1571 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1573 if( NULL != mImpl->mEventData )
1575 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1579 const std::string& Controller::GetInputShadowProperties() const
1581 if( NULL != mImpl->mEventData )
1583 return mImpl->mEventData->mInputStyle.shadowProperties;
1586 return EMPTY_STRING;
1589 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1591 if( NULL != mImpl->mEventData )
1593 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1597 const std::string& Controller::GetInputUnderlineProperties() const
1599 if( NULL != mImpl->mEventData )
1601 return mImpl->mEventData->mInputStyle.underlineProperties;
1604 return EMPTY_STRING;
1607 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1609 if( NULL != mImpl->mEventData )
1611 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1615 const std::string& Controller::GetInputEmbossProperties() const
1617 if( NULL != mImpl->mEventData )
1619 return mImpl->mEventData->mInputStyle.embossProperties;
1622 return GetDefaultEmbossProperties();
1625 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1627 if( NULL != mImpl->mEventData )
1629 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1633 const std::string& Controller::GetInputOutlineProperties() const
1635 if( NULL != mImpl->mEventData )
1637 return mImpl->mEventData->mInputStyle.outlineProperties;
1640 return GetDefaultOutlineProperties();
1643 void Controller::SetInputModePassword( bool passwordInput )
1645 if( NULL != mImpl->mEventData )
1647 mImpl->mEventData->mPasswordInput = passwordInput;
1651 bool Controller::IsInputModePassword()
1653 if( NULL != mImpl->mEventData )
1655 return mImpl->mEventData->mPasswordInput;
1660 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1662 if( NULL != mImpl->mEventData )
1664 mImpl->mEventData->mDoubleTapAction = action;
1668 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1670 NoTextTap::Action action = NoTextTap::NO_ACTION;
1672 if( NULL != mImpl->mEventData )
1674 action = mImpl->mEventData->mDoubleTapAction;
1680 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1682 if( NULL != mImpl->mEventData )
1684 mImpl->mEventData->mLongPressAction = action;
1688 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1690 NoTextTap::Action action = NoTextTap::NO_ACTION;
1692 if( NULL != mImpl->mEventData )
1694 action = mImpl->mEventData->mLongPressAction;
1700 bool Controller::IsUnderlineSetByString()
1702 return mImpl->mUnderlineSetByString;
1705 void Controller::UnderlineSetByString( bool setByString )
1707 mImpl->mUnderlineSetByString = setByString;
1710 bool Controller::IsShadowSetByString()
1712 return mImpl->mShadowSetByString;
1715 void Controller::ShadowSetByString( bool setByString )
1717 mImpl->mShadowSetByString = setByString;
1720 bool Controller::IsFontStyleSetByString()
1722 return mImpl->mFontStyleSetByString;
1725 void Controller::FontStyleSetByString( bool setByString )
1727 mImpl->mFontStyleSetByString = setByString;
1730 // public : Queries & retrieves.
1732 Layout::Engine& Controller::GetLayoutEngine()
1734 return mImpl->mLayoutEngine;
1737 View& Controller::GetView()
1739 return mImpl->mView;
1742 Vector3 Controller::GetNaturalSize()
1744 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
1745 Vector3 naturalSize;
1747 // Make sure the model is up-to-date before layouting
1748 ProcessModifyEvents();
1750 if( mImpl->mRecalculateNaturalSize )
1752 // Operations that can be done only once until the text changes.
1753 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1760 GET_GLYPH_METRICS );
1762 // Set the update info to relayout the whole text.
1763 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1764 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1766 // Make sure the model is up-to-date before layouting
1767 mImpl->UpdateModel( onlyOnceOperations );
1769 // Layout the text for the new width.
1770 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1772 // Store the actual control's size to restore later.
1773 const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
1775 DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
1776 static_cast<OperationsMask>( onlyOnceOperations |
1778 naturalSize.GetVectorXY() );
1780 // Do not do again the only once operations.
1781 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1783 // Do the size related operations again.
1784 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1787 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1789 // Stores the natural size to avoid recalculate it again
1790 // unless the text/style changes.
1791 mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
1793 mImpl->mRecalculateNaturalSize = false;
1795 // Clear the update info. This info will be set the next time the text is updated.
1796 mImpl->mTextUpdateInfo.Clear();
1798 // Restore the actual control's size.
1799 mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
1801 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1805 naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
1807 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
1810 naturalSize.x = ConvertToEven( naturalSize.x );
1811 naturalSize.y = ConvertToEven( naturalSize.y );
1816 float Controller::GetHeightForWidth( float width )
1818 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
1819 // Make sure the model is up-to-date before layouting
1820 ProcessModifyEvents();
1823 if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
1824 mImpl->mTextUpdateInfo.mFullRelayoutNeeded )
1826 // Operations that can be done only once until the text changes.
1827 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
1834 GET_GLYPH_METRICS );
1836 // Set the update info to relayout the whole text.
1837 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1838 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1840 // Make sure the model is up-to-date before layouting
1841 mImpl->UpdateModel( onlyOnceOperations );
1844 // Layout the text for the new width.
1845 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
1847 // Store the actual control's width.
1848 const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
1850 DoRelayout( Size( width, MAX_FLOAT ),
1851 static_cast<OperationsMask>( onlyOnceOperations |
1855 // Do not do again the only once operations.
1856 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
1858 // Do the size related operations again.
1859 const OperationsMask sizeOperations = static_cast<OperationsMask>( LAYOUT |
1863 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
1865 // Clear the update info. This info will be set the next time the text is updated.
1866 mImpl->mTextUpdateInfo.Clear();
1868 // Restore the actual control's width.
1869 mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
1871 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
1875 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1876 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
1879 return layoutSize.height;
1882 int Controller::GetLineCount( float width )
1884 GetHeightForWidth( width );
1885 int numberofLines = mImpl->mModel->GetNumberOfLines();
1886 return numberofLines;
1889 const ModelInterface* const Controller::GetTextModel() const
1891 return mImpl->mModel.Get();
1894 float Controller::GetScrollAmountByUserInput()
1896 float scrollAmount = 0.0f;
1898 if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1900 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1901 mImpl->mEventData->mCheckScrollAmount = false;
1903 return scrollAmount;
1906 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
1908 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1911 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1912 layoutHeight = layout.height;
1913 scrollPosition = mImpl->mModel->mScrollPosition.y;
1914 isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
1918 void Controller::SetHiddenInputOption(const Property::Map& options )
1920 if( NULL == mImpl->mHiddenInput )
1922 mImpl->mHiddenInput = new HiddenText( this );
1924 mImpl->mHiddenInput->SetProperties(options);
1927 void Controller::GetHiddenInputOption(Property::Map& options )
1929 if( NULL != mImpl->mHiddenInput )
1931 mImpl->mHiddenInput->GetProperties(options);
1935 void Controller::SetPlaceholderProperty( const Property::Map& map )
1937 const Property::Map::SizeType count = map.Count();
1939 for( Property::Map::SizeType position = 0; position < count; ++position )
1941 KeyValuePair keyValue = map.GetKeyValue( position );
1942 Property::Key& key = keyValue.first;
1943 Property::Value& value = keyValue.second;
1945 if( key == PLACEHOLDER_TEXT )
1947 std::string text = "";
1949 SetPlaceholderText( text );
1951 else if( key == PLACEHOLDER_COLOR )
1954 value.Get( textColor );
1955 if( GetPlaceholderTextColor() != textColor )
1957 SetPlaceholderTextColor( textColor );
1960 else if( key == PLACEHOLDER_FONT_FAMILY )
1962 std::string fontFamily = "";
1963 value.Get( fontFamily );
1964 SetPlaceholderFontFamily( fontFamily );
1966 else if( key == PLACEHOLDER_FONT_STYLE )
1968 SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
1970 else if( key == PLACEHOLDER_POINT_SIZE )
1973 value.Get( pointSize );
1974 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
1976 SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
1979 else if( key == PLACEHOLDER_PIXEL_SIZE )
1982 value.Get( pixelSize );
1983 if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
1985 SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
1991 void Controller::GetPlaceholderProperty( Property::Map& map )
1993 if( NULL != mImpl->mEventData )
1995 map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderText;
1996 map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
1997 map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
1999 Property::Value fontStyleMapGet;
2000 GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2001 map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
2003 // Choose font size : POINT_SIZE or PIXEL_SIZE
2004 if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2006 map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2010 map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2015 // public : Relayout.
2017 Controller::UpdateTextType Controller::Relayout( const Size& size )
2019 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false" );
2021 UpdateTextType updateTextType = NONE_UPDATED;
2023 if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2025 if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2027 mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2028 updateTextType = MODEL_UPDATED;
2031 // Clear the update info. This info will be set the next time the text is updated.
2032 mImpl->mTextUpdateInfo.Clear();
2034 // Not worth to relayout if width or height is equal to zero.
2035 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2037 return updateTextType;
2040 // Whether a new size has been set.
2041 const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2045 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2047 // Layout operations that need to be done if the size changes.
2048 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2051 UPDATE_LAYOUT_SIZE |
2053 // Set the update info to relayout the whole text.
2054 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2055 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2057 // Store the size used to layout the text.
2058 mImpl->mModel->mVisualModel->mControlSize = size;
2061 // Whether there are modify events.
2062 if( 0u != mImpl->mModifyEvents.Count() )
2064 // Style operations that need to be done if the text is modified.
2065 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2069 // Make sure the model is up-to-date before layouting.
2070 ProcessModifyEvents();
2071 bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2075 updated = DoRelayout( size,
2076 mImpl->mOperationsPending,
2077 layoutSize ) || updated;
2081 updateTextType = MODEL_UPDATED;
2084 // Do not re-do any operation until something changes.
2085 mImpl->mOperationsPending = NO_OPERATION;
2086 mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2088 // Whether the text control is editable
2089 const bool isEditable = NULL != mImpl->mEventData;
2091 // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2093 if( newSize && isEditable )
2095 offset = mImpl->mModel->mScrollPosition;
2098 if( !isEditable || !IsMultiLineEnabled() )
2100 // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2101 CalculateVerticalOffset( size );
2108 // If there is a new size, the scroll position needs to be clamped.
2109 mImpl->ClampHorizontalScroll( layoutSize );
2111 // Update the decorator's positions is needed if there is a new size.
2112 mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2115 // Move the cursor, grab handle etc.
2116 if( mImpl->ProcessInputEvents() )
2118 updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2122 // Clear the update info. This info will be set the next time the text is updated.
2123 mImpl->mTextUpdateInfo.Clear();
2124 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2126 return updateTextType;
2129 void Controller::RequestRelayout()
2131 mImpl->RequestRelayout();
2134 // public : Input style change signals.
2136 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2138 return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2141 void Controller::ProcessInputStyleChangedSignals()
2143 if( NULL == mImpl->mEventData )
2149 for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2150 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2154 const InputStyle::Mask mask = *it;
2156 if( NULL != mImpl->mEditableControlInterface )
2158 // Emit the input style changed signal.
2159 mImpl->mEditableControlInterface->InputStyleChanged( mask );
2163 mImpl->mEventData->mInputStyleChangedQueue.Clear();
2166 // public : Text-input Event Queuing.
2168 void Controller::KeyboardFocusGainEvent()
2170 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2172 if( NULL != mImpl->mEventData )
2174 if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2175 ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2177 mImpl->ChangeState( EventData::EDITING );
2178 mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2179 mImpl->mEventData->mUpdateInputStyle = true;
2181 mImpl->NotifyImfMultiLineStatus();
2182 if( mImpl->IsShowingPlaceholderText() )
2184 // Show alternative placeholder-text when editing
2185 ShowPlaceholderText();
2188 mImpl->RequestRelayout();
2192 void Controller::KeyboardFocusLostEvent()
2194 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2196 if( NULL != mImpl->mEventData )
2198 if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2200 mImpl->ChangeState( EventData::INACTIVE );
2202 if( !mImpl->IsShowingRealText() )
2204 // Revert to regular placeholder-text when not editing
2205 ShowPlaceholderText();
2209 mImpl->RequestRelayout();
2212 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2214 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2216 bool textChanged = false;
2217 bool relayoutNeeded = false;
2219 if( ( NULL != mImpl->mEventData ) &&
2220 ( keyEvent.state == KeyEvent::Down ) )
2222 int keyCode = keyEvent.keyCode;
2223 const std::string& keyString = keyEvent.keyPressed;
2225 const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2227 // Pre-process to separate modifying events from non-modifying input events.
2230 // In some platforms arrive key events with no key code.
2233 else if( Dali::DALI_KEY_ESCAPE == keyCode )
2235 // Escape key is a special case which causes focus loss
2236 KeyboardFocusLostEvent();
2238 // Will request for relayout.
2239 relayoutNeeded = true;
2241 else if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode ) ||
2242 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2243 ( Dali::DALI_KEY_CURSOR_UP == keyCode ) ||
2244 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode ) )
2246 // If don't have any text, do nothing.
2247 if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2252 uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2253 uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2254 uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2255 uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2257 // Logic to determine whether this text control will lose focus or not.
2258 if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition ) ||
2259 ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition) ||
2260 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2261 ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2262 ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2263 ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2268 mImpl->mEventData->mCheckScrollAmount = true;
2269 Event event( Event::CURSOR_KEY_EVENT );
2270 event.p1.mInt = keyCode;
2271 mImpl->mEventData->mEventQueue.push_back( event );
2273 // Will request for relayout.
2274 relayoutNeeded = true;
2276 else if( Dali::DALI_KEY_BACKSPACE == keyCode )
2278 textChanged = BackspaceKeyEvent();
2280 // Will request for relayout.
2281 relayoutNeeded = true;
2283 else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2284 IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2285 IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2287 // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2288 mImpl->ChangeState( EventData::INACTIVE );
2290 // Will request for relayout.
2291 relayoutNeeded = true;
2293 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2295 else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
2297 // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
2298 // and a character is typed after the type of a upper case latin character.
2302 else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2304 // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2309 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2311 // IMF manager is no longer handling key-events
2312 mImpl->ClearPreEditFlag();
2314 InsertText( keyString, COMMIT );
2317 // Will request for relayout.
2318 relayoutNeeded = true;
2321 if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2322 ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2324 ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2325 ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2326 ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2328 // Should not change the state if the key is the shift send by the imf manager.
2329 // Otherwise, when the state is SELECTING the text controller can't send the right
2330 // surrounding info to the imf.
2331 mImpl->ChangeState( EventData::EDITING );
2333 // Will request for relayout.
2334 relayoutNeeded = true;
2337 if( relayoutNeeded )
2339 mImpl->RequestRelayout();
2344 ( NULL != mImpl->mEditableControlInterface ) )
2346 // Do this last since it provides callbacks into application code
2347 mImpl->mEditableControlInterface->TextChanged();
2353 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2355 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2357 if( NULL != mImpl->mEventData )
2359 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2360 EventData::State state( mImpl->mEventData->mState );
2361 bool relayoutNeeded( false ); // to avoid unnecessary relayouts when tapping an empty text-field
2363 if( mImpl->IsClipboardVisible() )
2365 if( EventData::INACTIVE == state || EventData::EDITING == state)
2367 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2369 relayoutNeeded = true;
2371 else if( 1u == tapCount )
2373 if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2375 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE ); // If Popup shown hide it here so can be shown again if required.
2378 if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2380 mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2381 relayoutNeeded = true;
2385 if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2387 // Hide placeholder text
2391 if( EventData::INACTIVE == state )
2393 mImpl->ChangeState( EventData::EDITING );
2395 else if( !mImpl->IsClipboardEmpty() )
2397 mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2399 relayoutNeeded = true;
2402 else if( 2u == tapCount )
2404 if( mImpl->mEventData->mSelectionEnabled &&
2405 mImpl->IsShowingRealText() )
2407 relayoutNeeded = true;
2408 mImpl->mEventData->mIsLeftHandleSelected = true;
2409 mImpl->mEventData->mIsRightHandleSelected = true;
2413 // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2414 if( relayoutNeeded )
2416 Event event( Event::TAP_EVENT );
2417 event.p1.mUint = tapCount;
2418 event.p2.mFloat = x;
2419 event.p3.mFloat = y;
2420 mImpl->mEventData->mEventQueue.push_back( event );
2422 mImpl->RequestRelayout();
2426 // Reset keyboard as tap event has occurred.
2427 mImpl->ResetImfManager();
2430 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2432 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2434 if( NULL != mImpl->mEventData )
2436 Event event( Event::PAN_EVENT );
2437 event.p1.mInt = state;
2438 event.p2.mFloat = displacement.x;
2439 event.p3.mFloat = displacement.y;
2440 mImpl->mEventData->mEventQueue.push_back( event );
2442 mImpl->RequestRelayout();
2446 void Controller::LongPressEvent( Gesture::State state, float x, float y )
2448 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2450 if( ( state == Gesture::Started ) &&
2451 ( NULL != mImpl->mEventData ) )
2453 // The 1st long-press on inactive text-field is treated as tap
2454 if( EventData::INACTIVE == mImpl->mEventData->mState )
2456 mImpl->ChangeState( EventData::EDITING );
2458 Event event( Event::TAP_EVENT );
2460 event.p2.mFloat = x;
2461 event.p3.mFloat = y;
2462 mImpl->mEventData->mEventQueue.push_back( event );
2464 mImpl->RequestRelayout();
2466 else if( !mImpl->IsShowingRealText() )
2468 Event event( Event::LONG_PRESS_EVENT );
2469 event.p1.mInt = state;
2470 event.p2.mFloat = x;
2471 event.p3.mFloat = y;
2472 mImpl->mEventData->mEventQueue.push_back( event );
2473 mImpl->RequestRelayout();
2475 else if( !mImpl->IsClipboardVisible() )
2477 // Reset the imf manager to commit the pre-edit before selecting the text.
2478 mImpl->ResetImfManager();
2480 Event event( Event::LONG_PRESS_EVENT );
2481 event.p1.mInt = state;
2482 event.p2.mFloat = x;
2483 event.p3.mFloat = y;
2484 mImpl->mEventData->mEventQueue.push_back( event );
2485 mImpl->RequestRelayout();
2487 mImpl->mEventData->mIsLeftHandleSelected = true;
2488 mImpl->mEventData->mIsRightHandleSelected = true;
2493 ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
2495 // Whether the text needs to be relaid-out.
2496 bool requestRelayout = false;
2498 // Whether to retrieve the text and cursor position to be sent to the IMF manager.
2499 bool retrieveText = false;
2500 bool retrieveCursor = false;
2502 switch( imfEvent.eventName )
2504 case ImfManager::COMMIT:
2506 InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
2507 requestRelayout = true;
2508 retrieveCursor = true;
2511 case ImfManager::PREEDIT:
2513 InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
2514 requestRelayout = true;
2515 retrieveCursor = true;
2518 case ImfManager::DELETESURROUNDING:
2520 const bool textDeleted = RemoveText( imfEvent.cursorOffset,
2521 imfEvent.numberOfChars,
2522 DONT_UPDATE_INPUT_STYLE );
2526 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2527 !mImpl->IsPlaceholderAvailable() )
2529 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2533 ShowPlaceholderText();
2535 mImpl->mEventData->mUpdateCursorPosition = true;
2536 mImpl->mEventData->mScrollAfterDelete = true;
2538 requestRelayout = true;
2542 case ImfManager::GETSURROUNDING:
2544 retrieveText = true;
2545 retrieveCursor = true;
2548 case ImfManager::PRIVATECOMMAND:
2550 // PRIVATECOMMAND event is just for getting the private command message
2551 retrieveText = true;
2552 retrieveCursor = true;
2555 case ImfManager::VOID:
2562 if( requestRelayout )
2564 mImpl->mOperationsPending = ALL_OPERATIONS;
2565 mImpl->RequestRelayout();
2569 CharacterIndex cursorPosition = 0u;
2570 Length numberOfWhiteSpaces = 0u;
2572 if( retrieveCursor )
2574 numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
2576 cursorPosition = mImpl->GetLogicalCursorPosition();
2578 if( cursorPosition < numberOfWhiteSpaces )
2580 cursorPosition = 0u;
2584 cursorPosition -= numberOfWhiteSpaces;
2590 mImpl->GetText( numberOfWhiteSpaces, text );
2593 ImfManager::ImfCallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
2595 if( requestRelayout &&
2596 ( NULL != mImpl->mEditableControlInterface ) )
2598 // Do this last since it provides callbacks into application code
2599 mImpl->mEditableControlInterface->TextChanged();
2602 return callbackData;
2605 void Controller::PasteClipboardItemEvent()
2607 // Retrieve the clipboard contents first
2608 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
2609 std::string stringToPaste( notifier.GetContent() );
2611 // Commit the current pre-edit text; the contents of the clipboard should be appended
2612 mImpl->ResetImfManager();
2614 // Temporary disable hiding clipboard
2615 mImpl->SetClipboardHideEnable( false );
2618 PasteText( stringToPaste );
2620 mImpl->SetClipboardHideEnable( true );
2623 // protected : Inherit from Text::Decorator::ControllerInterface.
2625 void Controller::GetTargetSize( Vector2& targetSize )
2627 targetSize = mImpl->mModel->mVisualModel->mControlSize;
2630 void Controller::AddDecoration( Actor& actor, bool needsClipping )
2632 if( NULL != mImpl->mEditableControlInterface )
2634 mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
2638 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
2640 DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
2642 if( NULL != mImpl->mEventData )
2644 switch( handleType )
2648 Event event( Event::GRAB_HANDLE_EVENT );
2649 event.p1.mUint = state;
2650 event.p2.mFloat = x;
2651 event.p3.mFloat = y;
2653 mImpl->mEventData->mEventQueue.push_back( event );
2656 case LEFT_SELECTION_HANDLE:
2658 Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
2659 event.p1.mUint = state;
2660 event.p2.mFloat = x;
2661 event.p3.mFloat = y;
2663 mImpl->mEventData->mEventQueue.push_back( event );
2666 case RIGHT_SELECTION_HANDLE:
2668 Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
2669 event.p1.mUint = state;
2670 event.p2.mFloat = x;
2671 event.p3.mFloat = y;
2673 mImpl->mEventData->mEventQueue.push_back( event );
2676 case LEFT_SELECTION_HANDLE_MARKER:
2677 case RIGHT_SELECTION_HANDLE_MARKER:
2679 // Markers do not move the handles.
2682 case HANDLE_TYPE_COUNT:
2684 DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
2688 mImpl->RequestRelayout();
2692 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
2694 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
2696 if( NULL == mImpl->mEventData )
2703 case Toolkit::TextSelectionPopup::CUT:
2705 mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
2706 mImpl->mOperationsPending = ALL_OPERATIONS;
2708 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
2709 !mImpl->IsPlaceholderAvailable() )
2711 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
2715 ShowPlaceholderText();
2718 mImpl->mEventData->mUpdateCursorPosition = true;
2719 mImpl->mEventData->mScrollAfterDelete = true;
2721 mImpl->RequestRelayout();
2723 if( NULL != mImpl->mEditableControlInterface )
2725 mImpl->mEditableControlInterface->TextChanged();
2729 case Toolkit::TextSelectionPopup::COPY:
2731 mImpl->SendSelectionToClipboard( false ); // Text not modified
2733 mImpl->mEventData->mUpdateCursorPosition = true;
2735 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
2738 case Toolkit::TextSelectionPopup::PASTE:
2740 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
2743 case Toolkit::TextSelectionPopup::SELECT:
2745 const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
2747 if( mImpl->mEventData->mSelectionEnabled )
2749 // Creates a SELECT event.
2750 SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
2754 case Toolkit::TextSelectionPopup::SELECT_ALL:
2756 // Creates a SELECT_ALL event
2757 SelectEvent( 0.f, 0.f, true );
2760 case Toolkit::TextSelectionPopup::CLIPBOARD:
2762 mImpl->ShowClipboard();
2765 case Toolkit::TextSelectionPopup::NONE:
2773 void Controller::DisplayTimeExpired()
2775 mImpl->mEventData->mUpdateCursorPosition = true;
2776 // Apply modifications to the model
2777 mImpl->mOperationsPending = ALL_OPERATIONS;
2779 mImpl->RequestRelayout();
2782 // private : Update.
2784 void Controller::InsertText( const std::string& text, Controller::InsertType type )
2786 bool removedPrevious = false;
2787 bool removedSelected = false;
2788 bool maxLengthReached = false;
2790 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
2792 if( NULL == mImpl->mEventData )
2797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
2798 this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
2799 mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2801 // TODO: At the moment the underline runs are only for pre-edit.
2802 mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
2804 // Remove the previous IMF pre-edit.
2805 if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
2807 removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
2808 mImpl->mEventData->mPreEditLength,
2809 DONT_UPDATE_INPUT_STYLE );
2811 mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
2812 mImpl->mEventData->mPreEditLength = 0u;
2816 // Remove the previous Selection.
2817 removedSelected = RemoveSelectedText();
2821 Vector<Character> utf32Characters;
2822 Length characterCount = 0u;
2826 // Convert text into UTF-32
2827 utf32Characters.Resize( text.size() );
2829 // This is a bit horrible but std::string returns a (signed) char*
2830 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
2832 // Transform a text array encoded in utf8 into an array encoded in utf32.
2833 // It returns the actual number of characters.
2834 characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
2835 utf32Characters.Resize( characterCount );
2837 DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
2838 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
2841 if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
2843 // The placeholder text is no longer needed
2844 if( mImpl->IsShowingPlaceholderText() )
2849 mImpl->ChangeState( EventData::EDITING );
2851 // Handle the IMF (predicitive text) state changes
2852 if( COMMIT == type )
2854 // IMF manager is no longer handling key-events
2855 mImpl->ClearPreEditFlag();
2859 if( !mImpl->mEventData->mPreEditFlag )
2861 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
2863 // Record the start of the pre-edit text
2864 mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
2867 mImpl->mEventData->mPreEditLength = utf32Characters.Count();
2868 mImpl->mEventData->mPreEditFlag = true;
2870 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
2873 const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
2875 // Restrict new text to fit within Maximum characters setting.
2876 Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
2877 maxLengthReached = ( characterCount > maxSizeOfNewText );
2879 // The cursor position.
2880 CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
2882 // Update the text's style.
2884 // Updates the text style runs by adding characters.
2885 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
2887 // Get the character index from the cursor index.
2888 const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
2890 // Retrieve the text's style for the given index.
2892 mImpl->RetrieveDefaultInputStyle( style );
2893 mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
2895 // Whether to add a new text color run.
2896 const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
2898 // Whether to add a new font run.
2899 const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
2900 const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
2901 const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
2902 const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
2903 const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
2908 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
2909 mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
2911 ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
2912 colorRun.color = mImpl->mEventData->mInputStyle.textColor;
2913 colorRun.characterRun.characterIndex = cursorIndex;
2914 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2917 if( addFontNameRun ||
2923 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
2924 mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
2926 FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
2928 if( addFontNameRun )
2930 fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
2931 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
2932 memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
2933 fontDescriptionRun.familyDefined = true;
2935 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
2938 if( addFontWeightRun )
2940 fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
2941 fontDescriptionRun.weightDefined = true;
2944 if( addFontWidthRun )
2946 fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
2947 fontDescriptionRun.widthDefined = true;
2950 if( addFontSlantRun )
2952 fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
2953 fontDescriptionRun.slantDefined = true;
2956 if( addFontSizeRun )
2958 fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
2959 fontDescriptionRun.sizeDefined = true;
2962 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
2963 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
2966 // Insert at current cursor position.
2967 Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
2969 if( cursorIndex < numberOfCharactersInModel )
2971 modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2975 modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
2978 // Mark the first paragraph to be updated.
2979 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
2981 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
2982 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2983 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
2984 mImpl->mTextUpdateInfo.mClearAll = true;
2988 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
2989 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
2992 // Update the cursor index.
2993 cursorIndex += maxSizeOfNewText;
2995 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 );
2998 if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
2999 mImpl->IsPlaceholderAvailable() )
3001 // Show place-holder if empty after removing the pre-edit text
3002 ShowPlaceholderText();
3003 mImpl->mEventData->mUpdateCursorPosition = true;
3004 mImpl->ClearPreEditFlag();
3006 else if( removedPrevious ||
3008 ( 0 != utf32Characters.Count() ) )
3010 // Queue an inserted event
3011 mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3013 mImpl->mEventData->mUpdateCursorPosition = true;
3014 if( removedSelected )
3016 mImpl->mEventData->mScrollAfterDelete = true;
3020 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3024 if( maxLengthReached )
3026 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3028 mImpl->ResetImfManager();
3030 if( NULL != mImpl->mEditableControlInterface )
3032 // Do this last since it provides callbacks into application code
3033 mImpl->mEditableControlInterface->MaxLengthReached();
3038 void Controller::PasteText( const std::string& stringToPaste )
3040 InsertText( stringToPaste, Text::Controller::COMMIT );
3041 mImpl->ChangeState( EventData::EDITING );
3042 mImpl->RequestRelayout();
3044 if( NULL != mImpl->mEditableControlInterface )
3046 // Do this last since it provides callbacks into application code
3047 mImpl->mEditableControlInterface->TextChanged();
3051 bool Controller::RemoveText( int cursorOffset,
3052 int numberOfCharacters,
3053 UpdateInputStyleType type )
3055 bool removed = false;
3057 if( NULL == mImpl->mEventData )
3062 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3063 this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3065 if( !mImpl->IsShowingPlaceholderText() )
3067 // Delete at current cursor position
3068 Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3069 CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3071 CharacterIndex cursorIndex = 0;
3073 // Validate the cursor position & number of characters
3074 if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3076 cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3079 if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3081 numberOfCharacters = currentText.Count() - cursorIndex;
3084 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.
3085 ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3087 // Mark the paragraphs to be updated.
3088 if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3090 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3091 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3092 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3093 mImpl->mTextUpdateInfo.mClearAll = true;
3097 mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3098 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3101 // Update the input style and remove the text's style before removing the text.
3103 if( UPDATE_INPUT_STYLE == type )
3105 // Keep a copy of the current input style.
3106 InputStyle currentInputStyle;
3107 currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3109 // Set first the default input style.
3110 mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3112 // Update the input style.
3113 mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3115 // Compare if the input style has changed.
3116 const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3118 if( hasInputStyleChanged )
3120 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3121 // Queue the input style changed signal.
3122 mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3126 // Updates the text style runs by removing characters. Runs with no characters are removed.
3127 mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3129 // Remove the characters.
3130 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3131 Vector<Character>::Iterator last = first + numberOfCharacters;
3133 currentText.Erase( first, last );
3135 // Cursor position retreat
3136 oldCursorIndex = cursorIndex;
3138 mImpl->mEventData->mScrollAfterDelete = true;
3140 DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3148 bool Controller::RemoveSelectedText()
3150 bool textRemoved( false );
3152 if( EventData::SELECTING == mImpl->mEventData->mState )
3154 std::string removedString;
3155 mImpl->RetrieveSelection( removedString, true );
3157 if( !removedString.empty() )
3160 mImpl->ChangeState( EventData::EDITING );
3167 // private : Relayout.
3169 bool Controller::DoRelayout( const Size& size,
3170 OperationsMask operationsRequired,
3173 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3174 bool viewUpdated( false );
3176 // Calculate the operations to be done.
3177 const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3179 const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3180 const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3182 // Get the current layout size.
3183 layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3185 if( NO_OPERATION != ( LAYOUT & operations ) )
3187 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3189 // Some vectors with data needed to layout and reorder may be void
3190 // after the first time the text has been laid out.
3191 // Fill the vectors again.
3193 // Calculate the number of glyphs to layout.
3194 const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3195 const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3196 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3197 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3199 const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3200 const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3201 const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3202 const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3204 if( 0u == totalNumberOfGlyphs )
3206 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3208 mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3211 // Nothing else to do if there is no glyphs.
3212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3216 const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3217 const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3218 const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3219 const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3220 const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3221 const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3222 const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3224 // Set the layout parameters.
3225 Layout::Parameters layoutParameters( size,
3227 lineBreakInfo.Begin(),
3228 wordBreakInfo.Begin(),
3229 ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3231 glyphsToCharactersMap.Begin(),
3232 charactersPerGlyph.Begin(),
3233 charactersToGlyphBuffer,
3234 glyphsPerCharacterBuffer,
3235 totalNumberOfGlyphs,
3236 mImpl->mModel->mHorizontalAlignment,
3237 mImpl->mModel->mLineWrapMode );
3239 // Resize the vector of positions to have the same size than the vector of glyphs.
3240 Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3241 glyphPositions.Resize( totalNumberOfGlyphs );
3243 // Whether the last character is a new paragraph character.
3244 mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3245 layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3247 // The initial glyph and the number of glyphs to layout.
3248 layoutParameters.startGlyphIndex = startGlyphIndex;
3249 layoutParameters.numberOfGlyphs = numberOfGlyphs;
3250 layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3251 layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3253 // Update the visual model.
3255 viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3257 mImpl->mModel->mVisualModel->mLines,
3259 mImpl->mModel->mElideEnabled );
3261 viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3265 layoutSize = newLayoutSize;
3267 if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3269 mImpl->mAutoScrollDirectionRTL = false;
3272 // Reorder the lines
3273 if( NO_OPERATION != ( REORDER & operations ) )
3275 Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3276 Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3278 // Check first if there are paragraphs with bidirectional info.
3279 if( 0u != bidirectionalInfo.Count() )
3282 const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3284 // Reorder the lines.
3285 bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3286 ReorderLines( bidirectionalInfo,
3288 requestedNumberOfCharacters,
3289 mImpl->mModel->mVisualModel->mLines,
3290 bidirectionalLineInfo );
3292 // Set the bidirectional info per line into the layout parameters.
3293 layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3294 layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3296 // Re-layout the text. Reorder those lines with right to left characters.
3297 mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3299 requestedNumberOfCharacters,
3302 if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3304 const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3307 mImpl->mAutoScrollDirectionRTL = firstline->direction;
3313 // Sets the layout size.
3314 if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3316 mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3321 if( NO_OPERATION != ( ALIGN & operations ) )
3323 // The laid-out lines.
3324 Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3326 // Need to align with the control's size as the text may contain lines
3327 // starting either with left to right text or right to left.
3328 mImpl->mLayoutEngine.Align( size,
3330 requestedNumberOfCharacters,
3331 mImpl->mModel->mHorizontalAlignment,
3333 mImpl->mModel->mAlignmentOffset );
3337 #if defined(DEBUG_ENABLED)
3338 std::string currentText;
3339 GetText( currentText );
3340 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mAutoScrollDirectionRTL[%s] [%s]\n", this, (mImpl->mAutoScrollDirectionRTL)?"true":"false", currentText.c_str() );
3342 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3346 void Controller::CalculateVerticalOffset( const Size& controlSize )
3348 Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3350 if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3352 // Get the line height of the default font.
3353 layoutSize.height = mImpl->GetDefaultFontLineHeight();
3356 switch( mImpl->mModel->mVerticalAlignment )
3358 case Layout::VERTICAL_ALIGN_TOP:
3360 mImpl->mModel->mScrollPosition.y = 0.f;
3363 case Layout::VERTICAL_ALIGN_CENTER:
3365 mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3368 case Layout::VERTICAL_ALIGN_BOTTOM:
3370 mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3376 // private : Events.
3378 void Controller::ProcessModifyEvents()
3380 Vector<ModifyEvent>& events = mImpl->mModifyEvents;
3382 if( 0u == events.Count() )
3388 for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
3389 endIt = events.End();
3393 const ModifyEvent& event = *it;
3395 if( ModifyEvent::TEXT_REPLACED == event.type )
3397 // A (single) replace event should come first, otherwise we wasted time processing NOOP events
3398 DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
3400 TextReplacedEvent();
3402 else if( ModifyEvent::TEXT_INSERTED == event.type )
3404 TextInsertedEvent();
3406 else if( ModifyEvent::TEXT_DELETED == event.type )
3408 // Placeholder-text cannot be deleted
3409 if( !mImpl->IsShowingPlaceholderText() )
3416 if( NULL != mImpl->mEventData )
3418 // When the text is being modified, delay cursor blinking
3419 mImpl->mEventData->mDecorator->DelayCursorBlink();
3422 // Discard temporary text
3426 void Controller::TextReplacedEvent()
3428 // The natural size needs to be re-calculated.
3429 mImpl->mRecalculateNaturalSize = true;
3431 // Apply modifications to the model
3432 mImpl->mOperationsPending = ALL_OPERATIONS;
3435 void Controller::TextInsertedEvent()
3437 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
3439 if( NULL == mImpl->mEventData )
3444 mImpl->mEventData->mCheckScrollAmount = true;
3446 // The natural size needs to be re-calculated.
3447 mImpl->mRecalculateNaturalSize = true;
3449 // Apply modifications to the model; TODO - Optimize this
3450 mImpl->mOperationsPending = ALL_OPERATIONS;
3453 void Controller::TextDeletedEvent()
3455 DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
3457 if( NULL == mImpl->mEventData )
3462 mImpl->mEventData->mCheckScrollAmount = true;
3464 // The natural size needs to be re-calculated.
3465 mImpl->mRecalculateNaturalSize = true;
3467 // Apply modifications to the model; TODO - Optimize this
3468 mImpl->mOperationsPending = ALL_OPERATIONS;
3471 void Controller::SelectEvent( float x, float y, bool selectAll )
3473 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3475 if( NULL != mImpl->mEventData )
3479 Event event( Event::SELECT_ALL );
3480 mImpl->mEventData->mEventQueue.push_back( event );
3484 Event event( Event::SELECT );
3485 event.p2.mFloat = x;
3486 event.p3.mFloat = y;
3487 mImpl->mEventData->mEventQueue.push_back( event );
3490 mImpl->mEventData->mCheckScrollAmount = true;
3491 mImpl->mEventData->mIsLeftHandleSelected = true;
3492 mImpl->mEventData->mIsRightHandleSelected = true;
3493 mImpl->RequestRelayout();
3497 bool Controller::BackspaceKeyEvent()
3499 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
3501 bool removed = false;
3503 if( NULL == mImpl->mEventData )
3508 // IMF manager is no longer handling key-events
3509 mImpl->ClearPreEditFlag();
3511 if( EventData::SELECTING == mImpl->mEventData->mState )
3513 removed = RemoveSelectedText();
3515 else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
3517 // Remove the character before the current cursor position
3518 removed = RemoveText( -1,
3520 UPDATE_INPUT_STYLE );
3525 if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3526 !mImpl->IsPlaceholderAvailable() )
3528 mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3532 ShowPlaceholderText();
3534 mImpl->mEventData->mUpdateCursorPosition = true;
3535 mImpl->mEventData->mScrollAfterDelete = true;
3541 // private : Helpers.
3543 void Controller::ResetText()
3546 mImpl->mModel->mLogicalModel->mText.Clear();
3548 // We have cleared everything including the placeholder-text
3549 mImpl->PlaceholderCleared();
3551 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3552 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3553 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
3555 // Clear any previous text.
3556 mImpl->mTextUpdateInfo.mClearAll = true;
3558 // The natural size needs to be re-calculated.
3559 mImpl->mRecalculateNaturalSize = true;
3561 // Apply modifications to the model
3562 mImpl->mOperationsPending = ALL_OPERATIONS;
3565 void Controller::ShowPlaceholderText()
3567 if( mImpl->IsPlaceholderAvailable() )
3569 DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
3571 if( NULL == mImpl->mEventData )
3576 mImpl->mEventData->mIsShowingPlaceholderText = true;
3578 // Disable handles when showing place-holder text
3579 mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
3580 mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
3581 mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
3583 const char* text( NULL );
3586 if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
3588 if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
3589 ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
3591 text = mImpl->mEventData->mPlaceholderTextActive.c_str();
3592 size = mImpl->mEventData->mPlaceholderTextActive.size();
3596 text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
3597 size = mImpl->mEventData->mPlaceholderTextInactive.size();
3602 if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
3604 text = mImpl->mEventData->mPlaceholderText.c_str();
3605 size = mImpl->mEventData->mPlaceholderText.size();
3609 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3610 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3612 // Reset model for showing placeholder.
3613 mImpl->mModel->mLogicalModel->mText.Clear();
3614 mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
3616 // Convert text into UTF-32
3617 Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
3618 utf32Characters.Resize( size );
3620 // This is a bit horrible but std::string returns a (signed) char*
3621 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
3623 // Transform a text array encoded in utf8 into an array encoded in utf32.
3624 // It returns the actual number of characters.
3625 const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
3626 utf32Characters.Resize( characterCount );
3628 // The characters to be added.
3629 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
3631 // Reset the cursor position
3632 mImpl->mEventData->mPrimaryCursorPosition = 0;
3634 // The natural size needs to be re-calculated.
3635 mImpl->mRecalculateNaturalSize = true;
3637 // Apply modifications to the model
3638 mImpl->mOperationsPending = ALL_OPERATIONS;
3640 // Update the rest of the model during size negotiation
3641 mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
3645 void Controller::ClearFontData()
3647 if( mImpl->mFontDefaults )
3649 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
3652 // Set flags to update the model.
3653 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
3654 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3655 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
3657 mImpl->mTextUpdateInfo.mClearAll = true;
3658 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
3659 mImpl->mRecalculateNaturalSize = true;
3661 mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
3666 UPDATE_LAYOUT_SIZE |
3671 void Controller::ClearStyleData()
3673 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
3674 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
3677 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
3679 // Reset the cursor position
3680 if( NULL != mImpl->mEventData )
3682 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
3684 // Update the cursor if it's in editing mode.
3685 if( EventData::IsEditingState( mImpl->mEventData->mState ) )
3687 mImpl->mEventData->mUpdateCursorPosition = true;
3692 void Controller::ResetScrollPosition()
3694 if( NULL != mImpl->mEventData )
3696 // Reset the scroll position.
3697 mImpl->mModel->mScrollPosition = Vector2::ZERO;
3698 mImpl->mEventData->mScrollAfterUpdatePosition = true;
3702 // private : Private contructors & copy operator.
3704 Controller::Controller()
3707 mImpl = new Controller::Impl( NULL, NULL );
3710 Controller::Controller( ControlInterface* controlInterface )
3712 mImpl = new Controller::Impl( controlInterface, NULL );
3715 Controller::Controller( ControlInterface* controlInterface,
3716 EditableControlInterface* editableControlInterface )
3718 mImpl = new Controller::Impl( controlInterface,
3719 editableControlInterface );
3722 // The copy constructor and operator are left unimplemented.
3724 // protected : Destructor.
3726 Controller::~Controller()
3733 } // namespace Toolkit